1 /***************************************************************************/
4 * timers.c - Generic hardware timer support.
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 <linux/clocksource.h>
23 #include <linux/rtc.h>
24 #include <asm/setup.h>
25 #include <asm/machdep.h>
26 #include <asm/MC68VZ328.h>
30 /***************************************************************************/
32 #if defined(CONFIG_DRAGEN2)
33 /* with a 33.16 MHz clock, this will give usec resolution to the time functions */
34 #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
36 #define TICKS_PER_JIFFY 41450
38 #elif defined(CONFIG_XCOPILOT_BUGS)
40 * The only thing I know is that CLK32 is not available on Xcopilot
41 * I have little idea about what frequency SYSCLK has on Xcopilot.
42 * The values for prescaler and compare registers were simply
43 * taken from the original source
45 #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
47 #define TICKS_PER_JIFFY 0xd7e4
50 /* default to using the 32Khz clock */
51 #define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ
53 #define TICKS_PER_JIFFY 10
56 static u32 m68328_tick_cnt;
58 /***************************************************************************/
60 static irqreturn_t hw_tick(int irq, void *dummy)
65 m68328_tick_cnt += TICKS_PER_JIFFY;
70 /***************************************************************************/
72 static u64 m68328_read_clk(struct clocksource *cs)
77 local_irq_save(flags);
78 cycles = m68328_tick_cnt + TCN;
79 local_irq_restore(flags);
84 /***************************************************************************/
86 static struct clocksource m68328_clk = {
89 .read = m68328_read_clk,
90 .mask = CLOCKSOURCE_MASK(32),
91 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
94 /***************************************************************************/
96 void hw_timer_init(void)
100 /* disable timer 1 */
104 ret = request_irq(TMR_IRQ_NUM, hw_tick, IRQF_TIMER, "timer", NULL);
106 pr_err("Failed to request irq %d (timer): %pe\n", TMR_IRQ_NUM,
110 /* Restart mode, Enable int, Set clock source */
111 TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
113 TCMP = TICKS_PER_JIFFY;
117 clocksource_register_hz(&m68328_clk, TICKS_PER_JIFFY*HZ);
120 /***************************************************************************/
122 int m68328_hwclk(int set, struct rtc_time *t)
129 t->tm_hour = (now >> 24) % 24;
130 t->tm_min = (now >> 16) % 60;
131 t->tm_sec = now % 60;
137 /***************************************************************************/