Commit 71634f289de5850503738635cc96753c9b2c5d09

Authored by Simon Glass
1 parent d844efec47

spi: Add of-platdata support to SPI and SPI flash

Some boards may want to use these subsystems with of-platdata in SPL. Add
support for this by avoiding any device tree access in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 13 additions and 2 deletions Side-by-side Diff

drivers/mtd/spi/spi_flash.c
... ... @@ -1138,7 +1138,7 @@
1138 1138 return ret;
1139 1139 #endif
1140 1140  
1141   -#if CONFIG_IS_ENABLED(OF_CONTROL)
  1141 +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
1142 1142 ret = spi_flash_decode_fdt(gd->fdt_blob, flash);
1143 1143 if (ret) {
1144 1144 debug("SF: FDT decode error\n");
drivers/spi/spi-uclass.c
... ... @@ -108,6 +108,7 @@
108 108 return dm_spi_xfer(slave->dev, bitlen, dout, din, flags);
109 109 }
110 110  
  111 +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
111 112 static int spi_child_post_bind(struct udevice *dev)
112 113 {
113 114 struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
114 115  
115 116  
... ... @@ -117,14 +118,16 @@
117 118  
118 119 return spi_slave_ofdata_to_platdata(gd->fdt_blob, dev->of_offset, plat);
119 120 }
  121 +#endif
120 122  
121 123 static int spi_post_probe(struct udevice *bus)
122 124 {
  125 +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
123 126 struct dm_spi_bus *spi = dev_get_uclass_priv(bus);
124 127  
125 128 spi->max_hz = fdtdec_get_int(gd->fdt_blob, bus->of_offset,
126 129 "spi-max-frequency", 0);
127   -
  130 +#endif
128 131 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
129 132 struct dm_spi_ops *ops = spi_get_ops(bus);
130 133  
131 134  
... ... @@ -274,7 +277,11 @@
274 277 bool created = false;
275 278 int ret;
276 279  
  280 +#if CONFIG_IS_ENABLED(OF_PLATDATA)
  281 + ret = uclass_first_device_err(UCLASS_SPI, &bus);
  282 +#else
277 283 ret = uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus);
  284 +#endif
278 285 if (ret) {
279 286 printf("Invalid bus %d (err=%d)\n", busnum, ret);
280 287 return ret;
281 288  
282 289  
283 290  
... ... @@ -436,14 +443,18 @@
436 443 .id = UCLASS_SPI,
437 444 .name = "spi",
438 445 .flags = DM_UC_FLAG_SEQ_ALIAS,
  446 +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
439 447 .post_bind = dm_scan_fdt_dev,
  448 +#endif
440 449 .post_probe = spi_post_probe,
441 450 .child_pre_probe = spi_child_pre_probe,
442 451 .per_device_auto_alloc_size = sizeof(struct dm_spi_bus),
443 452 .per_child_auto_alloc_size = sizeof(struct spi_slave),
444 453 .per_child_platdata_auto_alloc_size =
445 454 sizeof(struct dm_spi_slave_platdata),
  455 +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
446 456 .child_post_bind = spi_child_post_bind,
  457 +#endif
447 458 };
448 459  
449 460 UCLASS_DRIVER(spi_generic) = {