Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 1 | /* |
Tony Lindgren | 0f622e8 | 2011-03-29 15:54:50 -0700 | [diff] [blame] | 2 | * linux/arch/arm/mach-omap2/timer.c |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 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> |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 38 | #include <linux/slab.h> |
Santosh Shilimkar | eed0de2 | 2012-07-04 18:32:32 +0530 | [diff] [blame] | 39 | #include <linux/of.h> |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 40 | #include <linux/of_address.h> |
| 41 | #include <linux/of_irq.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 42 | |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 43 | #include <asm/mach/time.h> |
Marc Zyngier | a45c983 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 44 | #include <asm/smp_twd.h> |
Paul Walmsley | cbc9438 | 2011-02-22 19:59:49 -0700 | [diff] [blame] | 45 | #include <asm/sched_clock.h> |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 46 | |
Santosh Shilimkar | 3c7c5da | 2012-08-13 14:39:03 +0530 | [diff] [blame] | 47 | #include <asm/arch_timer.h> |
Paul Walmsley | 38698be | 2011-02-23 00:14:08 -0700 | [diff] [blame] | 48 | #include <plat/omap_hwmod.h> |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 49 | #include <plat/omap_device.h> |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 50 | #include <plat/dmtimer.h> |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 51 | #include <plat/omap-pm.h> |
| 52 | |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 53 | #include "soc.h" |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 54 | #include "common.h" |
Tarun Kanti DebBarma | b481113 | 2011-09-20 17:00:24 +0530 | [diff] [blame] | 55 | #include "powerdomain.h" |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 56 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 57 | /* Parent clocks, eventually these will come from the clock framework */ |
| 58 | |
| 59 | #define OMAP2_MPU_SOURCE "sys_ck" |
| 60 | #define OMAP3_MPU_SOURCE OMAP2_MPU_SOURCE |
| 61 | #define OMAP4_MPU_SOURCE "sys_clkin_ck" |
| 62 | #define OMAP2_32K_SOURCE "func_32k_ck" |
| 63 | #define OMAP3_32K_SOURCE "omap_32k_fck" |
| 64 | #define OMAP4_32K_SOURCE "sys_32k_ck" |
| 65 | |
| 66 | #ifdef CONFIG_OMAP_32K_TIMER |
| 67 | #define OMAP2_CLKEV_SOURCE OMAP2_32K_SOURCE |
| 68 | #define OMAP3_CLKEV_SOURCE OMAP3_32K_SOURCE |
| 69 | #define OMAP4_CLKEV_SOURCE OMAP4_32K_SOURCE |
| 70 | #define OMAP3_SECURE_TIMER 12 |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 71 | #define TIMER_PROP_SECURE "ti,timer-secure" |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 72 | #else |
| 73 | #define OMAP2_CLKEV_SOURCE OMAP2_MPU_SOURCE |
| 74 | #define OMAP3_CLKEV_SOURCE OMAP3_MPU_SOURCE |
| 75 | #define OMAP4_CLKEV_SOURCE OMAP4_MPU_SOURCE |
| 76 | #define OMAP3_SECURE_TIMER 1 |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 77 | #define TIMER_PROP_SECURE "ti,timer-alwon" |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 78 | #endif |
Paul Walmsley | d8328f3 | 2011-01-15 21:32:01 -0700 | [diff] [blame] | 79 | |
Santosh Shilimkar | fa6d79d | 2012-08-13 14:24:24 +0530 | [diff] [blame] | 80 | #define REALTIME_COUNTER_BASE 0x48243200 |
| 81 | #define INCREMENTER_NUMERATOR_OFFSET 0x10 |
| 82 | #define INCREMENTER_DENUMERATOR_RELOAD_OFFSET 0x14 |
| 83 | #define NUMERATOR_DENUMERATOR_MASK 0xfffff000 |
| 84 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 85 | /* Clockevent code */ |
| 86 | |
| 87 | static struct omap_dm_timer clkev; |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 88 | static struct clock_event_device clockevent_gpt; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 89 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 90 | static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 91 | { |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 92 | struct clock_event_device *evt = &clockevent_gpt; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 93 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 94 | __omap_dm_timer_write_status(&clkev, OMAP_TIMER_INT_OVERFLOW); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 95 | |
| 96 | evt->event_handler(evt); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 97 | return IRQ_HANDLED; |
| 98 | } |
| 99 | |
| 100 | static struct irqaction omap2_gp_timer_irq = { |
Vaibhav Hiremath | f36921b | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 101 | .name = "gp_timer", |
Bernhard Walle | b30faba | 2007-05-08 00:35:39 -0700 | [diff] [blame] | 102 | .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 103 | .handler = omap2_gp_timer_interrupt, |
| 104 | }; |
| 105 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 106 | static int omap2_gp_timer_set_next_event(unsigned long cycles, |
| 107 | struct clock_event_device *evt) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 108 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 109 | __omap_dm_timer_load_start(&clkev, OMAP_TIMER_CTRL_ST, |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 110 | 0xffffffff - cycles, 1); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 111 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static void omap2_gp_timer_set_mode(enum clock_event_mode mode, |
| 116 | struct clock_event_device *evt) |
| 117 | { |
| 118 | u32 period; |
| 119 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 120 | __omap_dm_timer_stop(&clkev, 1, clkev.rate); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 121 | |
| 122 | switch (mode) { |
| 123 | case CLOCK_EVT_MODE_PERIODIC: |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 124 | period = clkev.rate / HZ; |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 125 | period -= 1; |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 126 | /* Looks like we need to first set the load value separately */ |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 127 | __omap_dm_timer_write(&clkev, OMAP_TIMER_LOAD_REG, |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 128 | 0xffffffff - period, 1); |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 129 | __omap_dm_timer_load_start(&clkev, |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 130 | OMAP_TIMER_CTRL_AR | OMAP_TIMER_CTRL_ST, |
| 131 | 0xffffffff - period, 1); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 132 | break; |
| 133 | case CLOCK_EVT_MODE_ONESHOT: |
| 134 | break; |
| 135 | case CLOCK_EVT_MODE_UNUSED: |
| 136 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 137 | case CLOCK_EVT_MODE_RESUME: |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | static struct clock_event_device clockevent_gpt = { |
Vaibhav Hiremath | f36921b | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 143 | .name = "gp_timer", |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 144 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, |
| 145 | .shift = 32, |
Santosh Shilimkar | 11d6ec2 | 2012-03-17 15:00:16 +0530 | [diff] [blame] | 146 | .rating = 300, |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 147 | .set_next_event = omap2_gp_timer_set_next_event, |
| 148 | .set_mode = omap2_gp_timer_set_mode, |
| 149 | }; |
| 150 | |
Jon Hunter | ad24bde | 2012-06-20 15:55:24 -0500 | [diff] [blame] | 151 | static struct property device_disabled = { |
| 152 | .name = "status", |
| 153 | .length = sizeof("disabled"), |
| 154 | .value = "disabled", |
| 155 | }; |
| 156 | |
| 157 | static struct of_device_id omap_timer_match[] __initdata = { |
| 158 | { .compatible = "ti,omap2-timer", }, |
| 159 | { } |
| 160 | }; |
| 161 | |
Jon Hunter | 9883f7c | 2012-10-09 14:12:26 -0500 | [diff] [blame^] | 162 | static struct of_device_id omap_counter_match[] __initdata = { |
| 163 | { .compatible = "ti,omap-counter32k", }, |
| 164 | { } |
| 165 | }; |
| 166 | |
Jon Hunter | ad24bde | 2012-06-20 15:55:24 -0500 | [diff] [blame] | 167 | /** |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 168 | * omap_get_timer_dt - get a timer using device-tree |
| 169 | * @match - device-tree match structure for matching a device type |
| 170 | * @property - optional timer property to match |
| 171 | * |
| 172 | * Helper function to get a timer during early boot using device-tree for use |
| 173 | * as kernel system timer. Optionally, the property argument can be used to |
| 174 | * select a timer with a specific property. Once a timer is found then mark |
| 175 | * the timer node in device-tree as disabled, to prevent the kernel from |
| 176 | * registering this timer as a platform device and so no one else can use it. |
| 177 | */ |
| 178 | static struct device_node * __init omap_get_timer_dt(struct of_device_id *match, |
| 179 | const char *property) |
| 180 | { |
| 181 | struct device_node *np; |
| 182 | |
| 183 | for_each_matching_node(np, match) { |
| 184 | if (!of_device_is_available(np)) { |
| 185 | of_node_put(np); |
| 186 | continue; |
| 187 | } |
| 188 | |
| 189 | if (property && !of_get_property(np, property, NULL)) { |
| 190 | of_node_put(np); |
| 191 | continue; |
| 192 | } |
| 193 | |
| 194 | prom_add_property(np, &device_disabled); |
| 195 | return np; |
| 196 | } |
| 197 | |
| 198 | return NULL; |
| 199 | } |
| 200 | |
| 201 | /** |
Jon Hunter | ad24bde | 2012-06-20 15:55:24 -0500 | [diff] [blame] | 202 | * omap_dmtimer_init - initialisation function when device tree is used |
| 203 | * |
| 204 | * For secure OMAP3 devices, timers with device type "timer-secure" cannot |
| 205 | * be used by the kernel as they are reserved. Therefore, to prevent the |
| 206 | * kernel registering these devices remove them dynamically from the device |
| 207 | * tree on boot. |
| 208 | */ |
| 209 | void __init omap_dmtimer_init(void) |
| 210 | { |
| 211 | struct device_node *np; |
| 212 | |
| 213 | if (!cpu_is_omap34xx()) |
| 214 | return; |
| 215 | |
| 216 | /* If we are a secure device, remove any secure timer nodes */ |
| 217 | if ((omap_type() != OMAP2_DEVICE_TYPE_GP)) { |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 218 | np = omap_get_timer_dt(omap_timer_match, "ti,timer-secure"); |
| 219 | if (np) |
| 220 | of_node_put(np); |
Jon Hunter | ad24bde | 2012-06-20 15:55:24 -0500 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 224 | static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer, |
| 225 | int gptimer_id, |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 226 | const char *fck_source, |
| 227 | const char *property) |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 228 | { |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 229 | char name[10]; /* 10 = sizeof("gptXX_Xck0") */ |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 230 | const char *oh_name; |
| 231 | struct device_node *np; |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 232 | struct omap_hwmod *oh; |
Paul Walmsley | 6c0c27f | 2012-04-19 04:01:50 -0600 | [diff] [blame] | 233 | struct resource irq_rsrc, mem_rsrc; |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 234 | size_t size; |
| 235 | int res = 0; |
Paul Walmsley | 6c0c27f | 2012-04-19 04:01:50 -0600 | [diff] [blame] | 236 | int r; |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 237 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 238 | if (of_have_populated_dt()) { |
| 239 | np = omap_get_timer_dt(omap_timer_match, NULL); |
| 240 | if (!np) |
| 241 | return -ENODEV; |
| 242 | |
| 243 | of_property_read_string_index(np, "ti,hwmods", 0, &oh_name); |
| 244 | if (!oh_name) |
| 245 | return -ENODEV; |
| 246 | |
| 247 | timer->irq = irq_of_parse_and_map(np, 0); |
| 248 | if (!timer->irq) |
| 249 | return -ENXIO; |
| 250 | |
| 251 | timer->io_base = of_iomap(np, 0); |
| 252 | |
| 253 | of_node_put(np); |
| 254 | } else { |
| 255 | if (omap_dm_timer_reserve_systimer(gptimer_id)) |
| 256 | return -ENODEV; |
| 257 | |
| 258 | sprintf(name, "timer%d", gptimer_id); |
| 259 | oh_name = name; |
| 260 | } |
| 261 | |
| 262 | omap_hwmod_setup_one(oh_name); |
| 263 | oh = omap_hwmod_lookup(oh_name); |
| 264 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 265 | if (!oh) |
| 266 | return -ENODEV; |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 267 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 268 | if (!of_have_populated_dt()) { |
| 269 | r = omap_hwmod_get_resource_byname(oh, IORESOURCE_IRQ, NULL, |
| 270 | &irq_rsrc); |
| 271 | if (r) |
| 272 | return -ENXIO; |
| 273 | timer->irq = irq_rsrc.start; |
Paul Walmsley | 6c0c27f | 2012-04-19 04:01:50 -0600 | [diff] [blame] | 274 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 275 | r = omap_hwmod_get_resource_byname(oh, IORESOURCE_MEM, NULL, |
| 276 | &mem_rsrc); |
| 277 | if (r) |
| 278 | return -ENXIO; |
| 279 | timer->phys_base = mem_rsrc.start; |
| 280 | size = mem_rsrc.end - mem_rsrc.start; |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 281 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 282 | /* Static mapping, never released */ |
| 283 | timer->io_base = ioremap(timer->phys_base, size); |
| 284 | } |
| 285 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 286 | if (!timer->io_base) |
| 287 | return -ENXIO; |
| 288 | |
| 289 | /* After the dmtimer is using hwmod these clocks won't be needed */ |
Tarun Kanti DebBarma | ae6df41 | 2012-07-05 18:10:59 +0530 | [diff] [blame] | 290 | timer->fclk = clk_get(NULL, omap_hwmod_get_main_clk(oh)); |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 291 | if (IS_ERR(timer->fclk)) |
| 292 | return -ENODEV; |
| 293 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 294 | omap_hwmod_enable(oh); |
| 295 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 296 | /* FIXME: Need to remove hard-coded test on timer ID */ |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 297 | if (gptimer_id != 12) { |
| 298 | struct clk *src; |
| 299 | |
| 300 | src = clk_get(NULL, fck_source); |
| 301 | if (IS_ERR(src)) { |
| 302 | res = -EINVAL; |
| 303 | } else { |
| 304 | res = __omap_dm_timer_set_source(timer->fclk, src); |
| 305 | if (IS_ERR_VALUE(res)) |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 306 | pr_warn("%s: %s cannot set source\n", |
| 307 | __func__, oh->name); |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 308 | clk_put(src); |
| 309 | } |
| 310 | } |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 311 | __omap_dm_timer_init_regs(timer); |
| 312 | __omap_dm_timer_reset(timer, 1, 1); |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 313 | timer->posted = 1; |
| 314 | |
| 315 | timer->rate = clk_get_rate(timer->fclk); |
| 316 | |
| 317 | timer->reserved = 1; |
Paul Walmsley | 38698be | 2011-02-23 00:14:08 -0700 | [diff] [blame] | 318 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 319 | return res; |
| 320 | } |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 321 | |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 322 | static void __init omap2_gp_clockevent_init(int gptimer_id, |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 323 | const char *fck_source, |
| 324 | const char *property) |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 325 | { |
| 326 | int res; |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 327 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 328 | res = omap_dm_timer_init_one(&clkev, gptimer_id, fck_source, property); |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 329 | BUG_ON(res); |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 330 | |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 331 | omap2_gp_timer_irq.dev_id = &clkev; |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 332 | setup_irq(clkev.irq, &omap2_gp_timer_irq); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 333 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 334 | __omap_dm_timer_int_enable(&clkev, OMAP_TIMER_INT_OVERFLOW); |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 335 | |
| 336 | clockevent_gpt.mult = div_sc(clkev.rate, NSEC_PER_SEC, |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 337 | clockevent_gpt.shift); |
| 338 | clockevent_gpt.max_delta_ns = |
| 339 | clockevent_delta2ns(0xffffffff, &clockevent_gpt); |
| 340 | clockevent_gpt.min_delta_ns = |
Aaro Koskinen | df88acb | 2009-01-29 08:57:17 -0800 | [diff] [blame] | 341 | clockevent_delta2ns(3, &clockevent_gpt); |
| 342 | /* Timer internal resynch latency. */ |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 343 | |
Santosh Shilimkar | 11d6ec2 | 2012-03-17 15:00:16 +0530 | [diff] [blame] | 344 | clockevent_gpt.cpumask = cpu_possible_mask; |
| 345 | clockevent_gpt.irq = omap_dm_timer_get_irq(&clkev); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 346 | clockevents_register_device(&clockevent_gpt); |
Tony Lindgren | aa56188 | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 347 | |
| 348 | pr_info("OMAP clockevent source: GPTIMER%d at %lu Hz\n", |
| 349 | gptimer_id, clkev.rate); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Paul Walmsley | f248076 | 2009-04-23 21:11:10 -0600 | [diff] [blame] | 352 | /* Clocksource code */ |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 353 | static struct omap_dm_timer clksrc; |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 354 | static bool use_gptimer_clksrc; |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 355 | |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 356 | /* |
| 357 | * clocksource |
| 358 | */ |
Magnus Damm | 8e19608 | 2009-04-21 12:24:00 -0700 | [diff] [blame] | 359 | static cycle_t clocksource_read_cycles(struct clocksource *cs) |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 360 | { |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 361 | return (cycle_t)__omap_dm_timer_read_counter(&clksrc, 1); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static struct clocksource clocksource_gpt = { |
Vaibhav Hiremath | f36921b | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 365 | .name = "gp_timer", |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 366 | .rating = 300, |
| 367 | .read = clocksource_read_cycles, |
| 368 | .mask = CLOCKSOURCE_MASK(32), |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 369 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 370 | }; |
| 371 | |
Marc Zyngier | 2f0778af | 2011-12-15 12:19:23 +0100 | [diff] [blame] | 372 | static u32 notrace dmtimer_read_sched_clock(void) |
Paul Walmsley | cbc9438 | 2011-02-22 19:59:49 -0700 | [diff] [blame] | 373 | { |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 374 | if (clksrc.reserved) |
Vaibhav Hiremath | dbc3982 | 2012-01-23 12:18:14 +0530 | [diff] [blame] | 375 | return __omap_dm_timer_read_counter(&clksrc, 1); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 376 | |
Marc Zyngier | 2f0778af | 2011-12-15 12:19:23 +0100 | [diff] [blame] | 377 | return 0; |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 378 | } |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 379 | |
Igor Grinberg | 45caae7 | 2012-08-28 01:26:14 +0300 | [diff] [blame] | 380 | #ifdef CONFIG_OMAP_32K_TIMER |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 381 | /* Setup free-running counter for clocksource */ |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 382 | static int __init omap2_sync32k_clocksource_init(void) |
| 383 | { |
| 384 | int ret; |
Jon Hunter | 9883f7c | 2012-10-09 14:12:26 -0500 | [diff] [blame^] | 385 | struct device_node *np = NULL; |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 386 | struct omap_hwmod *oh; |
| 387 | void __iomem *vbase; |
| 388 | const char *oh_name = "counter_32k"; |
| 389 | |
| 390 | /* |
Jon Hunter | 9883f7c | 2012-10-09 14:12:26 -0500 | [diff] [blame^] | 391 | * If device-tree is present, then search the DT blob |
| 392 | * to see if the 32kHz counter is supported. |
| 393 | */ |
| 394 | if (of_have_populated_dt()) { |
| 395 | np = omap_get_timer_dt(omap_counter_match, NULL); |
| 396 | if (!np) |
| 397 | return -ENODEV; |
| 398 | |
| 399 | of_property_read_string_index(np, "ti,hwmods", 0, &oh_name); |
| 400 | if (!oh_name) |
| 401 | return -ENODEV; |
| 402 | } |
| 403 | |
| 404 | /* |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 405 | * First check hwmod data is available for sync32k counter |
| 406 | */ |
| 407 | oh = omap_hwmod_lookup(oh_name); |
| 408 | if (!oh || oh->slaves_cnt == 0) |
| 409 | return -ENODEV; |
| 410 | |
| 411 | omap_hwmod_setup_one(oh_name); |
| 412 | |
Jon Hunter | 9883f7c | 2012-10-09 14:12:26 -0500 | [diff] [blame^] | 413 | if (np) { |
| 414 | vbase = of_iomap(np, 0); |
| 415 | of_node_put(np); |
| 416 | } else { |
| 417 | vbase = omap_hwmod_get_mpu_rt_va(oh); |
| 418 | } |
| 419 | |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 420 | if (!vbase) { |
| 421 | pr_warn("%s: failed to get counter_32k resource\n", __func__); |
| 422 | return -ENXIO; |
| 423 | } |
| 424 | |
| 425 | ret = omap_hwmod_enable(oh); |
| 426 | if (ret) { |
| 427 | pr_warn("%s: failed to enable counter_32k module (%d)\n", |
| 428 | __func__, ret); |
| 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | ret = omap_init_clocksource_32k(vbase); |
| 433 | if (ret) { |
| 434 | pr_warn("%s: failed to initialize counter_32k as a clocksource (%d)\n", |
| 435 | __func__, ret); |
| 436 | omap_hwmod_idle(oh); |
| 437 | } |
| 438 | |
| 439 | return ret; |
| 440 | } |
Igor Grinberg | 45caae7 | 2012-08-28 01:26:14 +0300 | [diff] [blame] | 441 | #else |
| 442 | static inline int omap2_sync32k_clocksource_init(void) |
| 443 | { |
| 444 | return -ENODEV; |
| 445 | } |
| 446 | #endif |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 447 | |
| 448 | static void __init omap2_gptimer_clocksource_init(int gptimer_id, |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 449 | const char *fck_source) |
| 450 | { |
| 451 | int res; |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 452 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 453 | res = omap_dm_timer_init_one(&clksrc, gptimer_id, fck_source, NULL); |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 454 | BUG_ON(res); |
Paul Walmsley | cbc9438 | 2011-02-22 19:59:49 -0700 | [diff] [blame] | 455 | |
Tony Lindgren | ee17f11 | 2011-09-16 15:44:20 -0700 | [diff] [blame] | 456 | __omap_dm_timer_load_start(&clksrc, |
Hemant Pedanekar | e9d0b97 | 2011-08-10 13:19:35 +0000 | [diff] [blame] | 457 | OMAP_TIMER_CTRL_ST | OMAP_TIMER_CTRL_AR, 0, 1); |
Marc Zyngier | 2f0778af | 2011-12-15 12:19:23 +0100 | [diff] [blame] | 458 | setup_sched_clock(dmtimer_read_sched_clock, 32, clksrc.rate); |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 459 | |
| 460 | if (clocksource_register_hz(&clocksource_gpt, clksrc.rate)) |
| 461 | pr_err("Could not register clocksource %s\n", |
| 462 | clocksource_gpt.name); |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 463 | else |
| 464 | pr_info("OMAP clocksource: GPTIMER%d at %lu Hz\n", |
| 465 | gptimer_id, clksrc.rate); |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 466 | } |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 467 | |
| 468 | static void __init omap2_clocksource_init(int gptimer_id, |
| 469 | const char *fck_source) |
| 470 | { |
| 471 | /* |
| 472 | * First give preference to kernel parameter configuration |
| 473 | * by user (clocksource="gp_timer"). |
| 474 | * |
| 475 | * In case of missing kernel parameter for clocksource, |
| 476 | * first check for availability for 32k-sync timer, in case |
| 477 | * of failure in finding 32k_counter module or registering |
| 478 | * it as clocksource, execution will fallback to gp-timer. |
| 479 | */ |
| 480 | if (use_gptimer_clksrc == true) |
| 481 | omap2_gptimer_clocksource_init(gptimer_id, fck_source); |
| 482 | else if (omap2_sync32k_clocksource_init()) |
| 483 | /* Fall back to gp-timer code */ |
| 484 | omap2_gptimer_clocksource_init(gptimer_id, fck_source); |
| 485 | } |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 486 | |
Santosh Shilimkar | fa6d79d | 2012-08-13 14:24:24 +0530 | [diff] [blame] | 487 | #ifdef CONFIG_SOC_HAS_REALTIME_COUNTER |
| 488 | /* |
| 489 | * The realtime counter also called master counter, is a free-running |
| 490 | * counter, which is related to real time. It produces the count used |
| 491 | * by the CPU local timer peripherals in the MPU cluster. The timer counts |
| 492 | * at a rate of 6.144 MHz. Because the device operates on different clocks |
| 493 | * in different power modes, the master counter shifts operation between |
| 494 | * clocks, adjusting the increment per clock in hardware accordingly to |
| 495 | * maintain a constant count rate. |
| 496 | */ |
| 497 | static void __init realtime_counter_init(void) |
| 498 | { |
| 499 | void __iomem *base; |
| 500 | static struct clk *sys_clk; |
| 501 | unsigned long rate; |
| 502 | unsigned int reg, num, den; |
| 503 | |
| 504 | base = ioremap(REALTIME_COUNTER_BASE, SZ_32); |
| 505 | if (!base) { |
| 506 | pr_err("%s: ioremap failed\n", __func__); |
| 507 | return; |
| 508 | } |
| 509 | sys_clk = clk_get(NULL, "sys_clkin_ck"); |
Wei Yongjun | 533b298 | 2012-10-08 15:01:41 -0700 | [diff] [blame] | 510 | if (IS_ERR(sys_clk)) { |
Santosh Shilimkar | fa6d79d | 2012-08-13 14:24:24 +0530 | [diff] [blame] | 511 | pr_err("%s: failed to get system clock handle\n", __func__); |
| 512 | iounmap(base); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | rate = clk_get_rate(sys_clk); |
| 517 | /* Numerator/denumerator values refer TRM Realtime Counter section */ |
| 518 | switch (rate) { |
| 519 | case 1200000: |
| 520 | num = 64; |
| 521 | den = 125; |
| 522 | break; |
| 523 | case 1300000: |
| 524 | num = 768; |
| 525 | den = 1625; |
| 526 | break; |
| 527 | case 19200000: |
| 528 | num = 8; |
| 529 | den = 25; |
| 530 | break; |
| 531 | case 2600000: |
| 532 | num = 384; |
| 533 | den = 1625; |
| 534 | break; |
| 535 | case 2700000: |
| 536 | num = 256; |
| 537 | den = 1125; |
| 538 | break; |
| 539 | case 38400000: |
| 540 | default: |
| 541 | /* Program it for 38.4 MHz */ |
| 542 | num = 4; |
| 543 | den = 25; |
| 544 | break; |
| 545 | } |
| 546 | |
| 547 | /* Program numerator and denumerator registers */ |
| 548 | reg = __raw_readl(base + INCREMENTER_NUMERATOR_OFFSET) & |
| 549 | NUMERATOR_DENUMERATOR_MASK; |
| 550 | reg |= num; |
| 551 | __raw_writel(reg, base + INCREMENTER_NUMERATOR_OFFSET); |
| 552 | |
| 553 | reg = __raw_readl(base + INCREMENTER_NUMERATOR_OFFSET) & |
| 554 | NUMERATOR_DENUMERATOR_MASK; |
| 555 | reg |= den; |
| 556 | __raw_writel(reg, base + INCREMENTER_DENUMERATOR_RELOAD_OFFSET); |
| 557 | |
| 558 | iounmap(base); |
| 559 | } |
| 560 | #else |
| 561 | static inline void __init realtime_counter_init(void) |
| 562 | {} |
| 563 | #endif |
| 564 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 565 | #define OMAP_SYS_TIMER_INIT(name, clkev_nr, clkev_src, clkev_prop, \ |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 566 | clksrc_nr, clksrc_src) \ |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 567 | static void __init omap##name##_timer_init(void) \ |
| 568 | { \ |
Jon Hunter | ad24bde | 2012-06-20 15:55:24 -0500 | [diff] [blame] | 569 | omap_dmtimer_init(); \ |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 570 | omap2_gp_clockevent_init((clkev_nr), clkev_src, clkev_prop); \ |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 571 | omap2_clocksource_init((clksrc_nr), clksrc_src); \ |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | #define OMAP_SYS_TIMER(name) \ |
| 575 | struct sys_timer omap##name##_timer = { \ |
| 576 | .init = omap##name##_timer_init, \ |
| 577 | }; |
| 578 | |
| 579 | #ifdef CONFIG_ARCH_OMAP2 |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 580 | OMAP_SYS_TIMER_INIT(2, 1, OMAP2_CLKEV_SOURCE, "ti,timer-alwon", |
| 581 | 2, OMAP2_MPU_SOURCE) |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 582 | OMAP_SYS_TIMER(2) |
| 583 | #endif |
| 584 | |
| 585 | #ifdef CONFIG_ARCH_OMAP3 |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 586 | OMAP_SYS_TIMER_INIT(3, 1, OMAP3_CLKEV_SOURCE, "ti,timer-alwon", |
| 587 | 2, OMAP3_MPU_SOURCE) |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 588 | OMAP_SYS_TIMER(3) |
Tony Lindgren | 3d05a3e | 2011-03-29 15:54:49 -0700 | [diff] [blame] | 589 | OMAP_SYS_TIMER_INIT(3_secure, OMAP3_SECURE_TIMER, OMAP3_CLKEV_SOURCE, |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 590 | TIMER_PROP_SECURE, 2, OMAP3_MPU_SOURCE) |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 591 | OMAP_SYS_TIMER(3_secure) |
| 592 | #endif |
| 593 | |
Afzal Mohammed | 08f3098 | 2012-05-11 00:38:49 +0530 | [diff] [blame] | 594 | #ifdef CONFIG_SOC_AM33XX |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 595 | OMAP_SYS_TIMER_INIT(3_am33xx, 1, OMAP4_MPU_SOURCE, "ti,timer-alwon", |
| 596 | 2, OMAP4_MPU_SOURCE) |
Afzal Mohammed | 08f3098 | 2012-05-11 00:38:49 +0530 | [diff] [blame] | 597 | OMAP_SYS_TIMER(3_am33xx) |
| 598 | #endif |
| 599 | |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 600 | #ifdef CONFIG_ARCH_OMAP4 |
Marc Zyngier | a45c983 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 601 | #ifdef CONFIG_LOCAL_TIMERS |
| 602 | static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, |
Tony Lindgren | 3f216ef | 2012-10-16 11:19:16 -0700 | [diff] [blame] | 603 | OMAP44XX_LOCAL_TWD_BASE, 29); |
Marc Zyngier | a45c983 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 604 | #endif |
| 605 | |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 606 | static void __init omap4_timer_init(void) |
Kevin Hilman | 5a3a388 | 2007-11-12 23:24:02 -0800 | [diff] [blame] | 607 | { |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 608 | omap2_gp_clockevent_init(1, OMAP4_CLKEV_SOURCE, "ti,timer-alwon"); |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 609 | omap2_clocksource_init(2, OMAP4_MPU_SOURCE); |
Marc Zyngier | a45c983 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 610 | #ifdef CONFIG_LOCAL_TIMERS |
| 611 | /* Local timers are not supprted on OMAP4430 ES1.0 */ |
| 612 | if (omap_rev() != OMAP4430_REV_ES1_0) { |
| 613 | int err; |
| 614 | |
Santosh Shilimkar | eed0de2 | 2012-07-04 18:32:32 +0530 | [diff] [blame] | 615 | if (of_have_populated_dt()) { |
| 616 | twd_local_timer_of_register(); |
| 617 | return; |
| 618 | } |
| 619 | |
Marc Zyngier | a45c983 | 2012-01-10 19:44:19 +0000 | [diff] [blame] | 620 | err = twd_local_timer_register(&twd_local_timer); |
| 621 | if (err) |
| 622 | pr_err("twd_local_timer_register failed %d\n", err); |
| 623 | } |
| 624 | #endif |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 625 | } |
Tony Lindgren | e74984e | 2011-03-29 15:54:48 -0700 | [diff] [blame] | 626 | OMAP_SYS_TIMER(4) |
| 627 | #endif |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 628 | |
R Sricharan | 37b3280 | 2012-05-02 13:07:12 +0530 | [diff] [blame] | 629 | #ifdef CONFIG_SOC_OMAP5 |
Santosh Shilimkar | fa6d79d | 2012-08-13 14:24:24 +0530 | [diff] [blame] | 630 | static void __init omap5_timer_init(void) |
| 631 | { |
Santosh Shilimkar | 3c7c5da | 2012-08-13 14:39:03 +0530 | [diff] [blame] | 632 | int err; |
| 633 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 634 | omap2_gp_clockevent_init(1, OMAP4_CLKEV_SOURCE, "ti,timer-alwon"); |
Santosh Shilimkar | fa6d79d | 2012-08-13 14:24:24 +0530 | [diff] [blame] | 635 | omap2_clocksource_init(2, OMAP4_MPU_SOURCE); |
| 636 | realtime_counter_init(); |
Santosh Shilimkar | 3c7c5da | 2012-08-13 14:39:03 +0530 | [diff] [blame] | 637 | |
| 638 | err = arch_timer_of_register(); |
| 639 | if (err) |
| 640 | pr_err("%s: arch_timer_register failed %d\n", __func__, err); |
Santosh Shilimkar | fa6d79d | 2012-08-13 14:24:24 +0530 | [diff] [blame] | 641 | } |
R Sricharan | 37b3280 | 2012-05-02 13:07:12 +0530 | [diff] [blame] | 642 | OMAP_SYS_TIMER(5) |
| 643 | #endif |
| 644 | |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 645 | /** |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 646 | * omap_timer_init - build and register timer device with an |
| 647 | * associated timer hwmod |
| 648 | * @oh: timer hwmod pointer to be used to build timer device |
| 649 | * @user: parameter that can be passed from calling hwmod API |
| 650 | * |
| 651 | * Called by omap_hwmod_for_each_by_class to register each of the timer |
| 652 | * devices present in the system. The number of timer devices is known |
| 653 | * by parsing through the hwmod database for a given class name. At the |
| 654 | * end of function call memory is allocated for timer device and it is |
| 655 | * registered to the framework ready to be proved by the driver. |
| 656 | */ |
| 657 | static int __init omap_timer_init(struct omap_hwmod *oh, void *unused) |
| 658 | { |
| 659 | int id; |
| 660 | int ret = 0; |
| 661 | char *name = "omap_timer"; |
| 662 | struct dmtimer_platform_data *pdata; |
Tony Lindgren | c541c15 | 2011-10-04 09:47:06 -0700 | [diff] [blame] | 663 | struct platform_device *pdev; |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 664 | struct omap_timer_capability_dev_attr *timer_dev_attr; |
| 665 | |
| 666 | pr_debug("%s: %s\n", __func__, oh->name); |
| 667 | |
| 668 | /* on secure device, do not register secure timer */ |
| 669 | timer_dev_attr = oh->dev_attr; |
| 670 | if (omap_type() != OMAP2_DEVICE_TYPE_GP && timer_dev_attr) |
| 671 | if (timer_dev_attr->timer_capability == OMAP_TIMER_SECURE) |
| 672 | return ret; |
| 673 | |
| 674 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
| 675 | if (!pdata) { |
| 676 | pr_err("%s: No memory for [%s]\n", __func__, oh->name); |
| 677 | return -ENOMEM; |
| 678 | } |
| 679 | |
| 680 | /* |
| 681 | * Extract the IDs from name field in hwmod database |
| 682 | * and use the same for constructing ids' for the |
| 683 | * timer devices. In a way, we are avoiding usage of |
| 684 | * static variable witin the function to do the same. |
| 685 | * CAUTION: We have to be careful and make sure the |
| 686 | * name in hwmod database does not change in which case |
| 687 | * we might either make corresponding change here or |
| 688 | * switch back static variable mechanism. |
| 689 | */ |
| 690 | sscanf(oh->name, "timer%2d", &id); |
| 691 | |
Jon Hunter | d1c1691 | 2012-06-05 12:34:52 -0500 | [diff] [blame] | 692 | if (timer_dev_attr) |
| 693 | pdata->timer_capability = timer_dev_attr->timer_capability; |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 694 | |
Tony Lindgren | c541c15 | 2011-10-04 09:47:06 -0700 | [diff] [blame] | 695 | pdev = omap_device_build(name, id, oh, pdata, sizeof(*pdata), |
Benoit Cousson | c16ae1e | 2011-10-04 23:20:41 +0200 | [diff] [blame] | 696 | NULL, 0, 0); |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 697 | |
Tony Lindgren | c541c15 | 2011-10-04 09:47:06 -0700 | [diff] [blame] | 698 | if (IS_ERR(pdev)) { |
Tarun Kanti DebBarma | c345c8b | 2011-09-20 17:00:18 +0530 | [diff] [blame] | 699 | pr_err("%s: Can't build omap_device for %s: %s.\n", |
| 700 | __func__, name, oh->name); |
| 701 | ret = -EINVAL; |
| 702 | } |
| 703 | |
| 704 | kfree(pdata); |
| 705 | |
| 706 | return ret; |
| 707 | } |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 708 | |
| 709 | /** |
| 710 | * omap2_dm_timer_init - top level regular device initialization |
| 711 | * |
| 712 | * Uses dedicated hwmod api to parse through hwmod database for |
| 713 | * given class name and then build and register the timer device. |
| 714 | */ |
| 715 | static int __init omap2_dm_timer_init(void) |
| 716 | { |
| 717 | int ret; |
| 718 | |
Jon Hunter | 9725f44 | 2012-05-14 10:41:37 -0500 | [diff] [blame] | 719 | /* If dtb is there, the devices will be created dynamically */ |
| 720 | if (of_have_populated_dt()) |
| 721 | return -ENODEV; |
| 722 | |
Tarun Kanti DebBarma | 3392cdd | 2011-09-20 17:00:20 +0530 | [diff] [blame] | 723 | ret = omap_hwmod_for_each_by_class("timer", omap_timer_init, NULL); |
| 724 | if (unlikely(ret)) { |
| 725 | pr_err("%s: device registration failed.\n", __func__); |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | arch_initcall(omap2_dm_timer_init); |
Vaibhav Hiremath | 1fe97c8 | 2012-05-09 10:07:05 -0700 | [diff] [blame] | 732 | |
| 733 | /** |
| 734 | * omap2_override_clocksource - clocksource override with user configuration |
| 735 | * |
| 736 | * Allows user to override default clocksource, using kernel parameter |
| 737 | * clocksource="gp_timer" (For all OMAP2PLUS architectures) |
| 738 | * |
| 739 | * Note that, here we are using same standard kernel parameter "clocksource=", |
| 740 | * and not introducing any OMAP specific interface. |
| 741 | */ |
| 742 | static int __init omap2_override_clocksource(char *str) |
| 743 | { |
| 744 | if (!str) |
| 745 | return 0; |
| 746 | /* |
| 747 | * For OMAP architecture, we only have two options |
| 748 | * - sync_32k (default) |
| 749 | * - gp_timer (sys_clk based) |
| 750 | */ |
| 751 | if (!strcmp(str, "gp_timer")) |
| 752 | use_gptimer_clksrc = true; |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | early_param("clocksource", omap2_override_clocksource); |