Commit 1704308eb63bca0425c524438a7a2992689e2982
1 parent
a7d0021063
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
dm: i2c: Convert uclass to livetree
Update the i2c uclass to support a live device tree. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 14 additions and 17 deletions Side-by-side Diff
drivers/i2c/i2c-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 <i2c.h> |
12 | 11 | #include <malloc.h> |
13 | 12 | #include <dm/device-internal.h> |
14 | 13 | |
15 | 14 | |
16 | 15 | |
... | ... | @@ -467,18 +466,20 @@ |
467 | 466 | } |
468 | 467 | |
469 | 468 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
470 | -int i2c_chip_ofdata_to_platdata(const void *blob, int node, | |
471 | - struct dm_i2c_chip *chip) | |
469 | +int i2c_chip_ofdata_to_platdata(struct udevice *dev, struct dm_i2c_chip *chip) | |
472 | 470 | { |
473 | - chip->offset_len = fdtdec_get_int(gd->fdt_blob, node, | |
474 | - "u-boot,i2c-offset-len", 1); | |
471 | + int addr; | |
472 | + | |
473 | + chip->offset_len = dev_read_u32_default(dev, "u-boot,i2c-offset-len", | |
474 | + 1); | |
475 | 475 | chip->flags = 0; |
476 | - chip->chip_addr = fdtdec_get_int(gd->fdt_blob, node, "reg", -1); | |
477 | - if (chip->chip_addr == -1) { | |
478 | - debug("%s: I2C Node '%s' has no 'reg' property\n", __func__, | |
479 | - fdt_get_name(blob, node, NULL)); | |
476 | + addr = dev_read_u32_default(dev, "reg", -1); | |
477 | + if (addr == -1) { | |
478 | + debug("%s: I2C Node '%s' has no 'reg' property %s\n", __func__, | |
479 | + dev_read_name(dev), dev->name); | |
480 | 480 | return -EINVAL; |
481 | 481 | } |
482 | + chip->chip_addr = addr; | |
482 | 483 | |
483 | 484 | return 0; |
484 | 485 | } |
... | ... | @@ -489,8 +490,7 @@ |
489 | 490 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
490 | 491 | struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev); |
491 | 492 | |
492 | - i2c->speed_hz = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), | |
493 | - "clock-frequency", 100000); | |
493 | + i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency", 100000); | |
494 | 494 | |
495 | 495 | return dm_i2c_set_bus_speed(dev, i2c->speed_hz); |
496 | 496 | #else |
497 | 497 | |
... | ... | @@ -503,11 +503,9 @@ |
503 | 503 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
504 | 504 | struct dm_i2c_chip *plat = dev_get_parent_platdata(dev); |
505 | 505 | |
506 | - if (dev_of_offset(dev) == -1) | |
506 | + if (!dev_of_valid(dev)) | |
507 | 507 | return 0; |
508 | - | |
509 | - return i2c_chip_ofdata_to_platdata(gd->fdt_blob, dev_of_offset(dev), | |
510 | - plat); | |
508 | + return i2c_chip_ofdata_to_platdata(dev, plat); | |
511 | 509 | #else |
512 | 510 | return 0; |
513 | 511 | #endif |
include/i2c.h
... | ... | @@ -525,8 +525,7 @@ |
525 | 525 | * @node: Node offset to read from |
526 | 526 | * @spi: Place to put the decoded information |
527 | 527 | */ |
528 | -int i2c_chip_ofdata_to_platdata(const void *blob, int node, | |
529 | - struct dm_i2c_chip *chip); | |
528 | +int i2c_chip_ofdata_to_platdata(struct udevice *dev, struct dm_i2c_chip *chip); | |
530 | 529 | |
531 | 530 | /** |
532 | 531 | * i2c_dump_msgs() - Dump a list of I2C messages |