Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4315706imc; Mon, 25 Feb 2019 02:46:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IZaYh696jmGTo2qdEoPbvybxNlaqvXgWg//P78I8dNxp3aeCGcotB+cENQtSFGN50tkiUx+ X-Received: by 2002:a17:902:6949:: with SMTP id k9mr19907740plt.85.1551091572783; Mon, 25 Feb 2019 02:46:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551091572; cv=none; d=google.com; s=arc-20160816; b=ZWiTUz/Napvi4QbqNwX8xzcAsBePLcKcAFTZM+fbs78AXAqosxTG3IqFTNnpAanAV8 nIq179a2iVwTdMxb5Ynj1ogwCtTHVHjN5I569wThs1ukTB2S4P6vxKDzZPodNNfaOjCr oBlm1nEal2dvyfaAW8YktuROIAgMIUi9zUts67yqagbgR8fiCfma5tk9E9smDSSdkd6m 99ngN00Zulxe/SIYMCh2Ff+c1Iruw6CA1GuTWUuWCVTIlSGwcf/nvtcd5xZVed3qmkzb n5iU0DF0FG0vIBR8OTn88ZOFYMbvdQCoP1QWQFMR9GbaYaF342cvgjj8XcdLZxhv6EFf H8AQ== 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=bUgz1yjbrFi82AIirsCsQJhBTidAIakozAIGbIXzdRs=; b=nuKBicCPyjjwvhA1fLSTTQ6/wBNviD66EiH+nNff3i8ecDHNvwykECA8nFATWs7iZ5 myTqIvXZw1uLFxl9KKfYpkr+c+60FGNnIfXoJOQEm+0HjZkSMMRqe7tPOMoWPSipEHTq Aufq6Dx0wdFgymEl7p/ZxvjRpwWC+nOdPP2Uyqs865LhbuFt/X6ZZ6qzYTpoY3rmKOWJ pTGAMhGrUsn+mz0KxGP1xt5OdJyUJgxvdJSxG1sQat4H8np7/tXB7LOP7Vw/zvem9s9B 7QRa5WG0uTP6EEmq1YRlIH88PeNV+SZBXgaFFFX7vM5GOg8h/1mNY2kijW6BIsSobs+i J+MQ== 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 k70si9120696pgd.74.2019.02.25.02.45.57; Mon, 25 Feb 2019 02:46:12 -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 S1726706AbfBYKnp (ORCPT + 99 others); Mon, 25 Feb 2019 05:43:45 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:32339 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726617AbfBYKnp (ORCPT ); Mon, 25 Feb 2019 05:43:45 -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 x1PAftBv025960; Mon, 25 Feb 2019 11:43:15 +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 2qtvtwsdep-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 25 Feb 2019 11:43:15 +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 BE1C73A; Mon, 25 Feb 2019 10:43:12 +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 92F242844; Mon, 25 Feb 2019 10:43:12 +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; Mon, 25 Feb 2019 11:43:11 +0100 From: Fabrice Gasnier To: , , CC: , , , , , , , , , , , Subject: [PATCH 2/2] iio: counter: stm32-lptimer: Add power management support Date: Mon, 25 Feb 2019 11:42:47 +0100 Message-ID: <1551091367-21718-3-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551091367-21718-1-git-send-email-fabrice.gasnier@st.com> References: <1551091367-21718-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: SFHDAG7NODE3.st.com (10.75.127.21) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-25_06:,, 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 struct platform_driver stm32_lptim_cnt_driver = { .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); -- 2.7.4