summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/device/i2c_bus.c6
-rw-r--r--src/include/device/i2c_bus.h5
2 files changed, 11 insertions, 0 deletions
diff --git a/src/device/i2c_bus.c b/src/device/i2c_bus.c
index a63086cf41bc..c355506f7256 100644
--- a/src/device/i2c_bus.c
+++ b/src/device/i2c_bus.c
@@ -6,6 +6,12 @@
#include <device/i2c_bus.h>
#include <commonlib/endian.h>
+bool i2c_dev_detect(struct device *dev, unsigned int addr)
+{
+ struct i2c_msg seg = { .flags = 0, .slave = addr, .buf = NULL, .len = 0 };
+ return dev->ops->ops_i2c_bus->transfer(dev, &seg, 0) == 0;
+}
+
struct bus *i2c_link(const struct device *const dev)
{
if (!dev || !dev->bus)
diff --git a/src/include/device/i2c_bus.h b/src/include/device/i2c_bus.h
index 42f461dc9e3a..1a7e777278c6 100644
--- a/src/include/device/i2c_bus.h
+++ b/src/include/device/i2c_bus.h
@@ -13,6 +13,11 @@ struct i2c_bus_operations {
int (*transfer)(struct device *, const struct i2c_msg *, size_t count);
};
+/**
+ * Determine device presence at a given slave address.
+ */
+bool i2c_dev_detect(struct device *dev, unsigned int addr);
+
/*
* Returns the first upstream facing link whose bus implements either
* `i2c_bus_operations` *or* `smbus_bus_operations`.