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.
8 * Based on linux:drivers/pwm/pwm-imx.c
10 * Sascha Hauer <s.hauer@pengutronix.de>
15 #include <asm/arch/imx-regs.h>
17 /* pwm_id from 0..7 */
18 struct pwm_regs *pwm_id_to_reg(int pwm_id)
22 return (struct pwm_regs *)PWM1_BASE_ADDR;
24 return (struct pwm_regs *)PWM2_BASE_ADDR;
27 return (struct pwm_regs *)PWM3_BASE_ADDR;
29 return (struct pwm_regs *)PWM4_BASE_ADDR;
33 return (struct pwm_regs *)PWM5_BASE_ADDR;
35 return (struct pwm_regs *)PWM6_BASE_ADDR;
37 return (struct pwm_regs *)PWM7_BASE_ADDR;
39 return (struct pwm_regs *)PWM8_BASE_ADDR;
42 printf("unknown pwm_id: %d\n", pwm_id);
48 int pwm_imx_get_parms(int period_ns, int duty_ns, unsigned long *period_c,
49 unsigned long *duty_c, unsigned long *prescale)
54 * we have not yet a clock framework for imx6, so add the clock
55 * value here as a define. Replace it when we have the clock
58 c = CONFIG_IMX6_PWM_PER_CLK;
60 do_div(c, 1000000000);
63 *prescale = *period_c / 0x10000 + 1;
65 *period_c /= *prescale;
66 c = *period_c * (unsigned long long)duty_ns;
71 * according to imx pwm RM, the real period value should be
72 * PERIOD value in PWMPR plus 2.