[U-Boot] [PATCH v1 02/19] dm: i2c: Add dm_i2c_probe_device() to test the presence of a chip
Jean-Jacques Hiblot
jjhiblot at ti.com
Thu Oct 4 13:47:27 UTC 2018
In a non-DM environment, it is possible to test the presence of a chip
using i2c_probe(chip_addr).
dm_i2c_probe_device() brings the same functionality with a DM interface.
The intent is to be able to test the presence of a chip for the device has
been created with i2c_get_chip_for_busnum(bus_num, chip_addr, ...)
Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>
---
drivers/i2c/i2c-uclass.c | 8 ++++++++
include/i2c.h | 13 +++++++++++++
2 files changed, 21 insertions(+)
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index c5a3c4e..ec88168 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -378,6 +378,14 @@ int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags,
return ret;
}
+int dm_i2c_probe_device(struct udevice *dev)
+{
+ struct udevice *bus = dev_get_parent(dev);
+ struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
+
+ return i2c_probe_chip(bus, chip->chip_addr, chip->flags);
+}
+
int dm_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
{
struct dm_i2c_ops *ops = i2c_get_ops(bus);
diff --git a/include/i2c.h b/include/i2c.h
index d33f827..3c8fde2 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -167,6 +167,19 @@ int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags,
struct udevice **devp);
/**
+ * dm_i2c_probe_dev() - probe the presence of a I2C device
+ *
+ * This can be useful to check for the existence of a chip already probed
+ * (software wise).
+ * It is typically implemented by writing the chip address to the bus
+ * and checking that the chip replies with an ACK.
+ *
+ * @bus: Device to probe
+ * @return 0 if a chip was found at that address, -ve if not
+ */
+int dm_i2c_probe_device(struct udevice *dev);
+
+/**
* dm_i2c_reg_read() - Read a value from an I2C register
*
* This reads a single value from the given address in an I2C chip
--
2.7.4
More information about the U-Boot
mailing list