Skip to contentSkip to conversation

mtd: fsl-quadspi: Distinguish the mtd device names

PATCH Superseded Fabio Estevam 3 participants 6 messages Jan 5, 2018 – Jan 10, 2018

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: fsl-quadspi: Distinguish the mtd device names

From: Fabio Estevam <[email protected]>

Currently on a imx6sx-sdb board, which has two SPI NOR chips connected to QSPI2 the following output from /proc/mtd is seen:

# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 01000000 00010000 "21e4000.qspi"
mtd1: 01000000 00010000 "21e4000.qspi"

Attempts to partition them on the kernel command line result in both chips with identical (and identically named) partitions, which is an inconvenient behavior.

Assign a different mtd->name for each mtd device to avoid this problem.

After this change the output from /proc/mtd becomes:

# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 01000000 00010000 "fsl-quadspi.0"
mtd1: 01000000 00010000 "fsl-quadspi.1"
---
 drivers/mtd/spi-nor/fsl-quadspi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/fsl-quadspi.c +9 -1
index f17d224..7712c63 100644
@@ -967,7 +967,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
 	struct resource *res;
 	struct spi_nor *nor;
 	struct mtd_info *mtd;
-	int ret, i = 0;
+	int ret, i = 0, mtd_index = 0;
 
 	q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
 	if (!q)
@@ -1047,6 +1047,13 @@ static int fsl_qspi_probe(struct platform_device *pdev)
 		nor = &q->nor[i];
 		mtd = &nor->mtd;
 
+		mtd->name = devm_kasprintf(dev, GFP_KERNEL, "fsl-quadspi.%d",
+					   mtd_index);
+		if (!mtd->name) {
+			ret = -ENOMEM;
+			goto mutex_failed;
+		}
+
 		nor->dev = dev;
 		spi_nor_set_flash_node(nor, np);
 		nor->priv = q;
@@ -1098,6 +1105,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
 			nor->page_size = q->devtype_data->txfifo;
 
 		i++;
+		mtd_index++;
 	}
 
 	/* finish the rest init. */
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw

________________________________________
From: Fabio Estevam <[email protected]>
Sent: Friday, January 5, 2018 1:46 PM
To: Han Xu
Cc: [email protected]; David Wolfe; Frank Li; [email protected]; Fabio Estevam
Subject: [PATCH] mtd: fsl-quadspi: Distinguish the mtd device names

From: Fabio Estevam <[email protected]>

Currently on a imx6sx-sdb board, which has two SPI NOR chips connected to QSPI2 the following output from /proc/mtd is seen:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "21e4000.qspi"
mtd1: 01000000 00010000 "21e4000.qspi"

Attempts to partition them on the kernel command line result in both chips with identical (and identically named) partitions, which is an inconvenient behavior.

Assign a different mtd->name for each mtd device to avoid this problem.

After this change the output from /proc/mtd becomes:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "fsl-quadspi.0"
mtd1: 01000000 00010000 "fsl-quadspi.1"
---
 drivers/mtd/spi-nor/fsl-quadspi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/fsl-quadspi.c +9 -1
index f17d224..7712c63 100644
@@ -967,7 +967,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
        struct resource *res;
        struct spi_nor *nor;
        struct mtd_info *mtd;
-       int ret, i = 0;
+       int ret, i = 0, mtd_index = 0;
 
        q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
        if (!q)
@@ -1047,6 +1047,13 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                nor = &q->nor[i];
                mtd = &nor->mtd;
 
+               mtd->name = devm_kasprintf(dev, GFP_KERNEL, "fsl-quadspi.%d",
+                                          mtd_index);
+               if (!mtd->name) {
+                       ret = -ENOMEM;
+                       goto mutex_failed;
+               }
+
                nor->dev = dev;
                spi_nor_set_flash_node(nor, np);
                nor->priv = q;
