summaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
authorMatt DeVillier <matt.devillier@gmail.com>2022-05-19 19:03:07 -0500
committerPaul Fagerburg <pfagerburg@chromium.org>2022-05-31 13:43:39 +0000
commitee849ba62574ac52e04d80f774a374d9b7558f67 (patch)
tree98d83a6f66f113c4717cff4006a620dc7d3b5727 /src/device
parent57097130d5e4880e39ce8f63eba6f11d7c51e94c (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>
Diffstat (limited to 'src/device')
-rw-r--r--src/device/i2c_bus.c6
1 files changed, 6 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)