diff options
Diffstat (limited to 'arch/arm/mach-ks8695/time.c')
-rw-r--r-- | arch/arm/mach-ks8695/time.c | 133 |
1 files changed, 90 insertions, 43 deletions
diff --git a/arch/arm/mach-ks8695/time.c b/arch/arm/mach-ks8695/time.c index ec783a3070ae..46c84bc7792c 100644 --- a/arch/arm/mach-ks8695/time.c +++ b/arch/arm/mach-ks8695/time.c | |||
@@ -25,53 +25,98 @@ | |||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/sched.h> | 26 | #include <linux/sched.h> |
27 | #include <linux/io.h> | 27 | #include <linux/io.h> |
28 | #include <linux/clockchips.h> | ||
28 | 29 | ||
29 | #include <asm/mach/time.h> | 30 | #include <asm/mach/time.h> |
30 | #include <asm/system_misc.h> | 31 | #include <asm/system_misc.h> |
31 | 32 | ||
32 | #include <mach/regs-timer.h> | ||
33 | #include <mach/regs-irq.h> | 33 | #include <mach/regs-irq.h> |
34 | 34 | ||
35 | #include "generic.h" | 35 | #include "generic.h" |
36 | 36 | ||
37 | #define KS8695_TMR_OFFSET (0xF0000 + 0xE400) | ||
38 | #define KS8695_TMR_VA (KS8695_IO_VA + KS8695_TMR_OFFSET) | ||
39 | #define KS8695_TMR_PA (KS8695_IO_PA + KS8695_TMR_OFFSET) | ||
40 | |||
37 | /* | 41 | /* |
38 | * Returns number of ms since last clock interrupt. Note that interrupts | 42 | * Timer registers |
39 | * will have been disabled by do_gettimeoffset() | ||
40 | */ | 43 | */ |
41 | static unsigned long ks8695_gettimeoffset (void) | 44 | #define KS8695_TMCON (0x00) /* Timer Control Register */ |
45 | #define KS8695_T1TC (0x04) /* Timer 1 Timeout Count Register */ | ||
46 | #define KS8695_T0TC (0x08) /* Timer 0 Timeout Count Register */ | ||
47 | #define KS8695_T1PD (0x0C) /* Timer 1 Pulse Count Register */ | ||
48 | #define KS8695_T0PD (0x10) /* Timer 0 Pulse Count Register */ | ||
49 | |||
50 | /* Timer Control Register */ | ||
51 | #define TMCON_T1EN (1 << 1) /* Timer 1 Enable */ | ||
52 | #define TMCON_T0EN (1 << 0) /* Timer 0 Enable */ | ||
53 | |||
54 | /* Timer0 Timeout Counter Register */ | ||
55 | #define T0TC_WATCHDOG (0xff) /* Enable watchdog mode */ | ||
56 | |||
57 | static void ks8695_set_mode(enum clock_event_mode mode, | ||
58 | struct clock_event_device *evt) | ||
42 | { | 59 | { |
43 | unsigned long elapsed, tick2, intpending; | 60 | u32 tmcon; |
44 | 61 | ||
45 | /* | 62 | if (mode == CLOCK_EVT_FEAT_PERIODIC) { |
46 | * Get the current number of ticks. Note that there is a race | 63 | u32 rate = DIV_ROUND_CLOSEST(KS8695_CLOCK_RATE, HZ); |
47 | * condition between us reading the timer and checking for an | 64 | u32 half = DIV_ROUND_CLOSEST(rate, 2); |
48 | * interrupt. We solve this by ensuring that the counter has not | 65 | |
49 | * reloaded between our two reads. | 66 | /* Disable timer 1 */ |
50 | */ | 67 | tmcon = readl_relaxed(KS8695_TMR_VA + KS8695_TMCON); |
51 | elapsed = __raw_readl(KS8695_TMR_VA + KS8695_T1TC) + __raw_readl(KS8695_TMR_VA + KS8695_T1PD); | 68 | tmcon &= ~TMCON_T1EN; |
52 | do { | 69 | writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON); |
53 | tick2 = elapsed; | 70 | |
54 | intpending = __raw_readl(KS8695_IRQ_VA + KS8695_INTST) & (1 << KS8695_IRQ_TIMER1); | 71 | /* Both registers need to count down */ |
55 | elapsed = __raw_readl(KS8695_TMR_VA + KS8695_T1TC) + __raw_readl(KS8695_TMR_VA + KS8695_T1PD); | 72 | writel_relaxed(half, KS8695_TMR_VA + KS8695_T1TC); |
56 | } while (elapsed > tick2); | 73 | writel_relaxed(half, KS8695_TMR_VA + KS8695_T1PD); |
57 | 74 | ||
58 | /* Convert to number of ticks expired (not remaining) */ | 75 | /* Re-enable timer1 */ |
59 | elapsed = (CLOCK_TICK_RATE / HZ) - elapsed; | 76 | tmcon |= TMCON_T1EN; |
60 | 77 | writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON); | |
61 | /* Is interrupt pending? If so, then timer has been reloaded already. */ | 78 | } |
62 | if (intpending) | ||
63 | elapsed += (CLOCK_TICK_RATE / HZ); | ||
64 | |||
65 | /* Convert ticks to usecs */ | ||
66 | return (unsigned long)(elapsed * (tick_nsec / 1000)) / LATCH; | ||
67 | } | 79 | } |
68 | 80 | ||
81 | static int ks8695_set_next_event(unsigned long cycles, | ||
82 | struct clock_event_device *evt) | ||
83 | |||
84 | { | ||
85 | u32 half = DIV_ROUND_CLOSEST(cycles, 2); | ||
86 | u32 tmcon; | ||
87 | |||
88 | /* Disable timer 1 */ | ||
89 | tmcon = readl_relaxed(KS8695_TMR_VA + KS8695_TMCON); | ||
90 | tmcon &= ~TMCON_T1EN; | ||
91 | writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON); | ||
92 | |||
93 | /* Both registers need to count down */ | ||
94 | writel_relaxed(half, KS8695_TMR_VA + KS8695_T1TC); | ||
95 | writel_relaxed(half, KS8695_TMR_VA + KS8695_T1PD); | ||
96 | |||
97 | /* Re-enable timer1 */ | ||
98 | tmcon |= TMCON_T1EN; | ||
99 | writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON); | ||
100 | |||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static struct clock_event_device clockevent_ks8695 = { | ||
105 | .name = "ks8695_t1tc", | ||
106 | .rating = 300, /* Reasonably fast and accurate clock event */ | ||
107 | .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC, | ||
108 | .set_next_event = ks8695_set_next_event, | ||
109 | .set_mode = ks8695_set_mode, | ||
110 | }; | ||
111 | |||
69 | /* | 112 | /* |
70 | * IRQ handler for the timer. | 113 | * IRQ handler for the timer. |
71 | */ | 114 | */ |
72 | static irqreturn_t ks8695_timer_interrupt(int irq, void *dev_id) | 115 | static irqreturn_t ks8695_timer_interrupt(int irq, void *dev_id) |
73 | { | 116 | { |
74 | timer_tick(); | 117 | struct clock_event_device *evt = &clockevent_ks8695; |
118 | |||
119 | evt->event_handler(evt); | ||
75 | return IRQ_HANDLED; | 120 | return IRQ_HANDLED; |
76 | } | 121 | } |
77 | 122 | ||
@@ -83,18 +128,22 @@ static struct irqaction ks8695_timer_irq = { | |||
83 | 128 | ||
84 | static void ks8695_timer_setup(void) | 129 | static void ks8695_timer_setup(void) |
85 | { | 130 | { |
86 | unsigned long tmout = CLOCK_TICK_RATE / HZ; | ||
87 | unsigned long tmcon; | 131 | unsigned long tmcon; |
88 | 132 | ||
89 | /* disable timer1 */ | 133 | /* Disable timer 0 and 1 */ |
90 | tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); | 134 | tmcon = readl_relaxed(KS8695_TMR_VA + KS8695_TMCON); |
91 | __raw_writel(tmcon & ~TMCON_T1EN, KS8695_TMR_VA + KS8695_TMCON); | 135 | tmcon &= ~TMCON_T0EN; |
92 | 136 | tmcon &= ~TMCON_T1EN; | |
93 | __raw_writel(tmout / 2, KS8695_TMR_VA + KS8695_T1TC); | 137 | writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON); |
94 | __raw_writel(tmout / 2, KS8695_TMR_VA + KS8695_T1PD); | ||
95 | 138 | ||
96 | /* re-enable timer1 */ | 139 | /* |
97 | __raw_writel(tmcon | TMCON_T1EN, KS8695_TMR_VA + KS8695_TMCON); | 140 | * Use timer 1 to fire IRQs on the timeline, minimum 2 cycles |
141 | * (one on each counter) maximum 2*2^32, but the API will only | ||
142 | * accept up to a 32bit full word (0xFFFFFFFFU). | ||
143 | */ | ||
144 | clockevents_config_and_register(&clockevent_ks8695, | ||
145 | KS8695_CLOCK_RATE, 2, | ||
146 | 0xFFFFFFFFU); | ||
98 | } | 147 | } |
99 | 148 | ||
100 | static void __init ks8695_timer_init (void) | 149 | static void __init ks8695_timer_init (void) |
@@ -107,8 +156,6 @@ static void __init ks8695_timer_init (void) | |||
107 | 156 | ||
108 | struct sys_timer ks8695_timer = { | 157 | struct sys_timer ks8695_timer = { |
109 | .init = ks8695_timer_init, | 158 | .init = ks8695_timer_init, |
110 | .offset = ks8695_gettimeoffset, | ||
111 | .resume = ks8695_timer_setup, | ||
112 | }; | 159 | }; |
113 | 160 | ||
114 | void ks8695_restart(char mode, const char *cmd) | 161 | void ks8695_restart(char mode, const char *cmd) |
@@ -119,12 +166,12 @@ void ks8695_restart(char mode, const char *cmd) | |||
119 | soft_restart(0); | 166 | soft_restart(0); |
120 | 167 | ||
121 | /* disable timer0 */ | 168 | /* disable timer0 */ |
122 | reg = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); | 169 | reg = readl_relaxed(KS8695_TMR_VA + KS8695_TMCON); |
123 | __raw_writel(reg & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); | 170 | writel_relaxed(reg & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); |
124 | 171 | ||
125 | /* enable watchdog mode */ | 172 | /* enable watchdog mode */ |
126 | __raw_writel((10 << 8) | T0TC_WATCHDOG, KS8695_TMR_VA + KS8695_T0TC); | 173 | writel_relaxed((10 << 8) | T0TC_WATCHDOG, KS8695_TMR_VA + KS8695_T0TC); |
127 | 174 | ||
128 | /* re-enable timer0 */ | 175 | /* re-enable timer0 */ |
129 | __raw_writel(reg | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); | 176 | writel_relaxed(reg | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); |
130 | } | 177 | } |