[U-Boot] [PATCH v7 12/34] sf: probe: Use spi_flash_scan in dm-spi-flash

Jagan Teki
2015-11-26T19:10:46Z

Hi Simon,

On 26 November 2015 at 23:20, Simon Glass <sjg@chromium.org> wrote:
> Hi Jagan,
>
> On 26 November 2015 at 04:03, Jagan Teki <jteki@openedev.com> wrote:
>> This patch add support to use spi_flash_scan in
>> dm-spi-flash probe, so-that it can access
>> the spi_flash functionalities same as non-dm sf probe.
>>
>> Signed-off-by: Jagan Teki <jteki@openedev.com>
>> ---
>> drivers/mtd/spi/sf_probe.c | 28 +++++++++++++++++++++++++---
>> 1 file changed, 25 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
>> index f2e210d..60856f9 100644
>> --- a/drivers/mtd/spi/sf_probe.c
>> +++ b/drivers/mtd/spi/sf_probe.c
>> @@ -137,14 +137,36 @@ int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
>>
>> int spi_flash_std_probe(struct udevice *dev)
>> {
>> - struct spi_slave *slave = dev_get_parent_priv(dev);
>> struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
>> + struct spi_slave *slave = dev_get_parent_priv(dev);
>> struct spi_flash *flash;
>> + int ret;
>> +
>> + debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
>>
>> flash = dev_get_uclass_priv(dev);
>> flash->dev = dev;
>> - debug("%s: slave=%p, cs=%d\n", __func__, slave, plat->cs);
>> - return spi_flash_probe_slave(slave, flash);
>> +
>> + /* Claim spi bus */
>> + ret = spi_claim_bus(slave);
>> + if (ret) {
>> + debug("SF: Failed to claim SPI bus: %d\n", ret);
>> + return ret;
>> + }
>> +
>> + ret = spi_flash_scan(slave, flash);
>> + if (ret) {
>> + ret = -EINVAL;
>> + goto err_read_id;
>> + }
>> +
>> +#ifdef CONFIG_SPI_FLASH_MTD
>> + ret = spi_flash_mtd_register(flash);
>> +#endif
>
> But you can't call this from driver model code. As far as I can see
> the MTD layer does not support driver model. You are going to create a
> plate of spaghetti and it will be a big job to untangle it.

This call is same as before, SPI_FLASH_MTD is not exactly a MTD core
it's an internal mtd driver for sf that in turn call mtd core and
anyway this will replaced with add_mtd_device coming patches.

And why can't we call mtd from here? because mtd core requires fill
mtd structure form respective flash layers like sf, nand and cfi.

>
>
>> +
>> +err_read_id:
>> + spi_release_bus(slave);
>> + return ret;
>> }
>>
>> static const struct dm_spi_flash_ops spi_flash_std_ops = {
>> --
>> 1.9.1

thanks!
--
Jagan | openedev.