Commit 7cea05ae authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Uwe Kleine-König

pwm-stm32: Make use of parametrised register definitions

There is no semantic change, but it is a nicer on the eyes of a reader,
because

	TIM_CCR1 + 4 * ch

encodes internal register knowledge, while

	TIM_CCRx(ch + 1)

keeps that information completely in the header defining the registers.

While I expected this to not result in any changes in the binary, gcc 13
(as provided by Debian in the gcc-13-arm-linux-gnueabihf 13.2.0-12cross1
package) compiles the new version with an allmodconfig to more compact
code:

	$ source/scripts/bloat-o-meter drivers/pwm/pwm-stm32.o-pre drivers/pwm/pwm-stm32.o
	add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-488 (-488)
	Function                                     old     new   delta
	stm32_pwm_get_state                          968     936     -32
	stm32_pwm_apply_locked                      1920    1464    -456
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/d7ef7a6158df4ba6687233b0e00d37796b069fb3.1718791090.git.u.kleine-koenig@baylibre.comSigned-off-by: default avatarUwe Kleine-König <ukleinek@kernel.org>
parent 2b17a6ee
...@@ -368,7 +368,7 @@ static int stm32_pwm_config(struct stm32_pwm *priv, unsigned int ch, ...@@ -368,7 +368,7 @@ static int stm32_pwm_config(struct stm32_pwm *priv, unsigned int ch,
dty = mul_u64_u64_div_u64(duty_ns, clk_get_rate(priv->clk), dty = mul_u64_u64_div_u64(duty_ns, clk_get_rate(priv->clk),
(u64)NSEC_PER_SEC * (prescaler + 1)); (u64)NSEC_PER_SEC * (prescaler + 1));
regmap_write(priv->regmap, TIM_CCR1 + 4 * ch, dty); regmap_write(priv->regmap, TIM_CCRx(ch + 1), dty);
/* Configure output mode */ /* Configure output mode */
shift = (ch & 0x1) * CCMR_CHANNEL_SHIFT; shift = (ch & 0x1) * CCMR_CHANNEL_SHIFT;
...@@ -390,9 +390,9 @@ static int stm32_pwm_set_polarity(struct stm32_pwm *priv, unsigned int ch, ...@@ -390,9 +390,9 @@ static int stm32_pwm_set_polarity(struct stm32_pwm *priv, unsigned int ch,
{ {
u32 mask; u32 mask;
mask = TIM_CCER_CC1P << (ch * 4); mask = TIM_CCER_CCxP(ch + 1);
if (priv->have_complementary_output) if (priv->have_complementary_output)
mask |= TIM_CCER_CC1NP << (ch * 4); mask |= TIM_CCER_CCxNP(ch + 1);
regmap_update_bits(priv->regmap, TIM_CCER, mask, regmap_update_bits(priv->regmap, TIM_CCER, mask,
polarity == PWM_POLARITY_NORMAL ? 0 : mask); polarity == PWM_POLARITY_NORMAL ? 0 : mask);
...@@ -410,9 +410,9 @@ static int stm32_pwm_enable(struct stm32_pwm *priv, unsigned int ch) ...@@ -410,9 +410,9 @@ static int stm32_pwm_enable(struct stm32_pwm *priv, unsigned int ch)
return ret; return ret;
/* Enable channel */ /* Enable channel */
mask = TIM_CCER_CC1E << (ch * 4); mask = TIM_CCER_CCxE(ch + 1);
if (priv->have_complementary_output) if (priv->have_complementary_output)
mask |= TIM_CCER_CC1NE << (ch * 4); mask |= TIM_CCER_CCxNE(ch);
regmap_set_bits(priv->regmap, TIM_CCER, mask); regmap_set_bits(priv->regmap, TIM_CCER, mask);
...@@ -430,9 +430,9 @@ static void stm32_pwm_disable(struct stm32_pwm *priv, unsigned int ch) ...@@ -430,9 +430,9 @@ static void stm32_pwm_disable(struct stm32_pwm *priv, unsigned int ch)
u32 mask; u32 mask;
/* Disable channel */ /* Disable channel */
mask = TIM_CCER_CC1E << (ch * 4); mask = TIM_CCER_CCxE(ch + 1);
if (priv->have_complementary_output) if (priv->have_complementary_output)
mask |= TIM_CCER_CC1NE << (ch * 4); mask |= TIM_CCER_CCxNE(ch + 1);
regmap_clear_bits(priv->regmap, TIM_CCER, mask); regmap_clear_bits(priv->regmap, TIM_CCER, mask);
...@@ -502,8 +502,8 @@ static int stm32_pwm_get_state(struct pwm_chip *chip, ...@@ -502,8 +502,8 @@ static int stm32_pwm_get_state(struct pwm_chip *chip,
if (ret) if (ret)
goto out; goto out;
state->enabled = ccer & (TIM_CCER_CC1E << (ch * 4)); state->enabled = ccer & TIM_CCER_CCxE(ch + 1);
state->polarity = (ccer & (TIM_CCER_CC1P << (ch * 4))) ? state->polarity = (ccer & TIM_CCER_CCxP(ch + 1)) ?
PWM_POLARITY_INVERSED : PWM_POLARITY_NORMAL; PWM_POLARITY_INVERSED : PWM_POLARITY_NORMAL;
ret = regmap_read(priv->regmap, TIM_PSC, &psc); ret = regmap_read(priv->regmap, TIM_PSC, &psc);
if (ret) if (ret)
...@@ -511,7 +511,7 @@ static int stm32_pwm_get_state(struct pwm_chip *chip, ...@@ -511,7 +511,7 @@ static int stm32_pwm_get_state(struct pwm_chip *chip,
ret = regmap_read(priv->regmap, TIM_ARR, &arr); ret = regmap_read(priv->regmap, TIM_ARR, &arr);
if (ret) if (ret)
goto out; goto out;
ret = regmap_read(priv->regmap, TIM_CCR1 + 4 * ch, &ccr); ret = regmap_read(priv->regmap, TIM_CCRx(ch + 1), &ccr);
if (ret) if (ret)
goto out; goto out;
...@@ -712,7 +712,7 @@ static int stm32_pwm_suspend(struct device *dev) ...@@ -712,7 +712,7 @@ static int stm32_pwm_suspend(struct device *dev)
ccer = active_channels(priv); ccer = active_channels(priv);
for (i = 0; i < chip->npwm; i++) { for (i = 0; i < chip->npwm; i++) {
mask = TIM_CCER_CC1E << (i * 4); mask = TIM_CCER_CCxE(i + 1);
if (ccer & mask) { if (ccer & mask) {
dev_err(dev, "PWM %u still in use by consumer %s\n", dev_err(dev, "PWM %u still in use by consumer %s\n",
i, chip->pwms[i].label); i, chip->pwms[i].label);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment