lkml.org 
[lkml]   [2023]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] pwm: mediatek: support inverted polarity
Date
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
\
 
 \ /
  Last update: 2023-03-27 00:43    [W:0.047 / U:0.512 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site