Skip to content

Commit 41fa8f5

Browse files
pH5thierryreding
authored andcommitted
pwm: stm32: Use hweight32 in stm32_pwm_detect_channels
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]>
1 parent c0504f5 commit 41fa8f5

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

drivers/pwm/pwm-stm32.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,9 @@ static void stm32_pwm_detect_complementary(struct stm32_pwm *priv)
563563
priv->have_complementary_output = (ccer != 0);
564564
}
565565

566-
static int stm32_pwm_detect_channels(struct stm32_pwm *priv)
566+
static unsigned int stm32_pwm_detect_channels(struct stm32_pwm *priv)
567567
{
568568
u32 ccer;
569-
int npwm = 0;
570569

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

579-
if (ccer & TIM_CCER_CC1E)
580-
npwm++;
581-
582-
if (ccer & TIM_CCER_CC2E)
583-
npwm++;
584-
585-
if (ccer & TIM_CCER_CC3E)
586-
npwm++;
587-
588-
if (ccer & TIM_CCER_CC4E)
589-
npwm++;
590-
591-
return npwm;
578+
return hweight32(ccer & TIM_CCER_CCXE);
592579
}
593580

594581
static int stm32_pwm_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)