[U-Boot] mtd; spi-nor: Probing dual uclass drivers from cmd

Simon Glass sjg at chromium.org
Sat Apr 9 20:34:36 CEST 2016


Hi Jagan,

On 17 March 2016 at 11:54, Jagan Teki <jagannadh.teki at gmail.com> wrote:
> Hi Simon and All,
>
> SPI-NOR with MTD uclass framework, we need to probe the two different
> uclass drivers from command like UCLASS_SPI and UCLASS_MTD
>
> UCLASS_SPI: will detect the spi drivers from drivers/spi and probe the
> m25p80 flash
> UCLASS_MTD: will detect the spi-nor drivers from drivers/mtd/spi-nor
> and probe the flash.
> like this:
> spi0 = &spi1;
> mtd1 = &qspi;
>
> I have written a sample routine to move the respective frameworks like
> spi and spi-nor, so based on the command bus number the respective
> driver need to probe.
>
> Issue here is if I use 'sf probe 1' it's probing the MTD uclass but
> the UCLASS_SPI error message is showing as "Invalid bus 0"
>
> Did you ever handling this kind of dual probe? I couldn't find it on
> the source?  any suggestions?

It suggests something is wrong IMO. To be honest I've struggled to
understand all this SPI/MTD stuff. I'd love to see how we can get rid
of the non-driver-model SPI flash code as there seems to be a lot of
churn going on.

Didn't you change SPI to use the MTD uclass? I can't keep up :-)

>
> sample code:
> --------------------
> 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 dm_mtd_ops *ops;
>     struct udevice *bus;
>     char name[30], *str;
>     int ret;
>
>     printf("Probe for SPI\n");
>     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) {
>         *devp = slave->dev;
>         return 0;
>     }
>
>     printf("Probe for MTD\n");
>     ret = uclass_get_device_by_seq(UCLASS_MTD, busnum, &bus);
>     if (ret) {
>         printf("Invalid bus %d (err=%d)\n", busnum, ret);
>         return ret;
>     }
>
>     ops = mtd_get_ops(bus);
>     ret = ops->probe_dev(bus);
>     if (ret)
>         return ret;
>
>     *devp = bus;
>     return 0;
> }
>
> --
> Jagan.

Regards,
Simon


More information about the U-Boot mailing list