From patchwork Fri Jun 6 15:52:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 31493 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6CF38202DA for ; Fri, 6 Jun 2014 15:52:53 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id f8sf1362629wiw.1 for ; Fri, 06 Jun 2014 08:52:52 -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=4zkyB5xPitDiSpL03MIF9w6a8egKszxTgz2L9L0Plvo=; b=d8y23k2F8RLgbIB2NAsGTRGlSLBqAWnr9/FSHVddRegK382ihwMbdb0hFwDfnu4Cgv C/evolEY4RjBkVFOlka6LveNZDseNACGQhiFRkhlgpCAUOda3BOAFabS72jKhII/8jkx jNVWq9l8fi7KKUPYZFQIfsZbUh/Zl49pwVluiUUo7JgcTE1Q+Fx/N5NUBDfhB4L3JR20 KVeqs1ABrQsHwScFcsugOGTIULMtrJFkxVWtivRvoBzj6c+8r3L0QXbxtTAPMjc/Zf9F mHUE9mUKOyg952l+OJsldB42RcP5aeAmEXfa+3wMbOgnBx2bU7Tt41EvAqJVmNlZjTuo KSVw== X-Gm-Message-State: ALoCoQn1ccHEEKSc+5s1tpUFz70awGOhgsIu61Xzs/jYALePV9nUwbRmAhUf2KmImq1wUcxnku+M X-Received: by 10.152.170.130 with SMTP id am2mr1560120lac.8.1402069972448; Fri, 06 Jun 2014 08:52:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.134 with SMTP id t6ls707560qgd.20.gmail; Fri, 06 Jun 2014 08:52:52 -0700 (PDT) X-Received: by 10.52.92.5 with SMTP id ci5mr5543578vdb.62.1402069972293; Fri, 06 Jun 2014 08:52:52 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id is9si6663531vdb.47.2014.06.06.08.52.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Jun 2014 08:52:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id db11so3423183veb.36 for ; Fri, 06 Jun 2014 08:52:52 -0700 (PDT) X-Received: by 10.220.15.8 with SMTP id i8mr4628081vca.45.1402069972193; Fri, 06 Jun 2014 08:52:52 -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.221.54.6 with SMTP id vs6csp115246vcb; Fri, 6 Jun 2014 08:52:51 -0700 (PDT) X-Received: by 10.50.33.72 with SMTP id p8mr7400909igi.32.1402069971460; Fri, 06 Jun 2014 08:52:51 -0700 (PDT) Received: from mail-ig0-f174.google.com (mail-ig0-f174.google.com [209.85.213.174]) by mx.google.com with ESMTPS id vk3si48500180igb.39.2014.06.06.08.52.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Jun 2014 08:52:51 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.213.174 as permitted sender) client-ip=209.85.213.174; Received: by mail-ig0-f174.google.com with SMTP id h3so1006334igd.13 for ; Fri, 06 Jun 2014 08:52:51 -0700 (PDT) X-Received: by 10.42.15.70 with SMTP id k6mr7391237ica.53.1402069971185; Fri, 06 Jun 2014 08:52:51 -0700 (PDT) Received: from localhost.localdomain (host86-181-29-77.range86-181.btcentralplus.com. [86.181.29.77]) by mx.google.com with ESMTPSA id j1sm27388094ige.0.2014.06.06.08.52.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Jun 2014 08:52:50 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: wsa@the-dreams.de, grant.likely@linaro.org, linus.walleij@linaro.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, Lee Jones Subject: [PATCH 2/9] i2c: Add the ability to match device to compatible string without an of_node Date: Fri, 6 Jun 2014 16:52:25 +0100 Message-Id: <1402069952-28022-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1402069952-28022-1-git-send-email-lee.jones@linaro.org> References: <1402069952-28022-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.177 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: , A great deal of I2C devices are currently matched via DT node name, and as such the compatible naming convention of ',' has gone somewhat awry - some nodes don't supply one, some supply an arbitrary string and others the correct device name with an arbitrary vendor prefix. In an effort to correct this problem we have to supply a mechanism to match a device by compatible string AND by simple device name. This function strips off the ',' part of a supplied compatible string and attempts to match without it. The plan is to remove this function once all of the compatible strings for each device have been brought into line. Signed-off-by: Lee Jones --- drivers/i2c/i2c-core.c | 25 +++++++++++++++++++++++++ include/linux/i2c.h | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index d3802dc..face8f9 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1090,6 +1090,31 @@ 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); + +const struct of_device_id +*i2c_of_match_device_strip_vendor(const struct of_device_id *matches, + struct device *dev) +{ + const struct i2c_client *client = i2c_verify_client(dev); + const char *name; + + if (!(client && matches)) + return NULL; + + for (; matches->compatible[0]; matches++) { + name = strchr(matches->compatible, ','); + if (!name) + name = matches->compatible; + else + name++; + + if (!strnicmp(client->name, name, strlen(client->name))) + return matches; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(i2c_of_match_device_strip_vendor); #else static void of_i2c_register_devices(struct i2c_adapter *adap) { } #endif /* CONFIG_OF */ diff --git a/include/linux/i2c.h b/include/linux/i2c.h index b556e0a..f7ec75b 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -564,6 +564,9 @@ extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); /* must call put_device() when done with returned i2c_adapter device */ extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node); +extern const struct of_device_id +*i2c_of_match_device_strip_vendor(const struct of_device_id *matches, + struct device *dev); #else static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) @@ -575,6 +578,13 @@ static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node { return NULL; } + +const struct of_device_id +*i2c_of_match_device_strip_vendor(const struct of_device_id *matches, + struct device *dev) +{ + return NULL; +} #endif /* CONFIG_OF */ #endif /* _LINUX_I2C_H */