Lines Matching full:pc
117 static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period, in sti_pwm_get_prescale() argument
124 clk_rate = clk_get_rate(pc->pwm_clk); in sti_pwm_get_prescale()
126 dev_err(pc->dev, "failed to get clock rate\n"); in sti_pwm_get_prescale()
134 value *= pc->max_pwm_cnt + 1; in sti_pwm_get_prescale()
140 if (ps > pc->max_prescale) in sti_pwm_get_prescale()
160 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_config() local
162 struct pwm_device *cur = pc->cur; in sti_pwm_config()
163 struct device *dev = pc->dev; in sti_pwm_config()
167 ncfg = hweight_long(pc->configured); in sti_pwm_config()
188 ret = clk_enable(pc->pwm_clk); in sti_pwm_config()
192 ret = clk_enable(pc->cpt_clk); in sti_pwm_config()
197 ret = sti_pwm_get_prescale(pc, period_ns, &prescale); in sti_pwm_config()
203 ret = regmap_field_write(pc->prescale_low, value); in sti_pwm_config()
209 ret = regmap_field_write(pc->prescale_high, value); in sti_pwm_config()
220 value = pc->max_pwm_cnt * duty_ns / period_ns; in sti_pwm_config()
222 ret = regmap_write(pc->regmap, PWM_OUT_VAL(pwm->hwpwm), value); in sti_pwm_config()
226 ret = regmap_field_write(pc->pwm_cpt_int_en, 0); in sti_pwm_config()
228 set_bit(pwm->hwpwm, &pc->configured); in sti_pwm_config()
229 pc->cur = pwm; in sti_pwm_config()
238 clk_disable(pc->pwm_clk); in sti_pwm_config()
239 clk_disable(pc->cpt_clk); in sti_pwm_config()
245 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_enable() local
246 struct device *dev = pc->dev; in sti_pwm_enable()
253 mutex_lock(&pc->sti_pwm_lock); in sti_pwm_enable()
255 if (!pc->en_count) { in sti_pwm_enable()
256 ret = clk_enable(pc->pwm_clk); in sti_pwm_enable()
260 ret = clk_enable(pc->cpt_clk); in sti_pwm_enable()
264 ret = regmap_field_write(pc->pwm_out_en, 1); in sti_pwm_enable()
272 pc->en_count++; in sti_pwm_enable()
275 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_enable()
281 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_disable() local
283 mutex_lock(&pc->sti_pwm_lock); in sti_pwm_disable()
285 if (--pc->en_count) { in sti_pwm_disable()
286 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_disable()
290 regmap_field_write(pc->pwm_out_en, 0); in sti_pwm_disable()
292 clk_disable(pc->pwm_clk); in sti_pwm_disable()
293 clk_disable(pc->cpt_clk); in sti_pwm_disable()
295 mutex_unlock(&pc->sti_pwm_lock); in sti_pwm_disable()
300 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_free() local
302 clear_bit(pwm->hwpwm, &pc->configured); in sti_pwm_free()
308 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_capture() local
309 struct sti_cpt_ddata *ddata = &pc->ddata[pwm->hwpwm]; in sti_pwm_capture()
310 struct device *dev = pc->dev; in sti_pwm_capture()
315 if (pwm->hwpwm >= pc->cpt_num_devs) { in sti_pwm_capture()
324 regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_RISING); in sti_pwm_capture()
325 regmap_field_write(pc->pwm_cpt_int_en, BIT(pwm->hwpwm)); in sti_pwm_capture()
328 ret = regmap_field_write(pc->pwm_cpt_en, 1); in sti_pwm_capture()
338 regmap_write(pc->regmap, PWM_CPT_EDGE(pwm->hwpwm), CPT_EDGE_DISABLED); in sti_pwm_capture()
363 effective_ticks = clk_get_rate(pc->cpt_clk); in sti_pwm_capture()
380 regmap_field_write(pc->pwm_cpt_en, 0); in sti_pwm_capture()
389 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); in sti_pwm_apply() local
390 struct device *dev = pc->dev; in sti_pwm_apply()
393 if (pwm->hwpwm >= pc->pwm_num_devs) { in sti_pwm_apply()
427 struct sti_pwm_chip *pc = data; in sti_pwm_interrupt() local
428 struct device *dev = pc->dev; in sti_pwm_interrupt()
435 ret = regmap_field_read(pc->pwm_cpt_int_stat, &cpt_int_stat); in sti_pwm_interrupt()
442 ddata = &pc->ddata[devicenum]; in sti_pwm_interrupt()
460 regmap_read(pc->regmap, in sti_pwm_interrupt()
467 regmap_read(pc->regmap, PWM_CPT_EDGE(devicenum), ®); in sti_pwm_interrupt()
469 regmap_write(pc->regmap, PWM_CPT_EDGE(devicenum), reg); in sti_pwm_interrupt()
475 regmap_write(pc->regmap, in sti_pwm_interrupt()
491 regmap_write(pc->regmap, PWM_INT_ACK, PWM_INT_ACK_MASK); in sti_pwm_interrupt()
496 static int sti_pwm_probe_regmap(struct sti_pwm_chip *pc) in sti_pwm_probe_regmap() argument
498 struct device *dev = pc->dev; in sti_pwm_probe_regmap()
500 pc->prescale_low = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_regmap()
502 if (IS_ERR(pc->prescale_low)) in sti_pwm_probe_regmap()
503 return PTR_ERR(pc->prescale_low); in sti_pwm_probe_regmap()
505 pc->prescale_high = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_regmap()
507 if (IS_ERR(pc->prescale_high)) in sti_pwm_probe_regmap()
508 return PTR_ERR(pc->prescale_high); in sti_pwm_probe_regmap()
510 pc->pwm_out_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_regmap()
512 if (IS_ERR(pc->pwm_out_en)) in sti_pwm_probe_regmap()
513 return PTR_ERR(pc->pwm_out_en); in sti_pwm_probe_regmap()
515 pc->pwm_cpt_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_regmap()
517 if (IS_ERR(pc->pwm_cpt_en)) in sti_pwm_probe_regmap()
518 return PTR_ERR(pc->pwm_cpt_en); in sti_pwm_probe_regmap()
520 pc->pwm_cpt_int_en = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_regmap()
522 if (IS_ERR(pc->pwm_cpt_int_en)) in sti_pwm_probe_regmap()
523 return PTR_ERR(pc->pwm_cpt_int_en); in sti_pwm_probe_regmap()
525 pc->pwm_cpt_int_stat = devm_regmap_field_alloc(dev, pc->regmap, in sti_pwm_probe_regmap()
527 if (PTR_ERR_OR_ZERO(pc->pwm_cpt_int_stat)) in sti_pwm_probe_regmap()
528 return PTR_ERR(pc->pwm_cpt_int_stat); in sti_pwm_probe_regmap()
547 struct sti_pwm_chip *pc; in sti_pwm_probe() local
562 chip = devm_pwmchip_alloc(dev, max(pwm_num_devs, cpt_num_devs), sizeof(*pc)); in sti_pwm_probe()
565 pc = to_sti_pwmchip(chip); in sti_pwm_probe()
567 pc->mmio = devm_platform_ioremap_resource(pdev, 0); in sti_pwm_probe()
568 if (IS_ERR(pc->mmio)) in sti_pwm_probe()
569 return PTR_ERR(pc->mmio); in sti_pwm_probe()
571 pc->regmap = devm_regmap_init_mmio(dev, pc->mmio, in sti_pwm_probe()
573 if (IS_ERR(pc->regmap)) in sti_pwm_probe()
574 return dev_err_probe(dev, PTR_ERR(pc->regmap), in sti_pwm_probe()
582 pdev->name, pc); in sti_pwm_probe()
590 pc->max_prescale = 0xff; in sti_pwm_probe()
591 pc->max_pwm_cnt = 255; in sti_pwm_probe()
592 pc->pwm_num_devs = pwm_num_devs; in sti_pwm_probe()
593 pc->cpt_num_devs = cpt_num_devs; in sti_pwm_probe()
595 pc->dev = dev; in sti_pwm_probe()
596 pc->en_count = 0; in sti_pwm_probe()
597 mutex_init(&pc->sti_pwm_lock); in sti_pwm_probe()
599 ret = sti_pwm_probe_regmap(pc); in sti_pwm_probe()
604 pc->pwm_clk = devm_clk_get_prepared(dev, "pwm"); in sti_pwm_probe()
605 if (IS_ERR(pc->pwm_clk)) in sti_pwm_probe()
606 return dev_err_probe(dev, PTR_ERR(pc->pwm_clk), in sti_pwm_probe()
611 pc->cpt_clk = devm_clk_get_prepared(dev, "capture"); in sti_pwm_probe()
612 if (IS_ERR(pc->cpt_clk)) in sti_pwm_probe()
613 return dev_err_probe(dev, PTR_ERR(pc->cpt_clk), in sti_pwm_probe()
616 pc->ddata = devm_kcalloc(dev, cpt_num_devs, in sti_pwm_probe()
617 sizeof(*pc->ddata), GFP_KERNEL); in sti_pwm_probe()
618 if (!pc->ddata) in sti_pwm_probe()
622 struct sti_cpt_ddata *ddata = &pc->ddata[i]; in sti_pwm_probe()