pwm: lpc18xx-sct: don't reconfigure PWM in .request and .free
diff mbox series

Message ID 20181116065208.3920-1-u.kleine-koenig@pengutronix.de
State New
Headers show
Series
  • pwm: lpc18xx-sct: don't reconfigure PWM in .request and .free
Related show

Commit Message

Uwe Kleine-König Nov. 16, 2018, 6:52 a.m. UTC
Regarding the .request case: The consumer might be interested in taking
over the configured state from the boot loader. So the initially
configured state should be retained.

For the free case the PWM consumer is responsible to disable the PWM
before calling pwm_release and there are three subcases to consider:

 a) The pwm is already off. Then there is no gain in disabling the PWM
    once more.
 b) The pwm is still running and there is a good reason for that. (Not
    sure this is a valid case, I cannot imagine such a good reason.)
    Then it is contra productive to disable the pwm.
 c) The pwm is still running because the consumer failed to disable the
    PWM. Then the consumer needs fixing and there is little incentive to
    paper over the problem in the backend driver.

This aligns the lpc18xx-sct driver to the other PWM drivers that also
don't reconfigure the hardware in .request and .free.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/pwm-lpc18xx-sct.c | 3 ---
 1 file changed, 3 deletions(-)

Comments

Uwe Kleine-König Nov. 16, 2018, 7:02 a.m. UTC | #1
Hello,

FTR: The e-mail address of Joachim Eastwood doesn't work. I got a bounce
back saying "The email account that you tried to reach is over quota.
Please direct the recipient to
https://support.google.com/mail/?p=OverQuotaPerm."

If you remember this when replying to this thread I think the right
thing is to drop him from the recipents.

Best regards
Uwe
Vladimir Zapolskiy Nov. 16, 2018, 9:22 a.m. UTC | #2
Hello Uwe,

On 11/16/2018 08:52 AM, Uwe Kleine-König wrote:
> Regarding the .request case: The consumer might be interested in taking
> over the configured state from the boot loader. So the initially
> configured state should be retained.
> 
> For the free case the PWM consumer is responsible to disable the PWM
> before calling pwm_release and there are three subcases to consider:
> 

the changes are fine per se, but please split them into two.

Probably pwm_disable() misusage began spreading from commit 54b2a999a1675.

--
Best wishes,
Vladimir
Uwe Kleine-König Nov. 16, 2018, 9:48 a.m. UTC | #3
On Fri, Nov 16, 2018 at 11:22:49AM +0200, Vladimir Zapolskiy wrote:
> Hello Uwe,
> 
> On 11/16/2018 08:52 AM, Uwe Kleine-König wrote:
> > Regarding the .request case: The consumer might be interested in taking
> > over the configured state from the boot loader. So the initially
> > configured state should be retained.
> > 
> > For the free case the PWM consumer is responsible to disable the PWM
> > before calling pwm_release and there are three subcases to consider:
> > 
> 
> the changes are fine per se, but please split them into two.
> 
> Probably pwm_disable() misusage began spreading from commit 54b2a999a1675.

I see little benefit, but if that's the only problem I can split.

Note that the behaviours of .request and .free are not unrelated.
Currently because .free sets a duty cycle of 0 we have
pwm_get_duty_cycle always return 0 in .request.

Waiting on what Thierry thinks.

Best regards
Uwe
Thierry Reding Nov. 16, 2018, 10:01 a.m. UTC | #4
On Fri, Nov 16, 2018 at 11:22:49AM +0200, Vladimir Zapolskiy wrote:
> Hello Uwe,
> 
> On 11/16/2018 08:52 AM, Uwe Kleine-König wrote:
> > Regarding the .request case: The consumer might be interested in taking
> > over the configured state from the boot loader. So the initially
> > configured state should be retained.
> > 
> > For the free case the PWM consumer is responsible to disable the PWM
> > before calling pwm_release and there are three subcases to consider:
> > 
> 
> the changes are fine per se, but please split them into two.
> 
> Probably pwm_disable() misusage began spreading from commit 54b2a999a1675.

It's not really misusage to call pwm_disable(). It's basically just a
shortcut for ->disable() or the atomic equivalent for it. So I think the
commit that you point to is doing exactly the right thing. Also note
that that commit was made 6 years ago, and a lot of things have changed
since then.

