From patchwork Wed Sep 9 18:33:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 53331 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id 4A5EE22B05 for ; Wed, 9 Sep 2015 18:36:05 +0000 (UTC) Received: by laeb10 with SMTP id b10sf7376795lae.1 for ; Wed, 09 Sep 2015 11:36:04 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=+R9cf2OZC6Sot6IfjyNhf4KPX12G+XAPgQvALKYvoAY=; b=D+bRwd7+3Bym555HzDHvfZqBepgBdP871MLRWPsi+k94LQ9p8ID+E4FYQ4G61EdIGe Bk+UyLi4lB30MtigBWlbey073TJPrRHdWVw0zTz4S9LPA1W0ISlEIid9nTycVp5Agg3T jTbCOS5SpHDOE3eQ3kqBUiQrJXgXwwHjNqCcsbkFxqIhDSSwNJ8di3BV7/7q47JfR4r6 YWhYAzqbXxVtkvBXXrqJLcgliI8eq/95DWsc4J/X9p+8rDRqDpSbdsniEULBJ0FdLCHi YSjTbwGbpyFrOK7j6k3FUP1ndLFxA4HZydqHp66w1QTH5gphKKDlRHrNqYmqxH02gs4j /5og== X-Gm-Message-State: ALoCoQlaE6TnuA6jknsiDzM3m0pSxRkdElOM4WOTRmstBa+Mk97LBg1t+WztskdPsiO9s0RFS0/L X-Received: by 10.152.29.36 with SMTP id g4mr8553402lah.3.1441823764182; Wed, 09 Sep 2015 11:36:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.243.39 with SMTP id wv7ls85620lac.85.gmail; Wed, 09 Sep 2015 11:36:04 -0700 (PDT) X-Received: by 10.152.234.72 with SMTP id uc8mr21976635lac.80.1441823764007; Wed, 09 Sep 2015 11:36:04 -0700 (PDT) Received: from mail-lb0-x230.google.com (mail-lb0-x230.google.com. [2a00:1450:4010:c04::230]) by mx.google.com with ESMTPS id d2si7474544laa.142.2015.09.09.11.36.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Sep 2015 11:36:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::230 as permitted sender) client-ip=2a00:1450:4010:c04::230; Received: by lbcao8 with SMTP id ao8so10774730lbc.3 for ; Wed, 09 Sep 2015 11:36:03 -0700 (PDT) X-Received: by 10.152.18.194 with SMTP id y2mr30781505lad.88.1441823763872; Wed, 09 Sep 2015 11:36:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp492752lbq; Wed, 9 Sep 2015 11:36:02 -0700 (PDT) X-Received: by 10.66.159.229 with SMTP id xf5mr62425590pab.45.1441823762830; Wed, 09 Sep 2015 11:36:02 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pz9si4950125pbb.69.2015.09.09.11.36.01; Wed, 09 Sep 2015 11:36:02 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754738AbbIISf6 (ORCPT + 28 others); Wed, 9 Sep 2015 14:35:58 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:34539 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754755AbbIISea (ORCPT ); Wed, 9 Sep 2015 14:34:30 -0400 Received: by wicfx3 with SMTP id fx3so1571755wic.1; Wed, 09 Sep 2015 11:34:28 -0700 (PDT) X-Received: by 10.194.95.71 with SMTP id di7mr61905968wjb.125.1441823668306; Wed, 09 Sep 2015 11:34:28 -0700 (PDT) Received: from localhost.localdomain (cpc17-aztw24-2-0-cust759.aztw.cable.virginm.net. [92.237.134.248]) by smtp.gmail.com with ESMTPSA id u1sm5155141wiz.22.2015.09.09.11.34.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 11:34:27 -0700 (PDT) From: Kieran Bingham To: Wolfram Sang , Samuel Ortiz , Lee Jones Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linus.walleij@linaro.org, grant.likely@linaro.org Subject: [PATCH v4 3/8] i2c: Match using traditional OF methods, then by vendor-less compatible strings Date: Wed, 9 Sep 2015 19:33:42 +0100 Message-Id: <1441823627-6227-4-git-send-email-kieranbingham@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441823627-6227-1-git-send-email-kieranbingham@gmail.com> References: <1441823627-6227-1-git-send-email-kieranbingham@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: kieranbingham@gmail.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::230 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@gmail.com; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Lee Jones This function provides a single call for all I2C devices which need to match firstly using traditional OF means i.e by of_node, then if that fails we attempt to match using the supplied I2C client name with a list of supplied compatible strings with the ',' string removed. The latter is required due to the unruly naming conventions used currently by I2C devices. Acked-by: Grant Likely Signed-off-by: Lee Jones --- drivers/i2c/i2c-core.c | 16 ++++++++++++++++ include/linux/i2c.h | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 0788c1f..94ca76e 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1394,6 +1394,22 @@ i2c_of_match_device_strip_vendor(const struct of_device_id *matches, return NULL; } +const struct of_device_id +*i2c_of_match_device(const struct of_device_id *matches, + struct i2c_client *client) +{ + const struct of_device_id *match; + + if (!(client && matches)) + return NULL; + + match = of_match_device(matches, &client->dev); + if (match) + return match; + + return i2c_of_match_device_strip_vendor(matches, client); +} +EXPORT_SYMBOL_GPL(i2c_of_match_device); #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 e83a738..48bbbab 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -638,6 +638,10 @@ 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(const struct of_device_id *matches, + struct i2c_client *client); + #else static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) @@ -649,6 +653,14 @@ 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(const struct of_device_id *matches, + struct i2c_client *client) +{ + return NULL; +} + #endif /* CONFIG_OF */ #endif /* _LINUX_I2C_H */