Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4982380ima; Tue, 5 Feb 2019 04:41:31 -0800 (PST) X-Google-Smtp-Source: AHgI3IZwWZNpC6lSELYjGLoOZg6/0phUW5HhZw1Xmaeo7irkBXmQGEjF5u2HvilaQibKsATb33HD X-Received: by 2002:a62:2cf:: with SMTP id 198mr4820144pfc.67.1549370491884; Tue, 05 Feb 2019 04:41:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549370491; cv=none; d=google.com; s=arc-20160816; b=b00CjlAeQPP19ifMjfmvwIHHrWGnO+AtNccNdtGQPX/FAaNdiJHfHoseQcs3ROyUm2 BZ00kxag0emtdSgiaJJMpWuZimCHZ+WjN/rAPOiuGrx8ySMj/LDyCxDJR7920hGT05KM 7gMHjfPu2J6PFyFdXjgk7EBn5fw47E2tcO4SPLLCuVTzJi9ge2D5OF0r7iEA+roIC+IW TKzzqRtvOpex3EekZsmBCw9Y/wY6PmC4bsTZV8K4lmzWDo6Rx7pHOFgoQ0Wd0okapfT0 0yPUJdTDBYRaL/gXrUyyAtkl9fIkYXu+Bol9Mm3CMEEW4oJE8R5QMrtYmyZoTvroJWpl A88g== 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=II/RzQnGcmXIrQhMQOVCguh9nH7C459mI5zqB5OdBJw=; b=xO90bjB1yAx5jpqFp7UTp4VDN1f6kcye7kAUNgxCVxGtxMKaZjrY9Byro2tKbLJXwc FiKS6IDdGbYuymgespxRWrYa7Wn69dgMkcy6priop53nQG27uN1D0TVzIY3VG2a4SeRc f0XJoUUpieerPrACi4lv8Byn32E4shP0eIG+ES1nMj7+2jrJTTvlKqiCGKU9A+3q1wZ2 Fdt5eblDAUYbBmclnlsQYdJzxUuR7USoWSFBYh7UOilRFog9BogDKac0xNPt+48jtXnm ibk/bdqfy+eoo7X5waECXRUBAn9iS4I3h+TP+bc8CcokCdDi72TkFuTOmYJ2Kw954vlj p8uw== 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 p11si3096132plo.363.2019.02.05.04.41.15; Tue, 05 Feb 2019 04:41:31 -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 S1728933AbfBEMlF (ORCPT + 99 others); Tue, 5 Feb 2019 07:41:05 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:23951 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728472AbfBEMk6 (ORCPT ); Tue, 5 Feb 2019 07:40:58 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x15CZncn027439; Tue, 5 Feb 2019 13:40:44 +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 2qdjdnkkn7-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 05 Feb 2019 13:40:44 +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 DA21D31; Tue, 5 Feb 2019 12:40:43 +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 A9CF229AF; Tue, 5 Feb 2019 12:40:43 +0000 (GMT) Received: from localhost (10.75.127.44) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 5 Feb 2019 13:40:43 +0100 From: Fabrice Gasnier To: , , CC: , , , , , , , , , , Subject: [PATCH 4/4] iio: counter: stm32-lptimer: Add power management support Date: Tue, 5 Feb 2019 13:40:29 +0100 Message-ID: <1549370429-19116-5-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.44] X-ClientProxiedBy: SFHDAG3NODE3.st.com (10.75.127.9) 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 counter. Only active counter should be resumed: don't touch disabled counter, as it may be used by other LPTimer MFD child driver. Signed-off-by: Fabrice Gasnier --- drivers/iio/counter/stm32-lptimer-cnt.c | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/iio/counter/stm32-lptimer-cnt.c b/drivers/iio/counter/stm32-lptimer-cnt.c index 42fb8ba..2a49cce 100644 --- a/drivers/iio/counter/stm32-lptimer-cnt.c +++ b/drivers/iio/counter/stm32-lptimer-cnt.c @@ -14,6 +14,7 @@ #include #include #include +#include #include struct stm32_lptim_cnt { @@ -23,6 +24,7 @@ struct stm32_lptim_cnt { u32 preset; u32 polarity; u32 quadrature_mode; + bool enabled; }; static int stm32_lptim_is_enabled(struct stm32_lptim_cnt *priv) @@ -50,6 +52,7 @@ static int stm32_lptim_set_enable_state(struct stm32_lptim_cnt *priv, if (!enable) { clk_disable(priv->clk); + priv->enabled = false; return 0; } @@ -79,6 +82,7 @@ static int stm32_lptim_set_enable_state(struct stm32_lptim_cnt *priv, regmap_write(priv->regmap, STM32_LPTIM_CR, 0); return ret; } + priv->enabled = true; /* Start LP timer in continuous mode */ return regmap_update_bits(priv->regmap, STM32_LPTIM_CR, @@ -361,6 +365,56 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev) return devm_iio_device_register(&pdev->dev, indio_dev); } +#ifdef CONFIG_PM_SLEEP +static int stm32_lptim_cnt_suspend(struct device *dev) +{ + struct stm32_lptim_cnt *priv = dev_get_drvdata(dev); + int ret; + + /* Only take care of enabled counter: don't disturb other MFD child */ + if (priv->enabled) { + ret = stm32_lptim_setup(priv, 0); + if (ret) + return ret; + + ret = stm32_lptim_set_enable_state(priv, 0); + if (ret) + return ret; + + /* Force enable state for later resume */ + priv->enabled = true; + } + + return pinctrl_pm_select_sleep_state(dev); +} + +static int stm32_lptim_cnt_resume(struct device *dev) +{ + struct stm32_lptim_cnt *priv = dev_get_drvdata(dev); + int ret; + + ret = pinctrl_pm_select_default_state(dev); + if (ret) + return ret; + + if (priv->enabled) { + priv->enabled = false; + ret = stm32_lptim_setup(priv, 1); + if (ret) + return ret; + + ret = stm32_lptim_set_enable_state(priv, 1); + if (ret) + return ret; + } + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(stm32_lptim_cnt_pm_ops, stm32_lptim_cnt_suspend, + stm32_lptim_cnt_resume); + static const struct of_device_id stm32_lptim_cnt_of_match[] = { { .compatible = "st,stm32-lptimer-counter", }, {}, @@ -372,6 +426,7 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev) .driver = { .name = "stm32-lptimer-counter", .of_match_table = stm32_lptim_cnt_of_match, + .pm = &stm32_lptim_cnt_pm_ops, }, }; module_platform_driver(stm32_lptim_cnt_driver); -- 1.9.1