From patchwork Mon Nov 7 12:47:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 81067 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp993361qge; Mon, 7 Nov 2016 04:48:29 -0800 (PST) X-Received: by 10.98.50.5 with SMTP id y5mr13144082pfy.141.1478522909265; Mon, 07 Nov 2016 04:48:29 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si21658107pft.153.2016.11.07.04.48.29; Mon, 07 Nov 2016 04:48:29 -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 S1753126AbcKGMsK (ORCPT + 27 others); Mon, 7 Nov 2016 07:48:10 -0500 Received: from mail.kernel.org ([198.145.29.136]:56668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753025AbcKGMsI (ORCPT ); Mon, 7 Nov 2016 07:48:08 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5924820220; Mon, 7 Nov 2016 12:48:06 +0000 (UTC) Received: from CookieMonster.cookiemonster.local (cpc87017-aztw30-2-0-cust65.18-1.cable.virginm.net [92.232.232.66]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2F7B12021F; Mon, 7 Nov 2016 12:48:04 +0000 (UTC) From: Kieran Bingham To: Wolfram Sang , Lee Jones , Kieran Bingham Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Javier Martinez Canillas , sameo@linux.intel.com Subject: [PATCHv7 02/11] i2c: Add the ability to match device to compatible string without an of_node Date: Mon, 7 Nov 2016 12:47:37 +0000 Message-Id: <1478522866-29620-3-git-send-email-kieran@bingham.xyz> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478522866-29620-1-git-send-email-kieran@bingham.xyz> References: <1478522866-29620-1-git-send-email-kieran@bingham.xyz> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lee Jones 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. Acked-by: Grant Likely Signed-off-by: Lee Jones [Kieran: strnicmp to strncasecmp] Tested-by: Kieran Bingham Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas Signed-off-by: Kieran Bingham --- changes from v6 - Rename i2c_of_match_device_strip_vendor to i2c_of_match_device_sysfs drivers/i2c/i2c-core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- 2.7.4 diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 86083e5e5520..dcbda850804f 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1769,6 +1769,27 @@ struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node) return adapter; } EXPORT_SYMBOL(of_get_i2c_adapter_by_node); + +static const struct of_device_id* +i2c_of_match_device_sysfs(const struct of_device_id *matches, + struct i2c_client *client) +{ + const char *name; + + for (; matches->compatible[0]; matches++) { + name = strchr(matches->compatible, ','); + if (!name) + name = matches->compatible; + else + name++; + + if (!strncasecmp(client->name, name, strlen(client->name))) + return matches; + } + + return NULL; +} + #else static void of_i2c_register_devices(struct i2c_adapter *adap) { } #endif /* CONFIG_OF */