Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp912119ybv; Thu, 20 Feb 2020 09:26:34 -0800 (PST) X-Google-Smtp-Source: APXvYqz7sACPJC7XQBY/pb7+O3ppta7U4Ov3vdNcC4JDfV9lP6tUr1FYfvcH5w92WzVu8IpcfMBk X-Received: by 2002:a05:6830:10c6:: with SMTP id z6mr26145312oto.203.1582219593985; Thu, 20 Feb 2020 09:26:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582219593; cv=none; d=google.com; s=arc-20160816; b=bA0zDTNCDIt077xH1YMNvVQdkFdIc/cHIVAqISokVyayVKGpymHY6ffko+Ml1RiCrL p28WDeiT+Kpv3fIKlhWXZTOys1JwoUqwtxX8fptSJW8SlHCBTLxPsR1ZqA1+uipGryeM zFfo10ChDOE/+r/1nseZ55IW9dl2hx/LtfVAfB8lAhfzACZz8QpS0p8KuvSmWuSBVzqR Lr09wrFHaZF+dDW/fjbMIrCfINjTQymiW7qrErM9I3Ks8IfysBsjtMP9iF/ay8QPU5Js z9AMa1koJa6wH+kPvAtsgK48chHwGdACZTggoUq6/7sWwRfm6rgGge14yR5WJCU1EdSU Vhvg== 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; bh=hYQBMsmwFISps3beKnA7ier4bjunzcpzVtrv5H1waoo=; b=IWndpXxH+fk6PLvenE8kE9d+/mBCy5KAcvgCPHTwArINu3cPX4mrVEG/VxQ+l0D/nh 8junryTuWMRUIXAq1j1PBG7DMbPGFYrEQ2WjNvERktba2oUPo8hkIWIuKUFRgGcR/apK FR9sbQvOdvadoFLi6DfzHI5+mXOUr0HNYBxin5bhziB3R6wTZH9mICbPdhRHO9mtdzJx nyZYHk9JgjWh+hzFUkFTLbMFFz4mA0sArkD1O8lp3WZ8V3jR19eGJVfxswVD39gKLPho 6mQSaOAuEpzljnbBgDJpBC1daul+zeYDLV5t0AdMi6/q5n58SSyOyLENmoFKQe4HkNrj W7Ow== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a22si10653961oii.98.2020.02.20.09.26.21; Thu, 20 Feb 2020 09:26:33 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728910AbgBTR0G (ORCPT + 99 others); Thu, 20 Feb 2020 12:26:06 -0500 Received: from sauhun.de ([88.99.104.3]:35170 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728858AbgBTRZ5 (ORCPT ); Thu, 20 Feb 2020 12:25:57 -0500 Received: from localhost (p5486CC48.dip0.t-ipconnect.de [84.134.204.72]) by pokefinder.org (Postfix) with ESMTPSA id 721632C1EC5; Thu, 20 Feb 2020 18:25:54 +0100 (CET) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-i3c@lists.infradead.org, Kieran Bingham , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Luca Ceresoli , Jacopo Mondi , Laurent Pinchart , Vladimir Zapolskiy , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Wolfram Sang Subject: [RFC PATCH 7/7] i2c: core: hand over reserved devices when requesting ancillary addresses Date: Thu, 20 Feb 2020 18:24:03 +0100 Message-Id: <20200220172403.26062-8-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200220172403.26062-1-wsa+renesas@sang-engineering.com> References: <20200220172403.26062-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With i2c_new_ancillary_address, we can check if the intended driver is requesting a reserved address. Update the function to do these checks. If the check passes, the "reserved" device will become a regular "dummy" device. Signed-off-by: Wolfram Sang --- drivers/i2c/i2c-core-base.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 4000a4384306..ba325f8107a3 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -975,6 +975,8 @@ struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client, u16 default_addr) { struct device_node *np = client->dev.of_node; + struct device *reserved_dev, *adapter_dev = &client->adapter->dev; + struct i2c_client *reserved_client; u32 addr = default_addr; int i; @@ -984,7 +986,21 @@ struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client, of_property_read_u32_index(np, "reg", i, &addr); } - dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr); + dev_info(adapter_dev, "Address for %s : 0x%x\n", name, addr); + + /* No need to scan muxes, siblings must sit on the same adapter */ + reserved_dev = device_find_child(adapter_dev, &addr, __i2c_check_addr_busy); + reserved_client = i2c_verify_client(reserved_dev); + + if (reserved_client) { + if (reserved_client->dev.of_node != np || + strcmp(reserved_client->name, I2C_RESERVED_DRV_NAME) != 0) + return ERR_PTR(-EBUSY); + + strlcpy(reserved_client->name, I2C_DUMMY_DRV_NAME, sizeof(client->name)); + return reserved_client; + } + return i2c_new_dummy_device(client->adapter, addr); } EXPORT_SYMBOL_GPL(i2c_new_ancillary_device); -- 2.20.1