diff options
Diffstat (limited to 'drivers/clocksource/sh_cmt.c')
-rw-r--r-- | drivers/clocksource/sh_cmt.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index c2475648961..d607ac2d516 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c | |||
@@ -111,16 +111,21 @@ static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p, | |||
111 | int *has_wrapped) | 111 | int *has_wrapped) |
112 | { | 112 | { |
113 | unsigned long v1, v2, v3; | 113 | unsigned long v1, v2, v3; |
114 | int o1, o2; | ||
115 | |||
116 | o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit; | ||
114 | 117 | ||
115 | /* Make sure the timer value is stable. Stolen from acpi_pm.c */ | 118 | /* Make sure the timer value is stable. Stolen from acpi_pm.c */ |
116 | do { | 119 | do { |
120 | o2 = o1; | ||
117 | v1 = sh_cmt_read(p, CMCNT); | 121 | v1 = sh_cmt_read(p, CMCNT); |
118 | v2 = sh_cmt_read(p, CMCNT); | 122 | v2 = sh_cmt_read(p, CMCNT); |
119 | v3 = sh_cmt_read(p, CMCNT); | 123 | v3 = sh_cmt_read(p, CMCNT); |
120 | } while (unlikely((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) | 124 | o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit; |
121 | || (v3 > v1 && v3 < v2))); | 125 | } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3) |
126 | || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2))); | ||
122 | 127 | ||
123 | *has_wrapped = sh_cmt_read(p, CMCSR) & p->overflow_bit; | 128 | *has_wrapped = o1; |
124 | return v2; | 129 | return v2; |
125 | } | 130 | } |
126 | 131 | ||
@@ -394,7 +399,7 @@ static cycle_t sh_cmt_clocksource_read(struct clocksource *cs) | |||
394 | raw = sh_cmt_get_counter(p, &has_wrapped); | 399 | raw = sh_cmt_get_counter(p, &has_wrapped); |
395 | 400 | ||
396 | if (unlikely(has_wrapped)) | 401 | if (unlikely(has_wrapped)) |
397 | raw = p->match_value; | 402 | raw += p->match_value; |
398 | spin_unlock_irqrestore(&p->lock, flags); | 403 | spin_unlock_irqrestore(&p->lock, flags); |
399 | 404 | ||
400 | return value + raw; | 405 | return value + raw; |