]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mtd: spi-nor: allow registering multiple MTDs when DM is enabled
authorMarek Behún <marek.behun@nic.cz>
Wed, 26 May 2021 12:08:20 +0000 (14:08 +0200)
committerJagan Teki <jagan@amarulasolutions.com>
Thu, 24 Jun 2021 06:23:31 +0000 (11:53 +0530)
Currently when the SPI_FLASH_MTD config option is enabled, only one SPI
can be registered as MTD at any time - it is the last one probed (since
with old non-DM model only one SPI NOR could be probed at any time).

When DM is enabled, allow for registering multiple SPI NORs as MTDs by
utilizing the nor->mtd structure, which is filled in by spi_nor_scan
anyway, instead of filling a separate struct mtd_info.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
Cc: Priyanka Jain <priyanka.jain@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Heiko Schocher <hs@denx.de>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
drivers/mtd/spi/sf_internal.h
drivers/mtd/spi/sf_mtd.c
drivers/mtd/spi/sf_probe.c

index 786301ba4a95bb46c692d08cce30e557f8c9d6ee..0b63e1bfc27756ca523bed5edc93b56e7fb42574 100644 (file)
@@ -81,14 +81,14 @@ int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash);
 
 #if CONFIG_IS_ENABLED(SPI_FLASH_MTD)
 int spi_flash_mtd_register(struct spi_flash *flash);
-void spi_flash_mtd_unregister(void);
+void spi_flash_mtd_unregister(struct spi_flash *flash);
 #else
 static inline int spi_flash_mtd_register(struct spi_flash *flash)
 {
        return 0;
 }
 
-static inline void spi_flash_mtd_unregister(void)
+static inline void spi_flash_mtd_unregister(struct spi_flash *flash)
 {
 }
 #endif
index 987fac2501f41d76affcb8a3ea0c6eddfd711162..94854fbfc42b989f1d9a2f8a97eb218bcdd40a6f 100644 (file)
 #include <linux/mtd/mtd.h>
 #include <spi_flash.h>
 
+#if CONFIG_IS_ENABLED(DM_SPI_FLASH)
+
+int spi_flash_mtd_register(struct spi_flash *flash)
+{
+       return add_mtd_device(&flash->mtd);
+}
+
+void spi_flash_mtd_unregister(struct spi_flash *flash)
+{
+       del_mtd_device(&flash->mtd);
+}
+
+#else /* !CONFIG_IS_ENABLED(DM_SPI_FLASH) */
+
 static struct mtd_info sf_mtd_info;
 static bool sf_mtd_registered;
 static char sf_mtd_name[8];
@@ -123,7 +137,7 @@ int spi_flash_mtd_register(struct spi_flash *flash)
        return ret;
 }
 
-void spi_flash_mtd_unregister(void)
+void spi_flash_mtd_unregister(struct spi_flash *flash)
 {
        int ret;
 
@@ -146,3 +160,5 @@ void spi_flash_mtd_unregister(void)
        printf("Failed to unregister MTD %s and the spi_flash object is going away: you're in deep trouble!",
               sf_mtd_info.name);
 }
+
+#endif /* !CONFIG_IS_ENABLED(DM_SPI_FLASH) */
index 3befbe91cacb49d9d343543b73044530c9a93fa9..7edb8759fdcb1af9aaac53e15cd94b3741e79b84 100644 (file)
@@ -84,7 +84,7 @@ struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs,
 void spi_flash_free(struct spi_flash *flash)
 {
        if (CONFIG_IS_ENABLED(SPI_FLASH_MTD))
-               spi_flash_mtd_unregister();
+               spi_flash_mtd_unregister(flash);
 
        spi_free_slave(flash->spi);
        free(flash);
@@ -150,8 +150,10 @@ int spi_flash_std_probe(struct udevice *dev)
 
 static int spi_flash_std_remove(struct udevice *dev)
 {
+       struct spi_flash *flash = dev_get_uclass_priv(dev);
+
        if (CONFIG_IS_ENABLED(SPI_FLASH_MTD))
-               spi_flash_mtd_unregister();
+               spi_flash_mtd_unregister(flash);
 
        return 0;
 }