From patchwork Fri Jun 21 15:03:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 2763261 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A0767C0AB1 for ; Fri, 21 Jun 2013 15:08:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3A1F02026B for ; Fri, 21 Jun 2013 15:08:18 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9E7BD2019E for ; Fri, 21 Jun 2013 15:08:16 +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 1Uq2wf-0005De-Sb; Fri, 21 Jun 2013 15:08:14 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uq2wd-0005Yp-Ao; Fri, 21 Jun 2013 15:08:11 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uq2wa-0005Y2-18 for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2013 15:08:09 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id r5LF7g9l022251; Fri, 21 Jun 2013 10:07:42 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id r5LF7f2Q028221; Fri, 21 Jun 2013 10:07:41 -0500 Received: from dlelxv22.itg.ti.com (172.17.1.197) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.2.342.3; Fri, 21 Jun 2013 10:07:41 -0500 Received: from localhost (uglx0174654.ucm2.emeaucm.ext.ti.com [10.167.145.172]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id r5LF7f5e026952; Fri, 21 Jun 2013 10:07:41 -0500 From: Grygorii Strashko To: Kevin Hilman , Tony Lindgren Subject: [RFC] ARM: OMAP2+: omap_device: add pinctrl handling Date: Fri, 21 Jun 2013 18:03:10 +0300 Message-ID: <1371826990-25820-1-git-send-email-grygorii.strashko@ti.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130621_110808_466451_202726C8 X-CRM114-Status: GOOD ( 17.95 ) X-Spam-Score: -8.4 (--------) Cc: Grygorii Strashko , Linus Walleij , linux-kernel@vger.kernel.org, Hebbar Gururaja , linux-omap@vger.kernel.org, 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before switching to DT pinctrl states of OMAP IPs have been handled by hwmod framework. After switching to DT-boot the pinctrl handling was dropped from hwmod framework and, as it was recommended, OMAP IP's drivers have to be updated to handle pinctrl states by itself using pinctrl_pm_select_xx() helpers (see http://lists.infradead.org/pipermail/linux-arm-kernel/2013-June/173514.html) But this is not right for OMAP2+ SoC where real IPs state is controlled by omap_device core which enables/disables modules & clocks actually. For example, if OMAP I2C driver will handle pinctrl state during system wide suspend the following issue may occure: - suspend_noirq - I2C device can be still active because of PM auto-suspend |-_od_suspend_noirq |- omap_i2c_suspend_noirq |- PINs state set to SLEEP |- pm_generic_runtime_suspend |- omap_i2c_runtime_suspend() |- PINs state set to IDLE <--- *oops* PINs state is IDLE and not SLEEP |- omap_device_idle() |- omap_hwmod_idle() |- _idle() |- disbale module (sysc&clocks) - resume_noirq - I2C was active before suspend |-_od_resume_noirq |- omap_hwmod_enable() |- _enable() |- enable module (sysc&clocks) |- pm_generic_runtime_resume |- omap_i2c_runtime_resume() |- PINs state set to DEFAULT <--- !!!! |- omap_i2c_resume_noirq |- PINs state set to DEFAULT |- PINs state set to IDLE <--- *big oops* we have active module and its PINs state is IDLE (see https://patchwork.kernel.org/patch/2642101/) Of course, everything can be handled by adding a tons of code in ecah driver to check PM state of device and override default behavior of omap_device core, but this not good. Hence, add pinctrl handling in omap_device core: 1) on PM runtime resume - switch pinctrl state to "default" (todo: "active") 2) on PM runtime suspend - switch pinctrl state to "idle" 3) during system wide suspend - switch pinctrl state to "sleep" or "idle" if omap_device core disables device - switch pinctrl state to "sleep" if device is disabled already 4) during system wide resume - switch pinctrl state to "default" (todo: "active") if omap_device core has disabled device during suspend - switch pinctrl state to "idle" if device was already disabled before suspend This will enable pinctrl for all OMAP2+ IP's drivers by default - no changes in code is needed and only DT data will need to be updated (add "default", "active", "idle", "sleep" states). This will enable pinctrl handling for all OMAP2+ drivers by default - no changes in code is needed and only DT data will need to be updated (add "default", "active", "idle", "sleep" states). Related discussions: - [3/3] i2c: nomadik: use pinctrl PM helpers https://patchwork.kernel.org/patch/2670291/ - mmc: omap_hsmmc: Remux pins to support SDIO interrupt and PM runtime https://patchwork.kernel.org/patch/2690191/ - [PATCH 00/11] drivers: Add Pinctrl PM support https://lkml.org/lkml/2013/5/31/210 CC: Hebbar Gururaja CC: Linus Walleij CC: linux-arm-kernel@lists.infradead.org CC: linux-omap@vger.kernel.org CC: linux-kernel@vger.kernel.org Signed-off-by: Grygorii Strashko --- Hi Kevin, Tony, I've verified this patch on OMAP4 SDP board: - PM runtime for I2C4, UART2, UART3 - suspend/resume with I2C4, UART2, UART3 seems it works and pinctrl states have been updated as expected. TODO: - need to be rebased when support for "active" state will be added. - need to be rebased when "Omap serial cleanup" patch series will be merged https://lkml.org/lkml/2013/4/26/503 based on top of: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 849aa58 Add linux-next specific files for 20130620 Best regards - grygorii arch/arm/mach-omap2/omap_device.c | 45 ++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c index e37feb2..d8cf17b 100644 --- a/arch/arm/mach-omap2/omap_device.c +++ b/arch/arm/mach-omap2/omap_device.c @@ -39,6 +39,7 @@ #include "soc.h" #include "omap_device.h" #include "omap_hwmod.h" +#include "iomap.h" /* Private functions */ @@ -585,8 +586,10 @@ static int _od_runtime_suspend(struct device *dev) ret = pm_generic_runtime_suspend(dev); - if (!ret) + if (!ret) { omap_device_idle(pdev); + pinctrl_pm_select_idle_state(dev); + } return ret; } @@ -595,12 +598,26 @@ static int _od_runtime_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); + /* TODO: should be replaced to pinctrl_pm_select_active_state() */ + pinctrl_pm_select_default_state(dev); + omap_device_enable(pdev); return pm_generic_runtime_resume(dev); } #endif +void _od_suspend_sel_pinctrl_state(struct device *dev) +{ + if (!dev->pins) + return; + /* try to select *deepest* pinctrl state */ + if (IS_ERR(dev->pins->sleep_state)) + pinctrl_pm_select_idle_state(dev); + else + pinctrl_pm_select_sleep_state(dev); +} + #ifdef CONFIG_SUSPEND static int _od_suspend_noirq(struct device *dev) { @@ -613,12 +630,22 @@ static int _od_suspend_noirq(struct device *dev) return 0; ret = pm_generic_suspend_noirq(dev); + if (!ret) { + if (!pm_runtime_status_suspended(dev)) { + if (pm_generic_runtime_suspend(dev) == 0) { + if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)) { + omap_device_idle(pdev); + _od_suspend_sel_pinctrl_state(dev); + } + } - if (!ret && !pm_runtime_status_suspended(dev)) { - if (pm_generic_runtime_suspend(dev) == 0) { - if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)) - omap_device_idle(pdev); od->flags |= OMAP_DEVICE_SUSPENDED; + } else { + /* + * "idle" pinctrl state already applied - + * try to set "sleep" state + */ + pinctrl_pm_select_sleep_state(dev); } } @@ -633,9 +660,15 @@ static int _od_resume_noirq(struct device *dev) if ((od->flags & OMAP_DEVICE_SUSPENDED) && !pm_runtime_status_suspended(dev)) { od->flags &= ~OMAP_DEVICE_SUSPENDED; - if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)) + if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND)) { omap_device_enable(pdev); + /* TODO: should be replaced to pinctrl_pm_select_active_state() */ + pinctrl_pm_select_default_state(dev); + } pm_generic_runtime_resume(dev); + } else if (!pm_runtime_status_suspended(dev)) { + /* switch back to "idle" pinctrl state */ + pinctrl_pm_select_idle_state(dev); } return pm_generic_resume_noirq(dev);