Lines Matching full:pc

122 static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period,  in sti_pwm_get_prescale()  argument
125 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_get_prescale()
130 clk_rate = clk_get_rate(pc->pwm_clk); in sti_pwm_get_prescale()
132 dev_err(pc->dev, "failed to get clock rate\n"); in sti_pwm_get_prescale()
166 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_config() local
167 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_config()
169 struct pwm_device *cur = pc->cur; in sti_pwm_config()
170 struct device *dev = pc->dev; in sti_pwm_config()
174 ncfg = hweight_long(pc->configured); in sti_pwm_config()
195 ret = clk_enable(pc->pwm_clk); in sti_pwm_config()
199 ret = clk_enable(pc->cpt_clk); in sti_pwm_config()
204 ret = sti_pwm_get_prescale(pc, period_ns, &prescale); in sti_pwm_config()
210 ret = regmap_field_write(pc->prescale_low, value); in sti_pwm_config()
216 ret = regmap_field_write(pc->prescale_high, value); in sti_pwm_config()
229 ret = regmap_write(pc->regmap, PWM_OUT_VAL(pwm->hwpwm), value); in sti_pwm_config()
233 ret = regmap_field_write(pc->pwm_cpt_int_en, 0); in sti_pwm_config()
235 set_bit(pwm->hwpwm, &pc->configured); in sti_pwm_config()
236 pc->cur = pwm; in sti_pwm_config()
245 clk_disable(pc->pwm_clk); in sti_pwm_config()
246 clk_disable(pc->cpt_clk); in sti_pwm_config()
252 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_enable() local
253 struct device *dev = pc->dev; in sti_pwm_enable()
260 mutex_lock(&pc->sti_pwm_lock); in sti_pwm_enable()
262 if (!pc->en_count) { in sti_pwm_enable()
263 ret = clk_enable(pc->pwm_clk); in sti_pwm_enable()
267 ret = clk_enable(pc->cpt_clk); in sti_pwm_enable()
271 ret = regmap_field_write(pc->pwm_out_en, 1); in sti_pwm_enable()
279 pc->en_count++; in sti_pwm_enable()
282 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_enable()
288 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_disable() local
290 mutex_lock(&pc->sti_pwm_lock); in sti_pwm_disable()
292 if (--pc->en_count) { in sti_pwm_disable()
293 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_disable()
297 regmap_field_write(pc->pwm_out_en, 0); in sti_pwm_disable()
299 clk_disable(pc->pwm_clk); in sti_pwm_disable()
300 clk_disable(pc->cpt_clk); in sti_pwm_disable()
302 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_disable()
307 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_free() local
309 clear_bit(pwm->hwpwm, &pc->configured); in sti_pwm_free()
315 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_capture() local
316 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_capture()
318 struct device *dev = pc->dev; in sti_pwm_capture()
332 regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_RISING); in sti_pwm_capture()
333 regmap_field_write(pc->pwm_cpt_int_en, BIT(pwm->hwpwm)); in sti_pwm_capture()
336 ret = regmap_field_write(pc->pwm_cpt_en, 1); in sti_pwm_capture()
346 regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_DISABLED); in sti_pwm_capture()
371 effective_ticks = clk_get_rate(pc->cpt_clk); in sti_pwm_capture()
388 regmap_field_write(pc->pwm_cpt_en, 0); in sti_pwm_capture()
428 struct sti_pwm_chip *pc = data; in sti_pwm_interrupt() local
429 struct device *dev = pc->dev; in sti_pwm_interrupt()
436 ret = regmap_field_read(pc->pwm_cpt_int_stat, &cpt_int_stat); in sti_pwm_interrupt()
443 ddata = pwm_get_chip_data(&pc->chip.pwms[devicenum]); in sti_pwm_interrupt()
461 regmap_read(pc->regmap, in sti_pwm_interrupt()
468 regmap_read(pc->regmap, PWM_CPT_EDGE(devicenum), &reg); in sti_pwm_interrupt()
470 regmap_write(pc->regmap, PWM_CPT_EDGE(devicenum), reg); in sti_pwm_interrupt()
476 regmap_write(pc->regmap, in sti_pwm_interrupt()
492 regmap_write(pc->regmap, PWM_INT_ACK, PWM_INT_ACK_MASK); in sti_pwm_interrupt()
497 static int sti_pwm_probe_dt(struct sti_pwm_chip *pc) in sti_pwm_probe_dt() argument
499 struct device *dev = pc->dev; in sti_pwm_probe_dt()
502 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_probe_dt()
521 pc->prescale_low = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
523 if (IS_ERR(pc->prescale_low)) in sti_pwm_probe_dt()
524 return PTR_ERR(pc->prescale_low); in sti_pwm_probe_dt()
526 pc->prescale_high = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
528 if (IS_ERR(pc->prescale_high)) in sti_pwm_probe_dt()
529 return PTR_ERR(pc->prescale_high); in sti_pwm_probe_dt()
531 pc->pwm_out_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
533 if (IS_ERR(pc->pwm_out_en)) in sti_pwm_probe_dt()
534 return PTR_ERR(pc->pwm_out_en); in sti_pwm_probe_dt()
536 pc->pwm_cpt_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
538 if (IS_ERR(pc->pwm_cpt_en)) in sti_pwm_probe_dt()
539 return PTR_ERR(pc->pwm_cpt_en); in sti_pwm_probe_dt()
541 pc->pwm_cpt_int_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
543 if (IS_ERR(pc->pwm_cpt_int_en)) in sti_pwm_probe_dt()
544 return PTR_ERR(pc->pwm_cpt_int_en); in sti_pwm_probe_dt()
546 pc->pwm_cpt_int_stat = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
548 if (PTR_ERR_OR_ZERO(pc->pwm_cpt_int_stat)) in sti_pwm_probe_dt()
549 return PTR_ERR(pc->pwm_cpt_int_stat); in sti_pwm_probe_dt()
564 struct sti_pwm_chip *pc; in sti_pwm_probe() local
568 pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); in sti_pwm_probe()
569 if (!pc) in sti_pwm_probe()
576 pc->mmio = devm_platform_ioremap_resource(pdev, 0); in sti_pwm_probe()
577 if (IS_ERR(pc->mmio)) in sti_pwm_probe()
578 return PTR_ERR(pc->mmio); in sti_pwm_probe()
580 pc->regmap = devm_regmap_init_mmio(dev, pc->mmio, in sti_pwm_probe()
582 if (IS_ERR(pc->regmap)) in sti_pwm_probe()
583 return PTR_ERR(pc->regmap); in sti_pwm_probe()
590 pdev->name, pc); in sti_pwm_probe()
606 pc->cdata = cdata; in sti_pwm_probe()
607 pc->dev = dev; in sti_pwm_probe()
608 pc->en_count = 0; in sti_pwm_probe()
609 mutex_init(&pc->sti_pwm_lock); in sti_pwm_probe()
611 ret = sti_pwm_probe_dt(pc); in sti_pwm_probe()
616 pc->pwm_clk = of_clk_get_by_name(dev->of_node, "pwm"); in sti_pwm_probe()
617 if (IS_ERR(pc->pwm_clk)) { in sti_pwm_probe()
619 return PTR_ERR(pc->pwm_clk); in sti_pwm_probe()
622 ret = clk_prepare(pc->pwm_clk); in sti_pwm_probe()
630 pc->cpt_clk = of_clk_get_by_name(dev->of_node, "capture"); in sti_pwm_probe()
631 if (IS_ERR(pc->cpt_clk)) { in sti_pwm_probe()
633 return PTR_ERR(pc->cpt_clk); in sti_pwm_probe()
636 ret = clk_prepare(pc->cpt_clk); in sti_pwm_probe()
643 pc->chip.dev = dev; in sti_pwm_probe()
644 pc->chip.ops = &sti_pwm_ops; in sti_pwm_probe()
645 pc->chip.npwm = pc->cdata->pwm_num_devs; in sti_pwm_probe()
647 ret = pwmchip_add(&pc->chip); in sti_pwm_probe()
649 clk_unprepare(pc->pwm_clk); in sti_pwm_probe()
650 clk_unprepare(pc->cpt_clk); in sti_pwm_probe()
664 pwm_set_chip_data(&pc->chip.pwms[i], ddata); in sti_pwm_probe()
667 platform_set_drvdata(pdev, pc); in sti_pwm_probe()
674 struct sti_pwm_chip *pc = platform_get_drvdata(pdev); in sti_pwm_remove() local
676 pwmchip_remove(&pc->chip); in sti_pwm_remove()
678 clk_unprepare(pc->pwm_clk); in sti_pwm_remove()
679 clk_unprepare(pc->cpt_clk); in sti_pwm_remove()