[RESEND,v6,1/2] mtd: fsl-quadspi: Distinguish the mtd device names

Message ID 1517001805-7646-1-git-send-email-festevam@gmail.com
State Accepted
Delegated to: Cyrille Pitchen
Headers show
Series
  • [RESEND,v6,1/2] mtd: fsl-quadspi: Distinguish the mtd device names
Related show

Commit Message

Fabio Estevam Jan. 26, 2018, 9:23 p.m.
From: Fabio Estevam <fabio.estevam@nxp.com>

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.

Reported-by: David Wolfe <david.wolfe@nxp.com>
Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Han Xu <han.xu@nxp.com>
---
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(+)

Comments

Fabio Estevam Feb. 14, 2018, 1:47 a.m. | #1
Hi Cyrille,

On Fri, Jan 26, 2018 at 7:23 PM, Fabio Estevam <festevam@gmail.com> wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
>
> 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.
>
> Reported-by: David Wolfe <david.wolfe@nxp.com>
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
> Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Han Xu <han.xu@nxp.com>
> ---
> Resending it as I missed to send it to Cyrille

 A gentle ping on this series.

>
> Changes since v5:
> - Preserve the label value, if any. (Boris)
>
>  drivers/mtd/spi-nor/fsl-quadspi.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
> index 2901c7b..1038842 100644
> --- a/drivers/mtd/spi-nor/fsl-quadspi.c
> +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
> @@ -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
>
Fabio Estevam March 15, 2018, 1:02 p.m. | #2
Hi Cyrille,

Any chance to get this one applied to 4.17?

On Tue, Feb 13, 2018 at 11:47 PM, Fabio Estevam <festevam@gmail.com> wrote:
> Hi Cyrille,
>
> On Fri, Jan 26, 2018 at 7:23 PM, Fabio Estevam <festevam@gmail.com> wrote:
>> From: Fabio Estevam <fabio.estevam@nxp.com>
>>
>> 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.
>>
>> Reported-by: David Wolfe <david.wolfe@nxp.com>
>> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
>> Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
>> Acked-by: Han Xu <han.xu@nxp.com>
>> ---
>> Resending it as I missed to send it to Cyrille
>
>  A gentle ping on this series.
>
>>
>> Changes since v5:
>> - Preserve the label value, if any. (Boris)
>>
>>  drivers/mtd/spi-nor/fsl-quadspi.c | 18 ++++++++++++++++++
>>  1 file changed, 18 insertions(+)
>>
>> diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
>> index 2901c7b..1038842 100644
>> --- a/drivers/mtd/spi-nor/fsl-quadspi.c
>> +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
>> @@ -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
>>
Cyrille Pitchen March 15, 2018, 6:58 p.m. | #3
Le 26/01/2018 à 22:23, Fabio Estevam a écrit :
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> 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.
> 
> Reported-by: David Wolfe <david.wolfe@nxp.com>
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
> Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Han Xu <han.xu@nxp.com>

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

Thanks!

Patch

diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
index 2901c7b..1038842 100644
--- a/drivers/mtd/spi-nor/fsl-quadspi.c
+++ b/drivers/mtd/spi-nor/fsl-quadspi.c
@@ -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;