1 // SPDX-License-Identifier: GPL-2.0+
4 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
6 * Basic support for the pwm module on imx6.
12 #include <asm/arch/imx-regs.h>
14 #include "pwm-imx-util.h"
16 int pwm_init(int pwm_id, int div, int invert)
18 struct pwm_regs *pwm = (struct pwm_regs *)pwm_id_to_reg(pwm_id);
27 int pwm_config(int pwm_id, int duty_ns, int period_ns)
29 struct pwm_regs *pwm = (struct pwm_regs *)pwm_id_to_reg(pwm_id);
30 unsigned long period_cycles, duty_cycles, prescale;
36 pwm_imx_get_parms(period_ns, duty_ns, &period_cycles, &duty_cycles,
39 cr = PWMCR_PRESCALER(prescale) |
40 PWMCR_DOZEEN | PWMCR_WAITEN |
41 PWMCR_DBGEN | PWMCR_CLKSRC_IPG_HIGH;
45 writel(duty_cycles, &pwm->sar);
46 /* set period cycles */
47 writel(period_cycles, &pwm->pr);
51 int pwm_enable(int pwm_id)
53 struct pwm_regs *pwm = (struct pwm_regs *)pwm_id_to_reg(pwm_id);
58 setbits_le32(&pwm->cr, PWMCR_EN);
62 void pwm_disable(int pwm_id)
64 struct pwm_regs *pwm = (struct pwm_regs *)pwm_id_to_reg(pwm_id);
69 clrbits_le32(&pwm->cr, PWMCR_EN);