mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data
Subsystems (9)
v2 cover mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data
Hi,
I noticed that, for MTD drivers that want to support DT partition parsing (essentially all recent ones), it's a bit awkward to set the tell MTD which DT node to use. I also noticed that this info is duplicated in a few places; namely, some sub-subsystems (like SPI NOR and NAND) need their own field to track the DT node, so let's have the propagate the 'MTD' DT node down for us.
Besides simplifying the boilerplate throughout MTD, this series also has the side effect of producing 'of_node' symlinks in sysfs. e.g.:
# ls -al /sys/class/mtd/mtd0/of_node lrwxrwxrwx 1 root root 0 Oct 26 19:17 /sys/class/mtd/mtd0/of_node -> ../../../../firmware/devicetree/base/spi@ff130000/flash@0
For NAND, this potentially has some other bigger initial side effects, since nand_dt_init() handles a bit more automagically for drivers that defined their ->flash_node. But these drivers should probably convert anyway. So, please test your favorite driver!
v1 -> v2:
* add helper functions for getting/setting the MTD/SPI-NOR/NAND DT node
* fix some build errors
* drop spi_nor's flash_node field (just use the MTD of_node)
Regards,
Brian
Brian Norris (11):
mtd: add get/set of_node/flash_node helpers
mtd: ofpart: grab device tree node directly from master device node
mtd: {nand,spi-nor}: assign MTD of_node
mtd: nand: convert to nand_set_flash_node()
mtd: spi-nor: convert to spi_nor_{get,set}_flash_node()
mtd: nand: drop unnecessary partition parser data
mtd: spi-nor: drop unnecessary partition parser data
mtd: spi-nor: drop flash_node field
mtd: drop unnecessary partition parser data
mtd: ofpart: drop 'of_node' partition parser data
mtd: physmap_of: assign parent for the concatenated MTD
drivers/mtd/devices/m25p80.c | 10 +++------- drivers/mtd/devices/mtd_dataflash.c | 5 ++--- drivers/mtd/devices/spear_smi.c | 6 ++---- drivers/mtd/devices/st_spi_fsm.c | 5 ++--- drivers/mtd/maps/lantiq-flash.c | 5 ++--- drivers/mtd/maps/physmap_of.c | 6 +++--- drivers/mtd/nand/atmel_nand.c | 7 +++---- drivers/mtd/nand/brcmnand/brcmnand.c | 5 ++--- drivers/mtd/nand/davinci_nand.c | 10 +++------- drivers/mtd/nand/fsl_elbc_nand.c | 5 ++--- drivers/mtd/nand/fsl_ifc_nand.c | 5 ++--- drivers/mtd/nand/fsl_upm.c | 5 ++--- drivers/mtd/nand/fsmc_nand.c | 9 ++++----- drivers/mtd/nand/gpio.c | 8 +++----- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 5 ++--- drivers/mtd/nand/hisi504_nand.c | 5 ++--- drivers/mtd/nand/lpc32xx_mlc.c | 7 +++---- drivers/mtd/nand/lpc32xx_slc.c | 7 +++---- drivers/mtd/nand/mpc5121_nfc.c | 5 ++--- drivers/mtd/nand/mxc_nand.c | 5 ++--- drivers/mtd/nand/nand_base.c | 3 +++ drivers/mtd/nand/ndfc.c | 5 ++--- drivers/mtd/nand/omap2.c | 6 ++---- drivers/mtd/nand/orion_nand.c | 6 ++---- drivers/mtd/nand/plat_nand.c | 5 ++--- drivers/mtd/nand/pxa3xx_nand.c | 10 +++++----- drivers/mtd/nand/sh_flctl.c | 6 ++---- drivers/mtd/nand/socrates_nand.c | 5 ++--- drivers/mtd/nand/sunxi_nand.c | 6 ++---- drivers/mtd/nand/vf610_nfc.c | 8 ++------ drivers/mtd/ofpart.c | 12 ++++-------- drivers/mtd/onenand/omap2.c | 8 +++----- drivers/mtd/spi-nor/fsl-quadspi.c | 6 ++---- drivers/mtd/spi-nor/nxp-spifi.c | 6 ++---- drivers/mtd/spi-nor/spi-nor.c | 2 +- drivers/staging/mt29f_spinand/mt29f_spinand.c | 5 ++--- include/linux/mtd/mtd.h | 11 +++++++++++ include/linux/mtd/nand.h | 11 +++++++++++ include/linux/mtd/partitions.h | 2 -- include/linux/mtd/spi-nor.h | 13 +++++++++++-- 40 files changed, 120 insertions(+), 141 deletions(-)
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 1/11 mtd: add get/set of_node/flash_node helpers
We are going to begin using the mtd->dev.of_node field for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions on spi_nor (and nand_chip eventually) too, so get that ready with their own helpers.
---
v2: new
include/linux/mtd/mtd.h | 11 +++++++++++ include/linux/mtd/nand.h | 11 +++++++++++ include/linux/mtd/spi-nor.h | 11 +++++++++++ 3 files changed, 33 insertions(+)
include/linux/mtd/mtd.h +11 -0
@@ -254,6 +254,17 @@ struct mtd_info {int usecount; }; +static inline void mtd_set_of_node (struct mtd_info *mtd, +struct device_node *np) +{ + mtd->dev.of_node = np; +} + +static inline struct device_node *mtd_get_of_node (struct mtd_info *mtd) +{ +return mtd->dev.of_node; +} +int mtd_erase (struct mtd_info *mtd,struct erase_info *instr);int mtd_point (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,void **virt,resource_size_t *phys);
include/linux/mtd/nand.h +11 -0
@@ -719,6 +719,17 @@ struct nand_chip {void *priv; }; +static inline void nand_set_flash_node (struct nand_chip *chip, +struct device_node *np) +{ + chip->flash_node = np; +} + +static inline struct device_node *nand_get_flash_node (struct nand_chip *chip) +{ +return chip->flash_node; +} +/* * NAND Flash Manufacturer ID Codes */
include/linux/mtd/spi-nor.h +11 -0
@@ -185,6 +185,17 @@ struct spi_nor {void *priv; }; +static inline void spi_nor_set_flash_node (struct spi_nor *nor, +struct device_node *np) +{ + nor->flash_node = np; +} + +static inline struct device_node *spi_nor_get_flash_node (struct spi_nor *nor) +{ +return nor->flash_node; +} +/** * spi_nor_scan() - scan the SPI NOR * @nor: the spi_nor structure
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Re: [PATCH v2 01/11] mtd: add get/set of_node/flash_node helpers
Quoted 19 lines · On Fri, 30 Oct 2015 20:33:20 -0700 Brian Norris <[email protected]>…
We are going to begin using the
mtd->dev.of_nodefield for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions onspi_nor(andnand_chipeventually) too, so get that ready with their own helpers.Signed-off-by Brian Norris <[email protected]>---
v2: newinclude/linux/mtd/mtd.h | 11 +++++++++++ include/linux/mtd/nand.h | 11 +++++++++++ include/linux/mtd/spi-nor.h | 11 +++++++++++ 3 files changed, 33 insertions(+)include/linux/mtd/mtd.h +0
-0
include/linux/mtd/mtd.h struct mtd_info { · line 260
Quoted 7 lines
include/linux/mtd/mtd.h +4
-0@@ -254,6 +254,17 @@ struct mtd_info {int usecount; }; +static inline void mtd_set_of_node (struct mtd_info *mtd, +struct device_node *np) +{ + mtd->dev.of_node = np;
Maybe we should retain a reference to the device_node here (IOW, replace '= np' by '= of_node_get(np)'). Of course this implies calling of_node_put() when the mtd device is unregistered.
include/linux/mtd/mtd.h struct mtd_info { · line 265
Quoted 5 lines
include/linux/mtd/mtd.h +5
-0+} + +static inline struct device_node *mtd_get_of_node (struct mtd_info *mtd) +{ +return mtd->dev.of_node;
Not sure this is relevant to to the same here before returning the device_node because it's mostly used by the MTD drivers and those are the ones who called mtd_set_of_node() in the first place, so we can assume it's safe to return an non-retained reference to a device_node.
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Re: [PATCH v2 01/11] mtd: add get/set of_node/flash_node helpers
Quoted 25 lines · Boris Brezillon
Quoted 22 lines · On Fri, 30 Oct 2015 20:33:20 -0700 Brian Norris <[email protected]>…
We are going to begin using the
mtd->dev.of_nodefield for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions onspi_nor(andnand_chipeventually) too, so get that ready with their own helpers.Signed-off-by Brian Norris <[email protected]>---
v2: newinclude/linux/mtd/mtd.h | 11 +++++++++++ include/linux/mtd/nand.h | 11 +++++++++++ include/linux/mtd/spi-nor.h | 11 +++++++++++ 3 files changed, 33 insertions(+)include/linux/mtd/mtd.h +0
-0@@ -254,6 +254,17 @@ struct mtd_info {int usecount; };
Quoted 8 lines
include/linux/mtd/mtd.h struct mtd_info { · line 260
Quoted 4 lines
include/linux/mtd/mtd.h +4
-0+static inline void mtd_set_of_node (struct mtd_info *mtd, +struct device_node *np) +{ + mtd->dev.of_node = np;Maybe we should retain a reference to the
device_nodehere (IOW, replace '= np' by '=of_node_get(np)'). Of course this implies callingof_node_put()when the mtd device is unregistered.
I'll admit I never really followed (nor verified) the OF get/put logic that well. But I suppose that makes sense.
Quoted 10 lines
include/linux/mtd/mtd.h struct mtd_info { · line 265
Quoted 5 lines
include/linux/mtd/mtd.h +5
-0+} + +static inline struct device_node *mtd_get_of_node (struct mtd_info *mtd) +{ +return mtd->dev.of_node;Not sure this is relevant to to the same here before returning the
device_nodebecause it's mostly used by the MTD drivers and those are the ones who calledmtd_set_of_node()in the first place, so we can assume it's safe to return an non-retained reference to adevice_node.
I think once the node has been "set", its consumers should stay in sync with the lifetime of the MTD; so I think just that initial refcount is sufficient.
IOW, if MTD drivers are still fiddling with an MTD's of_node after the MTD is unregistered, then we've failed somewhere else.
Brian
Re: [PATCH v2 01/11] mtd: add get/set of_node/flash_node helpers
In reply to Brian NorrisQuoted 8 lines · Brian Norris
We are going to begin using the
mtd->dev.of_nodefield for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions onspi_nor(andnand_chipeventually) too, so get that ready with their own helpers.Signed-off-by Brian Norris <[email protected]>---
v2: new
Pushed the first 5 to l2-mtd.git/next. Still re-reviewing the comments on the latter half of the series.
PATCH v2 2/11 mtd: ofpart: grab device tree node directly from master device node
In reply to Brian NorrisIt seems more logical to use a device node directly associated with the MTD master device (i.e., mtd->dev.of_node field) rather than requiring auxiliary partition parser information to be passed in by the driver in a separate struct.
This patch supports the mtd->dev.of_node field and deprecates the parser data 'of_node' field
Driver conversions may now follow.
Additional side benefit to assigning mtd->dev.of_node rather than using parser data: the driver core will automatically create a device -> node symlink for us.
---
v2: rebase, use new helpers
drivers/mtd/ofpart.c | 18 ++++++++++-------- include/linux/mtd/partitions.h | 4 +++- 2 files changed, 13 insertions(+), 9 deletions(-)
drivers/mtd/ofpart.c +10 -8
@@ -37,10 +37,11 @@ static int parse_ofpart_partitions(struct mtd_info *master,bool dedicated = true; -if (!data) -return 0 ; - - mtd_node = data->of_node; +/* +* of_node can be provided through auxiliary parser data or (preferred) +* by assigning the master device node +*/ + mtd_node = data && data->of_node ? data->of_node :mtd_get_of_node (master);if (!mtd_node)return 0 ;
@@ -149,10 +150,11 @@ static int parse_ofoldpart_partitions(struct mtd_info *master, } *part;const char *names; -if (!data) -return 0 ; - - dp = data->of_node; +/* +* of_node can be provided through auxiliary parser data or (preferred) +* by assigning the master device node +*/ + dp = data && data->of_node ? data->of_node :mtd_get_of_node (master);if (!dp)return 0 ;
include/linux/mtd/partitions.h +3 -1
@@ -56,7 +56,9 @@ struct device_node;/** * struct mtd_part_parser_data - used to pass data to MTD partition parsers. * @origin: for RedBoot, start address of MTD device -* @of_node: for OF parsers, device node containing partitioning information +* @of_node: for OF parsers, device node containing partitioning information. +* This field is deprecated, as the device node should simply be +* assigned to the master struct device. */ struct mtd_part_parser_data {unsigned long origin;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 3/11 mtd: {nand,spi-nor}: assign MTD of_node
In reply to Brian NorrisWe should pass along our flash DT node to the MTD layer, so it can set up ofpart for us.
---
v2: split out of the previous patch
drivers/mtd/nand/nand_base.c | 3 +++ drivers/mtd/spi-nor/spi-nor.c | 1 + 2 files changed, 4 insertions(+)
drivers/mtd/nand/nand_base.c +3 -0
@@ -3990,6 +3990,9 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,int ret;if (chip->flash_node) { +/* MTD can automatically handle DT partitions, etc. */ +mtd_set_of_node (mtd, chip->flash_node); + ret =nand_dt_init (mtd, chip, chip->flash_node);if (ret)return ret;
drivers/mtd/spi-nor/spi-nor.c +1 -0
@@ -1258,6 +1258,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) mtd->flags |=MTD_NO_ERASE ; mtd->dev.parent = dev; +mtd_set_of_node (mtd, np); nor->page_size = info->page_size; mtd->writebufsize = nor->page_size;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 4/11 mtd: nand: convert to nand_set_flash_node()
In reply to Brian NorrisUsed semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':
---8<----
virtual patch
@@
struct nand_chip *c;
struct device_node *d;
@@
-(c)->flash_node = (d)
+nand_set_flash_node(c, d)
---8<----
---
v2: new
drivers/mtd/nand/brcmnand/brcmnand.c | 2 +- drivers/mtd/nand/fsmc_nand.c | 2 +- drivers/mtd/nand/sunxi_nand.c | 2 +- drivers/mtd/nand/vf610_nfc.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +1 -1
@@ -1925,7 +1925,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host) mtd = &host->mtd; chip = &host->chip; - chip->flash_node = dn; +nand_set_flash_node (chip, dn); chip->priv = host; mtd->priv = chip; mtd->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "brcmnand.%d",
drivers/mtd/nand/fsmc_nand.c +1 -1
@@ -1033,7 +1033,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) nand->options = pdata->options; nand->select_chip = fsmc_select_chip; nand->badblockbits =7 ; - nand->flash_node = np; +nand_set_flash_node (nand, np);if (pdata->width ==FSMC_NAND_BW16 ) nand->options |=NAND_BUSWIDTH_16 ;
drivers/mtd/nand/sunxi_nand.c +1 -1
@@ -1330,7 +1330,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,* in the DT. */ nand->ecc.mode =NAND_ECC_HW ; - nand->flash_node = np; +nand_set_flash_node (nand, np); nand->select_chip = sunxi_nfc_select_chip; nand->cmd_ctrl = sunxi_nfc_cmd_ctrl; nand->read_buf = sunxi_nfc_read_buf;
drivers/mtd/nand/vf610_nfc.c +1 -1
@@ -714,7 +714,7 @@ static int vf610_nfc_probe(struct platform_device *pdev) goto error; } - chip->flash_node = child; +nand_set_flash_node (chip, child); } }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Re: [PATCH v2 04/11] mtd: nand: convert to nand_set_flash_node()
Quoted 13 lines · Brian Norris
Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':
---8<----
virtual patch@@
structnand_chip*c;
structdevice_node*d;
@@(quoted diff) +1
-2-(c)->flash_node = (d) +nand_set_flash_node(c, d) ---8<----
Quoted 1 line
Signed-off-by Brian Norris <[email protected]>
Thanks for the educational commit message!
Patch is
Best regards,
Marek Vasut
PATCH v2 5/11 mtd: spi-nor: convert to spi_nor_{get,set}_flash_node()
In reply to Brian NorrisUsed semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':
---8<----
virtual patch
@@
struct spi_nor b;
struct spi_nor *c;
expression d;
@@
(
-(b).flash_node = (d)
+spi_nor_set_flash_node(&b, d)
|
-(c)->flash_node = (d)
+spi_nor_set_flash_node(c, d)
)
---8<----
And a manual conversion for the one use of spi_nor_get_flash_node().
---
v2: new
drivers/mtd/devices/m25p80.c | 2 +- drivers/mtd/spi-nor/fsl-quadspi.c | 2 +- drivers/mtd/spi-nor/nxp-spifi.c | 2 +- drivers/mtd/spi-nor/spi-nor.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/mtd/devices/m25p80.c +1 -1
@@ -199,7 +199,7 @@ static int m25p_probe(struct spi_device *spi) nor->read_reg = m25p80_read_reg; nor->dev = &spi->dev; - nor->flash_node = spi->dev.of_node; +spi_nor_set_flash_node (nor, spi->dev.of_node); nor->priv = flash;spi_set_drvdata (spi, flash);
drivers/mtd/spi-nor/fsl-quadspi.c +1 -1
@@ -1013,7 +1013,7 @@ static int fsl_qspi_probe(struct platform_device *pdev) mtd = &nor->mtd; nor->dev = dev; - nor->flash_node = np; +spi_nor_set_flash_node (nor, np); nor->priv = q;/* fill the hooks */
drivers/mtd/spi-nor/nxp-spifi.c +1 -1
@@ -330,7 +330,7 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi,writel (ctrl, spifi->io_base +SPIFI_CTRL ); spifi->nor.dev = spifi->dev; - spifi->nor.flash_node = np; +spi_nor_set_flash_node (&spifi->nor, np); spifi->nor.priv = spifi; spifi->nor.read = nxp_spifi_read; spifi->nor.write = nxp_spifi_write;
drivers/mtd/spi-nor/spi-nor.c +1 -1
@@ -1151,7 +1151,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)const struct flash_info *info =NULL ;struct device *dev = nor->dev;struct mtd_info *mtd = &nor->mtd; -struct device_node *np = nor->flash_node; +struct device_node *np =spi_nor_get_flash_node (nor);int ret;int i;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 6/11 mtd: nand: drop unnecessary partition parser data
In reply to Brian NorrisAll of these drivers set up a parser data struct just to communicate DT partition data. This field has been deprecated and is instead supported by telling nand_scan_ident() about the 'flash_node'.
This patch:
* sets chip->flash_node for those drivers that didn't already (but used OF partitioning)
* drops the parser data
* switches to the simpler mtd_device_register() where possible, now that we've eliminated one of the auxiliary parameters
Now that we've assigned chip->flash_node for these drivers, we can probably rely on nand_dt_init() to do more of the DT parsing for us, but for now, I don't want to fiddle with each of these drivers. The parsing is done in duplicate for now on some drivers. I don't think this should break things. (Famous last words.)
---
v2: fix compile errors, use new helpers to set the DT node
drivers/mtd/nand/atmel_nand.c | 7 +++---- drivers/mtd/nand/brcmnand/brcmnand.c | 3 +-- drivers/mtd/nand/davinci_nand.c | 10 +++------- drivers/mtd/nand/fsl_elbc_nand.c | 5 ++--- drivers/mtd/nand/fsl_ifc_nand.c | 5 ++--- drivers/mtd/nand/fsl_upm.c | 5 ++--- drivers/mtd/nand/fsmc_nand.c | 7 +++---- drivers/mtd/nand/gpio.c | 8 +++----- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 5 ++--- drivers/mtd/nand/hisi504_nand.c | 5 ++--- drivers/mtd/nand/lpc32xx_mlc.c | 7 +++---- drivers/mtd/nand/lpc32xx_slc.c | 7 +++---- drivers/mtd/nand/mpc5121_nfc.c | 5 ++--- drivers/mtd/nand/mxc_nand.c | 5 ++--- drivers/mtd/nand/ndfc.c | 5 ++--- drivers/mtd/nand/omap2.c | 6 ++---- drivers/mtd/nand/orion_nand.c | 6 ++---- drivers/mtd/nand/plat_nand.c | 5 ++--- drivers/mtd/nand/pxa3xx_nand.c | 10 +++++----- drivers/mtd/nand/sh_flctl.c | 6 ++---- drivers/mtd/nand/socrates_nand.c | 5 ++--- drivers/mtd/nand/sunxi_nand.c | 4 +--- drivers/mtd/nand/vf610_nfc.c | 6 +----- drivers/staging/mt29f_spinand/mt29f_spinand.c | 5 ++--- 24 files changed, 54 insertions(+), 88 deletions(-)
drivers/mtd/nand/atmel_nand.c +3 -4
@@ -2093,7 +2093,6 @@ static int atmel_nand_probe(struct platform_device *pdev)struct mtd_info *mtd;struct nand_chip *nand_chip;struct resource *mem; -struct mtd_part_parser_data ppdata = {};int res, irq;/* Allocate memory for the device structure (and zero it) */
@@ -2117,6 +2116,7 @@ static int atmel_nand_probe(struct platform_device *pdev) nand_chip = &host->nand_chip; host->dev = &pdev->dev;if (IS_ENABLED (CONFIG_OF ) && pdev->dev.of_node) { +nand_set_flash_node (nand_chip, pdev->dev.of_node);/* Only when CONFIG_OF is enabled of_node can be parsed */ res =atmel_of_init_port (host, pdev->dev.of_node);if (res)
@@ -2259,9 +2259,8 @@ static int atmel_nand_probe(struct platform_device *pdev) } mtd->name ="atmel_nand" ; - ppdata.of_node = pdev->dev.of_node; - res =mtd_device_parse_register (mtd,NULL , &ppdata, - host->board.parts, host->board.num_parts); + res =mtd_device_register (mtd, host->board.parts, + host->board.num_parts);if (!res)return res;
drivers/mtd/nand/brcmnand/brcmnand.c +1 -2
@@ -1914,7 +1914,6 @@ static int brcmnand_init_cs(struct brcmnand_host *host)struct nand_chip *chip;int ret;u16 cfg_offs; -struct mtd_part_parser_data ppdata = { .of_node = dn }; ret =of_property_read_u32 (dn,"reg" , &host->cs);if (ret) {
@@ -1993,7 +1992,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host)if (nand_scan_tail (mtd))return -ENXIO ; -return mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); +return mtd_device_register (mtd,NULL ,0 ); } static void brcmnand_save_restore_cs_config(struct brcmnand_host *host,
drivers/mtd/nand/davinci_nand.c +3 -7
@@ -684,6 +684,7 @@ static int nand_davinci_probe(struct platform_device *pdev) info->mtd.priv = &info->chip; info->mtd.dev.parent = &pdev->dev; +nand_set_flash_node (&info->chip, pdev->dev.of_node); info->chip.IO_ADDR_R = vaddr; info->chip.IO_ADDR_W = vaddr;
@@ -839,13 +840,8 @@ syndrome_done:if (pdata->parts) ret =mtd_device_parse_register (&info->mtd,NULL ,NULL , pdata->parts, pdata->nr_parts); -else { -struct mtd_part_parser_data ppdata; - - ppdata.of_node = pdev->dev.of_node; - ret =mtd_device_parse_register (&info->mtd,NULL , &ppdata, -NULL ,0 ); - } +else + ret =mtd_device_register (&info->mtd,NULL ,0 );if (ret <0 ) goto err;
drivers/mtd/nand/fsl_elbc_nand.c +2 -3
@@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)/* Fill in fsl_elbc_mtd structure */ priv->mtd.priv = chip; priv->mtd.dev.parent = priv->dev; + chip->flash_node = priv->dev->of_node;/* set timeout to maximum */ priv->fmr =15 <<FMR_CWTO_SHIFT ;
@@ -823,9 +824,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)int bank;struct device *dev;struct device_node *node = pdev->dev.of_node; -struct mtd_part_parser_data ppdata; - ppdata.of_node = pdev->dev.of_node;if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs)return -ENODEV ; lbc = fsl_lbc_ctrl_dev->regs;
@@ -911,7 +910,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)/* First look for RedBoot table or partitions on the command * line, these take precedence over device tree information */ -mtd_device_parse_register (&priv->mtd, part_probe_types, &ppdata, +mtd_device_parse_register (&priv->mtd, part_probe_types,NULL ,NULL ,0 ); printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n",
drivers/mtd/nand/fsl_ifc_nand.c +2 -3
@@ -883,6 +883,7 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)/* Fill in fsl_ifc_mtd structure */ priv->mtd.priv = chip; priv->mtd.dev.parent = priv->dev; + chip->flash_node = priv->dev->of_node;/* fill in nand_chip structure */ /* set up function call table */
@@ -1030,9 +1031,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)int ret;int bank;struct device_node *node = dev->dev.of_node; -struct mtd_part_parser_data ppdata; - ppdata.of_node = dev->dev.of_node;if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->regs)return -ENODEV ; ifc = fsl_ifc_ctrl_dev->regs;
@@ -1128,7 +1127,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)/* First look for RedBoot table or partitions on the command * line, these take precedence over device tree information */ -mtd_device_parse_register (&priv->mtd, part_probe_types, &ppdata, +mtd_device_parse_register (&priv->mtd, part_probe_types,NULL ,NULL ,0 ); dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
drivers/mtd/nand/fsl_upm.c +2 -3
@@ -159,7 +159,6 @@ static int fun_chip_init(struct fsl_upm_nand *fun, {int ret;struct device_node *flash_np; -struct mtd_part_parser_data ppdata; fun->chip.IO_ADDR_R = fun->io_base; fun->chip.IO_ADDR_W = fun->io_base;
@@ -182,6 +181,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,if (!flash_np)return -ENODEV ; + fun->chip.flash_node = flash_np; fun->mtd.name =kasprintf (GFP_KERNEL ,"0x%llx.%s" , (u64 )io_res->start, flash_np->name);if (!fun->mtd.name) {
@@ -193,8 +193,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,if (ret) goto err; - ppdata.of_node = flash_np; - ret =mtd_device_parse_register (&fun->mtd,NULL , &ppdata,NULL ,0 ); + ret =mtd_device_register (&fun->mtd,NULL ,0 ); err:of_node_put (flash_np);if (ret)
drivers/mtd/nand/fsmc_nand.c +3 -4
@@ -926,7 +926,6 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) {struct fsmc_nand_platform_data *pdata =dev_get_platdata (&pdev->dev);struct device_node __maybe_unused *np = pdev->dev.of_node; -struct mtd_part_parser_data ppdata = {};struct fsmc_nand_data *host;struct mtd_info *mtd;struct nand_chip *nand;
@@ -1016,6 +1015,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) nand = &host->nand; mtd->priv = nand; nand->priv = host; +nand_set_flash_node (nand, np); host->mtd.dev.parent = &pdev->dev; nand->IO_ADDR_R = host->data_va;
@@ -1175,9 +1175,8 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)* Check for partition info passed */ host->mtd.name ="nand" ; - ppdata.of_node = np; - ret =mtd_device_parse_register (&host->mtd,NULL , &ppdata, - host->partitions, host->nr_partitions); + ret =mtd_device_register (&host->mtd, host->partitions, + host->nr_partitions);if (ret) goto err_probe;
drivers/mtd/nand/gpio.c +3 -5
@@ -209,7 +209,6 @@ static int gpio_nand_probe(struct platform_device *pdev)struct gpiomtd *gpiomtd;struct nand_chip *chip;struct resource *res; -struct mtd_part_parser_data ppdata = {};int ret =0 ;if (!pdev->dev.of_node && !dev_get_platdata (&pdev->dev))
@@ -268,6 +267,7 @@ static int gpio_nand_probe(struct platform_device *pdev) chip->dev_ready = gpio_nand_devready; } + chip->flash_node = pdev->dev.of_node; chip->IO_ADDR_W = chip->IO_ADDR_R; chip->ecc.mode =NAND_ECC_SOFT ; chip->options = gpiomtd->plat.options;
@@ -291,10 +291,8 @@ static int gpio_nand_probe(struct platform_device *pdev) gpiomtd->plat.adjust_parts (&gpiomtd->plat, gpiomtd->mtd_info.size); - ppdata.of_node = pdev->dev.of_node; - ret =mtd_device_parse_register (&gpiomtd->mtd_info,NULL , &ppdata, - gpiomtd->plat.parts, - gpiomtd->plat.num_parts); + ret =mtd_device_register (&gpiomtd->mtd_info, gpiomtd->plat.parts, + gpiomtd->plat.num_parts);if (!ret)return 0 ;
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +2 -3
@@ -1888,7 +1888,6 @@ static int gpmi_nand_init(struct gpmi_nand_data *this) {struct mtd_info *mtd = &this->mtd;struct nand_chip *chip = &this->nand; -struct mtd_part_parser_data ppdata = {};int ret;/* init current chip */
@@ -1901,6 +1900,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)/* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */ chip->priv = this; + chip->flash_node = this->pdev->dev.of_node; chip->select_chip = gpmi_select_chip; chip->cmd_ctrl = gpmi_cmd_ctrl; chip->dev_ready = gpmi_dev_ready;
@@ -1954,8 +1954,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)if (ret) goto err_out; - ppdata.of_node = this->pdev->dev.of_node; - ret =mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); + ret =mtd_device_register (mtd,NULL ,0 );if (ret) goto err_out;return 0 ;
drivers/mtd/nand/hisi504_nand.c +2 -3
@@ -704,7 +704,6 @@ static int hisi_nfc_probe(struct platform_device *pdev)struct mtd_info *mtd;struct resource *res;struct device_node *np = dev->of_node; -struct mtd_part_parser_data ppdata; host =devm_kzalloc (dev,sizeof (*host),GFP_KERNEL );if (!host)
@@ -742,6 +741,7 @@ static int hisi_nfc_probe(struct platform_device *pdev) mtd->dev.parent = &pdev->dev; chip->priv = host; +nand_set_flash_node (chip, np); chip->cmdfunc = hisi_nfc_cmdfunc; chip->select_chip = hisi_nfc_select_chip; chip->read_byte = hisi_nfc_read_byte;
@@ -805,8 +805,7 @@ static int hisi_nfc_probe(struct platform_device *pdev) goto err_res; } - ppdata.of_node = np; - ret =mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); + ret =mtd_device_register (mtd,NULL ,0 );if (ret) {dev_err (dev,"Err MTD partition=%d\n" , ret); goto err_mtd;
drivers/mtd/nand/lpc32xx_mlc.c +3 -4
@@ -647,7 +647,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)struct nand_chip *nand_chip;struct resource *rc;int res; -struct mtd_part_parser_data ppdata = {};/* Allocate memory for the device structure (and zero it) */ host =devm_kzalloc (&pdev->dev,sizeof (*host),GFP_KERNEL );
@@ -682,6 +681,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) host->pdata =dev_get_platdata (&pdev->dev); nand_chip->priv = host;/* link the private data structures */ + nand_chip->flash_node = pdev->dev.of_node; mtd->priv = nand_chip; mtd->dev.parent = &pdev->dev;
@@ -786,9 +786,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) mtd->name =DRV_NAME ; - ppdata.of_node = pdev->dev.of_node; - res =mtd_device_parse_register (mtd,NULL , &ppdata, host->ncfg->parts, - host->ncfg->num_parts); + res =mtd_device_register (mtd, host->ncfg->parts, + host->ncfg->num_parts);if (!res)return res;
drivers/mtd/nand/lpc32xx_slc.c +3 -4
@@ -763,7 +763,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)struct mtd_info *mtd;struct nand_chip *chip;struct resource *rc; -struct mtd_part_parser_data ppdata = {};int res; rc =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
@@ -803,6 +802,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) mtd = &host->mtd; chip = &host->nand_chip; chip->priv = host; + chip->flash_node = pdev->dev.of_node; mtd->priv = chip; mtd->owner =THIS_MODULE ; mtd->dev.parent = &pdev->dev;
@@ -908,9 +908,8 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) } mtd->name ="nxp_lpc3220_slc" ; - ppdata.of_node = pdev->dev.of_node; - res =mtd_device_parse_register (mtd,NULL , &ppdata, host->ncfg->parts, - host->ncfg->num_parts); + res =mtd_device_register (mtd, host->ncfg->parts, + host->ncfg->num_parts);if (!res)return res;
drivers/mtd/nand/mpc5121_nfc.c +2 -3
@@ -639,7 +639,6 @@ static int mpc5121_nfc_probe(struct platform_device *op)int resettime =0 ;int retval =0 ;int rev, len; -struct mtd_part_parser_data ppdata;/* * Check SoC revision. This driver supports only NFC
@@ -661,6 +660,7 @@ static int mpc5121_nfc_probe(struct platform_device *op) mtd->priv = chip; mtd->dev.parent = dev; chip->priv = prv; +nand_set_flash_node (chip, dn); prv->dev = dev;/* Read NFC configuration from Reset Config Word */
@@ -703,7 +703,6 @@ static int mpc5121_nfc_probe(struct platform_device *op) } mtd->name ="MPC5121 NAND" ; - ppdata.of_node = dn; chip->dev_ready = mpc5121_nfc_dev_ready; chip->cmdfunc = mpc5121_nfc_command; chip->read_byte = mpc5121_nfc_read_byte;
@@ -815,7 +814,7 @@ static int mpc5121_nfc_probe(struct platform_device *op)dev_set_drvdata (dev, mtd);/* Register device in MTD */ - retval =mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); + retval =mtd_device_register (mtd,NULL ,0 );if (retval) {dev_err (dev,"Error adding MTD device!\n" ); goto error;
drivers/mtd/nand/mxc_nand.c +2 -3
@@ -1524,6 +1524,7 @@ static int mxcnd_probe(struct platform_device *pdev) this->chip_delay =5 ; this->priv = host; + this->flash_node = pdev->dev.of_node, this->dev_ready = mxc_nand_dev_ready; this->cmdfunc = mxc_nand_command; this->read_byte = mxc_nand_read_byte;
@@ -1683,9 +1684,7 @@ static int mxcnd_probe(struct platform_device *pdev)/* Register the partitions */ mtd_device_parse_register (mtd, part_probes, - &(struct mtd_part_parser_data ){ - .of_node = pdev->dev.of_node, - }, +NULL , host->pdata.parts, host->pdata.nr_parts);
drivers/mtd/nand/ndfc.c +2 -3
@@ -147,7 +147,6 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc, {struct device_node *flash_np;struct nand_chip *chip = &ndfc->chip; -struct mtd_part_parser_data ppdata;int ret; chip->IO_ADDR_R = ndfc->ndfcbase +NDFC_DATA ;
@@ -174,8 +173,8 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc, flash_np =of_get_next_child (node,NULL );if (!flash_np)return -ENODEV ; +nand_set_flash_node (chip, flash_np); - ppdata.of_node = flash_np; ndfc->mtd.name =kasprintf (GFP_KERNEL ,"%s.%s" ,dev_name (&ndfc->ofdev->dev), flash_np->name);if (!ndfc->mtd.name) {
@@ -187,7 +186,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,if (ret) goto err; - ret =mtd_device_parse_register (&ndfc->mtd,NULL , &ppdata,NULL ,0 ); + ret =mtd_device_register (&ndfc->mtd,NULL ,0 ); err:of_node_put (flash_np);
drivers/mtd/nand/omap2.c +2 -4
@@ -1663,7 +1663,6 @@ static int omap_nand_probe(struct platform_device *pdev)unsigned sig;unsigned oob_index;struct resource *res; -struct mtd_part_parser_data ppdata = {}; pdata =dev_get_platdata (&pdev->dev);if (pdata ==NULL ) {
@@ -1688,6 +1687,7 @@ static int omap_nand_probe(struct platform_device *pdev) mtd->dev.parent = &pdev->dev; nand_chip = &info->nand; nand_chip->ecc.priv =NULL ; + nand_chip->flash_node = pdata->of_node; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); nand_chip->IO_ADDR_R =devm_ioremap_resource (&pdev->dev, res);
@@ -2037,9 +2037,7 @@ scan_tail: goto return_error; } - ppdata.of_node = pdata->of_node; -mtd_device_parse_register (mtd,NULL , &ppdata, pdata->parts, - pdata->nr_parts); +mtd_device_register (mtd, pdata->parts, pdata->nr_parts);platform_set_drvdata (pdev, mtd);
drivers/mtd/nand/orion_nand.c +2 -4
@@ -76,7 +76,6 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)static int __init orion_nand_probe (struct platform_device *pdev) {struct mtd_info *mtd; -struct mtd_part_parser_data ppdata = {};struct nand_chip *nc;struct orion_nand_data *board;struct resource *res;
@@ -127,6 +126,7 @@ static int __init orion_nand_probe(struct platform_device *pdev) mtd->dev.parent = &pdev->dev; nc->priv = board; + nc->flash_node = pdev->dev.of_node; nc->IO_ADDR_R = nc->IO_ADDR_W = io_base; nc->cmd_ctrl = orion_nand_cmd_ctrl; nc->read_buf = orion_nand_read_buf;
@@ -161,9 +161,7 @@ static int __init orion_nand_probe(struct platform_device *pdev) } mtd->name ="orion_nand" ; - ppdata.of_node = pdev->dev.of_node; - ret =mtd_device_parse_register (mtd,NULL , &ppdata, - board->parts, board->nr_parts); + ret =mtd_device_register (mtd, board->parts, board->nr_parts);if (ret) {nand_release (mtd); goto no_dev;
drivers/mtd/nand/plat_nand.c +2 -3
@@ -30,7 +30,6 @@ struct plat_nand_data {static int plat_nand_probe (struct platform_device *pdev) {struct platform_nand_data *pdata =dev_get_platdata (&pdev->dev); -struct mtd_part_parser_data ppdata;struct plat_nand_data *data;struct resource *res;const char **part_types;
@@ -58,6 +57,7 @@ static int plat_nand_probe(struct platform_device *pdev)return PTR_ERR (data->io_base); data->chip.priv = &data; + data->chip.flash_node = pdev->dev.of_node; data->mtd.priv = &data->chip; data->mtd.dev.parent = &pdev->dev;
@@ -94,8 +94,7 @@ static int plat_nand_probe(struct platform_device *pdev) part_types = pdata->chip.part_probe_types; - ppdata.of_node = pdev->dev.of_node; - err =mtd_device_parse_register (&data->mtd, part_types, &ppdata, + err =mtd_device_parse_register (&data->mtd, part_types,NULL , pdata->chip.partitions, pdata->chip.nr_partitions);
drivers/mtd/nand/pxa3xx_nand.c +5 -5
@@ -1697,6 +1697,7 @@ KEEP_CONFIG:static int alloc_nand_resource (struct platform_device *pdev) { +struct device_node *np = pdev->dev.of_node;struct pxa3xx_nand_platform_data *pdata;struct pxa3xx_nand_info *info;struct pxa3xx_nand_host *host;
@@ -1725,6 +1726,8 @@ static int alloc_nand_resource(struct platform_device *pdev) host->info_data = info; mtd->priv = host; mtd->dev.parent = &pdev->dev; +/* FIXME: all chips use the same device tree partitions */ +nand_set_flash_node (chip, np); chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; chip->ecc.write_page = pxa3xx_nand_write_page_hwecc;
@@ -1886,7 +1889,6 @@ static int pxa3xx_nand_probe_dt(struct platform_device *pdev)static int pxa3xx_nand_probe (struct platform_device *pdev) {struct pxa3xx_nand_platform_data *pdata; -struct mtd_part_parser_data ppdata = {};struct pxa3xx_nand_info *info;int ret, cs, probe_success, dma_available;
@@ -1933,10 +1935,8 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)continue ; } - ppdata.of_node = pdev->dev.of_node; - ret =mtd_device_parse_register (mtd,NULL , - &ppdata, pdata->parts[cs], - pdata->nr_parts[cs]); + ret =mtd_device_register (mtd, pdata->parts[cs], + pdata->nr_parts[cs]);if (!ret) probe_success =1 ; }
drivers/mtd/nand/sh_flctl.c +2 -4
@@ -1086,7 +1086,6 @@ static int flctl_probe(struct platform_device *pdev)struct sh_flctl_platform_data *pdata;int ret;int irq; -struct mtd_part_parser_data ppdata = {}; flctl =devm_kzalloc (&pdev->dev,sizeof (struct sh_flctl ),GFP_KERNEL );if (!flctl)
@@ -1123,6 +1122,7 @@ static int flctl_probe(struct platform_device *pdev)platform_set_drvdata (pdev, flctl); flctl_mtd = &flctl->mtd; nand = &flctl->chip; + nand->flash_node = pdev->dev.of_node; flctl_mtd->priv = nand; flctl_mtd->dev.parent = &pdev->dev; flctl->pdev = pdev;
@@ -1163,9 +1163,7 @@ static int flctl_probe(struct platform_device *pdev)if (ret) goto err_chip; - ppdata.of_node = pdev->dev.of_node; - ret =mtd_device_parse_register (flctl_mtd,NULL , &ppdata, pdata->parts, - pdata->nr_parts); + ret =mtd_device_register (flctl_mtd, pdata->parts, pdata->nr_parts);return 0 ;
drivers/mtd/nand/socrates_nand.c +2 -3
@@ -147,7 +147,6 @@ static int socrates_nand_probe(struct platform_device *ofdev)struct mtd_info *mtd;struct nand_chip *nand_chip;int res; -struct mtd_part_parser_data ppdata;/* Allocate memory for the device structure (and zero it) */ host =devm_kzalloc (&ofdev->dev,sizeof (*host),GFP_KERNEL );
@@ -165,10 +164,10 @@ static int socrates_nand_probe(struct platform_device *ofdev) host->dev = &ofdev->dev; nand_chip->priv = host;/* link the private data structures */ + nand_chip->flash_node = ofdev->dev.of_node; mtd->priv = nand_chip; mtd->name ="socrates_nand" ; mtd->dev.parent = &ofdev->dev; - ppdata.of_node = ofdev->dev.of_node;/*should never be accessed directly */ nand_chip->IO_ADDR_R = (void *)0xdeadbeef ;
@@ -200,7 +199,7 @@ static int socrates_nand_probe(struct platform_device *ofdev) goto out; } - res =mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); + res =mtd_device_register (mtd,NULL ,0 );if (!res)return res;
drivers/mtd/nand/sunxi_nand.c +1 -3
@@ -1232,7 +1232,6 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, {const struct nand_sdr_timings *timings;struct sunxi_nand_chip *chip; -struct mtd_part_parser_data ppdata;struct mtd_info *mtd;struct nand_chip *nand;int nsels;
@@ -1366,8 +1365,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,return ret; } - ppdata.of_node = np; - ret =mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); + ret =mtd_device_register (mtd,NULL ,0 );if (ret) {dev_err (dev,"failed to register mtd device: %d\n" , ret);nand_release (mtd);
drivers/mtd/nand/vf610_nfc.c +1 -5
@@ -811,11 +811,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, mtd);/* Register device in MTD */ -return mtd_device_parse_register (mtd,NULL , - &(struct mtd_part_parser_data ){ - .of_node = chip->flash_node, - }, -NULL ,0 ); +return mtd_device_register (mtd,NULL ,0 ); error:of_node_put (chip->flash_node);
drivers/staging/mt29f_spinand/mt29f_spinand.c +2 -3
@@ -853,7 +853,6 @@ static int spinand_probe(struct spi_device *spi_nand)struct nand_chip *chip;struct spinand_info *info;struct spinand_state *state; -struct mtd_part_parser_data ppdata; info =devm_kzalloc (&spi_nand->dev,sizeof (struct spinand_info ),GFP_KERNEL );
@@ -897,6 +896,7 @@ static int spinand_probe(struct spi_device *spi_nand)pr_info ("%s: disable ecc failed!\n" , __func__);#endif + chip->flash_node = spi_nand->dev.of_node; chip->priv = info; chip->read_buf = spinand_read_buf; chip->write_buf = spinand_write_buf;
@@ -919,8 +919,7 @@ static int spinand_probe(struct spi_device *spi_nand)if (nand_scan (mtd,1 ))return -ENXIO ; - ppdata.of_node = spi_nand->dev.of_node; -return mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); +return mtd_device_register (mtd,NULL ,0 ); }/*
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data
Quoted 134 lines · On Fri, 30 Oct 2015 20:33:25 -0700 Brian Norris <[email protected]>…
All of these drivers set up a parser data struct just to communicate DT partition data. This field has been deprecated and is instead supported by telling
nand_scan_ident()about the 'flash_node'.This patch:
* setschip->flash_nodefor those drivers that didn't already (but used OF partitioning)
* drops the parser data
* switches to the simplermtd_device_register()where possible, now that we've eliminated one of the auxiliary parametersNow that we've assigned
chip->flash_nodefor these drivers, we can probably rely onnand_dt_init()to do more of the DT parsing for us, but for now, I don't want to fiddle with each of these drivers. The parsing is done in duplicate for now on some drivers. I don't think this should break things. (Famous last words.)Signed-off-by Brian Norris <[email protected]>Acked-by Boris Brezillon <[email protected]>---
v2: fix compile errors, use new helpers to set the DT nodedrivers/mtd/nand/atmel_nand.c | 7 +++---- drivers/mtd/nand/brcmnand/brcmnand.c | 3 +-- drivers/mtd/nand/davinci_nand.c | 10 +++------- drivers/mtd/nand/fsl_elbc_nand.c | 5 ++--- drivers/mtd/nand/fsl_ifc_nand.c | 5 ++--- drivers/mtd/nand/fsl_upm.c | 5 ++--- drivers/mtd/nand/fsmc_nand.c | 7 +++---- drivers/mtd/nand/gpio.c | 8 +++----- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 5 ++--- drivers/mtd/nand/hisi504_nand.c | 5 ++--- drivers/mtd/nand/lpc32xx_mlc.c | 7 +++---- drivers/mtd/nand/lpc32xx_slc.c | 7 +++---- drivers/mtd/nand/mpc5121_nfc.c | 5 ++--- drivers/mtd/nand/mxc_nand.c | 5 ++--- drivers/mtd/nand/ndfc.c | 5 ++--- drivers/mtd/nand/omap2.c | 6 ++---- drivers/mtd/nand/orion_nand.c | 6 ++---- drivers/mtd/nand/plat_nand.c | 5 ++--- drivers/mtd/nand/pxa3xx_nand.c | 10 +++++----- drivers/mtd/nand/sh_flctl.c | 6 ++---- drivers/mtd/nand/socrates_nand.c | 5 ++--- drivers/mtd/nand/sunxi_nand.c | 4 +--- drivers/mtd/nand/vf610_nfc.c | 6 +----- drivers/staging/mt29f_spinand/mt29f_spinand.c | 5 ++--- 24 files changed, 54 insertions(+), 88 deletions(-)drivers/mtd/nand/atmel_nand.c +3
-4@@ -2093,7 +2093,6 @@ static int atmel_nand_probe(struct platform_device *pdev)struct mtd_info *mtd;struct nand_chip *nand_chip;struct resource *mem; -struct mtd_part_parser_data ppdata = {};int res, irq;/* Allocate memory for the device structure (and zero it) */ @@ -2117,6 +2116,7 @@ static int atmel_nand_probe(struct platform_device *pdev) nand_chip = &host->nand_chip; host->dev = &pdev->dev;if (IS_ENABLED (CONFIG_OF ) && pdev->dev.of_node) { +nand_set_flash_node (nand_chip, pdev->dev.of_node);/* Only when CONFIG_OF is enabled of_node can be parsed */ res =atmel_of_init_port (host, pdev->dev.of_node);if (res)@@ -2259,9 +2259,8 @@ static int atmel_nand_probe(struct platform_device *pdev) } mtd->name ="atmel_nand" ; - ppdata.of_node = pdev->dev.of_node; - res =mtd_device_parse_register (mtd,NULL , &ppdata, - host->board.parts, host->board.num_parts); + res =mtd_device_register (mtd, host->board.parts, + host->board.num_parts);if (!res)return res;drivers/mtd/nand/brcmnand/brcmnand.c +1
-2@@ -1914,7 +1914,6 @@ static int brcmnand_init_cs(struct brcmnand_host *host)struct nand_chip *chip;int ret;u16 cfg_offs; -struct mtd_part_parser_data ppdata = { .of_node = dn }; ret =of_property_read_u32 (dn,"reg" , &host->cs);if (ret) {@@ -1993,7 +1992,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host)if (nand_scan_tail (mtd))return -ENXIO ; -return mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); +return mtd_device_register (mtd,NULL ,0 ); } static void brcmnand_save_restore_cs_config(struct brcmnand_host *host,drivers/mtd/nand/davinci_nand.c +3
-7@@ -684,6 +684,7 @@ static int nand_davinci_probe(struct platform_device *pdev) info->mtd.priv = &info->chip; info->mtd.dev.parent = &pdev->dev; +nand_set_flash_node (&info->chip, pdev->dev.of_node); info->chip.IO_ADDR_R = vaddr; info->chip.IO_ADDR_W = vaddr;@@ -839,13 +840,8 @@ syndrome_done:if (pdata->parts) ret =mtd_device_parse_register (&info->mtd,NULL ,NULL , pdata->parts, pdata->nr_parts); -else { -struct mtd_part_parser_data ppdata; - - ppdata.of_node = pdev->dev.of_node; - ret =mtd_device_parse_register (&info->mtd,NULL , &ppdata, -NULL ,0 ); - } +else + ret =mtd_device_register (&info->mtd,NULL ,0 );if (ret <0 ) goto err;drivers/mtd/nand/fsl_elbc_nand.c +0
-0
drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) · line 751
Quoted 4 lines
drivers/mtd/nand/fsl_elbc_nand.c +1
-0@@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)/* Fill in fsl_elbc_mtd structure */ priv->mtd.priv = chip; priv->mtd.dev.parent = priv->dev; + chip->flash_node = priv->dev->of_node;
Shouldn't we use the nand_set_flash_node() helper here? Here is a diff replacing all 'chip->flash_node =' occurrences by nand_set_flash_node():
---->8----
drivers/mtd/nand/fsl_elbc_nand.c +1 -1
@@ -748,7 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)/* Fill in fsl_elbc_mtd structure */ priv->mtd.priv = chip; priv->mtd.dev.parent = priv->dev; - chip->flash_node = priv->dev->of_node; +nand_set_flash_node (chip, priv->dev->of_node);/* set timeout to maximum */ priv->fmr =15 <<FMR_CWTO_SHIFT ;
drivers/mtd/nand/fsl_ifc_nand.c +1 -1
@@ -883,7 +883,7 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)/* Fill in fsl_ifc_mtd structure */ priv->mtd.priv = chip; priv->mtd.dev.parent = priv->dev; - chip->flash_node = priv->dev->of_node; +nand_set_flash_node (chip, priv->dev->of_node);/* fill in nand_chip structure */ /* set up function call table */
drivers/mtd/nand/fsl_upm.c +1 -1
@@ -181,7 +181,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,if (!flash_np)return -ENODEV ; - fun->chip.flash_node = flash_np; +nand_set_flash_node (&fun->chip, flash_np); fun->mtd.name =kasprintf (GFP_KERNEL ,"0x%llx.%s" , (u64 )io_res->start, flash_np->name);if (!fun->mtd.name) {
drivers/mtd/nand/gpio.c +1 -1
@@ -267,7 +267,7 @@ static int gpio_nand_probe(struct platform_device *pdev) chip->dev_ready = gpio_nand_devready; } - chip->flash_node = pdev->dev.of_node; +nand_set_flash_node (chip, pdev->dev.of_node); chip->IO_ADDR_W = chip->IO_ADDR_R; chip->ecc.mode =NAND_ECC_SOFT ; chip->options = gpiomtd->plat.options;
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -1
@@ -1900,7 +1900,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)/* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */ chip->priv = this; - chip->flash_node = this->pdev->dev.of_node; +nand_set_flash_node (chip, this->pdev->dev.of_node); chip->select_chip = gpmi_select_chip; chip->cmd_ctrl = gpmi_cmd_ctrl; chip->dev_ready = gpmi_dev_ready;
drivers/mtd/nand/lpc32xx_mlc.c +1 -1
@@ -681,7 +681,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) host->pdata =dev_get_platdata (&pdev->dev); nand_chip->priv = host;/* link the private data structures */ - nand_chip->flash_node = pdev->dev.of_node; +nand_set_flash_node (nand_chip, pdev->dev.of_node); mtd->priv = nand_chip; mtd->dev.parent = &pdev->dev;
drivers/mtd/nand/lpc32xx_slc.c +1 -1
@@ -802,7 +802,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) mtd = &host->mtd; chip = &host->nand_chip; chip->priv = host; - chip->flash_node = pdev->dev.of_node; +nand_set_flash_node (chip, pdev->dev.of_node); mtd->priv = chip; mtd->owner =THIS_MODULE ; mtd->dev.parent = &pdev->dev;
drivers/mtd/nand/mxc_nand.c +1 -1
@@ -1524,7 +1524,7 @@ static int mxcnd_probe(struct platform_device *pdev) this->chip_delay =5 ; this->priv = host; - this->flash_node = pdev->dev.of_node, +nand_set_flash_node (this, pdev->dev.of_node), this->dev_ready = mxc_nand_dev_ready; this->cmdfunc = mxc_nand_command; this->read_byte = mxc_nand_read_byte;
drivers/mtd/nand/omap2.c +1 -1
@@ -1687,7 +1687,7 @@ static int omap_nand_probe(struct platform_device *pdev) mtd->dev.parent = &pdev->dev; nand_chip = &info->nand; nand_chip->ecc.priv =NULL ; - nand_chip->flash_node = pdata->of_node; +nand_set_flash_node (nand_chip, pdata->of_node); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); nand_chip->IO_ADDR_R =devm_ioremap_resource (&pdev->dev, res);
drivers/mtd/nand/orion_nand.c +1 -1
@@ -126,7 +126,7 @@ static int __init orion_nand_probe(struct platform_device *pdev) mtd->dev.parent = &pdev->dev; nc->priv = board; - nc->flash_node = pdev->dev.of_node; +nand_set_flash_node (nc, pdev->dev.of_node); nc->IO_ADDR_R = nc->IO_ADDR_W = io_base; nc->cmd_ctrl = orion_nand_cmd_ctrl; nc->read_buf = orion_nand_read_buf;
drivers/mtd/nand/plat_nand.c +1 -1
@@ -57,7 +57,7 @@ static int plat_nand_probe(struct platform_device *pdev)return PTR_ERR (data->io_base); data->chip.priv = &data; - data->chip.flash_node = pdev->dev.of_node; +nand_set_flash_node (&data->chip, pdev->dev.of_node); data->mtd.priv = &data->chip; data->mtd.dev.parent = &pdev->dev;
drivers/mtd/nand/sh_flctl.c +1 -1
@@ -1122,7 +1122,7 @@ static int flctl_probe(struct platform_device *pdev)platform_set_drvdata (pdev, flctl); flctl_mtd = &flctl->mtd; nand = &flctl->chip; - nand->flash_node = pdev->dev.of_node; +nand_set_flash_node (nand, pdev->dev.of_node); flctl_mtd->priv = nand; flctl_mtd->dev.parent = &pdev->dev; flctl->pdev = pdev;
drivers/mtd/nand/socrates_nand.c +1 -1
@@ -164,7 +164,7 @@ static int socrates_nand_probe(struct platform_device *ofdev) host->dev = &ofdev->dev; nand_chip->priv = host;/* link the private data structures */ - nand_chip->flash_node = ofdev->dev.of_node; +nand_set_flash_node (nand_chip, ofdev->dev.of_node); mtd->priv = nand_chip; mtd->name ="socrates_nand" ; mtd->dev.parent = &ofdev->dev;
drivers/staging/mt29f_spinand/mt29f_spinand.c +1 -1
@@ -896,7 +896,7 @@ static int spinand_probe(struct spi_device *spi_nand)pr_info ("%s: disable ecc failed!\n" , __func__);#endif - chip->flash_node = spi_nand->dev.of_node; +nand_set_flash_node (chip, spi_nand->dev.of_node); chip->priv = info; chip->read_buf = spinand_read_buf; chip->write_buf = spinand_write_buf;
Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data
Quoted 3 lines · Boris Brezillon
On Fri, 30 Oct 2015 20:33:25 -0700
Brian Norris <[email protected]> wrote:
[...]
Quoted 4 lines
Quoted 4 lines
drivers/mtd/nand/fsl_elbc_nand.c +0
-0
Quoted 8 lines
drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) · line 751
Quoted 5 lines
drivers/mtd/nand/fsl_elbc_nand.c +1
-0@@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)/* Fill in fsl_elbc_mtd structure */ priv->mtd.priv = chip; priv->mtd.dev.parent = priv->dev; + chip->flash_node = priv->dev->of_node;Shouldn't we use the
nand_set_flash_node()helper here? Here is a diff replacing all 'chip->flash_node=' occurrences bynand_set_flash_node():
Hmm, I don't know why I overlooked those. I think maybe I did the initial replacement before this patch and forgot to do the same replacement on my subsequent work. I guess that's what happens when I rebase/rework too much...
Thanks for the diff. I'll probably squash it into v3 if/when that comes.
Brian
Re: [PATCH v2 06/11] mtd: nand: drop unnecessary partition parser data
Quoted 18 lines · Brian Norris
Quoted 3 lines · Boris Brezillon
On Fri, 30 Oct 2015 20:33:25 -0700
Brian Norris <[email protected]> wrote:[...]
Quoted 4 lines
Quoted 4 lines
drivers/mtd/nand/fsl_elbc_nand.c +0
-0Quoted 8 lines
drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) · line 751
Quoted 5 lines
drivers/mtd/nand/fsl_elbc_nand.c +1
-0@@ -748,6 +748,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)/* Fill in fsl_elbc_mtd structure */ priv->mtd.priv = chip; priv->mtd.dev.parent = priv->dev; + chip->flash_node = priv->dev->of_node;Shouldn't we use the
nand_set_flash_node()helper here? Here is a diff replacing all 'chip->flash_node=' occurrences bynand_set_flash_node():
Quoted 6 lines
Hmm, I don't know why I overlooked those. I think maybe I did the initial replacement before this patch and forgot to do the same replacement on my subsequent work. I guess that's what happens when I rebase/rework too much...
Thanks for the diff. I'll probably squash it into v3 if/when that comes.
Pushed my patch 6 + your diff to l2-mtd.git/next. Thanks!
PATCH v2 7/11 mtd: spi-nor: drop unnecessary partition parser data
In reply to Brian NorrisNow that the SPI-NOR/MTD framework pass the 'flash_node' through to the partition parsing code, we don't have to do it ourselves.
Also convert to mtd_device_register(), since we don't need the 2nd and 3rd parameters anymore.
---
v2: no change
drivers/mtd/devices/m25p80.c | 8 ++------ drivers/mtd/spi-nor/fsl-quadspi.c | 4 +--- drivers/mtd/spi-nor/nxp-spifi.c | 4 +--- 3 files changed, 4 insertions(+), 12 deletions(-)
drivers/mtd/devices/m25p80.c +2 -6
@@ -175,7 +175,6 @@ static int m25p80_erase(struct spi_nor *nor, loff_t offset)*/ static int m25p_probe (struct spi_device *spi) { -struct mtd_part_parser_data ppdata;struct flash_platform_data *data;struct m25p *flash;struct spi_nor *nor;
@@ -227,11 +226,8 @@ static int m25p_probe(struct spi_device *spi)if (ret)return ret; - ppdata.of_node = spi->dev.of_node; - -return mtd_device_parse_register (&nor->mtd,NULL , &ppdata, - data ? data->parts :NULL , - data ? data->nr_parts :0 ); +return mtd_device_register (&nor->mtd, data ? data->parts :NULL , + data ? data->nr_parts :0 ); }
drivers/mtd/spi-nor/fsl-quadspi.c +1 -3
@@ -927,7 +927,6 @@ static void fsl_qspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops)static int fsl_qspi_probe (struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node; -struct mtd_part_parser_data ppdata;struct device *dev = &pdev->dev;struct fsl_qspi *q;struct resource *res;
@@ -1038,8 +1037,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)if (ret) goto mutex_failed; - ppdata.of_node = np; - ret =mtd_device_parse_register (mtd,NULL , &ppdata,NULL ,0 ); + ret =mtd_device_register (mtd,NULL ,0 );if (ret) goto mutex_failed;
drivers/mtd/spi-nor/nxp-spifi.c +1 -3
@@ -271,7 +271,6 @@ static void nxp_spifi_dummy_id_read(struct spi_nor *nor)static int nxp_spifi_setup_flash (struct nxp_spifi *spifi,struct device_node *np) { -struct mtd_part_parser_data ppdata;enum read_mode flash_read;u32 ctrl, property;u16 mode =0 ;
@@ -361,8 +360,7 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi,return ret; } - ppdata.of_node = np; - ret =mtd_device_parse_register (&spifi->nor.mtd,NULL , &ppdata,NULL ,0 ); + ret =mtd_device_register (&spifi->nor.mtd,NULL ,0 );if (ret) {dev_err (spifi->dev,"mtd device parse failed\n" );return ret;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 8/11 mtd: spi-nor: drop flash_node field
In reply to Brian NorrisWe can just alias to the MTD of_node.
---
v2: new
drivers/mtd/spi-nor/spi-nor.c | 1 - include/linux/mtd/spi-nor.h | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +0 -1
@@ -1258,7 +1258,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) mtd->flags |=MTD_NO_ERASE ; mtd->dev.parent = dev; -mtd_set_of_node (mtd, np); nor->page_size = info->page_size; mtd->writebufsize = nor->page_size;
include/linux/mtd/spi-nor.h +2 -4
@@ -124,7 +124,6 @@ struct mtd_info;* @mtd: point to a mtd_info structure * @lock: the lock for the read/write/erase/lock/unlock operations * @dev: point to a spi device, or a spi nor controller device. -* @flash_node: point to a device node describing this flash instance. * @page_size: the page size of the SPI NOR * @addr_width: number of address bytes * @erase_opcode: the opcode for erasing a sector
@@ -155,7 +154,6 @@ struct spi_nor {struct mtd_info mtd;struct mutex lock;struct device *dev; -struct device_node *flash_node;u32 page_size;u8 addr_width;u8 erase_opcode;
@@ -188,12 +186,12 @@ struct spi_nor {static inline void spi_nor_set_flash_node (struct spi_nor *nor,struct device_node *np) { - nor->flash_node = np; +mtd_set_of_node (&nor->mtd, np); }static inline struct device_node *spi_nor_get_flash_node (struct spi_nor *nor) { -return nor->flash_node; +return mtd_get_of_node (&nor->mtd); }/**
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 9/11 mtd: drop unnecessary partition parser data
In reply to Brian NorrisWe should assign the MTD dev.of_node instead of the parser data field. This gets us the equivalent partition parser behavior with fewer special fields and parameter passing.
Also convert several of these to mtd_device_register(), since we don't need the 2nd and 3rd parameters anymore.
---
v2: use new helpers
drivers/mtd/devices/mtd_dataflash.c | 5 ++--- drivers/mtd/devices/spear_smi.c | 6 ++---- drivers/mtd/devices/st_spi_fsm.c | 5 ++--- drivers/mtd/maps/lantiq-flash.c | 5 ++--- drivers/mtd/maps/physmap_of.c | 5 ++--- drivers/mtd/onenand/omap2.c | 8 +++----- 6 files changed, 13 insertions(+), 21 deletions(-)
drivers/mtd/devices/mtd_dataflash.c +2 -3
@@ -624,7 +624,6 @@ static int add_dataflash_otp(struct spi_device *spi, char *name, int nr_pages, {struct dataflash *priv;struct mtd_info *device; -struct mtd_part_parser_data ppdata;struct flash_platform_data *pdata =dev_get_platdata (&spi->dev);char *otp_tag ="" ;int err =0 ;
@@ -656,6 +655,7 @@ static int add_dataflash_otp(struct spi_device *spi, char *name, int nr_pages, device->priv = priv; device->dev.parent = &spi->dev; +mtd_set_of_node (device, spi->dev.of_node);if (revision >='c' ) otp_tag =otp_setup (device, revision);
@@ -665,8 +665,7 @@ static int add_dataflash_otp(struct spi_device *spi, char *name, int nr_pages, pagesize, otp_tag);spi_set_drvdata (spi, priv); - ppdata.of_node = spi->dev.of_node; - err =mtd_device_parse_register (device,NULL , &ppdata, + err =mtd_device_register (device, pdata ? pdata->parts :NULL , pdata ? pdata->nr_parts :0 );
drivers/mtd/devices/spear_smi.c +2 -4
@@ -810,7 +810,6 @@ static int spear_smi_setup_banks(struct platform_device *pdev, u32 bank, struct device_node *np) { struct spear_smi *dev = platform_get_drvdata(pdev); -struct mtd_part_parser_data ppdata = {};struct spear_smi_flash_info *flash_info;struct spear_smi_plat_data *pdata;struct spear_snor_flash *flash;
@@ -855,6 +854,7 @@ static int spear_smi_setup_banks(struct platform_device *pdev, flash->mtd.name = flash_devices[flash_index].name; flash->mtd.dev.parent = &pdev->dev; +mtd_set_of_node (&flash->mtd, np); flash->mtd.type =MTD_NORFLASH ; flash->mtd.writesize =1 ; flash->mtd.flags =MTD_CAP_NORFLASH ;
@@ -881,10 +881,8 @@ static int spear_smi_setup_banks(struct platform_device *pdev, count = flash_info->nr_partitions; }#endif - ppdata.of_node = np; - ret =mtd_device_parse_register (&flash->mtd,NULL , &ppdata, parts, - count); + ret =mtd_device_register (&flash->mtd, parts, count);if (ret) {dev_err (&dev->pdev->dev,"Err MTD partition=%d\n" , ret);return ret;
drivers/mtd/devices/st_spi_fsm.c +2 -3
@@ -2025,7 +2025,6 @@ boot_device_fail:static int stfsm_probe (struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node; -struct mtd_part_parser_data ppdata;struct flash_info *info;struct resource *res;struct stfsm *fsm;
@@ -2035,7 +2034,6 @@ static int stfsm_probe(struct platform_device *pdev)dev_err (&pdev->dev,"No DT found\n" );return -EINVAL ; } - ppdata.of_node = np; fsm =devm_kzalloc (&pdev->dev,sizeof (*fsm),GFP_KERNEL );if (!fsm)
@@ -2106,6 +2104,7 @@ static int stfsm_probe(struct platform_device *pdev) fsm->mtd.name = info->name; fsm->mtd.dev.parent = &pdev->dev; +mtd_set_of_node (&fsm->mtd, np); fsm->mtd.type =MTD_NORFLASH ; fsm->mtd.writesize =4 ; fsm->mtd.writebufsize = fsm->mtd.writesize;
@@ -2124,7 +2123,7 @@ static int stfsm_probe(struct platform_device *pdev) (long long )fsm->mtd.size, (long long )(fsm->mtd.size >>20 ), fsm->mtd.erasesize, (fsm->mtd.erasesize >> 10)); -return mtd_device_parse_register (&fsm->mtd,NULL , &ppdata,NULL ,0 ); +return mtd_device_register (&fsm->mtd,NULL ,0 ); }static int stfsm_remove (struct platform_device *pdev)
drivers/mtd/maps/lantiq-flash.c +2 -3
@@ -110,7 +110,6 @@ ltq_copy_to(struct map_info *map, unsigned long to,static int ltq_mtd_probe (struct platform_device *pdev) { -struct mtd_part_parser_data ppdata;struct ltq_mtd *ltq_mtd;struct cfi_private *cfi;int err;
@@ -161,13 +160,13 @@ ltq_mtd_probe(struct platform_device *pdev) } ltq_mtd->mtd->dev.parent = &pdev->dev; +mtd_set_of_node (<q_mtd->mtd, pdev->dev.of_node); cfi = ltq_mtd->map->fldrv_priv; cfi->addr_unlock1 ^=1 ; cfi->addr_unlock2 ^=1 ; - ppdata.of_node = pdev->dev.of_node; - err =mtd_device_parse_register (ltq_mtd->mtd,NULL , &ppdata,NULL ,0 ); + err =mtd_device_register (ltq_mtd->mtd,NULL ,0 );if (err) {dev_err (&pdev->dev,"failed to add partitions\n" ); goto err_destroy;
drivers/mtd/maps/physmap_of.c +2 -3
@@ -166,7 +166,6 @@ static int of_flash_probe(struct platform_device *dev)int reg_tuple_size;struct mtd_info **mtd_list =NULL ;resource_size_t res_size; -struct mtd_part_parser_data ppdata;bool map_indirect;const char *mtd_name =NULL ;
@@ -310,13 +309,13 @@ static int of_flash_probe(struct platform_device *dev)if (err) goto err_out; - ppdata.of_node = dp; +mtd_set_of_node (info->cmtd, dp); part_probe_types =of_get_probes (dp);if (!part_probe_types) { err = -ENOMEM ; goto err_out; } -mtd_device_parse_register (info->cmtd, part_probe_types, &ppdata, +mtd_device_parse_register (info->cmtd, part_probe_types,NULL ,NULL ,0 );of_free_probes (part_probe_types);
drivers/mtd/onenand/omap2.c +3 -5
@@ -614,7 +614,6 @@ static int omap2_onenand_probe(struct platform_device *pdev)struct onenand_chip *this;int r;struct resource *res; -struct mtd_part_parser_data ppdata = {}; pdata =dev_get_platdata (&pdev->dev);if (pdata ==NULL ) {
@@ -713,6 +712,7 @@ static int omap2_onenand_probe(struct platform_device *pdev) c->mtd.priv = &c->onenand; c->mtd.dev.parent = &pdev->dev; +mtd_set_of_node (&c->mtd, pdata->of_node); this = &c->onenand;if (c->dma_channel >=0 ) {
@@ -743,10 +743,8 @@ static int omap2_onenand_probe(struct platform_device *pdev)if ((r =onenand_scan (&c->mtd,1 )) <0 ) goto err_release_regulator; - ppdata.of_node = pdata->of_node; - r =mtd_device_parse_register (&c->mtd,NULL , &ppdata, - pdata ? pdata->parts :NULL , - pdata ? pdata->nr_parts :0 ); + r =mtd_device_register (&c->mtd, pdata ? pdata->parts :NULL , + pdata ? pdata->nr_parts :0 );if (r) goto err_release_onenand;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Re: [PATCH v2 09/11] mtd: drop unnecessary partition parser data
Quoted 8 lines · Brian Norris
We should assign the MTD dev.of_node instead of the parser data field. This gets us the equivalent partition parser behavior with fewer special fields and parameter passing.
Also convert several of these to
mtd_device_register(), since we don't need the 2nd and 3rd parameters anymore.Signed-off-by Brian Norris <[email protected]>
[...]
Quoted 15 lines
drivers/mtd/maps/physmap_of.c +0
-1@@ -166,7 +166,6 @@ static int of_flash_probe(struct platform_device *dev)int reg_tuple_size;struct mtd_info **mtd_list =NULL ;resource_size_t res_size; -struct mtd_part_parser_data ppdata;bool map_indirect;const char *mtd_name =NULL ;@@ -310,13 +309,13 @@ static int of_flash_probe(struct platform_device *dev) if (err) goto err_out;
drivers/mtd/maps/physmap_of.c static int of_flash_probe(struct platform_device · line 318
Quoted 10 lines
drivers/mtd/maps/physmap_of.c +2
-2- ppdata.of_node = dp; +mtd_set_of_node (info->cmtd, dp); part_probe_types =of_get_probes (dp);if (!part_probe_types) { err = -ENOMEM ; goto err_out; } - mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata, + mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
Did you miss this one ?
drivers/mtd/maps/physmap_of.c static int of_flash_probe(struct platform_device *dev) · line 321
Quoted 3 lines
drivers/mtd/maps/physmap_of.c +0
-0NULL, 0);of_free_probes (part_probe_types);
This is really good, I like to see the ppdata nonsense finally going away.
Best regards,
Marek Vasut
Re: [PATCH v2 09/11] mtd: drop unnecessary partition parser data
Quoted 5 lines · Marek Vasut
drivers/mtd/maps/physmap_of.c static int of_flash_probe(struct platform_device *dev) · line 318
Quoted 2 lines · Brian Norris
drivers/mtd/maps/physmap_of.c +1
-1- mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata, + mtd_device_parse_register(info->cmtd, part_probe_types, NULL,Did you miss this one ?
What about it? I removed the parser data (the third argument), but I can't yet drop the 2nd argument, since those parser types are different than the defaults. So I can't drop any more arguments, nor can I convert this to mtd_device_register().
(Now, I'd like to improve the device tree handling of parser types, so we don't need any more specialized handling in drivers like this.)
Quoted 8 lines
drivers/mtd/maps/physmap_of.c static int of_flash_probe(struct platform_device *dev) · line 320
Quoted 3 lines
drivers/mtd/maps/physmap_of.c +0
-0NULL, 0);of_free_probes (part_probe_types);This is really good, I like to see the ppdata nonsense finally going away.
Reviewed-by Marek Vasut <[email protected]>
Thanks for the review! I'm happy to kill off much of this nonsense too. And I think this will help in the long run on some other things too, since now we have a canonical place to put common MTD bindings.
Brian
Re: [PATCH v2 09/11] mtd: drop unnecessary partition parser data
In reply to Brian NorrisQuoted 11 lines · On Fri, 30 Oct 2015 20:33:28 -0700 Brian Norris <[email protected]>…
drivers/mtd/maps/lantiq-flash.c +0
-1@@ -110,7 +110,6 @@ ltq_copy_to(struct map_info *map, unsigned long to,static int ltq_mtd_probe (struct platform_device *pdev) { -struct mtd_part_parser_data ppdata;struct ltq_mtd *ltq_mtd;struct cfi_private *cfi;int err;
drivers/mtd/maps/lantiq-flash.c ltq_mtd_probe(struct platform_device *pdev) · line 163
Quoted 4 lines
drivers/mtd/maps/lantiq-flash.c +1
-0@@ -161,13 +160,13 @@ ltq_mtd_probe(struct platform_device *pdev) } ltq_mtd->mtd->dev.parent = &pdev->dev; +mtd_set_of_node (<q_mtd->mtd, pdev->dev.of_node);
Should be:
mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
(This error was reported by your aiaiai build test)
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Re: [PATCH v2 09/11] mtd: drop unnecessary partition parser data
Quoted 16 lines · Boris Brezillon
Quoted 13 lines · On Fri, 30 Oct 2015 20:33:28 -0700 Brian Norris <[email protected]>…
drivers/mtd/maps/lantiq-flash.c +0
-1@@ -110,7 +110,6 @@ ltq_copy_to(struct map_info *map, unsigned long to,static int ltq_mtd_probe (struct platform_device *pdev) { -struct mtd_part_parser_data ppdata;struct ltq_mtd *ltq_mtd;struct cfi_private *cfi;int err;@@ -161,13 +160,13 @@ ltq_mtd_probe(struct platform_device *pdev) }
Quoted 8 lines
drivers/mtd/maps/lantiq-flash.c ltq_mtd_probe(struct platform_device *pdev) · line 163
Quoted 2 lines
drivers/mtd/maps/lantiq-flash.c +1
-0ltq_mtd->mtd->dev.parent = &pdev->dev; +mtd_set_of_node (<q_mtd->mtd, pdev->dev.of_node);Should be:
mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);(This error was reported by your aiaiai build test)
Fixed that build error and pushed the rest of my 11 patches to l2-mtd.git/next.
PATCH v2 10/11 mtd: ofpart: drop 'of_node' partition parser data
In reply to Brian NorrisThis field is no longer used anywhere, as it is superseded by mtd->dev.of_node.
---
v2: use new helpers
drivers/mtd/ofpart.c | 14 ++++---------- include/linux/mtd/partitions.h | 4 ---- 2 files changed, 4 insertions(+), 14 deletions(-)
drivers/mtd/ofpart.c +4 -10
@@ -37,11 +37,8 @@ static int parse_ofpart_partitions(struct mtd_info *master,bool dedicated = true; -/* -* of_node can be provided through auxiliary parser data or (preferred) -* by assigning the master device node -*/ - mtd_node = data && data->of_node ? data->of_node :mtd_get_of_node (master); +/* Pull of_node from the master device node */ + mtd_node =mtd_get_of_node (master);if (!mtd_node)return 0 ;
@@ -150,11 +147,8 @@ static int parse_ofoldpart_partitions(struct mtd_info *master, } *part;const char *names; -/* -* of_node can be provided through auxiliary parser data or (preferred) -* by assigning the master device node -*/ - dp = data && data->of_node ? data->of_node :mtd_get_of_node (master); +/* Pull of_node from the master device node */ + dp =mtd_get_of_node (master);if (!dp)return 0 ;
include/linux/mtd/partitions.h +0 -4
@@ -56,13 +56,9 @@ struct device_node;/** * struct mtd_part_parser_data - used to pass data to MTD partition parsers. * @origin: for RedBoot, start address of MTD device -* @of_node: for OF parsers, device node containing partitioning information. -* This field is deprecated, as the device node should simply be -* assigned to the master struct device. */ struct mtd_part_parser_data {unsigned long origin; -struct device_node *of_node; };
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 11/11 mtd: physmap_of: assign parent for the concatenated MTD
In reply to Brian NorrisIf there is more than one map region for this device, then the concatenated MTD will not have a parent device assigned to it -- only the sub-devices (which are not actually registered with the framework) will have their parents assigned. Let's assign the concatenated device correctly.
---
v2: lumped into this series, since its context depends on this series
drivers/mtd/maps/physmap_of.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/maps/physmap_of.c +1 -0
@@ -309,6 +309,7 @@ static int of_flash_probe(struct platform_device *dev)if (err) goto err_out; + info->cmtd->dev.parent = &dev->dev;mtd_set_of_node (info->cmtd, dp); part_probe_types =of_get_probes (dp);if (!part_probe_types) {
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Quoted 11 lines · On Fri, 30 Oct 2015 20:33:19 -0700 Brian Norris <[email protected]>…
Hi,
I noticed that, for MTD drivers that want to support DT partition parsing (essentially all recent ones), it's a bit awkward to set the tell MTD which DT node to use. I also noticed that this info is duplicated in a few places; namely, some sub-subsystems (like SPI NOR and NAND) need their own field to track the DT node, so let's have the propagate the 'MTD' DT node down for us.
Besides simplifying the boilerplate throughout MTD, this series also has the side effect of producing '
of_node' symlinks in sysfs. e.g.:
Quoted 7 lines
# ls -al /sys/class/mtd/mtd0/of_node lrwxrwxrwx 1 root root 0 Oct 26 19:17 /sys/class/mtd/mtd0/of_node -> ../../../../firmware/devicetree/base/spi@ff130000/flash@0For NAND, this potentially has some other bigger initial side effects, since
nand_dt_init()handles a bit more automagically for drivers that defined their ->flash_node. But these drivers should probably convert anyway. So, please test your favorite driver!
Looks all good to me,
Quoted 64 lines
v1 -> v2:
* add helper functions for getting/setting the MTD/SPI-NOR/NAND DT node
* fix some build errors
* drop spi_nor'sflash_nodefield (just use the MTDof_node)Regards,
BrianBrian Norris (11):
mtd: add get/set of_node/flash_node helpers
mtd: ofpart: grab device tree node directly from master device node
mtd: {nand,spi-nor}: assign MTDof_node
mtd: nand: convert tonand_set_flash_node()
mtd: spi-nor: convert to spi_nor_{get,set}_flash_node()
mtd: nand: drop unnecessary partition parser data
mtd: spi-nor: drop unnecessary partition parser data
mtd: spi-nor: dropflash_nodefield
mtd: drop unnecessary partition parser data
mtd: ofpart: drop 'of_node' partition parser data
mtd:physmap_of: assign parent for the concatenated MTDdrivers/mtd/devices/m25p80.c | 10 +++------- drivers/mtd/devices/mtd_dataflash.c | 5 ++--- drivers/mtd/devices/spear_smi.c | 6 ++---- drivers/mtd/devices/st_spi_fsm.c | 5 ++--- drivers/mtd/maps/lantiq-flash.c | 5 ++--- drivers/mtd/maps/physmap_of.c | 6 +++--- drivers/mtd/nand/atmel_nand.c | 7 +++---- drivers/mtd/nand/brcmnand/brcmnand.c | 5 ++--- drivers/mtd/nand/davinci_nand.c | 10 +++------- drivers/mtd/nand/fsl_elbc_nand.c | 5 ++--- drivers/mtd/nand/fsl_ifc_nand.c | 5 ++--- drivers/mtd/nand/fsl_upm.c | 5 ++--- drivers/mtd/nand/fsmc_nand.c | 9 ++++----- drivers/mtd/nand/gpio.c | 8 +++----- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 5 ++--- drivers/mtd/nand/hisi504_nand.c | 5 ++--- drivers/mtd/nand/lpc32xx_mlc.c | 7 +++---- drivers/mtd/nand/lpc32xx_slc.c | 7 +++---- drivers/mtd/nand/mpc5121_nfc.c | 5 ++--- drivers/mtd/nand/mxc_nand.c | 5 ++--- drivers/mtd/nand/nand_base.c | 3 +++ drivers/mtd/nand/ndfc.c | 5 ++--- drivers/mtd/nand/omap2.c | 6 ++---- drivers/mtd/nand/orion_nand.c | 6 ++---- drivers/mtd/nand/plat_nand.c | 5 ++--- drivers/mtd/nand/pxa3xx_nand.c | 10 +++++----- drivers/mtd/nand/sh_flctl.c | 6 ++---- drivers/mtd/nand/socrates_nand.c | 5 ++--- drivers/mtd/nand/sunxi_nand.c | 6 ++---- drivers/mtd/nand/vf610_nfc.c | 8 ++------ drivers/mtd/ofpart.c | 12 ++++-------- drivers/mtd/onenand/omap2.c | 8 +++----- drivers/mtd/spi-nor/fsl-quadspi.c | 6 ++---- drivers/mtd/spi-nor/nxp-spifi.c | 6 ++---- drivers/mtd/spi-nor/spi-nor.c | 2 +- drivers/staging/mt29f_spinand/mt29f_spinand.c | 5 ++--- include/linux/mtd/mtd.h | 11 +++++++++++ include/linux/mtd/nand.h | 11 +++++++++++ include/linux/mtd/partitions.h | 2 -- include/linux/mtd/spi-nor.h | 13 +++++++++++-- 40 files changed, 120 insertions(+), 141 deletions(-)
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
[PATCH v2 12/11] mtd: nand: convert to nand_get_flash_node()
In reply to Brian NorrisUsed semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':
---8<----
virtual patch
@@
struct nand_chip c;
struct nand_chip *cp;
@@
(
-(cp)->flash_node
+nand_get_flash_node(cp)
|
-(c).flash_node
+nand_get_flash_node(&c)
)
---8<----
---
Hi Brian,
I think this patch could be part of your series too.
Best Regards,
Boris
drivers/mtd/nand/brcmnand/brcmnand.c | 2 +- drivers/mtd/nand/nand_base.c | 6 +++--- drivers/mtd/nand/vf610_nfc.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +1 -1
@@ -1816,7 +1816,7 @@ static int brcmnand_setup_dev(struct brcmnand_host *host)memset (cfg,0 ,sizeof (*cfg)); - ret =of_property_read_u32 (chip->flash_node, + ret =of_property_read_u32 (nand_get_flash_node (chip),"brcm,nand-oob-sector-size" , &oob_sector);if (ret) {
drivers/mtd/nand/nand_base.c +3 -3
@@ -3989,11 +3989,11 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,struct nand_flash_dev *type;int ret; -if (chip->flash_node) { +if (nand_get_flash_node (chip)) {/* MTD can automatically handle DT partitions, etc. */ -mtd_set_of_node (mtd, chip->flash_node); +mtd_set_of_node (mtd,nand_get_flash_node (chip)); - ret =nand_dt_init (mtd, chip, chip->flash_node); + ret =nand_dt_init (mtd, chip,nand_get_flash_node (chip));if (ret)return ret; }
drivers/mtd/nand/vf610_nfc.c +3 -3
@@ -707,7 +707,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)for_each_available_child_of_node (nfc->dev->of_node, child) {if (of_device_is_compatible (child,"fsl,vf610-nfc-nandcs" )) { -if (chip->flash_node) { +if (nand_get_flash_node (chip)) {dev_err (nfc->dev,"Only one NAND chip supported!\n" ); err = -EINVAL ;
@@ -718,7 +718,7 @@ static int vf610_nfc_probe(struct platform_device *pdev) } } -if (!chip->flash_node) { +if (!nand_get_flash_node (chip)) {dev_err (nfc->dev,"NAND chip sub-node missing!\n" ); err = -ENODEV ; goto err_clk;
@@ -814,7 +814,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)return mtd_device_register (mtd,NULL ,0 ); error: -of_node_put (chip->flash_node); +of_node_put (nand_get_flash_node (chip)); err_clk:clk_disable_unprepare (nfc->clk);return err;
Signature · 1 line
2.1.4
Re: [PATCH v2 12/11] mtd: nand: convert to nand_get_flash_node()
Quoted 19 lines · Boris Brezillon
Used semantic patch with 'make coccicheck MODE=patch COCCI=script.cocci':
---8<----
virtual patch@@
structnand_chipc;
structnand_chip*cp;
@@
((quoted diff) +1
-1-(cp)->flash_node +nand_get_flash_node(cp)|
(quoted diff) +1
-1-(c).flash_node +nand_get_flash_node(&c))
---8<----Signed-off-by Boris Brezillon <[email protected]>
Quoted 8 lines
---
Hi Brian,I think this patch could be part of your series too.
Best Regards,
Boris
Thanks! Pushed to l2-mtd.git/next
[PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices
In reply to Brian NorrisMTD partitions may have been created from a DT definition, and in this case the ->of_node of the struct device embedded in mtd_info should point to the DT node that was used to create the partition.
---
Hi Brian,
Yet another patch that IMO should go into your "mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data" series.
Best Regards,
Boris
drivers/mtd/mtdcore.c | 17 +++++++++++++---- drivers/mtd/mtdpart.c | 3 +++ drivers/mtd/ofpart.c | 1 + include/linux/mtd/partitions.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-)
drivers/mtd/mtdcore.c +13 -4
@@ -32,6 +32,7 @@#include <linux/err.h> #include <linux/ioctl.h> #include <linux/init.h> +#include <linux/of.h> #include <linux/proc_fs.h> #include <linux/idr.h> #include <linux/backing-dev.h>
@@ -584,11 +585,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,const struct mtd_partition *parts, int nr_parts) { - int ret; + int ret, i;struct mtd_partition *real_parts =NULL ; ret =parse_mtd_partitions (mtd, types, &real_parts, parser_data); -if (ret <=0 && nr_parts && parts) { +if (ret >0 ) { + nr_parts = ret; + }else if (nr_parts && parts) { real_parts =kmemdup (parts,sizeof (*parts) * nr_parts,GFP_KERNEL );if (!real_parts)
@@ -604,7 +607,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, ret =0 ; } - ret =mtd_add_device_partitions (mtd, real_parts, ret); + ret =mtd_add_device_partitions (mtd, real_parts, nr_parts);if (ret) goto out;
@@ -623,7 +626,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, } out: -kfree (real_parts); +if (real_parts) { +for (i =0 ; i < nr_parts; i++) +of_node_put (real_parts[i].of_node); + +kfree (real_parts); + } +return ret; }EXPORT_SYMBOL_GPL (mtd_device_parse_register);
drivers/mtd/mtdpart.c +3 -0
@@ -29,6 +29,7 @@#include <linux/kmod.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> +#include <linux/of.h> #include <linux/err.h> #include <linux/kconfig.h>
@@ -319,6 +320,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)static inline void free_partition (struct mtd_part *p) { +of_node_put (mtd_get_of_node (&p->mtd));kfree (p->mtd.name);kfree (p); }
@@ -391,6 +393,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.dev.parent =IS_ENABLED (CONFIG_MTD_PARTITIONED_MASTER ) ? &master->dev : master->dev.parent; +mtd_set_of_node (&slave->mtd,of_node_get (part->of_node)); slave->mtd._read = part_read; slave->mtd._write = part_write;
drivers/mtd/ofpart.c +1 -0
@@ -111,6 +111,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,if (of_get_property (pp,"lock" , &len)) (*pparts)[i].mask_flags |=MTD_POWERUP_LOCK ; + (*pparts)[i].of_node =of_node_get (pp); i++; }
include/linux/mtd/partitions.h +1 -0
@@ -42,6 +42,7 @@ struct mtd_partition {uint64_t offset;/* offset within the master MTD space */ uint32_t mask_flags;/* master MTD flags to mask out for this partition */ struct nand_ecclayout *ecclayout;/* out of band layout for this partition (NAND only) */ +struct device_node *of_node;/* OF node attached to the partition */ };#define MTDPART_OFS_RETAIN (-3)
Signature · 1 line
2.1.4
Re: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices
Quoted 5 lines · Boris Brezillon
MTD partitions may have been created from a DT definition, and in this case the ->of_node of the struct device embedded in
mtd_infoshould point to the DT node that was used to create the partition.Signed-off-by Boris Brezillon <[email protected]>
I like the idea of this patch, but I'm not sure about all of its details.
Quoted 101 lines
---
Hi Brian,Yet another patch that IMO should go into your "mtd: migrate '
of_node' handling to core, not inmtd_part_parser_data" series.Best Regards,
Boris
drivers/mtd/mtdcore.c | 17 +++++++++++++---- drivers/mtd/mtdpart.c | 3 +++ drivers/mtd/ofpart.c | 1 + include/linux/mtd/partitions.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-)drivers/mtd/mtdcore.c +13
-4@@ -32,6 +32,7 @@#include <linux/err.h> #include <linux/ioctl.h> #include <linux/init.h> +#include <linux/of.h> #include <linux/proc_fs.h> #include <linux/idr.h> #include <linux/backing-dev.h> @@ -584,11 +585,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,const struct mtd_partition *parts, int nr_parts) { - int ret; + int ret, i;struct mtd_partition *real_parts =NULL ; ret =parse_mtd_partitions (mtd, types, &real_parts, parser_data); -if (ret <=0 && nr_parts && parts) { +if (ret >0 ) { + nr_parts = ret; + }else if (nr_parts && parts) { real_parts =kmemdup (parts,sizeof (*parts) * nr_parts,GFP_KERNEL );if (!real_parts)@@ -604,7 +607,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, ret =0 ; } - ret =mtd_add_device_partitions (mtd, real_parts, ret); + ret =mtd_add_device_partitions (mtd, real_parts, nr_parts);if (ret) goto out;@@ -623,7 +626,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, } out: -kfree (real_parts); +if (real_parts) { +for (i =0 ; i < nr_parts; i++) +of_node_put (real_parts[i].of_node); + +kfree (real_parts); + } +return ret; }EXPORT_SYMBOL_GPL (mtd_device_parse_register);drivers/mtd/mtdpart.c +3
-0@@ -29,6 +29,7 @@#include <linux/kmod.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> +#include <linux/of.h> #include <linux/err.h> #include <linux/kconfig.h> @@ -319,6 +320,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)static inline void free_partition (struct mtd_part *p) { +of_node_put (mtd_get_of_node (&p->mtd));kfree (p->mtd.name);kfree (p); }@@ -391,6 +393,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.dev.parent =IS_ENABLED (CONFIG_MTD_PARTITIONED_MASTER ) ? &master->dev : master->dev.parent; +mtd_set_of_node (&slave->mtd,of_node_get (part->of_node)); slave->mtd._read = part_read; slave->mtd._write = part_write;drivers/mtd/ofpart.c +0
-0
drivers/mtd/ofpart.c static int parse_ofpart_partitions(struct mtd_info *master, · line 114
Quoted 4 lines
drivers/mtd/ofpart.c +1
-0@@ -111,6 +111,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,if (of_get_property (pp,"lock" , &len)) (*pparts)[i].mask_flags |=MTD_POWERUP_LOCK ; + (*pparts)[i].of_node =of_node_get (pp);
I don't think we should mix up too much of the error handling between ofpart.c and mtdcore.c (right now, you do of_node_get() here but the of_node_put() is forced into mtdcore.c). I think the problem here is the same as the problem with Linus' patch here:
http://lists.infradead.org/pipermail/linux-mtd/2015-November/063219.html
It's just too easy to leak resources when MTD parsers don't have their own cleanup functions (like C++ destructors, or the driver model's remove() function, or so many other resource models). If we had a cleanup function, then we could just put the release handling there.
But actually, I don't think we need to 'get' the property here; we only need to 'get' it when we're putting it somewhere that will actually use it long term. i.e., when it actually gets assigned to the mtd.dev.of_node field and is headed for sysfs.
IOW, I think we can grab the reference in add_mtd_device() and drop it in del_mtd_device(). This would handle both the partition and non-partition case the same.
I have a patch to do that (for the non-partition case) queued up. I'll push it out soon, then I expect you can make this patch a lot simpler.
Brian
Quoted 18 lines
drivers/mtd/ofpart.c +0
-0i++; }include/linux/mtd/partitions.h +1
-0@@ -42,6 +42,7 @@ struct mtd_partition {uint64_t offset;/* offset within the master MTD space */ uint32_t mask_flags;/* master MTD flags to mask out for this partition */ struct nand_ecclayout *ecclayout;/* out of band layout for this partition (NAND only) */ +struct device_node *of_node;/* OF node attached to the partition */ };#define MTDPART_OFS_RETAIN (-3)Signature · 1 line
2.1.4
Re: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices
Hi Brian,
Quoted 128 lines · On Wed, 11 Nov 2015 16:15:50 -0800 Brian Norris <[email protected]>…
Quoted 5 lines · Boris Brezillon
MTD partitions may have been created from a DT definition, and in this case the ->of_node of the struct device embedded in
mtd_infoshould point to the DT node that was used to create the partition.Signed-off-by Boris Brezillon <[email protected]>I like the idea of this patch, but I'm not sure about all of its details.
Quoted 101 lines
---
Hi Brian,Yet another patch that IMO should go into your "mtd: migrate '
of_node' handling to core, not inmtd_part_parser_data" series.Best Regards,
Boris
drivers/mtd/mtdcore.c | 17 +++++++++++++---- drivers/mtd/mtdpart.c | 3 +++ drivers/mtd/ofpart.c | 1 + include/linux/mtd/partitions.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-)drivers/mtd/mtdcore.c +13
-4@@ -32,6 +32,7 @@#include <linux/err.h> #include <linux/ioctl.h> #include <linux/init.h> +#include <linux/of.h> #include <linux/proc_fs.h> #include <linux/idr.h> #include <linux/backing-dev.h> @@ -584,11 +585,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,const struct mtd_partition *parts, int nr_parts) { - int ret; + int ret, i;struct mtd_partition *real_parts =NULL ; ret =parse_mtd_partitions (mtd, types, &real_parts, parser_data); -if (ret <=0 && nr_parts && parts) { +if (ret >0 ) { + nr_parts = ret; + }else if (nr_parts && parts) { real_parts =kmemdup (parts,sizeof (*parts) * nr_parts,GFP_KERNEL );if (!real_parts)@@ -604,7 +607,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, ret =0 ; } - ret =mtd_add_device_partitions (mtd, real_parts, ret); + ret =mtd_add_device_partitions (mtd, real_parts, nr_parts);if (ret) goto out;@@ -623,7 +626,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, } out: -kfree (real_parts); +if (real_parts) { +for (i =0 ; i < nr_parts; i++) +of_node_put (real_parts[i].of_node); + +kfree (real_parts); + } +return ret; }EXPORT_SYMBOL_GPL (mtd_device_parse_register);drivers/mtd/mtdpart.c +3
-0@@ -29,6 +29,7 @@#include <linux/kmod.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> +#include <linux/of.h> #include <linux/err.h> #include <linux/kconfig.h> @@ -319,6 +320,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)static inline void free_partition (struct mtd_part *p) { +of_node_put (mtd_get_of_node (&p->mtd));kfree (p->mtd.name);kfree (p); }@@ -391,6 +393,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.dev.parent =IS_ENABLED (CONFIG_MTD_PARTITIONED_MASTER ) ? &master->dev : master->dev.parent; +mtd_set_of_node (&slave->mtd,of_node_get (part->of_node)); slave->mtd._read = part_read; slave->mtd._write = part_write;drivers/mtd/ofpart.c +0
-0drivers/mtd/ofpart.c static int parse_ofpart_partitions(struct mtd_info *master, · line 114
Quoted 4 lines
drivers/mtd/ofpart.c +1
-0@@ -111,6 +111,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,if (of_get_property (pp,"lock" , &len)) (*pparts)[i].mask_flags |=MTD_POWERUP_LOCK ; + (*pparts)[i].of_node =of_node_get (pp);I don't think we should mix up too much of the error handling between
ofpart.candmtdcore.c(right now, you doof_node_get()here but theof_node_put()is forced intomtdcore.c). I think the problem here is the same as the problem with Linus' patch here:http://lists.infradead.org/pipermail/linux-mtd/2015-November/063219.html
It's just too easy to leak resources when MTD parsers don't have their own cleanup functions (like C++ destructors, or the driver model's
remove()function, or so many other resource models). If we had a cleanup function, then we could just put the release handling there.
Quoted 8 lines
But actually, I don't think we need to 'get' the property here; we only need to 'get' it when we're putting it somewhere that will actually use it long term. i.e., when it actually gets assigned to the mtd.dev.of_node field and is headed for sysfs.
IOW, I think we can grab the reference in
add_mtd_device()and drop it indel_mtd_device(). This would handle both the partition and non-partition case the same.
Hm, actually I think we need it. When you iterate over child nodes with for_each_child_of_node(), the node is released (of_node_put() is called) after each iteration. While this is not a problem for mtd device registration (because the controller usually retain the reference when add_mtd_device() is called), this is not true for the partitions. And if the partitions are ever defined using an overlay, this can be a problem.
To sum-up, I think we should retain the node reference until add_mtd_device() has retained it, so maybe we should have a ->cleanup() function in mtd part parsers.
Best Regards,
Boris
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Re: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices
Quoted 6 lines · Boris Brezillon
Quoted 3 lines · On Wed, 11 Nov 2015 16:15:50 -0800 Brian Norris <[email protected]>…
IOW, I think we can grab the reference in
add_mtd_device()and drop it indel_mtd_device(). This would handle both the partition and non-partition case the same.
Quoted 7 lines
Hm, actually I think we need it. When you iterate over child nodes with
for_each_child_of_node(), the node is released (of_node_put()is called) after each iteration. While this is not a problem for mtd device registration (because the controller usually retain the reference whenadd_mtd_device()is called), this is not true for the partitions. And if the partitions are ever defined using an overlay, this can be a problem.
Yep.
Quoted 3 lines
To sum-up, I think we should retain the node reference until
add_mtd_device()has retained it, so maybe we should have a ->cleanup() function in mtd part parsers.
OK. I'll drop my patch and send out my ->cleanup() stuff instead, so you can patch on top of that.
Brian