From patchwork Fri Dec 23 12:24:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9487399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 04C3A600CB for ; Fri, 23 Dec 2016 12:25:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB2C626247 for ; Fri, 23 Dec 2016 12:25:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E002926E82; Fri, 23 Dec 2016 12:25:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6642926247 for ; Fri, 23 Dec 2016 12:25:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941654AbcLWMZt (ORCPT ); Fri, 23 Dec 2016 07:25:49 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:52648 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941354AbcLWMZp (ORCPT ); Fri, 23 Dec 2016 07:25:45 -0500 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OIN02I0A16V2AB0@mailout1.samsung.com>; Fri, 23 Dec 2016 21:25:43 +0900 (KST) Received: from epsmges1p1.samsung.com (unknown [182.195.42.53]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20161223122542epcas1p4170b92a053085d86b5ede409e316885e~S4jSVmNQ71387513875epcas1p4p; Fri, 23 Dec 2016 12:25:42 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 7A.03.05883.6C71D585; Fri, 23 Dec 2016 21:25:42 +0900 (KST) Received: from epcpsbgm1new.samsung.com (u26.gpu120.samsung.co.kr [203.254.230.26]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20161223122542epcas1p444c9d8c91c2983f9934e68a6bb882726~S4jSEueWn1387513875epcas1p4o; Fri, 23 Dec 2016 12:25:42 +0000 (GMT) X-AuditID: b6c32a35-f799b6d0000016fb-1c-585d17c63b0a Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id 96.21.28252.6C71D585; Fri, 23 Dec 2016 21:25:42 +0900 (KST) Received: from AMDC2765.digital.local ([106.116.147.25]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OIN00JTK15R7DD0@mmp2.samsung.com>; Fri, 23 Dec 2016 21:25:42 +0900 (KST) From: Marek Szyprowski To: linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Sylwester Nawrocki , Krzysztof Kozlowski , Linus Walleij , Tomasz Figa , Ulf Hansson , Bartlomiej Zolnierkiewicz Subject: [PATCH 8/9] pinctrl: samsung: Add runtime PM support Date: Fri, 23 Dec 2016 13:24:48 +0100 Message-id: <1482495889-6201-9-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1482495889-6201-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrAIsWRmVeSWpSXmKPExsWy7bCmnu4x8dgIg1tT9S02zljPanH+/AZ2 iyl/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07VQUshL zE21VYrQ9Q0JUlIoS8wpBfKMDNCAg3OAe7CSvl2CW8bSxZMYCxpkKp4te8TYwLhXvIuRk0NC wERi6apudghbTOLCvfVsILaQwCxGidOvoiHsX4wSTzvMQWw2AUOJrrddQDVcHCICzYwSDUt6 wRxmgR1MEpPPrmHuYuTgEBawlVh5QAykgUVAVeLm04dMIDavgLvE7KmPGSGWyUmcPDaZFcTm FPCQ2LrhFTvEMneJC9sfsk9g5F3AyLCKUSK1ILmgOCk91zAvtVyvODG3uDQvXS85P3cTIzgC nkntYDy4y/0QowAHoxIP74mzMRFCrIllxZW5hxglOJiVRHinCMdGCPGmJFZWpRblxxeV5qQW H2I0BTpsIrOUaHI+MDrzSuINTcxNzI0NLMwtLU2MlMR5G2c/CxcSSE8sSc1OTS1ILYLpY+Lg lGpg3CO8+mPXvTrd/fPi0js4TVTfTTN+PHX5hztay3tvft/sNkfIe9G1GW+Xcql9tf7Nl9KS oRpXFXbB7r2jwNE574PdL56ut36ieG7dAakd506ILavjVG16maJT/Xu6Lofz1jeimRuPSiVf OlklU7HpT5TTl+NZSV+WfeTc8vzadMY1E2yr1uQVSCmxFGckGmoxFxUnAgDoyYOrlgIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161223122542epcas1p444c9d8c91c2983f9934e68a6bb882726 X-Msg-Generator: CA X-Sender-IP: 203.254.230.26 X-Local-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRtT?= =?UTF-8?B?YW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 101P X-HopCount: 7 X-CMS-RootMailID: 20161223122542epcas1p444c9d8c91c2983f9934e68a6bb882726 X-RootMTR: 20161223122542epcas1p444c9d8c91c2983f9934e68a6bb882726 References: <1482495889-6201-1-git-send-email-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds runtime power management support to Samsung pin controller driver. It uses recently introduced property to mark some pin states as suitable for power off. When all pins for given controller are set to this special state, the controller is able to enter runtime suspend state. This in turn might allow to turn respective power domain off to reduce power consumption. This patch moves saving driver state to runtime pm callbacks and implements system sleep suspend/resume callbacks with pm_runtime_force_suspend/resume helpers to keep the runtime pm state consistent with the hardware both during runtime and system sleep transitions. Signed-off-by: Marek Szyprowski Reviewed-by: Krzysztof Kozlowski --- drivers/pinctrl/samsung/pinctrl-samsung.c | 24 ++++++++++++++++++++++-- drivers/pinctrl/samsung/pinctrl-samsung.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c index 301169d2b6e1..c741e93d65b8 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.c +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "../core.h" @@ -378,6 +379,17 @@ static void samsung_pinmux_setup(struct pinctrl_dev *pctldev, unsigned selector, shift -= 32; reg += 4; } + if (func->rpm_active) { + if (!(bank->rpm_map & (1 << pin_offset))) { + bank->rpm_map |= 1 << pin_offset; + pm_runtime_get_sync(drvdata->dev); + } + } else { + if ((bank->rpm_map & (1 << pin_offset))) { + bank->rpm_map &= ~(1 << pin_offset); + pm_runtime_put(drvdata->dev); + } + } spin_lock_irqsave(&bank->slock, flags); @@ -427,6 +439,8 @@ static int samsung_pinconf_rw(struct pinctrl_dev *pctldev, unsigned int pin, if (cfg_type >= PINCFG_TYPE_NUM || !type->fld_width[cfg_type]) return -EINVAL; + pm_runtime_get_sync(drvdata->dev); + width = type->fld_width[cfg_type]; cfg_reg = type->reg_offset[cfg_type]; @@ -449,6 +463,8 @@ static int samsung_pinconf_rw(struct pinctrl_dev *pctldev, unsigned int pin, spin_unlock_irqrestore(&bank->slock, flags); + pm_runtime_put(drvdata->dev); + return 0; } @@ -1096,6 +1112,8 @@ static int samsung_pinctrl_probe(struct platform_device *pdev) ctrl->retention_init(drvdata); platform_set_drvdata(pdev, drvdata); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); return 0; } @@ -1242,8 +1260,10 @@ static int samsung_pinctrl_resume(struct device *dev) MODULE_DEVICE_TABLE(of, samsung_pinctrl_dt_match); static const struct dev_pm_ops samsung_pinctrl_pm_ops = { - SET_LATE_SYSTEM_SLEEP_PM_OPS(samsung_pinctrl_suspend, - samsung_pinctrl_resume) + SET_RUNTIME_PM_OPS(samsung_pinctrl_suspend, + samsung_pinctrl_resume, NULL) + SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) }; static struct platform_driver samsung_pinctrl_driver = { diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.h b/drivers/pinctrl/samsung/pinctrl-samsung.h index edeafa00abd3..ccb24ec46796 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.h +++ b/drivers/pinctrl/samsung/pinctrl-samsung.h @@ -172,6 +172,7 @@ struct samsung_pin_bank { const char *name; u32 pin_base; + u32 rpm_map; void *soc_priv; struct device_node *of_node; struct samsung_pinctrl_drv_data *drvdata;