From patchwork Wed Jun 4 12:09:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 31348 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ED8A2203AC for ; Wed, 4 Jun 2014 12:10:20 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id w8sf18501475qac.2 for ; Wed, 04 Jun 2014 05:10:20 -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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=5wBHSWIMNrm1pZfSDlLOBtYvE3M+ZSLt6K4Tc3YEJfw=; b=bWZtGj8bpqy1XsTUV3J90S0+B9FyVaOvQG0e7e8iSbKXARiUfqTognLYNBC1jQPIpR qzm7UmiH2RzznHUNDc7i2uB4hbKV38PcR82dBeUSftEhDfx/3cYlgU7tECbL2fNQ9ywk U9LoL3Prv3j8qBD7l7S01uGWeYU3Me6pFgalm/kNMPriPIJrZBkMmjTHADoQtCpnD/dh Zf2I/EJAXMN2+C61maixoZYUnY7DcrmSxgX0319Vht9eOgy7cwxUxI4o2hnWl64pdUsy ho9J9IdvhQ4YuGSdFEDt4YnvA1qaMujaTmGs/93s8GeKACMfUNn/Z+KjNhvHEsm0Ly1k qJOw== X-Gm-Message-State: ALoCoQmYJVNnsRpY+o6X1LEXVzqfVfFE33sPMYQlwt0zC81fED14oX0aqInhFX929ZRRwH1JJGK1 X-Received: by 10.58.118.226 with SMTP id kp2mr22021973veb.4.1401883820620; Wed, 04 Jun 2014 05:10:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.115 with SMTP id s106ls3047868qgd.49.gmail; Wed, 04 Jun 2014 05:10:20 -0700 (PDT) X-Received: by 10.58.247.66 with SMTP id yc2mr43746262vec.13.1401883820394; Wed, 04 Jun 2014 05:10:20 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id th3si1370802vdc.36.2014.06.04.05.10.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.169 as permitted sender) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id jx11so8771923veb.0 for ; Wed, 04 Jun 2014 05:10:20 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr42888805vcg.16.1401883820307; Wed, 04 Jun 2014 05:10:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp39873vcb; Wed, 4 Jun 2014 05:10:19 -0700 (PDT) X-Received: by 10.15.51.193 with SMTP id n41mr690449eew.80.1401883819055; Wed, 04 Jun 2014 05:10:19 -0700 (PDT) Received: from mail-ie0-f176.google.com (mail-ie0-f176.google.com [209.85.223.176]) by mx.google.com with ESMTPS id q6si3500755ich.107.2014.06.04.05.10.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:18 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.223.176 as permitted sender) client-ip=209.85.223.176; Received: by mail-ie0-f176.google.com with SMTP id rl12so7191228iec.35 for ; Wed, 04 Jun 2014 05:10:18 -0700 (PDT) X-Received: by 10.50.43.167 with SMTP id x7mr6662425igl.36.1401883818791; Wed, 04 Jun 2014 05:10:18 -0700 (PDT) Received: from localhost.localdomain (host109-148-113-200.range109-148.btcentralplus.com. [109.148.113.200]) by mx.google.com with ESMTPSA id on9sm10028136igb.11.2014.06.04.05.10.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:18 -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/7] i2c: Add the ability to match device to compatible string without an of_node Date: Wed, 4 Jun 2014 13:09:52 +0100 Message-Id: <1401883796-17841-4-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1401883796-17841-1-git-send-email-lee.jones@linaro.org> References: <1401883796-17841-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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. Signed-off-by: Lee Jones --- drivers/i2c/i2c-core.c | 25 +++++++++++++++++++++++++ include/linux/i2c.h | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index d3802dc..7dcd5c3 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1090,6 +1090,31 @@ 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); + +const struct of_device_id +*i2c_of_match_device_strip_vendor(const struct of_device_id *matches, + struct device *dev) +{ + const struct i2c_client *client = i2c_verify_client(dev); + const char *name; + + if (!(client && matches)) + return NULL; + + for (; matches->compatible[0]; matches++) { + name = strchr(matches->compatible, ','); + if (!name) + name = matches->compatible; + else + name++; + + if (!strncmp(client->name, name, strlen(client->name))) + return matches; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(i2c_of_match_device_strip_vendor); #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 b556e0a..f7ec75b 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -564,6 +564,9 @@ 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_strip_vendor(const struct of_device_id *matches, + struct device *dev); #else static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) @@ -575,6 +578,13 @@ 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_strip_vendor(const struct of_device_id *matches, + struct device *dev) +{ + return NULL; +} #endif /* CONFIG_OF */ #endif /* _LINUX_I2C_H */