* [U-Boot] [PATCH v4] dm: spi: Read default speed and mode values from DT
@ 2016-05-10 6:28 Vignesh R
2016-06-08 4:47 ` Vignesh R
0 siblings, 1 reply; 4+ messages in thread
From: Vignesh R @ 2016-05-10 6:28 UTC (permalink / raw)
To: u-boot
In case of DT boot, don't read default speed and mode for SPI from
CONFIG_*, instead read from DT node. This will make sure that boards
with multiple SPI/QSPI controllers can be probed at different
bus frequencies and SPI modes.
Signed-off-by: Vignesh R <vigneshr@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mugunthan V N <mugunthanvnm@ti.com>
---
v4: Update env_sf.c as well
v3: Update commit message to mention SPI mode changes
v2: Initialize speed, mode to 0 instead of -1
cmd/sf.c | 2 ++
common/env_sf.c | 8 ++++----
drivers/spi/spi-uclass.c | 8 ++++++--
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/cmd/sf.c b/cmd/sf.c
index 42862d9d921a..286906c3a151 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -88,6 +88,8 @@ static int do_spi_flash_probe(int argc, char * const argv[])
#ifdef CONFIG_DM_SPI_FLASH
struct udevice *new, *bus_dev;
int ret;
+ /* In DM mode defaults will be taken from DT */
+ speed = 0, mode = 0;
#else
struct spi_flash *new;
#endif
diff --git a/common/env_sf.c b/common/env_sf.c
index 273098ceb605..c53200f5c6fe 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -55,9 +55,9 @@ int saveenv(void)
#ifdef CONFIG_DM_SPI_FLASH
struct udevice *new;
+ /* 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);
+ 0, 0, &new);
if (ret) {
set_default_env("!spi_flash_probe_bus_cs() failed");
return 1;
@@ -245,9 +245,9 @@ int saveenv(void)
#ifdef CONFIG_DM_SPI_FLASH
struct udevice *new;
+ /* 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);
+ 0, 0, &new);
if (ret) {
set_default_env("!spi_flash_probe_bus_cs() failed");
return 1;
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 5561f36762f9..5fb5630e2981 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -264,6 +264,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
struct udevice **busp, struct spi_slave **devp)
{
struct udevice *bus, *dev;
+ struct dm_spi_slave_platdata *plat;
bool created = false;
int ret;
@@ -280,8 +281,6 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
* SPI flash chip - we will bind to the correct driver.
*/
if (ret == -ENODEV && drv_name) {
- struct dm_spi_slave_platdata *plat;
-
debug("%s: Binding new device '%s', busnum=%d, cs=%d, driver=%s\n",
__func__, dev_name, busnum, cs, drv_name);
ret = device_bind_driver(bus, drv_name, dev_name, &dev);
@@ -308,6 +307,11 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
slave->dev = dev;
}
+ plat = dev_get_parent_platdata(dev);
+ if (!speed) {
+ speed = plat->max_hz;
+ mode = plat->mode;
+ }
ret = spi_set_speed_mode(bus, speed, mode);
if (ret)
goto err;
--
2.8.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH v4] dm: spi: Read default speed and mode values from DT
2016-05-10 6:28 [U-Boot] [PATCH v4] dm: spi: Read default speed and mode values from DT Vignesh R
@ 2016-06-08 4:47 ` Vignesh R
0 siblings, 0 replies; 4+ messages in thread
From: Vignesh R @ 2016-06-08 4:47 UTC (permalink / raw)
To: u-boot
On Tuesday 10 May 2016 11:58 AM, Vignesh R wrote:
> In case of DT boot, don't read default speed and mode for SPI from
> CONFIG_*, instead read from DT node. This will make sure that boards
> with multiple SPI/QSPI controllers can be probed at different
> bus frequencies and SPI modes.
>
> Signed-off-by: Vignesh R <vigneshr@ti.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Mugunthan V N <mugunthanvnm@ti.com>
>
> ---
>
Gentle ping...
> v4: Update env_sf.c as well
>
> v3: Update commit message to mention SPI mode changes
>
> v2: Initialize speed, mode to 0 instead of -1
>
> cmd/sf.c | 2 ++
> common/env_sf.c | 8 ++++----
> drivers/spi/spi-uclass.c | 8 ++++++--
> 3 files changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/cmd/sf.c b/cmd/sf.c
> index 42862d9d921a..286906c3a151 100644
> --- a/cmd/sf.c
> +++ b/cmd/sf.c
> @@ -88,6 +88,8 @@ static int do_spi_flash_probe(int argc, char * const argv[])
> #ifdef CONFIG_DM_SPI_FLASH
> struct udevice *new, *bus_dev;
> int ret;
> + /* In DM mode defaults will be taken from DT */
> + speed = 0, mode = 0;
> #else
> struct spi_flash *new;
> #endif
> diff --git a/common/env_sf.c b/common/env_sf.c
> index 273098ceb605..c53200f5c6fe 100644
> --- a/common/env_sf.c
> +++ b/common/env_sf.c
> @@ -55,9 +55,9 @@ int saveenv(void)
> #ifdef CONFIG_DM_SPI_FLASH
> struct udevice *new;
>
> + /* 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);
> + 0, 0, &new);
> if (ret) {
> set_default_env("!spi_flash_probe_bus_cs() failed");
> return 1;
> @@ -245,9 +245,9 @@ int saveenv(void)
> #ifdef CONFIG_DM_SPI_FLASH
> struct udevice *new;
>
> + /* 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);
> + 0, 0, &new);
> if (ret) {
> set_default_env("!spi_flash_probe_bus_cs() failed");
> return 1;
> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
> index 5561f36762f9..5fb5630e2981 100644
> --- a/drivers/spi/spi-uclass.c
> +++ b/drivers/spi/spi-uclass.c
> @@ -264,6 +264,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
> struct udevice **busp, struct spi_slave **devp)
> {
> struct udevice *bus, *dev;
> + struct dm_spi_slave_platdata *plat;
> bool created = false;
> int ret;
>
> @@ -280,8 +281,6 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
> * SPI flash chip - we will bind to the correct driver.
> */
> if (ret == -ENODEV && drv_name) {
> - struct dm_spi_slave_platdata *plat;
> -
> debug("%s: Binding new device '%s', busnum=%d, cs=%d, driver=%s\n",
> __func__, dev_name, busnum, cs, drv_name);
> ret = device_bind_driver(bus, drv_name, dev_name, &dev);
> @@ -308,6 +307,11 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
> slave->dev = dev;
> }
>
> + plat = dev_get_parent_platdata(dev);
> + if (!speed) {
> + speed = plat->max_hz;
> + mode = plat->mode;
> + }
> ret = spi_set_speed_mode(bus, speed, mode);
> if (ret)
> goto err;
>
--
Regards
Vignesh
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH v4] dm: spi: Read default speed and mode values from DT
2019-02-27 14:36 ` [U-Boot] [PATCH v4] dm: spi: " Patrick Delaunay
@ 2019-04-12 6:26 ` Jagan Teki
0 siblings, 0 replies; 4+ messages in thread
From: Jagan Teki @ 2019-04-12 6:26 UTC (permalink / raw)
To: u-boot
On Wed, Feb 27, 2019 at 8:06 PM Patrick Delaunay
<patrick.delaunay@st.com> wrote:
>
> This patch update the behavior introduced by
> commit 96907c0fe50a ("dm: spi: Read default speed and mode values from DT")
>
> In case of DT boot, don't read default speed and mode for SPI from
> CONFIG_* but instead read from DT node. This will make sure that boards
> with multiple SPI/QSPI controllers can be probed at different
> bus frequencies and SPI modes.
>
> Remove also use in boards of the value speed=0 (no more supported)
> for ENV in SPI by using CONFIG_ENV_SPI_MAX_HZ=0.
>
> DT values will be always used when available (full DM support of
> SPI slave with available DT node) even if speed and mode are requested;
> for example in splash screen support (in splash_sf_read_raw)
> or in SPL boot (in spl_spi_load_image).
> The caller of spi_get_bus_and_cs() no more need to force speed=0.
>
> But the current behavior don't change if the SPI slave is not
> present (device with generic driver is created automatically)
> or if platdata is used (CONFIG_OF_PLATDATA).
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
Applied to u-boot-spi/master
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH v4] dm: spi: Read default speed and mode values from DT
2019-02-27 14:36 [U-Boot] [PATCH v4 0/1] " Patrick Delaunay
@ 2019-02-27 14:36 ` Patrick Delaunay
2019-04-12 6:26 ` Jagan Teki
0 siblings, 1 reply; 4+ messages in thread
From: Patrick Delaunay @ 2019-02-27 14:36 UTC (permalink / raw)
To: u-boot
This patch update the behavior introduced by
commit 96907c0fe50a ("dm: spi: Read default speed and mode values from DT")
In case of DT boot, don't read default speed and mode for SPI from
CONFIG_* but instead read from DT node. This will make sure that boards
with multiple SPI/QSPI controllers can be probed at different
bus frequencies and SPI modes.
Remove also use in boards of the value speed=0 (no more supported)
for ENV in SPI by using CONFIG_ENV_SPI_MAX_HZ=0.
DT values will be always used when available (full DM support of
SPI slave with available DT node) even if speed and mode are requested;
for example in splash screen support (in splash_sf_read_raw)
or in SPL boot (in spl_spi_load_image).
The caller of spi_get_bus_and_cs() no more need to force speed=0.
But the current behavior don't change if the SPI slave is not
present (device with generic driver is created automatically)
or if platdata is used (CONFIG_OF_PLATDATA).
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---
Changes in v4:
- rebase on v2019.04-rc2
- after Jagan review depends on Migrate SPI defines to Kconfig
http://patchwork.ozlabs.org/project/uboot/list/?series=94485
- remove no more supported configuration:
CONFIG_ENV_SPI_MAX_HZ=0 or CONFIG_ENV_SPI_MODE=0
Changes in v3:
- complete rework of the patch-set to avoid regression
Changes in v2:
- use variables to avoid duplicated code
cmd/sf.c | 3 +--
common/spl/spl_spi.c | 2 ++
configs/da850_am18xxevm_defconfig | 4 ----
configs/da850evm_defconfig | 4 ----
configs/mscc_jr2_defconfig | 4 ----
configs/mscc_luton_defconfig | 4 ----
configs/mscc_ocelot_defconfig | 4 ----
configs/mscc_serval_defconfig | 4 ----
configs/mscc_servalt_defconfig | 4 ----
drivers/mtd/spi/Kconfig | 6 ++++++
drivers/spi/spi-uclass.c | 4 +++-
include/spi.h | 9 +++++----
12 files changed, 17 insertions(+), 35 deletions(-)
diff --git a/cmd/sf.c b/cmd/sf.c
index 738ef0e..6ccf98a 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -81,14 +81,13 @@ static int do_spi_flash_probe(int argc, char * const argv[])
{
unsigned int bus = CONFIG_SF_DEFAULT_BUS;
unsigned int cs = CONFIG_SF_DEFAULT_CS;
+ /* In DM mode, defaults speed and mode will be taken from DT */
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;
- /* In DM mode defaults will be taken from DT */
- speed = 0, mode = 0;
#else
struct spi_flash *new;
#endif
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 8cd4830..9b74473 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -77,6 +77,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
/*
* Load U-Boot image from SPI flash into RAM
+ * In DM mode: defaults speed and mode will be
+ * taken from DT when available
*/
flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
diff --git a/configs/da850_am18xxevm_defconfig b/configs/da850_am18xxevm_defconfig
index b1cf9bd..58745fe 100644
--- a/configs/da850_am18xxevm_defconfig
+++ b/configs/da850_am18xxevm_defconfig
@@ -38,10 +38,6 @@ CONFIG_SPL_OF_CONTROL=y
CONFIG_DEFAULT_DEVICE_TREE="da850-evm"
CONFIG_SPL_OF_PLATDATA=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_USE_ENV_SPI_MAX_HZ=y
-CONFIG_ENV_SPI_MAX_HZ=0
-CONFIG_USE_ENV_SPI_MODE=y
-CONFIG_ENV_SPI_MODE=0
CONFIG_DM=y
CONFIG_SPL_DM=y
CONFIG_DA8XX_GPIO=y
diff --git a/configs/da850evm_defconfig b/configs/da850evm_defconfig
index e6031b4..5100ee7 100644
--- a/configs/da850evm_defconfig
+++ b/configs/da850evm_defconfig
@@ -40,10 +40,6 @@ CONFIG_SPL_OF_CONTROL=y
CONFIG_DEFAULT_DEVICE_TREE="da850-evm"
CONFIG_SPL_OF_PLATDATA=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_USE_ENV_SPI_MAX_HZ=y
-CONFIG_ENV_SPI_MAX_HZ=0
-CONFIG_USE_ENV_SPI_MODE=y
-CONFIG_ENV_SPI_MODE=0
CONFIG_DM=y
CONFIG_SPL_DM=y
CONFIG_DM_GPIO=y
diff --git a/configs/mscc_jr2_defconfig b/configs/mscc_jr2_defconfig
index 95562b7..9276df2 100644
--- a/configs/mscc_jr2_defconfig
+++ b/configs/mscc_jr2_defconfig
@@ -38,10 +38,6 @@ CONFIG_OF_LIST="jr2_pcb110 jr2_pcb111 serval2_pcb112"
CONFIG_DTB_RESELECT=y
CONFIG_MULTI_DTB_FIT=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_USE_ENV_SPI_MAX_HZ=y
-CONFIG_ENV_SPI_MAX_HZ=0
-CONFIG_USE_ENV_SPI_MODE=y
-CONFIG_ENV_SPI_MODE=0
CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_CLK=y
CONFIG_DM_GPIO=y
diff --git a/configs/mscc_luton_defconfig b/configs/mscc_luton_defconfig
index 162a514..0fdd9b8 100644
--- a/configs/mscc_luton_defconfig
+++ b/configs/mscc_luton_defconfig
@@ -44,10 +44,6 @@ CONFIG_OF_LIST="luton_pcb090 luton_pcb091"
CONFIG_DTB_RESELECT=y
CONFIG_MULTI_DTB_FIT=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_USE_ENV_SPI_MAX_HZ=y
-CONFIG_ENV_SPI_MAX_HZ=0
-CONFIG_USE_ENV_SPI_MODE=y
-CONFIG_ENV_SPI_MODE=0
CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_CLK=y
CONFIG_DM_GPIO=y
diff --git a/configs/mscc_ocelot_defconfig b/configs/mscc_ocelot_defconfig
index b0dcfaf..edc476d 100644
--- a/configs/mscc_ocelot_defconfig
+++ b/configs/mscc_ocelot_defconfig
@@ -43,10 +43,6 @@ CONFIG_OF_LIST="ocelot_pcb120 ocelot_pcb123"
CONFIG_DTB_RESELECT=y
CONFIG_MULTI_DTB_FIT=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_USE_ENV_SPI_MAX_HZ=y
-CONFIG_ENV_SPI_MAX_HZ=0
-CONFIG_USE_ENV_SPI_MODE=y
-CONFIG_ENV_SPI_MODE=0
CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_CLK=y
CONFIG_DM_GPIO=y
diff --git a/configs/mscc_serval_defconfig b/configs/mscc_serval_defconfig
index f2c9563..146188b 100644
--- a/configs/mscc_serval_defconfig
+++ b/configs/mscc_serval_defconfig
@@ -35,10 +35,6 @@ CONFIG_OF_LIST="serval_pcb106 serval_pcb105"
CONFIG_DTB_RESELECT=y
CONFIG_MULTI_DTB_FIT=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_USE_ENV_SPI_MAX_HZ=y
-CONFIG_ENV_SPI_MAX_HZ=0
-CONFIG_USE_ENV_SPI_MODE=y
-CONFIG_ENV_SPI_MODE=0
CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_CLK=y
CONFIG_DM_GPIO=y
diff --git a/configs/mscc_servalt_defconfig b/configs/mscc_servalt_defconfig
index 027aaa4..a450f48 100644
--- a/configs/mscc_servalt_defconfig
+++ b/configs/mscc_servalt_defconfig
@@ -33,10 +33,6 @@ CONFIG_DEFAULT_DEVICE_TREE="servalt_pcb116"
CONFIG_DTB_RESELECT=y
CONFIG_MULTI_DTB_FIT=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_USE_ENV_SPI_MAX_HZ=y
-CONFIG_ENV_SPI_MAX_HZ=0
-CONFIG_USE_ENV_SPI_MODE=y
-CONFIG_ENV_SPI_MODE=0
CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_CLK=y
CONFIG_DM_GPIO=y
diff --git a/drivers/mtd/spi/Kconfig b/drivers/mtd/spi/Kconfig
index 5671bca..d3b007a 100644
--- a/drivers/mtd/spi/Kconfig
+++ b/drivers/mtd/spi/Kconfig
@@ -62,6 +62,9 @@ config SF_DEFAULT_MODE
The default mode may be provided by the platform
to handle the common case when only a single serial
flash is present on the system.
+ Not used for boot with device tree; the SPI driver reads
+ speed and mode from platdata values computed from
+ available node.
config SF_DEFAULT_SPEED
int "SPI Flash default speed in Hz"
@@ -71,6 +74,9 @@ config SF_DEFAULT_SPEED
The default speed may be provided by the platform
to handle the common case when only a single serial
flash is present on the system.
+ Not used for boot with device tree; the SPI driver reads
+ speed and mode from platdata values computed from
+ available node.
if SPI_FLASH
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 2bc289a..88cb2a1 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -328,7 +328,9 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
}
plat = dev_get_parent_platdata(dev);
- if (!speed) {
+
+ /* get speed and mode from platdata when available */
+ if (plat->max_hz) {
speed = plat->max_hz;
mode = plat->mode;
}
diff --git a/include/spi.h b/include/spi.h
index 92427e5..3785941 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -496,14 +496,15 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp,
* device and slave device.
*
* If no such slave exists, and drv_name is not NULL, then a new slave device
- * is automatically bound on this chip select.
+ * is automatically bound on this chip select with requested speed and mode.
*
- * Ths new slave device is probed ready for use with the given speed and mode.
+ * Ths new slave device is probed ready for use with the speed and mode
+ * from platdata when available or the requested values.
*
* @busnum: SPI bus number
* @cs: Chip select to look for
- * @speed: SPI speed to use for this slave
- * @mode: SPI mode to use for this slave
+ * @speed: SPI speed to use for this slave when not available in platdata
+ * @mode: SPI mode to use for this slave when not available in platdata
* @drv_name: Name of driver to attach to this chip select
* @dev_name: Name of the new device thus created
* @busp: Returns bus device
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-04-12 6:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-10 6:28 [U-Boot] [PATCH v4] dm: spi: Read default speed and mode values from DT Vignesh R
2016-06-08 4:47 ` Vignesh R
2019-02-27 14:36 [U-Boot] [PATCH v4 0/1] " Patrick Delaunay
2019-02-27 14:36 ` [U-Boot] [PATCH v4] dm: spi: " Patrick Delaunay
2019-04-12 6:26 ` Jagan Teki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.