Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1787319imb; Sun, 3 Mar 2019 06:41:35 -0800 (PST) X-Google-Smtp-Source: APXvYqxQ12gX1Y0C9SgDsqG7p3sk6jBD9hfURVI0a8psvjjI1eu/4k4JNRDmYI2pt7+94JfzldNk X-Received: by 2002:a17:902:27a8:: with SMTP id d37mr15482459plb.164.1551624095621; Sun, 03 Mar 2019 06:41:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551624095; cv=none; d=google.com; s=arc-20160816; b=vbp+sBWacBRBoMIIjoGE+6wJ8SiWqFfa0Y2K+VFIekIbvjMFMhF3bHHL3khoFyOqJN 54gfQ5z4Mnj6q46fa0TplhsN+67lWrZ0vP5039ePmr4ew3CrWJ4Cr9qjjFHjfbb0fFs/ gU+SBC95Btu3QP7qCBQFYv41+kn8wJwLoIl25zmlN4vp98drxZN1lFoa0OtN/bAkWZTG +5sLE1A7Hw/542CLwYF6GMSk1jy614wlqe3lzOZ8sXXB6yUrYNBYFMhrY01jGVdMJmUe KS8SDDV/bBAq7/9cpDZy/djxFlfk/9stuBJyBMjzRsmI6e26f8BkCvgsHquyFXjoBtQH muYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=MnpC/pwx6qS/W+zJVKcQjs3LTRQoL0AT2XdXy8ewtOs=; b=Xu1G2OFWWpMxtOnHyXGSpbcTbqhfi6aaZzXC9eALwgi99BwnRRE1UuDCo5p9mrHimZ MmUCblR28N1ovByU9q1O6n/WKr2vD/uhVIawfXFSsqd/9F5TMTLKQLDKrxzvdlCPc1CF Y1QjmMmGwri4nqopaIo63eTjV10qquxTNBPLWWmrm0gDxgHQwroK2qCdiUD/3mLNSzL2 9P6nwnP/paWSMYoefp1v3MTIjMP9SKpGOUuKHFMHN6Clierq5OKksYoHWsR6ieRj1/34 k2KzpSPEJPc83nT7OiP/79yAjg8eNls1F0NL5kFRQPJRBqbK8p2S4NJfj/mN9W0q/sD4 YH0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qofhbKL2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si2953620plv.26.2019.03.03.06.41.20; Sun, 03 Mar 2019 06:41:35 -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; dkim=pass header.i=@kernel.org header.s=default header.b=qofhbKL2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726383AbfCCOki (ORCPT + 99 others); Sun, 3 Mar 2019 09:40:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:45018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726241AbfCCOki (ORCPT ); Sun, 3 Mar 2019 09:40:38 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D8EE620836; Sun, 3 Mar 2019 14:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551624037; bh=I5dE3gRoqLf4rVNydVf7iFmqqU7MECXQzNmVTa2jtFk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qofhbKL2TLdoMj5xb52j9tfi+0ZPtX/qX1iknni3Ico5H+oek7Tir0zoJX92lCtj3 +dHlm1BmREKfZlZFBYOPNsnq2rIitdWMw4xCSUIKK68wvgfhgJC7b9BqX5ioDK4VIX Q+nKUW+dg6+XlY9i6UkZERjJTgClMVmHJvPNCG/U= Date: Sun, 3 Mar 2019 14:40:31 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , , , , , , , , Subject: Re: [PATCH 2/2] iio: counter: stm32-lptimer: Add power management support Message-ID: <20190303144031.520421cf@archlinux> In-Reply-To: <1551091367-21718-3-git-send-email-fabrice.gasnier@st.com> References: <1551091367-21718-1-git-send-email-fabrice.gasnier@st.com> <1551091367-21718-3-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Feb 2019 11:42:47 +0100 Fabrice Gasnier wrote: > 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 Applied. Thanks, Jonathan > --- > 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);