From: "Uwe Kleine-König" <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
Cc: linux-pwm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Maxime Ripard
<maxime.ripard-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>,
Patrick Havelange
<patrick.havelange-buIOx9BAs4sybS5Ee8rs3A@public.gmane.org>,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org>,
Thierry Reding
<thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org
Subject: Re: [PATCH v3 2/6] pwm: let pwm_get_state() return the last implemented state
Date: Mon, 2 Sep 2019 16:32:31 +0200 [thread overview]
Message-ID: <20190902143231.k2ugpv2oemceaequ@pengutronix.de> (raw)
In-Reply-To: <5802279.ETANMDGNFP@phil>
On Fri, Aug 30, 2019 at 07:48:35PM +0200, Heiko Stuebner wrote:
> Am Samstag, 24. August 2019, 17:37:03 CEST schrieb Uwe Kleine-König:
> > When pwm_apply_state() is called the lowlevel driver usually has to
> > apply some rounding because the hardware doesn't support nanosecond
> > resolution. So let pwm_get_state() return the actually implemented state
> > instead of the last applied one if possible.
> >
> > Signed-off-by: Uwe Kleine-König <uwe-rXY34ruvC2xidJT2blvkqNi2O/JbrIOy@public.gmane.org>
>
> With this applied, the display brightness on my rk3399-gru-scarlet gets
> inverted. Now it's very bright on level 1 and very dim on the max level.
>
> According to the debugfs, the inverted state changes:
>
> OLD STATE:
> ----------
> root@localhost:~# cat /debug/pwm
> platform/ff420030.pwm, 1 PWM device
> pwm-0 (ppvar-bigcpu-pwm ): requested enabled period: 3334 ns duty: 331 ns polarity: normal
>
> platform/ff420020.pwm, 1 PWM device
> pwm-0 (ppvar-litcpu-pwm ): requested enabled period: 3334 ns duty: 414 ns polarity: normal
>
> platform/ff420010.pwm, 1 PWM device
> pwm-0 (backlight ): requested enabled period: 999996 ns duty: 941148 ns polarity: normal
>
> platform/ff420000.pwm, 1 PWM device
> pwm-0 (ppvar-gpu-pwm ): requested enabled period: 3334 ns duty: 3334 ns polarity: normal
>
> NEW STATE:
> ----------
> root@localhost:~# cat /debug/pwm
> platform/ff420030.pwm, 1 PWM device
> pwm-0 (ppvar-bigcpu-pwm ): requested enabled period: 3334 ns duty: 331 ns polarity: normal
>
> platform/ff420020.pwm, 1 PWM device
> pwm-0 (ppvar-litcpu-pwm ): requested enabled period: 3334 ns duty: 414 ns polarity: normal
>
> platform/ff420010.pwm, 1 PWM device
> pwm-0 (backlight ): requested enabled period: 999996 ns duty: 941148 ns polarity: inverse
>
> platform/ff420000.pwm, 1 PWM device
> pwm-0 (ppvar-gpu-pwm ): requested enabled period: 3334 ns duty: 3334 ns polarity: normal
>
>
> And the reason is below.
>
> > ---
> > drivers/pwm/core.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> > index 72347ca4a647..92333b89bf02 100644
> > --- a/drivers/pwm/core.c
> > +++ b/drivers/pwm/core.c
> > @@ -473,7 +473,14 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
> > if (err)
> > return err;
> >
> > - pwm->state = *state;
> > + /*
> > + * .apply might have to round some values in *state, if possible
> > + * read the actually implemented value back.
> > + */
> > + if (chip->ops->get_state)
> > + chip->ops->get_state(chip, pwm, &pwm->state);
> > + else
> > + pwm->state = *state;
>
> This should probably become
> >- pwm->state = *state;
> > +
> > + /*
> > + * .apply might have to round some values in *state, if possible
> > + * read the actually implemented value back.
> > + */
> > + if (chip->ops->get_state)
> > + chip->ops->get_state(chip, pwm, &pwm->state);
>
> so always initialize the state to the provided one and then let the driver
> override values?
This feels wrong. There is another thread that adds a developer knob
that emits some warnings. Catching this kind of error with it would be a
good idea IMHO.
> The inversion case stems from the Rockchip pwm driver (wrongly?) only
> setting the polarity field when actually inverted, so here the polarity field
> probably never actually got set at all.
>
> But while we should probably fix the rockchip driver to set polarity all the
> time, this is still being true for possible future state-fields, which also
> wouldn't get initialzed from all drivers, which might need an adaption
> first?
Actually I would prefer that all drivers do it right and rely on this.
Thanks for testing
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
next prev parent reply other threads:[~2019-09-02 14:32 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-24 15:37 [PATCH v3 0/6] pwm: ensure pwm_apply_state() doesn't modify the state argument Uwe Kleine-König
[not found] ` <20190824153707.13746-1-uwe-rXY34ruvC2xidJT2blvkqNi2O/JbrIOy@public.gmane.org>
2019-08-24 15:37 ` [PATCH v3 1/6] pwm: introduce local struct pwm_chip in pwm_apply_state() Uwe Kleine-König
2019-08-24 15:37 ` [PATCH v3 2/6] pwm: let pwm_get_state() return the last implemented state Uwe Kleine-König
[not found] ` <20190824153707.13746-3-uwe-rXY34ruvC2xidJT2blvkqNi2O/JbrIOy@public.gmane.org>
2019-08-30 17:48 ` Heiko Stuebner
2019-09-02 14:32 ` Uwe Kleine-König [this message]
[not found] ` <20190902143231.k2ugpv2oemceaequ-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2019-09-02 20:20 ` Uwe Kleine-König
2019-08-24 15:37 ` [PATCH v3 3/6] pwm: rockchip: Don't update the state for the caller of pwm_apply_state() Uwe Kleine-König
2019-08-24 15:37 ` [PATCH v3 4/6] pwm: sun4i: " Uwe Kleine-König
2019-08-24 15:37 ` [PATCH v3 5/6] pwm: fsl-ftm: " Uwe Kleine-König
[not found] ` <20190824153707.13746-6-uwe-rXY34ruvC2xidJT2blvkqNi2O/JbrIOy@public.gmane.org>
2019-08-30 17:39 ` Doug Anderson
[not found] ` <CAD=FV=X8kVU_zr69aKe-+GkAQh-tDwVf8tFogKve3s5O5ndF-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-02 14:27 ` Uwe Kleine-König
[not found] ` <20190902142709.wxrjsfzorozgeiuh-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2019-09-03 16:54 ` Doug Anderson
[not found] ` <CAD=FV=XFTuixKL-VBv-QObiO=Jg43i6W0enprLgXQ0U8=9C49A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-03 18:48 ` Uwe Kleine-König
[not found] ` <20190903184800.2fmmvwyzbwbsaf6y-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2019-09-03 19:35 ` Doug Anderson
[not found] ` <CAD=FV=XOyayzv6N9Ky8m2ffXe4UzUijzrL8JCMZC3K+MEzaRFw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-03 20:15 ` Uwe Kleine-König
[not found] ` <20190903201550.gxcyed5svtq33ev2-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2019-09-03 20:50 ` Doug Anderson
[not found] ` <CAD=FV=WjRiaNLJQJ25OeNSpY455H-ev8g3iZN24UXQtk3uXhtA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-03 21:07 ` Uwe Kleine-König
[not found] ` <20190903210740.qgyvxxmsdg5dzaby-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2019-09-03 21:48 ` Doug Anderson
[not found] ` <CAD=FV=VDj8pCmkBd70buQNVmiv56OUEVWfRJALYgtZcESvPXdw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-04 8:21 ` Uwe Kleine-König
2019-08-24 15:37 ` [PATCH v3 6/6] pwm: ensure pwm_apply_state() doesn't modify the state argument Uwe Kleine-König
2019-09-02 20:19 ` [PATCH v3 0/6] " 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=20190902143231.k2ugpv2oemceaequ@pengutronix.de \
--to=u.kleine-koenig-bicnvbalz9megne8c9+irq@public.gmane.org \
--cc=heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org \
--cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=linux-pwm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=maxime.ripard-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org \
--cc=patrick.havelange-buIOx9BAs4sybS5Ee8rs3A@public.gmane.org \
--cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=wens-jdAy2FN1RRM@public.gmane.org \
/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