From patchwork Wed Apr 23 21:35:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 28940 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8A8C120534 for ; Wed, 23 Apr 2014 21:36:22 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id m5sf4744211qaj.9 for ; Wed, 23 Apr 2014 14:36:21 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=MKqfwZRiDkxLJPMFsbX6dNyiGwEhlYVlIncb7JWB9SU=; b=BSyYt0UjIyOwePFp0t1+PL0omMcTb+D6NqqEVmDEREkHHn8PlZnKz5h9G99IudLT+z dBJOuvQdyTlqnADtV1LbyrsIYfTYJmyZoSoWmLeEErntWQTHgmDVFPnOgH/KnST5/LKc amZ+0Fqz+fIKNHJ3BnAf2BEYJcnmpE3e0FLhrBEHgrUBCUBk3u85PN+j9LjFFuAHDCn+ 0ardWdzfRU8/0c6X9Jo03sdd6LRerMfWd3Nnure+Oza034Dl53a3d1vKVw1KpNny23vU MImu7CtboIcK4FzmbqeOiBXhyUMWRoZ5E6V98VAjonX8bpvStd0hZi+gkSKqHiOnu+wO UpBw== X-Gm-Message-State: ALoCoQn/oEV08TFrntDsKl5PKToxZIox3be7uhbL5ouGd1ddSogcUAmdR+3tQ2nPdMA8StzgY/qv X-Received: by 10.224.22.71 with SMTP id m7mr16982785qab.8.1398288981770; Wed, 23 Apr 2014 14:36:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.112 with SMTP id p103ls937956qga.41.gmail; Wed, 23 Apr 2014 14:36:21 -0700 (PDT) X-Received: by 10.221.74.200 with SMTP id yx8mr43127112vcb.3.1398288981605; Wed, 23 Apr 2014 14:36:21 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id od9si448117vcb.173.2014.04.23.14.36.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 23 Apr 2014 14:36:21 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jx11so1893510veb.17 for ; Wed, 23 Apr 2014 14:36:21 -0700 (PDT) X-Received: by 10.220.101.3 with SMTP id a3mr2447889vco.31.1398288981497; Wed, 23 Apr 2014 14:36:21 -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.220.221.72 with SMTP id ib8csp134482vcb; Wed, 23 Apr 2014 14:36:20 -0700 (PDT) X-Received: by 10.68.190.200 with SMTP id gs8mr24480335pbc.130.1398288980481; Wed, 23 Apr 2014 14:36:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id as3si1328259pbc.393.2014.04.23.14.36.19; Wed, 23 Apr 2014 14:36:19 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751277AbaDWVgK (ORCPT + 27 others); Wed, 23 Apr 2014 17:36:10 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:37315 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750902AbaDWVgI (ORCPT ); Wed, 23 Apr 2014 17:36:08 -0400 Received: by mail-wi0-f170.google.com with SMTP id bs8so361442wib.3 for ; Wed, 23 Apr 2014 14:36:06 -0700 (PDT) X-Received: by 10.180.206.36 with SMTP id ll4mr3282670wic.57.1398288966717; Wed, 23 Apr 2014 14:36:06 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id ct2sm3169489wjb.33.2014.04.23.14.36.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Apr 2014 14:36:05 -0700 (PDT) From: Linus Walleij To: Samuel Ortiz , Lee Jones , linux-kernel@vger.kernel.org Cc: Silvio F , Philipp Zabel , Sascha Hauer , Shawn Guo , Viresh Kumar , Shiraz Hashim , spear-devel@list.st.com, Linus Walleij Subject: [PATCH 3/6 v3] mfd: stmpe: probe properly from the device tree Date: Wed, 23 Apr 2014 23:35:58 +0200 Message-Id: <1398288958-4723-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org 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: , The current STMPE I2C probing code does not really match the compatible strings - it matches node names happening to give the right device name. Instead, let's introduce some real compatible matching, more complex, more accurate. Make the driver depend on OF since all platforms using it are DT-only. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Fix a stupid error where I left a dangling return statement in the probe path. - Fix up subject prope->probe ChangeLog v1->v2: - Make driver depend on OF and remove some ifdeffery that way. - Squash OF match table to single lines. - Merge of-specific probe function into probe(). - Print a small nag if DT is using the node name trick to make the driver probe. --- drivers/mfd/Kconfig | 1 + drivers/mfd/stmpe-i2c.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 33834120d057..29be025d5835 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -675,6 +675,7 @@ config MFD_DB8500_PRCMU config MFD_STMPE bool "STMicroelectronics STMPE" depends on (I2C=y || SPI_MASTER=y) + depends on OF select MFD_CORE help Support for the STMPE family of I/O Expanders from diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c index 0da02e11d58e..a45f9c0a330a 100644 --- a/drivers/mfd/stmpe-i2c.c +++ b/drivers/mfd/stmpe-i2c.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "stmpe.h" static int i2c_reg_read(struct stmpe *stmpe, u8 reg) @@ -52,15 +53,41 @@ static struct stmpe_client_info i2c_ci = { .write_block = i2c_block_write, }; +static const struct of_device_id stmpe_of_match[] = { + { .compatible = "st,stmpe610", .data = (void *)STMPE610, }, + { .compatible = "st,stmpe801", .data = (void *)STMPE801, }, + { .compatible = "st,stmpe811", .data = (void *)STMPE811, }, + { .compatible = "st,stmpe1601", .data = (void *)STMPE1601, }, + { .compatible = "st,stmpe1801", .data = (void *)STMPE1801, }, + { .compatible = "st,stmpe2401", .data = (void *)STMPE2401, }, + { .compatible = "st,stmpe2403", .data = (void *)STMPE2403, }, + {}, +}; +MODULE_DEVICE_TABLE(of, stmpe_of_match); + static int stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { + int partnum; + const struct of_device_id *of_id; + i2c_ci.data = (void *)id; i2c_ci.irq = i2c->irq; i2c_ci.client = i2c; i2c_ci.dev = &i2c->dev; - return stmpe_probe(&i2c_ci, id->driver_data); + of_id = of_match_device(stmpe_of_match, &i2c->dev); + if (!of_id) { + /* + * This happens when the I2C ID matches the node name + * but no real compatible string has been given. + */ + dev_info(&i2c->dev, "matching on node name, compatible is preferred\n"); + partnum = id->driver_data; + } else + partnum = (int)of_id->data; + + return stmpe_probe(&i2c_ci, partnum); } static int stmpe_i2c_remove(struct i2c_client *i2c) @@ -89,6 +116,7 @@ static struct i2c_driver stmpe_i2c_driver = { #ifdef CONFIG_PM .pm = &stmpe_dev_pm_ops, #endif + .of_match_table = stmpe_of_match, }, .probe = stmpe_i2c_probe, .remove = stmpe_i2c_remove,