pwm: sifive: Simplify offset calculation for PWMCMP registers
[ Upstream commit 20550a61880fc55e68a0d290ad195b74729c0e7b ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
6d7f7ffbcd
commit
47902de24a
@@ -23,7 +23,7 @@
|
|||||||
#define PWM_SIFIVE_PWMCFG 0x0
|
#define PWM_SIFIVE_PWMCFG 0x0
|
||||||
#define PWM_SIFIVE_PWMCOUNT 0x8
|
#define PWM_SIFIVE_PWMCOUNT 0x8
|
||||||
#define PWM_SIFIVE_PWMS 0x10
|
#define PWM_SIFIVE_PWMS 0x10
|
||||||
#define PWM_SIFIVE_PWMCMP0 0x20
|
#define PWM_SIFIVE_PWMCMP(i) (0x20 + 4 * (i))
|
||||||
|
|
||||||
/* PWMCFG fields */
|
/* PWMCFG fields */
|
||||||
#define PWM_SIFIVE_PWMCFG_SCALE GENMASK(3, 0)
|
#define PWM_SIFIVE_PWMCFG_SCALE GENMASK(3, 0)
|
||||||
@@ -36,8 +36,6 @@
|
|||||||
#define PWM_SIFIVE_PWMCFG_GANG BIT(24)
|
#define PWM_SIFIVE_PWMCFG_GANG BIT(24)
|
||||||
#define PWM_SIFIVE_PWMCFG_IP BIT(28)
|
#define PWM_SIFIVE_PWMCFG_IP BIT(28)
|
||||||
|
|
||||||
/* PWM_SIFIVE_SIZE_PWMCMP is used to calculate offset for pwmcmpX registers */
|
|
||||||
#define PWM_SIFIVE_SIZE_PWMCMP 4
|
|
||||||
#define PWM_SIFIVE_CMPWIDTH 16
|
#define PWM_SIFIVE_CMPWIDTH 16
|
||||||
#define PWM_SIFIVE_DEFAULT_PERIOD 10000000
|
#define PWM_SIFIVE_DEFAULT_PERIOD 10000000
|
||||||
|
|
||||||
@@ -112,8 +110,7 @@ static void pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
|
|||||||
struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip);
|
struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip);
|
||||||
u32 duty, val;
|
u32 duty, val;
|
||||||
|
|
||||||
duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP0 +
|
duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
|
||||||
pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP);
|
|
||||||
|
|
||||||
state->enabled = duty > 0;
|
state->enabled = duty > 0;
|
||||||
|
|
||||||
@@ -194,8 +191,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
|||||||
pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk));
|
pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk));
|
||||||
}
|
}
|
||||||
|
|
||||||
writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP0 +
|
writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
|
||||||
pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP);
|
|
||||||
|
|
||||||
if (state->enabled != enabled)
|
if (state->enabled != enabled)
|
||||||
pwm_sifive_enable(chip, state->enabled);
|
pwm_sifive_enable(chip, state->enabled);
|
||||||
|
Reference in New Issue
Block a user