linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Clemens Gruber <clemens.gruber@pqgruber.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: linux-pwm@vger.kernel.org,
	Thierry Reding <thierry.reding@gmail.com>,
	Sven Van Asbroeck <TheSven73@gmail.com>,
	linux-kernel@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH 1/4] pwm: core: Support new usage_power setting in PWM state
Date: Fri, 7 May 2021 17:47:58 +0200	[thread overview]
Message-ID: <YJVhLrkeNXBp6M1p@workstation.tuxnet> (raw)
In-Reply-To: <20210507150317.bnluhqrqepde4xjm@pengutronix.de>

Hi Uwe,

On Fri, May 07, 2021 at 05:03:17PM +0200, Uwe Kleine-König wrote:
> Hello,
> 
> On Fri, May 07, 2021 at 03:18:42PM +0200, Clemens Gruber wrote:
> > diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> > index 5bb90af4997e..5a73251d28e3 100644
> > --- a/include/linux/pwm.h
> > +++ b/include/linux/pwm.h
> > @@ -54,12 +54,17 @@ enum {
> >   * @duty_cycle: PWM duty cycle (in nanoseconds)
> >   * @polarity: PWM polarity
> >   * @enabled: PWM enabled status
> > + * @usage_power: If set, the PWM driver is only required to maintain the power
> > + *               output but has more freedom regarding signal form.
> > + *               If supported, the signal can be optimized, for example to
> > + *               improve EMI by phase shifting individual channels.
> >   */
> >  struct pwm_state {
> >  	u64 period;
> >  	u64 duty_cycle;
> >  	enum pwm_polarity polarity;
> >  	bool enabled;
> > +	bool usage_power;
> >  };
> >  
> >  /**
> 
> If we really want to support this usecase, I would prefer to not have it
> in pwm_state because this concept is not a property of the wave form. So
> for a driver it doesn't really make sense to set this flag in
> .get_state().

It is related to the wave form in so far as it allows the driver to
change the wave form as long as the power output remains the same.

> Maybe it makes more sense to put this in a separate argument for a
> variant of pwm_apply_state? something like:
> 
> 	int pwm_apply_state_transition(struct pwm_device *pwm, const struct pwm_state *state, const struct pwm_state_transition *transition);
> 
> and pwm_state_transition can then contain something like this usage
> power concept and maybe also a sync flag that requests that the call
> should only return when the new setting is active and maybe also a
> complete_period flag that requests that the currently running period
> must be completed before the requested setting is implemented.
> 
> OTOH the information "I only care about the relative duty cycle" is
> relevant longer than during the transition to a new setting. (So if
> there are two consumers and one specified to be only interested in the
> relative duty cycle, the other might be allowed to change the common
> period.)

As you said, usage_power does not only apply to one state transition.


> Having said that, I don't like the proposed names. Neither "usage_power"
> nor "pwm_apply_state_transition".
> 
> In a non-representative survey among two hardware engineers and one
> software engineer who already contributed to PWM (!= me) I found out
> that these three have an intuitive right understanding of
> "allow-phase-shift" but have no idea what "usage-power" could mean.

One advantage of usage_power is that it is not limited to phase
shifting. Drivers could do other optimizations as long as the power
output remains the same.


> On a side note: The hardware guys noted that it might make sense to
> align the shifted phases. i.e. instead of shifting channel i by i *
> period/16, it might be better to let the 2nd channel get active when the
> first gets inactive. (i.e. try to keep the count of active channels
> constant).

I am not sure what you mean exactly, because the duty cycles of the
16 outputs are not necessarily the same and can all be active at the
same time. The idea is to spread the edges out as evenly as possible.
Shifting them by period/16 is the best way to smoothen the current
spikes in my opinion and the implementation is also very simple.


> And as already mentioned earlier I still think we should define the
> concept of "usage power" better. It should be clearly defined for a
> driver author which setting they should pick for a given request. This
> removes surprises for consumers and guessing for lowlevel driver
> authors. Also a uniform policy brings conflicts better to light.
> (Something like driver A does the right thing for consumer C and driver
> B makes it right for D. But once D tries to use A things break. (And
> then maybe A is changed to fit D, and C doesn't object because they
> don't read the pwm list resulting in a breakage for C later.))

I added documentation and comments to the header file as a first step
but we can always improve them.

Thanks,
Clemens

  reply	other threads:[~2021-05-07 15:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 13:18 [PATCH 1/4] pwm: core: Support new usage_power setting in PWM state Clemens Gruber
2021-05-07 13:18 ` [PATCH 2/4] pwm: pca9685: " Clemens Gruber
2021-05-07 13:18 ` [PATCH 3/4] pwm: pca9685: Restrict period change for enabled PWMs Clemens Gruber
2021-05-07 13:18 ` [PATCH 4/4] pwm: pca9685: Add error messages for failed regmap calls Clemens Gruber
2021-05-07 15:03 ` [PATCH 1/4] pwm: core: Support new usage_power setting in PWM state Uwe Kleine-König
2021-05-07 15:47   ` Clemens Gruber [this message]
2021-05-07 23:18     ` Uwe Kleine-König
2021-05-31 16:12       ` Clemens Gruber
2021-06-04  9:49         ` Thierry Reding
2021-06-07  6:08           ` Uwe Kleine-König
2021-06-07 14:40             ` Thierry Reding
2021-06-07 18:51               ` Uwe Kleine-König
2021-06-09 20:41                 ` Uwe Kleine-König
2021-06-10 13:11                   ` Thierry Reding
2021-06-21  6:47                     ` PWM-Patches for next merge window [Was: Re: [PATCH 1/4] pwm: core: Support new usage_power setting in PWM] state Uwe Kleine-König
2021-06-25  9:55                       ` PWM-Patches for next merge window Uwe Kleine-König
2021-06-04  9:44 ` [PATCH 1/4] pwm: core: Support new usage_power setting in PWM state Thierry Reding

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=YJVhLrkeNXBp6M1p@workstation.tuxnet \
    --to=clemens.gruber@pqgruber.com \
    --cc=TheSven73@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    --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 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).