@@ -1098,6 +1105,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                        nor->page_size = q->devtype_data->txfifo;
 
                i++;
+               mtd_index++;
        }
 
        /* finish the rest init. */

--
2.7.4

#2 lore raw
Quoted 21 lines · On Mon, 8 Jan 2018 17:13:17 +0000 Han Xu <[email protected]> wrote:

________________________________________
From: Fabio Estevam <[email protected]>
Sent: Friday, January 5, 2018 1:46 PM
To: Han Xu
Cc: [email protected]; David Wolfe; Frank Li; [email protected]; Fabio Estevam
Subject: [PATCH] mtd: fsl-quadspi: Distinguish the mtd device names

From: Fabio Estevam <[email protected]>

Currently on a imx6sx-sdb board, which has two SPI NOR chips connected to QSPI2 the following output from /proc/mtd is seen:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "21e4000.qspi"
mtd1: 01000000 00010000 "21e4000.qspi"

Attempts to partition them on the kernel command line result in both chips with identical (and identically named) partitions, which is an inconvenient behavior.

Quoted 8 lines

Assign a different mtd->name for each mtd device to avoid this problem.

After this change the output from /proc/mtd becomes:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "fsl-quadspi.0"
mtd1: 01000000 00010000 "fsl-quadspi.1"

What happens if you end up having 2 qspi IPs in the same SoC? IMHO, it's more future proof to have something like "<reg-addr>.qspi:<chipidx>" or "<reg-addr>.qspi:<chipidx>".

Quoted 12 lines
---
 drivers/mtd/spi-nor/fsl-quadspi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/fsl-quadspi.c +0 -0
index f17d224..7712c63 100644

drivers/mtd/spi-nor/fsl-quadspi.c static int fsl_qspi_probe(struct platform_device *pdev) · line 970

Quoted 5 lines
drivers/mtd/spi-nor/fsl-quadspi.c +1 -1
@@ -967,7 +967,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
        struct resource *res;
        struct spi_nor *nor;
        struct mtd_info *mtd;
-       int ret, i = 0;
+       int ret, i = 0, mtd_index = 0;

It's not the MTD index if you have other MTD devices. How about spiflash_idx?

drivers/mtd/spi-nor/fsl-quadspi.c static int fsl_qspi_probe(struct platform_device *pdev) · line 1051

Quoted 9 lines
drivers/mtd/spi-nor/fsl-quadspi.c +2 -0
        q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
        if (!q)
@@ -1047,6 +1047,13 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                nor = &q->nor[i];
                mtd = &nor->mtd;
 
+               mtd->name = devm_kasprintf(dev, GFP_KERNEL, "fsl-quadspi.%d",
+                                          mtd_index);

With the alternative naming scheme suggested above, it gives:

		mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%s:%d"
					   dev_name(&pdev->dev),
					   mtd_index);
Quoted 24 lines
drivers/mtd/spi-nor/fsl-quadspi.c +6 -1
+               if (!mtd->name) {
+                       ret = -ENOMEM;
+                       goto mutex_failed;
+               }
+
                nor->dev = dev;
                spi_nor_set_flash_node(nor, np);
                nor->priv = q;
@@ -1098,6 +1105,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                        nor->page_size = q->devtype_data->txfifo;
 
                i++;
+               mtd_index++;
        }
 
        /* finish the rest init. */
--

2.7.4

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#3 lore raw

Hi Boris,

Quoted 5 lines · Boris Brezillon

With the alternative naming scheme suggested above, it gives:

                mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%s:%d"
                                           dev_name(&pdev->dev),
                                           mtd_index);

Yes, this looks better.

I have made the suggested change. Will test it tomorrow on my board and will send a v2.

Thanks!

#4 lore raw
In reply to Boris Brezillon
Quoted 28 lines · On Wed, 10 Jan 2018 23:17:19 +0100 Boris Brezillon…
Quoted 25 lines · On Mon, 8 Jan 2018 17:13:17 +0000 Han Xu <[email protected]> wrote:

