Commit 96907c0fe50a856f66f60ade68864a2d7949bf15

Authored by Vignesh R
Committed by Jagan Teki
1 parent e835a74159

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_*, 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>
Reviewed-by: Jagan Teki <jteki@openedev.com>

Showing 3 changed files with 12 additions and 6 deletions Side-by-side Diff

... ... @@ -88,6 +88,8 @@
88 88 #ifdef CONFIG_DM_SPI_FLASH
89 89 struct udevice *new, *bus_dev;
90 90 int ret;
  91 + /* In DM mode defaults will be taken from DT */
  92 + speed = 0, mode = 0;
91 93 #else
92 94 struct spi_flash *new;
93 95 #endif
... ... @@ -55,9 +55,9 @@
55 55 #ifdef CONFIG_DM_SPI_FLASH
56 56 struct udevice *new;
57 57  
  58 + /* speed and mode will be read from DT */
58 59 ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
59   - CONFIG_ENV_SPI_MAX_HZ,
60   - CONFIG_ENV_SPI_MODE, &new);
  60 + 0, 0, &new);
61 61 if (ret) {
62 62 set_default_env("!spi_flash_probe_bus_cs() failed");
63 63 return 1;
64 64  
... ... @@ -245,9 +245,9 @@
245 245 #ifdef CONFIG_DM_SPI_FLASH
246 246 struct udevice *new;
247 247  
  248 + /* speed and mode will be read from DT */
248 249 ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
249   - CONFIG_ENV_SPI_MAX_HZ,
250   - CONFIG_ENV_SPI_MODE, &new);
  250 + 0, 0, &new);
251 251 if (ret) {
252 252 set_default_env("!spi_flash_probe_bus_cs() failed");
253 253 return 1;
drivers/spi/spi-uclass.c
... ... @@ -278,6 +278,7 @@
278 278 struct udevice **busp, struct spi_slave **devp)
279 279 {
280 280 struct udevice *bus, *dev;
  281 + struct dm_spi_slave_platdata *plat;
281 282 bool created = false;
282 283 int ret;
283 284  
... ... @@ -294,8 +295,6 @@
294 295 * SPI flash chip - we will bind to the correct driver.
295 296 */
296 297 if (ret == -ENODEV && drv_name) {
297   - struct dm_spi_slave_platdata *plat;
298   -
299 298 debug("%s: Binding new device '%s', busnum=%d, cs=%d, driver=%s\n",
300 299 __func__, dev_name, busnum, cs, drv_name);
301 300 ret = device_bind_driver(bus, drv_name, dev_name, &dev);
... ... @@ -322,6 +321,11 @@
322 321 slave->dev = dev;
323 322 }
324 323  
  324 + plat = dev_get_parent_platdata(dev);
  325 + if (!speed) {
  326 + speed = plat->max_hz;
  327 + mode = plat->mode;
  328 + }
325 329 ret = spi_set_speed_mode(bus, speed, mode);
326 330 if (ret)
327 331 goto err;