diff options
author | Matt DeVillier <matt.devillier@gmail.com> | 2022-05-19 19:03:07 -0500 |
---|---|---|
committer | Paul Fagerburg <pfagerburg@chromium.org> | 2022-05-31 13:43:39 +0000 |
commit | ee849ba62574ac52e04d80f774a374d9b7558f67 (patch) | |
tree | 98d83a6f66f113c4717cff4006a620dc7d3b5727 | |
parent | 57097130d5e4880e39ce8f63eba6f11d7c51e94c (diff) |
dev/i2c_bus: Add declaration, implementation of i2c_dev_detect()
This patch adds the I2C equivalent of an SMBus quick write to an I2C
device, which is used by some I2C drivers as a way to probe the
existence (or absence) of a certain device on the bus, based on
whether or not a 0-byte write to an I2C address is ACKed or NACKed.
i2c_dev_detect() is implemented using the existing i2c bus ops transfer()
function, so no further work is needed for existing controller drivers
to utilize this functionality.
Change-Id: I9b22bdc0343c846b235339f85d9f70b20f0f2bdd
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/64537
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin L Roth <gaumless@tutanota.com>
-rw-r--r-- | src/device/i2c_bus.c | 6 | ||||
-rw-r--r-- | src/include/device/i2c_bus.h | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/device/i2c_bus.c b/src/device/i2c_bus.c index a63086cf41..c355506f72 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 42f461dc9e..1a7e777278 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`. |