Skip to content

Commit

Permalink
pwm: meson: modify and simplify calculation in meson_pwm_get_state
Browse files Browse the repository at this point in the history
I don't see a reason why we should treat the case lo < hi differently
and return 0 as period and duty_cycle. The current logic was added with
c375bcb ("pwm: meson: Read the full hardware state in
meson_pwm_get_state()"), Martin as original author doesn't remember why
it was implemented this way back then.
So let's handle it as normal use case and also remove the optimization
for lo == 0. I think the improved readability is worth it.

Fixes: c375bcb ("pwm: meson: Read the full hardware state in meson_pwm_get_state()")
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
Acked-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Heiner Kallweit authored and Thierry Reding committed Jun 23, 2023
1 parent 5442c33 commit 6b9352f
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions drivers/pwm/pwm-meson.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,8 @@ static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
channel->lo = FIELD_GET(PWM_LOW_MASK, value);
channel->hi = FIELD_GET(PWM_HIGH_MASK, value);

if (channel->lo == 0) {
state->period = meson_pwm_cnt_to_ns(chip, pwm, channel->hi);
state->duty_cycle = state->period;
} else if (channel->lo >= channel->hi) {
state->period = meson_pwm_cnt_to_ns(chip, pwm,
channel->lo + channel->hi);
state->duty_cycle = meson_pwm_cnt_to_ns(chip, pwm,
channel->hi);
} else {
state->period = 0;
state->duty_cycle = 0;
}
state->period = meson_pwm_cnt_to_ns(chip, pwm, channel->lo + channel->hi);
state->duty_cycle = meson_pwm_cnt_to_ns(chip, pwm, channel->hi);

state->polarity = PWM_POLARITY_NORMAL;

Expand Down

0 comments on commit 6b9352f

Please sign in to comment.