[U-Boot] [PATCH 2/3] sf: spi_flash_probe for both dm/non-dm
Jagan Teki
jteki at openedev.com
Wed Oct 28 20:19:07 CET 2015
Hi Simon,
On 29 October 2015 at 00:19, Simon Glass <sjg at chromium.org> wrote:
> Hi Jagan,
>
> On 19 October 2015 at 10:09, Jagan Teki <jteki at openedev.com> wrote:
>> Let's use spi_flash_probe for dm and no-dm spi-flash
>> and make respective function definations separately.
>>
>> Signed-off-by: Jagan Teki <jteki at openedev.com>
>> Cc: Simon Glass <sjg at chromium.org>
>> ---
>> common/cmd_sf.c | 19 ++-----------------
>> drivers/mtd/spi/sf-uclass.c | 17 +----------------
>> include/spi_flash.h | 18 ++++--------------
>> 3 files changed, 7 insertions(+), 47 deletions(-)
>
> I think this is going in the wrong direction - we should not be
> abstracting out driver model, we should be moving everything to use
> it.
I'm thinking command code might not know about how driver model
handled for for particular device driver. Just process the inputs what
the user has given and do driver-model stuff at driver level.
Anyway dm_spi enabled boards will use driver model at sf-uclass and
non-dm will directly go.
>
>>
>> diff --git a/common/cmd_sf.c b/common/cmd_sf.c
>> index f1926e3..cdc6c26 100644
>> --- a/common/cmd_sf.c
>> +++ b/common/cmd_sf.c
>> @@ -83,9 +83,6 @@ 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;
>> -#ifndef CONFIG_DM_SPI_FLASH
>> - struct spi_flash *new;
>> -#endif
>>
>> if (argc >= 2) {
>> cs = simple_strtoul(argv[1], &endp, 0);
>> @@ -113,27 +110,15 @@ static int do_spi_flash_probe(int argc, char * const argv[])
>> return -1;
>> }
>>
>> -#ifdef CONFIG_DM_SPI_FLASH
>> - 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;
>> - }
>> -#else
>> if (flash)
>> spi_flash_free(flash);
>>
>> - new = spi_flash_probe(bus, cs, speed, mode);
>> - flash = new;
>> -
>> - if (!new) {
>> + flash = spi_flash_probe(bus, cs, speed, mode);
>> + if (!flash) {
>> printf("Failed to initialize SPI flash at %u:%u\n", bus, cs);
>> return 1;
>> }
>>
>> - flash = new;
>> -#endif
>> -
>> return 0;
>> }
>>
>> diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
>> index 9c109fa..a1c5810 100644
>> --- a/drivers/mtd/spi/sf-uclass.c
>> +++ b/drivers/mtd/spi/sf-uclass.c
>> @@ -27,21 +27,6 @@ int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
>> return sf_get_ops(dev)->erase(dev, offset, len);
>> }
>>
>> -/*
>> - * TODO(sjg at chromium.org): This is an old-style function. We should remove
>> - * it when all SPI flash drivers use dm
>> - */
>> -struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
>> - unsigned int max_hz, unsigned int spi_mode)
>> -{
>> - struct udevice *dev;
>> -
>> - if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev))
>> - return NULL;
>> -
>> - return dev_get_uclass_priv(dev);
>> -}
>> -
>> void spi_flash_free(struct spi_flash *flash)
>> {
>> spi_flash_remove(flash->spi->dev);
>> @@ -67,7 +52,7 @@ static 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,
>> +struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs,
>> unsigned int max_hz, unsigned int spi_mode)
>> {
>> struct udevice *bus, *new;
>> diff --git a/include/spi_flash.h b/include/spi_flash.h
>> index 5abbf99..0afc9fb 100644
>> --- a/include/spi_flash.h
>> +++ b/include/spi_flash.h
>> @@ -154,16 +154,6 @@ 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);
>>
>> -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,
>> - unsigned int max_hz, unsigned int spi_mode);
>> -
>> -/* Compatibility function - this is the old U-Boot API */
>> -void spi_flash_free(struct spi_flash *flash);
>> -
>> int spi_flash_remove(struct udevice *flash);
>>
>> static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
>> @@ -192,8 +182,6 @@ 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
>> -struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
>> - unsigned int max_hz, unsigned int spi_mode);
>>
>> /**
>> * Set up a new SPI flash from an fdt node
>> @@ -207,8 +195,6 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
>> struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
>> int spi_node);
>>
>> -void spi_flash_free(struct spi_flash *flash);
>> -
>> static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
>> size_t len, void *buf)
>> {
>> @@ -228,6 +214,10 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
>> }
>> #endif
>>
>> +struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
>> + unsigned int max_hz, unsigned int spi_mode);
>> +void spi_flash_free(struct spi_flash *flash);
>> +
>> void spi_boot(void) __noreturn;
>> void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
>>
>> --
>> 1.9.1
>>
>
> Regards,
> Simon
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
--
Jagan | openedev.
More information about the U-Boot
mailing list