]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
i2c: of: Try to find an I2C adapter matching the parent
authorThierry Reding <treding@nvidia.com>
Fri, 25 Jan 2019 13:11:42 +0000 (14:11 +0100)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1838116
[ Upstream commit e814e688413aabd7b0d75e2a8ed1caa472951dec ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/i2c/i2c-core-of.c

index 8d474bb1dc15755ddc0a5768ae7c518d5d374fec..be11757825850f45603b70b4cf5722f447f0bf3f 100644 (file)
@@ -118,6 +118,17 @@ static int of_dev_node_match(struct device *dev, void *data)
        return dev->of_node == data;
 }
 
+static int of_dev_or_parent_node_match(struct device *dev, void *data)
+{
+       if (dev->of_node == data)
+               return 1;
+
+       if (dev->parent)
+               return dev->parent->of_node == data;
+
+       return 0;
+}
+
 /* must call put_device() when done with returned i2c_client device */
 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 {
@@ -142,7 +153,8 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
        struct device *dev;
        struct i2c_adapter *adapter;
 
-       dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
+       dev = bus_find_device(&i2c_bus_type, NULL, node,
+                             of_dev_or_parent_node_match);
        if (!dev)
                return NULL;