Lines Matching refs:pc
199 static void configure_polarity(struct ehrpwm_pwm_chip *pc, int chan) in configure_polarity() argument
214 if (pc->polarity[chan] == PWM_POLARITY_INVERSED) in configure_polarity()
222 if (pc->polarity[chan] == PWM_POLARITY_INVERSED) in configure_polarity()
229 ehrpwm_modify(pc->mmio_base, aqctl_reg, aqctl_mask, aqctl_val); in configure_polarity()
239 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); in ehrpwm_pwm_config() local
248 c = pc->clk_rate; in ehrpwm_pwm_config()
257 c = pc->clk_rate; in ehrpwm_pwm_config()
268 if (pc->period_cycles[i] && in ehrpwm_pwm_config()
269 (pc->period_cycles[i] != period_cycles)) { in ehrpwm_pwm_config()
283 pc->period_cycles[pwm->hwpwm] = period_cycles; in ehrpwm_pwm_config()
295 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_CLKDIV_MASK, tb_divval); in ehrpwm_pwm_config()
302 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_PRDLD_MASK, TBCTL_PRDLD_SHDW); in ehrpwm_pwm_config()
304 ehrpwm_write(pc->mmio_base, TBPRD, period_cycles); in ehrpwm_pwm_config()
307 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_CTRMODE_MASK, in ehrpwm_pwm_config()
317 ehrpwm_write(pc->mmio_base, cmp_reg, duty_cycles); in ehrpwm_pwm_config()
326 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); in ehrpwm_pwm_set_polarity() local
329 pc->polarity[pwm->hwpwm] = polarity; in ehrpwm_pwm_set_polarity()
335 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); in ehrpwm_pwm_enable() local
352 ehrpwm_modify(pc->mmio_base, AQSFRC, AQSFRC_RLDCSF_MASK, in ehrpwm_pwm_enable()
355 ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val); in ehrpwm_pwm_enable()
358 configure_polarity(pc, pwm->hwpwm); in ehrpwm_pwm_enable()
361 ret = clk_enable(pc->tbclk); in ehrpwm_pwm_enable()
364 dev_name(pc->chip.dev)); in ehrpwm_pwm_enable()
369 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_FREE_RUN); in ehrpwm_pwm_enable()
375 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); in ehrpwm_pwm_disable() local
391 ehrpwm_modify(pc->mmio_base, AQSFRC, AQSFRC_RLDCSF_MASK, in ehrpwm_pwm_disable()
394 ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val); in ehrpwm_pwm_disable()
397 clk_disable(pc->tbclk); in ehrpwm_pwm_disable()
400 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_STOP_NEXT); in ehrpwm_pwm_disable()
408 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); in ehrpwm_pwm_free() local
416 pc->period_cycles[pwm->hwpwm] = 0; in ehrpwm_pwm_free()
439 struct ehrpwm_pwm_chip *pc; in ehrpwm_pwm_probe() local
442 pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); in ehrpwm_pwm_probe()
443 if (!pc) in ehrpwm_pwm_probe()
452 pc->clk_rate = clk_get_rate(clk); in ehrpwm_pwm_probe()
453 if (!pc->clk_rate) { in ehrpwm_pwm_probe()
458 pc->chip.dev = &pdev->dev; in ehrpwm_pwm_probe()
459 pc->chip.ops = &ehrpwm_pwm_ops; in ehrpwm_pwm_probe()
460 pc->chip.of_xlate = of_pwm_xlate_with_flags; in ehrpwm_pwm_probe()
461 pc->chip.of_pwm_n_cells = 3; in ehrpwm_pwm_probe()
462 pc->chip.base = -1; in ehrpwm_pwm_probe()
463 pc->chip.npwm = NUM_PWM_CHANNEL; in ehrpwm_pwm_probe()
466 pc->mmio_base = devm_ioremap_resource(&pdev->dev, r); in ehrpwm_pwm_probe()
467 if (IS_ERR(pc->mmio_base)) in ehrpwm_pwm_probe()
468 return PTR_ERR(pc->mmio_base); in ehrpwm_pwm_probe()
471 pc->tbclk = devm_clk_get(&pdev->dev, "tbclk"); in ehrpwm_pwm_probe()
472 if (IS_ERR(pc->tbclk)) { in ehrpwm_pwm_probe()
474 return PTR_ERR(pc->tbclk); in ehrpwm_pwm_probe()
477 ret = clk_prepare(pc->tbclk); in ehrpwm_pwm_probe()
483 ret = pwmchip_add(&pc->chip); in ehrpwm_pwm_probe()
502 platform_set_drvdata(pdev, pc); in ehrpwm_pwm_probe()
508 pwmchip_remove(&pc->chip); in ehrpwm_pwm_probe()
509 clk_unprepare(pc->tbclk); in ehrpwm_pwm_probe()
515 struct ehrpwm_pwm_chip *pc = platform_get_drvdata(pdev); in ehrpwm_pwm_remove() local
517 clk_unprepare(pc->tbclk); in ehrpwm_pwm_remove()
529 return pwmchip_remove(&pc->chip); in ehrpwm_pwm_remove()
533 static void ehrpwm_pwm_save_context(struct ehrpwm_pwm_chip *pc) in ehrpwm_pwm_save_context() argument
535 pm_runtime_get_sync(pc->chip.dev); in ehrpwm_pwm_save_context()
536 pc->ctx.tbctl = ehrpwm_read(pc->mmio_base, TBCTL); in ehrpwm_pwm_save_context()
537 pc->ctx.tbprd = ehrpwm_read(pc->mmio_base, TBPRD); in ehrpwm_pwm_save_context()
538 pc->ctx.cmpa = ehrpwm_read(pc->mmio_base, CMPA); in ehrpwm_pwm_save_context()
539 pc->ctx.cmpb = ehrpwm_read(pc->mmio_base, CMPB); in ehrpwm_pwm_save_context()
540 pc->ctx.aqctla = ehrpwm_read(pc->mmio_base, AQCTLA); in ehrpwm_pwm_save_context()
541 pc->ctx.aqctlb = ehrpwm_read(pc->mmio_base, AQCTLB); in ehrpwm_pwm_save_context()
542 pc->ctx.aqsfrc = ehrpwm_read(pc->mmio_base, AQSFRC); in ehrpwm_pwm_save_context()
543 pc->ctx.aqcsfrc = ehrpwm_read(pc->mmio_base, AQCSFRC); in ehrpwm_pwm_save_context()
544 pm_runtime_put_sync(pc->chip.dev); in ehrpwm_pwm_save_context()
547 static void ehrpwm_pwm_restore_context(struct ehrpwm_pwm_chip *pc) in ehrpwm_pwm_restore_context() argument
549 ehrpwm_write(pc->mmio_base, TBPRD, pc->ctx.tbprd); in ehrpwm_pwm_restore_context()
550 ehrpwm_write(pc->mmio_base, CMPA, pc->ctx.cmpa); in ehrpwm_pwm_restore_context()
551 ehrpwm_write(pc->mmio_base, CMPB, pc->ctx.cmpb); in ehrpwm_pwm_restore_context()
552 ehrpwm_write(pc->mmio_base, AQCTLA, pc->ctx.aqctla); in ehrpwm_pwm_restore_context()
553 ehrpwm_write(pc->mmio_base, AQCTLB, pc->ctx.aqctlb); in ehrpwm_pwm_restore_context()
554 ehrpwm_write(pc->mmio_base, AQSFRC, pc->ctx.aqsfrc); in ehrpwm_pwm_restore_context()
555 ehrpwm_write(pc->mmio_base, AQCSFRC, pc->ctx.aqcsfrc); in ehrpwm_pwm_restore_context()
556 ehrpwm_write(pc->mmio_base, TBCTL, pc->ctx.tbctl); in ehrpwm_pwm_restore_context()
561 struct ehrpwm_pwm_chip *pc = dev_get_drvdata(dev); in ehrpwm_pwm_suspend() local
564 ehrpwm_pwm_save_context(pc); in ehrpwm_pwm_suspend()
565 for (i = 0; i < pc->chip.npwm; i++) { in ehrpwm_pwm_suspend()
566 struct pwm_device *pwm = &pc->chip.pwms[i]; in ehrpwm_pwm_suspend()
579 struct ehrpwm_pwm_chip *pc = dev_get_drvdata(dev); in ehrpwm_pwm_resume() local
582 for (i = 0; i < pc->chip.npwm; i++) { in ehrpwm_pwm_resume()
583 struct pwm_device *pwm = &pc->chip.pwms[i]; in ehrpwm_pwm_resume()
591 ehrpwm_pwm_restore_context(pc); in ehrpwm_pwm_resume()