________________________________________
From: Fabio Estevam <[email protected]>
Sent: Friday, January 5, 2018 1:46 PM
To: Han Xu
Cc: [email protected]; David Wolfe; Frank Li; [email protected]; Fabio Estevam
Subject: [PATCH] mtd: fsl-quadspi: Distinguish the mtd device names

From: Fabio Estevam <[email protected]>

Currently on a imx6sx-sdb board, which has two SPI NOR chips connected to QSPI2 the following output from /proc/mtd is seen:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "21e4000.qspi"
mtd1: 01000000 00010000 "21e4000.qspi"

Attempts to partition them on the kernel command line result in both chips with identical (and identically named) partitions, which is an inconvenient behavior.

Assign a different mtd->name for each mtd device to avoid this problem.

After this change the output from /proc/mtd becomes:

Quoted 8 lines
Quoted 4 lines
# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "fsl-quadspi.0"
mtd1: 01000000 00010000 "fsl-quadspi.1"  

What happens if you end up having 2 qspi IPs in the same SoC? IMHO, it's more future proof to have something like "<reg-addr>.qspi:<chipidx>" or "<reg-addr>.qspi:<chipidx>".

Hm, ':' is not a good separator because it's already used by mtdparts, so I suggest using '-' ("<reg-addr>.qspi-<chipid>").

Quoted 29 lines
Quoted 13 lines
---
 drivers/mtd/spi-nor/fsl-quadspi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/fsl-quadspi.c +0 -0
index f17d224..7712c63 100644

drivers/mtd/spi-nor/fsl-quadspi.c static int fsl_qspi_probe(struct platform_device *pdev) · line 970

Quoted 5 lines
drivers/mtd/spi-nor/fsl-quadspi.c +1 -1
@@ -967,7 +967,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
        struct resource *res;
        struct spi_nor *nor;
        struct mtd_info *mtd;
-       int ret, i = 0;
+       int ret, i = 0, mtd_index = 0;  

It's not the MTD index if you have other MTD devices. How about spiflash_idx?

Quoted 7 lines
drivers/mtd/spi-nor/fsl-quadspi.c +0 -0
        q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
        if (!q)
@@ -1047,6 +1047,13 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                nor = &q->nor[i];
                mtd = &nor->mtd;
 
Quoted 8 lines

drivers/mtd/spi-nor/fsl-quadspi.c static int fsl_qspi_probe(struct platform_device *pdev) · line 1051

Quoted 2 lines
drivers/mtd/spi-nor/fsl-quadspi.c +2 -0
+               mtd->name = devm_kasprintf(dev, GFP_KERNEL, "fsl-quadspi.%d",
+                                          mtd_index);  

With the alternative naming scheme suggested above, it gives:

		mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%s:%d"
					   dev_name(&pdev->dev),
					   mtd_index);

I realize your index depends on the order the nodes have been defined in the DT, which is fragile. You should find a better solution to uniquely identify each device connected to the fsl-qspi controller (<busid>.<devid>?) and then have a property describing that (reg?).

Quoted 30 lines
Quoted 20 lines
drivers/mtd/spi-nor/fsl-quadspi.c +6 -1
+               if (!mtd->name) {
+                       ret = -ENOMEM;
+                       goto mutex_failed;
+               }
+
                nor->dev = dev;
                spi_nor_set_flash_node(nor, np);
                nor->priv = q;
@@ -1098,6 +1105,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                        nor->page_size = q->devtype_data->txfifo;
 
                i++;
+               mtd_index++;
        }
 
        /* finish the rest init. */
--

2.7.4

Quoted 5 lines

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#5 lore raw
In reply to Boris Brezillon
Quoted 65 lines · On Wed, 10 Jan 2018 23:17:19 +0100 Boris Brezillon…
Quoted 21 lines · On Mon, 8 Jan 2018 17:13:17 +0000 Han Xu <[email protected]> wrote:

