linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/7] pwm: sifive: Simplify offset calculation for PWMCMP registers
@ 2022-07-21 10:31 Uwe Kleine-König
  2022-07-21 10:31 ` [PATCH 2/7] pwm: sifive: Fold pwm_sifive_enable() into its only caller Uwe Kleine-König
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2022-07-21 10:31 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Wan Jiabing, kernel, linux-pwm, linux-riscv, Palmer Dabbelt,
	Paul Walmsley, Yash Shah, Atish Patra, Wesley W. Terpstra

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>
---
 drivers/pwm/pwm-sifive.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c
index e6d05a329002..b7fc33b08d82 100644
--- a/drivers/pwm/pwm-sifive.c
+++ b/drivers/pwm/pwm-sifive.c
@@ -23,7 +23,7 @@
 #define PWM_SIFIVE_PWMCFG		0x0
 #define PWM_SIFIVE_PWMCOUNT		0x8
 #define PWM_SIFIVE_PWMS			0x10
-#define PWM_SIFIVE_PWMCMP0		0x20
+#define PWM_SIFIVE_PWMCMP(i)		(0x20 + 4 * (i))
 
 /* PWMCFG fields */
 #define PWM_SIFIVE_PWMCFG_SCALE		GENMASK(3, 0)
@@ -36,8 +36,6 @@
 #define PWM_SIFIVE_PWMCFG_GANG		BIT(24)
 #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_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);
 	u32 duty, val;
 
-	duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP0 +
-		     pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP);
+	duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
 
 	state->enabled = duty > 0;
 
@@ -193,8 +190,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 		pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk));
 	}
 
-	writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP0 +
-	       pwm->hwpwm * PWM_SIFIVE_SIZE_PWMCMP);
+	writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
 
 	if (state->enabled != enabled)
 		pwm_sifive_enable(chip, state->enabled);

base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56
-- 
2.36.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-07-28 17:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21 10:31 [PATCH 1/7] pwm: sifive: Simplify offset calculation for PWMCMP registers Uwe Kleine-König
2022-07-21 10:31 ` [PATCH 2/7] pwm: sifive: Fold pwm_sifive_enable() into its only caller Uwe Kleine-König
2022-07-21 10:31 ` [PATCH 3/7] pwm: sifive: Reduce time the controller lock is held Uwe Kleine-König
2022-07-21 10:31 ` [PATCH 4/7] pwm: sifive: Enable clk only after period check in .apply() Uwe Kleine-König
2022-07-21 10:31 ` [PATCH 5/7] pwm: sifive: Simplify clk handling Uwe Kleine-König
2022-07-21 10:31 ` [PATCH 6/7] pwm: sifive: Ensure the clk is enabled exactly one per running PWM Uwe Kleine-König
2022-07-21 20:45   ` Uwe Kleine-König
2022-07-28 17:10     ` Thierry Reding
2022-07-21 10:31 ` [PATCH 7/7] pwm: sifive: Shut down hardware only after pwmchip_remove() completed Uwe Kleine-König
2022-07-22 17:45   ` Emil Renner Berthing
2022-07-28 17:12     ` Thierry Reding
2022-07-28 17:45       ` Conor.Dooley
2022-07-28 17:12 ` [PATCH 1/7] pwm: sifive: Simplify offset calculation for PWMCMP registers Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).