[U-Boot] [PATCH v2 1/3] sf: Add dm_spi_flash_probe

Simon Glass sjg at chromium.org
Thu Nov 5 19:25:15 CET 2015


Hi Jagan,

On 23 October 2015 at 21:54, Jagan Teki <jteki at openedev.com> wrote:
> Updated dm-spi-flash probe using dm_spi_flash_probe.
>
> Cc: Simon Glass <sjg at chromium.org>
> Signed-off-by: Jagan Teki <jteki at openedev.com>
> ---
> Changes for v2:
>         - none
>
>  common/cmd_sf.c             | 23 ++++-------------------
>  drivers/mtd/spi/sf-uclass.c | 27 ++++++++++++++++++++++++++-
>  include/spi_flash.h         |  5 ++---
>  3 files changed, 32 insertions(+), 23 deletions(-)
>
> diff --git a/common/cmd_sf.c b/common/cmd_sf.c
> index ac7f5df..f1926e3 100644
> --- a/common/cmd_sf.c
> +++ b/common/cmd_sf.c
> @@ -8,7 +8,6 @@
>
>  #include <common.h>
>  #include <div64.h>
> -#include <dm.h>
>  #include <malloc.h>
>  #include <mapmem.h>
>  #include <spi.h>
> @@ -17,7 +16,6 @@
>  #include <linux/mtd/mtd.h>
>
>  #include <asm/io.h>
> -#include <dm/device-internal.h>
>
>  static struct spi_flash *flash;
>
> @@ -85,10 +83,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
> -       struct udevice *new, *bus_dev;
> -       int ret;
> -#else
> +#ifndef CONFIG_DM_SPI_FLASH
>         struct spi_flash *new;
>  #endif
>
> @@ -119,21 +114,11 @@ static int do_spi_flash_probe(int argc, char * const argv[])
>         }
>
>  #ifdef CONFIG_DM_SPI_FLASH
> -       /* Remove the old device, otherwise probe will just be a nop */
> -       ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new);
> -       if (!ret) {
> -               device_remove(new);
> -               device_unbind(new);
> -       }
> -       flash = NULL;
> -       ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new);
> -       if (ret) {
> -               printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
> -                      bus, cs, ret);
> +       flash = dm_spi_flash_probe(bus, cs, speed, mode);
> +       if (!flash) {
> +               printf("Failed to initialize SPI flash at %u:%u\n", bus, cs);
>                 return 1;
>         }
> -
> -       flash = dev_get_uclass_priv(new);
>  #else
>         if (flash)
>                 spi_flash_free(flash);
> diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
> index 350e21a..9c109fa 100644
> --- a/drivers/mtd/spi/sf-uclass.c
> +++ b/drivers/mtd/spi/sf-uclass.c
> @@ -47,7 +47,7 @@ void spi_flash_free(struct spi_flash *flash)
>         spi_flash_remove(flash->spi->dev);
>  }
>
> -int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
> +static int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
>                            unsigned int max_hz, unsigned int spi_mode,
>                            struct udevice **devp)
>  {
> @@ -67,6 +67,31 @@ int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
>         return 0;
>  }
>
> +struct spi_flash *dm_spi_flash_probe(unsigned int busnum, unsigned int cs,
> +                               unsigned int max_hz, unsigned int spi_mode)

This is a probe function....

> +{
> +       struct udevice *bus, *new;
> +       struct spi_flash *flash;
> +       int ret;
> +
> +       /* Remove the old device, otherwise probe will just be a nop */
> +       ret = spi_find_bus_and_cs(busnum, cs, &bus, &new);
> +       if (!ret) {
> +               device_remove(new);
> +               device_unbind(new);
> +       }

But it starts by removing a device. The probe function should probe, only.

> +       flash = NULL;
> +
> +       ret = spi_flash_probe_bus_cs(busnum, cs, max_hz, spi_mode, &new);
> +       if (ret) {
> +               printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
> +                      busnum, cs, ret);
> +               return flash;
> +       }
> +
> +       return dev_get_uclass_priv(new);
> +}
> +
>  int spi_flash_remove(struct udevice *dev)
>  {
>         return device_remove(dev);
> diff --git a/include/spi_flash.h b/include/spi_flash.h
> index 3b2d555..5abbf99 100644
> --- a/include/spi_flash.h
> +++ b/include/spi_flash.h
> @@ -154,9 +154,8 @@ int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
>   */
>  int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len);
>
> -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_flash *dm_spi_flash_probe(unsigned int busnum, unsigned int cs,
> +                               unsigned int max_hz, unsigned int spi_mode);
>
>  /* Compatibility function - this is the old U-Boot API */
>  struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
> --
> 1.9.1
>

Regards,
Simon


More information about the U-Boot mailing list