.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/arch/arm/common/time-acorn.c |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 1996-2000 Russell King. |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License version 2 as |
---|
8 | | - * published by the Free Software Foundation. |
---|
9 | 6 | * |
---|
10 | 7 | * Changelog: |
---|
11 | 8 | * 24-Sep-1996 RMK Created |
---|
.. | .. |
---|
13 | 10 | * 04-Dec-1997 RMK Updated for new arch/arm/time.c |
---|
14 | 11 | * 13=Jun-2004 DS Moved to arch/arm/common b/c shared w/CLPS7500 |
---|
15 | 12 | */ |
---|
16 | | -#include <linux/timex.h> |
---|
| 13 | +#include <linux/clocksource.h> |
---|
17 | 14 | #include <linux/init.h> |
---|
18 | 15 | #include <linux/interrupt.h> |
---|
19 | 16 | #include <linux/irq.h> |
---|
.. | .. |
---|
27 | 24 | #define RPC_CLOCK_FREQ 2000000 |
---|
28 | 25 | #define RPC_LATCH DIV_ROUND_CLOSEST(RPC_CLOCK_FREQ, HZ) |
---|
29 | 26 | |
---|
30 | | -static u32 ioc_timer_gettimeoffset(void) |
---|
| 27 | +static u32 ioc_time; |
---|
| 28 | + |
---|
| 29 | +static u64 ioc_timer_read(struct clocksource *cs) |
---|
31 | 30 | { |
---|
32 | 31 | unsigned int count1, count2, status; |
---|
33 | | - long offset; |
---|
| 32 | + unsigned long flags; |
---|
| 33 | + u32 ticks; |
---|
34 | 34 | |
---|
| 35 | + local_irq_save(flags); |
---|
35 | 36 | ioc_writeb (0, IOC_T0LATCH); |
---|
36 | 37 | barrier (); |
---|
37 | 38 | count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8); |
---|
.. | .. |
---|
41 | 42 | ioc_writeb (0, IOC_T0LATCH); |
---|
42 | 43 | barrier (); |
---|
43 | 44 | count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8); |
---|
| 45 | + ticks = ioc_time + RPC_LATCH - count2; |
---|
| 46 | + local_irq_restore(flags); |
---|
44 | 47 | |
---|
45 | | - offset = count2; |
---|
46 | 48 | if (count2 < count1) { |
---|
47 | 49 | /* |
---|
48 | | - * We have not had an interrupt between reading count1 |
---|
49 | | - * and count2. |
---|
| 50 | + * The timer has not reloaded between reading count1 and |
---|
| 51 | + * count2, check whether an interrupt was actually pending. |
---|
50 | 52 | */ |
---|
51 | 53 | if (status & (1 << 5)) |
---|
52 | | - offset -= RPC_LATCH; |
---|
| 54 | + ticks += RPC_LATCH; |
---|
53 | 55 | } else if (count2 > count1) { |
---|
54 | 56 | /* |
---|
55 | | - * We have just had another interrupt between reading |
---|
56 | | - * count1 and count2. |
---|
| 57 | + * The timer has reloaded, so count2 indicates the new |
---|
| 58 | + * count since the wrap. The interrupt would not have |
---|
| 59 | + * been processed, so add the missed ticks. |
---|
57 | 60 | */ |
---|
58 | | - offset -= RPC_LATCH; |
---|
| 61 | + ticks += RPC_LATCH; |
---|
59 | 62 | } |
---|
60 | 63 | |
---|
61 | | - offset = (RPC_LATCH - offset) * (tick_nsec / 1000); |
---|
62 | | - return DIV_ROUND_CLOSEST(offset, RPC_LATCH) * 1000; |
---|
| 64 | + return ticks; |
---|
63 | 65 | } |
---|
| 66 | + |
---|
| 67 | +static struct clocksource ioctime_clocksource = { |
---|
| 68 | + .read = ioc_timer_read, |
---|
| 69 | + .mask = CLOCKSOURCE_MASK(32), |
---|
| 70 | + .rating = 100, |
---|
| 71 | +}; |
---|
64 | 72 | |
---|
65 | 73 | void __init ioctime_init(void) |
---|
66 | 74 | { |
---|
.. | .. |
---|
72 | 80 | static irqreturn_t |
---|
73 | 81 | ioc_timer_interrupt(int irq, void *dev_id) |
---|
74 | 82 | { |
---|
| 83 | + ioc_time += RPC_LATCH; |
---|
75 | 84 | timer_tick(); |
---|
76 | 85 | return IRQ_HANDLED; |
---|
77 | 86 | } |
---|
78 | | - |
---|
79 | | -static struct irqaction ioc_timer_irq = { |
---|
80 | | - .name = "timer", |
---|
81 | | - .handler = ioc_timer_interrupt |
---|
82 | | -}; |
---|
83 | 87 | |
---|
84 | 88 | /* |
---|
85 | 89 | * Set up timer interrupt. |
---|
86 | 90 | */ |
---|
87 | 91 | void __init ioc_timer_init(void) |
---|
88 | 92 | { |
---|
89 | | - arch_gettimeoffset = ioc_timer_gettimeoffset; |
---|
| 93 | + WARN_ON(clocksource_register_hz(&ioctime_clocksource, RPC_CLOCK_FREQ)); |
---|
90 | 94 | ioctime_init(); |
---|
91 | | - setup_irq(IRQ_TIMER0, &ioc_timer_irq); |
---|
| 95 | + if (request_irq(IRQ_TIMER0, ioc_timer_interrupt, 0, "timer", NULL)) |
---|
| 96 | + pr_err("Failed to request irq %d (timer)\n", IRQ_TIMER0); |
---|
92 | 97 | } |
---|