aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-omap2/timer.c')
-rw-r--r--arch/arm/mach-omap2/timer.c194
1 files changed, 182 insertions, 12 deletions
diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c
index cf1de7d2630d..e49fc7be2229 100644
--- a/arch/arm/mach-omap2/timer.c
+++ b/arch/arm/mach-omap2/timer.c
@@ -35,6 +35,7 @@
35#include <linux/irq.h> 35#include <linux/irq.h>
36#include <linux/clocksource.h> 36#include <linux/clocksource.h>
37#include <linux/clockchips.h> 37#include <linux/clockchips.h>
38#include <linux/slab.h>
38 39
39#include <asm/mach/time.h> 40#include <asm/mach/time.h>
40#include <plat/dmtimer.h> 41#include <plat/dmtimer.h>
@@ -42,6 +43,10 @@
42#include <asm/sched_clock.h> 43#include <asm/sched_clock.h>
43#include <plat/common.h> 44#include <plat/common.h>
44#include <plat/omap_hwmod.h> 45#include <plat/omap_hwmod.h>
46#include <plat/omap_device.h>
47#include <plat/omap-pm.h>
48
49#include "powerdomain.h"
45 50
46/* Parent clocks, eventually these will come from the clock framework */ 51/* Parent clocks, eventually these will come from the clock framework */
47 52
@@ -67,7 +72,7 @@
67/* MAX_GPTIMER_ID: number of GPTIMERs on the chip */ 72/* MAX_GPTIMER_ID: number of GPTIMERs on the chip */
68#define MAX_GPTIMER_ID 12 73#define MAX_GPTIMER_ID 12
69 74
70u32 sys_timer_reserved; 75static u32 sys_timer_reserved;
71 76
72/* Clockevent code */ 77/* Clockevent code */
73 78
@@ -78,7 +83,7 @@ static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id)
78{ 83{
79 struct clock_event_device *evt = &clockevent_gpt; 84 struct clock_event_device *evt = &clockevent_gpt;
80 85
81 __omap_dm_timer_write_status(clkev.io_base, OMAP_TIMER_INT_OVERFLOW); 86 __omap_dm_timer_write_status(&clkev, OMAP_TIMER_INT_OVERFLOW);
82 87
83 evt->event_handler(evt); 88 evt->event_handler(evt);
84 return IRQ_HANDLED; 89 return IRQ_HANDLED;
@@ -93,7 +98,7 @@ static struct irqaction omap2_gp_timer_irq = {
93static int omap2_gp_timer_set_next_event(unsigned long cycles, 98static int omap2_gp_timer_set_next_event(unsigned long cycles,
94 struct clock_event_device *evt) 99 struct clock_event_device *evt)
95{ 100{
96 __omap_dm_timer_load_start(clkev.io_base, OMAP_TIMER_CTRL_ST, 101 __omap_dm_timer_load_start(&clkev, OMAP_TIMER_CTRL_ST,
97 0xffffffff - cycles, 1); 102 0xffffffff - cycles, 1);
98 103
99 return 0; 104 return 0;
@@ -104,16 +109,16 @@ static void omap2_gp_timer_set_mode(enum clock_event_mode mode,
104{ 109{
105 u32 period; 110 u32 period;
106 111
107 __omap_dm_timer_stop(clkev.io_base, 1, clkev.rate); 112 __omap_dm_timer_stop(&clkev, 1, clkev.rate);
108 113
109 switch (mode) { 114 switch (mode) {
110 case CLOCK_EVT_MODE_PERIODIC: 115 case CLOCK_EVT_MODE_PERIODIC:
111 period = clkev.rate / HZ; 116 period = clkev.rate / HZ;
112 period -= 1; 117 period -= 1;
113 /* Looks like we need to first set the load value separately */ 118 /* Looks like we need to first set the load value separately */
114 __omap_dm_timer_write(clkev.io_base, OMAP_TIMER_LOAD_REG, 119 __omap_dm_timer_write(&clkev, OMAP_TIMER_LOAD_REG,
115 0xffffffff - period, 1); 120 0xffffffff - period, 1);
116 __omap_dm_timer_load_start(clkev.io_base, 121 __omap_dm_timer_load_start(&clkev,
117 OMAP_TIMER_CTRL_AR | OMAP_TIMER_CTRL_ST, 122 OMAP_TIMER_CTRL_AR | OMAP_TIMER_CTRL_ST,
118 0xffffffff - period, 1); 123 0xffffffff - period, 1);
119 break; 124 break;
@@ -189,7 +194,8 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
189 clk_put(src); 194 clk_put(src);
190 } 195 }
191 } 196 }
192 __omap_dm_timer_reset(timer->io_base, 1, 1); 197 __omap_dm_timer_init_regs(timer);
198 __omap_dm_timer_reset(timer, 1, 1);
193 timer->posted = 1; 199 timer->posted = 1;
194 200
195 timer->rate = clk_get_rate(timer->fclk); 201 timer->rate = clk_get_rate(timer->fclk);
@@ -210,7 +216,7 @@ static void __init omap2_gp_clockevent_init(int gptimer_id,
210 omap2_gp_timer_irq.dev_id = (void *)&clkev; 216 omap2_gp_timer_irq.dev_id = (void *)&clkev;
211 setup_irq(clkev.irq, &omap2_gp_timer_irq); 217 setup_irq(clkev.irq, &omap2_gp_timer_irq);
212 218
213 __omap_dm_timer_int_enable(clkev.io_base, OMAP_TIMER_INT_OVERFLOW); 219 __omap_dm_timer_int_enable(&clkev, OMAP_TIMER_INT_OVERFLOW);
214 220
215 clockevent_gpt.mult = div_sc(clkev.rate, NSEC_PER_SEC, 221 clockevent_gpt.mult = div_sc(clkev.rate, NSEC_PER_SEC,
216 clockevent_gpt.shift); 222 clockevent_gpt.shift);
@@ -251,7 +257,7 @@ static struct omap_dm_timer clksrc;
251static DEFINE_CLOCK_DATA(cd); 257static DEFINE_CLOCK_DATA(cd);
252static cycle_t clocksource_read_cycles(struct clocksource *cs) 258static cycle_t clocksource_read_cycles(struct clocksource *cs)
253{ 259{
254 return (cycle_t)__omap_dm_timer_read_counter(clksrc.io_base, 1); 260 return (cycle_t)__omap_dm_timer_read_counter(&clksrc, 1);
255} 261}
256 262
257static struct clocksource clocksource_gpt = { 263static struct clocksource clocksource_gpt = {
@@ -266,7 +272,7 @@ static void notrace dmtimer_update_sched_clock(void)
266{ 272{
267 u32 cyc; 273 u32 cyc;
268 274
269 cyc = __omap_dm_timer_read_counter(clksrc.io_base, 1); 275 cyc = __omap_dm_timer_read_counter(&clksrc, 1);
270 276
271 update_sched_clock(&cd, cyc, (u32)~0); 277 update_sched_clock(&cd, cyc, (u32)~0);
272} 278}
@@ -276,7 +282,7 @@ unsigned long long notrace sched_clock(void)
276 u32 cyc = 0; 282 u32 cyc = 0;
277 283
278 if (clksrc.reserved) 284 if (clksrc.reserved)
279 cyc = __omap_dm_timer_read_counter(clksrc.io_base, 1); 285 cyc = __omap_dm_timer_read_counter(&clksrc, 1);
280 286
281 return cyc_to_sched_clock(&cd, cyc, (u32)~0); 287 return cyc_to_sched_clock(&cd, cyc, (u32)~0);
282} 288}
@@ -293,7 +299,7 @@ static void __init omap2_gp_clocksource_init(int gptimer_id,
293 pr_info("OMAP clocksource: GPTIMER%d at %lu Hz\n", 299 pr_info("OMAP clocksource: GPTIMER%d at %lu Hz\n",
294 gptimer_id, clksrc.rate); 300 gptimer_id, clksrc.rate);
295 301
296 __omap_dm_timer_load_start(clksrc.io_base, 302 __omap_dm_timer_load_start(&clksrc,
297 OMAP_TIMER_CTRL_ST | OMAP_TIMER_CTRL_AR, 0, 1); 303 OMAP_TIMER_CTRL_ST | OMAP_TIMER_CTRL_AR, 0, 1);
298 init_sched_clock(&cd, dmtimer_update_sched_clock, 32, clksrc.rate); 304 init_sched_clock(&cd, dmtimer_update_sched_clock, 32, clksrc.rate);
299 305
@@ -341,3 +347,167 @@ static void __init omap4_timer_init(void)
341} 347}
342OMAP_SYS_TIMER(4) 348OMAP_SYS_TIMER(4)
343#endif 349#endif
350
351/**
352 * omap2_dm_timer_set_src - change the timer input clock source
353 * @pdev: timer platform device pointer
354 * @source: array index of parent clock source
355 */
356static int omap2_dm_timer_set_src(struct platform_device *pdev, int source)
357{
358 int ret;
359 struct dmtimer_platform_data *pdata = pdev->dev.platform_data;
360 struct clk *fclk, *parent;
361 char *parent_name = NULL;
362
363 fclk = clk_get(&pdev->dev, "fck");
364 if (IS_ERR_OR_NULL(fclk)) {
365 dev_err(&pdev->dev, "%s: %d: clk_get() FAILED\n",
366 __func__, __LINE__);
367 return -EINVAL;
368 }
369
370 switch (source) {
371 case OMAP_TIMER_SRC_SYS_CLK:
372 parent_name = "sys_ck";
373 break;
374
375 case OMAP_TIMER_SRC_32_KHZ:
376 parent_name = "32k_ck";
377 break;
378
379 case OMAP_TIMER_SRC_EXT_CLK:
380 if (pdata->timer_ip_version == OMAP_TIMER_IP_VERSION_1) {
381 parent_name = "alt_ck";
382 break;
383 }
384 dev_err(&pdev->dev, "%s: %d: invalid clk src.\n",
385 __func__, __LINE__);
386 clk_put(fclk);
387 return -EINVAL;
388 }
389
390 parent = clk_get(&pdev->dev, parent_name);
391 if (IS_ERR_OR_NULL(parent)) {
392 dev_err(&pdev->dev, "%s: %d: clk_get() %s FAILED\n",
393 __func__, __LINE__, parent_name);
394 clk_put(fclk);
395 return -EINVAL;
396 }
397
398 ret = clk_set_parent(fclk, parent);
399 if (IS_ERR_VALUE(ret)) {
400 dev_err(&pdev->dev, "%s: clk_set_parent() to %s FAILED\n",
401 __func__, parent_name);
402 ret = -EINVAL;
403 }
404
405 clk_put(parent);
406 clk_put(fclk);
407
408 return ret;
409}
410
411struct omap_device_pm_latency omap2_dmtimer_latency[] = {
412 {
413 .deactivate_func = omap_device_idle_hwmods,
414 .activate_func = omap_device_enable_hwmods,
415 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
416 },
417};
418
419/**
420 * omap_timer_init - build and register timer device with an
421 * associated timer hwmod
422 * @oh: timer hwmod pointer to be used to build timer device
423 * @user: parameter that can be passed from calling hwmod API
424 *
425 * Called by omap_hwmod_for_each_by_class to register each of the timer
426 * devices present in the system. The number of timer devices is known
427 * by parsing through the hwmod database for a given class name. At the
428 * end of function call memory is allocated for timer device and it is
429 * registered to the framework ready to be proved by the driver.
430 */
431static int __init omap_timer_init(struct omap_hwmod *oh, void *unused)
432{
433 int id;
434 int ret = 0;
435 char *name = "omap_timer";
436 struct dmtimer_platform_data *pdata;
437 struct platform_device *pdev;
438 struct omap_timer_capability_dev_attr *timer_dev_attr;
439 struct powerdomain *pwrdm;
440
441 pr_debug("%s: %s\n", __func__, oh->name);
442
443 /* on secure device, do not register secure timer */
444 timer_dev_attr = oh->dev_attr;
445 if (omap_type() != OMAP2_DEVICE_TYPE_GP && timer_dev_attr)
446 if (timer_dev_attr->timer_capability == OMAP_TIMER_SECURE)
447 return ret;
448
449 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
450 if (!pdata) {
451 pr_err("%s: No memory for [%s]\n", __func__, oh->name);
452 return -ENOMEM;
453 }
454
455 /*
456 * Extract the IDs from name field in hwmod database
457 * and use the same for constructing ids' for the
458 * timer devices. In a way, we are avoiding usage of
459 * static variable witin the function to do the same.
460 * CAUTION: We have to be careful and make sure the
461 * name in hwmod database does not change in which case
462 * we might either make corresponding change here or
463 * switch back static variable mechanism.
464 */
465 sscanf(oh->name, "timer%2d", &id);
466
467 pdata->set_timer_src = omap2_dm_timer_set_src;
468 pdata->timer_ip_version = oh->class->rev;
469
470 /* Mark clocksource and clockevent timers as reserved */
471 if ((sys_timer_reserved >> (id - 1)) & 0x1)
472 pdata->reserved = 1;
473
474 pwrdm = omap_hwmod_get_pwrdm(oh);
475 pdata->loses_context = pwrdm_can_ever_lose_context(pwrdm);
476#ifdef CONFIG_PM
477 pdata->get_context_loss_count = omap_pm_get_dev_context_loss_count;
478#endif
479 pdev = omap_device_build(name, id, oh, pdata, sizeof(*pdata),
480 omap2_dmtimer_latency,
481 ARRAY_SIZE(omap2_dmtimer_latency),
482 0);
483
484 if (IS_ERR(pdev)) {
485 pr_err("%s: Can't build omap_device for %s: %s.\n",
486 __func__, name, oh->name);
487 ret = -EINVAL;
488 }
489
490 kfree(pdata);
491
492 return ret;
493}
494
495/**
496 * omap2_dm_timer_init - top level regular device initialization
497 *
498 * Uses dedicated hwmod api to parse through hwmod database for
499 * given class name and then build and register the timer device.
500 */
501static int __init omap2_dm_timer_init(void)
502{
503 int ret;
504
505 ret = omap_hwmod_for_each_by_class("timer", omap_timer_init, NULL);
506 if (unlikely(ret)) {
507 pr_err("%s: device registration failed.\n", __func__);
508 return -EINVAL;
509 }
510
511 return 0;
512}
513arch_initcall(omap2_dm_timer_init);