Commit 279e26f5a3b865b1a6acf87b404ddec80bc57e63
1 parent
8327d41b19
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
dm: spi: Convert uclass to livetree
Update the SPI uclass to support a live device tree. Also adjust spi_slave_ofdata_to_platdata() to accept a device instead of a blob and offset. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 15 additions and 18 deletions Side-by-side Diff
drivers/spi/spi-uclass.c
... | ... | @@ -7,7 +7,6 @@ |
7 | 7 | #include <common.h> |
8 | 8 | #include <dm.h> |
9 | 9 | #include <errno.h> |
10 | -#include <fdtdec.h> | |
11 | 10 | #include <malloc.h> |
12 | 11 | #include <spi.h> |
13 | 12 | #include <dm/device-internal.h> |
14 | 13 | |
... | ... | @@ -113,11 +112,10 @@ |
113 | 112 | { |
114 | 113 | struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev); |
115 | 114 | |
116 | - if (dev_of_offset(dev) == -1) | |
115 | + if (!dev_of_valid(dev)) | |
117 | 116 | return 0; |
118 | 117 | |
119 | - return spi_slave_ofdata_to_platdata(gd->fdt_blob, dev_of_offset(dev), | |
120 | - plat); | |
118 | + return spi_slave_ofdata_to_platdata(dev, plat); | |
121 | 119 | } |
122 | 120 | #endif |
123 | 121 | |
... | ... | @@ -126,8 +124,7 @@ |
126 | 124 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
127 | 125 | struct dm_spi_bus *spi = dev_get_uclass_priv(bus); |
128 | 126 | |
129 | - spi->max_hz = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), | |
130 | - "spi-max-frequency", 0); | |
127 | + spi->max_hz = dev_read_u32_default(bus, "spi-max-frequency", 0); | |
131 | 128 | #endif |
132 | 129 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
133 | 130 | struct dm_spi_ops *ops = spi_get_ops(bus); |
... | ... | @@ -375,7 +372,7 @@ |
375 | 372 | int ret; |
376 | 373 | |
377 | 374 | ret = spi_get_bus_and_cs(busnum, cs, speed, mode, NULL, 0, &dev, |
378 | - &slave); | |
375 | + &slave); | |
379 | 376 | if (ret) |
380 | 377 | return NULL; |
381 | 378 | |
382 | 379 | |
383 | 380 | |
384 | 381 | |
385 | 382 | |
386 | 383 | |
387 | 384 | |
... | ... | @@ -388,27 +385,27 @@ |
388 | 385 | slave->dev = NULL; |
389 | 386 | } |
390 | 387 | |
391 | -int spi_slave_ofdata_to_platdata(const void *blob, int node, | |
388 | +int spi_slave_ofdata_to_platdata(struct udevice *dev, | |
392 | 389 | struct dm_spi_slave_platdata *plat) |
393 | 390 | { |
394 | 391 | int mode = 0; |
395 | 392 | int value; |
396 | 393 | |
397 | - plat->cs = fdtdec_get_int(blob, node, "reg", -1); | |
398 | - plat->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency", 0); | |
399 | - if (fdtdec_get_bool(blob, node, "spi-cpol")) | |
394 | + plat->cs = dev_read_u32_default(dev, "reg", -1); | |
395 | + plat->max_hz = dev_read_u32_default(dev, "spi-max-frequency", 0); | |
396 | + if (dev_read_bool(dev, "spi-cpol")) | |
400 | 397 | mode |= SPI_CPOL; |
401 | - if (fdtdec_get_bool(blob, node, "spi-cpha")) | |
398 | + if (dev_read_bool(dev, "spi-cpha")) | |
402 | 399 | mode |= SPI_CPHA; |
403 | - if (fdtdec_get_bool(blob, node, "spi-cs-high")) | |
400 | + if (dev_read_bool(dev, "spi-cs-high")) | |
404 | 401 | mode |= SPI_CS_HIGH; |
405 | - if (fdtdec_get_bool(blob, node, "spi-3wire")) | |
402 | + if (dev_read_bool(dev, "spi-3wire")) | |
406 | 403 | mode |= SPI_3WIRE; |
407 | - if (fdtdec_get_bool(blob, node, "spi-half-duplex")) | |
404 | + if (dev_read_bool(dev, "spi-half-duplex")) | |
408 | 405 | mode |= SPI_PREAMBLE; |
409 | 406 | |
410 | 407 | /* Device DUAL/QUAD mode */ |
411 | - value = fdtdec_get_uint(blob, node, "spi-tx-bus-width", 1); | |
408 | + value = dev_read_u32_default(dev, "spi-tx-bus-width", 1); | |
412 | 409 | switch (value) { |
413 | 410 | case 1: |
414 | 411 | break; |
... | ... | @@ -423,7 +420,7 @@ |
423 | 420 | break; |
424 | 421 | } |
425 | 422 | |
426 | - value = fdtdec_get_uint(blob, node, "spi-rx-bus-width", 1); | |
423 | + value = dev_read_u32_default(dev, "spi-rx-bus-width", 1); | |
427 | 424 | switch (value) { |
428 | 425 | case 1: |
429 | 426 | break; |
include/spi.h
... | ... | @@ -562,7 +562,7 @@ |
562 | 562 | * @node: Node offset to read from |
563 | 563 | * @plat: Place to put the decoded information |
564 | 564 | */ |
565 | -int spi_slave_ofdata_to_platdata(const void *blob, int node, | |
565 | +int spi_slave_ofdata_to_platdata(struct udevice *dev, | |
566 | 566 | struct dm_spi_slave_platdata *plat); |
567 | 567 | |
568 | 568 | /** |