mtd: spi-nor: Decouple SPI NOR's device_node from controller device
Subsystems (2)
PATCH 1/1 mtd: spi-nor: Decouple SPI NOR's device_node from controller device
The problem this patch is trying to address is such, that SPI NOR flash devices attached to a dedicated SPI NOR controller cannot read their properties from the associated struct device_node.
A couple of facts first:
1) Each SPI NOR flash has a struct spi_nor associated with it.
2) Each SPI NOR flash has certain device properties associated with it, for example the OF property 'm25p,fast-read' is a good pick. These properties are used by the SPI NOR core to select which opcodes are sent to such SPI NOR flash. These properties are coming from spi_nor .dev->device_node .
The problem is, that for SPI NOR controllers, the struct spi_nor .dev element points to the struct device of the SPI NOR controller, not the SPI NOR flash. Therefore, the associated dev->device_node also is the one of the controller and therefore the SPI NOR core code is trying to parse the SPI NOR controller's properties, not the properties of the SPI NOR flash.
Note: The m25p80 driver is not affected, because the controller and
the flash are the same device, so the associated device_node of the controller and the flash are the same.
This patch adjusts the SPI NOR core such that the device_node is not picked from spi_nor .dev directly, but from a new separate spi_nor .dn element. This let's the SPI NOR controller drivers set up a different spi_nor .dn element for each SPI NOR flash.
This patch also fixes the controller drivers to be compatible with this modification and correctly set the spi_nor .dn element.
This patch is inspired by 5844feeaa4154d1c46d3462c7a4653d22356d8b4
mtd: nand: add common DT init code
--- drivers/mtd/devices/m25p80.c | 1 + drivers/mtd/spi-nor/fsl-quadspi.c | 1 + drivers/mtd/spi-nor/nxp-spifi.c | 1 + include/linux/mtd/spi-nor.h | 3 +++ 4 files changed, 6 insertions(+)
drivers/mtd/devices/m25p80.c +1 -0
@@ -202,6 +202,7 @@ static int m25p_probe(struct spi_device *spi) nor->dev = &spi->dev; nor->mtd = &flash->mtd; + nor->dn = &spi->dev.of_node; nor->priv = flash;spi_set_drvdata (spi, flash);
drivers/mtd/spi-nor/fsl-quadspi.c +1 -0
@@ -1017,6 +1017,7 @@ static int fsl_qspi_probe(struct platform_device *pdev) nor->mtd = mtd; nor->dev = dev; + nor->dn = np; nor->priv = q; mtd->priv = nor;
drivers/mtd/spi-nor/nxp-spifi.c +1 -0
@@ -334,6 +334,7 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi, spifi->mtd.priv = &spifi->nor; spifi->nor.mtd = &spifi->mtd; spifi->nor.dev = spifi->dev; + spifi->nor.dn = np; spifi->nor.priv = spifi; spifi->nor.read = nxp_spifi_read; spifi->nor.write = nxp_spifi_write;
include/linux/mtd/spi-nor.h +3 -0
@@ -169,6 +169,7 @@ enum spi_nor_option_flags {* @lock: [FLASH-SPECIFIC] lock a region of the SPI NOR * @unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR * @priv: the private data +* @dn: [BOARD-SPECIFIC] device node describing this instance */ struct spi_nor {struct mtd_info *mtd;
@@ -208,6 +209,8 @@ struct spi_nor {int (*flash_unlock)(struct spi_nor *nor,loff_t ofs,uint64_t len);void *priv; + +struct device_node *dn; };/**
Signature · 1 line
2.1.4
Hi,
Quoted 11 lines · Marek Vasut
The problem this patch is trying to address is such, that SPI NOR flash devices attached to a dedicated SPI NOR controller cannot read their properties from the associated struct
device_node.A couple of facts first:
1) Each SPI NOR flash has a structspi_norassociated with it.
2) Each SPI NOR flash has certain device properties associated with it, for example the OF property 'm25p,fast-read' is a good pick. These properties are used by the SPI NOR core to select which opcodes are sent to such SPI NOR flash. These properties are coming fromspi_nor.dev->device_node .
dev->of_node
Quoted 4 lines
The problem is, that for SPI NOR controllers, the struct
spi_nor.dev element points to the struct device of the SPI NOR controller, not the SPI NOR flash. Therefore, the associateddev->device_nodealso is the
dev->of_node
Quoted 13 lines
one of the controller and therefore the SPI NOR core code is trying to parse the SPI NOR controller's properties, not the properties of the SPI NOR flash.
Note: The m25p80 driver is not affected, because the controller and
the flash are the same device, so the associateddevice_nodeof the controller and the flash are the same.This patch adjusts the SPI NOR core such that the
device_nodeis not picked fromspi_nor.dev directly, but from a new separatespi_nor.dn element. This let's the SPI NOR controller drivers set up a differentspi_nor.dn element for each SPI NOR flash.
Quoted 5 lines
This patch also fixes the controller drivers to be compatible with this modification and correctly set the
spi_nor.dn element.This patch is inspired by
5844feeaa4154d1c46d3462c7a4653d22356d8b4
mtd: nand: add common DT init code
I know that this commit named it dn for nand, but IMHO "dn" isn't a very readable member name, so I would suggest using something with "node" in it (just using of_node as well seems to be common). I see no place where the name length might become an issue.
Quoted 14 lines
Signed-off-by Marek Vasut <[email protected]>Cc Brian Norris <[email protected]>--- drivers/mtd/devices/m25p80.c | 1 + drivers/mtd/spi-nor/fsl-quadspi.c | 1 + drivers/mtd/spi-nor/nxp-spifi.c | 1 + include/linux/mtd/spi-nor.h | 3 +++ 4 files changed, 6 insertions(+)drivers/mtd/devices/m25p80.c +0
-0
drivers/mtd/devices/m25p80.c static int m25p_probe(struct spi_device *spi) · line 205
Quoted 4 lines
drivers/mtd/devices/m25p80.c +1
-0@@ -202,6 +202,7 @@ static int m25p_probe(struct spi_device *spi) nor->dev = &spi->dev; nor->mtd = &flash->mtd; + nor->dn = &spi->dev.of_node;
drivers/mtd/devices/m25p80.c: In function 'm25p_probe':drivers/mtd/devices/m25p80.c:221:5: warning: assignment from incompatible pointer type [enabled by default]
this needs to be ... = spi->dev.of_node;
Quoted 40 lines
drivers/mtd/devices/m25p80.c +0
-0nor->priv = flash;spi_set_drvdata (spi, flash);drivers/mtd/spi-nor/fsl-quadspi.c +1
-0@@ -1017,6 +1017,7 @@ static int fsl_qspi_probe(struct platform_device *pdev) nor->mtd = mtd; nor->dev = dev; + nor->dn = np; nor->priv = q; mtd->priv = nor;drivers/mtd/spi-nor/nxp-spifi.c +1
-0@@ -334,6 +334,7 @@ static int nxp_spifi_setup_flash(struct nxp_spifi *spifi, spifi->mtd.priv = &spifi->nor; spifi->nor.mtd = &spifi->mtd; spifi->nor.dev = spifi->dev; + spifi->nor.dn = np; spifi->nor.priv = spifi; spifi->nor.read = nxp_spifi_read; spifi->nor.write = nxp_spifi_write;include/linux/mtd/spi-nor.h +1
-0@@ -169,6 +169,7 @@ enum spi_nor_option_flags {* @lock: [FLASH-SPECIFIC] lock a region of the SPI NOR * @unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR * @priv: the private data +* @dn: [BOARD-SPECIFIC] device node describing this instance */ struct spi_nor {struct mtd_info *mtd;
include/linux/mtd/spi-nor.h struct spi_nor { · line 214
Quoted 6 lines
include/linux/mtd/spi-nor.h +2
-0@@ -208,6 +209,8 @@ struct spi_nor {int (*flash_unlock)(struct spi_nor *nor,loff_t ofs,uint64_t len);void *priv; + +struct device_node *dn; };
Regards
Jonas
Quoted 1 line · Jonas Gorski
Hi,
Hi,
Quoted 9 lines · Marek Vasut
Quoted 8 lines
The problem this patch is trying to address is such, that SPI NOR flash devices attached to a dedicated SPI NOR controller cannot read their properties from the associated struct
device_node.A couple of facts first:
1) Each SPI NOR flash has a structspi_norassociated with it.
2) Each SPI NOR flash has certain device properties associated
Quoted 6 lines
Quoted 4 lines
with it, for example the OF property 'm25p,fast-read' is a good pick. These properties are used by the SPI NOR core to select which opcodes are sent to such SPI NOR flash. These properties are coming from
spi_nor.dev->device_node .
dev->of_node
Guh, right, thanks :)
Quoted 5 lines
Quoted 3 lines
The problem is, that for SPI NOR controllers, the struct
spi_nor.dev element points to the struct device of the SPI NOR controller, not the SPI NOR flash. Therefore, the associateddev->device_nodealso is the
dev->of_node
Yep, thanks :)
Quoted 17 lines
Quoted 17 lines
one of the controller and therefore the SPI NOR core code is trying to parse the SPI NOR controller's properties, not the properties of the SPI NOR flash.
Note: The m25p80 driver is not affected, because the controller and
the flash are the same device, so the associated
device_nodeof the controller and the flash are the same.This patch adjusts the SPI NOR core such that the
device_nodeis not picked fromspi_nor.dev directly, but from a new separatespi_nor.dn element. This let's the SPI NOR controller drivers set up a differentspi_nor.dn element for each SPI NOR flash.This patch also fixes the controller drivers to be compatible with this modification and correctly set the
spi_nor.dn element.
Quoted 7 lines
Quoted 2 lines
This patch is inspired by
5844feeaa4154d1c46d3462c7a4653d22356d8b4
mtd: nand: add common DT init codeI know that this commit named it dn for nand, but IMHO "dn" isn't a very readable member name, so I would suggest using something with "node" in it (just using
of_nodeas well seems to be common). I see no place where the name length might become an issue.
I thought .dn was supposed to be abbrev for device_node ;-)
Quoted 19 lines
Quoted 19 lines
Signed-off-by Marek Vasut <[email protected]>Cc Brian Norris <[email protected]>---
drivers/mtd/devices/m25p80.c | 1 + drivers/mtd/spi-nor/fsl-quadspi.c | 1 + drivers/mtd/spi-nor/nxp-spifi.c | 1 + include/linux/mtd/spi-nor.h | 3 +++ 4 files changed, 6 insertions(+)drivers/mtd/devices/m25p80.c +0
-0@@ -202,6 +202,7 @@ static int m25p_probe(struct spi_device *spi) nor->dev = &spi->dev; nor->mtd = &flash->mtd;
Quoted 7 lines
drivers/mtd/devices/m25p80.c static int m25p_probe(struct spi_device *spi) · line 205
Quoted 1 line
drivers/mtd/devices/m25p80.c +1
-0+ nor->dn = &spi->dev.of_node;
drivers/mtd/devices/m25p80.c: In function 'm25p_probe':drivers/mtd/devices/m25p80.c:221:5: warning: assignment from incompatible pointer type [enabled by default]this needs to be ... =
spi->dev.of_node;
Right, thanks!
I'll wait for a bit to figure out if this approach is sensible and then repost with the fixes.
Quoted 10 lines · Marek Vasut
Quoted 7 lines · Jonas Gorski
Quoted 2 lines
This patch is inspired by
5844feeaa4154d1c46d3462c7a4653d22356d8b4
mtd: nand: add common DT init codeI know that this commit named it dn for nand, but IMHO "dn" isn't a very readable member name, so I would suggest using something with "node" in it (just using
of_nodeas well seems to be common). I see no place where the name length might become an issue.I thought .dn was supposed to be abbrev for
device_node;-)
Sure, if you know what it is supposed to stand for it is obvious ;-). And from a "stylistic" point of view, struct spi_nor has members called page_size, flash_read or cmd_buf and not ps, fr, or cb so using dn instead of e.g. dev_node seems a bit odd.
Jonas
Quoted 10 lines · Jonas Gorski
Quoted 9 lines · Marek Vasut
Quoted 7 lines · Jonas Gorski
Quoted 2 lines
This patch is inspired by
5844feeaa4154d1c46d3462c7a4653d22356d8b4
mtd: nand: add common DT init codeI know that this commit named it dn for nand, but IMHO "dn" isn't a very readable member name, so I would suggest using something with "node" in it (just using
of_nodeas well seems to be common). I see no place where the name length might become an issue.
Quoted 6 lines
Quoted 1 line
I thought .dn was supposed to be abbrev for
device_node;-)Sure, if you know what it is supposed to stand for it is obvious ;-). And from a "stylistic" point of view, struct
spi_norhas members calledpage_size,flash_readorcmd_bufand not ps, fr, or cb so using dn instead of e.g.dev_nodeseems a bit odd.
On the other hand, the .dn is consistent across the MTD subsystem. I don't have a strong prefference though.
Best regards,
Marek Vasut
Quoted 13 lines · Marek Vasut
Quoted 12 lines · Jonas Gorski
Quoted 10 lines · Marek Vasut
Quoted 7 lines · Jonas Gorski
Quoted 2 lines
This patch is inspired by
5844feeaa4154d1c46d3462c7a4653d22356d8b4
mtd: nand: add common DT init codeI know that this commit named it dn for nand, but IMHO "dn" isn't a very readable member name, so I would suggest using something with "node" in it (just using
of_nodeas well seems to be common). I see no place where the name length might become an issue.I thought .dn was supposed to be abbrev for
device_node;-)
Quoted 7 lines
Quoted 4 lines
Sure, if you know what it is supposed to stand for it is obvious ;-). And from a "stylistic" point of view, struct
spi_norhas members calledpage_size,flash_readorcmd_bufand not ps, fr, or cb so using dn instead of e.g.dev_nodeseems a bit odd.On the other hand, the .dn is consistent across the MTD subsystem. I don't have a strong prefference though.
I just stuck in nand_chip::dn since we needed something, and because I've seen it used as a function parameter name and a local variable name all over the place, enough that it just seemed natural. But a field name is probably a bit more important. I'd be OK with making the "standard" a bit more verbose, and maybe even changing the one in struct nand_chip.
How about:
flash_node <-- this one leaves room for a controller node, if we
eventually need it
device_node
dev_node
of_node <-- this one is commonly used, but mostly out of legacy
reasons. We're not really dealing with Open Firmware
?
Pick one and run with it.
Brian
Quoted 28 lines · Brian Norris
Quoted 13 lines · Marek Vasut
Quoted 12 lines · Jonas Gorski
Quoted 10 lines · Marek Vasut
Quoted 7 lines · Jonas Gorski
Quoted 2 lines
This patch is inspired by
5844feeaa4154d1c46d3462c7a4653d22356d8b4
mtd: nand: add common DT init codeI know that this commit named it dn for nand, but IMHO "dn" isn't a very readable member name, so I would suggest using something with "node" in it (just using
of_nodeas well seems to be common). I see no place where the name length might become an issue.I thought .dn was supposed to be abbrev for
device_node;-)Quoted 7 lines
Quoted 4 lines
Sure, if you know what it is supposed to stand for it is obvious ;-). And from a "stylistic" point of view, struct
spi_norhas members calledpage_size,flash_readorcmd_bufand not ps, fr, or cb so using dn instead of e.g.dev_nodeseems a bit odd.On the other hand, the .dn is consistent across the MTD subsystem. I don't have a strong prefference though.
I just stuck in
nand_chip::dnsince we needed something, and because I've seen it used as a function parameter name and a local variable name all over the place, enough that it just seemed natural. But a field name is probably a bit more important. I'd be OK with making the "standard" a bit more verbose, and maybe even changing the one in structnand_chip.
Quoted 4 lines
How about:
flash_node<-- this one leaves room for a controller node, if we
eventually need it
I like this one the most, exactly because of your reasoning.
Quoted 10 lines
device_node
dev_node
of_node<-- this one is commonly used, but mostly out of legacy
reasons. We're not really dealing with Open Firmware?
Pick one and run with it.
Brian
Best regards,
Marek Vasut
Quoted 19 lines · Marek Vasut
The problem this patch is trying to address is such, that SPI NOR flash devices attached to a dedicated SPI NOR controller cannot read their properties from the associated struct
device_node.A couple of facts first:
1) Each SPI NOR flash has a structspi_norassociated with it.
2) Each SPI NOR flash has certain device properties associated with it, for example the OF property 'm25p,fast-read' is a good pick. These properties are used by the SPI NOR core to select which opcodes are sent to such SPI NOR flash. These properties are coming fromspi_nor.dev->device_node .The problem is, that for SPI NOR controllers, the struct
spi_nor.dev element points to the struct device of the SPI NOR controller, not the SPI NOR flash. Therefore, the associateddev->device_nodealso is the one of the controller and therefore the SPI NOR core code is trying to parse the SPI NOR controller's properties, not the properties of the SPI NOR flash.
Quoted 7 lines
Note: The m25p80 driver is not affected, because the controller and
the flash are the same device, so the associateddevice_nodeof the controller and the flash are the same.This patch adjusts the SPI NOR core such that the
device_nodeis not picked fromspi_nor.dev directly, but from a new separatespi_nor.dn element.
Does it really?
[...]
Quoted 6 lines
--- drivers/mtd/devices/m25p80.c | 1 + drivers/mtd/spi-nor/fsl-quadspi.c | 1 + drivers/mtd/spi-nor/nxp-spifi.c | 1 + include/linux/mtd/spi-nor.h | 3 +++ 4 files changed, 6 insertions(+)
^^ I would expect to see spi-nor.c changes in the diffstat. Did you miss something?
[...]
include/linux/mtd/spi-nor.h enum spi_nor_option_flags { · line 172
Quoted 9 lines
include/linux/mtd/spi-nor.h +1
-0@@ -169,6 +169,7 @@ enum spi_nor_option_flags {* @lock: [FLASH-SPECIFIC] lock a region of the SPI NOR * @unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR * @priv: the private data +* @dn: [BOARD-SPECIFIC] device node describing this instance
I might like to see this up near the @dev entry, for organization purposes.
include/linux/mtd/spi-nor.h struct spi_nor { · line 213
Quoted 9 lines
include/linux/mtd/spi-nor.h +2
-0*/ struct spi_nor {struct mtd_info *mtd;@@ -208,6 +209,8 @@ struct spi_nor {int (*flash_unlock)(struct spi_nor *nor,loff_t ofs,uint64_t len);void *priv; + +struct device_node *dn;
And this would get moved up as well.
include/linux/mtd/spi-nor.h struct spi_nor { · line 216
Quoted 3 lines
include/linux/mtd/spi-nor.h +0
-0};/**
Brian
Quoted 23 lines · Brian Norris
Quoted 22 lines · Marek Vasut
The problem this patch is trying to address is such, that SPI NOR flash devices attached to a dedicated SPI NOR controller cannot read their properties from the associated struct
device_node.A couple of facts first:
1) Each SPI NOR flash has a structspi_norassociated with it.
2) Each SPI NOR flash has certain device properties associatedwith it, for example the OF property 'm25p,fast-read' is a good pick. These properties are used by the SPI NOR core to select which opcodes are sent to such SPI NOR flash. These properties are coming from
spi_nor.dev->device_node .The problem is, that for SPI NOR controllers, the struct
spi_nor.dev element points to the struct device of the SPI NOR controller, not the SPI NOR flash. Therefore, the associateddev->device_nodealso is the one of the controller and therefore the SPI NOR core code is trying to parse the SPI NOR controller's properties, not the properties of the SPI NOR flash.Note: The m25p80 driver is not affected, because the controller and
Quoted 8 lines
Quoted 6 lines
the flash are the same device, so the associated
device_nodeof the controller and the flash are the same.This patch adjusts the SPI NOR core such that the
device_nodeis not picked fromspi_nor.dev directly, but from a new separatespi_nor.dn element.Does it really?
Yes, it does, but I missed a bit from this patch, sorry.
Quoted 4 lines
[...]
Quoted 2 lines
---
Quoted 8 lines
Quoted 5 lines
drivers/mtd/devices/m25p80.c | 1 + drivers/mtd/spi-nor/fsl-quadspi.c | 1 + drivers/mtd/spi-nor/nxp-spifi.c | 1 + include/linux/mtd/spi-nor.h | 3 +++ 4 files changed, 6 insertions(+)^^ I would expect to see
spi-nor.cchanges in the diffstat. Did you miss something?
Yes, sorry.
Quoted 8 lines
[...]
Quoted 6 lines
include/linux/mtd/spi-nor.h +0
-0@@ -169,6 +169,7 @@ enum spi_nor_option_flags {
Quoted 5 lines
include/linux/mtd/spi-nor.h enum spi_nor_option_flags {
Quoted 5 lines
include/linux/mtd/spi-nor.h +1
-0* @lock: [FLASH-SPECIFIC] lock a region of the SPI NOR * @unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR * @priv: the private data +* @dn: [BOARD-SPECIFIC] device node describing this
instance
Quoted 3 lines
I might like to see this up near the @dev entry, for organization purposes.
Right, will do in V2.