1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#include <linux/clockchips.h>
35#include <linux/clocksource.h>
36#include <linux/interrupt.h>
37#include <linux/spinlock.h>
38
39#include <asm/idle.h>
40#include <asm/processor.h>
41#include <asm/time.h>
42#include <asm/mach-au1x00/au1000.h>
43
44
45#define CNTR_OK (SYS_CNTRL_E0 | SYS_CNTRL_32S)
46
47static cycle_t au1x_counter1_read(struct clocksource *cs)
48{
49 return alchemy_rdsys(AU1000_SYS_RTCREAD);
50}
51
52static struct clocksource au1x_counter1_clocksource = {
53 .name = "alchemy-counter1",
54 .read = au1x_counter1_read,
55 .mask = CLOCKSOURCE_MASK(32),
56 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
57 .rating = 1500,
58};
59
60static int au1x_rtcmatch2_set_next_event(unsigned long delta,
61 struct clock_event_device *cd)
62{
63 delta += alchemy_rdsys(AU1000_SYS_RTCREAD);
64
65 while (alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_M21)
66 ;
67 alchemy_wrsys(delta, AU1000_SYS_RTCMATCH2);
68
69 return 0;
70}
71
72static void au1x_rtcmatch2_set_mode(enum clock_event_mode mode,
73 struct clock_event_device *cd)
74{
75}
76
77static irqreturn_t au1x_rtcmatch2_irq(int irq, void *dev_id)
78{
79 struct clock_event_device *cd = dev_id;
80 cd->event_handler(cd);
81 return IRQ_HANDLED;
82}
83
84static struct clock_event_device au1x_rtcmatch2_clockdev = {
85 .name = "rtcmatch2",
86 .features = CLOCK_EVT_FEAT_ONESHOT,
87 .rating = 1500,
88 .set_next_event = au1x_rtcmatch2_set_next_event,
89 .set_mode = au1x_rtcmatch2_set_mode,
90 .cpumask = cpu_all_mask,
91};
92
93static struct irqaction au1x_rtcmatch2_irqaction = {
94 .handler = au1x_rtcmatch2_irq,
95 .flags = IRQF_TIMER,
96 .name = "timer",
97 .dev_id = &au1x_rtcmatch2_clockdev,
98};
99
100static int __init alchemy_time_init(unsigned int m2int)
101{
102 struct clock_event_device *cd = &au1x_rtcmatch2_clockdev;
103 unsigned long t;
104
105 au1x_rtcmatch2_clockdev.irq = m2int;
106
107
108
109
110
111
112
113
114 if (CNTR_OK != (alchemy_rdsys(AU1000_SYS_CNTRCTRL) & CNTR_OK))
115 goto cntr_err;
116
117
118
119
120 t = 0xffffff;
121 while ((alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_T1S) && --t)
122 asm volatile ("nop");
123 if (!t)
124 goto cntr_err;
125
126 alchemy_wrsys(0, AU1000_SYS_RTCTRIM);
127
128 t = 0xffffff;
129 while ((alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_C1S) && --t)
130 asm volatile ("nop");
131 if (!t)
132 goto cntr_err;
133 alchemy_wrsys(0, AU1000_SYS_RTCWRITE);
134
135 t = 0xffffff;
136 while ((alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_C1S) && --t)
137 asm volatile ("nop");
138 if (!t)
139 goto cntr_err;
140
141
142 clocksource_register_hz(&au1x_counter1_clocksource, 32768);
143
144 cd->shift = 32;
145 cd->mult = div_sc(32768, NSEC_PER_SEC, cd->shift);
146 cd->max_delta_ns = clockevent_delta2ns(0xffffffff, cd);
147 cd->min_delta_ns = clockevent_delta2ns(9, cd);
148 clockevents_register_device(cd);
149 setup_irq(m2int, &au1x_rtcmatch2_irqaction);
150
151 printk(KERN_INFO "Alchemy clocksource installed\n");
152
153 return 0;
154
155cntr_err:
156 return -1;
157}
158
159static int alchemy_m2inttab[] __initdata = {
160 AU1000_RTC_MATCH2_INT,
161 AU1500_RTC_MATCH2_INT,
162 AU1100_RTC_MATCH2_INT,
163 AU1550_RTC_MATCH2_INT,
164 AU1200_RTC_MATCH2_INT,
165 AU1300_RTC_MATCH2_INT,
166};
167
168void __init plat_time_init(void)
169{
170 int t;
171
172 t = alchemy_get_cputype();
173 if (t == ALCHEMY_CPU_UNKNOWN ||
174 alchemy_time_init(alchemy_m2inttab[t]))
175 cpu_wait = NULL;
176}
177