All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>,
	linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	kernel@pengutronix.de, Shawn Guo <shawn.guo@linaro.org>,
	Matt Sealey <matt@genesi-usa.com>
Subject: Re: [PATCH 2/3] leds/pwm: Don't disable pwm when setting brightness to 0
Date: Wed, 11 Dec 2013 16:30:51 +0100	[thread overview]
Message-ID: <20131211153050.GE31617@ulmo.nvidia.com> (raw)
In-Reply-To: <20131205212641.GC4707@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 2380 bytes --]

On Thu, Dec 05, 2013 at 10:26:41PM +0100, Uwe Kleine-König wrote:
> Hello Thierry,
> 
> On Mon, Dec 02, 2013 at 02:18:07PM +0100, Uwe Kleine-König wrote:
> > On Mon, Dec 02, 2013 at 01:33:19PM +0100, Thierry Reding wrote:
> > > On Mon, Nov 25, 2013 at 09:43:44PM +0100, Uwe Kleine-König wrote:
> > > > This fixes disabling the LED on i.MX28. The PWM hardware delays using
> > > > the newly set pwm-config until the beginning of a new period. It's very
> > > > likely that pwm_disable is called before the current period ends. In
> > > > case the LED was on brightness=max before the LED stays on because in
> > > > the disabled PWM block the period never ends.
> > > > 
> > > > Also only call pwm_enable only once in the probe call back and the
> > > > matching pwm_disable in .remove(). Moreover the pwm is explicitly
> > > > initialized to off.
> > > 
> > > While I do understand the reasoning behind this, if this is really the
> > > behaviour that we need then there's no use in having pwm_enable() and
> > > pwm_disable() at all. They can just be folded into pwm_get() and
> > > pwm_put(), respectively.
> > So after the first pwm_get the pwm starts with an unspecified duty
> > cycle? That's not that nice, is it?
> How can we come forward here? After all it's a real bug being fixed.

I've thought about this some more, and this isn't actually fixing a bug.
Rather it's working around some quirk of the hardware in your setup. So
in the long run I think the best option would have to be to define the
behaviour of the PWM subsystem, and then make sure in drivers that they
behave accordingly. So if we define, or rather keep with the existing
implied behaviour, that the configuration is active when pwm_config()
returns, we can easily write generic client drivers because it means
they can rely on said behaviour. If a driver doesn't behave accordingly
it needs to be fixed.

If that means that a particular PWM controller applies the configuration
only after the current period has expired, then that's something only
the driver can now and therefore the driver should handle this by only
returning from pwm_config() when that's actually happened.

That seems to me the only reasonable approach. Otherwise we'll have to
keep changing API whenever some new controller comes around that behaves
slightly differently.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: thierry.reding@gmail.com (Thierry Reding)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3] leds/pwm: Don't disable pwm when setting brightness to 0
Date: Wed, 11 Dec 2013 16:30:51 +0100	[thread overview]
Message-ID: <20131211153050.GE31617@ulmo.nvidia.com> (raw)
In-Reply-To: <20131205212641.GC4707@pengutronix.de>

On Thu, Dec 05, 2013 at 10:26:41PM +0100, Uwe Kleine-K?nig wrote:
> Hello Thierry,
> 
> On Mon, Dec 02, 2013 at 02:18:07PM +0100, Uwe Kleine-K?nig wrote:
> > On Mon, Dec 02, 2013 at 01:33:19PM +0100, Thierry Reding wrote:
> > > On Mon, Nov 25, 2013 at 09:43:44PM +0100, Uwe Kleine-K?nig wrote:
> > > > This fixes disabling the LED on i.MX28. The PWM hardware delays using
> > > > the newly set pwm-config until the beginning of a new period. It's very
> > > > likely that pwm_disable is called before the current period ends. In
> > > > case the LED was on brightness=max before the LED stays on because in
> > > > the disabled PWM block the period never ends.
> > > > 
> > > > Also only call pwm_enable only once in the probe call back and the
> > > > matching pwm_disable in .remove(). Moreover the pwm is explicitly
> > > > initialized to off.
> > > 
> > > While I do understand the reasoning behind this, if this is really the
> > > behaviour that we need then there's no use in having pwm_enable() and
> > > pwm_disable() at all. They can just be folded into pwm_get() and
> > > pwm_put(), respectively.
> > So after the first pwm_get the pwm starts with an unspecified duty
> > cycle? That's not that nice, is it?
> How can we come forward here? After all it's a real bug being fixed.

I've thought about this some more, and this isn't actually fixing a bug.
Rather it's working around some quirk of the hardware in your setup. So
in the long run I think the best option would have to be to define the
behaviour of the PWM subsystem, and then make sure in drivers that they
behave accordingly. So if we define, or rather keep with the existing
implied behaviour, that the configuration is active when pwm_config()
returns, we can easily write generic client drivers because it means
they can rely on said behaviour. If a driver doesn't behave accordingly
it needs to be fixed.

If that means that a particular PWM controller applies the configuration
only after the current period has expired, then that's something only
the driver can now and therefore the driver should handle this by only
returning from pwm_config() when that's actually happened.

That seems to me the only reasonable approach. Otherwise we'll have to
keep changing API whenever some new controller comes around that behaves
slightly differently.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131211/c365de3c/attachment.sig>

  reply	other threads:[~2013-12-11 15:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-25 20:43 [PATCH 0/3] leds/pwm: don't call pwm_disable when setting brightness Uwe Kleine-König
2013-11-25 20:43 ` Uwe Kleine-König
2013-11-25 20:43 ` [PATCH 1/3] pwm/doc: Clearify that the pin state after pwm_disable is undefined Uwe Kleine-König
2013-11-25 20:43   ` Uwe Kleine-König
2013-11-25 20:43 ` [PATCH 2/3] leds/pwm: Don't disable pwm when setting brightness to 0 Uwe Kleine-König
2013-11-25 20:43   ` Uwe Kleine-König
2013-12-02 12:33   ` Thierry Reding
2013-12-02 12:33     ` Thierry Reding
2013-12-02 13:18     ` Uwe Kleine-König
2013-12-02 13:18       ` Uwe Kleine-König
2013-12-05 21:26       ` Uwe Kleine-König
2013-12-05 21:26         ` Uwe Kleine-König
2013-12-11 15:30         ` Thierry Reding [this message]
2013-12-11 15:30           ` Thierry Reding
2013-12-12 21:10           ` Uwe Kleine-König
2013-12-12 21:10             ` Uwe Kleine-König
2013-11-25 20:43 ` [PATCH 3/3] leds/pwm: fix driver description and make license match the header Uwe Kleine-König
2013-11-25 20:43   ` Uwe Kleine-König
2015-11-19 19:17   ` Uwe Kleine-König
2015-11-19 19:17     ` Uwe Kleine-König
2015-11-20  9:36     ` Jacek Anaszewski
2015-11-20  9:36       ` Jacek Anaszewski
2014-02-21 14:15 ` [PATCH 0/3] leds/pwm: don't call pwm_disable when setting brightness Uwe Kleine-König
2014-02-21 14:15   ` 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=20131211153050.GE31617@ulmo.nvidia.com \
    --to=thierry.reding@gmail.com \
    --cc=cooloney@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=matt@genesi-usa.com \
    --cc=rpurdie@rpsys.net \
    --cc=shawn.guo@linaro.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 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.