From patchwork Fri Sep 11 11:55:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 53447 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 C208F215BF for ; Fri, 11 Sep 2015 11:59:34 +0000 (UTC) Received: by lamp12 with SMTP id p12sf24511495lam.2 for ; Fri, 11 Sep 2015 04:59:33 -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=z+a5UFWrIJlpBhLP3kxPb4/y9mPGr5g9VVCuI31X6Wg=; b=PWv6OK6x5wWZQtho6+R71lgyIsxs5uZUeywUyV8KBrAcNPWzOYkKfM/CzHiiaw24V/ Hbi3cxOlObsuvh1S9C5t6+mtMNnR5A0+2SdbU8sQ16G/pnh8IEOucze5cD8LBlSNkAB2 YofaU9hoswcw18XJASp3hI4KkWGQWrSr3eaR2emVS3C8jAfdg3LyB5r5FMJBSGgvCabr 9edcM1CXS3y0PcLW4tWFJwLTluNK1yGmwo/oGaZ2RAGd56fNXanfkAjBryOtnUAS+XqV tVpyTA/F3vQ0o3uAUe9bqwgn7aLPEu3NjXIy7Yh/XM0g/jhUzU1+Wt/1i2b625T+87M0 rPLw== X-Gm-Message-State: ALoCoQnqOfsgCzw61QS5BtZ+ziCqbQKiAUw34nY5IFQiW5T9VXi2ucBlraANiEVIUJTUEZ7taAOu X-Received: by 10.180.12.203 with SMTP id a11mr2306889wic.3.1441972773729; Fri, 11 Sep 2015 04:59:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.227 with SMTP id t3ls262951laj.98.gmail; Fri, 11 Sep 2015 04:59:33 -0700 (PDT) X-Received: by 10.152.161.232 with SMTP id xv8mr25044625lab.32.1441972773535; Fri, 11 Sep 2015 04:59:33 -0700 (PDT) Received: from mail-la0-x230.google.com (mail-la0-x230.google.com. [2a00:1450:4010:c03::230]) by mx.google.com with ESMTPS id j10si759771lbv.162.2015.09.11.04.59.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 04:59:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::230 as permitted sender) client-ip=2a00:1450:4010:c03::230; Received: by lagj9 with SMTP id j9so47090558lag.2 for ; Fri, 11 Sep 2015 04:59:33 -0700 (PDT) X-Received: by 10.152.161.232 with SMTP id xv8mr25044600lab.32.1441972772970; Fri, 11 Sep 2015 04:59:32 -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 w3csp1542555lbq; Fri, 11 Sep 2015 04:59:31 -0700 (PDT) X-Received: by 10.107.150.196 with SMTP id y187mr3072714iod.91.1441972771841; Fri, 11 Sep 2015 04:59:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d79si138723ioj.86.2015.09.11.04.59.31; Fri, 11 Sep 2015 04:59:31 -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 S1753023AbbIKL73 (ORCPT + 28 others); Fri, 11 Sep 2015 07:59:29 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:34276 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751696AbbIKL5u (ORCPT ); Fri, 11 Sep 2015 07:57:50 -0400 Received: by wicfx3 with SMTP id fx3so61311144wic.1; Fri, 11 Sep 2015 04:57:48 -0700 (PDT) X-Received: by 10.194.222.227 with SMTP id qp3mr6645172wjc.36.1441972668859; Fri, 11 Sep 2015 04:57:48 -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 wj4sm25354wjb.10.2015.09.11.04.57.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Sep 2015 04:57:47 -0700 (PDT) From: Kieran Bingham To: Wolfram Sang , Samuel Ortiz , Lee Jones Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, grant.likely@linaro.org, javier@osg.samsung.com, Kieran Bingham Subject: [RESEND PATCH v4 3/8] i2c: Match using traditional OF methods, then by vendor-less compatible strings Date: Fri, 11 Sep 2015 12:55:59 +0100 Message-Id: <1441972564-9621-4-git-send-email-kieranbingham@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441972564-9621-1-git-send-email-kieranbingham@gmail.com> References: <1441972564-9621-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:c03::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 Signed-off-by: Kieran Bingham --- 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 */