Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pwm: sifive: Simplify offset calculation for PWMCMP registers

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 <u.kleine-koenig@pengutronix.de>
Tested-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Uwe Kleine-König and committed by
Thierry Reding
20550a61 394b5175

+3 -7
+3 -7
drivers/pwm/pwm-sifive.c
··· 23 23 #define PWM_SIFIVE_PWMCFG 0x0 24 24 #define PWM_SIFIVE_PWMCOUNT 0x8 25 25 #define PWM_SIFIVE_PWMS 0x10 26 - #define PWM_SIFIVE_PWMCMP0 0x20 26 + #define PWM_SIFIVE_PWMCMP(i) (0x20 + 4 * (i)) 27 27 28 28 /* PWMCFG fields */ 29 29 #define PWM_SIFIVE_PWMCFG_SCALE GENMASK(3, 0) ··· 36 36 #define PWM_SIFIVE_PWMCFG_GANG BIT(24) 37 37 #define PWM_SIFIVE_PWMCFG_IP BIT(28) 38 38 39 - /* PWM_SIFIVE_SIZE_PWMCMP is used to calculate offset for pwmcmpX registers */ 40 - #define PWM_SIFIVE_SIZE_PWMCMP 4 41 39 #define PWM_SIFIVE_CMPWIDTH 16 42 40 #define PWM_SIFIVE_DEFAULT_PERIOD 10000000 43 41 ··· 110 112 struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); 111 113 u32 duty, val; 112 114 113 - duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP0 + 114 - pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP); 115 + duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); 115 116 116 117 state->enabled = duty > 0; 117 118 ··· 190 193 pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk)); 191 194 } 192 195 193 - writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP0 + 194 - pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP); 196 + writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); 195 197 196 198 if (state->enabled != enabled) 197 199 pwm_sifive_enable(chip, state->enabled);