From patchwork Mon Jun 2 13:41:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 31285 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6D6CB20AE6 for ; Mon, 2 Jun 2014 13:41:22 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id va2sf26188311obc.1 for ; Mon, 02 Jun 2014 06:41:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=b29DBVO2lWYMtxAQKee5CAcu+3/v1194177KweCQR2s=; b=drmFxF3WctOFDPlj2Uu0OcVd76eqMUsO1gis1XmMv55jHSxB43BQB4t7bL721H+8wR 5+mU3nG1m+gsvsvxtfU80EEq4VKqPo3Xx/emi7NGk/7HenbnXeFUgVx/dhgwSVyDfRAP dRvLP3YY3RqYKKYx+96fnrXVTPe909/ZxyQYmrJox5xuWf7QYwTKcUIaNTkJP6JaXnO+ BJn+5Gml7E0K03PxUSK+Mxt1aYkjKR2n16iYt8P912ACdL9xNb2yuudN6DKezVYNcb5k A7Su299zRjlr5T0TVTpQDz+ODMLXtynRAqFouhm4DWs1VC6aj7+mdC7OJcoBPmkvPQyf 4nRw== X-Gm-Message-State: ALoCoQnTcQ2DVGUiylY++EZbDVm84tiJH3jsYOpwo0fUpvIYFyVLfC/AfX0zWiPoLiPeC11IL7mS X-Received: by 10.182.128.166 with SMTP id np6mr14530554obb.16.1401716482013; Mon, 02 Jun 2014 06:41:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.209 with SMTP id x75ls2055646qgx.46.gmail; Mon, 02 Jun 2014 06:41:21 -0700 (PDT) X-Received: by 10.221.20.199 with SMTP id qp7mr30449076vcb.24.1401716481919; Mon, 02 Jun 2014 06:41:21 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id dc6si7873417vcb.70.2014.06.02.06.41.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 06:41:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.170 as permitted sender) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id db11so5148832veb.15 for ; Mon, 02 Jun 2014 06:41:21 -0700 (PDT) X-Received: by 10.58.186.207 with SMTP id fm15mr30570855vec.4.1401716481850; Mon, 02 Jun 2014 06:41:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp98745vcb; Mon, 2 Jun 2014 06:41:21 -0700 (PDT) X-Received: by 10.50.114.194 with SMTP id ji2mr19328005igb.21.1401716481168; Mon, 02 Jun 2014 06:41:21 -0700 (PDT) Received: from mail-ie0-f171.google.com (mail-ie0-f171.google.com [209.85.223.171]) by mx.google.com with ESMTPS id t10si21028197igr.26.2014.06.02.06.41.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 06:41:21 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.223.171 as permitted sender) client-ip=209.85.223.171; Received: by mail-ie0-f171.google.com with SMTP id to1so4470314ieb.30 for ; Mon, 02 Jun 2014 06:41:20 -0700 (PDT) X-Received: by 10.42.78.136 with SMTP id n8mr34758421ick.28.1401716480898; Mon, 02 Jun 2014 06:41:20 -0700 (PDT) Received: from localhost.localdomain (host109-148-113-200.range109-148.btcentralplus.com. [109.148.113.200]) by mx.google.com with ESMTPSA id hy3sm6561043igb.1.2014.06.02.06.41.18 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 06:41:20 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, wsa@the-dreams.de Cc: linus.walleij@linaro.org, grant.likely@linaro.org, linux-i2c@vger.kernel.org, Lee Jones Subject: [PATCH 1/3] i2c: Provide 'device type' to 'OF device node' look-up Date: Mon, 2 Jun 2014 14:41:01 +0100 Message-Id: <1401716463-23457-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1401716463-23457-1-git-send-email-lee.jones@linaro.org> References: <1401716463-23457-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , We have a problem. There are lots of I2C device ID tables scattered around the kernel which are redundant in all Device Tree and/or ACPI only supported device drivers. After recent discussions it has become apparent that the only thing blocking the complete removal of these tables is the continued support of 'register an I2C device via sysfs' functionality. As the sysfs method doesn't know anything about Device Tree or ACPI, we can not pass any nodes in. This patch searches all known Device Tree nodes and attempts to acquire a match from the device name provided via sysfs. It can not fail, but if found assigns the matching of_node to i2c_board_info prior to registering. Signed-off-by: Lee Jones --- drivers/i2c/i2c-core.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 7c7f4b8..2e47641 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -64,6 +64,7 @@ static DEFINE_IDR(i2c_adapter_idr); static struct device_type i2c_client_type; static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); +static struct device_node *of_i2c_type_to_node(char *type); static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; @@ -863,6 +864,8 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, return -EINVAL; } + info.of_node = of_i2c_type_to_node(info.type); + client = i2c_new_device(adap, &info); if (!client) return -EINVAL; @@ -1088,8 +1091,36 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) return i2c_verify_adapter(dev); } EXPORT_SYMBOL(of_find_i2c_adapter_by_node); + +static struct device_node *of_i2c_type_to_node(char *type) +{ + struct device_node *np; + const char *compatible, *name; + int len; + + if (!type) + return NULL; + + for_each_of_allnodes(np) { + compatible = of_get_property(np, "compatible", &len); + if (!compatible) + continue; + + name = strchr(compatible, ','); + if (!name) + name = compatible; + else + name++; + + if (!strncmp(name, type, len - (name - compatible))) + return np; + } + + return NULL; +} #else static void of_i2c_register_devices(struct i2c_adapter *adap) { } +static struct device_node *of_i2c_type_to_node(char *type) { return NULL; } #endif /* CONFIG_OF */ /* ACPI support code */