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

Jagan Teki jagannadh.teki at gmail.com
Thu Mar 17 18:54:04 CET 2016


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?

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.


More information about the U-Boot mailing list