Skip to content

Commit e495f47

Browse files
pH5thierryreding
authored andcommitted
pwm: stm32: Replace write_ccrx with regmap_write
The TIM_CCR1...4 registers are consecutive, so replace the switch case with a simple calculation. Since ch is known to be in the 0...3 range (it is set to hwpwm < npwm <= 4), drop the unnecessary error handling. The return value was not checked anyway. What remains does not warrant keeping the write_ccrx() function around, so instead call regmap_write() directly at the singular call site. Signed-off-by: Philipp Zabel <[email protected]> Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Fabrice Gasnier <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 7ee2273 commit e495f47

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

drivers/pwm/pwm-stm32.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,6 @@ static u32 active_channels(struct stm32_pwm *dev)
5252
return ccer & TIM_CCER_CCXE;
5353
}
5454

55-
static int write_ccrx(struct stm32_pwm *dev, int ch, u32 value)
56-
{
57-
switch (ch) {
58-
case 0:
59-
return regmap_write(dev->regmap, TIM_CCR1, value);
60-
case 1:
61-
return regmap_write(dev->regmap, TIM_CCR2, value);
62-
case 2:
63-
return regmap_write(dev->regmap, TIM_CCR3, value);
64-
case 3:
65-
return regmap_write(dev->regmap, TIM_CCR4, value);
66-
}
67-
return -EINVAL;
68-
}
69-
7055
#define TIM_CCER_CC12P (TIM_CCER_CC1P | TIM_CCER_CC2P)
7156
#define TIM_CCER_CC12E (TIM_CCER_CC1E | TIM_CCER_CC2E)
7257
#define TIM_CCER_CC34P (TIM_CCER_CC3P | TIM_CCER_CC4P)
@@ -369,7 +354,7 @@ static int stm32_pwm_config(struct stm32_pwm *priv, int ch,
369354
dty = prd * duty_ns;
370355
do_div(dty, period_ns);
371356

372-
write_ccrx(priv, ch, dty);
357+
regmap_write(priv->regmap, TIM_CCR1 + 4 * ch, dty);
373358

374359
/* Configure output mode */
375360
shift = (ch & 0x1) * CCMR_CHANNEL_SHIFT;

0 commit comments

Comments
 (0)