From patchwork Thu Sep 1 17:21:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benoit Cousson X-Patchwork-Id: 1120102 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p81HagJh026841 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 1 Sep 2011 17:37:08 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QzB7k-0002gK-9N; Thu, 01 Sep 2011 17:32:23 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QzAzL-0007Kg-Gs; Thu, 01 Sep 2011 17:23:39 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QzAyG-00071k-2T for linux-arm-kernel@lists.infradead.org; Thu, 01 Sep 2011 17:22:34 +0000 Received: from dlep33.itg.ti.com ([157.170.170.112]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id p81HMSvu016479 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Sep 2011 12:22:28 -0500 Received: from dlep26.itg.ti.com (smtp-le.itg.ti.com [157.170.170.27]) by dlep33.itg.ti.com (8.13.7/8.13.8) with ESMTP id p81HMSV2016546; Thu, 1 Sep 2011 12:22:28 -0500 (CDT) Received: from DFLE71.ent.ti.com (localhost [127.0.0.1]) by dlep26.itg.ti.com (8.13.8/8.13.8) with ESMTP id p81HMSaJ017870; Thu, 1 Sep 2011 12:22:28 -0500 (CDT) Received: from dlelxv22.itg.ti.com (172.17.1.197) by dfle71.ent.ti.com (128.247.5.62) with Microsoft SMTP Server id 14.1.323.3; Thu, 1 Sep 2011 12:22:28 -0500 Received: from localhost.localdomain (lncpu04.tif.ti.com [137.167.102.15]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id p81HLa52016431; Thu, 1 Sep 2011 12:22:25 -0500 From: Benoit Cousson To: , Subject: [PATCH 04/13] mfd: twl-core: Add initial DT support for twl4030/twl6030 Date: Thu, 1 Sep 2011 19:21:20 +0200 Message-ID: <1314897689-17791-5-git-send-email-b-cousson@ti.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1314897689-17791-1-git-send-email-b-cousson@ti.com> References: <1314897689-17791-1-git-send-email-b-cousson@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110901_132232_248462_0258D55F X-CRM114-Status: GOOD ( 19.84 ) X-Spam-Score: -2.8 (--) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-2.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [198.47.26.152 listed in list.dnswl.org] -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Benoit Cousson , manjugk@ti.com, devicetree-discuss@lists.ozlabs.org, Graeme Gregory , Samuel Ortiz , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Balaji T K X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 01 Sep 2011 17:37:08 +0000 (UTC) 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 Cc: Balaji T K Cc: Graeme Gregory Cc: Samuel Ortiz --- 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 #include #include +#include +#include +#include #include @@ -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", ®)) { + 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; }