summaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2020-03-31 11:47:04 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2020-04-01 07:45:47 +0200
commit1437676f8cdf8fafd3269e364fc06f996acc0aad (patch)
tree3d73a45bd69614806c195f03606cbf7138add92b /drivers/i2c
parent1a414ba273f9d8825957ce7b55b135c3b8e2b67a (diff)
downloadbarebox-1437676f8cdf8fafd3269e364fc06f996acc0aad.tar.gz
barebox-1437676f8cdf8fafd3269e364fc06f996acc0aad.tar.xz
i2c: Port of_find_i2c_device_by_node() from Linux
Port of_find_i2c_device_by_node() from Linux in order to allow looking i2c_client up by corresponding DT node. Useful for interacting with identical raw/driverless I2C devices that are not found on the same bus between board variants. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 9df5ee70c7..2fed624d69 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -556,6 +556,19 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
return NULL;
}
+struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
+{
+ struct device_d *dev = of_find_device_by_node(node);
+
+ if (!dev)
+ return NULL;
+
+ if (dev->bus != &i2c_bus)
+ return NULL;
+
+ return to_i2c_client(dev);
+}
+
/**
* i2c_parse_fw_timings - get I2C related timing parameters from firmware
* @dev: The device to scan for I2C timing properties