[U-Boot] [PATCH v2 2/3] sf: spi_flash_probe for both dm/non-dm

Jagan Teki jteki at openedev.com
Sat Oct 24 05:54:50 CEST 2015


Let's use spi_flash_probe for dm and no-dm spi-flash
and make respective function definations separately.

Cc: Simon Glass <sjg at chromium.org>
Signed-off-by: Jagan Teki <jteki at openedev.com>
---
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(-)

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



More information about the U-Boot mailing list