blob: b15ddef1ec765e78442d8721b730649f31b78c35 [file] [log] [blame]
Greg Ungerer75003c42005-09-09 09:32:14 +10001/***************************************************************************/
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
Greg Ungerer75003c42005-09-09 09:32:14 +100017#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/mm.h>
Greg Ungerer1ea9acc2007-03-07 11:28:13 +100020#include <linux/interrupt.h>
Greg Ungererbe03e562007-07-27 01:09:00 +100021#include <linux/irq.h>
Greg Ungerer36a90f22008-02-01 17:40:17 +100022#include <linux/clocksource.h>
Greg Ungerer95177462012-01-23 13:25:56 +100023#include <linux/rtc.h>
Greg Ungerer75003c42005-09-09 09:32:14 +100024#include <asm/setup.h>
25#include <asm/system.h>
26#include <asm/pgtable.h>
Greg Ungerer75003c42005-09-09 09:32:14 +100027#include <asm/machdep.h>
28#include <asm/MC68VZ328.h>
29
30/***************************************************************************/
31
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
35#define CLOCK_PRE 7
36#define TICKS_PER_JIFFY 41450
37
38#elif defined(CONFIG_XCOPILOT_BUGS)
39/*
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
44 */
45#define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
46#define CLOCK_PRE 2
47#define TICKS_PER_JIFFY 0xd7e4
48
49#else
50/* default to using the 32Khz clock */
51#define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ
52#define CLOCK_PRE 31
53#define TICKS_PER_JIFFY 10
54#endif
55
Greg Ungerer36a90f22008-02-01 17:40:17 +100056static u32 m68328_tick_cnt;
57
58/***************************************************************************/
59
60static irqreturn_t hw_tick(int irq, void *dummy)
61{
62 /* Reset Timer1 */
63 TSTAT &= 0;
64
65 m68328_tick_cnt += TICKS_PER_JIFFY;
66 return arch_timer_interrupt(irq, dummy);
67}
68
Greg Ungerer75003c42005-09-09 09:32:14 +100069/***************************************************************************/
70
Greg Ungererbe03e562007-07-27 01:09:00 +100071static struct irqaction m68328_timer_irq = {
Greg Ungerer84675712007-10-24 12:03:20 +100072 .name = "timer",
73 .flags = IRQF_DISABLED | IRQF_TIMER,
74 .handler = hw_tick,
Greg Ungererbe03e562007-07-27 01:09:00 +100075};
76
Greg Ungerer36a90f22008-02-01 17:40:17 +100077/***************************************************************************/
78
Magnus Damm8e196082009-04-21 12:24:00 -070079static cycle_t m68328_read_clk(struct clocksource *cs)
Greg Ungerer36a90f22008-02-01 17:40:17 +100080{
81 unsigned long flags;
82 u32 cycles;
83
84 local_irq_save(flags);
85 cycles = m68328_tick_cnt + TCN;
86 local_irq_restore(flags);
87
88 return cycles;
89}
90
91/***************************************************************************/
92
93static struct clocksource m68328_clk = {
94 .name = "timer",
95 .rating = 250,
96 .read = m68328_read_clk,
Greg Ungerer36a90f22008-02-01 17:40:17 +100097 .mask = CLOCKSOURCE_MASK(32),
98 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
99};
100
101/***************************************************************************/
102
Greg Ungerer84675712007-10-24 12:03:20 +1000103void hw_timer_init(void)
Greg Ungerer75003c42005-09-09 09:32:14 +1000104{
105 /* disable timer 1 */
106 TCTL = 0;
107
108 /* set ISR */
Greg Ungererbe03e562007-07-27 01:09:00 +1000109 setup_irq(TMR_IRQ_NUM, &m68328_timer_irq);
Greg Ungerer75003c42005-09-09 09:32:14 +1000110
111 /* Restart mode, Enable int, Set clock source */
112 TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
113 TPRER = CLOCK_PRE;
114 TCMP = TICKS_PER_JIFFY;
115
116 /* Enable timer 1 */
117 TCTL |= TCTL_TEN;
John Stultz010f3f12010-04-26 20:21:52 -0700118 clocksource_register_hz(&m68328_clk, TICKS_PER_JIFFY*HZ);
Greg Ungerer75003c42005-09-09 09:32:14 +1000119}
120
121/***************************************************************************/
122
Greg Ungerer95177462012-01-23 13:25:56 +1000123int m68328_hwclk(int set, struct rtc_time *t)
Greg Ungerer75003c42005-09-09 09:32:14 +1000124{
Greg Ungerer95177462012-01-23 13:25:56 +1000125 if (!set) {
126 long now = RTCTIME;
127 t->tm_year = t->tm_mon = t->tm_mday = 1;
128 t->tm_hour = (now >> 24) % 24;
129 t->tm_min = (now >> 16) % 60;
130 t->tm_sec = now % 60;
131 }
Greg Ungerer75003c42005-09-09 09:32:14 +1000132
Greg Ungerer95177462012-01-23 13:25:56 +1000133 return 0;
Greg Ungerer75003c42005-09-09 09:32:14 +1000134}
135
136/***************************************************************************/