* [PATCH V2 1/2] mtd: spi-nor: Decouple SPI NOR's device_node from controller device
@ 2015-09-03 16:35 Marek Vasut
2015-09-03 16:35 ` [PATCH 2/2] mtd: nand: Rename nand_chip .dn to .flash_node Marek Vasut
2015-09-11 22:50 ` [PATCH V2 1/2] mtd: spi-nor: Decouple SPI NOR's device_node from controller device Brian Norris
0 siblings, 2 replies; 3+ messages in thread
From: Marek Vasut @ 2015-09-03 16:35 UTC (permalink / raw)
To: linux-mtd; +Cc: Jonas Gorski, Marek Vasut, Brian Norris
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->of_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->of_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
.flash_node element. This let's the SPI NOR controller drivers set up
a different spi_nor .flash_node 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 .flash_node element.
This patch is inspired by 5844feeaa4154d1c46d3462c7a4653d22356d8b4
mtd: nand: add common DT init code
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Brian Norris <computersforpeace@gmail.com>
---
drivers/mtd/devices/m25p80.c | 1 +
drivers/mtd/spi-nor/fsl-quadspi.c | 1 +
drivers/mtd/spi-nor/nxp-spifi.c | 1 +
drivers/mtd/spi-nor/spi-nor.c | 2 +-
include/linux/mtd/spi-nor.h | 2 ++
5 files changed, 6 insertions(+), 1 deletion(-)
V2: - Rename .dn to .flash_node
- Add missing change to spi-nor.c
- Fix build issue in m25p80, where there was one deref. too much
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 9cd3631..dfd5cf2 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -202,6 +202,7 @@ static int m25p_probe(struct spi_device *spi)
nor->dev = &spi->dev;
nor->mtd = &flash->mtd;
+ nor->flash_node = spi->dev.of_node;
nor->priv = flash;
spi_set_drvdata(spi, flash);
diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
index d32b7e0..5b4cacc 100644
--- a/drivers/mtd/spi-nor/fsl-quadspi.c
+++ b/drivers/mtd/spi-nor/fsl-quadspi.c
@@ -1017,6 +1017,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
nor->mtd = mtd;
nor->dev = dev;
+ nor->flash_node = np;
nor->priv = q;
mtd->priv = nor;
diff --git a/drivers/mtd/spi-nor/nxp-spifi.c b/drivers/mtd/spi-nor/nxp-spifi.c
index 9ad1dd0..7c48616 100644
--- a/drivers/mtd/spi-nor/nxp-spifi.c
+++ b/drivers/mtd/spi-nor/nxp-spifi.c
@@ -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.flash_node = np;
spifi->nor.priv = spifi;
spifi->nor.read = nxp_spifi_read;
spifi->nor.write = nxp_spifi_write;
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 39a6a34..0734478 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1026,7 +1026,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 = dev->of_node;
+ struct device_node *np = nor->flash_node;
int ret;
int i;
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 1bf6f11..67a6320 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -142,6 +142,7 @@ enum spi_nor_option_flags {
* @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
@@ -174,6 +175,7 @@ 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;
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] mtd: nand: Rename nand_chip .dn to .flash_node
2015-09-03 16:35 [PATCH V2 1/2] mtd: spi-nor: Decouple SPI NOR's device_node from controller device Marek Vasut
@ 2015-09-03 16:35 ` Marek Vasut
2015-09-11 22:50 ` [PATCH V2 1/2] mtd: spi-nor: Decouple SPI NOR's device_node from controller device Brian Norris
1 sibling, 0 replies; 3+ messages in thread
From: Marek Vasut @ 2015-09-03 16:35 UTC (permalink / raw)
To: linux-mtd; +Cc: Jonas Gorski, Marek Vasut, Brian Norris
Use a more descriptive name for the device_node element in struct nand_chip .
This name matches the element name used for device_node property of a flash
in the spi-nor framework.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Brian Norris <computersforpeace@gmail.com>
---
drivers/mtd/nand/brcmnand/brcmnand.c | 5 +++--
drivers/mtd/nand/nand_base.c | 4 ++--
include/linux/mtd/nand.h | 4 ++--
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index fddb795..048e4e0 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -1792,7 +1792,8 @@ static int brcmnand_setup_dev(struct brcmnand_host *host)
memset(cfg, 0, sizeof(*cfg));
- ret = of_property_read_u32(chip->dn, "brcm,nand-oob-sector-size",
+ ret = of_property_read_u32(chip->flash_node,
+ "brcm,nand-oob-sector-size",
&oob_sector);
if (ret) {
/* Use detected size */
@@ -1899,7 +1900,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host)
mtd = &host->mtd;
chip = &host->chip;
- chip->dn = dn;
+ chip->flash_node = dn;
chip->priv = host;
mtd->priv = chip;
mtd->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "brcmnand.%d",
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ceb68ca..51f7816 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3846,8 +3846,8 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
struct nand_flash_dev *type;
int ret;
- if (chip->dn) {
- ret = nand_dt_init(mtd, chip, chip->dn);
+ if (chip->flash_node) {
+ ret = nand_dt_init(mtd, chip, chip->flash_node);
if (ret)
return ret;
}
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 272f429..3140b3d 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -544,7 +544,7 @@ struct nand_buffers {
* flash device
* @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the
* flash device.
- * @dn: [BOARDSPECIFIC] device node describing this instance
+ * @flash_node: [BOARDSPECIFIC] device node describing this instance
* @read_byte: [REPLACEABLE] read one byte from the chip
* @read_word: [REPLACEABLE] read one word from the chip
* @write_byte: [REPLACEABLE] write a single byte to the chip on the
@@ -647,7 +647,7 @@ struct nand_chip {
void __iomem *IO_ADDR_R;
void __iomem *IO_ADDR_W;
- struct device_node *dn;
+ struct device_node *flash_node;
uint8_t (*read_byte)(struct mtd_info *mtd);
u16 (*read_word)(struct mtd_info *mtd);
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH V2 1/2] mtd: spi-nor: Decouple SPI NOR's device_node from controller device
2015-09-03 16:35 [PATCH V2 1/2] mtd: spi-nor: Decouple SPI NOR's device_node from controller device Marek Vasut
2015-09-03 16:35 ` [PATCH 2/2] mtd: nand: Rename nand_chip .dn to .flash_node Marek Vasut
@ 2015-09-11 22:50 ` Brian Norris
1 sibling, 0 replies; 3+ messages in thread
From: Brian Norris @ 2015-09-11 22:50 UTC (permalink / raw)
To: Marek Vasut; +Cc: linux-mtd, Jonas Gorski
On Thu, Sep 03, 2015 at 06:35:36PM +0200, Marek Vasut wrote:
> 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->of_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->of_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
> .flash_node element. This let's the SPI NOR controller drivers set up
> a different spi_nor .flash_node 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 .flash_node element.
>
> This patch is inspired by 5844feeaa4154d1c46d3462c7a4653d22356d8b4
> mtd: nand: add common DT init code
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Brian Norris <computersforpeace@gmail.com>
> ---
> drivers/mtd/devices/m25p80.c | 1 +
> drivers/mtd/spi-nor/fsl-quadspi.c | 1 +
> drivers/mtd/spi-nor/nxp-spifi.c | 1 +
> drivers/mtd/spi-nor/spi-nor.c | 2 +-
> include/linux/mtd/spi-nor.h | 2 ++
> 5 files changed, 6 insertions(+), 1 deletion(-)
>
> V2: - Rename .dn to .flash_node
> - Add missing change to spi-nor.c
> - Fix build issue in m25p80, where there was one deref. too much
Pushed both to l2-mtd.git/next
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-09-11 22:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-03 16:35 [PATCH V2 1/2] mtd: spi-nor: Decouple SPI NOR's device_node from controller device Marek Vasut
2015-09-03 16:35 ` [PATCH 2/2] mtd: nand: Rename nand_chip .dn to .flash_node Marek Vasut
2015-09-11 22:50 ` [PATCH V2 1/2] mtd: spi-nor: Decouple SPI NOR's device_node from controller device Brian Norris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).