From: Thierry Reding <thierry.reding@gmail.com>
To: Lorenz Brun <lorenz@brun.one>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH v2] pwm: mediatek: support inverted polarity
Date: Thu, 6 Apr 2023 15:38:48 +0200 [thread overview]
Message-ID: <ZC7LaC19YjNwTIi1@orome> (raw)
In-Reply-To: <20230309010410.2106525-1-lorenz@brun.one>
[-- Attachment #1: Type: text/plain, Size: 2503 bytes --]
On Thu, Mar 09, 2023 at 02:04:10AM +0100, Lorenz Brun wrote:
> According to the MT7986 Reference Manual the Mediatek PWM controller
> doesn't appear to have support for inverted polarity.
>
> To still support inverted PWM for common use cases, this relaxes the
> check for inverted polarity within the driver to allow it to work in
> case usage_power is set to true, i.e. the exact waveform does not
> matter. If usage_power is true and the polarity is inverted the duty
> cycle is mathematically inverted before being applied to the hardware.
>
> Signed-off-by: Lorenz Brun <lorenz@brun.one>
> ---
> V2: Only allow mathematically inverted PWM if usage_power is true
> ---
> drivers/pwm/pwm-mediatek.c | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
> index 5b5eeaff35da..18791304d1ca 100644
> --- a/drivers/pwm/pwm-mediatek.c
> +++ b/drivers/pwm/pwm-mediatek.c
> @@ -202,8 +202,16 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> const struct pwm_state *state)
> {
> int err;
> -
> - if (state->polarity != PWM_POLARITY_NORMAL)
> + u64 duty_cycle;
> +
> + /* According to the MT7986 Reference Manual the peripheral does not
Block comments should have no text on the first line:
/*
* According
* ...
*/
> + * appear to have the capability to invert the output.
> + * This means that inverted mode can not be fully supported as the
> + * waveform will always start with the low period and end with the high
> + * period. Thus reject non-normal polarity if the shape of the waveform
> + * matters, i.e. usage_power is not set.
> + */
> + if (state->polarity != PWM_POLARITY_NORMAL && !state->usage_power)
> return -EINVAL;
>
> if (!state->enabled) {
> @@ -213,7 +221,11 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> return 0;
> }
>
> - err = pwm_mediatek_config(pwm->chip, pwm, state->duty_cycle, state->period);
> + duty_cycle = state->duty_cycle;
> + if (state->polarity == PWM_POLARITY_INVERSED)
> + duty_cycle = state->period - state->duty_cycle;
That's not really what state->usage_power was meant to address. What's
wrong with just reversing the duty cycle in the pwm-fan? If you use DT
it's quite trivial to do that by just reversing the entries in your
cooling-levels property. Does that not work for you?
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-04-06 13:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 1:04 [PATCH v2] pwm: mediatek: support inverted polarity Lorenz Brun
2023-04-06 13:38 ` Thierry Reding [this message]
2023-04-06 13:53 ` Uwe Kleine-König
2023-04-06 14:30 ` Thierry Reding
2023-04-14 5:39 ` 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=ZC7LaC19YjNwTIi1@orome \
--to=thierry.reding@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pwm@vger.kernel.org \
--cc=lorenz@brun.one \
--cc=matthias.bgg@gmail.com \
--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