Re: [PATCH 1/3] pwm: cros-ec: Don't care about consumers in .get_state()

From: Uwe Kleine-König
Date: Thu Jun 13 2024 - 02:07:31 EST


Hello,

On Wed, Jun 12, 2024 at 06:27:14AM +0000, Tzung-Bi Shih wrote:
> On Tue, Jun 11, 2024 at 12:39:44PM +0200, Uwe Kleine-König wrote:
> > On Tue, Jun 11, 2024 at 08:50:44AM +0000, Tzung-Bi Shih wrote:
> > > On Fri, Jun 07, 2024 at 10:44:15AM +0200, Uwe Kleine-König wrote:
> > > > The get_state() callback is never called (in a visible way) after there
> > > > is a consumer for a pwm device. The core handles loosing the information
> > > > about duty_cycle just fine.
> > >
> > > ChromeOS EC has no separated "enabled" state, it sees `duty == 0` as
> > > "disabled"[1]. 1db37f9561b2 ("pwm: cros-ec: Cache duty cycle value")
> > > caches the value in kernel side so that it can retrieve the original duty
> > > value even if (struct pwm_state *)->enabled is false.
> >
> > There is no need to cache, so the following would work:
>
> Ack.
>
> > > To make sure I understand, did you mean the original duty value could be less
> > > important because:
> > > - We are less caring as it is in a debug context at [2]?
> > > - At [3], the PWM device is still initializing.
> >
> > It doesn't really matter that this is about debug or initialisation. The
> > key here is that the core can handle the PWM using duty_cycle 0 (or
> > anything else) when it was requested to be disabled.
> >
> >
> > > [1]: https://crrev.com/0e16954460a08133b2557150e0897014ea2b9672/common/pwm.c#66
> > > [2]: https://elixir.bootlin.com/linux/v6.10-rc3/source/drivers/pwm/core.c#L52
> > > [3]: https://elixir.bootlin.com/linux/v6.10-rc3/source/drivers/pwm/core.c#L371
>
> I was trying to understand the description in the commit message:
> : The get_state() callback is never called (in a visible way) after there
> : is a consumer for a pwm device.
>
> I guess I understood; the core reads the duty value via get_state() when:
> - Initializing the device for the intial value.

Yes, that a consumer cannot do any assumptions about a PWM just aquired,
so there is no danger for confusion.

> - Debugging for checking if apply() really takes effect.

Right, and the read pwm_state is only used in the core. The core won't
be confused about disabled vs. duty=0. Consumers never see the result of
the .get_state callback.

> What 1db37f9561b2 worried about is already addressed by the core[4].
> [4]: https://elixir.bootlin.com/linux/v6.10-rc3/source/drivers/pwm/core.c#L495

What 1db37f9561b2 worried about is bogus, because pwm_get_state()
doesn't call the .get_state() callback:

$ git show 1db37f9561b2:include/linux/pwm.h | awk '/void pwm_get_state/,/^$/'
static inline void pwm_get_state(const struct pwm_device *pwm,
struct pwm_state *state)
{
*state = pwm->state;
}

> Reviewed-by: Tzung-Bi Shih <tzungbi@xxxxxxxxxx>

I'll apply the patch under discussion and create a proper patch for the
ad-hoc change from my previous mail.

Thanks
Uwe

Attachment: signature.asc
Description: PGP signature