Lines Matching full:pc
123 static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period, in sti_pwm_get_prescale() argument
126 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_get_prescale()
131 clk_rate = clk_get_rate(pc->pwm_clk); in sti_pwm_get_prescale()
133 dev_err(pc->dev, "failed to get clock rate\n"); in sti_pwm_get_prescale()
167 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_config() local
168 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_config()
170 struct pwm_device *cur = pc->cur; in sti_pwm_config()
171 struct device *dev = pc->dev; in sti_pwm_config()
175 ncfg = hweight_long(pc->configured); in sti_pwm_config()
196 ret = clk_enable(pc->pwm_clk); in sti_pwm_config()
200 ret = clk_enable(pc->cpt_clk); in sti_pwm_config()
205 ret = sti_pwm_get_prescale(pc, period_ns, &prescale); in sti_pwm_config()
211 ret = regmap_field_write(pc->prescale_low, value); in sti_pwm_config()
217 ret = regmap_field_write(pc->prescale_high, value); in sti_pwm_config()
230 ret = regmap_write(pc->regmap, PWM_OUT_VAL(pwm->hwpwm), value); in sti_pwm_config()
234 ret = regmap_field_write(pc->pwm_cpt_int_en, 0); in sti_pwm_config()
236 set_bit(pwm->hwpwm, &pc->configured); in sti_pwm_config()
237 pc->cur = pwm; in sti_pwm_config()
246 clk_disable(pc->pwm_clk); in sti_pwm_config()
247 clk_disable(pc->cpt_clk); in sti_pwm_config()
253 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_enable() local
254 struct device *dev = pc->dev; in sti_pwm_enable()
261 mutex_lock(&pc->sti_pwm_lock); in sti_pwm_enable()
263 if (!pc->en_count) { in sti_pwm_enable()
264 ret = clk_enable(pc->pwm_clk); in sti_pwm_enable()
268 ret = clk_enable(pc->cpt_clk); in sti_pwm_enable()
272 ret = regmap_field_write(pc->pwm_out_en, 1); in sti_pwm_enable()
280 pc->en_count++; in sti_pwm_enable()
283 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_enable()
289 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_disable() local
291 mutex_lock(&pc->sti_pwm_lock); in sti_pwm_disable()
293 if (--pc->en_count) { in sti_pwm_disable()
294 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_disable()
298 regmap_field_write(pc->pwm_out_en, 0); in sti_pwm_disable()
300 clk_disable(pc->pwm_clk); in sti_pwm_disable()
301 clk_disable(pc->cpt_clk); in sti_pwm_disable()
303 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_disable()
308 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_free() local
310 clear_bit(pwm->hwpwm, &pc->configured); in sti_pwm_free()
316 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_capture() local
317 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_capture()
319 struct device *dev = pc->dev; in sti_pwm_capture()
333 regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_RISING); in sti_pwm_capture()
334 regmap_field_write(pc->pwm_cpt_int_en, BIT(pwm->hwpwm)); in sti_pwm_capture()
337 ret = regmap_field_write(pc->pwm_cpt_en, 1); in sti_pwm_capture()
347 regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_DISABLED); in sti_pwm_capture()
372 effective_ticks = clk_get_rate(pc->cpt_clk); in sti_pwm_capture()
389 regmap_field_write(pc->pwm_cpt_en, 0); in sti_pwm_capture()
398 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_apply() local
399 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_apply()
400 struct device *dev = pc->dev; in sti_pwm_apply()
438 struct sti_pwm_chip *pc = data; in sti_pwm_interrupt() local
439 struct device *dev = pc->dev; in sti_pwm_interrupt()
446 ret = regmap_field_read(pc->pwm_cpt_int_stat, &cpt_int_stat); in sti_pwm_interrupt()
453 ddata = &pc->cdata->ddata[devicenum]; in sti_pwm_interrupt()
471 regmap_read(pc->regmap, in sti_pwm_interrupt()
478 regmap_read(pc->regmap, PWM_CPT_EDGE(devicenum), ®); in sti_pwm_interrupt()
480 regmap_write(pc->regmap, PWM_CPT_EDGE(devicenum), reg); in sti_pwm_interrupt()
486 regmap_write(pc->regmap, in sti_pwm_interrupt()
502 regmap_write(pc->regmap, PWM_INT_ACK, PWM_INT_ACK_MASK); in sti_pwm_interrupt()
507 static int sti_pwm_probe_dt(struct sti_pwm_chip *pc) in sti_pwm_probe_dt() argument
509 struct device *dev = pc->dev; in sti_pwm_probe_dt()
512 struct sti_pwm_compat_data *cdata = pc->cdata; in sti_pwm_probe_dt()
531 pc->prescale_low = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
533 if (IS_ERR(pc->prescale_low)) in sti_pwm_probe_dt()
534 return PTR_ERR(pc->prescale_low); in sti_pwm_probe_dt()
536 pc->prescale_high = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
538 if (IS_ERR(pc->prescale_high)) in sti_pwm_probe_dt()
539 return PTR_ERR(pc->prescale_high); in sti_pwm_probe_dt()
541 pc->pwm_out_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
543 if (IS_ERR(pc->pwm_out_en)) in sti_pwm_probe_dt()
544 return PTR_ERR(pc->pwm_out_en); in sti_pwm_probe_dt()
546 pc->pwm_cpt_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
548 if (IS_ERR(pc->pwm_cpt_en)) in sti_pwm_probe_dt()
549 return PTR_ERR(pc->pwm_cpt_en); in sti_pwm_probe_dt()
551 pc->pwm_cpt_int_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
553 if (IS_ERR(pc->pwm_cpt_int_en)) in sti_pwm_probe_dt()
554 return PTR_ERR(pc->pwm_cpt_int_en); in sti_pwm_probe_dt()
556 pc->pwm_cpt_int_stat = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_dt()
558 if (PTR_ERR_OR_ZERO(pc->pwm_cpt_int_stat)) in sti_pwm_probe_dt()
559 return PTR_ERR(pc->pwm_cpt_int_stat); in sti_pwm_probe_dt()
575 struct sti_pwm_chip *pc; in sti_pwm_probe() local
579 pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); in sti_pwm_probe()
580 if (!pc) in sti_pwm_probe()
582 chip = &pc->chip; in sti_pwm_probe()
588 pc->mmio = devm_platform_ioremap_resource(pdev, 0); in sti_pwm_probe()
589 if (IS_ERR(pc->mmio)) in sti_pwm_probe()
590 return PTR_ERR(pc->mmio); in sti_pwm_probe()
592 pc->regmap = devm_regmap_init_mmio(dev, pc->mmio, in sti_pwm_probe()
594 if (IS_ERR(pc->regmap)) in sti_pwm_probe()
595 return PTR_ERR(pc->regmap); in sti_pwm_probe()
602 pdev->name, pc); in sti_pwm_probe()
618 pc->cdata = cdata; in sti_pwm_probe()
619 pc->dev = dev; in sti_pwm_probe()
620 pc->en_count = 0; in sti_pwm_probe()
621 mutex_init(&pc->sti_pwm_lock); in sti_pwm_probe()
623 ret = sti_pwm_probe_dt(pc); in sti_pwm_probe()
628 pc->pwm_clk = devm_clk_get_prepared(dev, "pwm"); in sti_pwm_probe()
629 if (IS_ERR(pc->pwm_clk)) { in sti_pwm_probe()
631 return PTR_ERR(pc->pwm_clk); in sti_pwm_probe()
636 pc->cpt_clk = devm_clk_get_prepared(dev, "capture"); in sti_pwm_probe()
637 if (IS_ERR(pc->cpt_clk)) { in sti_pwm_probe()
639 return PTR_ERR(pc->cpt_clk); in sti_pwm_probe()