Thierry
Thierry Reding Nov. 16, 2018, 10:05 a.m. UTC | #5
On Fri, Nov 16, 2018 at 07:52:08AM +0100, Uwe Kleine-König wrote:
> Regarding the .request case: The consumer might be interested in taking
> over the configured state from the boot loader. So the initially
> configured state should be retained.
> 
> For the free case the PWM consumer is responsible to disable the PWM
> before calling pwm_release and there are three subcases to consider:
> 
>  a) The pwm is already off. Then there is no gain in disabling the PWM
>     once more.
>  b) The pwm is still running and there is a good reason for that. (Not
>     sure this is a valid case, I cannot imagine such a good reason.)
>     Then it is contra productive to disable the pwm.
>  c) The pwm is still running because the consumer failed to disable the
>     PWM. Then the consumer needs fixing and there is little incentive to
>     paper over the problem in the backend driver.
> 
> This aligns the lpc18xx-sct driver to the other PWM drivers that also
> don't reconfigure the hardware in .request and .free.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/pwm/pwm-lpc18xx-sct.c | 3 ---
>  1 file changed, 3 deletions(-)

Applied, with some minor fixes to the commit message (pwm -> PWM,
pwm_release -> pwm_put(), ...).

Thanks,
Thierry
Uwe Kleine-König Nov. 16, 2018, 10:45 a.m. UTC | #6
Hello Thierry,

On Fri, Nov 16, 2018 at 11:01:14AM +0100, Thierry Reding wrote:
> On Fri, Nov 16, 2018 at 11:22:49AM +0200, Vladimir Zapolskiy wrote:
> > On 11/16/2018 08:52 AM, Uwe Kleine-König wrote:
> > > Regarding the .request case: The consumer might be interested in taking
> > > over the configured state from the boot loader. So the initially
> > > configured state should be retained.
> > > 
> > > For the free case the PWM consumer is responsible to disable the PWM
> > > before calling pwm_release and there are three subcases to consider:
> > > 
> > 
> > the changes are fine per se, but please split them into two.
> > 
> > Probably pwm_disable() misusage began spreading from commit 54b2a999a1675.
> 
> It's not really misusage to call pwm_disable(). It's basically just a
> shortcut for ->disable() or the atomic equivalent for it.

I'd say that pwm_disable() is not a shortcut but the long way round to
.disable() at best.

And that calling pwm_disable() from the low level driver doesn't result
in problems is just luck because the pwm framework is such a thin
wrapper. If it would do locking, .free might already hold the lock and
pwm_disable might try to grab it again. If it would do more checking
that only a caller of pwm_get calls pwm_disable, the check would trigger
because the consumer already called pwm_put and the lowlevel driver
didn't use pwm_get.

Best regards
Uwe
Uwe Kleine-König Nov. 19, 2018, 7:55 p.m. UTC | #7
Hello Thierry,

On Fri, Nov 16, 2018 at 11:05:00AM +0100, Thierry Reding wrote:
> Applied, with some minor fixes to the commit message (pwm -> PWM,
> pwm_release -> pwm_put(), ...).

Thanks. I wonder though why the commit didn't make it into next yet.
Your for-next branch doesn't contain anything that's not already in
Linus Torvalds' tree. I assume this isn't on purpose and you just didn't
push your changes out?

Best regards
Uwe
Thierry Reding Nov. 20, 2018, 3:42 p.m. UTC | #8
On Mon, Nov 19, 2018 at 08:55:28PM +0100, Uwe Kleine-König wrote:
> Hello Thierry,
> 
> On Fri, Nov 16, 2018 at 11:05:00AM +0100, Thierry Reding wrote:
> > Applied, with some minor fixes to the commit message (pwm -> PWM,
> > pwm_release -> pwm_put(), ...).
> 
> Thanks. I wonder though why the commit didn't make it into next yet.
> Your for-next branch doesn't contain anything that's not already in
> Linus Torvalds' tree. I assume this isn't on purpose and you just didn't
> push your changes out?

Pushed now.

Thierry

Patch
diff mbox series

diff --git a/drivers/pwm/pwm-lpc18xx-sct.c b/drivers/pwm/pwm-lpc18xx-sct.c
index d7f5f7de030d..475918d9f543 100644
--- a/drivers/pwm/pwm-lpc18xx-sct.c
+++ b/drivers/pwm/pwm-lpc18xx-sct.c
@@ -296,7 +296,6 @@  static int lpc18xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
 
 	set_bit(event, &lpc18xx_pwm->event_map);
 	lpc18xx_data->duty_event = event;
-	lpc18xx_pwm_config_duty(chip, pwm, pwm_get_duty_cycle(pwm));
 
 	return 0;
 }
@@ -306,8 +305,6 @@  static void lpc18xx_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
 	struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
 	struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm);
 
-	pwm_disable(pwm);
-	pwm_set_duty_cycle(pwm, 0);
 	clear_bit(lpc18xx_data->duty_event, &lpc18xx_pwm->event_map);
 }