From: Thierry Reding <thierry.reding@gmail.com>
To: Fabrice Gasnier <fabrice.gasnier@st.com>
Cc: mark.rutland@arm.com, devicetree@vger.kernel.org,
alexandre.torgue@st.com, linux-pwm@vger.kernel.org,
linux-kernel@vger.kernel.org, robh+dt@kernel.org,
mcoquelin.stm32@gmail.com, u.kleine-koenig@pengutronix.de,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org, benjamin.gaignard@st.com
Subject: Re: [PATCH v2 3/3] pwm: stm32: add power management support
Date: Wed, 16 Oct 2019 09:06:35 +0200 [thread overview]
Message-ID: <20191016070635.GC1296874@ulmo> (raw)
In-Reply-To: <1570193633-6600-4-git-send-email-fabrice.gasnier@st.com>
[-- Attachment #1.1: Type: text/plain, Size: 3230 bytes --]
On Fri, Oct 04, 2019 at 02:53:53PM +0200, Fabrice Gasnier wrote:
> Add suspend/resume PM sleep ops. When going to low power, enforce the PWM
> channel isn't active. Let the PWM consumers disable it during their own
> suspend sequence, see [1]. So, perform a check here, and handle the
> pinctrl states. Also restore the break inputs upon resume, as registers
> content may be lost when going to low power mode.
>
> [1] https://lkml.org/lkml/2019/2/5/770
>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
> ---
> Changes in v2:
> Follow Uwe suggestions/remarks:
> - Add a precursor patch to ease reviewing
> - Use registers read instead of pwm_get_state
> - Add a comment to mention registers content may be lost in low power mode
> ---
> drivers/pwm/pwm-stm32.c | 38 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
Applied, thanks. I made two minor changes, though, see below.
>
> diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
> index cf8658c..546b661 100644
> --- a/drivers/pwm/pwm-stm32.c
> +++ b/drivers/pwm/pwm-stm32.c
> @@ -12,6 +12,7 @@
> #include <linux/mfd/stm32-timers.h>
> #include <linux/module.h>
> #include <linux/of.h>
> +#include <linux/pinctrl/consumer.h>
> #include <linux/platform_device.h>
> #include <linux/pwm.h>
>
> @@ -655,6 +656,42 @@ static int stm32_pwm_remove(struct platform_device *pdev)
> return 0;
> }
>
> +static int __maybe_unused stm32_pwm_suspend(struct device *dev)
> +{
> + struct stm32_pwm *priv = dev_get_drvdata(dev);
> + unsigned int ch;
I renamed this to just "i", which is more idiomatic for loop variables.
The function is small enough not to need to differentiate between loop
variables.
> + u32 ccer, mask;
> +
> + /* Look for active channels */
> + ccer = active_channels(priv);
> +
> + for (ch = 0; ch < priv->chip.npwm; ch++) {
> + mask = TIM_CCER_CC1E << (ch * 4);
> + if (ccer & mask) {
> + dev_err(dev, "The consumer didn't stop us (%s)\n",
> + priv->chip.pwms[ch].label);
Changed this to:
"PWM %u still in use by consumer %s\n", i, priv->chip.pwms[i].label
I think that might help clarify which PWM is still enabled in case the
consumers don't set a label.
Thierry
> + return -EBUSY;
> + }
> + }
> +
> + return pinctrl_pm_select_sleep_state(dev);
> +}
> +
> +static int __maybe_unused stm32_pwm_resume(struct device *dev)
> +{
> + struct stm32_pwm *priv = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = pinctrl_pm_select_default_state(dev);
> + if (ret)
> + return ret;
> +
> + /* restore breakinput registers that may have been lost in low power */
> + return stm32_pwm_apply_breakinputs(priv);
> +}
> +
> +static SIMPLE_DEV_PM_OPS(stm32_pwm_pm_ops, stm32_pwm_suspend, stm32_pwm_resume);
> +
> static const struct of_device_id stm32_pwm_of_match[] = {
> { .compatible = "st,stm32-pwm", },
> { /* end node */ },
> @@ -667,6 +704,7 @@ static struct platform_driver stm32_pwm_driver = {
> .driver = {
> .name = "stm32-pwm",
> .of_match_table = stm32_pwm_of_match,
> + .pm = &stm32_pwm_pm_ops,
> },
> };
> module_platform_driver(stm32_pwm_driver);
> --
> 2.7.4
>
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Thierry Reding <thierry.reding@gmail.com>
To: Fabrice Gasnier <fabrice.gasnier@st.com>
Cc: robh+dt@kernel.org, u.kleine-koenig@pengutronix.de,
alexandre.torgue@st.com, mark.rutland@arm.com,
mcoquelin.stm32@gmail.com, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org,
benjamin.gaignard@st.com,
linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH v2 3/3] pwm: stm32: add power management support
Date: Wed, 16 Oct 2019 09:06:35 +0200 [thread overview]
Message-ID: <20191016070635.GC1296874@ulmo> (raw)
In-Reply-To: <1570193633-6600-4-git-send-email-fabrice.gasnier@st.com>
[-- Attachment #1: Type: text/plain, Size: 3230 bytes --]
On Fri, Oct 04, 2019 at 02:53:53PM +0200, Fabrice Gasnier wrote:
> Add suspend/resume PM sleep ops. When going to low power, enforce the PWM
> channel isn't active. Let the PWM consumers disable it during their own
> suspend sequence, see [1]. So, perform a check here, and handle the
> pinctrl states. Also restore the break inputs upon resume, as registers
> content may be lost when going to low power mode.
>
> [1] https://lkml.org/lkml/2019/2/5/770
>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
> ---
> Changes in v2:
> Follow Uwe suggestions/remarks:
> - Add a precursor patch to ease reviewing
> - Use registers read instead of pwm_get_state
> - Add a comment to mention registers content may be lost in low power mode
> ---
> drivers/pwm/pwm-stm32.c | 38 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
Applied, thanks. I made two minor changes, though, see below.
>
> diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
> index cf8658c..546b661 100644
> --- a/drivers/pwm/pwm-stm32.c
> +++ b/drivers/pwm/pwm-stm32.c
> @@ -12,6 +12,7 @@
> #include <linux/mfd/stm32-timers.h>
> #include <linux/module.h>
> #include <linux/of.h>
> +#include <linux/pinctrl/consumer.h>
> #include <linux/platform_device.h>
> #include <linux/pwm.h>
>
> @@ -655,6 +656,42 @@ static int stm32_pwm_remove(struct platform_device *pdev)
> return 0;
> }
>
> +static int __maybe_unused stm32_pwm_suspend(struct device *dev)
> +{
> + struct stm32_pwm *priv = dev_get_drvdata(dev);
> + unsigned int ch;
I renamed this to just "i", which is more idiomatic for loop variables.
The function is small enough not to need to differentiate between loop
variables.
> + u32 ccer, mask;
> +
> + /* Look for active channels */
> + ccer = active_channels(priv);
> +
> + for (ch = 0; ch < priv->chip.npwm; ch++) {
> + mask = TIM_CCER_CC1E << (ch * 4);
> + if (ccer & mask) {
> + dev_err(dev, "The consumer didn't stop us (%s)\n",
> + priv->chip.pwms[ch].label);
Changed this to:
"PWM %u still in use by consumer %s\n", i, priv->chip.pwms[i].label
I think that might help clarify which PWM is still enabled in case the
consumers don't set a label.
Thierry
> + return -EBUSY;
> + }
> + }
> +
> + return pinctrl_pm_select_sleep_state(dev);
> +}
> +
> +static int __maybe_unused stm32_pwm_resume(struct device *dev)
> +{
> + struct stm32_pwm *priv = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = pinctrl_pm_select_default_state(dev);
> + if (ret)
> + return ret;
> +
> + /* restore breakinput registers that may have been lost in low power */
> + return stm32_pwm_apply_breakinputs(priv);
> +}
> +
> +static SIMPLE_DEV_PM_OPS(stm32_pwm_pm_ops, stm32_pwm_suspend, stm32_pwm_resume);
> +
> static const struct of_device_id stm32_pwm_of_match[] = {
> { .compatible = "st,stm32-pwm", },
> { /* end node */ },
> @@ -667,6 +704,7 @@ static struct platform_driver stm32_pwm_driver = {
> .driver = {
> .name = "stm32-pwm",
> .of_match_table = stm32_pwm_of_match,
> + .pm = &stm32_pwm_pm_ops,
> },
> };
> module_platform_driver(stm32_pwm_driver);
> --
> 2.7.4
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-10-16 7:06 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-04 12:53 [PATCH v2 0/3] Add PM support to STM32 Timer PWM Fabrice Gasnier
2019-10-04 12:53 ` Fabrice Gasnier
2019-10-04 12:53 ` Fabrice Gasnier
2019-10-04 12:53 ` [PATCH v2 1/3] dt-bindings: pwm-stm32: document pinctrl sleep state Fabrice Gasnier
2019-10-04 12:53 ` Fabrice Gasnier
2019-10-04 12:53 ` Fabrice Gasnier
2019-10-11 15:10 ` Rob Herring
2019-10-11 15:10 ` Rob Herring
2019-10-11 15:10 ` Rob Herring
2019-10-16 6:59 ` Thierry Reding
2019-10-16 6:59 ` Thierry Reding
2019-10-04 12:53 ` [PATCH v2 2/3] pwm: stm32: split breakinput apply routine to ease PM support Fabrice Gasnier
2019-10-04 12:53 ` Fabrice Gasnier
2019-10-04 12:53 ` Fabrice Gasnier
2019-10-16 7:03 ` Thierry Reding
2019-10-16 7:03 ` Thierry Reding
2019-10-04 12:53 ` [PATCH v2 3/3] pwm: stm32: add power management support Fabrice Gasnier
2019-10-04 12:53 ` Fabrice Gasnier
2019-10-04 12:53 ` Fabrice Gasnier
2019-10-16 7:06 ` Thierry Reding [this message]
2019-10-16 7:06 ` Thierry Reding
2019-10-16 10:08 ` Fabrice Gasnier
2019-10-16 10:08 ` Fabrice Gasnier
2019-10-16 10:08 ` Fabrice Gasnier
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=20191016070635.GC1296874@ulmo \
--to=thierry.reding@gmail.com \
--cc=alexandre.torgue@st.com \
--cc=benjamin.gaignard@st.com \
--cc=devicetree@vger.kernel.org \
--cc=fabrice.gasnier@st.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mark.rutland@arm.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=robh+dt@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.