1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/mm.h>
20#include <linux/tty.h>
21#include <linux/console.h>
22#include <linux/linkage.h>
23#include <linux/init.h>
24#include <linux/major.h>
25#include <linux/genhd.h>
26#include <linux/rtc.h>
27#include <linux/interrupt.h>
28#include <linux/bcd.h>
29
30#include <asm/bootinfo.h>
31#include <asm/pgtable.h>
32#include <asm/setup.h>
33#include <asm/irq.h>
34#include <asm/traps.h>
35#include <asm/rtc.h>
36#include <asm/machdep.h>
37#include <asm/bvme6000hw.h>
38
39static void bvme6000_get_model(char *model);
40extern void bvme6000_sched_init(irq_handler_t handler);
41extern unsigned long bvme6000_gettimeoffset (void);
42extern int bvme6000_hwclk (int, struct rtc_time *);
43extern int bvme6000_set_clock_mmss (unsigned long);
44extern void bvme6000_reset (void);
45void bvme6000_set_vectors (void);
46
47
48
49
50static irq_handler_t tick_handler;
51
52
53int bvme6000_parse_bootinfo(const struct bi_record *bi)
54{
55 if (bi->tag == BI_VME_TYPE)
56 return 0;
57 else
58 return 1;
59}
60
61void bvme6000_reset(void)
62{
63 volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
64
65 printk ("\r\n\nCalled bvme6000_reset\r\n"
66 "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r");
67
68
69
70
71 pit->pcddr |= 0x10;
72
73 while(1)
74 ;
75}
76
77static void bvme6000_get_model(char *model)
78{
79 sprintf(model, "BVME%d000", m68k_cputype == CPU_68060 ? 6 : 4);
80}
81
82
83
84
85
86static void __init bvme6000_init_IRQ(void)
87{
88 m68k_setup_user_interrupt(VEC_USER, 192);
89}
90
91void __init config_bvme6000(void)
92{
93 volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
94
95
96 if (!vme_brdtype) {
97 if (m68k_cputype == CPU_68060)
98 vme_brdtype = VME_TYPE_BVME6000;
99 else
100 vme_brdtype = VME_TYPE_BVME4000;
101 }
102#if 0
103
104
105
106
107 bvme6000_set_vectors();
108#endif
109
110 mach_max_dma_address = 0xffffffff;
111 mach_sched_init = bvme6000_sched_init;
112 mach_init_IRQ = bvme6000_init_IRQ;
113 mach_gettimeoffset = bvme6000_gettimeoffset;
114 mach_hwclk = bvme6000_hwclk;
115 mach_set_clock_mmss = bvme6000_set_clock_mmss;
116 mach_reset = bvme6000_reset;
117 mach_get_model = bvme6000_get_model;
118
119 printk ("Board is %sconfigured as a System Controller\n",
120 *config_reg_ptr & BVME_CONFIG_SW1 ? "" : "not ");
121
122
123
124 pit->pgcr = 0x00;
125 pit->psrr = 0x18;
126 pit->pacr = 0x00;
127 pit->padr = 0x00;
128 pit->paddr = 0x00;
129 pit->pbcr = 0x80;
130 pit->pbdr = 0xbc | (*config_reg_ptr & BVME_CONFIG_SW1 ? 0 : 0x40);
131
132 pit->pbddr = 0xf3;
133 pit->pcdr = 0x01;
134 pit->pcddr = 0x03;
135
136
137
138 bvme_acr_addrctl = 0;
139}
140
141
142irqreturn_t bvme6000_abort_int (int irq, void *dev_id)
143{
144 unsigned long *new = (unsigned long *)vectors;
145 unsigned long *old = (unsigned long *)0xf8000000;
146
147
148 while (*(volatile unsigned char *)BVME_LOCAL_IRQ_STAT & BVME_ABORT_STATUS)
149 ;
150
151 *(new+4) = *(old+4);
152 *(new+9) = *(old+9);
153 *(new+47) = *(old+47);
154 *(new+0x1f) = *(old+0x1f);
155 return IRQ_HANDLED;
156}
157
158
159static irqreturn_t bvme6000_timer_int (int irq, void *dev_id)
160{
161 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
162 unsigned char msr = rtc->msr & 0xc0;
163
164 rtc->msr = msr | 0x20;
165
166 return tick_handler(irq, dev_id);
167}
168
169
170
171
172
173
174
175
176
177
178void bvme6000_sched_init (irq_handler_t timer_routine)
179{
180 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
181 unsigned char msr = rtc->msr & 0xc0;
182
183 rtc->msr = 0;
184
185 tick_handler = timer_routine;
186 if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, 0,
187 "timer", bvme6000_timer_int))
188 panic ("Couldn't register timer int");
189
190 rtc->t1cr_omr = 0x04;
191 rtc->t1msb = 39999 >> 8;
192 rtc->t1lsb = 39999 & 0xff;
193 rtc->irr_icr1 &= 0xef;
194 rtc->msr = 0x40;
195 rtc->pfr_icr0 = 0x80;
196 rtc->irr_icr1 = 0;
197 rtc->t1cr_omr = 0x0a;
198 rtc->t0cr_rtmr &= 0xdf;
199 rtc->msr = 0;
200 rtc->t1cr_omr = 0x05;
201
202 rtc->msr = msr;
203
204 if (request_irq(BVME_IRQ_ABORT, bvme6000_abort_int, 0,
205 "abort", bvme6000_abort_int))
206 panic ("Couldn't register abort int");
207}
208
209
210
211
212
213
214
215
216
217
218
219unsigned long bvme6000_gettimeoffset (void)
220{
221 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
222 volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
223 unsigned char msr = rtc->msr & 0xc0;
224 unsigned char t1int, t1op;
225 unsigned long v = 800000, ov;
226
227 rtc->msr = 0;
228
229 do {
230 ov = v;
231 t1int = rtc->msr & 0x20;
232 t1op = pit->pcdr & 0x04;
233 rtc->t1cr_omr |= 0x40;
234 v = rtc->t1msb << 8;
235 v |= rtc->t1lsb;
236 } while (t1int != (rtc->msr & 0x20) ||
237 t1op != (pit->pcdr & 0x04) ||
238 abs(ov-v) > 80 ||
239 v > 39960);
240
241 v = 39999 - v;
242 if (!t1op)
243 v += 40000;
244 v /= 8;
245 if (t1int)
246 v += 10000;
247 rtc->msr = msr;
248
249 return v;
250}
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267int bvme6000_hwclk(int op, struct rtc_time *t)
268{
269 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
270 unsigned char msr = rtc->msr & 0xc0;
271
272 rtc->msr = 0x40;
273
274 if (op)
275 {
276 rtc->t0cr_rtmr = t->tm_year%4;
277 rtc->bcd_tenms = 0;
278 rtc->bcd_sec = bin2bcd(t->tm_sec);
279 rtc->bcd_min = bin2bcd(t->tm_min);
280 rtc->bcd_hr = bin2bcd(t->tm_hour);
281 rtc->bcd_dom = bin2bcd(t->tm_mday);
282 rtc->bcd_mth = bin2bcd(t->tm_mon + 1);
283 rtc->bcd_year = bin2bcd(t->tm_year%100);
284 if (t->tm_wday >= 0)
285 rtc->bcd_dow = bin2bcd(t->tm_wday+1);
286 rtc->t0cr_rtmr = t->tm_year%4 | 0x08;
287 }
288 else
289 {
290 do {
291 t->tm_sec = bcd2bin(rtc->bcd_sec);
292 t->tm_min = bcd2bin(rtc->bcd_min);
293 t->tm_hour = bcd2bin(rtc->bcd_hr);
294 t->tm_mday = bcd2bin(rtc->bcd_dom);
295 t->tm_mon = bcd2bin(rtc->bcd_mth)-1;
296 t->tm_year = bcd2bin(rtc->bcd_year);
297 if (t->tm_year < 70)
298 t->tm_year += 100;
299 t->tm_wday = bcd2bin(rtc->bcd_dow)-1;
300 } while (t->tm_sec != bcd2bin(rtc->bcd_sec));
301 }
302
303 rtc->msr = msr;
304
305 return 0;
306}
307
308
309
310
311
312
313
314
315int bvme6000_set_clock_mmss (unsigned long nowtime)
316{
317 int retval = 0;
318 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
319 unsigned char rtc_minutes, rtc_tenms;
320 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
321 unsigned char msr = rtc->msr & 0xc0;
322 unsigned long flags;
323 volatile int i;
324
325 rtc->msr = 0;
326 rtc_minutes = bcd2bin (rtc->bcd_min);
327
328 if ((rtc_minutes < real_minutes
329 ? real_minutes - rtc_minutes
330 : rtc_minutes - real_minutes) < 30)
331 {
332 local_irq_save(flags);
333 rtc_tenms = rtc->bcd_tenms;
334 while (rtc_tenms == rtc->bcd_tenms)
335 ;
336 for (i = 0; i < 1000; i++)
337 ;
338 rtc->bcd_min = bin2bcd(real_minutes);
339 rtc->bcd_sec = bin2bcd(real_seconds);
340 local_irq_restore(flags);
341 }
342 else
343 retval = -1;
344
345 rtc->msr = msr;
346
347 return retval;
348}
349
350