[U-Boot] [PATCH v6 09/76] mtd: spi-nor: Add dm spi-nor probing

Jagan Teki jteki at openedev.com
Mon Feb 15 10:15:50 CET 2016


Hi Masahiro,

On 15 February 2016 at 02:18, Jagan Teki <jteki at openedev.com> wrote:
> This patch adds driver-model probe from cmd_sf through
> MTD_DM_SPI_NOR which is depends on MTD and DM_SPI uclass.
>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Bin Meng <bmeng.cn at gmail.com>
> Cc: Mugunthan V N <mugunthanvnm at ti.com>
> Cc: Michal Simek <michal.simek at xilinx.com>
> Cc: Siva Durga Prasad Paladugu <sivadur at xilinx.com>
> Signed-off-by: Jagan Teki <jteki at openedev.com>
> ---
>  cmd/sf.c                            |  4 ++--
>  common/env_sf.c                     |  4 ++--
>  drivers/mtd/spi-nor/Kconfig         |  5 +++++
>  drivers/mtd/spi-nor/Makefile        |  2 ++
>  drivers/mtd/spi-nor/spi-nor-probe.c | 30 ++++++++++++++++++++++++++++++
>  include/spi_flash.h                 | 11 ++++++++++-
>  6 files changed, 51 insertions(+), 5 deletions(-)
>  create mode 100644 drivers/mtd/spi-nor/spi-nor-probe.c
>
> diff --git a/cmd/sf.c b/cmd/sf.c
> index 42862d9..e4d1274 100644
> --- a/cmd/sf.c
> +++ b/cmd/sf.c
> @@ -85,7 +85,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
>         unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
>         unsigned int mode = CONFIG_SF_DEFAULT_MODE;
>         char *endp;
> -#ifdef CONFIG_DM_SPI_FLASH
> +#if defined(CONFIG_DM_SPI_FLASH) || defined (CONFIG_MTD_DM_SPI_NOR)
>         struct udevice *new, *bus_dev;
>         int ret;
>  #else
> @@ -118,7 +118,7 @@ static int do_spi_flash_probe(int argc, char * const argv[])
>                         return -1;
>         }
>
> -#ifdef CONFIG_DM_SPI_FLASH
> +#if defined(CONFIG_DM_SPI_FLASH) || defined (CONFIG_MTD_DM_SPI_NOR)
>         /* Remove the old device, otherwise probe will just be a nop */
>         ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new);
>         if (!ret) {
> diff --git a/common/env_sf.c b/common/env_sf.c
> index 892e6cb..6d5d847 100644
> --- a/common/env_sf.c
> +++ b/common/env_sf.c
> @@ -52,7 +52,7 @@ int saveenv(void)
>         char    *saved_buffer = NULL, flag = OBSOLETE_FLAG;
>         u32     saved_size, saved_offset, sector = 1;
>         int     ret;
> -#ifdef CONFIG_DM_SPI_FLASH
> +#if defined(CONFIG_DM_SPI_FLASH) || defined (CONFIG_MTD_DM_SPI_NOR)
>         struct udevice *new;
>
>         ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
> @@ -242,7 +242,7 @@ int saveenv(void)
>         char    *saved_buffer = NULL;
>         int     ret = 1;
>         env_t   env_new;
> -#ifdef CONFIG_DM_SPI_FLASH
> +#if defined(CONFIG_DM_SPI_FLASH) || defined (CONFIG_MTD_DM_SPI_NOR)
>         struct udevice *new;
>
>         ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
> diff --git a/drivers/mtd/spi-nor/Kconfig b/drivers/mtd/spi-nor/Kconfig
> index 374cdcb..59bb943 100644
> --- a/drivers/mtd/spi-nor/Kconfig
> +++ b/drivers/mtd/spi-nor/Kconfig
> @@ -1,5 +1,6 @@
>  menuconfig MTD_SPI_NOR
>         tristate "SPI-NOR device support"
> +       select MTD_DM_SPI_NOR
>         help
>           This is the core SPI NOR framework which can be used to interact SPI-NOR
>           to SPI driver interface layer and the SPI-NOR controller driver.
> @@ -12,6 +13,10 @@ menuconfig MTD_SPI_NOR
>           SPI-NOR controller drivers for SPI-NOR device access. Note that from SPI-NOR
>           core to SPI drivers there should be an interface layer.
>
> +config MTD_DM_SPI_NOR
> +       tristate
> +       depends on DM_SPI && MTD
> +

Need some inputs here, my intention was not to add extra config
MTD_DM_SPI_NOR on individual board configs. So  MTD_SPI_NOR is
selecting MTD_DM_SPI_NOR and there MTD_DM_SPI_NOR is depends on DM_SPI
and MTD configs.

1) MTD_DM_SPI_NOR will select only If DM_SPI and MTD defined
2) MTD_DM_SPI_NOR will un-select if DM_SPI or MTD undefined

