All of lore.kernel.org
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>,
	linux-leds@vger.kernel.org
Subject: Re: [PATCH 4/5] leds: leds-pwm: implement PWM inversion
Date: Mon, 7 Apr 2014 12:35:47 +0100	[thread overview]
Message-ID: <20140407113547.GB7528@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20140407111003.GA26985@ulmo>

On Mon, Apr 07, 2014 at 01:10:05PM +0200, Thierry Reding wrote:
> On Mon, Apr 07, 2014 at 10:46:51AM +0200, Alexandre Belloni wrote:
> > (adding Thierry Reding)
> > 
> > Hi,
> > 
> > On 06/04/2014 at 23:20:18 +0100, Russell King wrote :
> > > Some PWM outputs are wired such that the LED they're controlling is
> > > connected to supply rather than ground.  These PWMs may not support
> > > output inversion, or when they do, disabling the PWM may set the
> > > PWM output low, causing a "brightness" value of zero to turn the LED
> > > fully on.
> > > 
> > > The platform data for this driver already indicates that this was
> > > thought about, and we have the "active_low" property there already.
> > > However, the implementation for this is missing.
> > > 
> > > Add the trivial implementation for this feature.
> > > 
> > > Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
> > > ---
> > >  drivers/leds/leds-pwm.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
> > > index e1b4c23a409a..1d47742c551f 100644
> > > --- a/drivers/leds/leds-pwm.c
> > > +++ b/drivers/leds/leds-pwm.c
> > > @@ -70,6 +70,10 @@ static void led_pwm_set(struct led_classdev *led_cdev,
> > >  
> > >  	duty *= brightness;
> > >  	do_div(duty, max);
> > > +
> > > +	if (led_dat->active_low)
> > > +		duty = led_dat->period - duty;
> > > +
> > >  	led_dat->duty = duty;
> > >  
> > 
> > This will conflict with my patch (which is still lacking proper review)
> > there:
> > http://thread.gmane.org/gmane.linux.leds/482
> > 
> > I would say that it is better to hide the polarity inversion in the PWM
> > driver for your specific PWM. Else we will end up with all the drivers
> > using PWMs trying to detect whether the PWM supports inversion and if it
> > is not the case, calculating the inverted duty cycle.
> 
> If the PWM hardware really does support inversion of the polarity, then
> by all means that's what you should be using. However, and I've said
> this a few times already, polarity inversion is not the same as
> reversing the duty-cycle. The *effect* will be the same for LEDs and
> backlights, but the signal is not in fact inverted.

Sorry, for the general case, you're talking rubbish there.  The PWM layer
does not define the starting point in the PWM cycle, so there's no precise
definition of the exact waveform.  Therefore:

Here's a 10% duty cycle:		~_________~_________~_________
Here's another 10% duty cycle:		_________~_________~_________~
which are both equally valid implementations of a 10% PWM.

Here's a 90% duty cycle:		~~~~~~~~~_~~~~~~~~~_~~~~~~~~~_
Here's another 90% duty cycle:		_~~~~~~~~~_~~~~~~~~~_~~~~~~~~~
which are again both equally valid implementations of a 90% PWM.

Here's the first 10% duty cycle,
inverted:				_~~~~~~~~~_~~~~~~~~~_~~~~~~~~~
which is the same as the second example of a 90% PWM signal.

Here's the second 10% duty cycle,
inverted:				~~~~~~~~~_~~~~~~~~~_~~~~~~~~~_
which is the same as the first example of a 90% PWM signal.

Now, if PWM did define the starting point of the wave (which it doesn't,
or if it does, it's not documented which means we probably have loads of
buggy drivers) then yes, there would be some grounds to object.

In any case, we probably already have drivers which implement both
variants of the 10% signal, so really there's no grounds to say "a 90%
duty cycle is not the same as an inverted 10% duty cycle signal".

The electronic engineer in me says you're talking rubbish too, from the
point of view of designing stuff to produce a PWM signal.

So please, justify your statement.

-- 
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.

  reply	other threads:[~2014-04-07 11:36 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-06 22:18 [PATCH 0/5] Fix various issues with leds-pwm Russell King - ARM Linux
2014-04-06 22:20 ` [PATCH 1/5] leds: leds-pwm: properly clean up after probe failure Russell King
2014-04-06 22:20 ` [PATCH 2/5] leds: leds-pwm: provide a common function to setup a single led-pwm device Russell King
2014-04-06 22:20 ` [PATCH 3/5] leds: leds-pwm: convert OF parsing code to use led_pwm_add() Russell King
2014-04-06 22:20 ` [PATCH 4/5] leds: leds-pwm: implement PWM inversion Russell King
2014-04-07  8:46   ` Alexandre Belloni
2014-04-07  8:52     ` Russell King - ARM Linux
2014-04-07  9:28       ` Alexandre Belloni
2014-04-07  9:42         ` Russell King - ARM Linux
2014-04-07 11:10     ` Thierry Reding
2014-04-07 11:35       ` Russell King - ARM Linux [this message]
2014-04-07 12:01         ` Thierry Reding
2014-04-07 12:37           ` Russell King - ARM Linux
2014-04-07 13:37             ` Thierry Reding
2014-04-07 14:20               ` Alexandre Belloni
2014-04-07 15:01                 ` Russell King - ARM Linux
2014-04-06 22:20 ` [PATCH 5/5] leds: leds-pwm: add DT support for LEDs wired to supply Russell King
2014-04-07 21:31 ` [PATCH 0/5] Fix various issues with leds-pwm Bryan Wu
2014-04-07 21:33   ` Russell King - ARM Linux
2014-04-07 21:36     ` Bryan Wu
2014-06-12 17:12       ` Russell King - ARM Linux
2014-06-12 17:37         ` Bryan Wu
2014-06-12 17:56           ` Alexandre Belloni
2014-06-12 18:01             ` Bryan Wu
2014-06-12 18:03           ` Russell King - ARM Linux
2014-06-12 18:16             ` Bryan Wu
2014-06-12 18:21               ` Russell King - ARM Linux

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=20140407113547.GB7528@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=cooloney@gmail.com \
    --cc=linux-leds@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    --cc=thierry.reding@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.