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@xxxxxxxxxxxxxxxx> > > --- > > 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. There were at my latest count exactly two drivers who used PWM devices, so the extent is somewhat limited. But if you're concerned about code duplication, then perhaps a helper can be created that checks whether or not a PWM channel's signal can be inverted and otherwise reverses the duty-cycle. That can then be used for the special case where only the effect of the PWM signal matters rather than the signal's inversion. Thierry
Attachment:
pgp07U7PWEndN.pgp
Description: PGP signature