blob: 65c9204ab9ac626aaec3066967bdce9b1792ea60 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/m68k/bvme6000/config.c
3 *
4 * Copyright (C) 1997 Richard Hirst [richard@sleepie.demon.co.uk]
5 *
6 * Based on:
7 *
8 * linux/amiga/config.c
9 *
10 * Copyright (C) 1993 Hamish Macdonald
11 *
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file README.legal in the main directory of this archive
14 * for more details.
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>
Adrian Bunk5b1d5f92008-10-13 21:58:47 +020028#include <linux/bcd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include <asm/bootinfo.h>
31#include <asm/system.h>
32#include <asm/pgtable.h>
33#include <asm/setup.h>
34#include <asm/irq.h>
35#include <asm/traps.h>
36#include <asm/rtc.h>
37#include <asm/machdep.h>
38#include <asm/bvme6000hw.h>
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static void bvme6000_get_model(char *model);
41static int bvme6000_get_hardware_list(char *buffer);
David Howells40220c12006-10-09 12:19:47 +010042extern void bvme6000_sched_init(irq_handler_t handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043extern unsigned long bvme6000_gettimeoffset (void);
44extern int bvme6000_hwclk (int, struct rtc_time *);
45extern int bvme6000_set_clock_mmss (unsigned long);
46extern void bvme6000_reset (void);
47extern void bvme6000_waitbut(void);
48void bvme6000_set_vectors (void);
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/* Save tick handler routine pointer, will point to do_timer() in
51 * kernel/sched.c, called via bvme6000_process_int() */
52
David Howells40220c12006-10-09 12:19:47 +010053static irq_handler_t tick_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55
56int bvme6000_parse_bootinfo(const struct bi_record *bi)
57{
58 if (bi->tag == BI_VME_TYPE)
59 return 0;
60 else
61 return 1;
62}
63
64void bvme6000_reset(void)
65{
66 volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
67
68 printk ("\r\n\nCalled bvme6000_reset\r\n"
69 "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r");
70 /* The string of returns is to delay the reset until the whole
71 * message is output. */
72 /* Enable the watchdog, via PIT port C bit 4 */
73
74 pit->pcddr |= 0x10; /* WDOG enable */
75
76 while(1)
77 ;
78}
79
80static void bvme6000_get_model(char *model)
81{
82 sprintf(model, "BVME%d000", m68k_cputype == CPU_68060 ? 6 : 4);
83}
84
85
86/* No hardware options on BVME6000? */
87
88static int bvme6000_get_hardware_list(char *buffer)
89{
90 *buffer = '\0';
91 return 0;
92}
93
Roman Zippel200a3d32006-06-25 05:47:06 -070094/*
95 * This function is called during kernel startup to initialize
96 * the bvme6000 IRQ handling routines.
97 */
Al Viro66a3f822007-07-20 04:33:28 +010098static void __init bvme6000_init_IRQ(void)
Roman Zippel200a3d32006-06-25 05:47:06 -070099{
100 m68k_setup_user_interrupt(VEC_USER, 192, NULL);
101}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103void __init config_bvme6000(void)
104{
105 volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
106
107 /* Board type is only set by newer versions of vmelilo/tftplilo */
108 if (!vme_brdtype) {
109 if (m68k_cputype == CPU_68060)
110 vme_brdtype = VME_TYPE_BVME6000;
111 else
112 vme_brdtype = VME_TYPE_BVME4000;
113 }
114#if 0
115 /* Call bvme6000_set_vectors() so ABORT will work, along with BVMBug
116 * debugger. Note trap_init() will splat the abort vector, but
117 * bvme6000_init_IRQ() will put it back again. Hopefully. */
118
119 bvme6000_set_vectors();
120#endif
121
122 mach_max_dma_address = 0xffffffff;
123 mach_sched_init = bvme6000_sched_init;
124 mach_init_IRQ = bvme6000_init_IRQ;
125 mach_gettimeoffset = bvme6000_gettimeoffset;
126 mach_hwclk = bvme6000_hwclk;
127 mach_set_clock_mmss = bvme6000_set_clock_mmss;
128 mach_reset = bvme6000_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 mach_get_model = bvme6000_get_model;
130 mach_get_hardware_list = bvme6000_get_hardware_list;
131
132 printk ("Board is %sconfigured as a System Controller\n",
133 *config_reg_ptr & BVME_CONFIG_SW1 ? "" : "not ");
134
135 /* Now do the PIT configuration */
136
137 pit->pgcr = 0x00; /* Unidirectional 8 bit, no handshake for now */
Akinobu Mita0b280022006-03-26 01:38:58 -0800138 pit->psrr = 0x18; /* PIACK and PIRQ functions enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 pit->pacr = 0x00; /* Sub Mode 00, H2 i/p, no DMA */
140 pit->padr = 0x00; /* Just to be tidy! */
141 pit->paddr = 0x00; /* All inputs for now (safest) */
142 pit->pbcr = 0x80; /* Sub Mode 1x, H4 i/p, no DMA */
143 pit->pbdr = 0xbc | (*config_reg_ptr & BVME_CONFIG_SW1 ? 0 : 0x40);
144 /* PRI, SYSCON?, Level3, SCC clks from xtal */
145 pit->pbddr = 0xf3; /* Mostly outputs */
146 pit->pcdr = 0x01; /* PA transceiver disabled */
147 pit->pcddr = 0x03; /* WDOG disable */
148
149 /* Disable snooping for Ethernet and VME accesses */
150
151 bvme_acr_addrctl = 0;
152}
153
154
Al Viro2850bc22006-10-07 14:16:45 +0100155irqreturn_t bvme6000_abort_int (int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 unsigned long *new = (unsigned long *)vectors;
158 unsigned long *old = (unsigned long *)0xf8000000;
159
160 /* Wait for button release */
161 while (*(volatile unsigned char *)BVME_LOCAL_IRQ_STAT & BVME_ABORT_STATUS)
162 ;
163
164 *(new+4) = *(old+4); /* Illegal instruction */
165 *(new+9) = *(old+9); /* Trace */
166 *(new+47) = *(old+47); /* Trap #15 */
167 *(new+0x1f) = *(old+0x1f); /* ABORT switch */
168 return IRQ_HANDLED;
169}
170
171
Al Viro2850bc22006-10-07 14:16:45 +0100172static irqreturn_t bvme6000_timer_int (int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
175 unsigned char msr = rtc->msr & 0xc0;
176
177 rtc->msr = msr | 0x20; /* Ack the interrupt */
178
Al Viro2850bc22006-10-07 14:16:45 +0100179 return tick_handler(irq, dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
182/*
183 * Set up the RTC timer 1 to mode 2, so T1 output toggles every 5ms
184 * (40000 x 125ns). It will interrupt every 10ms, when T1 goes low.
185 * So, when reading the elapsed time, you should read timer1,
186 * subtract it from 39999, and then add 40000 if T1 is high.
187 * That gives you the number of 125ns ticks in to the 10ms period,
188 * so divide by 8 to get the microsecond result.
189 */
190
David Howells40220c12006-10-09 12:19:47 +0100191void bvme6000_sched_init (irq_handler_t timer_routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
194 unsigned char msr = rtc->msr & 0xc0;
195
196 rtc->msr = 0; /* Ensure timer registers accessible */
197
198 tick_handler = timer_routine;
199 if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, 0,
200 "timer", bvme6000_timer_int))
201 panic ("Couldn't register timer int");
202
203 rtc->t1cr_omr = 0x04; /* Mode 2, ext clk */
204 rtc->t1msb = 39999 >> 8;
205 rtc->t1lsb = 39999 & 0xff;
206 rtc->irr_icr1 &= 0xef; /* Route timer 1 to INTR pin */
207 rtc->msr = 0x40; /* Access int.cntrl, etc */
208 rtc->pfr_icr0 = 0x80; /* Just timer 1 ints enabled */
209 rtc->irr_icr1 = 0;
210 rtc->t1cr_omr = 0x0a; /* INTR+T1 active lo, push-pull */
211 rtc->t0cr_rtmr &= 0xdf; /* Stop timers in standby */
212 rtc->msr = 0; /* Access timer 1 control */
213 rtc->t1cr_omr = 0x05; /* Mode 2, ext clk, GO */
214
215 rtc->msr = msr;
216
217 if (request_irq(BVME_IRQ_ABORT, bvme6000_abort_int, 0,
218 "abort", bvme6000_abort_int))
219 panic ("Couldn't register abort int");
220}
221
222
223/* This is always executed with interrupts disabled. */
224
225/*
226 * NOTE: Don't accept any readings within 5us of rollover, as
227 * the T1INT bit may be a little slow getting set. There is also
228 * a fault in the chip, meaning that reads may produce invalid
229 * results...
230 */
231
232unsigned long bvme6000_gettimeoffset (void)
233{
234 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
235 volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
236 unsigned char msr = rtc->msr & 0xc0;
237 unsigned char t1int, t1op;
238 unsigned long v = 800000, ov;
239
240 rtc->msr = 0; /* Ensure timer registers accessible */
241
242 do {
243 ov = v;
244 t1int = rtc->msr & 0x20;
245 t1op = pit->pcdr & 0x04;
246 rtc->t1cr_omr |= 0x40; /* Latch timer1 */
247 v = rtc->t1msb << 8; /* Read timer1 */
248 v |= rtc->t1lsb; /* Read timer1 */
249 } while (t1int != (rtc->msr & 0x20) ||
250 t1op != (pit->pcdr & 0x04) ||
251 abs(ov-v) > 80 ||
252 v > 39960);
253
254 v = 39999 - v;
255 if (!t1op) /* If in second half cycle.. */
256 v += 40000;
257 v /= 8; /* Convert ticks to microseconds */
258 if (t1int)
259 v += 10000; /* Int pending, + 10ms */
260 rtc->msr = msr;
261
262 return v;
263}
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265/*
266 * Looks like op is non-zero for setting the clock, and zero for
267 * reading the clock.
268 *
269 * struct hwclk_time {
270 * unsigned sec; 0..59
271 * unsigned min; 0..59
272 * unsigned hour; 0..23
273 * unsigned day; 1..31
274 * unsigned mon; 0..11
275 * unsigned year; 00...
276 * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
277 * };
278 */
279
280int bvme6000_hwclk(int op, struct rtc_time *t)
281{
282 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
283 unsigned char msr = rtc->msr & 0xc0;
284
285 rtc->msr = 0x40; /* Ensure clock and real-time-mode-register
286 * are accessible */
287 if (op)
288 { /* Write.... */
289 rtc->t0cr_rtmr = t->tm_year%4;
290 rtc->bcd_tenms = 0;
291 rtc->bcd_sec = bin2bcd(t->tm_sec);
292 rtc->bcd_min = bin2bcd(t->tm_min);
293 rtc->bcd_hr = bin2bcd(t->tm_hour);
294 rtc->bcd_dom = bin2bcd(t->tm_mday);
295 rtc->bcd_mth = bin2bcd(t->tm_mon + 1);
296 rtc->bcd_year = bin2bcd(t->tm_year%100);
297 if (t->tm_wday >= 0)
298 rtc->bcd_dow = bin2bcd(t->tm_wday+1);
299 rtc->t0cr_rtmr = t->tm_year%4 | 0x08;
300 }
301 else
302 { /* Read.... */
303 do {
304 t->tm_sec = bcd2bin(rtc->bcd_sec);
305 t->tm_min = bcd2bin(rtc->bcd_min);
306 t->tm_hour = bcd2bin(rtc->bcd_hr);
307 t->tm_mday = bcd2bin(rtc->bcd_dom);
308 t->tm_mon = bcd2bin(rtc->bcd_mth)-1;
309 t->tm_year = bcd2bin(rtc->bcd_year);
310 if (t->tm_year < 70)
311 t->tm_year += 100;
312 t->tm_wday = bcd2bin(rtc->bcd_dow)-1;
313 } while (t->tm_sec != bcd2bin(rtc->bcd_sec));
314 }
315
316 rtc->msr = msr;
317
318 return 0;
319}
320
321/*
322 * Set the minutes and seconds from seconds value 'nowtime'. Fail if
323 * clock is out by > 30 minutes. Logic lifted from atari code.
324 * Algorithm is to wait for the 10ms register to change, and then to
325 * wait a short while, and then set it.
326 */
327
328int bvme6000_set_clock_mmss (unsigned long nowtime)
329{
330 int retval = 0;
331 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
332 unsigned char rtc_minutes, rtc_tenms;
333 volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
334 unsigned char msr = rtc->msr & 0xc0;
335 unsigned long flags;
336 volatile int i;
337
338 rtc->msr = 0; /* Ensure clock accessible */
339 rtc_minutes = bcd2bin (rtc->bcd_min);
340
341 if ((rtc_minutes < real_minutes
342 ? real_minutes - rtc_minutes
343 : rtc_minutes - real_minutes) < 30)
344 {
345 local_irq_save(flags);
346 rtc_tenms = rtc->bcd_tenms;
347 while (rtc_tenms == rtc->bcd_tenms)
348 ;
349 for (i = 0; i < 1000; i++)
350 ;
351 rtc->bcd_min = bin2bcd(real_minutes);
352 rtc->bcd_sec = bin2bcd(real_seconds);
353 local_irq_restore(flags);
354 }
355 else
356 retval = -1;
357
358 rtc->msr = msr;
359
360 return retval;
361}
362