Skip to contentSkip to conversation

ARM: SAMSUNG: Fix the value of tcnt and tcmp for PWM

PATCH New Kukjin Kim 1 participant 1 message May 9, 2012

Subsystems (3)
lore
Share & tools
lore

Kukjin Kim

author
#0 lore raw

PATCH 1/1 ARM: SAMSUNG: Fix the value of tcnt and tcmp for PWM

According to PWM hardware spec, the actual period which has been calculated by period and input clock is same with (tcnt + 1), so need to down count for tcnt register. And current PWM HW checks the compare register after tcmp++ internally in hardware.

---
 arch/arm/plat-samsung/pwm.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
arch/arm/plat-samsung/pwm.c +19 -4
index c559d84..88fdb1c 100644
@@ -22,6 +22,7 @@
 
 #include <mach/map.h>
 
+#include <plat/cpu.h>
 #include <plat/regs-timer.h>
 
 struct pwm_device {
@@ -215,10 +216,24 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
 
 	tcmp = duty_ns / tin_ns;
 	tcmp = tcnt - tcmp;
-	/* the pwm hw only checks the compare register after a decrement,
-	   so the pin never toggles if tcmp = tcnt */
-	if (tcmp == tcnt)
-		tcmp--;
+
+	if (soc_is_s3c24xx()) {
+		/*
+		 * The S3C24XX PWM HW only checks the compare register after
+		 * a decrement, so the pin never toggles if tcmp = tcnt.
+		 */
+		if (tcmp == tcnt)
+			tcmp--;
+	} else {
+		/*
+		 * The other PWM HW checks the compare register after tcmp++
+		 * internally, so needs -2 for tcmp, and the actual period
+		 * which has been calculated by period_ns and tin_ns is same
+		 * with (tcnt + 1), so need to down count for tcnt register.
+		 */
+		tcmp = tcmp - 2;
+		tcnt--;
+	}
 
 	pwm_dbg(pwm, "tin_ns=%lu, tcmp=%ld/%lu\n", tin_ns, tcmp, tcnt);
 
Signature · 1 line
1.7.1