[PATCH 1/4] ARM i.MX IIM: Add a iim read function

Sascha Hauer s.hauer at pengutronix.de
Thu Jul 28 06:05:57 EDT 2011


To allow reading the iim from code.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/iim.c              |   28 ++++++++++++++++++++++++----
 arch/arm/mach-imx/include/mach/iim.h |    7 +++++++
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-imx/iim.c b/arch/arm/mach-imx/iim.c
index 0774ebb..7a8712b 100644
--- a/arch/arm/mach-imx/iim.c
+++ b/arch/arm/mach-imx/iim.c
@@ -22,6 +22,8 @@
 #include <xfuncs.h>
 #include <errno.h>
 #include <param.h>
+#include <fcntl.h>
+#include <malloc.h>
 
 #include <asm/io.h>
 
@@ -73,7 +75,7 @@ static int do_fuse_sense(unsigned long reg_base, unsigned int bank,
 	return readb(reg_base + IIM_SDAT);
 }
 
-static ssize_t imx_iim_read(struct cdev *cdev, void *buf, size_t count,
+static ssize_t imx_iim_cdev_read(struct cdev *cdev, void *buf, size_t count,
 		ulong offset, ulong flags)
 {
 	ulong size, i;
@@ -168,7 +170,7 @@ out:
 }
 #endif /* CONFIG_IMX_IIM_FUSE_BLOW */
 
-static ssize_t imx_iim_write(struct cdev *cdev, const void *buf, size_t count,
+static ssize_t imx_iim_cdev_write(struct cdev *cdev, const void *buf, size_t count,
 		ulong offset, ulong flags)
 {
 	ulong size, i;
@@ -204,8 +206,8 @@ static ssize_t imx_iim_write(struct cdev *cdev, const void *buf, size_t count,
 }
 
 static struct file_operations imx_iim_ops = {
-	.read	= imx_iim_read,
-	.write	= imx_iim_write,
+	.read	= imx_iim_cdev_read,
+	.write	= imx_iim_cdev_write,
 	.lseek	= dev_lseek_default,
 };
 
@@ -297,6 +299,24 @@ static int imx_iim_init(void)
 }
 coredevice_initcall(imx_iim_init);
 
+int imx_iim_read(unsigned int bank, int offset, int count, void *buf)
+{
+	struct cdev *cdev;
+	char *name = asprintf(DRIVERNAME "_bank%d", bank);
+	int ret;
+
+	cdev = cdev_open(name, O_RDONLY);
+	if (!cdev)
+		return -ENODEV;
+
+	ret = cdev_read(cdev, buf, count, offset, 0);
+
+	cdev_close(cdev);
+	free(name);
+
+	return ret;
+}
+
 int imx_iim_get_mac(unsigned char *mac)
 {
 	int i;
diff --git a/arch/arm/mach-imx/include/mach/iim.h b/arch/arm/mach-imx/include/mach/iim.h
index 03ff485..9ff44be 100644
--- a/arch/arm/mach-imx/include/mach/iim.h
+++ b/arch/arm/mach-imx/include/mach/iim.h
@@ -46,8 +46,15 @@ struct imx_iim_platform_data {
 };
 
 #ifdef CONFIG_IMX_IIM
+int imx_iim_read(unsigned int bank, int offset, int count, void *buf);
 int imx_iim_get_mac(unsigned char *mac);
 #else
+static inline int imx_iim_read(unsigned int bank, int offset, int count,
+		void *buf)
+{
+	return -EINVAL;
+}
+
 static inline int imx_iim_get_mac(unsigned char *mac)
 {
 	return -EINVAL;
-- 
1.7.5.4




More information about the barebox mailing list