[RESEND PATCH v4 2/3] spi: spi_flash_probe_bus_cs() rely on DT for spi speed and mode
Patrice Chotard
patrice.chotard at foss.st.com
Wed May 18 08:46:47 CEST 2022
Now, spi_flash_probe_bus_cs() relies on DT for spi speed and mode
and logically calls spi_get_bus_and_cs(). In case spi mode and speed are
not read from DT, make usage of spi_flash_probe() instead.
To sum-up:
- Previous call tree was:
spi_flash_probe() -> spi_flash_probe_bus_cs() -> spi_get_bus_and_cs()
- Current call tree is:
spi_flash_probe() -> _spi_get_bus_and_cs()
spi_flash_probe_bus_cs() -> spi_get_bus_and_cs()
This patch impacts the following :
- cmd/sf.c: if spi mode and/or speed is passed in argument of
do_spi_flash_probe(), call spi_flash_probe() otherwise call
spi_flash_probe_bus_cs().
- drivers/net/fm/fm.c: as by default spi speed and mode was set to
0 and a comment indicates that speed and mode are read from DT,
use spi_flash_probe_bus_cs().
- drivers/net/pfe_eth/pfe_firmware.c: spi speed and mode are not read
from DT by all platforms using this driver, so keep legacy and replace
spi_flash_probe_bus_cs() by spi_flash_probe();
- drivers/net/sni_netsec.c : spi speed and mode are not read from DT,
so replace spi_flash_probe_bus_cs() by spi_flash_probe().
- drivers/usb/gadget/max3420_udc.c: Can't find any platform which make
usage of this driver, nevertheless, keep legacy and replace
spi_get_bus_and_cs() by _spi_get_bus_and_cs().
- env/sf.c: a comment indicates that speed and mode are read
from DT. So use spi_flash_probe_bus_cs().
Signed-off-by: Patrice Chotard <patrice.chotard at foss.st.com>
Cc: Marek Behun <marek.behun at nic.cz>
Cc: Jagan Teki <jagan at amarulasolutions.com>
Cc: Vignesh R <vigneshr at ti.com>
Cc: Joe Hershberger <joe.hershberger at ni.com>
Cc: Ramon Fried <rfried.dev at gmail.com>
Cc: Lukasz Majewski <lukma at denx.de>
Cc: Marek Vasut <marex at denx.de>
Cc: Wolfgang Denk <wd at denx.de>
Cc: Simon Glass <sjg at chromium.org>
Cc: Stefan Roese <sr at denx.de>
Cc: "Pali Rohár" <pali at kernel.org>
Cc: Konstantin Porotchkin <kostap at marvell.com>
Cc: Igal Liberman <igall at marvell.com>
Cc: Bin Meng <bmeng.cn at gmail.com>
Cc: Pratyush Yadav <p.yadav at ti.com>
Cc: Sean Anderson <seanga2 at gmail.com>
Cc: Anji J <anji.jagarlmudi at nxp.com>
Cc: Biwen Li <biwen.li at nxp.com>
Cc: Priyanka Jain <priyanka.jain at nxp.com>
Cc: Chaitanya Sakinam <chaitanya.sakinam at nxp.com>
---
Changes in v4:
- Split previous series in 3 patches
- Update commit message with additionnal information
Changes in v3:
- Update commit header to reflect what the patch really do.
- Rename legacy spi_get_bus_and_cs() to _spi_get_bus_and_cs().
- New spi_get_bus_and_cs() rely on DT for spi speed and mode values.
- spi_flash_probe_bus_cs() rely also on DT for spi and mode values.
Changes in v2:
- add spi_flash_probe_bus_cs_default() which calls spi_get_bus_and_cs()
with "use_dt" param set to true, whereas spi_flash_probe_bus_cs() calls
spi_get_bus_and_cs() with "use_dt" param set to true.
cmd/sf.c | 15 ++++++++++----
drivers/mtd/spi/sf-uclass.c | 33 +++++++++++++++---------------
drivers/net/fm/fm.c | 4 ++--
drivers/net/pfe_eth/pfe_firmware.c | 19 ++++-------------
drivers/net/sni_netsec.c | 6 ++----
env/sf.c | 1 -
include/spi_flash.h | 1 -
7 files changed, 36 insertions(+), 43 deletions(-)
diff --git a/cmd/sf.c b/cmd/sf.c
index 8bdebd9fd8..8713736b2a 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -91,6 +91,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;
+ bool use_dt = true;
#if CONFIG_IS_ENABLED(DM_SPI_FLASH)
struct udevice *new, *bus_dev;
int ret;
@@ -117,11 +118,13 @@ static int do_spi_flash_probe(int argc, char *const argv[])
speed = simple_strtoul(argv[2], &endp, 0);
if (*argv[2] == 0 || *endp != 0)
return -1;
+ use_dt = false;
}
if (argc >= 4) {
mode = hextoul(argv[3], &endp);
if (*argv[3] == 0 || *endp != 0)
return -1;
+ use_dt = false;
}
#if CONFIG_IS_ENABLED(DM_SPI_FLASH)
@@ -131,14 +134,18 @@ static int do_spi_flash_probe(int argc, char *const argv[])
device_remove(new, DM_REMOVE_NORMAL);
}
flash = NULL;
- ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new);
- if (ret) {
+ if (use_dt) {
+ spi_flash_probe_bus_cs(bus, cs, &new);
+ flash = dev_get_uclass_priv(new);
+ } else {
+ flash = spi_flash_probe(bus, cs, speed, mode);
+ }
+
+ if (!flash) {
printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
bus, cs, ret);
return 1;
}
-
- flash = dev_get_uclass_priv(new);
#else
if (flash)
spi_flash_free(flash);
diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
index b45ba54ebf..e6e650ef8c 100644
--- a/drivers/mtd/spi/sf-uclass.c
+++ b/drivers/mtd/spi/sf-uclass.c
@@ -46,25 +46,12 @@ int spl_flash_get_sw_write_prot(struct udevice *dev)
* 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,
+struct spi_flash *spi_flash_probe(unsigned int busnum, 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);
-}
-
-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 udevice *bus;
char *str;
- int ret;
#if defined(CONFIG_SPL_BUILD) && CONFIG_IS_ENABLED(USE_TINY_PRINTF)
str = "spi_flash";
@@ -74,8 +61,22 @@ int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
snprintf(name, sizeof(name), "spi_flash@%d:%d", busnum, cs);
str = strdup(name);
#endif
- ret = _spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode,
- "jedec_spi_nor", str, &bus, &slave);
+
+ if (_spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode,
+ "jedec_spi_nor", str, &bus, &slave))
+ return NULL;
+
+ return dev_get_uclass_priv(slave->dev);
+}
+
+int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
+ struct udevice **devp)
+{
+ struct spi_slave *slave;
+ struct udevice *bus;
+ int ret;
+
+ ret = spi_get_bus_and_cs(busnum, cs, &bus, &slave);
if (ret)
return ret;
diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c
index f825612640..d0b492b5a1 100644
--- a/drivers/net/fm/fm.c
+++ b/drivers/net/fm/fm.c
@@ -388,7 +388,7 @@ int fm_init_common(int index, struct ccsr_fman *reg)
/* speed and mode will be read from DT */
ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS,
- CONFIG_SF_DEFAULT_CS, 0, 0, &new);
+ CONFIG_SF_DEFAULT_CS, &new);
ucode_flash = dev_get_uclass_priv(new);
#else
@@ -475,7 +475,7 @@ int fm_init_common(int index, struct ccsr_fman *reg)
/* speed and mode will be read from DT */
ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS,
- 0, 0, &new);
+ &new);
ucode_flash = dev_get_uclass_priv(new);
#else
diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c
index 6669048181..82a4aa89a4 100644
--- a/drivers/net/pfe_eth/pfe_firmware.c
+++ b/drivers/net/pfe_eth/pfe_firmware.c
@@ -172,31 +172,20 @@ static int pfe_fit_check(void)
int pfe_spi_flash_init(void)
{
struct spi_flash *pfe_flash;
- struct udevice *new;
int ret = 0;
void *addr = malloc(CONFIG_SYS_LS_PFE_FW_LENGTH);
if (!addr)
return -ENOMEM;
- ret = spi_flash_probe_bus_cs(CONFIG_SYS_FSL_PFE_SPI_BUS,
- CONFIG_SYS_FSL_PFE_SPI_CS,
- CONFIG_SYS_FSL_PFE_SPI_MAX_HZ,
- CONFIG_SYS_FSL_PFE_SPI_MODE,
- &new);
- if (ret) {
- printf("SF: failed to probe spi\n");
- free(addr);
- device_remove(new, DM_REMOVE_NORMAL);
- return ret;
- }
-
+ pfe_flash = spi_flash_probe(CONFIG_SYS_FSL_PFE_SPI_BUS,
+ CONFIG_SYS_FSL_PFE_SPI_CS,
+ CONFIG_SYS_FSL_PFE_SPI_MAX_HZ,
+ CONFIG_SYS_FSL_PFE_SPI_MODE);
- pfe_flash = dev_get_uclass_priv(new);
if (!pfe_flash) {
printf("SF: probe for pfe failed\n");
free(addr);
- device_remove(new, DM_REMOVE_NORMAL);
return -ENODEV;
}
diff --git a/drivers/net/sni_netsec.c b/drivers/net/sni_netsec.c
index 24caacf847..9780f2092b 100644
--- a/drivers/net/sni_netsec.c
+++ b/drivers/net/sni_netsec.c
@@ -621,12 +621,10 @@ static int netsec_stop_gmac(struct netsec_priv *priv)
static void netsec_spi_read(char *buf, loff_t len, loff_t offset)
{
- struct udevice *new;
struct spi_flash *flash;
- spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS,
- CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE, &new);
- flash = dev_get_uclass_priv(new);
+ flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS,
+ CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE);
spi_flash_read(flash, offset, len, buf);
}
diff --git a/env/sf.c b/env/sf.c
index d2c07cd716..4b768542c1 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -48,7 +48,6 @@ static int setup_flash_device(struct spi_flash **env_flash)
/* speed and mode will be read from DT */
ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
- CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE,
&new);
if (ret) {
env_set_default("spi_flash_probe_bus_cs() failed", 0);
diff --git a/include/spi_flash.h b/include/spi_flash.h
index d33d0dd46a..10d19fd4b1 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -102,7 +102,6 @@ int spl_flash_get_sw_write_prot(struct udevice *dev);
int spi_flash_std_probe(struct udevice *dev);
int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
- unsigned int max_hz, unsigned int spi_mode,
struct udevice **devp);
/* Compatibility function - this is the old U-Boot API */
--
2.25.1
More information about the U-Boot
mailing list