Skip to contentSkip to conversation

mtd: fsl-quadspi: Distinguish the mtd device names

PATCH RESEND In review Fabio Estevam 2 participants 5 messages Jan 26, 2018 – Mar 15, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND v6 1/2 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 "21e4000.qspi-0"
mtd1: 01000000 00010000 "21e4000.qspi-1"

In order to keep mtdparts compatibility keep the mtd->name unchanged when a single SPI NOR is present.

---
Resending it as I missed to send it to Cyrille

Changes since v5:
- Preserve the label value, if any. (Boris)

 drivers/mtd/spi-nor/fsl-quadspi.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/mtd/spi-nor/fsl-quadspi.c +18 -0
index 2901c7b..1038842 100644
@@ -1051,6 +1051,24 @@ static int fsl_qspi_probe(struct platform_device *pdev)
 		spi_nor_set_flash_node(nor, np);
 		nor->priv = q;
 
+		if (q->nor_num > 1 && !mtd->name) {
+			int spiflash_idx;
+
+			ret = of_property_read_u32(np, "reg", &spiflash_idx);
+			if (!ret) {
+				mtd->name = devm_kasprintf(dev, GFP_KERNEL,
+							   "%s-%d",
+							   dev_name(dev),
+							   spiflash_idx);
+				if (!mtd->name) {
+					ret = -ENOMEM;
+					goto mutex_failed;
+				}
+			} else {
+				dev_warn(dev, "reg property is missing\n");
+			}
+		}
+
 		/* fill the hooks */
 		nor->read_reg = fsl_qspi_read_reg;
 		nor->write_reg = fsl_qspi_write_reg;
Signature · 1 line
2.7.4
#1 lore raw

PATCH RESEND v6 2/2 dt-bindings: fsl-quadspi: Add the example of two SPI NOR

From: Fabio Estevam <[email protected]>

Improve the bindings example by adding an example of how to represent two SPI NOR devices.

---
Resending it as I missed to send it to Cyrille

Changes since v5:
- None

 .../devicetree/bindings/mtd/fsl-quadspi.txt        | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Documentation/devicetree/bindings/mtd/fsl-quadspi.txt +24 -0
index 63d4d626..483e9cf 100644
@@ -39,3 +39,27 @@ qspi0: quadspi@40044000 {
 		....
 	};
 };
+
+Example showing the usage of two SPI NOR devices:
+
+&qspi2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_qspi2>;
+	status = "okay";
+
+	flash0: n25q256a@0 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "micron,n25q256a", "jedec,spi-nor";
+		spi-max-frequency = <29000000>;
+		reg = <0>;
+	};
+
+	flash1: n25q256a@1 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "micron,n25q256a", "jedec,spi-nor";
+		spi-max-frequency = <29000000>;
+		reg = <1>;
+	};
+};
Signature · 1 line
2.7.4
#2 lore raw
In reply to Fabio Estevam

Hi Cyrille,

Quoted 26 lines · Fabio Estevam

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 "21e4000.qspi-0"
mtd1: 01000000 00010000 "21e4000.qspi-1"

In order to keep mtdparts compatibility keep the mtd->name unchanged when a single SPI NOR is present.

Quoted 6 lines

---
Resending it as I missed to send it to Cyrille

A gentle ping on this series.

Quoted 39 lines

Changes since v5:
- Preserve the label value, if any. (Boris)

 drivers/mtd/spi-nor/fsl-quadspi.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/mtd/spi-nor/fsl-quadspi.c +18 -1
index 2901c7b..1038842 100644
@@ -1051,6 +1051,24 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                spi_nor_set_flash_node(nor, np);
                nor->priv = q;
 
+               if (q->nor_num > 1 && !mtd->name) {
+                       int spiflash_idx;
+
+                       ret = of_property_read_u32(np, "reg", &spiflash_idx);
+                       if (!ret) {
+                               mtd->name = devm_kasprintf(dev, GFP_KERNEL,
+                                                          "%s-%d",
+                                                          dev_name(dev),
+                                                          spiflash_idx);
+                               if (!mtd->name) {
+                                       ret = -ENOMEM;
+                                       goto mutex_failed;
+                               }
+                       } else {
+                               dev_warn(dev, "reg property is missing\n");
+                       }
+               }
+
                /* fill the hooks */
                nor->read_reg = fsl_qspi_read_reg;
                nor->write_reg = fsl_qspi_write_reg;
--

2.7.4

#3 lore raw

Hi Cyrille,

Any chance to get this one applied to 4.17?

Quoted 77 lines · Fabio Estevam

Hi Cyrille,

Quoted 26 lines · Fabio Estevam

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 "21e4000.qspi-0"
mtd1: 01000000 00010000 "21e4000.qspi-1"

In order to keep mtdparts compatibility keep the mtd->name unchanged when a single SPI NOR is present.

Quoted 6 lines

---
Resending it as I missed to send it to Cyrille

A gentle ping on this series.

Quoted 39 lines

Changes since v5:
- Preserve the label value, if any. (Boris)

 drivers/mtd/spi-nor/fsl-quadspi.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/mtd/spi-nor/fsl-quadspi.c +18 -1
index 2901c7b..1038842 100644
@@ -1051,6 +1051,24 @@ static int fsl_qspi_probe(struct platform_device *pdev)
                spi_nor_set_flash_node(nor, np);
                nor->priv = q;
 
+               if (q->nor_num > 1 && !mtd->name) {
+                       int spiflash_idx;
+
+                       ret = of_property_read_u32(np, "reg", &spiflash_idx);
+                       if (!ret) {
+                               mtd->name = devm_kasprintf(dev, GFP_KERNEL,
+                                                          "%s-%d",
+                                                          dev_name(dev),
+                                                          spiflash_idx);
+                               if (!mtd->name) {
+                                       ret = -ENOMEM;
+                                       goto mutex_failed;
+                               }
+                       } else {
+                               dev_warn(dev, "reg property is missing\n");
+                       }
+               }
+
                /* fill the hooks */
                nor->read_reg = fsl_qspi_read_reg;
                nor->write_reg = fsl_qspi_write_reg;
--

2.7.4

#4 lore raw
In reply to Fabio Estevam

Le 26/01/2018 à 22:23, Fabio Estevam a écrit :

Quoted 23 lines

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 "21e4000.qspi-0"
mtd1: 01000000 00010000 "21e4000.qspi-1"
Quoted 7 lines

In order to keep mtdparts compatibility keep the mtd->name unchanged when a single SPI NOR is present.

Series applied to the spi-nor/next branch of linux-mtd

Thanks!