@@ -3715,8 +3715,10 @@ int spi_nor_scan(struct spi_nor *nor)
if (ret)
return ret;
- if (!mtd->name)
- mtd->name = info->name;
+ if (!mtd->name) {
+ sprintf(nor->mtd_name, "nor%d", dev_seq(nor->dev));
+ mtd->name = nor->mtd_name;
+ }
mtd->dev = nor->dev;
mtd->priv = nor;
mtd->type = MTD_NORFLASH;
@@ -3821,7 +3823,7 @@ int spi_nor_scan(struct spi_nor *nor)
nor->rdsr_dummy = params.rdsr_dummy;
nor->rdsr_addr_nbytes = params.rdsr_addr_nbytes;
- nor->name = mtd->name;
+ nor->name = info->name;
nor->size = mtd->size;
nor->erase_size = mtd->erasesize;
nor->sector_size = mtd->erasesize;
@@ -561,6 +561,7 @@ struct spi_nor {
int (*ready)(struct spi_nor *nor);
void *priv;
+ char mtd_name[10];
/* Compatibility for spi_flash, remove once sf layer is merged with mtd */
const char *name;
u32 size;
Force the mtd name of spi-nor to "nor" + the driver sequence number: "nor0", "nor1"... This patch is coherent with existing "nand" and "spi-nand" mtd device names. I keep the existing "nor" name to don't disturb the existing users of mtd functions. The mtd name 'nor' was configured previously by the function drivers/mtd/spi/sf_mtd.c:spi_flash_mtd_register() = "nor%d" + spi_flash_mtd_number() The 'nor' name is also coherent with get_mtd_info() and the macro MTD_DEV_TYPE(): MTD_DEV_TYPE_NOR is associated with "nor" name. This generic name can be use to identify the mtd spi-nor device without knowing the real device name or the DT path of the device, used with API get_mtd_device_nm(). And also avoid issue when the same NOR device is present 2 times, for example on STM32MP15F-EV1: STM32MP> mtd list SF: Detected mx66l51235l with page size 256 Bytes, erase size 64 KiB, \ total 64 MiB List of MTD devices: * nand0 - type: NAND flash - block size: 0x40000 bytes - min I/O: 0x1000 bytes - OOB size: 224 bytes - OOB available: 118 bytes - ECC strength: 8 bits - ECC step size: 512 bytes - bitflip threshold: 6 bits - 0x000000000000-0x000040000000 : "nand0" * mx66l51235l - device: mx66l51235l@0 - parent: spi@58003000 - driver: jedec_spi_nor - path: /soc/spi@58003000/mx66l51235l@0 - type: NOR flash - block size: 0x10000 bytes - min I/O: 0x1 bytes - 0x000000000000-0x000004000000 : "mx66l51235l" * mx66l51235l - device: mx66l51235l@1 - parent: spi@58003000 - driver: jedec_spi_nor - path: /soc/spi@58003000/mx66l51235l@1 - type: NOR flash - block size: 0x10000 bytes - min I/O: 0x1 bytes - 0x000000000000-0x000004000000 : "mx66l51235l" The same mtd name "mx66l51235l" identify the 2 instance mx66l51235l@0 and mx66l51235l@1. This patch solves a ST32CubeProgrammer / stm32prog command issue with nor0 target on STM32MP157C-EV1 board. Fixes: b7f060565e31 ("mtd: spi-nor: allow registering multiple MTDs when DM is enabled") Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> --- For other device, the mtd name are hardcoded in each MTD driver: drivers/mtd/nand/spi/core.c:1169: sprintf(mtd->name, "spi-nand%d", spi_nand_idx++); drivers/mtd/nand/raw/nand.c:59: sprintf(dev_name[devnum], "nand%d", devnum); The existing user with "nor..." arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c:625: mtd = get_mtd_device_nm(mtd_id); board/emulation/common/qemu_mtdparts.c:63: mtd = get_mtd_device_nm("nor0"); board/emulation/common/qemu_mtdparts.c:70: mtd = get_mtd_device_nm("nor1"); board/emulation/common/qemu_dfu.c:61: mtd = get_mtd_device_nm("nor0"); board/st/common/stm32mp_dfu.c:132: mtd = get_mtd_device_nm("nor0"); drivers/dfu/dfu_mtd.c:259: mtd = get_mtd_device_nm(devstr); => see "dfu mtd" support in doc/usage/dfu.rst Changes in v2: - update commit message, change invalid patman tag "Series-Cc" drivers/mtd/spi/spi-nor-core.c | 8 +++++--- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-)