[U-Boot] [PATCH 3/3] dm: i2c: get chip address with dev_get_reg()

Przemyslaw Marczak
2015-12-15T16:32:03Z

This commit cleanups the I2C uclass driver by:
- simplify i2c_child_post_bind() method
- cleanups i2c_chip_ofdata_to_platdata(), by calling dev_get_reg()
for getting chip address

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Heiko Schocher <hs@denx.de>
Cc: Stefan Roese <sr@denx.de>
---
drivers/i2c/i2c-uclass.c | 17 ++++++++---------
include/i2c.h | 11 ++++-------
2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index 50b99ea..3cfbd22 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -467,16 +467,17 @@ int i2c_deblock(struct udevice *bus)
return ops->deblock(bus);
}

-int i2c_chip_ofdata_to_platdata(const void *blob, int node,
- struct dm_i2c_chip *chip)
+int i2c_chip_ofdata_to_platdata(struct udevice *dev)
{
- chip->offset_len = fdtdec_get_int(gd->fdt_blob, node,
+ struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
+
+ chip->offset_len = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
"u-boot,i2c-offset-len", 1);
chip->flags = 0;
- chip->chip_addr = fdtdec_get_int(gd->fdt_blob, node, "reg", -1);
- if (chip->chip_addr == -1) {
+ chip->chip_addr = dev_get_reg(dev);
+ if (chip->chip_addr == FDT_ADDR_T_NONE) {
debug("%s: I2C Node '%s' has no 'reg' property\n", __func__,
- fdt_get_name(blob, node, NULL));
+ fdt_get_name(gd->fdt_blob, dev->of_offset, NULL));
return -EINVAL;
}

@@ -501,12 +502,10 @@ static int i2c_post_bind(struct udevice *dev)

static int i2c_child_post_bind(struct udevice *dev)
{
- struct dm_i2c_chip *plat = dev_get_parent_platdata(dev);
-
if (dev->of_offset == -1)
return 0;

- return i2c_chip_ofdata_to_platdata(gd->fdt_blob, dev->of_offset, plat);
+ return i2c_chip_ofdata_to_platdata(dev);
}

UCLASS_DRIVER(i2c) = {
diff --git a/include/i2c.h b/include/i2c.h
index 1f5ae45..c5bb39c 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -518,15 +518,12 @@ int i2c_get_chip_for_busnum(int busnum, int chip_addr, uint offset_len,
* i2c_chip_ofdata_to_platdata() - Decode standard I2C platform data
*
* This decodes the chip address from a device tree node and puts it into
- * its dm_i2c_chip structure. This should be called in your driver's
- * ofdata_to_platdata() method.
+ * its dm_i2c_chip structure. This is called after device's bind inside
+ * uclass driver's i2c_child_post_bind() method.
*
- * @blob: Device tree blob
- * @node: Node offset to read from
- * @spi: Place to put the decoded information
+ * @dev: pointer to a chip device
*/
-int i2c_chip_ofdata_to_platdata(const void *blob, int node,
- struct dm_i2c_chip *chip);
+int i2c_chip_ofdata_to_platdata(struct udevice *dev);

/**
* i2c_dump_msgs() - Dump a list of I2C messages
--
1.9.1