1 /***************************************************************************/
4 * linux/arch/m68knommu/platform/68328/timers.c
6 * Copyright (C) 1993 Hamish Macdonald
7 * Copyright (C) 1999 D. Jeff Dionne
8 * Copyright (C) 2001 Georges Menie, Ken Desmet
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
15 /***************************************************************************/
17 #include <linux/types.h>
18 #include <linux/kernel.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>
28 /***************************************************************************/
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
34 #define TICKS_PER_JIFFY 41450
36 #elif defined(CONFIG_XCOPILOT_BUGS)
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
43 #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
45 #define TICKS_PER_JIFFY 0xd7e4
48 /* default to using the 32Khz clock */
49 #define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ
51 #define TICKS_PER_JIFFY 10
54 /***************************************************************************/
56 static irqreturn_t hw_tick(int irq, void *dummy)
61 return arch_timer_interrupt(irq, dummy);
64 /***************************************************************************/
66 static struct irqaction m68328_timer_irq = {
68 .flags = IRQF_DISABLED | IRQF_TIMER,
72 void hw_timer_init(void)
78 setup_irq(TMR_IRQ_NUM, &m68328_timer_irq);
80 /* Restart mode, Enable int, Set clock source */
81 TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
83 TCMP = TICKS_PER_JIFFY;
89 /***************************************************************************/
91 unsigned long hw_timer_offset(void)
93 unsigned long ticks = TCN, offset = 0;
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;
102 /***************************************************************************/
104 void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec)
108 *year = *mon = *day = 1;
109 *hour = (now >> 24) % 24;
110 *min = (now >> 16) % 60;
114 /***************************************************************************/