Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5646100img; Wed, 27 Mar 2019 12:21:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6/Ae6plfAY5VC9Hny19ryvptwsj5qYRegk25NJkzRVrnrJtGmbB7n5rlKztz8SS2qNTa+ X-Received: by 2002:a62:1701:: with SMTP id 1mr29290759pfx.120.1553714489556; Wed, 27 Mar 2019 12:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714489; cv=none; d=google.com; s=arc-20160816; b=t3YR4xWaW9RwAE9ceajKFuC7BVlbqUxdupxD9hlWch4JAJTt5T71rM2u1j7Z/oL9+0 F/5icBTB6vTYBbCUKUkjTvKkIRL48jsJ9eaZHQk63pBkf5rUfyAqrflAMhay0bnXwj+y 3PK0M4FIlUzJADpBDNUXPpyWaAdtlwMGZsu9RB8tzgJBtvaosj1OaKFVvpcfg6PTcl2q S8ii5qsfQpo4/T0gc0PLFr2pxzD/euuY1Yi4rFyzCIPP+1BZ71co/mNDs6ZCctXzLJ9X E/qTuwdktqZt0MUe0l7DPAA9NnG96S734OXUoXfLqIxVcHu/V0DWYVAJ5sCYoNBFGCdQ oc9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K4WEkR1a6/ejr0gBFjKLJ3hsvbdLDmmo7OjJIfBKkSA=; b=rSqLSghwJFQ2ipKNkXjkSE6xRUdWJPVIdePYiBrY3JW/0mpKoD0jzzgZKbnKVfrSnA skB04DkiSW2y0HgzhfUW7Af3DRcSd2Ai0eP1yFB6mxTo/hozmjrJWZLLwnBpyX5ukpSE Nj+wgqpOSApLDTG2zqAf+pzeenq5wOZXfKpxYxdSwpK8LVRyMvLExUZorHDKZaTscu4/ QnZU0tMwrUkLX6wdzz4RRm2SsUehJSq90TEAMsApOwVmhdOMsXlVcnqk1eEZ7GXz9lav Ws2Flx0g4Vsl7MxkE1b7GptOyZdxwWQ3FFPLSgzh/ioAmyr7OFVjPWdjxHM5QtMGd+iy I/LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Sl/cqI9T"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a15si3921201pgd.166.2019.03.27.12.21.14; Wed, 27 Mar 2019 12:21:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Sl/cqI9T"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388177AbfC0TTc (ORCPT + 99 others); Wed, 27 Mar 2019 15:19:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:49580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387585AbfC0SHn (ORCPT ); Wed, 27 Mar 2019 14:07:43 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 41CBA217F5; Wed, 27 Mar 2019 18:07:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710063; bh=ZDhQpB0ioPGHMPMBgA0cHbi3r2MKPFAktmo+AUTS5c8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sl/cqI9TTJ99WuU9uQ1+fmofWxEi6g7lHGALlhqNYHDdHl6YiuoVJyU6be+7UDSLv qrmQSgxQTvej4h1a3GVFIn8ITUg6Fg10GC+Vb0mve85fPCOmtEmLz4Df+XbtTGzJ44 S2zUfXD0jAeyRgkBU5xDRVLLD/wUQGnWMQgvHbws= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Thierry Reding , Wolfram Sang , Sasha Levin , linux-i2c@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 180/262] i2c: of: Try to find an I2C adapter matching the parent Date: Wed, 27 Mar 2019 14:00:35 -0400 Message-Id: <20190327180158.10245-180-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thierry Reding [ 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 Tested-by: Tristan Bastian Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- 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; -- 2.19.1