devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: "Vokáč Michal" <Michal.Vokac@ysoft.com>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
	"Lukasz Majewski" <l.majewski@majess.pl>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	"kernel@pengutronix.de" <kernel@pengutronix.de>,
	"Fabio Estevam" <fabio.estevam@nxp.com>,
	"Lothar Waßmann" <LW@karo-electronics.de>
Subject: Re: [RCF PATCH,v2,2/2] pwm: imx: Configure output to GPIO in disabled state
Date: Wed, 14 Nov 2018 12:34:49 +0100	[thread overview]
Message-ID: <20181114113449.GB2620@ulmo> (raw)
In-Reply-To: <20181109165555.vqbiwh4hlcnozdna@pengutronix.de>

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

On Fri, Nov 09, 2018 at 05:55:55PM +0100, Uwe Kleine-König wrote:
> On Fri, Nov 09, 2018 at 02:24:42PM +0000, Vokáč Michal wrote:
> > On 8.11.2018 20:18, Uwe Kleine-König wrote:
> > > On Thu, Nov 08, 2018 at 03:21:44PM +0000, Vokáč Michal wrote:
> > >> Hi Uwe,
> > >>
> > >> On 7.11.2018 16:01, Uwe Kleine-König wrote:
> > >>>> Interesting idea. I just wonder why nobody else did not come up with such
> > >>>> a simple solution before.
> > >>>
> > >>> I think I mentioned it already in this thread, but it went unnoticed :-)
> > >>
> > >> I meant it like "How happened this was not invented years ago, when people
> > >> first noticed the issue with using inverted PWM for backlight on i.MX6."
> > >> In our project, this issue dates back to 2015 :(
> > >>
> > >>> Then the patch isn't correct yet. The idea is always keep the hardware
> > >>> running and only disable it if it's uninverted.
> > >>
> > >> OK, I got the point.
> > >>
> > >>> In imx_pwm_probe it's not yet known what the polarity is supposed to be,
> > >>> right?
> > >>
> > >> Not really. It can already be known but currently there is no way how to
> > >> pass the information to the probe function. I, as a creator of the device
> > >> (and author of a DTS file) know that the circuit needs inverted PWM signal.
> > >> And I know that the circuit needs to be disabled until I say it can be
> > >> enabled. How I say that can warry. It may be default brightness level > 0
> > >> in DTS file or from a userspace program using PWM sysfs interface.
> > >>
> > >>>   So the right thing to do there is to not touch the configuration
> > >>> of the pwm. I think all states that are problematic then are also
> > >>> problematic with the gpio/pinmux approach.
> > >>
> > >> I think my use-case I already presented before is an example where
> > >> involving pinctrl solves the problem while the "leave PWM enabled
> > >> for inverted users" does not. That is all the time between
> > >> imx_pwm_probe() and imx_pwm_apply_v2().
> > > 
> > > You're doing in probe:
> > > 
> > >    if (pwm_is_running()):
> > >      mux(pin, function=pwm)
> > >    else:
> > >      gpio_set_value(gpio, 0)
> > >      mux(pin, function=gpio)
> > > 
> > > This gives you the right level assuming the gpio specification uses the
> > > right flag (GPIO_ACTIVE_HIGH or GPIO_ACTIVE_LOW).
> > 
> > Agree.
> > 
> > > Taking your example with the backlight device you specify an "init" and
> > > a "default" pinctrl and only "default" contains the muxing for the PWM
> > > pin everything should be as smooth as necessary: The pwm is only muxed
> > > when the backlight device is successfully bound.
> > 
> > Have you tried that Uwe? The bad news is I tested that before and now
> > again and it does not work like that. We already discussed that earlier.
> 
> The key is that the pinmux setting for the PWM pin should be part of the
> bl pinctrl, not the pwm pinctrl. Then "default" is only setup when the
> bl device is successfully bound which is after the bl's .probe callback
> called pwm_apply().

No, that's not at all correct. Pinmux settings should reside with the
consumer of the pin. In this case, the PWM is the consumer of the pin,
whereas the backlight is the consumer of the *PWM*.

The problem with making the PWM mode the "default" pinctrl state is that
the default state will be applied before the driver is even probed. That
makes it unsuitable for this case. I think what we really want here is
explicitly "active" and "inactive" states for pinctrl where the PWM
driver controls when exactly each state is applied.

This solves the problem quite nicely because by default the pinctrl
state isn't touched. For the case where the bootloader didn't initialize
the PWM pin at all, the driver core won't do anything and keep it at the
100k pull-up default. Only when the PWM is actually taken into active
use will the "active" state (i.e. PWM mode) be applied, so that the PWM
can drive it with the right configuration to give the desired result. If
the bootloader did initialize the PWM it would also work because then at
PWM driver probe time we don't do anything either, keeping the pin in
the PWM mode as configured by the bootloader and not touching the PWM
configuration either. If hardware readout is implemented, we can load
the exact state that we're in and seamlessly take over in the kernel
driver. Enabling the PWM in this case would apply the current setting,
which should be a no-op, or at least idempotent.

> > > No I meant the pwm. Well, it's as easy as that: Whenever with your
> > > approach you configure the pin as GPIO with the output set to low,
> > > instead configure the pwm with duty_cycle to zero (or disable it).
> > > Whenever with your approach you configure the pin as GPIO with the
> > > output set to high, configure the pwm with duty_cycle to 100%. (Keeping
> > > out inverted PWMs for the ease of discussion, but the procedure can be
> > > adapted accordingly.) The only difference then is that with your
> > > approach you already "know" in pwm-imx's .probe the idle level and can
> > > configure the GPIO accordingly. With my approach you just have to wait
> > > until the first pwm_apply which (as described above) works just as well.
> > 
> > While here I am quite confident you are talking about kernel code, right?
> > If yes, then your approach is clear to me.
> > 
> > The problem is I am quite sure your approach does not solve the cases
> > the pinctrl solution does. And according to my tests so far it does not
> > work at all because the "init" and "default" states does not work as you
> > are saying.
> 
> That's as pointed out above, because you're looking at the pwm's pinctrl
> and I at the pwm-consumer's pinctrl.
> 
> Note that a sysfs consumer cannot be operated smoothly here, because
> there is no pinctrl node to add the PWM mode to that only gets active
> after the first configuration. This however is something that should not
> be addressed in the imx driver but in the pwm core (if at all).

With the pinctrl-based solution outlined above you can even operate a
sysfs consumer properly. The pinctrl states are where they belong, with
the PWM device and therefore they can be properly set when the PWM is
used, rather than waiting for a PWM consumer to muck with the pinmux.

Note how all the pieces are suddenly falling into place. In my
experience that's usually a good indication that you're on the right
track.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2018-11-14 11:34 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10  9:33 [RCF PATCH v2 0/2] pwm: imx: Configure output to GPIO in disabled state Vokáč Michal
2018-10-10  9:33 ` [RCF PATCH v2 1/2] dt-bindings: pwm: imx: Allow switching PWM output between PWM and GPIO Vokáč Michal
2018-10-10 13:39   ` Thierry Reding
2018-10-29 15:52     ` Vokáč Michal
2018-10-10  9:33 ` [RCF PATCH v2 2/2] pwm: imx: Configure output to GPIO in disabled state Vokáč Michal
2018-10-12  8:57   ` [RCF PATCH,v2,2/2] " Uwe Kleine-König
2018-10-12 15:04     ` Vokáč Michal
2018-10-12 15:54       ` Thierry Reding
2018-10-12 16:08       ` Uwe Kleine-König
2018-10-14 20:24         ` Uwe Kleine-König
2018-10-15  8:45           ` Thierry Reding
2018-10-29 15:55             ` Vokáč Michal
2018-10-29 15:54         ` Vokáč Michal
2018-11-07  9:33           ` Uwe Kleine-König
2018-11-07 13:32             ` Vokáč Michal
2018-11-07 15:01               ` Uwe Kleine-König
2018-11-08 15:21                 ` Vokáč Michal
2018-11-08 19:18                   ` Uwe Kleine-König
2018-11-09 14:24                     ` Vokáč Michal
2018-11-09 16:55                       ` Uwe Kleine-König
2018-11-14  9:09                         ` Uwe Kleine-König
2018-11-14 11:34                         ` Thierry Reding [this message]
2018-11-14 21:51                           ` Uwe Kleine-König
2018-11-15 15:25                             ` Thierry Reding
2018-11-15 20:37                               ` Uwe Kleine-König
2018-11-16  7:34                                 ` Lothar Waßmann
2018-11-16  8:25                                   ` Uwe Kleine-König
2018-11-22 15:42                                     ` Vokáč Michal
2018-11-22 16:23                                       ` Uwe Kleine-König
2018-11-22 16:46                                         ` Vokáč Michal
2018-11-22 19:03                                           ` Uwe Kleine-König
2018-11-23 15:15                                             ` Vokáč Michal
2018-11-25 20:56                                               ` Uwe Kleine-König
2018-11-26  9:11                                                 ` Lothar Waßmann
2018-11-26  9:18                                                   ` Uwe Kleine-König
2018-11-26 10:03                                                     ` Lothar Waßmann
2018-11-26 11:51                                               ` Thierry Reding
2018-11-26 12:23                                                 ` Lothar Waßmann
2018-11-26 13:34                                                   ` Thierry Reding
2018-11-26 15:50                                                     ` Vokáč Michal
2018-11-16  9:51                                 ` Thierry Reding
2018-11-16 10:39                                   ` Uwe Kleine-König
2018-11-16 11:56                                     ` Lothar Waßmann
2018-11-18 11:30                                       ` Uwe Kleine-König
2018-11-16 12:24                                     ` Thierry Reding
2018-11-18 20:08                                       ` Uwe Kleine-König
2018-11-19  8:48                                         ` Uwe Kleine-König
2018-11-22 15:03                                         ` Thierry Reding
2018-11-22 16:17                                           ` Uwe Kleine-König
2018-11-20 13:14                                   ` Vokáč Michal
2018-11-20 16:54                                     ` Uwe Kleine-König
2018-11-22 14:23                                       ` Vokáč Michal
2018-11-19  7:44                             ` Linus Walleij
2018-11-19  8:32                               ` Uwe Kleine-König
2018-11-20  8:35                                 ` Linus Walleij
2018-11-20  9:16                                   ` Viresh Kumar
2018-11-20  9:53                                   ` Uwe Kleine-König
2018-11-14 11:14                   ` Thierry Reding
2018-10-12 16:00   ` [RCF PATCH v2 2/2] " Thierry Reding
2018-10-29 15:53     ` Vokáč Michal

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=20181114113449.GB2620@ulmo \
    --to=thierry.reding@gmail.com \
    --cc=LW@karo-electronics.de \
    --cc=Michal.Vokac@ysoft.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fabio.estevam@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=l.majewski@majess.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@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).