linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Marek Vasut <marex@denx.de>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-pwm@vger.kernel.org,
	"Brian Norris" <briannorris@chromium.org>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Yoshihiro Shimoda" <yoshihiro.shimoda.uh@renesas.com>
Subject: Re: [PATCH] pwm: core: Permit unset period when applying configuration of disabled PWMs
Date: Tue, 16 May 2023 11:42:00 +0200	[thread overview]
Message-ID: <ZGNP6B5JRaHiJ5uL@orome> (raw)
In-Reply-To: <d33a20a5-33e3-16a0-6b7c-7b0ec44fc3b3@denx.de>

[-- Attachment #1: Type: text/plain, Size: 3328 bytes --]

On Fri, May 12, 2023 at 02:20:12PM +0200, Marek Vasut wrote:
> On 5/12/23 08:22, Uwe Kleine-König wrote:
> > Hello Marek,
> > 
> > On Thu, May 11, 2023 at 08:18:53PM +0200, Marek Vasut wrote:
> > > In case the PWM is not enabled, the period can still be left unconfigured,
> > > i.e. zero . Currently the pwm_class_apply_state() errors out in such a case.
> > > This e.g. makes suspend fail on systems where pwmchip has been exported via
> > > sysfs interface, but left unconfigured before suspend occurred.
> > > 
> > > Failing case:
> > > "
> > > $ echo 1 > /sys/class/pwm/pwmchip4/export
> > > $ echo mem > /sys/power/state
> > > ...
> > > pwm pwmchip4: PM: dpm_run_callback(): pwm_class_suspend+0x1/0xa8 returns -22
> > > pwm pwmchip4: PM: failed to suspend: error -22
> > > PM: Some devices failed to suspend, or early wake event detected
> > > "
> > > 
> > > Working case:
> > > "
> > > $ echo 1 > /sys/class/pwm/pwmchip4/export
> > > $ echo 100 > /sys/class/pwm/pwmchip4/pwm1/period
> > > $ echo 10 > /sys/class/pwm/pwmchip4/pwm1/duty_cycle
> > > $ echo mem > /sys/power/state
> > > ...
> > > "
> > > 
> > > Permit unset period in pwm_class_apply_state() in case the PWM is disabled
> > > to fix this issue.
> > > 
> > > Fixes: ef2bf4997f7d ("pwm: Improve args checking in pwm_apply_state()")
> > > Signed-off-by: Marek Vasut <marex@denx.de>
> > > ---
> > > Cc: Brian Norris <briannorris@chromium.org>
> > > Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
> > > Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> > > Cc: Thierry Reding <thierry.reding@gmail.com>
> > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > Cc: linux-pwm@vger.kernel.org
> > > ---
> > >   drivers/pwm/core.c | 4 ++--
> > >   1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> > > index 3dacceaef4a9b..87252b70f1c81 100644
> > > --- a/drivers/pwm/core.c
> > > +++ b/drivers/pwm/core.c
> > > @@ -510,8 +510,8 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
> > >   	 */
> > >   	might_sleep();
> > > -	if (!pwm || !state || !state->period ||
> > > -	    state->duty_cycle > state->period)
> > > +	if (!pwm || !state || (state->enabled &&
> > > +	    (!state->period || state->duty_cycle > state->period)))
> > 
> > While I tend to agree that the checks about period and duty_cycle are
> > (somewhat) irrelevant if enabled == false, I fear we'd break assumptions
> > here as some drivers configure duty_cycle/period in hardware even with
> > .enabled == false, and so proably rely on period > 0 and duty_cycle <=
> > period.
> > 
> > Another approach would be to skip pwm_apply_state() in
> > pwm_class_suspend() if the state is already disabled. That one sounds
> > safer.
> 
> I am not convinced that would be identical behavior.
> 
> If we skip apply_state call on PWMs exported via sysfs interface which are
> enabled=false , then the drivers wouldn't have their apply_state callback
> called to disable the PWM before suspend ... I think ... which seems like a
> problem to me ?

If a PWM exported via sysfs has enabled=false, then it should already be
disabled, so calling pwm_apply_state() on them to disable them should be
a no-op.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2023-05-16  9:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11 18:18 [PATCH] pwm: core: Permit unset period when applying configuration of disabled PWMs Marek Vasut
2023-05-11 21:08 ` Brian Norris
2023-05-11 23:32   ` Marek Vasut
2023-05-12  0:51     ` Brian Norris
2023-05-12 16:50       ` Marek Vasut
2023-05-12  6:22 ` Uwe Kleine-König
2023-05-12 12:20   ` Marek Vasut
2023-05-16  9:42     ` Thierry Reding [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=ZGNP6B5JRaHiJ5uL@orome \
    --to=thierry.reding@gmail.com \
    --cc=briannorris@chromium.org \
    --cc=geert+renesas@glider.be \
    --cc=linux-pwm@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /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).