case 2) here is forcing MTD_DM_SPI_NOR selecting even if DM_SPI or MTD
undefined, any idea how to fix this? I saw the Linux
Documentation/kbuild/kconfig-language.txt have similar issue with
"Adding common features and make the usage configurable" but couldn't
find any solution.

>  if MTD_SPI_NOR
>
>  config MTD_M25P80
> diff --git a/drivers/mtd/spi-nor/Makefile b/drivers/mtd/spi-nor/Makefile
> index 9ab6e3d..71e7ae2 100644
> --- a/drivers/mtd/spi-nor/Makefile
> +++ b/drivers/mtd/spi-nor/Makefile
> @@ -6,6 +6,8 @@
>  ifdef CONFIG_MTD_SPI_NOR
>  obj-y += spi-nor.o
>  obj-y += spi-nor-ids.o
> +
> +obj-$(CONFIG_MTD_DM_SPI_NOR)   += spi-nor-probe.o
>  endif
>
>  obj-$(CONFIG_MTD_M25P80)       += m25p80.o
> diff --git a/drivers/mtd/spi-nor/spi-nor-probe.c b/drivers/mtd/spi-nor/spi-nor-probe.c
> new file mode 100644
> index 0000000..c808a7d
> --- /dev/null
> +++ b/drivers/mtd/spi-nor/spi-nor-probe.c
> @@ -0,0 +1,30 @@
> +/*
> + * Copyright (c) 2014 Google, Inc
> + *
> + * SPDX-License-Identifier:    GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <spi.h>
> +#include <spi_flash.h>
> +
> +int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
> +                          unsigned int max_hz, unsigned int spi_mode,
> +                          struct udevice **devp)
> +{
> +       struct spi_slave *slave;
> +       struct udevice *bus;
> +       char name[30], *str;
> +       int ret;
> +
> +       snprintf(name, sizeof(name), "spi-nor@%d:%d", busnum, cs);
> +       str = strdup(name);
> +       ret = spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode,
> +                                "m25p80", str, &bus, &slave);
> +       if (ret)
> +               return ret;
> +
> +       *devp = slave->dev;
> +       return 0;
> +}
> diff --git a/include/spi_flash.h b/include/spi_flash.h
> index d0ce9e7..db07b99 100644
> --- a/include/spi_flash.h
> +++ b/include/spi_flash.h
> @@ -108,6 +108,14 @@ struct spi_flash {
>  #endif
>  };
>
> +#if defined(CONFIG_MTD_SPI_NOR) && defined(CONFIG_MTD_DM_SPI_NOR)
> +
> +int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
> +                          unsigned int max_hz, unsigned int spi_mode,
> +                          struct udevice **devp);
> +
> +#endif
> +
>  struct dm_spi_flash_ops {
>         int (*read)(struct udevice *dev, u32 offset, size_t len, void *buf);
>         int (*write)(struct udevice *dev, u32 offset, size_t len,
> @@ -190,7 +198,8 @@ int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs,
>
>  void sandbox_sf_unbind_emul(struct sandbox_state *state, int busnum, int cs);
>
> -#else
> +#elif !defined(CONFIG_MTD_SPI_NOR)
> +
>  struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
>                 unsigned int max_hz, unsigned int spi_mode);
>
> --
> 1.9.1
>

thanks!
-- 
Jagan.


More information about the U-Boot mailing list