]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/m68knommu/platform/68328/timers.c
Pull acpi_device_handle_cleanup into release branch
[linux-2.6.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 <asm/setup.h>
21 #include <asm/system.h>
22 #include <asm/pgtable.h>
23 #include <asm/irq.h>
24 #include <asm/machdep.h>
25 #include <asm/MC68VZ328.h>
26
27 /***************************************************************************/
28
29 #if defined(CONFIG_DRAGEN2)
30 /* with a 33.16 MHz clock, this will give usec resolution to the time functions */
31 #define CLOCK_SOURCE    TCTL_CLKSOURCE_SYSCLK
32 #define CLOCK_PRE       7
33 #define TICKS_PER_JIFFY 41450
34
35 #elif defined(CONFIG_XCOPILOT_BUGS)
36 /*
37  * The only thing I know is that CLK32 is not available on Xcopilot
38  * I have little idea about what frequency SYSCLK has on Xcopilot.
39  * The values for prescaler and compare registers were simply
40  * taken from the original source
41  */
42 #define CLOCK_SOURCE    TCTL_CLKSOURCE_SYSCLK
43 #define CLOCK_PRE       2
44 #define TICKS_PER_JIFFY 0xd7e4
45
46 #else
47 /* default to using the 32Khz clock */
48 #define CLOCK_SOURCE    TCTL_CLKSOURCE_32KHZ
49 #define CLOCK_PRE       31
50 #define TICKS_PER_JIFFY 10
51 #endif
52
53 /***************************************************************************/
54
55 void m68328_timer_init(irqreturn_t (*timer_routine) (int, void *, struct pt_regs *))
56 {
57         /* disable timer 1 */
58         TCTL = 0;
59
60         /* set ISR */
61         if (request_irq(TMR_IRQ_NUM, timer_routine, IRQ_FLG_LOCK, "timer", NULL)) 
62                 panic("Unable to attach timer interrupt\n");
63
64         /* Restart mode, Enable int, Set clock source */
65         TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
66         TPRER = CLOCK_PRE;
67         TCMP = TICKS_PER_JIFFY;
68
69         /* Enable timer 1 */
70         TCTL |= TCTL_TEN;
71 }
72
73 /***************************************************************************/
74
75 void m68328_timer_tick(void)
76 {
77         /* Reset Timer1 */
78         TSTAT &= 0;
79 }
80 /***************************************************************************/
81
82 unsigned long m68328_timer_gettimeoffset(void)
83 {
84         unsigned long ticks = TCN, offset = 0;
85
86         /* check for pending interrupt */
87         if (ticks < (TICKS_PER_JIFFY >> 1) && (ISR & (1 << TMR_IRQ_NUM)))
88                 offset = 1000000 / HZ;
89         ticks = (ticks * 1000000 / HZ) / TICKS_PER_JIFFY;
90         return ticks + offset;
91 }
92
93 /***************************************************************************/
94
95 void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec)
96 {
97         long now = RTCTIME;
98
99         *year = *mon = *day = 1;
100         *hour = (now >> 24) % 24;
101         *min = (now >> 16) % 60;
102         *sec = now % 60;
103 }
104
105 /***************************************************************************/