Skip to contentSkip to conversation

pwm: meson: modify and simplify calculation in meson_pwm_get_state

PATCH In review Heiner Kallweit 3 participants 3 messages May 2, 2023 – May 11, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 pwm: meson: modify and simplify calculation in meson_pwm_get_state

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 c375bcbaabdb ("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 c375bcbaabdb ("pwm: meson: Read the full hardware state in meson_pwm_get_state()")

---
v2:
- improve commit description
v3:
- make patch a fix

---
 drivers/pwm/pwm-meson.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/pwm/pwm-meson.c +2 -12
index 5732300eb..3865538dd 100644
@@ -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;
 
Signature · 1 line
2.40.0
reviewer Acked-by on v3 1/1
#1 lore raw
Quoted 9 lines · Heiner Kallweit

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 c375bcbaabdb ("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.

Quoted 4 lines
Fixes c375bcbaabdb ("pwm: meson: Read the full hardware state in meson_pwm_get_state()")

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

Reviewed-by on v3 1/1
#2 lore raw
In reply to Heiner Kallweit
Quoted 48 lines · Heiner Kallweit

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 c375bcbaabdb ("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 c375bcbaabdb ("pwm: meson: Read the full hardware state in meson_pwm_get_state()")

---
v2:
- improve commit description
v3:
- make patch a fix

---
 drivers/pwm/pwm-meson.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/pwm/pwm-meson.c +2 -12
index 5732300eb..3865538dd 100644
@@ -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;
 
Signature · 1 line
2.40.0
Signature · 7 lines
Thank you,
Dmitry

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic