[PATCH 02/10] drivers/nor/m25p80: add MEMGETINFO ioctl

Sascha Hauer s.hauer at pengutronix.de
Tue Sep 4 04:20:24 EDT 2012


On Mon, Sep 03, 2012 at 01:45:57PM +0200, Jan Luebbe wrote:
> Signed-off-by: Jan Luebbe <jlu at pengutronix.de>
> ---
>  drivers/nor/m25p80.c |   26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
> index 61f2195..1722e0a 100644
> --- a/drivers/nor/m25p80.c
> +++ b/drivers/nor/m25p80.c
> @@ -20,6 +20,7 @@
>  #include <common.h>
>  #include <init.h>
>  #include <driver.h>
> +#include <ioctl.h>
>  #include <spi/spi.h>
>  #include <spi/flash.h>
>  #include <xfuncs.h>
> @@ -690,9 +691,34 @@ static const struct spi_device_id *jedec_probe(struct spi_device *spi)
>  	return NULL;
>  }
>  
> +static int m25p80_ioctl(struct cdev *cdev, int request, void *buf)
> +{
> +	struct m25p *flash = cdev->priv;
> +	struct flash_info *info = flash->info;
> +	struct mtd_info_user *user = buf;
> +
> +	switch (request) {
> +	case MEMGETINFO:
> +		memset(user, 0, sizeof(*user));
> +		user->type = MTD_NORFLASH;
> +		user->flags = MTD_CAP_NORFLASH;
> +		user->size = flash->size;
> +		user->erasesize = info->sector_size;
> +		user->writesize = 1;
> +		user->oobsize = 0;
> +		/* The below fields are obsolete */
> +		user->ecctype = -1;
> +		user->eccsize = 0;
> +		return 0;
> +	}
> +
> +	return -EINVAL;
> +}
> +
>  static struct file_operations m25p80_ops = {
>  	.read   = m25p80_read,
>  	.write  = m25p80_write,
> +	.ioctl  = m25p80_ioctl,

Rather than doing this you should simply fill in cdev->mtd. See how the
cfi flash driver does this. Then it will also work for partitions on a
m25p80.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list