Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * timers.c -- generic ColdFire hardware timer support. |
| 5 | * |
| 6 | * Copyright (C) 1999-2003, Greg Ungerer (gerg@snapgear.com) |
| 7 | */ |
| 8 | |
| 9 | /***************************************************************************/ |
| 10 | |
| 11 | #include <linux/config.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/param.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/init.h> |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 17 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/irq.h> |
| 19 | #include <asm/traps.h> |
| 20 | #include <asm/machdep.h> |
| 21 | #include <asm/coldfire.h> |
| 22 | #include <asm/mcftimer.h> |
| 23 | #include <asm/mcfsim.h> |
| 24 | |
| 25 | /***************************************************************************/ |
| 26 | |
| 27 | /* |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 28 | * By default use timer1 as the system clock timer. |
| 29 | */ |
| 30 | #define TA(a) (MCF_MBAR + MCFTIMER_BASE1 + (a)) |
| 31 | |
| 32 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * Default the timer and vector to use for ColdFire. Some ColdFire |
| 34 | * CPU's and some boards may want different. Their sub-architecture |
| 35 | * startup code (in config.c) can change these if they want. |
| 36 | */ |
| 37 | unsigned int mcf_timervector = 29; |
| 38 | unsigned int mcf_profilevector = 31; |
| 39 | unsigned int mcf_timerlevel = 5; |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* |
| 42 | * These provide the underlying interrupt vector support. |
| 43 | * Unfortunately it is a little different on each ColdFire. |
| 44 | */ |
| 45 | extern void mcf_settimericr(int timer, int level); |
| 46 | extern int mcf_timerirqpending(int timer); |
| 47 | |
| 48 | /***************************************************************************/ |
| 49 | |
| 50 | void coldfire_tick(void) |
| 51 | { |
| 52 | /* Reset the ColdFire timer */ |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 53 | __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, TA(MCFTIMER_TER)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /***************************************************************************/ |
| 57 | |
| 58 | void coldfire_timer_init(irqreturn_t (*handler)(int, void *, struct pt_regs *)) |
| 59 | { |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 60 | __raw_writew(MCFTIMER_TMR_DISABLE, TA(MCFTIMER_TMR)); |
| 61 | __raw_writew(((MCF_BUSCLK / 16) / HZ), TA(MCFTIMER_TRR)); |
| 62 | __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 | |
| 63 | MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, TA(MCFTIMER_TMR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | request_irq(mcf_timervector, handler, SA_INTERRUPT, "timer", NULL); |
| 66 | mcf_settimericr(1, mcf_timerlevel); |
| 67 | |
| 68 | #ifdef CONFIG_HIGHPROFILE |
| 69 | coldfire_profile_init(); |
| 70 | #endif |
| 71 | } |
| 72 | |
| 73 | /***************************************************************************/ |
| 74 | |
| 75 | unsigned long coldfire_timer_offset(void) |
| 76 | { |
| 77 | unsigned long trr, tcn, offset; |
| 78 | |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 79 | tcn = __raw_readw(TA(MCFTIMER_TCN)); |
| 80 | trr = __raw_readw(TA(MCFTIMER_TRR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | offset = (tcn * (1000000 / HZ)) / trr; |
| 82 | |
| 83 | /* Check if we just wrapped the counters and maybe missed a tick */ |
| 84 | if ((offset < (1000000 / HZ / 2)) && mcf_timerirqpending(1)) |
| 85 | offset += 1000000 / HZ; |
| 86 | return offset; |
| 87 | } |
| 88 | |
| 89 | /***************************************************************************/ |
| 90 | #ifdef CONFIG_HIGHPROFILE |
| 91 | /***************************************************************************/ |
| 92 | |
| 93 | /* |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 94 | * By default use timer2 as the profiler clock timer. |
| 95 | */ |
| 96 | #define PA(a) (MCF_MBAR + MCFTIMER_BASE2 + (a)) |
| 97 | |
| 98 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | * Choose a reasonably fast profile timer. Make it an odd value to |
| 100 | * try and get good coverage of kernal operations. |
| 101 | */ |
| 102 | #define PROFILEHZ 1013 |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* |
| 105 | * Use the other timer to provide high accuracy profiling info. |
| 106 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | void coldfire_profile_tick(int irq, void *dummy, struct pt_regs *regs) |
| 108 | { |
| 109 | /* Reset ColdFire timer2 */ |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 110 | __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, PA(MCFTIMER_TER)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | if (current->pid) |
| 112 | profile_tick(CPU_PROFILING, regs); |
| 113 | } |
| 114 | |
| 115 | /***************************************************************************/ |
| 116 | |
| 117 | void coldfire_profile_init(void) |
| 118 | { |
| 119 | printk(KERN_INFO "PROFILE: lodging TIMER2 @ %dHz as profile timer\n", PROFILEHZ); |
| 120 | |
| 121 | /* Set up TIMER 2 as high speed profile clock */ |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 122 | __raw_writew(MCFTIMER_TMR_DISABLE, PA(MCFTIMER_TMR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Greg Ungerer | 0b7ac8e | 2006-06-26 10:33:10 +1000 | [diff] [blame^] | 124 | __raw_writew(((MCF_CLK / 16) / PROFILEHZ), PA(MCFTIMER_TRR)); |
| 125 | __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 | |
| 126 | MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, PA(MCFTIMER_TMR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | request_irq(mcf_profilevector, coldfire_profile_tick, |
| 129 | (SA_INTERRUPT | IRQ_FLG_FAST), "profile timer", NULL); |
| 130 | mcf_settimericr(2, 7); |
| 131 | } |
| 132 | |
| 133 | /***************************************************************************/ |
| 134 | #endif /* CONFIG_HIGHPROFILE */ |
| 135 | /***************************************************************************/ |