[PATCH u-boot-dm + u-boot-spi v3 05/11] mtd: spi-nor: allow registering multiple MTDs when DM is enabled

Miquel Raynal miquel.raynal at bootlin.com
Thu Feb 25 16:51:56 CET 2021


Hi Marek,

Marek Behún <marek.behun at nic.cz> wrote on Thu, 25 Feb 2021 15:13:30
+0100:

> 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 at nic.cz>
> Reviewed-by: Pali Rohár <pali at kernel.org>
> Cc: Jagan Teki <jagan at amarulasolutions.com>
> Cc: Priyanka Jain <priyanka.jain at nxp.com>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Heiko Schocher <hs at denx.de>
> Cc: Jagan Teki <jagan at amarulasolutions.com>
> Cc: Patrick Delaunay <patrick.delaunay at st.com>
> Cc: Patrice CHOTARD <patrice.chotard at foss.st.com>
> Cc: Miquel Raynal <miquel.raynal at bootlin.com>
> ---
>  drivers/mtd/spi/sf_internal.h |  4 ++--
>  drivers/mtd/spi/sf_mtd.c      | 18 +++++++++++++++++-
>  drivers/mtd/spi/sf_probe.c    |  6 ++++--
>  3 files changed, 23 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
> index 9ceff0e7c1..865955124c 100644
> --- a/drivers/mtd/spi/sf_internal.h
> +++ b/drivers/mtd/spi/sf_internal.h
> @@ -77,14 +77,14 @@ extern const struct flash_info spi_nor_ids[];
>  
>  #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
> diff --git a/drivers/mtd/spi/sf_mtd.c b/drivers/mtd/spi/sf_mtd.c
> index 987fac2501..94854fbfc4 100644
> --- a/drivers/mtd/spi/sf_mtd.c
> +++ b/drivers/mtd/spi/sf_mtd.c
> @@ -10,6 +10,20 @@
>  #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) */
> +

I actually started something to overcome the same issue but left it
aside waiting for more inspiration. Your approach is neat, thanks for
pushing this!

Thanks,
Miquèl


More information about the U-Boot mailing list