From patchwork Fri Jun 20 12:02:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 362180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id EC39E140084 for ; Fri, 20 Jun 2014 22:05:56 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967478AbaFTMFS (ORCPT ); Fri, 20 Jun 2014 08:05:18 -0400 Received: from mail-ie0-f181.google.com ([209.85.223.181]:61988 "EHLO mail-ie0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967259AbaFTMDX (ORCPT ); Fri, 20 Jun 2014 08:03:23 -0400 Received: by mail-ie0-f181.google.com with SMTP id y20so3018976ier.26 for ; Fri, 20 Jun 2014 05:03:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WL197FXGRSTCLwbwM3rF6zFKUuk1EMvRbfmz299v2j8=; b=DN7f/P8i8h3BJDkvjYBWTJRWz/vyDJ3Tahxd23hgrWoYJggJ7vU8nmlzmqeIExmAzE XuImlI7cXdx35gvsnzIOSLlBgxLIehA8s7yuY8/QnI2TmsE6qtt/xz6d6xSQA4q+2cYl oUbc4MPCb4KdJqHibocgBOJHt3kGwWO29tlEf/QXreE37kuk701A2ujidE7D8QUgB1fX wPZTg3XIywbph29UjttooSr6EgibIsXK3p3B5oAyXqjfaJE65krpra5QWvL/40XiF6sP cW4UZMzeCednJbDw9/QSjK+BG9gwVISc+UpaEJTxRa7TK28Gzgs3SzjNaSX0Ixzyd5a4 T4kQ== X-Gm-Message-State: ALoCoQkm1VIRBJjRCBwPowHVJ4Z5x9B6iWzUTflVsbDX2IDdzMw1UCn2327CFpzdK3kNoeiGgoXn X-Received: by 10.42.111.135 with SMTP id u7mr3161054icp.80.1403265802952; Fri, 20 Jun 2014 05:03:22 -0700 (PDT) Received: from localhost.localdomain (host109-148-235-194.range109-148.btcentralplus.com. [109.148.235.194]) by mx.google.com with ESMTPSA id qn5sm3890078igb.7.2014.06.20.05.03.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 05:03:22 -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, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linus.walleij@linaro.org, Lee Jones Subject: [PATCH 3/9] i2c: Add the ability to match device to compatible string without an of_node Date: Fri, 20 Jun 2014 13:02:27 +0100 Message-Id: <1403265753-25851-5-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1403265753-25851-1-git-send-email-lee.jones@linaro.org> References: <1403265753-25851-1-git-send-email-lee.jones@linaro.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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 --- 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 d3802dc..8a37745 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1090,6 +1090,27 @@ 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); + +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 (!strnicmp(client->name, name, strlen(client->name))) + return matches; + } + + return NULL; +} + #else static void of_i2c_register_devices(struct i2c_adapter *adap) { } #endif /* CONFIG_OF */