From patchwork Fri Jan 25 13:11:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 10781347 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87D4F922 for ; Fri, 25 Jan 2019 13:11:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7735D2F5E2 for ; Fri, 25 Jan 2019 13:11:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B0F52F6AE; Fri, 25 Jan 2019 13:11:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2077E2F60D for ; Fri, 25 Jan 2019 13:11:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C831189B95; Fri, 25 Jan 2019 13:11:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4F5AE89A5D for ; Fri, 25 Jan 2019 13:11:46 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id y8so6563946wmi.4 for ; Fri, 25 Jan 2019 05:11:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aQn5vfGBJuPihT9+lVxG/EDhj6eto8PXg4ptWHreGII=; b=o7P7pzdhti38DLQls6bZRA/bi+nizgfMXGY2osVP8vmcplzOUX43LN2eKq1CycIo9B TGwNC/rGZBKWvJINY+oMEcxb1Kt8HGFTOYUonAAlgdsyXb1kHuNijZF05SkYoV9qFz5c cDF3ekrBOtjjEfwe2WfAdflEYvkdRf25pPIT8VVxY6Nyu9oif31qquOiqPAvyWcN8D/t RPTViQjbE7B8r8Ayp/em9+EzzZJgYfnnYLMFRsJiFgJ9ookPJpofXRSdSxiWf3f9L/t2 PYfr10/hLwbRnyq274oP1IsCLPqwHXQdzNrwh/6hRCzrAFZJSs97mGKs3mHTz3mk/b9W fkRA== X-Gm-Message-State: AJcUukcn2E/FY9xZ9O+5t9s+ql1229YXVwY38YM4ciWR11uxyBbkbqa9 7HAyidLR13bz351MEZdzh2Y= X-Google-Smtp-Source: ALg8bN42oFi2lrRphOCRoBA7Ydbzmljk7DsTZ65sf0MxjHJgqG1LKm0Clm8/WS/kZQcWzrDfSDe3Ug== X-Received: by 2002:a1c:4301:: with SMTP id q1mr6821577wma.44.1548421904824; Fri, 25 Jan 2019 05:11:44 -0800 (PST) Received: from localhost (pD9E51040.dip0.t-ipconnect.de. [217.229.16.64]) by smtp.gmail.com with ESMTPSA id t76sm68373501wme.33.2019.01.25.05.11.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Jan 2019 05:11:44 -0800 (PST) From: Thierry Reding To: Wolfram Sang Subject: [PATCH v2] i2c: of: Try to find an I2C adapter matching the parent Date: Fri, 25 Jan 2019 14:11:42 +0100 Message-Id: <20190125131142.26837-1-thierry.reding@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tristan Bastian , Vlado Plaga , dri-devel@lists.freedesktop.org, Rob Herring , linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding 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 Tested-by: Tristan Bastian Tested-by: Tristan Bastian --- Changes in v2: - check for both device and parent device tree nodes for each device instead of looping through the list of devices twice drivers/i2c/i2c-core-of.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c index 6cb7ad608bcd..0f01cdba9d2c 100644 --- a/drivers/i2c/i2c-core-of.c +++ b/drivers/i2c/i2c-core-of.c @@ -121,6 +121,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) { @@ -145,7 +156,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;