linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Samuel Ortiz <sameo@linux.intel.com>,
	Lee Jones <lee.jones@linaro.org>,
	linux-kernel@vger.kernel.org
Cc: Silvio F <silvio.fricke@gmail.com>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Shawn Guo <shawn.guo@linaro.org>,
	Viresh Kumar <viresh.linux@gmail.com>,
	Shiraz Hashim <shiraz.hashim@st.com>,
	spear-devel@list.st.com, Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 3/6] mfd: stmpe: prope properly from the device tree
Date: Wed, 16 Apr 2014 16:44:12 +0200	[thread overview]
Message-ID: <1397659455-13638-4-git-send-email-linus.walleij@linaro.org> (raw)
In-Reply-To: <1397659455-13638-1-git-send-email-linus.walleij@linaro.org>

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.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/mfd/stmpe-i2c.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
index 0da02e11d58e..8902a600d978 100644
--- a/drivers/mfd/stmpe-i2c.c
+++ b/drivers/mfd/stmpe-i2c.c
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/types.h>
+#include <linux/of_device.h>
 #include "stmpe.h"
 
 static int i2c_reg_read(struct stmpe *stmpe, u8 reg)
@@ -52,15 +53,71 @@ static struct stmpe_client_info i2c_ci = {
 	.write_block = i2c_block_write,
 };
 
+#ifdef CONFIG_OF
+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);
+
+int stmpe_i2c_of_probe(struct i2c_client *i2c)
+{
+	const struct of_device_id *of_id;
+
+	of_id = of_match_device(stmpe_of_match, &i2c->dev);
+	if (!of_id)
+		return -EINVAL;
+	return (int)of_id->data;
+}
+#else
+int stmpe_i2c_of_probe(struct i2c_client *i2c)
+{
+	return -EINVAL;
+}
+#endif
+
 static int
 stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 {
+	int partnum;
+
 	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);
+	partnum = stmpe_i2c_of_probe(i2c);
+	if (partnum < 0)
+		partnum = id->driver_data;
+
+	return stmpe_probe(&i2c_ci, partnum);
 }
 
 static int stmpe_i2c_remove(struct i2c_client *i2c)
@@ -89,6 +146,7 @@ static struct i2c_driver stmpe_i2c_driver = {
 #ifdef CONFIG_PM
 		.pm = &stmpe_dev_pm_ops,
 #endif
+		.of_match_table = of_match_ptr(stmpe_of_match),
 	},
 	.probe		= stmpe_i2c_probe,
 	.remove		= stmpe_i2c_remove,
-- 
1.9.0


  parent reply	other threads:[~2014-04-16 14:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-16 14:44 [PATCH 0/6] mfd/gpio: cleanup of STMPE driver Linus Walleij
2014-04-16 14:44 ` [PATCH 1/6] mfd: stmpe: root out static GPIO and IRQ assignments Linus Walleij
2014-04-17 10:49   ` Lee Jones
2014-04-23 11:39     ` Linus Walleij
2014-04-23 13:22       ` Lee Jones
2014-04-23 21:23         ` Linus Walleij
2014-04-28  9:25           ` Lee Jones
2014-04-16 14:44 ` [PATCH 2/6] mfd: stmpe: add optional regulators Linus Walleij
2014-04-17 10:30   ` Lee Jones
2014-04-23  8:38     ` Linus Walleij
2014-05-06 12:52   ` Shawn Guo
     [not found]     ` <CAF2Aj3gDTYvv+vqa3FPBVdgOLwqctH0bd+coN29TpR53jNYKhg@mail.gmail.com>
2014-05-08 21:15       ` Linus Walleij
2014-04-16 14:44 ` Linus Walleij [this message]
2014-04-17 10:44   ` [PATCH 3/6] mfd: stmpe: prope properly from the device tree Lee Jones
2014-04-23  8:52     ` Linus Walleij
2014-04-16 14:44 ` [PATCH 4/6] mfd: stmpe: mask off unused blocks properly Linus Walleij
2014-04-17 10:52   ` Lee Jones
2014-04-16 14:44 ` [PATCH 5/6] ARM: ux500: add VCC and VIO regulators to STMPE IC Linus Walleij
2014-04-16 14:44 ` [PATCH 6/6] gpio: stmpe: switch to use gpiolib irqchip helpers Linus Walleij
2014-04-17  6:11 ` [PATCH 0/6] mfd/gpio: cleanup of STMPE driver Shawn Guo
2014-04-17 13:28   ` Silvio Fricke
2014-04-19  5:07     ` Shawn Guo
2014-04-17 13:28   ` [PATCH] ARM: dts: imx6: edmqmx6: add vcc and vio power supplies to stmpe Silvio Fricke
2014-04-23 11:43     ` Linus Walleij
2014-05-10  6:10     ` Shawn Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1397659455-13638-4-git-send-email-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=s.hauer@pengutronix.de \
    --cc=sameo@linux.intel.com \
    --cc=shawn.guo@linaro.org \
    --cc=shiraz.hashim@st.com \
    --cc=silvio.fricke@gmail.com \
    --cc=spear-devel@list.st.com \
    --cc=viresh.linux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).