From: Lorenz Brun <lorenz@brun.one>
To: "Thierry Reding" <thierry.reding@gmail.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>
Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: [PATCH] pwm: mediatek: support inverted polarity
Date: Fri, 3 Mar 2023 21:58:21 +0100 [thread overview]
Message-ID: <20230303205821.2285418-1-lorenz@brun.one> (raw)
According to the MT7986 Reference Manual the Mediatek PWM controller
doesn't appear to have support for inverted polarity.
This implements the same solution as in pwm-meson and just inverts the
duty cycle instead, which results in the same outcome.
Signed-off-by: Lorenz Brun <lorenz@brun.one>
---
drivers/pwm/pwm-mediatek.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
index 5b5eeaff35da..6f4a54c8299f 100644
--- a/drivers/pwm/pwm-mediatek.c
+++ b/drivers/pwm/pwm-mediatek.c
@@ -202,9 +202,7 @@ 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)
- return -EINVAL;
+ u64 duty_cycle;
if (!state->enabled) {
if (pwm->state.enabled)
@@ -213,7 +211,14 @@ 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);
+ // According to the MT7986 Reference Manual the peripheral does not
+ // appear to have the capability to invert the output. Instead just
+ // invert the duty cycle.
+ duty_cycle = state->duty_cycle;
+ if (state->polarity == PWM_POLARITY_INVERSED)
+ duty_cycle = state->period - state->duty_cycle;
+
+ err = pwm_mediatek_config(pwm->chip, pwm, duty_cycle, state->period);
if (err)
return err;
--
2.39.1
next reply other threads:[~2023-03-03 20:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-03 20:58 Lorenz Brun [this message]
2023-03-03 21:17 ` Uwe Kleine-König
2023-03-03 22:23 ` Lorenz Brun
2023-03-04 10:18 ` 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=20230303205821.2285418-1-lorenz@brun.one \
--to=lorenz@brun.one \
--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=matthias.bgg@gmail.com \
--cc=thierry.reding@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
all inboxes | Powered by JetHome®