Skip to content

Commit

Permalink
pwm: stm32: Use hweight32 in stm32_pwm_detect_channels
Browse files Browse the repository at this point in the history
Use hweight32() to count the CCxE bits in stm32_pwm_detect_channels().
Since the return value is assigned to chip.npwm, change it to unsigned
int as well.

Signed-off-by: Philipp Zabel <[email protected]>
Signed-off-by: Uwe Kleine-König <[email protected]>
Reviewed-by: Fabrice Gasnier <[email protected]>
Signed-off-by: Thierry Reding <[email protected]>
  • Loading branch information
pH5 authored and thierryreding committed Dec 20, 2023
1 parent c0504f5 commit 41fa8f5
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions drivers/pwm/pwm-stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,9 @@ static void stm32_pwm_detect_complementary(struct stm32_pwm *priv)
priv->have_complementary_output = (ccer != 0);
}

static int stm32_pwm_detect_channels(struct stm32_pwm *priv)
static unsigned int stm32_pwm_detect_channels(struct stm32_pwm *priv)
{
u32 ccer;
int npwm = 0;

/*
* If channels enable bits don't exist writing 1 will have no
Expand All @@ -576,19 +575,7 @@ static int stm32_pwm_detect_channels(struct stm32_pwm *priv)
regmap_read(priv->regmap, TIM_CCER, &ccer);
regmap_clear_bits(priv->regmap, TIM_CCER, TIM_CCER_CCXE);

if (ccer & TIM_CCER_CC1E)
npwm++;

if (ccer & TIM_CCER_CC2E)
npwm++;

if (ccer & TIM_CCER_CC3E)
npwm++;

if (ccer & TIM_CCER_CC4E)
npwm++;

return npwm;
return hweight32(ccer & TIM_CCER_CCXE);
}

static int stm32_pwm_probe(struct platform_device *pdev)
Expand Down

0 comments on commit 41fa8f5

Please sign in to comment.