public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: Benoit Cousson <b-cousson@ti.com>
To: grant.likely@secretlab.ca, tony@atomide.com
Cc: linux-omap@vger.kernel.org, devicetree-discuss@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org, manjugk@ti.com,
	Benoit Cousson <b-cousson@ti.com>, Balaji T K <balajitk@ti.com>,
	Graeme Gregory <gg@slimlogic.co.uk>,
	Samuel Ortiz <sameo@linux.intel.com>
Subject: [PATCH 04/13] mfd: twl-core: Add initial DT support for twl4030/twl6030
Date: Thu, 1 Sep 2011 19:21:20 +0200	[thread overview]
Message-ID: <1314897689-17791-5-git-send-email-b-cousson@ti.com> (raw)
In-Reply-To: <1314897689-17791-1-git-send-email-b-cousson@ti.com>

Add initial device-tree support for twl familly chips.
The current version is missing the regulator entries due
to the lack of DT regulator bindings for the moment.
Only the simple sub-modules that do not depend on
platform_data information can be initialized properly.

Signed-off-by: Benoit Cousson <b-cousson@ti.com>
Cc: Balaji T K <balajitk@ti.com>
Cc: Graeme Gregory <gg@slimlogic.co.uk>
Cc: Samuel Ortiz <sameo@linux.intel.com>
---
 drivers/mfd/twl-core.c |   99 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 95 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 01ecfee..a12af12 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -33,6 +33,9 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/of_irq.h>
+#include <linux/irqdomain.h>
 
 #include <linux/regulator/machine.h>
 
@@ -633,6 +636,55 @@ add_regulator(int num, struct regulator_init_data *pdata,
 	return add_regulator_linked(num, pdata, NULL, 0, features);
 }
 
+#ifdef CONFIG_OF
+#define MODALIAS_SIZE 32
+
+static int add_of_children(struct i2c_client *client, unsigned long features)
+{
+	u32 reg;
+	struct device *child, *dev = &client->dev;
+	struct device_node *node, *parent = client->dev.of_node;
+	int irq;
+	char alias[MODALIAS_SIZE];
+
+	for_each_child_of_node(parent, node) {
+		if (of_property_read_u32(node, "reg", &reg)) {
+			dev_err(dev, "%s(): invalid reg on %s\n", __func__,
+				node->full_name);
+			continue;
+		}
+
+		irq = irq_of_parse_and_map(node, 0);
+
+		if (of_modalias_node(node, alias, MODALIAS_SIZE)) {
+			dev_err(dev, "%s(): modalias failure on %s\n", __func__,
+				node->full_name);
+			continue;
+		}
+
+		if (of_device_is_compatible(node, "ti,twl_reg")) {
+			dev_dbg(dev, " %s(): add_regulator\n", __func__);
+			child = NULL;
+		} else {
+			dev_dbg(dev, " %s(): add_child\n", __func__);
+			child = add_child(reg, alias, NULL, 0, true, irq, 0);
+		}
+
+		if (IS_ERR(child)) {
+			dev_err(dev, " %s(): add_child failed: %ld\n", __func__,
+				PTR_ERR(child));
+			continue;
+		}
+	}
+	return 0;
+}
+#else
+static int add_of_children(struct device_node *parent, unsigned long features)
+{
+	return 0;
+}
+#endif
+
 /*
  * NOTE:  We know the first 8 IRQs after pdata->base_irq are
  * for the PIH, and the next are for the PWR_INT SIH, since
@@ -1182,22 +1234,53 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	int				status;
 	unsigned			i;
 	struct twl4030_platform_data	*pdata = client->dev.platform_data;
+	struct device_node		*node = client->dev.of_node;
 	u8 temp;
 	int ret = 0;
 
+	if (node && !pdata) {
+		/*
+		 * XXX: Temporary fake pdata until the information
+		 * is correctly retrieved by every TWL modules from DT.
+		 */
+		pdata = kzalloc(sizeof(struct twl4030_platform_data),
+				GFP_KERNEL);
+		if (!pdata) {
+			status = -ENOMEM;
+			goto exit;
+		}
+
+		/*
+		 * XXX: For the moment the IRQs for TWL seems to be encoded in
+		 * the global OMAP space. That should be cleaned to allow
+		 * dynamically adding a new IRQ controller.
+		 */
+		if ((id->driver_data) & TWL6030_CLASS) {
+			pdata->irq_base = TWL6030_IRQ_BASE;
+			pdata->irq_end = pdata->irq_base + TWL6030_BASE_NR_IRQS;
+		} else {
+			pdata->irq_base = TWL4030_IRQ_BASE;
+			pdata->irq_end = pdata->irq_base + TWL4030_BASE_NR_IRQS;
+		}
+		irq_domain_add_simple(node, pdata->irq_base);
+	}
+
 	if (!pdata) {
 		dev_dbg(&client->dev, "no platform data?\n");
-		return -EINVAL;
+		status = -EINVAL;
+		goto fail_free;
 	}
 
 	if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
 		dev_dbg(&client->dev, "can't talk I2C?\n");
-		return -EIO;
+		status = -EIO;
+		goto fail_free;
 	}
 
 	if (inuse) {
 		dev_dbg(&client->dev, "driver is already in use\n");
-		return -EBUSY;
+		status = -EBUSY;
+		goto fail_free;
 	}
 
 	for (i = 0; i < TWL_NUM_SLAVES; i++) {
@@ -1269,10 +1352,18 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
 	}
 
-	status = add_children(pdata, id->driver_data);
+	if (node)
+		status = add_of_children(client, id->driver_data);
+	else
+		status = add_children(pdata, id->driver_data);
+
 fail:
 	if (status < 0)
 		twl_remove(client);
+fail_free:
+	if (node)
+		kfree(pdata);
+exit:
 	return status;
 }
 
-- 
1.7.0.4


  parent reply	other threads:[~2011-09-01 17:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-01 17:21 [PATCH 00/13] OMAP4: Add DT support for i2c and twl6030 Benoit Cousson
2011-09-01 17:21 ` [PATCH 01/13] irq: Add stub for none DT build in irqdomain.h Benoit Cousson
2011-09-01 17:21 ` [PATCH 02/13] i2c: OMAP: Add DT support for i2c controller Benoit Cousson
2011-09-01 17:21 ` [PATCH 03/13] documentation/dt: Add OMAP i2c bindings documentation Benoit Cousson
2011-09-01 17:21 ` Benoit Cousson [this message]
2011-09-01 18:27   ` [PATCH 04/13] mfd: twl-core: Add initial DT support for twl4030/twl6030 Arnd Bergmann
2011-09-05 16:05     ` Cousson, Benoit
2011-09-01 17:21 ` [PATCH 05/13] documentation/dt: Add TWL4030 and TWL6030 bindings Benoit Cousson
2011-09-01 17:21 ` [PATCH 06/13] arm/dts: OMAP4: Add i2c controller nodes Benoit Cousson
2011-09-01 17:21 ` [PATCH 07/13] arm/dts: omap4-sdp: Set clock freq for i2c controllers Benoit Cousson
2011-09-01 17:21 ` [PATCH 08/13] arm/dts: omap4-panda: " Benoit Cousson
2011-09-01 17:21 ` [PATCH 09/13] arm/dts: omap4-sdp: Add twl6030 node Benoit Cousson
2011-09-01 17:21 ` [PATCH 10/13] arm/dts: omap4-panda: " Benoit Cousson
2011-09-01 17:21 ` [PATCH 11/13] OMAP4: board-dt: Remove static i2c init Benoit Cousson
2011-09-01 17:21 ` [PATCH 12/13] arm/dts: omap4-sdp: Add i2c3 & i2c4 devices Benoit Cousson
2011-09-01 17:21 ` [PATCH 13/13] arm/dts: omap4-panda: Add EEPROM entry in i2c3 Benoit Cousson
2011-09-01 19:14 ` [PATCH 00/13] OMAP4: Add DT support for i2c and twl6030 Arnd Bergmann

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=1314897689-17791-5-git-send-email-b-cousson@ti.com \
    --to=b-cousson@ti.com \
    --cc=balajitk@ti.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=gg@slimlogic.co.uk \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=manjugk@ti.com \
    --cc=sameo@linux.intel.com \
    --cc=tony@atomide.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