Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: OMAP: timer32k: fix tick count calculation when reprogramming

Reprogramming takes places before putting the CPU into idle mode if
the dynamic tick option is enabled. The timer is then set to expire
at the next pending timer event. Because some time has already passed
since the last reported jiffy we have to wait less than the time
specified in jiffies.

Also make sure we don't set a load value of 0 whose outcome is
unspecified according to the TRM.

Signed-off-by: Imre Deak <imre.deak@solidboot.com>
Signed-off-by: Juha Yrjola <juha.yrjola@solidboot.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>

authored by

Imre Deak and committed by
Tony Lindgren
df51a84d ae78dcf7

+11 -1
+11 -1
arch/arm/plat-omap/timer32k.c
··· 105 105 106 106 static inline void omap_32k_timer_start(unsigned long load_val) 107 107 { 108 + if (!load_val) 109 + load_val = 1; 108 110 omap_32k_timer_write(load_val, OMAP1_32K_TIMER_TVR); 109 111 omap_32k_timer_write(0x0f, OMAP1_32K_TIMER_CR); 110 112 } ··· 232 230 */ 233 231 void omap_32k_timer_reprogram(unsigned long next_tick) 234 232 { 235 - omap_32k_timer_start(JIFFIES_TO_HW_TICKS(next_tick, 32768) + 1); 233 + unsigned long ticks = JIFFIES_TO_HW_TICKS(next_tick, 32768) + 1; 234 + unsigned long now = omap_32k_sync_timer_read(); 235 + unsigned long idled = now - omap_32k_last_tick; 236 + 237 + if (idled + 1 < ticks) 238 + ticks -= idled; 239 + else 240 + ticks = 1; 241 + omap_32k_timer_start(ticks); 236 242 } 237 243 238 244 static struct irqaction omap_32k_timer_irq;