Greg Ungerer | 75003c4 | 2005-09-09 09:32:14 +1000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * linux/arch/m68knommu/platform/68328/timers.c |
| 5 | * |
| 6 | * Copyright (C) 1993 Hamish Macdonald |
| 7 | * Copyright (C) 1999 D. Jeff Dionne |
| 8 | * Copyright (C) 2001 Georges Menie, Ken Desmet |
| 9 | * |
| 10 | * This file is subject to the terms and conditions of the GNU General Public |
| 11 | * License. See the file COPYING in the main directory of this archive |
| 12 | * for more details. |
| 13 | */ |
| 14 | |
| 15 | /***************************************************************************/ |
| 16 | |
Greg Ungerer | 75003c4 | 2005-09-09 09:32:14 +1000 | [diff] [blame] | 17 | #include <linux/types.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/mm.h> |
Greg Ungerer | 1ea9acc | 2007-03-07 11:28:13 +1000 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
Greg Ungerer | be03e56 | 2007-07-27 01:09:00 +1000 | [diff] [blame] | 21 | #include <linux/irq.h> |
Greg Ungerer | 36a90f2 | 2008-02-01 17:40:17 +1000 | [diff] [blame] | 22 | #include <linux/clocksource.h> |
Greg Ungerer | 75003c4 | 2005-09-09 09:32:14 +1000 | [diff] [blame] | 23 | #include <asm/setup.h> |
| 24 | #include <asm/system.h> |
| 25 | #include <asm/pgtable.h> |
Greg Ungerer | 75003c4 | 2005-09-09 09:32:14 +1000 | [diff] [blame] | 26 | #include <asm/machdep.h> |
| 27 | #include <asm/MC68VZ328.h> |
| 28 | |
| 29 | /***************************************************************************/ |
| 30 | |
| 31 | #if defined(CONFIG_DRAGEN2) |
| 32 | /* with a 33.16 MHz clock, this will give usec resolution to the time functions */ |
| 33 | #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK |
| 34 | #define CLOCK_PRE 7 |
| 35 | #define TICKS_PER_JIFFY 41450 |
| 36 | |
| 37 | #elif defined(CONFIG_XCOPILOT_BUGS) |
| 38 | /* |
| 39 | * The only thing I know is that CLK32 is not available on Xcopilot |
| 40 | * I have little idea about what frequency SYSCLK has on Xcopilot. |
| 41 | * The values for prescaler and compare registers were simply |
| 42 | * taken from the original source |
| 43 | */ |
| 44 | #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK |
| 45 | #define CLOCK_PRE 2 |
| 46 | #define TICKS_PER_JIFFY 0xd7e4 |
| 47 | |
| 48 | #else |
| 49 | /* default to using the 32Khz clock */ |
| 50 | #define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ |
| 51 | #define CLOCK_PRE 31 |
| 52 | #define TICKS_PER_JIFFY 10 |
| 53 | #endif |
| 54 | |
Greg Ungerer | 36a90f2 | 2008-02-01 17:40:17 +1000 | [diff] [blame] | 55 | static u32 m68328_tick_cnt; |
| 56 | |
| 57 | /***************************************************************************/ |
| 58 | |
| 59 | static irqreturn_t hw_tick(int irq, void *dummy) |
| 60 | { |
| 61 | /* Reset Timer1 */ |
| 62 | TSTAT &= 0; |
| 63 | |
| 64 | m68328_tick_cnt += TICKS_PER_JIFFY; |
| 65 | return arch_timer_interrupt(irq, dummy); |
| 66 | } |
| 67 | |
Greg Ungerer | 75003c4 | 2005-09-09 09:32:14 +1000 | [diff] [blame] | 68 | /***************************************************************************/ |
| 69 | |
Greg Ungerer | 8467571 | 2007-10-24 12:03:20 +1000 | [diff] [blame] | 70 | static irqreturn_t hw_tick(int irq, void *dummy) |
| 71 | { |
| 72 | /* Reset Timer1 */ |
| 73 | TSTAT &= 0; |
| 74 | |
| 75 | return arch_timer_interrupt(irq, dummy); |
| 76 | } |
| 77 | |
| 78 | /***************************************************************************/ |
| 79 | |
Greg Ungerer | be03e56 | 2007-07-27 01:09:00 +1000 | [diff] [blame] | 80 | static struct irqaction m68328_timer_irq = { |
Greg Ungerer | 8467571 | 2007-10-24 12:03:20 +1000 | [diff] [blame] | 81 | .name = "timer", |
| 82 | .flags = IRQF_DISABLED | IRQF_TIMER, |
| 83 | .handler = hw_tick, |
Greg Ungerer | be03e56 | 2007-07-27 01:09:00 +1000 | [diff] [blame] | 84 | }; |
| 85 | |
Greg Ungerer | 36a90f2 | 2008-02-01 17:40:17 +1000 | [diff] [blame] | 86 | /***************************************************************************/ |
| 87 | |
| 88 | static cycle_t m68328_read_clk(void) |
| 89 | { |
| 90 | unsigned long flags; |
| 91 | u32 cycles; |
| 92 | |
| 93 | local_irq_save(flags); |
| 94 | cycles = m68328_tick_cnt + TCN; |
| 95 | local_irq_restore(flags); |
| 96 | |
| 97 | return cycles; |
| 98 | } |
| 99 | |
| 100 | /***************************************************************************/ |
| 101 | |
| 102 | static struct clocksource m68328_clk = { |
| 103 | .name = "timer", |
| 104 | .rating = 250, |
| 105 | .read = m68328_read_clk, |
| 106 | .shift = 20, |
| 107 | .mask = CLOCKSOURCE_MASK(32), |
| 108 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 109 | }; |
| 110 | |
| 111 | /***************************************************************************/ |
| 112 | |
Greg Ungerer | 8467571 | 2007-10-24 12:03:20 +1000 | [diff] [blame] | 113 | void hw_timer_init(void) |
Greg Ungerer | 75003c4 | 2005-09-09 09:32:14 +1000 | [diff] [blame] | 114 | { |
| 115 | /* disable timer 1 */ |
| 116 | TCTL = 0; |
| 117 | |
| 118 | /* set ISR */ |
Greg Ungerer | be03e56 | 2007-07-27 01:09:00 +1000 | [diff] [blame] | 119 | setup_irq(TMR_IRQ_NUM, &m68328_timer_irq); |
Greg Ungerer | 75003c4 | 2005-09-09 09:32:14 +1000 | [diff] [blame] | 120 | |
| 121 | /* Restart mode, Enable int, Set clock source */ |
| 122 | TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE; |
| 123 | TPRER = CLOCK_PRE; |
| 124 | TCMP = TICKS_PER_JIFFY; |
| 125 | |
| 126 | /* Enable timer 1 */ |
| 127 | TCTL |= TCTL_TEN; |
Greg Ungerer | 36a90f2 | 2008-02-01 17:40:17 +1000 | [diff] [blame] | 128 | m68328_clk.mult = clocksource_hz2mult(TICKS_PER_JIFFY*HZ, m68328_clk.shift); |
| 129 | clocksource_register(&m68328_clk); |
Greg Ungerer | 75003c4 | 2005-09-09 09:32:14 +1000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /***************************************************************************/ |
| 133 | |
| 134 | void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec) |
| 135 | { |
| 136 | long now = RTCTIME; |
| 137 | |
| 138 | *year = *mon = *day = 1; |
| 139 | *hour = (now >> 24) % 24; |
| 140 | *min = (now >> 16) % 60; |
| 141 | *sec = now % 60; |
| 142 | } |
| 143 | |
| 144 | /***************************************************************************/ |