Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-omap2/timer-gp.c |
| 3 | * |
| 4 | * OMAP2 GP timer support. |
| 5 | * |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 6 | * Copyright (C) 2009 Nokia Corporation |
| 7 | * |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 8 | * Update to use new clocksource/clockevent layers |
| 9 | * Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com> |
| 10 | * Copyright (C) 2007 MontaVista Software, Inc. |
| 11 | * |
| 12 | * Original driver: |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 13 | * Copyright (C) 2005 Nokia Corporation |
| 14 | * Author: Paul Mundt <paul.mundt@nokia.com> |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 15 | * Juha Yrjölä <juha.yrjola@nokia.com> |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 16 | * OMAP Dual-mode timer framework support by Timo Teras |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 17 | * |
| 18 | * Some parts based off of TI's 24xx code: |
| 19 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 20 | * Copyright (C) 2004-2009 Texas Instruments, Inc. |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 21 | * |
| 22 | * Roughly modelled after the OMAP1 MPU timer code. |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 23 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 24 | * |
| 25 | * This file is subject to the terms and conditions of the GNU General Public |
| 26 | * License. See the file "COPYING" in the main directory of this archive |
| 27 | * for more details. |
| 28 | */ |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/time.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 33 | #include <linux/clk.h> |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 34 | #include <linux/delay.h> |
Dirk Behme | e668729 | 2006-12-06 17:14:00 -0800 | [diff] [blame] | 35 | #include <linux/irq.h> |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 36 | #include <linux/clocksource.h> |
| 37 | #include <linux/clockchips.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 38 | |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 39 | #include <asm/mach/time.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 40 | #include <plat/dmtimer.h> |
Santosh Shilimkar | 39e1d4c | 2009-04-28 20:52:00 +0530 | [diff] [blame] | 41 | #include <asm/localtimer.h> |
Paul Walmsley | cbc9438 | 2011-02-22 19:59:49 -0700 | [diff] [blame] | 42 | #include <asm/sched_clock.h> |
Paul Walmsley | 38698be | 2011-02-23 00:14:08 -0700 | [diff] [blame] | 43 | #include <plat/common.h> |
| 44 | #include <plat/omap_hwmod.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 45 | |
Manjunath Kondaiah G | 04aeae7 | 2010-10-08 09:58:35 -0700 | [diff] [blame] | 46 | #include "timer-gp.h" |
| 47 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 48 | /* Parent clocks, eventually these will come from the clock framework */ |
| 49 | |
| 50 | #define OMAP2_MPU_SOURCE "sys_ck" |
| 51 | #define OMAP3_MPU_SOURCE OMAP2_MPU_SOURCE |
| 52 | #define OMAP4_MPU_SOURCE "sys_clkin_ck" |
| 53 | #define OMAP2_32K_SOURCE "func_32k_ck" |
| 54 | #define OMAP3_32K_SOURCE "omap_32k_fck" |
| 55 | #define OMAP4_32K_SOURCE "sys_32k_ck" |
| 56 | |
| 57 | #ifdef CONFIG_OMAP_32K_TIMER |
| 58 | #define OMAP2_CLKEV_SOURCE OMAP2_32K_SOURCE |
| 59 | #define OMAP3_CLKEV_SOURCE OMAP3_32K_SOURCE |
| 60 | #define OMAP4_CLKEV_SOURCE OMAP4_32K_SOURCE |
| 61 | #define OMAP3_SECURE_TIMER 12 |
| 62 | #else |
| 63 | #define OMAP2_CLKEV_SOURCE OMAP2_MPU_SOURCE |
| 64 | #define OMAP3_CLKEV_SOURCE OMAP3_MPU_SOURCE |
| 65 | #define OMAP4_CLKEV_SOURCE OMAP4_MPU_SOURCE |
| 66 | #define OMAP3_SECURE_TIMER 1 |
| 67 | #endif |
Paul Walmsley | d8328f3 | 2011-01-15 21:32:01 -0700 | [diff] [blame] | 68 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 69 | /* MAX_GPTIMER_ID: number of GPTIMERs on the chip */ |
| 70 | #define MAX_GPTIMER_ID 12 |
| 71 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 72 | /* Clockevent code */ |
| 73 | |
| 74 | static struct omap_dm_timer clkev; |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 75 | static struct omap_dm_timer *gptimer; |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 76 | static struct clock_event_device clockevent_gpt; |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 77 | static u8 __initdata gptimer_id = 1; |
| 78 | static u8 __initdata inited; |
Kevin Hilman | d7814e4 | 2009-10-06 14:30:23 -0700 | [diff] [blame] | 79 | struct omap_dm_timer *gptimer_wakeup; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 80 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 81 | static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 82 | { |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 83 | struct clock_event_device *evt = &clockevent_gpt; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 84 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 85 | __omap_dm_timer_write_status(clkev.io_base, OMAP_TIMER_INT_OVERFLOW); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 86 | |
| 87 | evt->event_handler(evt); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 88 | return IRQ_HANDLED; |
| 89 | } |
| 90 | |
| 91 | static struct irqaction omap2_gp_timer_irq = { |
| 92 | .name = "gp timer", |
Bernhard Walle | b30faba | 2007-05-08 00:35:39 -0700 | [diff] [blame] | 93 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 94 | .handler = omap2_gp_timer_interrupt, |
| 95 | }; |
| 96 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 97 | static int omap2_gp_timer_set_next_event(unsigned long cycles, |
| 98 | struct clock_event_device *evt) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 99 | { |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 100 | __omap_dm_timer_load_start(clkev.io_base, OMAP_TIMER_CTRL_ST, |
| 101 | 0xffffffff - cycles, 1); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 102 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static void omap2_gp_timer_set_mode(enum clock_event_mode mode, |
| 107 | struct clock_event_device *evt) |
| 108 | { |
| 109 | u32 period; |
| 110 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 111 | __omap_dm_timer_stop(clkev.io_base, 1, clkev.rate); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 112 | |
| 113 | switch (mode) { |
| 114 | case CLOCK_EVT_MODE_PERIODIC: |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 115 | period = clkev.rate / HZ; |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 116 | period -= 1; |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 117 | /* Looks like we need to first set the load value separately */ |
| 118 | __omap_dm_timer_write(clkev.io_base, OMAP_TIMER_LOAD_REG, |
| 119 | 0xffffffff - period, 1); |
| 120 | __omap_dm_timer_load_start(clkev.io_base, |
| 121 | OMAP_TIMER_CTRL_AR | OMAP_TIMER_CTRL_ST, |
| 122 | 0xffffffff - period, 1); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 123 | break; |
| 124 | case CLOCK_EVT_MODE_ONESHOT: |
| 125 | break; |
| 126 | case CLOCK_EVT_MODE_UNUSED: |
| 127 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 128 | case CLOCK_EVT_MODE_RESUME: |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static struct clock_event_device clockevent_gpt = { |
| 134 | .name = "gp timer", |
| 135 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, |
| 136 | .shift = 32, |
| 137 | .set_next_event = omap2_gp_timer_set_next_event, |
| 138 | .set_mode = omap2_gp_timer_set_mode, |
| 139 | }; |
| 140 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 141 | /** |
| 142 | * omap2_gp_clockevent_set_gptimer - set which GPTIMER is used for clockevents |
| 143 | * @id: GPTIMER to use (1..MAX_GPTIMER_ID) |
| 144 | * |
| 145 | * Define the GPTIMER that the system should use for the tick timer. |
| 146 | * Meant to be called from board-*.c files in the event that GPTIMER1, the |
| 147 | * default, is unsuitable. Returns -EINVAL on error or 0 on success. |
| 148 | */ |
| 149 | int __init omap2_gp_clockevent_set_gptimer(u8 id) |
| 150 | { |
| 151 | if (id < 1 || id > MAX_GPTIMER_ID) |
| 152 | return -EINVAL; |
| 153 | |
| 154 | BUG_ON(inited); |
| 155 | |
| 156 | gptimer_id = id; |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 161 | static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer, |
| 162 | int gptimer_id, |
| 163 | const char *fck_source) |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 164 | { |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 165 | char name[10]; /* 10 = sizeof("gptXX_Xck0") */ |
| 166 | struct omap_hwmod *oh; |
| 167 | size_t size; |
| 168 | int res = 0; |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 169 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 170 | sprintf(name, "timer%d", gptimer_id); |
| 171 | omap_hwmod_setup_one(name); |
| 172 | oh = omap_hwmod_lookup(name); |
| 173 | if (!oh) |
| 174 | return -ENODEV; |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 175 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 176 | timer->irq = oh->mpu_irqs[0].irq; |
| 177 | timer->phys_base = oh->slaves[0]->addr->pa_start; |
| 178 | size = oh->slaves[0]->addr->pa_end - timer->phys_base; |
| 179 | |
| 180 | /* Static mapping, never released */ |
| 181 | timer->io_base = ioremap(timer->phys_base, size); |
| 182 | if (!timer->io_base) |
| 183 | return -ENXIO; |
| 184 | |
| 185 | /* After the dmtimer is using hwmod these clocks won't be needed */ |
| 186 | sprintf(name, "gpt%d_fck", gptimer_id); |
| 187 | timer->fclk = clk_get(NULL, name); |
| 188 | if (IS_ERR(timer->fclk)) |
| 189 | return -ENODEV; |
| 190 | |
| 191 | sprintf(name, "gpt%d_ick", gptimer_id); |
| 192 | timer->iclk = clk_get(NULL, name); |
| 193 | if (IS_ERR(timer->iclk)) { |
| 194 | clk_put(timer->fclk); |
| 195 | return -ENODEV; |
| 196 | } |
| 197 | |
| 198 | omap_hwmod_enable(oh); |
| 199 | |
| 200 | if (gptimer_id != 12) { |
| 201 | struct clk *src; |
| 202 | |
| 203 | src = clk_get(NULL, fck_source); |
| 204 | if (IS_ERR(src)) { |
| 205 | res = -EINVAL; |
| 206 | } else { |
| 207 | res = __omap_dm_timer_set_source(timer->fclk, src); |
| 208 | if (IS_ERR_VALUE(res)) |
| 209 | pr_warning("%s: timer%i cannot set source\n", |
| 210 | __func__, gptimer_id); |
| 211 | clk_put(src); |
| 212 | } |
| 213 | } |
| 214 | __omap_dm_timer_reset(timer->io_base, 1, 1); |
| 215 | timer->posted = 1; |
| 216 | |
| 217 | timer->rate = clk_get_rate(timer->fclk); |
| 218 | |
| 219 | timer->reserved = 1; |
Paul Walmsley | 38698be | 2011-02-23 00:14:08 -0700 | [diff] [blame] | 220 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 221 | gptimer = omap_dm_timer_request_specific(gptimer_id); |
Timo Teras | 77900a2 | 2006-06-26 16:16:12 -0700 | [diff] [blame] | 222 | BUG_ON(gptimer == NULL); |
Kevin Hilman | d7814e4 | 2009-10-06 14:30:23 -0700 | [diff] [blame] | 223 | gptimer_wakeup = gptimer; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 224 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 225 | return res; |
| 226 | } |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 227 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 228 | static void __init omap2_gp_clockevent_init(int gptimer_id, |
| 229 | const char *fck_source) |
| 230 | { |
| 231 | int res; |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 232 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 233 | inited = 1; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 234 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 235 | res = omap_dm_timer_init_one(&clkev, gptimer_id, fck_source); |
| 236 | BUG_ON(res); |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 237 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 238 | omap2_gp_timer_irq.dev_id = (void *)gptimer; |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 239 | setup_irq(clkev.irq, &omap2_gp_timer_irq); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 240 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 241 | __omap_dm_timer_int_enable(clkev.io_base, OMAP_TIMER_INT_OVERFLOW); |
| 242 | |
| 243 | clockevent_gpt.mult = div_sc(clkev.rate, NSEC_PER_SEC, |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 244 | clockevent_gpt.shift); |
| 245 | clockevent_gpt.max_delta_ns = |
| 246 | clockevent_delta2ns(0xffffffff, &clockevent_gpt); |
| 247 | clockevent_gpt.min_delta_ns = |
Aaro Koskinen | df88acb | 2009-01-29 08:57:17 -0800 | [diff] [blame] | 248 | clockevent_delta2ns(3, &clockevent_gpt); |
| 249 | /* Timer internal resynch latency. */ |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 250 | |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 251 | clockevent_gpt.cpumask = cpumask_of(0); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 252 | clockevents_register_device(&clockevent_gpt); |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 253 | |
| 254 | pr_info("OMAP clockevent source: GPTIMER%d at %lu Hz\n", |
| 255 | gptimer_id, clkev.rate); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 258 | /* Clocksource code */ |
| 259 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 260 | #ifdef CONFIG_OMAP_32K_TIMER |
| 261 | /* |
| 262 | * When 32k-timer is enabled, don't use GPTimer for clocksource |
| 263 | * instead, just leave default clocksource which uses the 32k |
Paul Walmsley | d8328f3 | 2011-01-15 21:32:01 -0700 | [diff] [blame] | 264 | * sync counter. See clocksource setup in plat-omap/counter_32k.c |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 265 | */ |
| 266 | |
Paul Walmsley | d8328f3 | 2011-01-15 21:32:01 -0700 | [diff] [blame] | 267 | static void __init omap2_gp_clocksource_init(void) |
| 268 | { |
| 269 | omap_init_clocksource_32k(); |
| 270 | } |
| 271 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 272 | #else |
| 273 | /* |
| 274 | * clocksource |
| 275 | */ |
Paul Walmsley | cbc9438 | 2011-02-22 19:59:49 -0700 | [diff] [blame] | 276 | static DEFINE_CLOCK_DATA(cd); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 277 | static struct omap_dm_timer *gpt_clocksource; |
Magnus Damm | 8e19608 | 2009-04-21 12:24:00 -0700 | [diff] [blame] | 278 | static cycle_t clocksource_read_cycles(struct clocksource *cs) |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 279 | { |
| 280 | return (cycle_t)omap_dm_timer_read_counter(gpt_clocksource); |
| 281 | } |
| 282 | |
| 283 | static struct clocksource clocksource_gpt = { |
| 284 | .name = "gp timer", |
| 285 | .rating = 300, |
| 286 | .read = clocksource_read_cycles, |
| 287 | .mask = CLOCKSOURCE_MASK(32), |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 288 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 289 | }; |
| 290 | |
Paul Walmsley | cbc9438 | 2011-02-22 19:59:49 -0700 | [diff] [blame] | 291 | static void notrace dmtimer_update_sched_clock(void) |
| 292 | { |
| 293 | u32 cyc; |
| 294 | |
| 295 | cyc = omap_dm_timer_read_counter(gpt_clocksource); |
| 296 | |
| 297 | update_sched_clock(&cd, cyc, (u32)~0); |
| 298 | } |
| 299 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 300 | /* Setup free-running counter for clocksource */ |
| 301 | static void __init omap2_gp_clocksource_init(void) |
| 302 | { |
| 303 | static struct omap_dm_timer *gpt; |
Aaro Koskinen | 2862945 | 2010-11-18 19:59:51 +0200 | [diff] [blame] | 304 | u32 tick_rate; |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 305 | static char err1[] __initdata = KERN_ERR |
| 306 | "%s: failed to request dm-timer\n"; |
| 307 | static char err2[] __initdata = KERN_ERR |
| 308 | "%s: can't register clocksource!\n"; |
| 309 | |
| 310 | gpt = omap_dm_timer_request(); |
| 311 | if (!gpt) |
| 312 | printk(err1, clocksource_gpt.name); |
| 313 | gpt_clocksource = gpt; |
| 314 | |
| 315 | omap_dm_timer_set_source(gpt, OMAP_TIMER_SRC_SYS_CLK); |
| 316 | tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gpt)); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 317 | |
Richard Woodruff | 3fddd09 | 2008-07-03 12:24:30 +0300 | [diff] [blame] | 318 | omap_dm_timer_set_load_start(gpt, 1, 0); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 319 | |
Paul Walmsley | cbc9438 | 2011-02-22 19:59:49 -0700 | [diff] [blame] | 320 | init_sched_clock(&cd, dmtimer_update_sched_clock, 32, tick_rate); |
| 321 | |
Russell King | 8437c25 | 2010-12-13 13:18:44 +0000 | [diff] [blame] | 322 | if (clocksource_register_hz(&clocksource_gpt, tick_rate)) |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 323 | printk(err2, clocksource_gpt.name); |
| 324 | } |
| 325 | #endif |
| 326 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 327 | #define OMAP_SYS_TIMER_INIT(name, clkev_nr, clkev_src) \ |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 328 | static void __init omap##name##_timer_init(void) \ |
| 329 | { \ |
| 330 | omap_dm_timer_init(); \ |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 331 | omap2_gp_clockevent_init((clkev_nr), clkev_src); \ |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 332 | omap2_gp_clocksource_init(); \ |
| 333 | } |
| 334 | |
| 335 | #define OMAP_SYS_TIMER(name) \ |
| 336 | struct sys_timer omap##name##_timer = { \ |
| 337 | .init = omap##name##_timer_init, \ |
| 338 | }; |
| 339 | |
| 340 | #ifdef CONFIG_ARCH_OMAP2 |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 341 | OMAP_SYS_TIMER_INIT(2, 1, OMAP2_CLKEV_SOURCE) |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 342 | OMAP_SYS_TIMER(2) |
| 343 | #endif |
| 344 | |
| 345 | #ifdef CONFIG_ARCH_OMAP3 |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 346 | OMAP_SYS_TIMER_INIT(3, 1, OMAP3_CLKEV_SOURCE) |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 347 | OMAP_SYS_TIMER(3) |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 348 | OMAP_SYS_TIMER_INIT(3_secure, OMAP3_SECURE_TIMER, OMAP3_CLKEV_SOURCE) |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 349 | OMAP_SYS_TIMER(3_secure) |
| 350 | #endif |
| 351 | |
| 352 | #ifdef CONFIG_ARCH_OMAP4 |
| 353 | static void __init omap4_timer_init(void) |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 354 | { |
Santosh Shilimkar | 39e1d4c | 2009-04-28 20:52:00 +0530 | [diff] [blame] | 355 | #ifdef CONFIG_LOCAL_TIMERS |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 356 | twd_base = ioremap(OMAP44XX_LOCAL_TWD_BASE, SZ_256); |
| 357 | BUG_ON(!twd_base); |
Santosh Shilimkar | 39e1d4c | 2009-04-28 20:52:00 +0530 | [diff] [blame] | 358 | #endif |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 359 | omap_dm_timer_init(); |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame^] | 360 | omap2_gp_clockevent_init(1, OMAP4_CLKEV_SOURCE); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 361 | omap2_gp_clocksource_init(); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 362 | } |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 363 | OMAP_SYS_TIMER(4) |
| 364 | #endif |