Skip to content

Commit 19f1016

Browse files
pH5thierryreding
authored andcommitted
pwm: stm32: Fix enable count for clk in .probe()
Make the driver take over hardware state without disabling in .probe() and enable the clock for each enabled channel. Signed-off-by: Philipp Zabel <[email protected]> [ukleinek: split off from a patch that also implemented .get_state()] Signed-off-by: Uwe Kleine-König <[email protected]> Fixes: 7edf736 ("pwm: Add driver for STM32 plaftorm") Reviewed-by: Fabrice Gasnier <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent e56ec7b commit 19f1016

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/pwm/pwm-stm32.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,21 @@ static void stm32_pwm_detect_complementary(struct stm32_pwm *priv)
605605
priv->have_complementary_output = (ccer != 0);
606606
}
607607

608-
static unsigned int stm32_pwm_detect_channels(struct stm32_pwm *priv)
608+
static unsigned int stm32_pwm_detect_channels(struct stm32_pwm *priv,
609+
unsigned int *num_enabled)
609610
{
610-
u32 ccer;
611+
u32 ccer, ccer_backup;
611612

612613
/*
613614
* If channels enable bits don't exist writing 1 will have no
614615
* effect so we can detect and count them.
615616
*/
617+
regmap_read(priv->regmap, TIM_CCER, &ccer_backup);
616618
regmap_set_bits(priv->regmap, TIM_CCER, TIM_CCER_CCXE);
617619
regmap_read(priv->regmap, TIM_CCER, &ccer);
618-
regmap_clear_bits(priv->regmap, TIM_CCER, TIM_CCER_CCXE);
620+
regmap_write(priv->regmap, TIM_CCER, ccer_backup);
621+
622+
*num_enabled = hweight32(ccer_backup & TIM_CCER_CCXE);
619623

620624
return hweight32(ccer & TIM_CCER_CCXE);
621625
}
@@ -626,6 +630,8 @@ static int stm32_pwm_probe(struct platform_device *pdev)
626630
struct device_node *np = dev->of_node;
627631
struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
628632
struct stm32_pwm *priv;
633+
unsigned int num_enabled;
634+
unsigned int i;
629635
int ret;
630636

631637
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -648,7 +654,11 @@ static int stm32_pwm_probe(struct platform_device *pdev)
648654

649655
priv->chip.dev = dev;
650656
priv->chip.ops = &stm32pwm_ops;
651-
priv->chip.npwm = stm32_pwm_detect_channels(priv);
657+
priv->chip.npwm = stm32_pwm_detect_channels(priv, &num_enabled);
658+
659+
/* Initialize clock refcount to number of enabled PWM channels. */
660+
for (i = 0; i < num_enabled; i++)
661+
clk_enable(priv->clk);
652662

653663
ret = devm_pwmchip_add(dev, &priv->chip);
654664
if (ret < 0)

0 commit comments

Comments
 (0)