mtd: spi-nor: Decouple SPI NOR's device_node from controller device
authorMarek Vasut <marex@denx.de>
Thu, 3 Sep 2015 16:35:36 +0000 (18:35 +0200)
committerBrian Norris <computersforpeace@gmail.com>
Fri, 11 Sep 2015 22:48:21 +0000 (15:48 -0700)
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>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
drivers/mtd/devices/m25p80.c
drivers/mtd/spi-nor/fsl-quadspi.c
drivers/mtd/spi-nor/nxp-spifi.c
drivers/mtd/spi-nor/spi-nor.c
include/linux/mtd/spi-nor.h

index b6bc9a2a5f872d3dce2811d1e92e00fd96ccf202..05bf0d71abeaa86c741110259c0c3d181fd11b75 100644 (file)
@@ -200,6 +200,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;
        nor->priv = flash;
 
        spi_set_drvdata(spi, flash);
index f28dcc1cd63ff69e563bfaaecfe00266b6155ee6..f72483247c759cd6a768f415dd1b187489312e66 100644 (file)
@@ -1013,6 +1013,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                mtd = &nor->mtd;
 
                nor->dev = dev;
+               nor->flash_node = np;
                nor->priv = q;
 
                /* fill the hooks */
index 0f6b452574bd43fd31beb17ef860b8dfade514a7..ce7bf6b2916b821498175103d602636c2e76685f 100644 (file)
@@ -331,6 +331,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;
        spifi->nor.priv  = spifi;
        spifi->nor.read  = nxp_spifi_read;
        spifi->nor.write = nxp_spifi_write;
index 55c67a4ea2311e135e5708e2b8a340a2fff24b01..22cca87db9caea289519e65d26dad1e28f0ddcb6 100644 (file)
@@ -1005,7 +1005,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;
 
index 495433d3f56d5f9b631d23f9e3166eb42fbd1c0f..6379e107f2e58b8f128e4bced00f2ac50dea9163 100644 (file)
@@ -134,6 +134,7 @@ 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
@@ -165,6 +166,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;
This page took 0.054311 seconds and 5 git commands to generate.