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

clocksource: samsung_pwm_timer: Work around rounding errors in clockevents core

Due to rounding errors in clockevents core (in conversions between ticks
and nsecs), it might happen that the set_next_event callback gets called
with cycles = 0, causing the code to incorrectly program the PWM timer.

This patch modifies the callback to program the timer for 1 tick, if
received tick count value is 0.

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Kukjin Kim <kgene.kim@samsung.com>
Signed-off-by: Olof Johansson <olof@lixom.net>

authored by

Tomasz Figa and committed by
Olof Johansson
81d4f7bf 6fe4dfd0

+13
+13
drivers/clocksource/samsung_pwm_timer.c
··· 176 176 static int samsung_set_next_event(unsigned long cycles, 177 177 struct clock_event_device *evt) 178 178 { 179 + /* 180 + * This check is needed to account for internal rounding 181 + * errors inside clockevents core, which might result in 182 + * passing cycles = 0, which in turn would not generate any 183 + * timer interrupt and hang the system. 184 + * 185 + * Another solution would be to set up the clockevent device 186 + * with min_delta = 2, but this would unnecessarily increase 187 + * the minimum sleep period. 188 + */ 189 + if (!cycles) 190 + cycles = 1; 191 + 179 192 samsung_time_setup(pwm.event_id, cycles); 180 193 samsung_time_start(pwm.event_id, false); 181 194