Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 1 | /* linux/arch/arm/mach-msm/timer.c |
| 2 | * |
| 3 | * Copyright (C) 2007 Google, Inc. |
| 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/time.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/clockchips.h> |
| 22 | #include <linux/delay.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 23 | #include <linux/io.h> |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 24 | |
| 25 | #include <asm/mach/time.h> |
Stephen Boyd | ebf30dc | 2011-05-31 16:10:00 -0700 | [diff] [blame] | 26 | #include <asm/hardware/gic.h> |
| 27 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/msm_iomap.h> |
David Brown | 8c27e6f | 2011-01-07 10:20:49 -0800 | [diff] [blame] | 29 | #include <mach/cpu.h> |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 30 | |
| 31 | #define TIMER_MATCH_VAL 0x0000 |
| 32 | #define TIMER_COUNT_VAL 0x0004 |
| 33 | #define TIMER_ENABLE 0x0008 |
| 34 | #define TIMER_ENABLE_CLR_ON_MATCH_EN 2 |
| 35 | #define TIMER_ENABLE_EN 1 |
| 36 | #define TIMER_CLEAR 0x000C |
Jeff Ohlstein | 672039f | 2010-10-05 15:23:57 -0700 | [diff] [blame] | 37 | #define DGT_CLK_CTL 0x0034 |
| 38 | enum { |
| 39 | DGT_CLK_CTL_DIV_1 = 0, |
| 40 | DGT_CLK_CTL_DIV_2 = 1, |
| 41 | DGT_CLK_CTL_DIV_3 = 2, |
| 42 | DGT_CLK_CTL_DIV_4 = 3, |
| 43 | }; |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 44 | #define CSR_PROTECTION 0x0020 |
| 45 | #define CSR_PROTECTION_EN 1 |
| 46 | |
| 47 | #define GPT_HZ 32768 |
Jeff Ohlstein | 672039f | 2010-10-05 15:23:57 -0700 | [diff] [blame] | 48 | |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 49 | enum timer_location { |
| 50 | LOCAL_TIMER = 0, |
| 51 | GLOBAL_TIMER = 1, |
| 52 | }; |
| 53 | |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 54 | #define MSM_GLOBAL_TIMER MSM_CLOCK_DGT |
| 55 | |
David Brown | 8c27e6f | 2011-01-07 10:20:49 -0800 | [diff] [blame] | 56 | /* TODO: Remove these ifdefs */ |
Jeff Ohlstein | 672039f | 2010-10-05 15:23:57 -0700 | [diff] [blame] | 57 | #if defined(CONFIG_ARCH_QSD8X50) |
| 58 | #define DGT_HZ (19200000 / 4) /* 19.2 MHz / 4 by default */ |
| 59 | #define MSM_DGT_SHIFT (0) |
Stephen Boyd | fdb9c3c | 2011-04-21 23:09:11 +0000 | [diff] [blame] | 60 | #elif defined(CONFIG_ARCH_MSM7X30) |
Jeff Ohlstein | 672039f | 2010-10-05 15:23:57 -0700 | [diff] [blame] | 61 | #define DGT_HZ (24576000 / 4) /* 24.576 MHz (LPXO) / 4 by default */ |
| 62 | #define MSM_DGT_SHIFT (0) |
Stephen Boyd | fdb9c3c | 2011-04-21 23:09:11 +0000 | [diff] [blame] | 63 | #elif defined(CONFIG_ARCH_MSM8X60) || defined(CONFIG_ARCH_MSM8960) |
| 64 | #define DGT_HZ (27000000 / 4) /* 27 MHz (PXO) / 4 by default */ |
| 65 | #define MSM_DGT_SHIFT (0) |
Jeff Ohlstein | 672039f | 2010-10-05 15:23:57 -0700 | [diff] [blame] | 66 | #else |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 67 | #define DGT_HZ 19200000 /* 19.2 MHz or 600 KHz after shift */ |
Jeff Ohlstein | 672039f | 2010-10-05 15:23:57 -0700 | [diff] [blame] | 68 | #define MSM_DGT_SHIFT (5) |
| 69 | #endif |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 70 | |
| 71 | struct msm_clock { |
| 72 | struct clock_event_device clockevent; |
| 73 | struct clocksource clocksource; |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 74 | unsigned int irq; |
Brian Swetland | bcc0f6a | 2008-09-10 14:00:53 -0700 | [diff] [blame] | 75 | void __iomem *regbase; |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 76 | uint32_t freq; |
| 77 | uint32_t shift; |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 78 | void __iomem *global_counter; |
| 79 | void __iomem *local_counter; |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 80 | union { |
| 81 | struct clock_event_device *evt; |
| 82 | struct clock_event_device __percpu **percpu_evt; |
| 83 | }; |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 86 | enum { |
| 87 | MSM_CLOCK_GPT, |
| 88 | MSM_CLOCK_DGT, |
| 89 | NR_TIMERS, |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | static struct msm_clock msm_clocks[]; |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 94 | |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 95 | static irqreturn_t msm_timer_interrupt(int irq, void *dev_id) |
| 96 | { |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 97 | struct clock_event_device *evt = *(struct clock_event_device **)dev_id; |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 98 | if (evt->event_handler == NULL) |
| 99 | return IRQ_HANDLED; |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 100 | evt->event_handler(evt); |
| 101 | return IRQ_HANDLED; |
| 102 | } |
| 103 | |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 104 | static cycle_t msm_read_timer_count(struct clocksource *cs) |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 105 | { |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 106 | struct msm_clock *clk = container_of(cs, struct msm_clock, clocksource); |
| 107 | |
Jeff Ohlstein | 650f156 | 2011-06-17 13:55:38 -0700 | [diff] [blame] | 108 | /* |
| 109 | * Shift timer count down by a constant due to unreliable lower bits |
| 110 | * on some targets. |
| 111 | */ |
| 112 | return readl(clk->global_counter) >> clk->shift; |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 113 | } |
| 114 | |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 115 | static struct msm_clock *clockevent_to_clock(struct clock_event_device *evt) |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 116 | { |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 117 | #ifdef CONFIG_SMP |
| 118 | int i; |
| 119 | for (i = 0; i < NR_TIMERS; i++) |
| 120 | if (evt == &(msm_clocks[i].clockevent)) |
| 121 | return &msm_clocks[i]; |
| 122 | return &msm_clocks[MSM_GLOBAL_TIMER]; |
| 123 | #else |
| 124 | return container_of(evt, struct msm_clock, clockevent); |
| 125 | #endif |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static int msm_timer_set_next_event(unsigned long cycles, |
| 129 | struct clock_event_device *evt) |
| 130 | { |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 131 | struct msm_clock *clock = clockevent_to_clock(evt); |
| 132 | uint32_t now = readl(clock->local_counter); |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 133 | uint32_t alarm = now + (cycles << clock->shift); |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 134 | |
| 135 | writel(alarm, clock->regbase + TIMER_MATCH_VAL); |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static void msm_timer_set_mode(enum clock_event_mode mode, |
| 140 | struct clock_event_device *evt) |
| 141 | { |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 142 | struct msm_clock *clock = clockevent_to_clock(evt); |
| 143 | |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 144 | switch (mode) { |
| 145 | case CLOCK_EVT_MODE_RESUME: |
| 146 | case CLOCK_EVT_MODE_PERIODIC: |
| 147 | break; |
| 148 | case CLOCK_EVT_MODE_ONESHOT: |
| 149 | writel(TIMER_ENABLE_EN, clock->regbase + TIMER_ENABLE); |
| 150 | break; |
| 151 | case CLOCK_EVT_MODE_UNUSED: |
| 152 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 153 | writel(0, clock->regbase + TIMER_ENABLE); |
| 154 | break; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | static struct msm_clock msm_clocks[] = { |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 159 | [MSM_CLOCK_GPT] = { |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 160 | .clockevent = { |
| 161 | .name = "gp_timer", |
| 162 | .features = CLOCK_EVT_FEAT_ONESHOT, |
| 163 | .shift = 32, |
| 164 | .rating = 200, |
| 165 | .set_next_event = msm_timer_set_next_event, |
| 166 | .set_mode = msm_timer_set_mode, |
| 167 | }, |
| 168 | .clocksource = { |
| 169 | .name = "gp_timer", |
| 170 | .rating = 200, |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 171 | .read = msm_read_timer_count, |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 172 | .mask = CLOCKSOURCE_MASK(32), |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 173 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 174 | }, |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 175 | .irq = INT_GP_TIMER_EXP, |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 176 | .freq = GPT_HZ, |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 177 | }, |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 178 | [MSM_CLOCK_DGT] = { |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 179 | .clockevent = { |
| 180 | .name = "dg_timer", |
| 181 | .features = CLOCK_EVT_FEAT_ONESHOT, |
| 182 | .shift = 32 + MSM_DGT_SHIFT, |
| 183 | .rating = 300, |
| 184 | .set_next_event = msm_timer_set_next_event, |
| 185 | .set_mode = msm_timer_set_mode, |
| 186 | }, |
| 187 | .clocksource = { |
| 188 | .name = "dg_timer", |
| 189 | .rating = 300, |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 190 | .read = msm_read_timer_count, |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 191 | .mask = CLOCKSOURCE_MASK((32 - MSM_DGT_SHIFT)), |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 192 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 193 | }, |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 194 | .irq = INT_DEBUG_TIMER_EXP, |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 195 | .freq = DGT_HZ >> MSM_DGT_SHIFT, |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 196 | .shift = MSM_DGT_SHIFT, |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 197 | } |
| 198 | }; |
| 199 | |
| 200 | static void __init msm_timer_init(void) |
| 201 | { |
| 202 | int i; |
| 203 | int res; |
David Brown | 8c27e6f | 2011-01-07 10:20:49 -0800 | [diff] [blame] | 204 | int global_offset = 0; |
| 205 | |
| 206 | if (cpu_is_msm7x01()) { |
| 207 | msm_clocks[MSM_CLOCK_GPT].regbase = MSM_CSR_BASE; |
| 208 | msm_clocks[MSM_CLOCK_DGT].regbase = MSM_CSR_BASE + 0x10; |
| 209 | } else if (cpu_is_msm7x30()) { |
| 210 | msm_clocks[MSM_CLOCK_GPT].regbase = MSM_CSR_BASE + 0x04; |
| 211 | msm_clocks[MSM_CLOCK_DGT].regbase = MSM_CSR_BASE + 0x24; |
| 212 | } else if (cpu_is_qsd8x50()) { |
| 213 | msm_clocks[MSM_CLOCK_GPT].regbase = MSM_CSR_BASE; |
| 214 | msm_clocks[MSM_CLOCK_DGT].regbase = MSM_CSR_BASE + 0x10; |
Stepan Moskovchenko | a81c8c3 | 2010-12-01 19:25:14 -0800 | [diff] [blame] | 215 | } else if (cpu_is_msm8x60() || cpu_is_msm8960()) { |
David Brown | 8c27e6f | 2011-01-07 10:20:49 -0800 | [diff] [blame] | 216 | msm_clocks[MSM_CLOCK_GPT].regbase = MSM_TMR_BASE + 0x04; |
| 217 | msm_clocks[MSM_CLOCK_DGT].regbase = MSM_TMR_BASE + 0x24; |
| 218 | |
| 219 | /* Use CPU0's timer as the global timer. */ |
| 220 | global_offset = MSM_TMR0_BASE - MSM_TMR_BASE; |
| 221 | } else |
| 222 | BUG(); |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 223 | |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 224 | #ifdef CONFIG_ARCH_MSM_SCORPIONMP |
Jeff Ohlstein | 672039f | 2010-10-05 15:23:57 -0700 | [diff] [blame] | 225 | writel(DGT_CLK_CTL_DIV_4, MSM_TMR_BASE + DGT_CLK_CTL); |
| 226 | #endif |
| 227 | |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 228 | for (i = 0; i < ARRAY_SIZE(msm_clocks); i++) { |
| 229 | struct msm_clock *clock = &msm_clocks[i]; |
| 230 | struct clock_event_device *ce = &clock->clockevent; |
| 231 | struct clocksource *cs = &clock->clocksource; |
David Brown | 8c27e6f | 2011-01-07 10:20:49 -0800 | [diff] [blame] | 232 | |
| 233 | clock->local_counter = clock->regbase + TIMER_COUNT_VAL; |
| 234 | clock->global_counter = clock->local_counter + global_offset; |
| 235 | |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 236 | writel(0, clock->regbase + TIMER_ENABLE); |
| 237 | writel(0, clock->regbase + TIMER_CLEAR); |
| 238 | writel(~0, clock->regbase + TIMER_MATCH_VAL); |
| 239 | |
| 240 | ce->mult = div_sc(clock->freq, NSEC_PER_SEC, ce->shift); |
| 241 | /* allow at least 10 seconds to notice that the timer wrapped */ |
| 242 | ce->max_delta_ns = |
| 243 | clockevent_delta2ns(0xf0000000 >> clock->shift, ce); |
| 244 | /* 4 gets rounded down to 3 */ |
| 245 | ce->min_delta_ns = clockevent_delta2ns(4, ce); |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 246 | ce->cpumask = cpumask_of(0); |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 247 | |
Russell King | ff9c977 | 2010-12-13 13:18:12 +0000 | [diff] [blame] | 248 | res = clocksource_register_hz(cs, clock->freq); |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 249 | if (res) |
| 250 | printk(KERN_ERR "msm_timer_init: clocksource_register " |
| 251 | "failed for %s\n", cs->name); |
| 252 | |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 253 | ce->irq = clock->irq; |
| 254 | if (cpu_is_msm8x60() || cpu_is_msm8960()) { |
| 255 | clock->percpu_evt = alloc_percpu(struct clock_event_device *); |
| 256 | if (!clock->percpu_evt) { |
| 257 | pr_err("msm_timer_init: memory allocation " |
| 258 | "failed for %s\n", ce->name); |
| 259 | continue; |
| 260 | } |
| 261 | |
| 262 | *__this_cpu_ptr(clock->percpu_evt) = ce; |
| 263 | res = request_percpu_irq(ce->irq, msm_timer_interrupt, |
| 264 | ce->name, clock->percpu_evt); |
| 265 | if (!res) |
| 266 | enable_percpu_irq(ce->irq, 0); |
| 267 | } else { |
| 268 | clock->evt = ce; |
| 269 | res = request_irq(ce->irq, msm_timer_interrupt, |
| 270 | IRQF_TIMER | IRQF_NOBALANCING | IRQF_TRIGGER_RISING, |
| 271 | ce->name, &clock->evt); |
| 272 | } |
| 273 | |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 274 | if (res) |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 275 | pr_err("msm_timer_init: request_irq failed for %s\n", |
| 276 | ce->name); |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 277 | |
| 278 | clockevents_register_device(ce); |
| 279 | } |
| 280 | } |
| 281 | |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 282 | #ifdef CONFIG_SMP |
Santosh Shilimkar | af90f10d | 2011-02-23 18:53:15 +0100 | [diff] [blame] | 283 | int __cpuinit local_timer_setup(struct clock_event_device *evt) |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 284 | { |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 285 | static bool local_timer_inited; |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 286 | struct msm_clock *clock = &msm_clocks[MSM_GLOBAL_TIMER]; |
| 287 | |
| 288 | /* Use existing clock_event for cpu 0 */ |
| 289 | if (!smp_processor_id()) |
David Brown | 893b66c | 2011-03-30 11:26:57 -0700 | [diff] [blame] | 290 | return 0; |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 291 | |
| 292 | writel(DGT_CLK_CTL_DIV_4, MSM_TMR_BASE + DGT_CLK_CTL); |
| 293 | |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 294 | if (!local_timer_inited) { |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 295 | writel(0, clock->regbase + TIMER_ENABLE); |
| 296 | writel(0, clock->regbase + TIMER_CLEAR); |
| 297 | writel(~0, clock->regbase + TIMER_MATCH_VAL); |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 298 | local_timer_inited = true; |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 299 | } |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 300 | evt->irq = clock->irq; |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 301 | evt->name = "local_timer"; |
| 302 | evt->features = CLOCK_EVT_FEAT_ONESHOT; |
| 303 | evt->rating = clock->clockevent.rating; |
| 304 | evt->set_mode = msm_timer_set_mode; |
| 305 | evt->set_next_event = msm_timer_set_next_event; |
| 306 | evt->shift = clock->clockevent.shift; |
| 307 | evt->mult = div_sc(clock->freq, NSEC_PER_SEC, evt->shift); |
| 308 | evt->max_delta_ns = |
| 309 | clockevent_delta2ns(0xf0000000 >> clock->shift, evt); |
| 310 | evt->min_delta_ns = clockevent_delta2ns(4, evt); |
| 311 | |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 312 | *__this_cpu_ptr(clock->percpu_evt) = evt; |
| 313 | enable_percpu_irq(evt->irq, 0); |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 314 | |
| 315 | clockevents_register_device(evt); |
Santosh Shilimkar | af90f10d | 2011-02-23 18:53:15 +0100 | [diff] [blame] | 316 | return 0; |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 319 | void local_timer_stop(struct clock_event_device *evt) |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 320 | { |
Marc Zyngier | 28af690 | 2011-07-22 12:52:37 +0100 | [diff] [blame^] | 321 | evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt); |
| 322 | disable_percpu_irq(evt->irq); |
Jeff Ohlstein | 94790ec | 2010-12-02 12:05:12 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | #endif |
| 326 | |
Arve Hjønnevåg | 3e4ea37 | 2007-11-26 04:11:58 -0800 | [diff] [blame] | 327 | struct sys_timer msm_timer = { |
| 328 | .init = msm_timer_init |
| 329 | }; |