1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/init.h>
23#include <linux/interrupt.h>
24#include <linux/irq.h>
25#include <linux/kernel.h>
26#include <linux/sched.h>
27#include <linux/io.h>
28#include <linux/clockchips.h>
29
30#include <asm/mach/time.h>
31#include <asm/system_misc.h>
32
33#include <mach/regs-irq.h>
34
35#include "generic.h"
36
37#define KS8695_TMR_OFFSET (0xF0000 + 0xE400)
38#define KS8695_TMR_VA (KS8695_IO_VA + KS8695_TMR_OFFSET)
39#define KS8695_TMR_PA (KS8695_IO_PA + KS8695_TMR_OFFSET)
40
41
42
43
44#define KS8695_TMCON (0x00)
45#define KS8695_T1TC (0x04)
46#define KS8695_T0TC (0x08)
47#define KS8695_T1PD (0x0C)
48#define KS8695_T0PD (0x10)
49
50
51#define TMCON_T1EN (1 << 1)
52#define TMCON_T0EN (1 << 0)
53
54
55#define T0TC_WATCHDOG (0xff)
56
57static void ks8695_set_mode(enum clock_event_mode mode,
58 struct clock_event_device *evt)
59{
60 u32 tmcon;
61
62 if (mode == CLOCK_EVT_FEAT_PERIODIC) {
63 u32 rate = DIV_ROUND_CLOSEST(KS8695_CLOCK_RATE, HZ);
64 u32 half = DIV_ROUND_CLOSEST(rate, 2);
65
66
67 tmcon = readl_relaxed(KS8695_TMR_VA + KS8695_TMCON);
68 tmcon &= ~TMCON_T1EN;
69 writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON);
70
71
72 writel_relaxed(half, KS8695_TMR_VA + KS8695_T1TC);
73 writel_relaxed(half, KS8695_TMR_VA + KS8695_T1PD);
74
75
76 tmcon |= TMCON_T1EN;
77 writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON);
78 }
79}
80
81static int ks8695_set_next_event(unsigned long cycles,
82 struct clock_event_device *evt)
83
84{
85 u32 half = DIV_ROUND_CLOSEST(cycles, 2);
86 u32 tmcon;
87
88
89 tmcon = readl_relaxed(KS8695_TMR_VA + KS8695_TMCON);
90 tmcon &= ~TMCON_T1EN;
91 writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON);
92
93
94 writel_relaxed(half, KS8695_TMR_VA + KS8695_T1TC);
95 writel_relaxed(half, KS8695_TMR_VA + KS8695_T1PD);
96
97
98 tmcon |= TMCON_T1EN;
99 writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON);
100
101 return 0;
102}
103
104static struct clock_event_device clockevent_ks8695 = {
105 .name = "ks8695_t1tc",
106 .rating = 300,
107 .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC,
108 .set_next_event = ks8695_set_next_event,
109 .set_mode = ks8695_set_mode,
110};
111
112
113
114
115static irqreturn_t ks8695_timer_interrupt(int irq, void *dev_id)
116{
117 struct clock_event_device *evt = &clockevent_ks8695;
118
119 evt->event_handler(evt);
120 return IRQ_HANDLED;
121}
122
123static struct irqaction ks8695_timer_irq = {
124 .name = "ks8695_tick",
125 .flags = IRQF_DISABLED | IRQF_TIMER,
126 .handler = ks8695_timer_interrupt,
127};
128
129static void ks8695_timer_setup(void)
130{
131 unsigned long tmcon;
132
133
134 tmcon = readl_relaxed(KS8695_TMR_VA + KS8695_TMCON);
135 tmcon &= ~TMCON_T0EN;
136 tmcon &= ~TMCON_T1EN;
137 writel_relaxed(tmcon, KS8695_TMR_VA + KS8695_TMCON);
138
139
140
141
142
143
144 clockevents_config_and_register(&clockevent_ks8695,
145 KS8695_CLOCK_RATE, 2,
146 0xFFFFFFFFU);
147}
148
149static void __init ks8695_timer_init (void)
150{
151 ks8695_timer_setup();
152
153
154 setup_irq(KS8695_IRQ_TIMER1, &ks8695_timer_irq);
155}
156
157struct sys_timer ks8695_timer = {
158 .init = ks8695_timer_init,
159};
160
161void ks8695_restart(char mode, const char *cmd)
162{
163 unsigned int reg;
164
165 if (mode == 's')
166 soft_restart(0);
167
168
169 reg = readl_relaxed(KS8695_TMR_VA + KS8695_TMCON);
170 writel_relaxed(reg & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
171
172
173 writel_relaxed((10 << 8) | T0TC_WATCHDOG, KS8695_TMR_VA + KS8695_T0TC);
174
175
176 writel_relaxed(reg | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
177}
178