usb: dwc2: gadget: Set extcon state for usb cable as always true
[platform/kernel/linux-rpi.git] / drivers / pwm / pwm-stm32.c
index 3d6be77..dd2ee5d 100644 (file)
@@ -579,32 +579,23 @@ 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,
+                                             unsigned int *num_enabled)
 {
-       u32 ccer;
-       int npwm = 0;
+       u32 ccer, ccer_backup;
 
        /*
         * If channels enable bits don't exist writing 1 will have no
         * effect so we can detect and count them.
         */
+       regmap_read(priv->regmap, TIM_CCER, &ccer_backup);
        regmap_set_bits(priv->regmap, TIM_CCER, TIM_CCER_CCXE);
        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++;
+       regmap_write(priv->regmap, TIM_CCER, ccer_backup);
 
-       if (ccer & TIM_CCER_CC3E)
-               npwm++;
+       *num_enabled = hweight32(ccer_backup & TIM_CCER_CCXE);
 
-       if (ccer & TIM_CCER_CC4E)
-               npwm++;
-
-       return npwm;
+       return hweight32(ccer & TIM_CCER_CCXE);
 }
 
 static int stm32_pwm_probe(struct platform_device *pdev)
@@ -613,6 +604,8 @@ static int stm32_pwm_probe(struct platform_device *pdev)
        struct device_node *np = dev->of_node;
        struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
        struct stm32_pwm *priv;
+       unsigned int num_enabled;
+       unsigned int i;
        int ret;
 
        priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -635,7 +628,11 @@ static int stm32_pwm_probe(struct platform_device *pdev)
 
        priv->chip.dev = dev;
        priv->chip.ops = &stm32pwm_ops;
-       priv->chip.npwm = stm32_pwm_detect_channels(priv);
+       priv->chip.npwm = stm32_pwm_detect_channels(priv, &num_enabled);
+
+       /* Initialize clock refcount to number of enabled PWM channels. */
+       for (i = 0; i < num_enabled; i++)
+               clk_enable(priv->clk);
 
        ret = devm_pwmchip_add(dev, &priv->chip);
        if (ret < 0)