Thread (60 messages) 60 messages, 6 authors, 2018-11-26

Re: [RCF PATCH,v2,2/2] pwm: imx: Configure output to GPIO in disabled state

From: Thierry Reding <hidden>
Date: 2018-11-14 11:34:57
Also in: linux-pwm, lkml

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:
quoted
On 8.11.2018 20:18, Uwe Kleine-König wrote:
quoted
On Thu, Nov 08, 2018 at 03:21:44PM +0000, Vokáč Michal wrote:
quoted
Hi Uwe,

On 7.11.2018 16:01, Uwe Kleine-König wrote:
quoted
quoted
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 :(
quoted
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.
quoted
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.
quoted
  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.
quoted
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.
quoted
quoted
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

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help