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/processor.h>
40#include <asm/time.h>
41#include <asm/mach-au1x00/au1000.h>
42
43
44#define CNTR_OK (SYS_CNTRL_E0 | SYS_CNTRL_32S)
45
46static cycle_t au1x_counter1_read(struct clocksource *cs)
47{
48 return au_readl(SYS_RTCREAD);
49}
50
51static struct clocksource au1x_counter1_clocksource = {
52 .name = "alchemy-counter1",
53 .read = au1x_counter1_read,
54 .mask = CLOCKSOURCE_MASK(32),
55 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
56 .rating = 100,
57};
58
59static int au1x_rtcmatch2_set_next_event(unsigned long delta,
60 struct clock_event_device *cd)
61{
62 delta += au_readl(SYS_RTCREAD);
63
64 while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M21)
65 ;
66 au_writel(delta, SYS_RTCMATCH2);
67 au_sync();
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 = 100,
88 .irq = AU1000_RTC_MATCH2_INT,
89 .set_next_event = au1x_rtcmatch2_set_next_event,
90 .set_mode = au1x_rtcmatch2_set_mode,
91 .cpumask = cpu_all_mask,
92};
93
94static struct irqaction au1x_rtcmatch2_irqaction = {
95 .handler = au1x_rtcmatch2_irq,
96 .flags = IRQF_DISABLED | IRQF_TIMER,
97 .name = "timer",
98 .dev_id = &au1x_rtcmatch2_clockdev,
99};
100
101void __init plat_time_init(void)
102{
103 struct clock_event_device *cd = &au1x_rtcmatch2_clockdev;
104 unsigned long t;
105
106
107
108
109
110
111
112
113 if (CNTR_OK != (au_readl(SYS_COUNTER_CNTRL) & CNTR_OK))
114 goto cntr_err;
115
116
117
118
119 t = 0xffffff;
120 while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T1S) && --t)
121 asm volatile ("nop");
122 if (!t)
123 goto cntr_err;
124
125 au_writel(0, SYS_RTCTRIM);
126 au_sync();
127
128 t = 0xffffff;
129 while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C1S) && --t)
130 asm volatile ("nop");
131 if (!t)
132 goto cntr_err;
133 au_writel(0, SYS_RTCWRITE);
134 au_sync();
135
136 t = 0xffffff;
137 while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C1S) && --t)
138 asm volatile ("nop");
139 if (!t)
140 goto cntr_err;
141
142
143 clocksource_set_clock(&au1x_counter1_clocksource, 32768);
144 clocksource_register(&au1x_counter1_clocksource);
145
146 cd->shift = 32;
147 cd->mult = div_sc(32768, NSEC_PER_SEC, cd->shift);
148 cd->max_delta_ns = clockevent_delta2ns(0xffffffff, cd);
149 cd->min_delta_ns = clockevent_delta2ns(8, cd);
150 clockevents_register_device(cd);
151 setup_irq(AU1000_RTC_MATCH2_INT, &au1x_rtcmatch2_irqaction);
152
153 printk(KERN_INFO "Alchemy clocksource installed\n");
154
155 return;
156
157cntr_err:
158
159
160
161
162
163
164
165 cpu_wait = NULL;
166 r4k_clockevent_init();
167 init_r4k_clocksource();
168}
169