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

Marc Kleine-Budde mkl at pengutronix.de
Thu Jul 28 10:10:23 EDT 2011


On 07/28/2011 12:05 PM, Sascha Hauer wrote:
> 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)

The order of count and buf is IMHO unintuitive:

       ssize_t read(int fildes, void *buf, size_t nbyte);

Marc

> +{
> +	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;


-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20110728/16ff7c76/attachment.sig>


More information about the barebox mailing list