Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4982427ima; Tue, 5 Feb 2019 04:41:34 -0800 (PST) X-Google-Smtp-Source: AHgI3IYmjbw4zlf7uvR2bAz1qxA8CVvqncX8ZRQWd0Wvlb8tK6W+DDLUoGzngBYEss+8BvCS8fak X-Received: by 2002:a63:d904:: with SMTP id r4mr4395743pgg.207.1549370494778; Tue, 05 Feb 2019 04:41:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549370494; cv=none; d=google.com; s=arc-20160816; b=VD4wwZFiDCjDwzVy8qDvNWW9OLC6+/v+t7ItLUNQ6W7alRhAkQs65PzH+AuXE9LJ6w qp7VD/3CKIV0DtQ+y22Agb/0pND/KtbFSqVz+d19hZDQqvC/A29kWvWoviRN+1T25U8N GtjiVOmGT3PiOuBDFJZ5QqM0TVASzxAR43VRmCdH79BQiXeVu8Cl6UYa9AXAuo9D2mEm vphjHbiIjfyEABFTj3ngmMqE8bqPmwq4VOg3nMOFZckQQEjtBnj5NZnJJNfcc5E3wVuC I0jnpL2bsdzu/GU4LIhX/ovAaLSmYAmaaHC/zNtjB08MtSdgRsJnuaIEFVqZysj/wBh0 tOWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=PavVWAN3GjYH/sFF9vj+XJMeberlZqWqU4ptYxeNfKY=; b=Cw1/dwoAM6wy4HnQYVSGJjohpNzpiBFs6D7cmDZFUo9ZH7JvsiuNRtzIxo9IFONu0h SqGAeqnERncxcfs2PHwom1zGlfvXcEJwBaBZJ3OXMrbeTcV/gAdM5WB5UUdn6YF44dyT vL6KtS+3IMeXtJ/d3VsQlNEr0HJxRowaVkjJ6Ezgy0rWO5LQd7xqddiPjNAcZQ+FSzec +m6S/GwEWiMresoFSAm6vq/wYTGjP6161VGFePJSyFC+i7x7IirHfE9FoRtlGLMcOfOg lFPj3K9hU/7SA/gmdaKKKFK6MU9WP6PWBqyP4CjhewsX/gQEfF9D4hU3TA+hSNzGtiiY zOPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g69si3201621pfg.225.2019.02.05.04.41.19; Tue, 05 Feb 2019 04:41:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728993AbfBEMlH (ORCPT + 99 others); Tue, 5 Feb 2019 07:41:07 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:37571 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbfBEMk6 (ORCPT ); Tue, 5 Feb 2019 07:40:58 -0500 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x15CaEJQ002718; Tue, 5 Feb 2019 13:40:42 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2qd1v06pqn-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 05 Feb 2019 13:40:42 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 43A8A31; Tue, 5 Feb 2019 12:40:42 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 20A8829AC; Tue, 5 Feb 2019 12:40:42 +0000 (GMT) Received: from localhost (10.75.127.47) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 5 Feb 2019 13:40:41 +0100 From: Fabrice Gasnier To: , , CC: , , , , , , , , , , Subject: [PATCH 2/4] pwm: stm32-lp: Add power management support Date: Tue, 5 Feb 2019 13:40:27 +0100 Message-ID: <1549370429-19116-3-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1549370429-19116-1-git-send-email-fabrice.gasnier@st.com> References: <1549370429-19116-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-05_05:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add suspend/resume PM sleep ops. When going to low power, disable active PWM channel. Active PWM channel is resumed, by calling pwm_apply_state(). This is inspired by Thierry's comment in [1]. Don't touch inactive channels, as it may be used by other LPTimer MFD child driver. [1]https://lkml.org/lkml/2017/12/5/175 Signed-off-by: Fabrice Gasnier --- drivers/pwm/pwm-stm32-lp.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/pwm/pwm-stm32-lp.c b/drivers/pwm/pwm-stm32-lp.c index 0059b24c..0c40d48 100644 --- a/drivers/pwm/pwm-stm32-lp.c +++ b/drivers/pwm/pwm-stm32-lp.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,8 @@ struct stm32_pwm_lp { struct pwm_chip chip; struct clk *clk; struct regmap *regmap; + struct pwm_state suspend; + bool suspended; }; static inline struct stm32_pwm_lp *to_stm32_pwm_lp(struct pwm_chip *chip) @@ -223,6 +226,40 @@ static int stm32_pwm_lp_remove(struct platform_device *pdev) return pwmchip_remove(&priv->chip); } +#ifdef CONFIG_PM_SLEEP +static int stm32_pwm_lp_suspend(struct device *dev) +{ + struct stm32_pwm_lp *priv = dev_get_drvdata(dev); + + pwm_get_state(&priv->chip.pwms[0], &priv->suspend); + priv->suspended = priv->suspend.enabled; + + /* safe to call pwm_disable() for already disabled pwm */ + pwm_disable(&priv->chip.pwms[0]); + + return pinctrl_pm_select_sleep_state(dev); +} + +static int stm32_pwm_lp_resume(struct device *dev) +{ + struct stm32_pwm_lp *priv = dev_get_drvdata(dev); + int ret; + + ret = pinctrl_pm_select_default_state(dev); + if (ret) + return ret; + + /* Only restore suspended pwm, not to disrupt other MFD child */ + if (!priv->suspended) + return 0; + + return pwm_apply_state(&priv->chip.pwms[0], &priv->suspend); +} +#endif + +static SIMPLE_DEV_PM_OPS(stm32_pwm_lp_pm_ops, stm32_pwm_lp_suspend, + stm32_pwm_lp_resume); + static const struct of_device_id stm32_pwm_lp_of_match[] = { { .compatible = "st,stm32-pwm-lp", }, {}, @@ -235,6 +272,7 @@ static int stm32_pwm_lp_remove(struct platform_device *pdev) .driver = { .name = "stm32-pwm-lp", .of_match_table = of_match_ptr(stm32_pwm_lp_of_match), + .pm = &stm32_pwm_lp_pm_ops, }, }; module_platform_driver(stm32_pwm_lp_driver); -- 1.9.1