From: Thierry Reding <thierry.reding@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: "linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
"Gavin Schenk" <g.schenk@eckelmann.de>,
"Vokáč Michal" <Michal.Vokac@ysoft.com>,
kernel@pengutronix.de, "Philip, Avinash" <avinashphilip@ti.com>
Subject: Re: RFC: don't let drivers issue pwm_disable after pwm_config(pwm, 0, period)
Date: Mon, 15 Oct 2018 11:28:25 +0200 [thread overview]
Message-ID: <20181015092825.GC12357@ulmo> (raw)
In-Reply-To: <20181015081421.7kx3syv4rnp5vqma@pengutronix.de>
[-- Attachment #1: Type: text/plain, Size: 5118 bytes --]
On Mon, Oct 15, 2018 at 10:14:21AM +0200, Uwe Kleine-König wrote:
> Hello,
>
> adding the author of the commit that introduced the .set_polarity
> callback (0aa0869c3c9b10338dd92a20fa4a9b6959f177b5), maybe he can add
> some value to this discussion.
>
> On Sun, Oct 14, 2018 at 01:34:00PM +0200, Uwe Kleine-König wrote:
> > On Fri, Oct 12, 2018 at 12:11:43PM +0200, Thierry Reding wrote:
> > > On Fri, Oct 12, 2018 at 11:45:57AM +0200, Uwe Kleine-König wrote:
> > > > On Thu, Oct 11, 2018 at 01:15:44PM +0000, Vokáč Michal wrote:
> > > [...]
> > > > > >> Sidenote: With the current capabilities of the pwm framework there is no
> > > > > >> technical reason to expose to the hardware drivers that the pwm user uses
> > > > > >> inverted logic. The framework could just apply
> > > > > >>
> > > > > >> duty = period - duty;
> > > > > >>
> > > > >
> > > > > I prefer to utilize as much HW capabilities as possible. And it seems
> > > > > like most PWM chips support HW output inversion (to some extent) so to
> > > > > me it seems perfectly OK that that information can be propagated from
> > > > > the upper SW levels to the lowest one.
> > > >
> > > > If the hardware capability is useful I fully agree. But if inversion can
> > > > be accomplished by a chip that doesn't support inversion in hardware by
> > > > just using duty = period - duty (and so can be accomplished by a chip
> > > > that has inversion support without making use of it) then the drivers
> > > > shouldn't be confronted with it.
> > >
> > > These two are orthogonal problems. If all you care about is the power
> > > output of the PWM (as is the case for backlights, LEDs or fans, for
> > > example), then inverted polarity has the same effect as duty = period -
> > > duty.
> > >
> > > However, the two don't result in identical waveforms.
> >
> > OK, let's find the difference then. Consider a pwm that is off at start,
> > then it's configured to run at 66% duty cycle at time A and then it's
> > disabled again at time B.
> >
> > The resulting wave form is:
> >
> > ______________ __ __ __ _____________________
> > \_____/ \_____/ \_____/ \_____/
> > A B
> > ^ ^ ^ ^
> >
> > With the ^ markers pointing out where the periods started.
> >
> > Correct?
> >
> > Now with the duty = period - duty trick the wave would look as follows:
> >
> >
> > _________________ __ __ __ __________________
> > \_____/ \_____/ \_____/ \_____/
> > A B
> > ^ ^ ^ ^
> >
> > Apart from a shift I cannot see any difference. I confirm that this
> > might be bad if there are two (or more) PWMs that are expected to run in
> > sync, but given that the current API doesn't provide the possibility to
> > map such a use case this is irrelevant.
> >
> > Another difference I confirm there might be is that this might result in
> > one more (or less) periods depending on timing and the capabilities of
> > the hardware. Is this bad? I'd say it isn't.
> >
> > What am I missing?
>
> The commit log of 0aa0869c3c9b10338dd92a20fa4a9b6959f177b5 mentions:
>
> A practical example where [changing polarity] can prove useful is to
> simulate inversion of the duty cycle. While inversion of polarity
> and duty cycle are not exactly the same, the differences for most
> use-cases are negligible.
>
> This doesn't help me to understand why the polarity stuff is useful
> though. Does this log say that the motivation to support changing
> polarity was to simulate "inversion of the duty cycle"? What exactly is
> "inversion of the duty cycle"? Just
>
> duty_cycle = period - duty_cycle;
>
> ? Why does this have to be simulated, the API was able to do this
> without any simulation before?
>
> Is there a single use-case that can be done with polarity support in the
> API that isn't possible without it? I cannot imagine there is any but
> would like to learn and understand why this is valuable.
See my earlier mail which will hopefully answer these questions.
> Currently there is no user of pwm_set_polarity(), I suggest to remove it
> to not give users an incentive to still rely on the non-atomic API.
Yeah, that's probably a good idea. The long-term plan was always to get
rid of the legacy API, but I haven't gotten around to that yet.
> Also among the users of pwm_apply_state there is none which makes use of
> the polarity setting.
Well, this is primarily because our current users don't care much about
the polarity setting, so they just go with whatever initial setting they
get (usually via pwm_get_args()). These correspond to whatever was
specified in the flags of the PWM specifier in DT or in the lookup table
for non-DT devices (see for example of_pwm_xlate_with_flags()).
There is one user that allows changing the polarity, and that's sysfs.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-10-15 9:28 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-06 15:51 RFC: don't let drivers issue pwm_disable after pwm_config(pwm, 0, period) Uwe Kleine-König
2018-08-09 11:30 ` Thierry Reding
2018-08-09 15:23 ` Uwe Kleine-König
2018-08-20 9:52 ` Uwe Kleine-König
2018-08-20 14:43 ` [PATCH 0/2] specify the pin state after pwm_disable as explicitly undefined Uwe Kleine-König
2018-08-20 14:43 ` [PATCH 1/2] pwm: document the pin state after pwm_disable() to be undefined Uwe Kleine-König
2018-10-09 7:34 ` Thierry Reding
2018-10-09 9:04 ` Uwe Kleine-König
2018-10-16 7:44 ` Boris Brezillon
2018-10-16 9:07 ` Uwe Kleine-König
2018-10-18 8:44 ` Uwe Kleine-König
2018-10-18 14:44 ` Thierry Reding
2018-10-18 20:43 ` Uwe Kleine-König
2018-10-18 15:06 ` Thierry Reding
2018-08-20 14:43 ` [PATCH 2/2] pwm: warn callers of pwm_apply_state() that expect a certain level after disabling Uwe Kleine-König
2018-09-04 20:37 ` RFC: don't let drivers issue pwm_disable after pwm_config(pwm, 0, period) Uwe Kleine-König
2018-09-21 16:02 ` Uwe Kleine-König
2018-09-27 18:26 ` Uwe Kleine-König
2018-09-27 20:29 ` Thierry Reding
2018-10-08 20:02 ` Uwe Kleine-König
2018-10-09 7:53 ` Thierry Reding
2018-10-09 9:35 ` Uwe Kleine-König
2018-10-10 12:26 ` Thierry Reding
2018-10-10 13:50 ` Vokáč Michal
2018-10-11 10:19 ` Uwe Kleine-König
2018-10-11 12:00 ` Thierry Reding
2018-10-11 13:15 ` Vokáč Michal
2018-10-12 9:45 ` Uwe Kleine-König
2018-10-12 10:11 ` Thierry Reding
2018-10-14 11:34 ` Uwe Kleine-König
2018-10-15 8:14 ` Uwe Kleine-König
2018-10-15 8:16 ` Uwe Kleine-König
2018-10-15 9:28 ` Thierry Reding [this message]
2018-10-15 9:22 ` Thierry Reding
2018-10-15 12:33 ` Uwe Kleine-König
2018-10-12 12:25 ` Vokáč Michal
2018-10-12 15:47 ` Uwe Kleine-König
2018-10-11 20:34 ` Uwe Kleine-König
2018-10-12 9:53 ` Thierry Reding
2018-10-12 10:00 ` Thierry Reding
2018-10-12 17:14 ` Uwe Kleine-König
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=20181015092825.GC12357@ulmo \
--to=thierry.reding@gmail.com \
--cc=Michal.Vokac@ysoft.com \
--cc=avinashphilip@ti.com \
--cc=g.schenk@eckelmann.de \
--cc=kernel@pengutronix.de \
--cc=linux-pwm@vger.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 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).