________________________________________
From: Fabio Estevam <[email protected]>
Sent: Friday, January 5, 2018 1:46 PM
To: Han Xu
Cc: [email protected]; David Wolfe; Frank Li; [email protected]; Fabio Estevam
Subject: [PATCH] mtd: fsl-quadspi: Distinguish the mtd device names

From: Fabio Estevam <[email protected]>

Currently on a imx6sx-sdb board, which has two SPI NOR chips connected to QSPI2 the following output from /proc/mtd is seen:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "21e4000.qspi"
mtd1: 01000000 00010000 "21e4000.qspi"

Attempts to partition them on the kernel command line result in both chips with identical (and identically named) partitions, which is an inconvenient behavior.

Quoted 8 lines

Assign a different mtd->name for each mtd device to avoid this problem.

After this change the output from /proc/mtd becomes:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "fsl-quadspi.0"
mtd1: 01000000 00010000 "fsl-quadspi.1"  

What happens if you end up having 2 qspi IPs in the same SoC? IMHO, it's more future proof to have something like "<reg-addr>.qspi:<chipidx>" or "<reg-addr>.qspi:<chipidx>".

Quoted 12 lines
---
 drivers/mtd/spi-nor/fsl-quadspi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/fsl-quadspi.c +0 -0
index f17d224..7712c63 100644

drivers/mtd/spi-nor/fsl-quadspi.c static int fsl_qspi_probe(struct platform_device *pdev) · line 970

Quoted 5 lines
drivers/mtd/spi-nor/fsl-quadspi.c +1 -1
@@ -967,7 +967,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
        struct resource *res;
        struct spi_nor *nor;
        struct mtd_info *mtd;
-       int ret, i = 0;
+       int ret, i = 0, mtd_index = 0;  

It's not the MTD index if you have other MTD devices. How about spiflash_idx?

Quoted 7 lines
drivers/mtd/spi-nor/fsl-quadspi.c +0 -0
        q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
        if (!q)
@@ -1047,6 +1047,13 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                nor = &q->nor[i];
                mtd = &nor->mtd;
 
Quoted 16 lines

drivers/mtd/spi-nor/fsl-quadspi.c static int fsl_qspi_probe(struct platform_device *pdev) · line 1051

Quoted 2 lines
drivers/mtd/spi-nor/fsl-quadspi.c +2 -0
+               mtd->name = devm_kasprintf(dev, GFP_KERNEL, "fsl-quadspi.%d",
+                                          mtd_index);  

With the alternative naming scheme suggested above, it gives:

		mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%s:%d"
					   dev_name(&pdev->dev),
					   mtd_index);
Quoted 7 lines
drivers/mtd/spi-nor/fsl-quadspi.c +5 -0
+               if (!mtd->name) {
+                       ret = -ENOMEM;
+                       goto mutex_failed;
+               }
+
                nor->dev = dev;
                spi_nor_set_flash_node(nor, np);

One, last thing: there's a generic mechanism using the value of the 'label' property for mtd->name, which is particularly useful if one wants to assign user-friendly names to his flashes. This is done in spi_nor_set_flash_node() (more precisely in mtd_set_of_node() which is called by spi_nor_set_flash_node()), but it only works if mtd->name is NULL. So I recommend move the mtd->name assignment here, and making it conditional:

		if (!mtd->name) {
			mtd->name = devm_kasprintf(...);
			...
		}
Quoted 22 lines
Quoted 12 lines
drivers/mtd/spi-nor/fsl-quadspi.c +1 -1
                nor->priv = q;
@@ -1098,6 +1105,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                        nor->page_size = q->devtype_data->txfifo;
 
                i++;
+               mtd_index++;
        }
 
        /* finish the rest init. */
--

2.7.4

Quoted 5 lines

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/