sf: Add dm_spi_flash_probe
PATCH v2 1/3 sf: Add dm_spi_flash_probe
Updated dm-spi-flash probe using dm_spi_flash_probe.
---
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(-)
common/cmd_sf.c +4 -19
@@ -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);
drivers/mtd/spi/sf-uclass.c +26 -1
@@ -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) +{ +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); + } + 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);
include/spi_flash.h +2 -3
@@ -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,
Signature · 1 line
1.9.1
PATCH v2 2/3 sf: spi_flash_probe for both dm/non-dm
Let's use spi_flash_probe for dm and no-dm spi-flash and make respective function definations separately.
---
Changes for v2:
- none
common/cmd_sf.c | 19 ++----------------- drivers/mtd/spi/sf-uclass.c | 17 +---------------- include/spi_flash.h | 18 ++++-------------- 3 files changed, 7 insertions(+), 47 deletions(-)
common/cmd_sf.c +2 -17
@@ -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 ; }
drivers/mtd/spi/sf-uclass.c +1 -16
@@ -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;
include/spi_flash.h +4 -14
@@ -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);
Signature · 1 line
1.9.1
PATCH v2 2/3 sf: spi_flash_probe for both dm/non-dm
Hi Jagan,
Quoted 63 lines · Jagan Teki
Let's use
spi_flash_probefor dm and no-dm spi-flash and make respective function definations separately.Cc Simon Glass <[email protected]>Signed-off-by Jagan Teki <[email protected]>---
Changes for v2:
- nonecommon/cmd_sf.c | 19 ++----------------- drivers/mtd/spi/sf-uclass.c | 17 +---------------- include/spi_flash.h | 18 ++++-------------- 3 files changed, 7 insertions(+), 47 deletions(-)common/cmd_sf.c +2
-17@@ -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 ; }drivers/mtd/spi/sf-uclass.c +0
-0
drivers/mtd/spi/sf-uclass.c int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len) · line 35
Quoted 9 lines
drivers/mtd/spi/sf-uclass.c +0
-6@@ -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)
How come this function is being removed? I don't think all drivers have been converted to driver model yet.
Quoted 72 lines
drivers/mtd/spi/sf-uclass.c +1
-10-{ -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;include/spi_flash.h +4
-15@@ -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); --
Quoted 2 lines
1.9.1
Regards,
Simon
PATCH v2 3/3 sf: Remove spi_flash_remove
In reply to Jagan TekiUse direct call to device_remove instead of exctra spi_flash_remove defination.
---
Changes for v2:
- none
drivers/mtd/spi/sf-uclass.c | 7 +------ include/spi_flash.h | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-)
drivers/mtd/spi/sf-uclass.c +1 -6
@@ -29,7 +29,7 @@ int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)void spi_flash_free (struct spi_flash *flash) { -spi_flash_remove (flash->spi->dev); +device_remove (flash->spi->dev); } static int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
@@ -77,11 +77,6 @@ struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs,return dev_get_uclass_priv (new); } -int spi_flash_remove (struct udevice *dev) -{ -return device_remove (dev); -} -UCLASS_DRIVER (spi_flash) = { .id =UCLASS_SPI_FLASH , .name ="spi_flash" ,
include/spi_flash.h +0 -2
@@ -154,8 +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); -int spi_flash_remove (struct udevice *flash); -static inline int spi_flash_read (struct spi_flash *flash,u32 offset,size_t len,void *buf) {
Signature · 1 line
1.9.1
PATCH v2 3/3 sf: Remove spi_flash_remove
Quoted 5 lines · Jagan Teki
Use direct call to
device_removeinstead of exctraspi_flash_removedefination.Cc Simon Glass <[email protected]>Signed-off-by Jagan Teki <[email protected]>
Quoted 8 lines
---
Changes for v2:
- nonedrivers/mtd/spi/sf-uclass.c | 7 +------ include/spi_flash.h | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-)
PATCH v2 3/3 sf: Remove spi_flash_remove
Quoted 10 lines · Simon Glass
Quoted 9 lines · Jagan Teki
Use direct call to
device_removeinstead of exctraspi_flash_removedefination.Cc Simon Glass <[email protected]>Signed-off-by Jagan Teki <[email protected]>---
Changes for v2:
- none
Quoted 6 lines
Quoted 4 lines
drivers/mtd/spi/sf-uclass.c | 7 +------ include/spi_flash.h | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-)Reviewed-by Simon Glass <[email protected]>
Applied to u-boot-spi/master
thanks!
Signature · 1 line
Jagan.
PATCH v2 1/3 sf: Add dm_spi_flash_probe
In reply to Jagan TekiHi Jagan,
Quoted 84 lines · Jagan Teki
Updated dm-spi-flash probe using
dm_spi_flash_probe.Cc Simon Glass <[email protected]>Signed-off-by Jagan Teki <[email protected]>---
Changes for v2:
- nonecommon/cmd_sf.c | 23 ++++------------------- drivers/mtd/spi/sf-uclass.c | 27 ++++++++++++++++++++++++++- include/spi_flash.h | 5 ++--- 3 files changed, 32 insertions(+), 23 deletions(-)common/cmd_sf.c +4
-19@@ -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);drivers/mtd/spi/sf-uclass.c +1
-1@@ -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) {
drivers/mtd/spi/sf-uclass.c int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, · line 71
Quoted 5 lines
drivers/mtd/spi/sf-uclass.c +2
-0@@ -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....
drivers/mtd/spi/sf-uclass.c int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, · line 82
Quoted 11 lines
drivers/mtd/spi/sf-uclass.c +11
-0+{ +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.
Quoted 32 lines
drivers/mtd/spi/sf-uclass.c +12
-0+ 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);include/spi_flash.h +2
-4@@ -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, --
Quoted 2 lines
1.9.1
Regards,
Simon