Skip to content

Commit 5c86cf4

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
pwm: sifive: Simplify offset calculation for PWMCMP registers
[ Upstream commit 20550a6 ] Instead of explicitly using PWM_SIFIVE_PWMCMP0 + pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP for each access to one of the PWMCMP registers, introduce a macro that takes the hwpwm id as parameter. For the register definition using a plain 4 instead of the cpp constant PWM_SIFIVE_SIZE_PWMCMP is easier to read, so define the offset macro without the constant. The latter can then be dropped as there are no users left. Signed-off-by: Uwe Kleine-König <[email protected]> Tested-by: Emil Renner Berthing <[email protected]> Signed-off-by: Thierry Reding <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 87efb79 commit 5c86cf4

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

drivers/pwm/pwm-sifive.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define PWM_SIFIVE_PWMCFG 0x0
2424
#define PWM_SIFIVE_PWMCOUNT 0x8
2525
#define PWM_SIFIVE_PWMS 0x10
26-
#define PWM_SIFIVE_PWMCMP0 0x20
26+
#define PWM_SIFIVE_PWMCMP(i) (0x20 + 4 * (i))
2727

2828
/* PWMCFG fields */
2929
#define PWM_SIFIVE_PWMCFG_SCALE GENMASK(3, 0)
@@ -36,8 +36,6 @@
3636
#define PWM_SIFIVE_PWMCFG_GANG BIT(24)
3737
#define PWM_SIFIVE_PWMCFG_IP BIT(28)
3838

39-
/* PWM_SIFIVE_SIZE_PWMCMP is used to calculate offset for pwmcmpX registers */
40-
#define PWM_SIFIVE_SIZE_PWMCMP 4
4139
#define PWM_SIFIVE_CMPWIDTH 16
4240
#define PWM_SIFIVE_DEFAULT_PERIOD 10000000
4341

@@ -112,8 +110,7 @@ static void pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
112110
struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip);
113111
u32 duty, val;
114112

115-
duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP0 +
116-
pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP);
113+
duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
117114

118115
state->enabled = duty > 0;
119116

@@ -194,8 +191,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
194191
pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk));
195192
}
196193

197-
writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP0 +
198-
pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP);
194+
writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
199195

200196
if (state->enabled != enabled)
201197
pwm_sifive_enable(chip, state->enabled);

0 commit comments

Comments
 (0)