Skip to content

Commit d66a928

Browse files
Lee Jonesthierryreding
authored andcommitted
pwm: sti: Supply PWM Capture clock handling
ST's PWM IP is supplied by 2 different clocks. One for PWM output and the other for capture. This patch provides clock handling for the latter. Signed-off-by: Lee Jones <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent f66d78f commit d66a928

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

drivers/pwm/pwm-sti.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct sti_pwm_compat_data {
7474
struct sti_pwm_chip {
7575
struct device *dev;
7676
struct clk *pwm_clk;
77+
struct clk *cpt_clk;
7778
struct regmap *regmap;
7879
struct sti_pwm_compat_data *cdata;
7980
struct regmap_field *prescale_low;
@@ -183,6 +184,10 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
183184
if (ret)
184185
return ret;
185186

187+
ret = clk_enable(pc->cpt_clk);
188+
if (ret)
189+
return ret;
190+
186191
if (!period_same) {
187192
ret = sti_pwm_get_prescale(pc, period_ns, &prescale);
188193
if (ret)
@@ -227,6 +232,7 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
227232

228233
clk_dis:
229234
clk_disable(pc->pwm_clk);
235+
clk_disable(pc->cpt_clk);
230236
return ret;
231237
}
232238

@@ -246,6 +252,10 @@ static int sti_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
246252
if (ret)
247253
goto out;
248254

255+
ret = clk_enable(pc->cpt_clk);
256+
if (ret)
257+
goto out;
258+
249259
ret = regmap_field_write(pc->pwm_out_en, 1);
250260
if (ret) {
251261
dev_err(dev, "failed to enable PWM device:%d\n",
@@ -271,6 +281,7 @@ static void sti_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
271281
regmap_field_write(pc->pwm_out_en, 0);
272282

273283
clk_disable(pc->pwm_clk);
284+
clk_disable(pc->cpt_clk);
274285
mutex_unlock(&pc->sti_pwm_lock);
275286
}
276287

@@ -390,6 +401,18 @@ static int sti_pwm_probe(struct platform_device *pdev)
390401
return ret;
391402
}
392403

404+
pc->cpt_clk = of_clk_get_by_name(dev->of_node, "capture");
405+
if (IS_ERR(pc->cpt_clk)) {
406+
dev_err(dev, "failed to get PWM capture clock\n");
407+
return PTR_ERR(pc->cpt_clk);
408+
}
409+
410+
ret = clk_prepare(pc->cpt_clk);
411+
if (ret) {
412+
dev_err(dev, "failed to prepare clock\n");
413+
return ret;
414+
}
415+
393416
pc->chip.dev = dev;
394417
pc->chip.ops = &sti_pwm_ops;
395418
pc->chip.base = -1;
@@ -399,6 +422,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
399422
ret = pwmchip_add(&pc->chip);
400423
if (ret < 0) {
401424
clk_unprepare(pc->pwm_clk);
425+
clk_unprepare(pc->cpt_clk);
402426
return ret;
403427
}
404428

@@ -416,6 +440,7 @@ static int sti_pwm_remove(struct platform_device *pdev)
416440
pwm_disable(&pc->chip.pwms[i]);
417441

418442
clk_unprepare(pc->pwm_clk);
443+
clk_unprepare(pc->cpt_clk);
419444

420445
return pwmchip_remove(&pc->chip);
421446
}

0 commit comments

Comments
 (0)