From: Jonathan Cameron <jic23@kernel.org>
To: Fabrice Gasnier <fabrice.gasnier@st.com>
Cc: lars@metafoo.de, olivier.moysan@st.com, alexandre.torgue@st.com,
linux-iio@vger.kernel.org, pmeerw@pmeerw.net,
linux-kernel@vger.kernel.org, mcoquelin.stm32@gmail.com,
knaack.h@gmx.de, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org, benjamin.gaignard@st.com
Subject: Re: [PATCH 2/2] iio: trigger: stm32-timer: add power management support
Date: Sat, 7 Mar 2020 15:21:27 +0000 [thread overview]
Message-ID: <20200307152127.404aba78@archlinux> (raw)
In-Reply-To: <1583247585-16698-3-git-send-email-fabrice.gasnier@st.com>
On Tue, 3 Mar 2020 15:59:45 +0100
Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> Add suspend/resume PM sleep ops to stm32-timer-trigger driver.
> Register contents may be lost depending on low power modes.
> When going to low power, enforce the timer isn't active. Gracefully
> restore its state upon resume in case it's been left enabled prior to
> suspend.
>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Seems sensible. Applied,
Thanks,
Jonathan
> ---
> drivers/iio/trigger/stm32-timer-trigger.c | 63 +++++++++++++++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c
> index 32e1249..37545a8 100644
> --- a/drivers/iio/trigger/stm32-timer-trigger.c
> +++ b/drivers/iio/trigger/stm32-timer-trigger.c
> @@ -75,6 +75,15 @@ static const void *stm32h7_valids_table[][MAX_VALIDS] = {
> { }, /* timer 17 */
> };
>
> +struct stm32_timer_trigger_regs {
> + u32 cr1;
> + u32 cr2;
> + u32 psc;
> + u32 arr;
> + u32 cnt;
> + u32 smcr;
> +};
> +
> struct stm32_timer_trigger {
> struct device *dev;
> struct regmap *regmap;
> @@ -86,6 +95,7 @@ struct stm32_timer_trigger {
> bool has_trgo2;
> struct mutex lock; /* concurrent sysfs configuration */
> struct list_head tr_list;
> + struct stm32_timer_trigger_regs bak;
> };
>
> struct stm32_timer_trigger_cfg {
> @@ -812,6 +822,58 @@ static int stm32_timer_trigger_remove(struct platform_device *pdev)
> return 0;
> }
>
> +static int __maybe_unused stm32_timer_trigger_suspend(struct device *dev)
> +{
> + struct stm32_timer_trigger *priv = dev_get_drvdata(dev);
> +
> + /* Only take care of enabled timer: don't disturb other MFD child */
> + if (priv->enabled) {
> + /* Backup registers that may get lost in low power mode */
> + regmap_read(priv->regmap, TIM_CR1, &priv->bak.cr1);
> + regmap_read(priv->regmap, TIM_CR2, &priv->bak.cr2);
> + regmap_read(priv->regmap, TIM_PSC, &priv->bak.psc);
> + regmap_read(priv->regmap, TIM_ARR, &priv->bak.arr);
> + regmap_read(priv->regmap, TIM_CNT, &priv->bak.cnt);
> + regmap_read(priv->regmap, TIM_SMCR, &priv->bak.smcr);
> +
> + /* Disable the timer */
> + regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
> + clk_disable(priv->clk);
> + }
> +
> + return 0;
> +}
> +
> +static int __maybe_unused stm32_timer_trigger_resume(struct device *dev)
> +{
> + struct stm32_timer_trigger *priv = dev_get_drvdata(dev);
> + int ret;
> +
> + if (priv->enabled) {
> + ret = clk_enable(priv->clk);
> + if (ret)
> + return ret;
> +
> + /* restore master/slave modes */
> + regmap_write(priv->regmap, TIM_SMCR, priv->bak.smcr);
> + regmap_write(priv->regmap, TIM_CR2, priv->bak.cr2);
> +
> + /* restore sampling_frequency (trgo / trgo2 triggers) */
> + regmap_write(priv->regmap, TIM_PSC, priv->bak.psc);
> + regmap_write(priv->regmap, TIM_ARR, priv->bak.arr);
> + regmap_write(priv->regmap, TIM_CNT, priv->bak.cnt);
> +
> + /* Also re-enables the timer */
> + regmap_write(priv->regmap, TIM_CR1, priv->bak.cr1);
> + }
> +
> + return 0;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(stm32_timer_trigger_pm_ops,
> + stm32_timer_trigger_suspend,
> + stm32_timer_trigger_resume);
> +
> static const struct stm32_timer_trigger_cfg stm32_timer_trg_cfg = {
> .valids_table = valids_table,
> .num_valids_table = ARRAY_SIZE(valids_table),
> @@ -840,6 +902,7 @@ static struct platform_driver stm32_timer_trigger_driver = {
> .driver = {
> .name = "stm32-timer-trigger",
> .of_match_table = stm32_trig_of_match,
> + .pm = &stm32_timer_trigger_pm_ops,
> },
> };
> module_platform_driver(stm32_timer_trigger_driver);
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
prev parent reply other threads:[~2020-03-07 15:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 14:59 [PATCH 0/2] iio: trigger: stm32-timer: add support for power management Fabrice Gasnier
2020-03-03 14:59 ` [PATCH 1/2] iio: trigger: stm32-timer: rename enabled flag Fabrice Gasnier
2020-03-07 15:20 ` Jonathan Cameron
2020-03-03 14:59 ` [PATCH 2/2] iio: trigger: stm32-timer: add power management support Fabrice Gasnier
2020-03-07 15:21 ` Jonathan Cameron [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200307152127.404aba78@archlinux \
--to=jic23@kernel.org \
--cc=alexandre.torgue@st.com \
--cc=benjamin.gaignard@st.com \
--cc=fabrice.gasnier@st.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=olivier.moysan@st.com \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).