Re: [PATCH v3 2/2] pwm: sprd: Add Spreadtrum PWM support

From: Uwe Kleine-König
Date: Fri Aug 16 2019 - 02:45:22 EST


Hello Baolin,

On Fri, Aug 16, 2019 at 10:44:41AM +0800, Baolin Wang wrote:
> On Thu, 15 Aug 2019 at 20:25, Uwe Kleine-König
> <u.kleine-koenig@xxxxxxxxxxxxxx> wrote:
> >
> > On Thu, Aug 15, 2019 at 07:05:53PM +0800, Baolin Wang wrote:
> > > On Thu, 15 Aug 2019 at 18:11, Uwe Kleine-König
> > > <u.kleine-koenig@xxxxxxxxxxxxxx> wrote:
> > > >
> > > > Hello,
> > > >
> > > > On Thu, Aug 15, 2019 at 05:34:02PM +0800, Baolin Wang wrote:
> > > > > On Thu, 15 Aug 2019 at 16:54, Uwe Kleine-König
> > > > > <u.kleine-koenig@xxxxxxxxxxxxxx> wrote:
> > > > > > On Thu, Aug 15, 2019 at 04:16:32PM +0800, Baolin Wang wrote:
> > > > > > > On Thu, 15 Aug 2019 at 14:15, Uwe Kleine-König
> > > > > > > <u.kleine-koenig@xxxxxxxxxxxxxx> wrote:
> > > > > > > > On Thu, Aug 15, 2019 at 11:34:27AM +0800, Baolin Wang wrote:
> > > > > > > > > On Wed, 14 Aug 2019 at 23:03, Uwe Kleine-König
> > > > > > > > > <u.kleine-koenig@xxxxxxxxxxxxxx> wrote:
> > > > > > > > > > On Wed, Aug 14, 2019 at 08:46:11PM +0800, Baolin Wang wrote:
> > > > > > > > > > > + * To keep the maths simple we're always using MOD = SPRD_PWM_MOD_MAX.
> > > > > > > > > >
> > > > > > > > > > Did you spend some thoughts about how wrong your period can get because
> > > > > > > > > > of that "lazyness"?
> > > > > > > > > >
> > > > > > > > > > Let's assume a clk rate of 100/3 MHz. Then the available period lengths
> > > > > > > > > > are:
> > > > > > > > > >
> > > > > > > > > > PRESCALE = 0 -> period = 7.65 µs
> > > > > > > > > > PRESCALE = 1 -> period = 15.30 µs
> > > > > > > > > > ...
> > > > > > > > > > PRESCALE = 17 -> period = 137.70 µs
> > > > > > > > > > PRESCALE = 18 -> period = 145.35 µs
> > > > > > > > > >
> > > > > > > > > > So the error can be up to (nearly) 7.65 µs (or in general
> > > > > > > > >
> > > > > > > > > Yes, but for our use case (pwm backlight), the precision can meet our
> > > > > > > > > requirement. Moreover, we usually do not change the period, just
> > > > > > > > > adjust the duty to change the back light.
> > > > > > > >
> > > > > > > > Is this a license requirement for you SoC to only drive a backlight with
> > > > > > > > the PWM? The idea of having a PWM driver on your platform is that it can
> > > > > > > > also be used to control a step motor or a laser.
> > > > > > >
> > > > > > > Not a license requirement. Until now we have not got any higher
> > > > > > > precision requirements, and we've run this driver for many years in
> > > > > > > our downstream kernel.
> > > > > >
> > > > > > I understood that you're not ambitious to do something better than "it
> > > > > > worked for years".
> > > > >
> > > > > How do you know that?
> > > >
> > > > I showed you how you could match the requested PWM output better and
> > > > you refused telling it worked for years and the added precision isn't
> > > > necessary for a backlight.
> > >
> > > Please I said the reason, it is not that I do not want a better
> > > precision. The problem is we do not know how much precision to be
> > > asked by users if no use case
> >
> > I don't understand the problem here. If you are asked for period =
> > 145340 ns and configure the hardware to yield 137700 ns in reply to that
> > but you could provide 144780 ns I don't understand why you need a use
> > case as 144780 ns is objectively better than 137700 ns. A better match
>
> You are wrong, we will provide 145350 ns with
> DIV_ROUND_CLOSEST_ULL()., which is better than your 144780.

There are two problems with your statement:

- You're ignoring the fact that I base my argumentation on not using
DIV_ROUND_CLOSEST_ULL because it has downsides I pointed out to you.
If my suggested algorithm targeted a closest match (and not
closest-but-not-bigger) it would pick 145350 ns, too. (I didn't check
if something in the interval [145331, 145349] could be achieved. If
there is, this should of course be preferred.)
I obviously would have to pick a different example request to show
that "targeting nearest with MOD always 255" is for some requests
worse (probably by a similar factor) than "targeting nearest".
It's not surprising that your apple is a better apple than my orange.

- It's not objective that when 145340 ns was requested 145350 ns is
better than 144780 ns. Some approximations are obviously better than
others, but these two are not comparable in a way that all PWM
consumers agree.

I'm not perfect and I do mistakes of course. But I'm still convinced
that my argumentation here is right.

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |