From 0405d2dc4145805868b6f33fbb0b6ff5053c6319 Mon Sep 17 00:00:00 2001 From: Yuxi Sun Date: Thu, 15 Dec 2011 10:12:53 +0800 Subject: [PATCH] ENGR00170342 PWM: fix pwm output can't be set to 100% full duty The chip document says the counter counts up to period_cycles + 1 and then is reset to 0, so the actual period of the PWM wave is period_cycles + 2 Signed-off-by: Yuxi Sun --- arch/arm/plat-mxc/pwm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm/plat-mxc/pwm.c b/arch/arm/plat-mxc/pwm.c index c95622c27734..c663acf65c3f 100755 --- a/arch/arm/plat-mxc/pwm.c +++ b/arch/arm/plat-mxc/pwm.c @@ -86,7 +86,11 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) prescale = period_cycles / 0x10000 + 1; period_cycles /= prescale; - c = (unsigned long long)period_cycles * duty_ns; + /* the chip document says the counter counts up to + * period_cycles + 1 and then is reset to 0, so the + * actual period of the PWM wave is period_cycles + 2 + */ + c = (unsigned long long)(period_cycles + 2) * duty_ns; do_div(c, period_ns); duty_cycles = c; -- 2.39.5