From patchwork Wed Sep 9 18:33:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 53325 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 patches.linaro.org (Postfix) with ESMTPS id 9142F22B05 for ; Wed, 9 Sep 2015 18:34:38 +0000 (UTC) Received: by wisv5 with SMTP id v5sf9999711wis.0 for ; Wed, 09 Sep 2015 11:34:37 -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=+xdn9DZBPyfCDiQ3gYnrs5TvEHGSQWxmMSBSEk9C4B4=; b=VudyBVP3RRqZrSrGXkimDVTIchRLQOVWc6PHhlII43dZBsE3wScTCFR2icgbGbySQD 2UPRryw3dT1WYS/KtNXCFnKcC7uK0Ibek9Ld6w/QrSO0EsEbMfKhNk0lXZ4QlfdRIC7E kmOvvvhFjUuxIu3W6M9N3MVuHnvIhXpUca52ogvoJUp7yijkfyOqeaS+f4HJFHGnEZBn xqOAvvYsEUyoumUHubjFeBhdTmlJ0dDrlxo47tHp7iZE/Eo8o8NvHzZLFXF72xBy4DOT Q9sEt/WmvmH4OOgwADzeeFsz5s57AZx3eGHPdpPAEm5ec6IoTUn3stPSGzsn3vEz9UPx JahA== X-Gm-Message-State: ALoCoQlLv8aQ6QoYp/YQKKlGx3CatNqL5kojI3klEPp0iSIbL+lz87F6uz2vy6qXBQzLdqiYa+1R X-Received: by 10.152.224.129 with SMTP id rc1mr8540042lac.10.1441823677763; Wed, 09 Sep 2015 11:34:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.130 with SMTP id r2ls75930laa.87.gmail; Wed, 09 Sep 2015 11:34:37 -0700 (PDT) X-Received: by 10.112.210.6 with SMTP id mq6mr30308556lbc.83.1441823677432; Wed, 09 Sep 2015 11:34:37 -0700 (PDT) Received: from mail-la0-x229.google.com (mail-la0-x229.google.com. [2a00:1450:4010:c03::229]) by mx.google.com with ESMTPS id c5si7483584lae.45.2015.09.09.11.34.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Sep 2015 11:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::229 as permitted sender) client-ip=2a00:1450:4010:c03::229; Received: by lamp12 with SMTP id p12so12542233lam.0 for ; Wed, 09 Sep 2015 11:34:37 -0700 (PDT) X-Received: by 10.152.18.164 with SMTP id x4mr31100926lad.35.1441823677104; Wed, 09 Sep 2015 11:34:37 -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 w3csp492018lbq; Wed, 9 Sep 2015 11:34:36 -0700 (PDT) X-Received: by 10.68.217.8 with SMTP id ou8mr25655482pbc.164.1441823676054; Wed, 09 Sep 2015 11:34:36 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vl3si2729765pbc.187.2015.09.09.11.34.35; Wed, 09 Sep 2015 11:34:36 -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 S1754886AbbIISeb (ORCPT + 28 others); Wed, 9 Sep 2015 14:34:31 -0400 Received: from mail-wi0-f193.google.com ([209.85.212.193]:33368 "EHLO mail-wi0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754783AbbIISe2 (ORCPT ); Wed, 9 Sep 2015 14:34:28 -0400 Received: by wicuu12 with SMTP id uu12so5382962wic.0; Wed, 09 Sep 2015 11:34:26 -0700 (PDT) X-Received: by 10.194.7.106 with SMTP id i10mr61270135wja.86.1441823666714; Wed, 09 Sep 2015 11:34:26 -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.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 11:34:25 -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, Kieran Bingham Subject: [PATCH v4 2/8] i2c: Add the ability to match device to compatible string without an of_node Date: Wed, 9 Sep 2015 19:33:41 +0100 Message-Id: <1441823627-6227-3-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:c03::229 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 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] Signed-off-by: Kieran Bingham --- drivers/i2c/i2c-core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 30d8a77..0788c1f 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1373,6 +1373,27 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) return adapter; } EXPORT_SYMBOL(of_find_i2c_adapter_by_node); + +static const struct of_device_id* +i2c_of_match_device_strip_vendor(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 */