drivers/mtd: add powernv flash MTD abstraction driver
Subsystems (2)
PATCH v3 1/1 drivers/mtd: add powernv flash MTD abstraction driver
Powerpc powernv platforms allow access to certain system flash devices through a firmwarwe interface. This change adds an mtd driver for these flash devices.
Minor updates from Jeremy Kerr and Joel Stanley.
---
V2: Address Brian Norris' review
Fix typos
Change from NAND flash type to NOR flash type
Correctness tweaks
V3: Address Neelesh Gupta's review
Minor corrections
Release the opal token on error
Unregister mtd device on module remove
--- drivers/mtd/devices/Kconfig | 8 + drivers/mtd/devices/Makefile | 1 + drivers/mtd/devices/powernv_flash.c | 286 ++++++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+) create mode 100644 drivers/mtd/devices/powernv_flash.c
drivers/mtd/devices/Kconfig +8 -0
@@ -195,6 +195,14 @@ config MTD_BLOCK2MTD Testing MTD users (eg JFFS2) on large media and media that might be removed during a write (using the floppy drive). +config MTD_POWERNV_FLASH + tristate "powernv flash MTD driver" + depends on PPC_POWERNV + help + This provides an MTD device to access flash on powernv OPAL + platforms from Linux. This device abstracts away the + firmware interface for flash access. + comment "Disk-On-Chip Device Drivers" config MTD_DOCG3
drivers/mtd/devices/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_MTD_SPEAR_SMI) += spear_smi.o obj-$(CONFIG_MTD_SST25L) += sst25l.o obj-$(CONFIG_MTD_BCM47XXSFLASH) += bcm47xxsflash.o obj-$(CONFIG_MTD_ST_SPI_FSM) += st_spi_fsm.o +obj-$(CONFIG_MTD_POWERNV_FLASH) += powernv_flash.o CFLAGS_docg3.o += -I$(src)
drivers/mtd/devices/powernv_flash.c new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
1.9.1
[...]
Quoted 12 lines
drivers/mtd/devices/powernv_flash.c new file +12
-0+/** +* @mtd: the device +* @erase: the erase info +* Returns 0 if erase successful or -ERRNO if an error occurred +*/ +static int powernv_flash_erase (struct mtd_info *mtd,struct erase_info *erase) +{ +int rc; + + erase->state =MTD_ERASING ; + +/* todo: register our own notifier to do a true async implementation */
drivers/mtd/devices/powernv_flash.c line 164
Quoted 10 lines
drivers/mtd/devices/powernv_flash.c new file +10
-0+ rc =powernv_flash_async_op (mtd,FLASH_OP_ERASE , erase->addr, + erase->len,NULL ,NULL ); + +if (rc) { + erase->fail_addr = erase->addr; + erase->state =MTD_ERASE_FAILED ; + }else { + erase->state =MTD_ERASE_DONE ; + } +mtd_erase_callback (erase);
return rc ? You also document the same '.... or -ERRNO if an error occurred'
Quoted 54 lines
drivers/mtd/devices/powernv_flash.c new file +54
-0+return 0 ; +} + +/** +* powernv_flash_set_driver_info - Fill the mtd_info structure and docg3 +* structure @pdev: The platform device +* @mtd: The structure to fill +*/ +static int powernv_flash_set_driver_info (struct device *dev, +struct mtd_info *mtd) +{ +u64 size; +u32 erase_size; +int rc; + + rc =of_property_read_u32 (dev->of_node,"ibm,flash-block-size" , + &erase_size); +if (rc) { +dev_err (dev,"couldn't get resource block size information\n" ); +return rc; + } + + rc =of_property_read_u64 (dev->of_node,"reg" , &size); +if (rc) { +dev_err (dev,"couldn't get resource size information\n" ); +return rc; + } + +/* +* Going to have to check what details I need to set and how to +* get them +*/ + mtd->name =of_get_property (dev->of_node,"name" ,NULL ); + mtd->type =MTD_NORFLASH ; + mtd->flags =MTD_WRITEABLE ; + mtd->size = size; + mtd->erasesize = erase_size; + mtd->writebufsize = mtd->writesize =1 ; + mtd->owner =THIS_MODULE ; + mtd->_erase = powernv_flash_erase; + mtd->_read = powernv_flash_read; + mtd->_write = powernv_flash_write; + mtd->dev.parent = dev; +return 0 ; +} + +/** +* powernv_flash_probe +* @pdev: platform device +* +* Returns 0 on success, -ENOMEM, -ENXIO on error +*/ +static int powernv_flash_probe (struct platform_device *pdev) +{
drivers/mtd/devices/powernv_flash.c line 228
Quoted 10 lines
drivers/mtd/devices/powernv_flash.c new file +10
-0+struct device *dev = &pdev->dev; +struct powernv_flash *data; +int ret; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) { + ret = -ENOMEM ; + goto out; + } + data->mtd.priv = data;
'mtd' is contained within the 'data' so you can cast 'mtd' to get the 'data' anywhere you want using container_of() macro.. 'priv' can be used to pass an unrelated structure .... just a thought, you may ignore it.. :)
Rest looks ok.
Neelesh.
Quoted 20 lines · Neelesh Gupta
[...]
Quoted 17 lines
drivers/mtd/devices/powernv_flash.c new file +17
-0+/** +* @mtd: the device +* @erase: the erase info +* Returns 0 if erase successful or -ERRNO if an error occurred +*/ +static int powernv_flash_erase (struct mtd_info *mtd,struct erase_info *erase) +{ +int rc; + + erase->state =MTD_ERASING ; + +/* todo: register our own notifier to do a true async implementation */ + rc =powernv_flash_async_op (mtd,FLASH_OP_ERASE , erase->addr, + erase->len,NULL ,NULL ); + +if (rc) { + erase->fail_addr = erase->addr;
Quoted 9 lines
drivers/mtd/devices/powernv_flash.c line 164
Quoted 5 lines
drivers/mtd/devices/powernv_flash.c new file +5
-0+ erase->state =MTD_ERASE_FAILED ; + }else { + erase->state =MTD_ERASE_DONE ; + } +mtd_erase_callback (erase);return rc ? You also document the same '.... or
-ERRNOif an error occurred'
Good catch, I'll amend.
Quoted 62 lines
Quoted 62 lines
drivers/mtd/devices/powernv_flash.c new file +62
-0+return 0 ; +} + +/** +* powernv_flash_set_driver_info - Fill the mtd_info structure and docg3 +* structure @pdev: The platform device +* @mtd: The structure to fill +*/ +static int powernv_flash_set_driver_info (struct device *dev, +struct mtd_info *mtd) +{ +u64 size; +u32 erase_size; +int rc; + + rc =of_property_read_u32 (dev->of_node,"ibm,flash-block-size" , + &erase_size); +if (rc) { +dev_err (dev,"couldn't get resource block size information\n" ); +return rc; + } + + rc =of_property_read_u64 (dev->of_node,"reg" , &size); +if (rc) { +dev_err (dev,"couldn't get resource size information\n" ); +return rc; + } + +/* +* Going to have to check what details I need to set and how to +* get them +*/ + mtd->name =of_get_property (dev->of_node,"name" ,NULL ); + mtd->type =MTD_NORFLASH ; + mtd->flags =MTD_WRITEABLE ; + mtd->size = size; + mtd->erasesize = erase_size; + mtd->writebufsize = mtd->writesize =1 ; + mtd->owner =THIS_MODULE ; + mtd->_erase = powernv_flash_erase; + mtd->_read = powernv_flash_read; + mtd->_write = powernv_flash_write; + mtd->dev.parent = dev; +return 0 ; +} + +/** +* powernv_flash_probe +* @pdev: platform device +* +* Returns 0 on success, -ENOMEM, -ENXIO on error +*/ +static int powernv_flash_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct powernv_flash *data; +int ret; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) { + ret = -ENOMEM ; + goto out;
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + data->mtd.priv = data;'mtd' is contained within the 'data' so you can cast 'mtd' to get the 'data'
anywhere you want usingcontainer_of()macro.. 'priv' can be used to pass
an unrelated structure .... just a thought, you may ignore it.. :)
Yeah, I think I couldn't agree with myself when I wrote and I figured there might be something I'd want to use priv for. There never was, that stayed. I realised it got quite circular and there are now many ways of getting back to data, I can't see any harm in leaving it like that, except the strangeness of it.
Thanks,
Cyril
Quoted 5 lines
Rest looks ok.
Neelesh.
PATCH v3 1/1 drivers/mtd: add powernv flash MTD abstraction driver
In reply to Neelesh GuptaPowerpc powernv platforms allow access to certain system flash devices through a firmwarwe interface. This change adds an mtd driver for these flash devices.
Minor updates from Jeremy Kerr and Joel Stanley.
---
V2: Address Brian Norris' review
Fix typos
Change from NAND flash type to NOR flash type
Correctness tweaks
V3: Address Neelesh Gupta's review
Minor corrections
Release the opal token on error
Unregister mtd device on module remove
--- drivers/mtd/devices/Kconfig | 8 + drivers/mtd/devices/Makefile | 1 + drivers/mtd/devices/powernv_flash.c | 286 ++++++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+) create mode 100644 drivers/mtd/devices/powernv_flash.c
drivers/mtd/devices/Kconfig +8 -0
@@ -195,6 +195,14 @@ config MTD_BLOCK2MTD Testing MTD users (eg JFFS2) on large media and media that might be removed during a write (using the floppy drive). +config MTD_POWERNV_FLASH + tristate "powernv flash MTD driver" + depends on PPC_POWERNV + help + This provides an MTD device to access flash on powernv OPAL + platforms from Linux. This device abstracts away the + firmware interface for flash access. + comment "Disk-On-Chip Device Drivers" config MTD_DOCG3
drivers/mtd/devices/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_MTD_SPEAR_SMI) += spear_smi.o obj-$(CONFIG_MTD_SST25L) += sst25l.o obj-$(CONFIG_MTD_BCM47XXSFLASH) += bcm47xxsflash.o obj-$(CONFIG_MTD_ST_SPI_FSM) += st_spi_fsm.o +obj-$(CONFIG_MTD_POWERNV_FLASH) += powernv_flash.o CFLAGS_docg3.o += -I$(src)
drivers/mtd/devices/powernv_flash.c new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
1.9.1
Michael Ellerman
reviewerQuoted 9 lines · Cyril Bur
Powerpc powernv platforms allow access to certain system flash devices through a firmwarwe interface. This change adds an mtd driver for these flash devices.
Minor updates from Jeremy Kerr and Joel Stanley.
Signed-off-by Cyril Bur <[email protected]>Signed-off-by Joel Stanley <[email protected]>Signed-off-by Jeremy Kerr <[email protected]>
Quoted 9 lines
---
V2: Address Brian Norris' review
Fix typos
Change from NAND flash type to NOR flash type
Correctness tweaks
V3: Address Neelesh Gupta's review
Minor corrections
Release the opal token on error
Unregister mtd device on module remove
You seem to have dropped Brian and linux-mtd from Cc?
Please put them back and repost, with a request for an ACK so we can take it via the powerpc tree.
cheers