Skip to contentSkip to conversation

pwm: rockchip: simplify rockchip_pwm_get_state()

PATCH In review Rasmus Villemoes 4 participants 5 messages Sep 19, 2019 – Jun 3, 2020

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

PATCH 1/1 pwm: rockchip: simplify rockchip_pwm_get_state()

The way state->enabled is computed is rather convoluted and hard to read - both branches of the if() actually do the exact same thing. So remove the if(), and further simplify "<boolean condition> ? true :
false" to "<boolean condition>".

---
I stumbled on this while trying to understand how the pwm subsystem works. This patch is a semantic no-op, but it's also possible that, say, the first branch simply contains a "double negative" so either the != should be == or the "false : true" should be "true : false".

 drivers/pwm/pwm-rockchip.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/pwm/pwm-rockchip.c +1 -6
index 51b96cb7dd25..54c6399e3f00 100644
@@ -83,12 +83,7 @@ static void rockchip_pwm_get_state(struct pwm_chip *chip,
 	state->duty_cycle =  DIV_ROUND_CLOSEST_ULL(tmp, clk_rate);
 
 	val = readl_relaxed(pc->base + pc->data->regs.ctrl);
-	if (pc->data->supports_polarity)
-		state->enabled = ((val & enable_conf) != enable_conf) ?
-				 false : true;
-	else
-		state->enabled = ((val & enable_conf) == enable_conf) ?
-				 true : false;
+	state->enabled = ((val & enable_conf) == enable_conf);
 
 	if (pc->data->supports_polarity) {
 		if (!(val & PWM_DUTY_POSITIVE))
Signature · 1 line
2.20.1
#1 lore raw
Quoted 11 lines · Rasmus Villemoes

The way state->enabled is computed is rather convoluted and hard to read - both branches of the if() actually do the exact same thing. So remove the if(), and further simplify "<boolean condition> ? true :
false" to "<boolean condition>".

---
I stumbled on this while trying to understand how the pwm subsystem works. This patch is a semantic no-op, but it's also possible that, say, the first branch simply contains a "double negative" so either the != should be == or the "false : true" should be "true : false".

The change looks obviously right, it's a noop.

I share your doubts however. The construct was introduced in commit 831b2790507b ("pwm: rockchip: Use same PWM ops for each IP") by David Wu.

Before there were rockchip_pwm_get_state_v1 for the supports_polarity = false case and rockchip_pwm_get_state_v2 for supports_polarity = true.

In both state->enabled was assigned true if ((val & enable_conf) == enable_conf). So I assume everything is fine.

A confirmation by David would be great though.

As a side note: Is there publicly available documentation for this IP? If a link were added to the driver's header we could check easily ourselves.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#2 lore raw

Hello David,

Quoted 19 lines · oUwe Kleine-König
Quoted 11 lines · Rasmus Villemoes

The way state->enabled is computed is rather convoluted and hard to read - both branches of the if() actually do the exact same thing. So remove the if(), and further simplify "<boolean condition> ? true :
false" to "<boolean condition>".

---
I stumbled on this while trying to understand how the pwm subsystem works. This patch is a semantic no-op, but it's also possible that, say, the first branch simply contains a "double negative" so either the != should be == or the "false : true" should be "true : false".

The change looks obviously right, it's a noop.

I share your doubts however. The construct was introduced in commit 831b2790507b ("pwm: rockchip: Use same PWM ops for each IP") by David Wu.

Quoted 7 lines

Before there were rockchip_pwm_get_state_v1 for the supports_polarity = false case and rockchip_pwm_get_state_v2 for supports_polarity = true.

In both state->enabled was assigned true if ((val & enable_conf) == enable_conf). So I assume everything is fine.

A confirmation by David would be great though.

This is still open. Can you please have a look at
https://patchwork.ozlabs.org/project/linux-pwm/patch/[email protected]/
and verify it's correct?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#3 lore raw
In reply to Rasmus Villemoes
Quoted 6 lines · Rasmus Villemoes

The way state->enabled is computed is rather convoluted and hard to read - both branches of the if() actually do the exact same thing. So remove the if(), and further simplify "<boolean condition> ? true :
false" to "<boolean condition>".

Quoted 8 lines

---
I stumbled on this while trying to understand how the pwm subsystem works. This patch is a semantic no-op, but it's also possible that, say, the first branch simply contains a "double negative" so either the != should be == or the "false : true" should be "true : false".

 drivers/pwm/pwm-rockchip.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

I've applied this. Irrespective of any feedback David would have this is correct and a nice simplification.

Thierry

#4 lore raw

This change is very good, thank you. The code continues from the original code(get_state_v1 and get_state_v2), didn’t make any changes at that time, and sorry I have not seen [email protected] mail recently.

Quoted 13 lines · Thierry Reding
Quoted 12 lines · Rasmus Villemoes

The way state->enabled is computed is rather convoluted and hard to read - both branches of the if() actually do the exact same thing. So remove the if(), and further simplify "<boolean condition> ? true :
false" to "<boolean condition>".

---
I stumbled on this while trying to understand how the pwm subsystem works. This patch is a semantic no-op, but it's also possible that, say, the first branch simply contains a "double negative" so either the != should be == or the "false : true" should be "true : false".

Quoted 8 lines
Quoted 2 lines
  drivers/pwm/pwm-rockchip.c | 7 +------
  1 file changed, 1 insertion(+), 6 deletions(-)

I've applied this. Irrespective of any feedback David would have this is correct and a nice simplification.

Thierry

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