Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[pandora-kernel.git] / arch / m68knommu / platform / 68328 / timers.c
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
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/mm.h>
20 #include <linux/interrupt.h>
21 #include <linux/irq.h>
22 #include <asm/setup.h>
23 #include <asm/system.h>
24 #include <asm/pgtable.h>
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
56 static struct irqaction m68328_timer_irq = {
57         .name    = "timer",
58         .flags   = IRQF_DISABLED | IRQF_TIMER,
59 };
60
61 void m68328_timer_init(irq_handler_t timer_routine)
62 {
63         /* disable timer 1 */
64         TCTL = 0;
65
66         /* set ISR */
67         m68328_timer_irq.handler = timer_routine;
68         setup_irq(TMR_IRQ_NUM, &m68328_timer_irq);
69
70         /* Restart mode, Enable int, Set clock source */
71         TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
72         TPRER = CLOCK_PRE;
73         TCMP = TICKS_PER_JIFFY;
74
75         /* Enable timer 1 */
76         TCTL |= TCTL_TEN;
77 }
78
79 /***************************************************************************/
80
81 void m68328_timer_tick(void)
82 {
83         /* Reset Timer1 */
84         TSTAT &= 0;
85 }
86 /***************************************************************************/
87
88 unsigned long m68328_timer_gettimeoffset(void)
89 {
90         unsigned long ticks = TCN, offset = 0;
91
92         /* check for pending interrupt */
93         if (ticks < (TICKS_PER_JIFFY >> 1) && (ISR & (1 << TMR_IRQ_NUM)))
94                 offset = 1000000 / HZ;
95         ticks = (ticks * 1000000 / HZ) / TICKS_PER_JIFFY;
96         return ticks + offset;
97 }
98
99 /***************************************************************************/
100
101 void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec)
102 {
103         long now = RTCTIME;
104
105         *year = *mon = *day = 1;
106         *hour = (now >> 24) % 24;
107         *min = (now >> 16) % 60;
108         *sec = now % 60;
109 }
110
111 /***************************************************************************/