Commit | Line | Data |
---|---|---|
75003c48 GU |
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 | ||
75003c48 GU |
17 | #include <linux/types.h> |
18 | #include <linux/kernel.h> | |
19 | #include <linux/mm.h> | |
1ea9acc7 | 20 | #include <linux/interrupt.h> |
be03e56b | 21 | #include <linux/irq.h> |
75003c48 GU |
22 | #include <asm/setup.h> |
23 | #include <asm/system.h> | |
24 | #include <asm/pgtable.h> | |
75003c48 GU |
25 | #include <asm/machdep.h> |
26 | #include <asm/MC68VZ328.h> | |
27 | ||
28 | /***************************************************************************/ | |
29 | ||
30 | #if defined(CONFIG_DRAGEN2) | |
31 | /* with a 33.16 MHz clock, this will give usec resolution to the time functions */ | |
32 | #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK | |
33 | #define CLOCK_PRE 7 | |
34 | #define TICKS_PER_JIFFY 41450 | |
35 | ||
36 | #elif defined(CONFIG_XCOPILOT_BUGS) | |
37 | /* | |
38 | * The only thing I know is that CLK32 is not available on Xcopilot | |
39 | * I have little idea about what frequency SYSCLK has on Xcopilot. | |
40 | * The values for prescaler and compare registers were simply | |
41 | * taken from the original source | |
42 | */ | |
43 | #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK | |
44 | #define CLOCK_PRE 2 | |
45 | #define TICKS_PER_JIFFY 0xd7e4 | |
46 | ||
47 | #else | |
48 | /* default to using the 32Khz clock */ | |
49 | #define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ | |
50 | #define CLOCK_PRE 31 | |
51 | #define TICKS_PER_JIFFY 10 | |
52 | #endif | |
53 | ||
54 | /***************************************************************************/ | |
55 | ||
84675716 GU |
56 | static irqreturn_t hw_tick(int irq, void *dummy) |
57 | { | |
58 | /* Reset Timer1 */ | |
59 | TSTAT &= 0; | |
60 | ||
61 | return arch_timer_interrupt(irq, dummy); | |
62 | } | |
63 | ||
64 | /***************************************************************************/ | |
65 | ||
be03e56b | 66 | static struct irqaction m68328_timer_irq = { |
84675716 GU |
67 | .name = "timer", |
68 | .flags = IRQF_DISABLED | IRQF_TIMER, | |
69 | .handler = hw_tick, | |
be03e56b GU |
70 | }; |
71 | ||
84675716 | 72 | void hw_timer_init(void) |
75003c48 GU |
73 | { |
74 | /* disable timer 1 */ | |
75 | TCTL = 0; | |
76 | ||
77 | /* set ISR */ | |
be03e56b | 78 | setup_irq(TMR_IRQ_NUM, &m68328_timer_irq); |
75003c48 GU |
79 | |
80 | /* Restart mode, Enable int, Set clock source */ | |
81 | TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE; | |
82 | TPRER = CLOCK_PRE; | |
83 | TCMP = TICKS_PER_JIFFY; | |
84 | ||
85 | /* Enable timer 1 */ | |
86 | TCTL |= TCTL_TEN; | |
87 | } | |
88 | ||
89 | /***************************************************************************/ | |
90 | ||
84675716 | 91 | unsigned long hw_timer_offset(void) |
75003c48 GU |
92 | { |
93 | unsigned long ticks = TCN, offset = 0; | |
94 | ||
95 | /* check for pending interrupt */ | |
96 | if (ticks < (TICKS_PER_JIFFY >> 1) && (ISR & (1 << TMR_IRQ_NUM))) | |
97 | offset = 1000000 / HZ; | |
98 | ticks = (ticks * 1000000 / HZ) / TICKS_PER_JIFFY; | |
99 | return ticks + offset; | |
100 | } | |
101 | ||
102 | /***************************************************************************/ | |
103 | ||
104 | void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec) | |
105 | { | |
106 | long now = RTCTIME; | |
107 | ||
108 | *year = *mon = *day = 1; | |
109 | *hour = (now >> 24) % 24; | |
110 | *min = (now >> 16) % 60; | |
111 | *sec = now % 60; | |
112 | } | |
113 | ||
114 | /***************************************************************************/ |