Commit b0cc1b846fcb310c0ac2f8cbeb4ed5947dc52912

Authored by Patrick Delaunay
Committed by Jagan Teki
1 parent f909ddb3e1

dm: spi: Read default speed and mode values from DT

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>
Acked-by: Jagan Teki <jagan@amarulasolutions.com>

Showing 12 changed files with 17 additions and 35 deletions Side-by-side Diff

... ... @@ -81,14 +81,13 @@
81 81 {
82 82 unsigned int bus = CONFIG_SF_DEFAULT_BUS;
83 83 unsigned int cs = CONFIG_SF_DEFAULT_CS;
  84 + /* In DM mode, defaults speed and mode will be taken from DT */
84 85 unsigned int speed = CONFIG_SF_DEFAULT_SPEED;
85 86 unsigned int mode = CONFIG_SF_DEFAULT_MODE;
86 87 char *endp;
87 88 #ifdef CONFIG_DM_SPI_FLASH
88 89 struct udevice *new, *bus_dev;
89 90 int ret;
90   - /* In DM mode defaults will be taken from DT */
91   - speed = 0, mode = 0;
92 91 #else
93 92 struct spi_flash *new;
94 93 #endif
common/spl/spl_spi.c
... ... @@ -77,6 +77,8 @@
77 77  
78 78 /*
79 79 * Load U-Boot image from SPI flash into RAM
  80 + * In DM mode: defaults speed and mode will be
  81 + * taken from DT when available
80 82 */
81 83  
82 84 flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
configs/da850_am18xxevm_defconfig
... ... @@ -39,10 +39,6 @@
39 39 CONFIG_DEFAULT_DEVICE_TREE="da850-evm"
40 40 CONFIG_SPL_OF_PLATDATA=y
41 41 CONFIG_ENV_IS_IN_SPI_FLASH=y
42   -CONFIG_USE_ENV_SPI_MAX_HZ=y
43   -CONFIG_ENV_SPI_MAX_HZ=0
44   -CONFIG_USE_ENV_SPI_MODE=y
45   -CONFIG_ENV_SPI_MODE=0
46 42 CONFIG_DM=y
47 43 CONFIG_SPL_DM=y
48 44 CONFIG_DA8XX_GPIO=y
configs/da850evm_defconfig
... ... @@ -41,10 +41,6 @@
41 41 CONFIG_DEFAULT_DEVICE_TREE="da850-evm"
42 42 CONFIG_SPL_OF_PLATDATA=y
43 43 CONFIG_ENV_IS_IN_SPI_FLASH=y
44   -CONFIG_USE_ENV_SPI_MAX_HZ=y
45   -CONFIG_ENV_SPI_MAX_HZ=0
46   -CONFIG_USE_ENV_SPI_MODE=y
47   -CONFIG_ENV_SPI_MODE=0
48 44 CONFIG_DM=y
49 45 CONFIG_SPL_DM=y
50 46 CONFIG_DM_GPIO=y
configs/mscc_jr2_defconfig
... ... @@ -38,10 +38,6 @@
38 38 CONFIG_DTB_RESELECT=y
39 39 CONFIG_MULTI_DTB_FIT=y
40 40 CONFIG_ENV_IS_IN_SPI_FLASH=y
41   -CONFIG_USE_ENV_SPI_MAX_HZ=y
42   -CONFIG_ENV_SPI_MAX_HZ=0
43   -CONFIG_USE_ENV_SPI_MODE=y
44   -CONFIG_ENV_SPI_MODE=0
45 41 CONFIG_NET_RANDOM_ETHADDR=y
46 42 CONFIG_CLK=y
47 43 CONFIG_DM_GPIO=y
configs/mscc_luton_defconfig
... ... @@ -44,10 +44,6 @@
44 44 CONFIG_DTB_RESELECT=y
45 45 CONFIG_MULTI_DTB_FIT=y
46 46 CONFIG_ENV_IS_IN_SPI_FLASH=y
47   -CONFIG_USE_ENV_SPI_MAX_HZ=y
48   -CONFIG_ENV_SPI_MAX_HZ=0
49   -CONFIG_USE_ENV_SPI_MODE=y
50   -CONFIG_ENV_SPI_MODE=0
51 47 CONFIG_NET_RANDOM_ETHADDR=y
52 48 CONFIG_CLK=y
53 49 CONFIG_DM_GPIO=y
configs/mscc_ocelot_defconfig
... ... @@ -43,10 +43,6 @@
43 43 CONFIG_DTB_RESELECT=y
44 44 CONFIG_MULTI_DTB_FIT=y
45 45 CONFIG_ENV_IS_IN_SPI_FLASH=y
46   -CONFIG_USE_ENV_SPI_MAX_HZ=y
47   -CONFIG_ENV_SPI_MAX_HZ=0
48   -CONFIG_USE_ENV_SPI_MODE=y
49   -CONFIG_ENV_SPI_MODE=0
50 46 CONFIG_NET_RANDOM_ETHADDR=y
51 47 CONFIG_CLK=y
52 48 CONFIG_DM_GPIO=y
configs/mscc_serval_defconfig
... ... @@ -35,10 +35,6 @@
35 35 CONFIG_DTB_RESELECT=y
36 36 CONFIG_MULTI_DTB_FIT=y
37 37 CONFIG_ENV_IS_IN_SPI_FLASH=y
38   -CONFIG_USE_ENV_SPI_MAX_HZ=y
39   -CONFIG_ENV_SPI_MAX_HZ=0
40   -CONFIG_USE_ENV_SPI_MODE=y
41   -CONFIG_ENV_SPI_MODE=0
42 38 CONFIG_NET_RANDOM_ETHADDR=y
43 39 CONFIG_CLK=y
44 40 CONFIG_DM_GPIO=y
configs/mscc_servalt_defconfig
... ... @@ -33,10 +33,6 @@
33 33 CONFIG_DTB_RESELECT=y
34 34 CONFIG_MULTI_DTB_FIT=y
35 35 CONFIG_ENV_IS_IN_SPI_FLASH=y
36   -CONFIG_USE_ENV_SPI_MAX_HZ=y
37   -CONFIG_ENV_SPI_MAX_HZ=0
38   -CONFIG_USE_ENV_SPI_MODE=y
39   -CONFIG_ENV_SPI_MODE=0
40 36 CONFIG_NET_RANDOM_ETHADDR=y
41 37 CONFIG_CLK=y
42 38 CONFIG_DM_GPIO=y
drivers/mtd/spi/Kconfig
... ... @@ -62,6 +62,9 @@
62 62 The default mode may be provided by the platform
63 63 to handle the common case when only a single serial
64 64 flash is present on the system.
  65 + Not used for boot with device tree; the SPI driver reads
  66 + speed and mode from platdata values computed from
  67 + available node.
65 68  
66 69 config SF_DEFAULT_SPEED
67 70 int "SPI Flash default speed in Hz"
... ... @@ -71,6 +74,9 @@
71 74 The default speed may be provided by the platform
72 75 to handle the common case when only a single serial
73 76 flash is present on the system.
  77 + Not used for boot with device tree; the SPI driver reads
  78 + speed and mode from platdata values computed from
  79 + available node.
74 80  
75 81 if SPI_FLASH
76 82  
drivers/spi/spi-uclass.c
... ... @@ -328,7 +328,9 @@
328 328 }
329 329  
330 330 plat = dev_get_parent_platdata(dev);
331   - if (!speed) {
  331 +
  332 + /* get speed and mode from platdata when available */
  333 + if (plat->max_hz) {
332 334 speed = plat->max_hz;
333 335 mode = plat->mode;
334 336 }
... ... @@ -496,14 +496,15 @@
496 496 * device and slave device.
497 497 *
498 498 * If no such slave exists, and drv_name is not NULL, then a new slave device
499   - * is automatically bound on this chip select.
  499 + * is automatically bound on this chip select with requested speed and mode.
500 500 *
501   - * Ths new slave device is probed ready for use with the given speed and mode.
  501 + * Ths new slave device is probed ready for use with the speed and mode
  502 + * from platdata when available or the requested values.
502 503 *
503 504 * @busnum: SPI bus number
504 505 * @cs: Chip select to look for
505   - * @speed: SPI speed to use for this slave
506   - * @mode: SPI mode to use for this slave
  506 + * @speed: SPI speed to use for this slave when not available in platdata
  507 + * @mode: SPI mode to use for this slave when not available in platdata
507 508 * @drv_name: Name of driver to attach to this chip select
508 509 * @dev_name: Name of the new device thus created
509 510 * @busp: Returns bus device