Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: of: Try to find an I2C adapter matching the parent

If an I2C adapter doesn't match the provided device tree node, also try
matching the parent's device tree node. This allows finding an adapter
based on the device node of the parent device that was used to register
it.

This fixes a regression on Tegra124-based Chromebooks (Nyan) where the
eDP controller registers an I2C adapter that is used to read to EDID.
After commit 993a815dcbb2 ("dt-bindings: panel: Add missing .txt
suffix") this stopped working because the I2C adapter could no longer
be found. The approach in this patch fixes the regression without
introducing the issues that the above commit solved.

Fixes: 17ab7806de0c ("drm: don't link DP aux i2c adapter to the hardware device node")
Signed-off-by: Thierry Reding <treding@nvidia.com>
Tested-by: Tristan Bastian <tristan-c.bastian@gmx.de>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Thierry Reding and committed by
Wolfram Sang
e814e688 44783efd

+13 -1
+13 -1
drivers/i2c/i2c-core-of.c
··· 121 121 return dev->of_node == data; 122 122 } 123 123 124 + static int of_dev_or_parent_node_match(struct device *dev, void *data) 125 + { 126 + if (dev->of_node == data) 127 + return 1; 128 + 129 + if (dev->parent) 130 + return dev->parent->of_node == data; 131 + 132 + return 0; 133 + } 134 + 124 135 /* must call put_device() when done with returned i2c_client device */ 125 136 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) 126 137 { ··· 156 145 struct device *dev; 157 146 struct i2c_adapter *adapter; 158 147 159 - dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match); 148 + dev = bus_find_device(&i2c_bus_type, NULL, node, 149 + of_dev_or_parent_node_match); 160 150 if (!dev) 161 151 return NULL; 162 152