From patchwork Thu May 30 13:51:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Vaussard X-Patchwork-Id: 2637121 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id AECD2DFF69 for ; Thu, 30 May 2013 14:53:32 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ui3Kq-0000kI-8J; Thu, 30 May 2013 13:56:11 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ui3I8-0000Bh-F8; Thu, 30 May 2013 13:53:20 +0000 Received: from slb-mail4.epfl.ch ([2001:620:618:1e0:1:80b2:e059:1] helo=smtp4.epfl.ch) by merlin.infradead.org with smtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ui3Hc-00007b-Cp for linux-arm-kernel@lists.infradead.org; Thu, 30 May 2013 13:52:51 +0000 Received: (qmail 1057 invoked by uid 107); 30 May 2013 13:52:23 -0000 X-Virus-Scanned: ClamAV Received: from lsro1pc340.epfl.ch (HELO lsro1pc340.epfl.ch) (128.178.145.154) (authenticated) by smtp4.epfl.ch (AngelmatoPhylax SMTP proxy) with ESMTPA; Thu, 30 May 2013 15:52:23 +0200 From: Florian Vaussard To: Grant Likely , Rob Herring , Samuel Ortiz Subject: [PATCH 2/3] mfd: twl4030-power: Start transition to DT Date: Thu, 30 May 2013 15:51:55 +0200 Message-Id: <1369921916-7435-3-git-send-email-florian.vaussard@epfl.ch> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1369921916-7435-1-git-send-email-florian.vaussard@epfl.ch> References: <1369921916-7435-1-git-send-email-florian.vaussard@epfl.ch> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130530_095249_612854_1F03EF44 X-CRM114-Status: GOOD ( 19.56 ) X-Spam-Score: -3.0 (---) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-3.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.1 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Tero Kristo , linux-doc@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, Mark Brown , linux-kernel@vger.kernel.org, Peter Ujfalusi , Florian Vaussard , Rob Landley , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Support for loading twl4030-power module via devicetree. For now, when booting with a DT, only the poweroff callback feature is supported through the ti,use_poweroff property. Signed-off-by: Florian Vaussard --- .../devicetree/bindings/mfd/twl4030-power.txt | 28 +++++++ drivers/mfd/twl4030-power.c | 86 +++++++++++++++---- 2 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/twl4030-power.txt diff --git a/Documentation/devicetree/bindings/mfd/twl4030-power.txt b/Documentation/devicetree/bindings/mfd/twl4030-power.txt new file mode 100644 index 0000000..8e15ec3 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/twl4030-power.txt @@ -0,0 +1,28 @@ +Texas Instruments TWL family (twl4030) reset and power management module + +The power management module inside the TWL family provides several facilities +to control the power resources, including power scripts. For now, the +binding only supports the complete shutdown of the system after poweroff. + +Required properties: +- compatible : must be "ti,twl4030-power" + +Optional properties: +- ti,use_poweroff: With this flag, the chip will initiates an ACTIVE-to-OFF or + SLEEP-to-OFF transition when the system poweroffs. + +Example: +&i2c1 { + clock-frequency = <2600000>; + + twl: twl@48 { + reg = <0x48>; + interrupts = <7>; /* SYS_NIRQ cascaded to intc */ + interrupt-parent = <&intc>; + + twl_power: power { + compatible = "ti,twl4030-power"; + ti,use_poweroff; + }; + }; +}; diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c index c9a2a5c..d12d748 100644 --- a/drivers/mfd/twl4030-power.c +++ b/drivers/mfd/twl4030-power.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -492,6 +493,39 @@ int twl4030_remove_script(u8 flags) return err; } +int twl4030_power_configure_scripts(struct twl4030_power_data *pdata) +{ + int err; + int i; + u8 address = twl4030_start_script_address; + + for (i = 0; i < pdata->num; i++) { + err = load_twl4030_script(pdata->scripts[i], address); + if (err) + return err; + address += pdata->scripts[i]->size; + } + + return 0; +} + +int twl4030_power_configure_resources(struct twl4030_power_data *pdata) +{ + struct twl4030_resconfig *resconfig = pdata->resource_config; + int err; + + if (resconfig) { + while (resconfig->resource) { + err = twl4030_configure_resource(resconfig); + if (err) + return err; + resconfig++; + } + } + + return 0; +} + /* * In master mode, start the power off sequence. * After a successful execution, TWL shuts down the power to the SoC @@ -507,13 +541,29 @@ void twl4030_power_off(void) pr_err("TWL4030 Unable to power off\n"); } +static bool twl4030_power_use_poweroff(struct twl4030_power_data *pdata, + struct device_node *node) +{ + if (pdata && pdata->use_poweroff) + return true; + + if (of_property_read_bool(node, "ti,use_poweroff")) + return true; + + return false; +} + int twl4030_power_probe(struct platform_device *pdev) { struct twl4030_power_data *pdata = pdev->dev.platform_data; + struct device_node *node = pdev->dev.of_node; int err = 0; - int i; - struct twl4030_resconfig *resconfig; - u8 val, address = twl4030_start_script_address; + u8 val; + + if (!pdata && !node) { + dev_err(&pdev->dev, "Platform data is missing\n"); + return -EINVAL; + } err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1, TWL4030_PM_MASTER_PROTECT_KEY); @@ -525,26 +575,17 @@ int twl4030_power_probe(struct platform_device *pdev) if (err) goto unlock; - for (i = 0; i < pdata->num; i++) { - err = load_twl4030_script(pdata->scripts[i], address); + if (pdata) { + err = twl4030_power_configure_scripts(pdata); if (err) goto load; - address += pdata->scripts[i]->size; - } - - resconfig = pdata->resource_config; - if (resconfig) { - while (resconfig->resource) { - err = twl4030_configure_resource(resconfig); - if (err) - goto resource; - resconfig++; - - } + err = twl4030_power_configure_resources(pdata); + if (err) + goto resource; } /* Board has to be wired properly to use this feature */ - if (pdata->use_poweroff && !pm_power_off) { + if (twl4030_power_use_poweroff(pdata, node) && !pm_power_off) { /* Default for SEQ_OFFSYNC is set, lets ensure this */ err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val, TWL4030_PM_MASTER_CFG_P123_TRANSITION); @@ -590,10 +631,19 @@ static int twl4030_power_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_OF +static const struct of_device_id twl4030_power_of_match[] = { + {.compatible = "ti,twl4030-power", }, + { }, +}; +MODULE_DEVICE_TABLE(of, twl4030_power_of_match); +#endif + static struct platform_driver twl4030_power_driver = { .driver = { .name = "twl4030_power", .owner = THIS_MODULE, + .of_match_table = of_match_ptr(twl4030_power_of_match), }, .probe = twl4030_power_probe, .remove = twl4030_power_remove,