Import 2.3.9pre5
[davej-history.git] / drivers / sgi / char / sgiserial.c
blobaaa9e7e469c5997603728cab1bd0854ee799a862
1 /* sgiserial.c: Serial port driver for SGI machines.
3 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5 */
7 #include <linux/config.h> /* for CONFIG_REMOTE_DEBUG */
8 #include <linux/errno.h>
9 #include <linux/signal.h>
10 #include <linux/sched.h>
11 #include <linux/timer.h>
12 #include <linux/interrupt.h>
13 #include <linux/tty.h>
14 #include <linux/tty_flip.h>
15 #include <linux/major.h>
16 #include <linux/string.h>
17 #include <linux/fcntl.h>
18 #include <linux/mm.h>
19 #include <linux/kernel.h>
20 #include <linux/delay.h>
21 #include <linux/console.h>
22 #include <linux/init.h>
24 #include <asm/io.h>
25 #include <asm/irq.h>
26 #include <asm/sgialib.h>
27 #include <asm/system.h>
28 #include <asm/bitops.h>
29 #include <asm/sgihpc.h>
30 #include <asm/sgint23.h>
31 #include <asm/uaccess.h>
33 #include "sgiserial.h"
35 #define NUM_SERIAL 1 /* One chip on board. */
36 #define NUM_CHANNELS (NUM_SERIAL * 2)
38 extern wait_queue_head_t keypress_wait;
40 struct sgi_zslayout *zs_chips[NUM_SERIAL] = { 0, };
41 struct sgi_zschannel *zs_channels[NUM_CHANNELS] = { 0, 0, };
42 struct sgi_zschannel *zs_conschan;
43 struct sgi_zschannel *zs_kgdbchan;
45 struct sgi_serial zs_soft[NUM_CHANNELS];
46 struct sgi_serial *zs_chain; /* IRQ servicing chain */
47 static int zilog_irq = 21;
49 /* Console hooks... */
50 static int zs_cons_chanout = 0;
51 static int zs_cons_chanin = 0;
52 struct sgi_serial *zs_consinfo = 0;
54 static unsigned char kgdb_regs[16] = {
55 0, 0, 0, /* write 0, 1, 2 */
56 (Rx8 | RxENABLE), /* write 3 */
57 (X16CLK | SB1 | PAR_EVEN), /* write 4 */
58 (Tx8 | TxENAB), /* write 5 */
59 0, 0, 0, /* write 6, 7, 8 */
60 (NV), /* write 9 */
61 (NRZ), /* write 10 */
62 (TCBR | RCBR), /* write 11 */
63 0, 0, /* BRG time constant, write 12 + 13 */
64 (BRENABL), /* write 14 */
65 (DCDIE) /* write 15 */
68 static unsigned char zscons_regs[16] = {
69 0, /* write 0 */
70 (EXT_INT_ENAB | INT_ALL_Rx), /* write 1 */
71 0, /* write 2 */
72 (Rx8 | RxENABLE), /* write 3 */
73 (X16CLK), /* write 4 */
74 (DTR | Tx8 | TxENAB), /* write 5 */
75 0, 0, 0, /* write 6, 7, 8 */
76 (NV | MIE), /* write 9 */
77 (NRZ), /* write 10 */
78 (TCBR | RCBR), /* write 11 */
79 0, 0, /* BRG time constant, write 12 + 13 */
80 (BRENABL), /* write 14 */
81 (DCDIE | CTSIE | TxUIE | BRKIE) /* write 15 */
84 #define ZS_CLOCK 3672000 /* Zilog input clock rate */
86 DECLARE_TASK_QUEUE(tq_serial);
88 struct tty_driver serial_driver, callout_driver;
89 static int serial_refcount;
91 /* serial subtype definitions */
92 #define SERIAL_TYPE_NORMAL 1
93 #define SERIAL_TYPE_CALLOUT 2
95 /* number of characters left in xmit buffer before we ask for more */
96 #define WAKEUP_CHARS 256
98 /* Debugging... DEBUG_INTR is bad to use when one of the zs
99 * lines is your console ;(
101 #undef SERIAL_DEBUG_INTR
102 #undef SERIAL_DEBUG_OPEN
103 #undef SERIAL_DEBUG_FLOW
105 #define RS_STROBE_TIME 10
106 #define RS_ISR_PASS_LIMIT 256
108 #define _INLINE_ inline
110 static void change_speed(struct sgi_serial *info);
112 static struct tty_struct *serial_table[NUM_CHANNELS];
113 static struct termios *serial_termios[NUM_CHANNELS];
114 static struct termios *serial_termios_locked[NUM_CHANNELS];
116 #ifndef MIN
117 #define MIN(a,b) ((a) < (b) ? (a) : (b))
118 #endif
121 * tmp_buf is used as a temporary buffer by serial_write. We need to
122 * lock it in case the memcpy_fromfs blocks while swapping in a page,
123 * and some other program tries to do a serial write at the same time.
124 * Since the lock will only come under contention when the system is
125 * swapping and available memory is low, it makes sense to share one
126 * buffer across all the serial ports, since it significantly saves
127 * memory if large numbers of serial ports are open.
129 static unsigned char tmp_buf[4096]; /* This is cheating */
130 static DECLARE_MUTEX(tmp_buf_sem);
132 static inline int serial_paranoia_check(struct sgi_serial *info,
133 dev_t device, const char *routine)
135 #ifdef SERIAL_PARANOIA_CHECK
136 static const char *badmagic =
137 "Warning: bad magic number for serial struct (%d, %d) in %s\n";
138 static const char *badinfo =
139 "Warning: null sun_serial for (%d, %d) in %s\n";
141 if (!info) {
142 printk(badinfo, MAJOR(device), MINOR(device), routine);
143 return 1;
145 if (info->magic != SERIAL_MAGIC) {
146 printk(badmagic, MAJOR(device), MINOR(device), routine);
147 return 1;
149 #endif
150 return 0;
154 * This is used to figure out the divisor speeds and the timeouts
156 static int baud_table[] = {
157 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
158 9600, 19200, 38400, 57600, 115200, 0 };
161 * Reading and writing Zilog8530 registers. The delays are to make this
162 * driver work on the Sun4 which needs a settling delay after each chip
163 * register access, other machines handle this in hardware via auxiliary
164 * flip-flops which implement the settle time we do in software.
166 * read_zsreg() and write_zsreg() may get called from rs_kgdb_hook() before
167 * interrupts are enabled. Therefore we have to check ioc_iocontrol before we
168 * access it.
170 static inline unsigned char read_zsreg(struct sgi_zschannel *channel, unsigned char reg)
172 unsigned char retval;
173 volatile unsigned char junk;
175 udelay(2);
176 channel->control = reg;
177 if (ioc_icontrol)
178 junk = ioc_icontrol->istat0;
179 udelay(1);
180 retval = channel->control;
181 return retval;
184 static inline void write_zsreg(struct sgi_zschannel *channel, unsigned char reg, unsigned char value)
186 volatile unsigned char junk;
188 udelay(2);
189 channel->control = reg;
190 if (ioc_icontrol)
191 junk = ioc_icontrol->istat0;
192 udelay(1);
193 channel->control = value;
194 if (ioc_icontrol)
195 junk = ioc_icontrol->istat0;
196 return;
199 static inline void load_zsregs(struct sgi_zschannel *channel, unsigned char *regs)
201 ZS_CLEARERR(channel);
202 ZS_CLEARFIFO(channel);
203 /* Load 'em up */
204 write_zsreg(channel, R4, regs[R4]);
205 write_zsreg(channel, R10, regs[R10]);
206 write_zsreg(channel, R3, regs[R3] & ~RxENABLE);
207 write_zsreg(channel, R5, regs[R5] & ~TxENAB);
208 write_zsreg(channel, R1, regs[R1]);
209 write_zsreg(channel, R9, regs[R9]);
210 write_zsreg(channel, R11, regs[R11]);
211 write_zsreg(channel, R12, regs[R12]);
212 write_zsreg(channel, R13, regs[R13]);
213 write_zsreg(channel, R14, regs[R14]);
214 write_zsreg(channel, R15, regs[R15]);
215 write_zsreg(channel, R3, regs[R3]);
216 write_zsreg(channel, R5, regs[R5]);
217 return;
220 /* Sets or clears DTR/RTS on the requested line */
221 static inline void zs_rtsdtr(struct sgi_serial *ss, int set)
223 if(set) {
224 ss->curregs[5] |= (RTS | DTR);
225 ss->pendregs[5] = ss->curregs[5];
226 write_zsreg(ss->zs_channel, 5, ss->curregs[5]);
227 } else {
228 ss->curregs[5] &= ~(RTS | DTR);
229 ss->pendregs[5] = ss->curregs[5];
230 write_zsreg(ss->zs_channel, 5, ss->curregs[5]);
232 return;
235 static inline void kgdb_chaninit(struct sgi_serial *ss, int intson, int bps)
237 int brg;
239 if(intson) {
240 kgdb_regs[R1] = INT_ALL_Rx;
241 kgdb_regs[R9] |= MIE;
242 } else {
243 kgdb_regs[R1] = 0;
244 kgdb_regs[R9] &= ~MIE;
246 brg = BPS_TO_BRG(bps, ZS_CLOCK/ss->clk_divisor);
247 kgdb_regs[R12] = (brg & 255);
248 kgdb_regs[R13] = ((brg >> 8) & 255);
249 load_zsregs(ss->zs_channel, kgdb_regs);
252 /* Utility routines for the Zilog */
253 static inline int get_zsbaud(struct sgi_serial *ss)
255 struct sgi_zschannel *channel = ss->zs_channel;
256 int brg;
258 /* The baud rate is split up between two 8-bit registers in
259 * what is termed 'BRG time constant' format in my docs for
260 * the chip, it is a function of the clk rate the chip is
261 * receiving which happens to be constant.
263 brg = ((read_zsreg(channel, 13)&0xff) << 8);
264 brg |= (read_zsreg(channel, 12)&0xff);
265 return BRG_TO_BPS(brg, (ZS_CLOCK/(ss->clk_divisor)));
269 * ------------------------------------------------------------
270 * rs_stop() and rs_start()
272 * This routines are called before setting or resetting tty->stopped.
273 * They enable or disable transmitter interrupts, as necessary.
274 * ------------------------------------------------------------
276 static void rs_stop(struct tty_struct *tty)
278 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
279 unsigned long flags;
281 if (serial_paranoia_check(info, tty->device, "rs_stop"))
282 return;
284 save_flags(flags); cli();
285 if (info->curregs[5] & TxENAB) {
286 info->curregs[5] &= ~TxENAB;
287 info->pendregs[5] &= ~TxENAB;
288 write_zsreg(info->zs_channel, 5, info->curregs[5]);
290 restore_flags(flags);
293 static void rs_start(struct tty_struct *tty)
295 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
296 unsigned long flags;
298 if (serial_paranoia_check(info, tty->device, "rs_start"))
299 return;
301 save_flags(flags); cli();
302 if (info->xmit_cnt && info->xmit_buf && !(info->curregs[5] & TxENAB)) {
303 info->curregs[5] |= TxENAB;
304 info->pendregs[5] = info->curregs[5];
305 write_zsreg(info->zs_channel, 5, info->curregs[5]);
307 restore_flags(flags);
310 /* Drop into either the boot monitor or kadb upon receiving a break
311 * from keyboard/console input.
313 static void batten_down_hatches(void)
315 prom_imode();
316 #if 0
317 /* If we are doing kadb, we call the debugger
318 * else we just drop into the boot monitor.
319 * Note that we must flush the user windows
320 * first before giving up control.
322 printk("\n");
323 if((((unsigned long)linux_dbvec)>=DEBUG_FIRSTVADDR) &&
324 (((unsigned long)linux_dbvec)<=DEBUG_LASTVADDR))
325 sp_enter_debugger();
326 else
327 prom_halt();
329 /* XXX We want to notify the keyboard driver that all
330 * XXX keys are in the up state or else weird things
331 * XXX happen...
333 #endif
334 return;
337 /* On receive, this clears errors and the receiver interrupts */
338 static inline void rs_recv_clear(struct sgi_zschannel *zsc)
340 volatile unsigned char junk;
342 udelay(2);
343 zsc->control = ERR_RES;
344 junk = ioc_icontrol->istat0;
345 udelay(2);
346 zsc->control = RES_H_IUS;
347 junk = ioc_icontrol->istat0;
351 * ----------------------------------------------------------------------
353 * Here starts the interrupt handling routines. All of the following
354 * subroutines are declared as inline and are folded into
355 * rs_interrupt(). They were separated out for readability's sake.
357 * Note: rs_interrupt() is a "fast" interrupt, which means that it
358 * runs with interrupts turned off. People who may want to modify
359 * rs_interrupt() should try to keep the interrupt handler as fast as
360 * possible. After you are done making modifications, it is not a bad
361 * idea to do:
363 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
365 * and look at the resulting assemble code in serial.s.
367 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
368 * -----------------------------------------------------------------------
372 * This routine is used by the interrupt handler to schedule
373 * processing in the software interrupt portion of the driver.
375 static _INLINE_ void rs_sched_event(struct sgi_serial *info,
376 int event)
378 info->event |= 1 << event;
379 queue_task(&info->tqueue, &tq_serial);
380 mark_bh(SERIAL_BH);
383 #ifdef CONFIG_REMOTE_DEBUG
384 extern void set_async_breakpoint(unsigned int epc);
385 #endif
387 static _INLINE_ void receive_chars(struct sgi_serial *info, struct pt_regs *regs)
389 struct tty_struct *tty = info->tty;
390 volatile unsigned char junk;
391 unsigned char ch, stat;
393 udelay(2);
394 ch = info->zs_channel->data;
395 junk = ioc_icontrol->istat0;
396 udelay(2);
397 stat = read_zsreg(info->zs_channel, R1);
399 /* If this is the console keyboard, we need to handle
400 * L1-A's here.
402 if(info->is_cons) {
403 if(ch==0) { /* whee, break received */
404 batten_down_hatches();
405 rs_recv_clear(info->zs_channel);
406 return;
407 } else if (ch == 1) {
408 show_state();
409 return;
410 } else if (ch == 2) {
411 show_buffers();
412 return;
414 /* It is a 'keyboard interrupt' ;-) */
415 wake_up(&keypress_wait);
417 /* Look for kgdb 'stop' character, consult the gdb documentation
418 * for remote target debugging and arch/sparc/kernel/sparc-stub.c
419 * to see how all this works.
421 #ifdef CONFIG_REMOTE_DEBUG
422 if((info->kgdb_channel) && (ch =='\003')) {
423 set_async_breakpoint(read_32bit_cp0_register(CP0_EPC));
424 goto clear_and_exit;
426 #endif
427 if(!tty)
428 goto clear_and_exit;
430 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
431 queue_task(&tty->flip.tqueue, &tq_timer);
432 tty->flip.count++;
433 if(stat & PAR_ERR)
434 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
435 else if(stat & Rx_OVR)
436 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
437 else if(stat & CRC_ERR)
438 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
439 else
440 *tty->flip.flag_buf_ptr++ = 0; /* XXX */
441 *tty->flip.char_buf_ptr++ = ch;
443 queue_task(&tty->flip.tqueue, &tq_timer);
445 clear_and_exit:
446 rs_recv_clear(info->zs_channel);
447 return;
450 static _INLINE_ void transmit_chars(struct sgi_serial *info)
452 volatile unsigned char junk;
454 /* P3: In theory we have to test readiness here because a
455 * serial console can clog the chip through rs_put_char().
456 * David did not do this. I think he relies on 3-chars FIFO in 8530.
457 * Let's watch for lost _output_ characters. XXX
460 /* SGI ADDENDUM: On most SGI machines, the Zilog does possess
461 * a 16 or 17 byte fifo, so no worries. -dm
464 if (info->x_char) {
465 /* Send next char */
466 udelay(2);
467 info->zs_channel->data = info->x_char;
468 junk = ioc_icontrol->istat0;
470 info->x_char = 0;
471 goto clear_and_return;
474 if((info->xmit_cnt <= 0) || info->tty->stopped) {
475 /* That's peculiar... */
476 udelay(2);
477 info->zs_channel->control = RES_Tx_P;
478 junk = ioc_icontrol->istat0;
479 goto clear_and_return;
482 /* Send char */
483 udelay(2);
484 info->zs_channel->data = info->xmit_buf[info->xmit_tail++];
485 junk = ioc_icontrol->istat0;
487 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
488 info->xmit_cnt--;
490 if (info->xmit_cnt < WAKEUP_CHARS)
491 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
493 if(info->xmit_cnt <= 0) {
494 udelay(2);
495 info->zs_channel->control = RES_Tx_P;
496 junk = ioc_icontrol->istat0;
497 goto clear_and_return;
500 clear_and_return:
501 /* Clear interrupt */
502 udelay(2);
503 info->zs_channel->control = RES_H_IUS;
504 junk = ioc_icontrol->istat0;
505 return;
508 static _INLINE_ void status_handle(struct sgi_serial *info)
510 volatile unsigned char junk;
511 unsigned char status;
513 /* Get status from Read Register 0 */
514 udelay(2);
515 status = info->zs_channel->control;
516 junk = ioc_icontrol->istat0;
517 /* Clear status condition... */
518 udelay(2);
519 info->zs_channel->control = RES_EXT_INT;
520 junk = ioc_icontrol->istat0;
521 /* Clear the interrupt */
522 udelay(2);
523 info->zs_channel->control = RES_H_IUS;
524 junk = ioc_icontrol->istat0;
526 #if 0
527 if(status & DCD) {
528 if((info->tty->termios->c_cflag & CRTSCTS) &&
529 ((info->curregs[3] & AUTO_ENAB)==0)) {
530 info->curregs[3] |= AUTO_ENAB;
531 info->pendregs[3] |= AUTO_ENAB;
532 write_zsreg(info->zs_channel, 3, info->curregs[3]);
534 } else {
535 if((info->curregs[3] & AUTO_ENAB)) {
536 info->curregs[3] &= ~AUTO_ENAB;
537 info->pendregs[3] &= ~AUTO_ENAB;
538 write_zsreg(info->zs_channel, 3, info->curregs[3]);
541 #endif
542 /* Whee, if this is console input and this is a
543 * 'break asserted' status change interrupt, call
544 * the boot prom.
546 if((status & BRK_ABRT) && info->break_abort)
547 batten_down_hatches();
549 /* XXX Whee, put in a buffer somewhere, the status information
550 * XXX whee whee whee... Where does the information go...
552 return;
556 * This is the serial driver's generic interrupt routine
558 void rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
560 struct sgi_serial * info = (struct sgi_serial *) dev_id;
561 unsigned char zs_intreg;
563 zs_intreg = read_zsreg(info->zs_next->zs_channel, 3);
565 /* NOTE: The read register 3, which holds the irq status,
566 * does so for both channels on each chip. Although
567 * the status value itself must be read from the A
568 * channel and is only valid when read from channel A.
569 * Yes... broken hardware...
571 #define CHAN_A_IRQMASK (CHARxIP | CHATxIP | CHAEXT)
572 #define CHAN_B_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
574 /* *** Chip 1 *** */
575 /* Channel B -- /dev/ttyb, could be the console */
576 if(zs_intreg & CHAN_B_IRQMASK) {
577 if (zs_intreg & CHBRxIP)
578 receive_chars(info, regs);
579 if (zs_intreg & CHBTxIP)
580 transmit_chars(info);
581 if (zs_intreg & CHBEXT)
582 status_handle(info);
585 info=info->zs_next;
587 /* Channel A -- /dev/ttya, could be the console */
588 if(zs_intreg & CHAN_A_IRQMASK) {
589 if (zs_intreg & CHARxIP)
590 receive_chars(info, regs);
591 if (zs_intreg & CHATxIP)
592 transmit_chars(info);
593 if (zs_intreg & CHAEXT)
594 status_handle(info);
599 * -------------------------------------------------------------------
600 * Here ends the serial interrupt routines.
601 * -------------------------------------------------------------------
605 * This routine is used to handle the "bottom half" processing for the
606 * serial driver, known also the "software interrupt" processing.
607 * This processing is done at the kernel interrupt level, after the
608 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
609 * is where time-consuming activities which can not be done in the
610 * interrupt driver proper are done; the interrupt driver schedules
611 * them using rs_sched_event(), and they get done here.
613 static void do_serial_bh(void)
615 run_task_queue(&tq_serial);
618 static void do_softint(void *private_)
620 struct sgi_serial *info = (struct sgi_serial *) private_;
621 struct tty_struct *tty;
623 tty = info->tty;
624 if (!tty)
625 return;
627 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
628 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
629 tty->ldisc.write_wakeup)
630 (tty->ldisc.write_wakeup)(tty);
631 wake_up_interruptible(&tty->write_wait);
636 * This routine is called from the scheduler tqueue when the interrupt
637 * routine has signalled that a hangup has occurred. The path of
638 * hangup processing is:
640 * serial interrupt routine -> (scheduler tqueue) ->
641 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
644 static void do_serial_hangup(void *private_)
646 struct sgi_serial *info = (struct sgi_serial *) private_;
647 struct tty_struct *tty;
649 tty = info->tty;
650 if (!tty)
651 return;
653 tty_hangup(tty);
658 * This subroutine is called when the RS_TIMER goes off. It is used
659 * by the serial driver to handle ports that do not have an interrupt
660 * (irq=0). This doesn't work at all for 16450's, as a sun has a Z8530.
663 static void rs_timer(void)
665 printk("rs_timer called\n");
666 prom_halt();
667 return;
670 static int startup(struct sgi_serial * info)
672 volatile unsigned char junk;
673 unsigned long flags;
675 if (info->flags & ZILOG_INITIALIZED)
676 return 0;
678 if (!info->xmit_buf) {
679 info->xmit_buf = (unsigned char *) get_free_page(GFP_KERNEL);
680 if (!info->xmit_buf)
681 return -ENOMEM;
684 save_flags(flags); cli();
686 #ifdef SERIAL_DEBUG_OPEN
687 printk("starting up ttys%d (irq %d)...", info->line, info->irq);
688 #endif
691 * Clear the FIFO buffers and disable them
692 * (they will be reenabled in change_speed())
694 ZS_CLEARFIFO(info->zs_channel);
695 info->xmit_fifo_size = 1;
698 * Clear the interrupt registers.
700 udelay(2);
701 info->zs_channel->control = ERR_RES;
702 junk = ioc_icontrol->istat0;
703 udelay(2);
704 info->zs_channel->control = RES_H_IUS;
705 junk = ioc_icontrol->istat0;
708 * Now, initialize the Zilog
710 zs_rtsdtr(info, 1);
713 * Finally, enable sequencing and interrupts
715 info->curregs[1] |= (info->curregs[1] & ~0x18) | (EXT_INT_ENAB|INT_ALL_Rx);
716 info->pendregs[1] = info->curregs[1];
717 info->curregs[3] |= (RxENABLE | Rx8);
718 info->pendregs[3] = info->curregs[3];
719 /* We enable Tx interrupts as needed. */
720 info->curregs[5] |= (TxENAB | Tx8);
721 info->pendregs[5] = info->curregs[5];
722 info->curregs[9] |= (NV | MIE);
723 info->pendregs[9] = info->curregs[9];
724 write_zsreg(info->zs_channel, 3, info->curregs[3]);
725 write_zsreg(info->zs_channel, 5, info->curregs[5]);
726 write_zsreg(info->zs_channel, 9, info->curregs[9]);
729 * And clear the interrupt registers again for luck.
731 udelay(2);
732 info->zs_channel->control = ERR_RES;
733 junk = ioc_icontrol->istat0;
734 udelay(2);
735 info->zs_channel->control = RES_H_IUS;
736 junk = ioc_icontrol->istat0;
738 if (info->tty)
739 clear_bit(TTY_IO_ERROR, &info->tty->flags);
740 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
743 * Set up serial timers...
745 #if 0 /* Works well and stops the machine. */
746 timer_table[RS_TIMER].expires = jiffies + 2;
747 timer_active |= 1 << RS_TIMER;
748 #endif
751 * and set the speed of the serial port
753 change_speed(info);
755 info->flags |= ZILOG_INITIALIZED;
756 restore_flags(flags);
757 return 0;
761 * This routine will shutdown a serial port; interrupts are disabled, and
762 * DTR is dropped if the hangup on close termio flag is on.
764 static void shutdown(struct sgi_serial * info)
766 unsigned long flags;
768 if (!(info->flags & ZILOG_INITIALIZED))
769 return;
771 #ifdef SERIAL_DEBUG_OPEN
772 printk("Shutting down serial port %d (irq %d)....", info->line,
773 info->irq);
774 #endif
776 save_flags(flags); cli(); /* Disable interrupts */
778 if (info->xmit_buf) {
779 free_page((unsigned long) info->xmit_buf);
780 info->xmit_buf = 0;
783 if (info->tty)
784 set_bit(TTY_IO_ERROR, &info->tty->flags);
786 info->flags &= ~ZILOG_INITIALIZED;
787 restore_flags(flags);
791 * This routine is called to set the UART divisor registers to match
792 * the specified baud rate for a serial port.
794 static void change_speed(struct sgi_serial *info)
796 unsigned short port;
797 unsigned cflag;
798 int i;
799 int brg;
801 if (!info->tty || !info->tty->termios)
802 return;
803 cflag = info->tty->termios->c_cflag;
804 if (!(port = info->port))
805 return;
806 i = cflag & CBAUD;
807 if (i & CBAUDEX) {
808 /* XXX CBAUDEX is not obeyed.
809 * It is impossible at a 32bits SPARC.
810 * But we have to report this to user ... someday.
812 i = B9600;
814 if (i == 0) {
815 /* XXX B0, hangup the line. */
816 do_serial_hangup(info);
817 } else if (baud_table[i]) {
818 info->zs_baud = baud_table[i];
819 info->clk_divisor = 16;
821 info->curregs[4] = X16CLK;
822 info->curregs[11] = TCBR | RCBR;
823 brg = BPS_TO_BRG(info->zs_baud, ZS_CLOCK/info->clk_divisor);
824 info->curregs[12] = (brg & 255);
825 info->curregs[13] = ((brg >> 8) & 255);
826 info->curregs[14] = BRENABL;
829 /* byte size and parity */
830 switch (cflag & CSIZE) {
831 case CS5:
832 info->curregs[3] &= ~(0xc0);
833 info->curregs[3] |= Rx5;
834 info->pendregs[3] = info->curregs[3];
835 info->curregs[5] &= ~(0xe0);
836 info->curregs[5] |= Tx5;
837 info->pendregs[5] = info->curregs[5];
838 break;
839 case CS6:
840 info->curregs[3] &= ~(0xc0);
841 info->curregs[3] |= Rx6;
842 info->pendregs[3] = info->curregs[3];
843 info->curregs[5] &= ~(0xe0);
844 info->curregs[5] |= Tx6;
845 info->pendregs[5] = info->curregs[5];
846 break;
847 case CS7:
848 info->curregs[3] &= ~(0xc0);
849 info->curregs[3] |= Rx7;
850 info->pendregs[3] = info->curregs[3];
851 info->curregs[5] &= ~(0xe0);
852 info->curregs[5] |= Tx7;
853 info->pendregs[5] = info->curregs[5];
854 break;
855 case CS8:
856 default: /* defaults to 8 bits */
857 info->curregs[3] &= ~(0xc0);
858 info->curregs[3] |= Rx8;
859 info->pendregs[3] = info->curregs[3];
860 info->curregs[5] &= ~(0xe0);
861 info->curregs[5] |= Tx8;
862 info->pendregs[5] = info->curregs[5];
863 break;
865 info->curregs[4] &= ~(0x0c);
866 if (cflag & CSTOPB) {
867 info->curregs[4] |= SB2;
868 } else {
869 info->curregs[4] |= SB1;
871 info->pendregs[4] = info->curregs[4];
872 if (cflag & PARENB) {
873 info->curregs[4] |= PAR_ENA;
874 info->pendregs[4] |= PAR_ENA;
875 } else {
876 info->curregs[4] &= ~PAR_ENA;
877 info->pendregs[4] &= ~PAR_ENA;
879 if (!(cflag & PARODD)) {
880 info->curregs[4] |= PAR_EVEN;
881 info->pendregs[4] |= PAR_EVEN;
882 } else {
883 info->curregs[4] &= ~PAR_EVEN;
884 info->pendregs[4] &= ~PAR_EVEN;
887 /* Load up the new values */
888 load_zsregs(info->zs_channel, info->curregs);
890 return;
893 /* This is for console output over ttya/ttyb */
894 static void rs_put_char(char ch)
896 struct sgi_zschannel *chan = zs_conschan;
897 volatile unsigned char junk;
898 int flags, loops = 0;
900 save_flags(flags); cli();
901 while(((junk = chan->control) & Tx_BUF_EMP)==0 && loops < 10000) {
902 loops++;
903 udelay(2);
906 udelay(2);
907 chan->data = ch;
908 junk = ioc_icontrol->istat0;
909 restore_flags(flags);
912 /* These are for receiving and sending characters under the kgdb
913 * source level kernel debugger.
915 int putDebugChar(char kgdb_char)
917 struct sgi_zschannel *chan = zs_kgdbchan;
918 volatile unsigned char junk;
919 unsigned long flags;
921 save_flags(flags); cli();
922 udelay(2);
923 while((chan->control & Tx_BUF_EMP)==0)
924 udelay(2);
926 udelay(2);
927 chan->data = kgdb_char;
928 junk = ioc_icontrol->istat0;
929 restore_flags(flags);
931 return 1;
934 char getDebugChar(void)
936 struct sgi_zschannel *chan = zs_kgdbchan;
937 unsigned char junk;
939 while((chan->control & Rx_CH_AV)==0)
940 udelay(2);
942 junk = ioc_icontrol->istat0;
943 udelay(2);
944 return chan->data;
948 * Fair output driver allows a process to speak.
950 static void rs_fair_output(void)
952 int left; /* Output no more than that */
953 unsigned long flags;
954 struct sgi_serial *info = zs_consinfo;
955 volatile unsigned char junk;
956 char c;
958 if (info == 0) return;
959 if (info->xmit_buf == 0) return;
961 save_flags(flags); cli();
962 left = info->xmit_cnt;
963 while (left != 0) {
964 c = info->xmit_buf[info->xmit_tail];
965 info->xmit_tail = (info->xmit_tail+1) & (SERIAL_XMIT_SIZE-1);
966 info->xmit_cnt--;
967 restore_flags(flags);
969 rs_put_char(c);
971 save_flags(flags); cli();
972 left = MIN(info->xmit_cnt, left-1);
975 /* Last character is being transmitted now (hopefully). */
976 udelay(2);
977 zs_conschan->control = RES_Tx_P;
978 junk = ioc_icontrol->istat0;
980 restore_flags(flags);
981 return;
985 static int rs_write(struct tty_struct * tty, int from_user,
986 const unsigned char *buf, int count)
988 int c, total = 0;
989 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
990 unsigned long flags;
992 if (serial_paranoia_check(info, tty->device, "rs_write"))
993 return 0;
995 if (!tty || !info->xmit_buf)
996 return 0;
998 save_flags(flags);
999 while (1) {
1000 cli();
1001 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1002 SERIAL_XMIT_SIZE - info->xmit_head));
1003 if (c <= 0)
1004 break;
1006 if (from_user) {
1007 down(&tmp_buf_sem);
1008 copy_from_user(tmp_buf, buf, c);
1009 c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1010 SERIAL_XMIT_SIZE - info->xmit_head));
1011 memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
1012 up(&tmp_buf_sem);
1013 } else
1014 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1015 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1016 info->xmit_cnt += c;
1017 restore_flags(flags);
1018 buf += c;
1019 count -= c;
1020 total += c;
1022 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1023 !(info->curregs[5] & TxENAB)) {
1024 /* Enable transmitter */
1025 info->curregs[1] |= TxINT_ENAB|EXT_INT_ENAB;
1026 info->pendregs[1] |= TxINT_ENAB|EXT_INT_ENAB;
1027 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1028 info->curregs[5] |= TxENAB;
1029 info->pendregs[5] |= TxENAB;
1030 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1032 restore_flags(flags);
1033 return total;
1036 static int rs_write_room(struct tty_struct *tty)
1038 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
1039 int ret;
1041 if (serial_paranoia_check(info, tty->device, "rs_write_room"))
1042 return 0;
1043 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1044 if (ret < 0)
1045 ret = 0;
1046 return ret;
1049 static int rs_chars_in_buffer(struct tty_struct *tty)
1051 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
1053 if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
1054 return 0;
1055 return info->xmit_cnt;
1058 static void rs_flush_buffer(struct tty_struct *tty)
1060 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
1062 if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
1063 return;
1064 cli();
1065 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1066 sti();
1067 wake_up_interruptible(&tty->write_wait);
1068 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1069 tty->ldisc.write_wakeup)
1070 (tty->ldisc.write_wakeup)(tty);
1073 static void rs_flush_chars(struct tty_struct *tty)
1075 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
1076 unsigned long flags;
1078 if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
1079 return;
1081 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1082 !info->xmit_buf)
1083 return;
1085 /* Enable transmitter */
1086 save_flags(flags); cli();
1087 info->curregs[1] |= TxINT_ENAB|EXT_INT_ENAB;
1088 info->pendregs[1] |= TxINT_ENAB|EXT_INT_ENAB;
1089 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1090 info->curregs[5] |= TxENAB;
1091 info->pendregs[5] |= TxENAB;
1092 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1095 * Send a first (bootstrapping) character. A best solution is
1096 * to call transmit_chars() here which handles output in a
1097 * generic way. Current transmit_chars() not only transmits,
1098 * but resets interrupts also what we do not desire here.
1099 * XXX Discuss with David.
1101 if (info->zs_channel->control & Tx_BUF_EMP) {
1102 volatile unsigned char junk;
1104 /* Send char */
1105 udelay(2);
1106 info->zs_channel->data = info->xmit_buf[info->xmit_tail++];
1107 junk = ioc_icontrol->istat0;
1108 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
1109 info->xmit_cnt--;
1111 restore_flags(flags);
1115 * ------------------------------------------------------------
1116 * rs_throttle()
1118 * This routine is called by the upper-layer tty layer to signal that
1119 * incoming characters should be throttled.
1120 * ------------------------------------------------------------
1122 static void rs_throttle(struct tty_struct * tty)
1124 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
1125 #ifdef SERIAL_DEBUG_THROTTLE
1126 char buf[64];
1128 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1129 tty->ldisc.chars_in_buffer(tty));
1130 #endif
1132 if (serial_paranoia_check(info, tty->device, "rs_throttle"))
1133 return;
1135 if (I_IXOFF(tty))
1136 info->x_char = STOP_CHAR(tty);
1138 /* Turn off RTS line */
1139 cli();
1140 info->curregs[5] &= ~RTS;
1141 info->pendregs[5] &= ~RTS;
1142 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1143 sti();
1146 static void rs_unthrottle(struct tty_struct * tty)
1148 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
1149 #ifdef SERIAL_DEBUG_THROTTLE
1150 char buf[64];
1152 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1153 tty->ldisc.chars_in_buffer(tty));
1154 #endif
1156 if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
1157 return;
1159 if (I_IXOFF(tty)) {
1160 if (info->x_char)
1161 info->x_char = 0;
1162 else
1163 info->x_char = START_CHAR(tty);
1166 /* Assert RTS line */
1167 cli();
1168 info->curregs[5] |= RTS;
1169 info->pendregs[5] |= RTS;
1170 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1171 sti();
1175 * ------------------------------------------------------------
1176 * rs_ioctl() and friends
1177 * ------------------------------------------------------------
1180 static int get_serial_info(struct sgi_serial * info,
1181 struct serial_struct * retinfo)
1183 struct serial_struct tmp;
1185 if (!retinfo)
1186 return -EFAULT;
1187 memset(&tmp, 0, sizeof(tmp));
1188 tmp.type = info->type;
1189 tmp.line = info->line;
1190 tmp.port = info->port;
1191 tmp.irq = info->irq;
1192 tmp.flags = info->flags;
1193 tmp.baud_base = info->baud_base;
1194 tmp.close_delay = info->close_delay;
1195 tmp.closing_wait = info->closing_wait;
1196 tmp.custom_divisor = info->custom_divisor;
1197 return copy_to_user(retinfo,&tmp,sizeof(*retinfo));
1200 static int set_serial_info(struct sgi_serial * info,
1201 struct serial_struct * new_info)
1203 struct serial_struct new_serial;
1204 struct sgi_serial old_info;
1205 int retval = 0;
1207 if (!new_info)
1208 return -EFAULT;
1209 copy_from_user(&new_serial,new_info,sizeof(new_serial));
1210 old_info = *info;
1212 if (!capable(CAP_SYS_ADMIN)) {
1213 if ((new_serial.baud_base != info->baud_base) ||
1214 (new_serial.type != info->type) ||
1215 (new_serial.close_delay != info->close_delay) ||
1216 ((new_serial.flags & ~ZILOG_USR_MASK) !=
1217 (info->flags & ~ZILOG_USR_MASK)))
1218 return -EPERM;
1219 info->flags = ((info->flags & ~ZILOG_USR_MASK) |
1220 (new_serial.flags & ZILOG_USR_MASK));
1221 info->custom_divisor = new_serial.custom_divisor;
1222 goto check_and_exit;
1225 if (info->count > 1)
1226 return -EBUSY;
1229 * OK, past this point, all the error checking has been done.
1230 * At this point, we start making changes.....
1233 info->baud_base = new_serial.baud_base;
1234 info->flags = ((info->flags & ~ZILOG_FLAGS) |
1235 (new_serial.flags & ZILOG_FLAGS));
1236 info->type = new_serial.type;
1237 info->close_delay = new_serial.close_delay;
1238 info->closing_wait = new_serial.closing_wait;
1240 check_and_exit:
1241 retval = startup(info);
1242 return retval;
1246 * get_lsr_info - get line status register info
1248 * Purpose: Let user call ioctl() to get info when the UART physically
1249 * is emptied. On bus types like RS485, the transmitter must
1250 * release the bus after transmitting. This must be done when
1251 * the transmit shift register is empty, not be done when the
1252 * transmit holding register is empty. This functionality
1253 * allows an RS485 driver to be written in user space.
1255 static int get_lsr_info(struct sgi_serial * info, unsigned int *value)
1257 volatile unsigned char junk;
1258 unsigned char status;
1260 cli();
1261 udelay(2);
1262 status = info->zs_channel->control;
1263 junk = ioc_icontrol->istat0;
1264 sti();
1265 return put_user(status,value);
1269 * This routine sends a break character out the serial port.
1271 static void send_break( struct sgi_serial * info, int duration)
1273 if (!info->port)
1274 return;
1275 current->state = TASK_INTERRUPTIBLE;
1276 cli();
1277 write_zsreg(info->zs_channel, 5, (info->curregs[5] | SND_BRK));
1278 schedule_timeout(duration);
1279 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1280 sti();
1283 static int rs_ioctl(struct tty_struct *tty, struct file * file,
1284 unsigned int cmd, unsigned long arg)
1286 int error;
1287 struct sgi_serial * info = (struct sgi_serial *)tty->driver_data;
1288 int retval;
1290 if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
1291 return -ENODEV;
1293 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1294 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1295 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
1296 if (tty->flags & (1 << TTY_IO_ERROR))
1297 return -EIO;
1300 switch (cmd) {
1301 case TCSBRK: /* SVID version: non-zero arg --> no break */
1302 retval = tty_check_change(tty);
1303 if (retval)
1304 return retval;
1305 tty_wait_until_sent(tty, 0);
1306 if (!arg)
1307 send_break(info, HZ/4); /* 1/4 second */
1308 return 0;
1309 case TCSBRKP: /* support for POSIX tcsendbreak() */
1310 retval = tty_check_change(tty);
1311 if (retval)
1312 return retval;
1313 tty_wait_until_sent(tty, 0);
1314 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1315 return 0;
1316 case TIOCGSOFTCAR:
1317 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
1318 if (error)
1319 return error;
1320 put_user(C_CLOCAL(tty) ? 1 : 0,
1321 (unsigned long *) arg);
1322 return 0;
1323 case TIOCSSOFTCAR:
1324 error = get_user(arg, (unsigned long *)arg);
1325 if (error)
1326 return error;
1327 tty->termios->c_cflag =
1328 ((tty->termios->c_cflag & ~CLOCAL) |
1329 (arg ? CLOCAL : 0));
1330 return 0;
1331 case TIOCGSERIAL:
1332 error = verify_area(VERIFY_WRITE, (void *) arg,
1333 sizeof(struct serial_struct));
1334 if (error)
1335 return error;
1336 return get_serial_info(info,
1337 (struct serial_struct *) arg);
1338 case TIOCSSERIAL:
1339 return set_serial_info(info,
1340 (struct serial_struct *) arg);
1341 case TIOCSERGETLSR: /* Get line status register */
1342 error = verify_area(VERIFY_WRITE, (void *) arg,
1343 sizeof(unsigned int));
1344 if (error)
1345 return error;
1346 else
1347 return get_lsr_info(info, (unsigned int *) arg);
1349 case TIOCSERGSTRUCT:
1350 error = verify_area(VERIFY_WRITE, (void *) arg,
1351 sizeof(struct sgi_serial));
1352 if (error)
1353 return error;
1354 copy_to_user((struct sun_serial *) arg,
1355 info, sizeof(struct sgi_serial));
1356 return 0;
1358 default:
1359 return -ENOIOCTLCMD;
1361 return 0;
1364 static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1366 struct sgi_serial *info = (struct sgi_serial *)tty->driver_data;
1368 if (tty->termios->c_cflag == old_termios->c_cflag)
1369 return;
1371 change_speed(info);
1373 if ((old_termios->c_cflag & CRTSCTS) &&
1374 !(tty->termios->c_cflag & CRTSCTS)) {
1375 tty->hw_stopped = 0;
1376 rs_start(tty);
1381 * ------------------------------------------------------------
1382 * rs_close()
1384 * This routine is called when the serial port gets closed. First, we
1385 * wait for the last remaining data to be sent. Then, we unlink its
1386 * ZILOG structure from the interrupt chain if necessary, and we free
1387 * that IRQ if nothing is left in the chain.
1388 * ------------------------------------------------------------
1390 static void rs_close(struct tty_struct *tty, struct file * filp)
1392 struct sgi_serial * info = (struct sgi_serial *)tty->driver_data;
1393 unsigned long flags;
1395 if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
1396 return;
1398 save_flags(flags); cli();
1400 if (tty_hung_up_p(filp)) {
1401 restore_flags(flags);
1402 return;
1405 #ifdef SERIAL_DEBUG_OPEN
1406 printk("rs_close ttys%d, count = %d\n", info->line, info->count);
1407 #endif
1408 if ((tty->count == 1) && (info->count != 1)) {
1410 * Uh, oh. tty->count is 1, which means that the tty
1411 * structure will be freed. Info->count should always
1412 * be one in these conditions. If it's greater than
1413 * one, we've got real problems, since it means the
1414 * serial port won't be shutdown.
1416 printk("rs_close: bad serial port count; tty->count is 1, "
1417 "info->count is %d\n", info->count);
1418 info->count = 1;
1420 if (--info->count < 0) {
1421 printk("rs_close: bad serial port count for ttys%d: %d\n",
1422 info->line, info->count);
1423 info->count = 0;
1425 if (info->count) {
1426 restore_flags(flags);
1427 return;
1429 info->flags |= ZILOG_CLOSING;
1431 * Save the termios structure, since this port may have
1432 * separate termios for callout and dialin.
1434 if (info->flags & ZILOG_NORMAL_ACTIVE)
1435 info->normal_termios = *tty->termios;
1436 if (info->flags & ZILOG_CALLOUT_ACTIVE)
1437 info->callout_termios = *tty->termios;
1439 * Now we wait for the transmit buffer to clear; and we notify
1440 * the line discipline to only process XON/XOFF characters.
1442 tty->closing = 1;
1443 if (info->closing_wait != ZILOG_CLOSING_WAIT_NONE)
1444 tty_wait_until_sent(tty, info->closing_wait);
1446 * At this point we stop accepting input. To do this, we
1447 * disable the receive line status interrupts, and tell the
1448 * interrupt driver to stop checking the data ready bit in the
1449 * line status register.
1451 /** if (!info->iscons) ... **/
1452 info->curregs[3] &= ~RxENABLE;
1453 info->pendregs[3] = info->curregs[3];
1454 write_zsreg(info->zs_channel, 3, info->curregs[3]);
1455 info->curregs[1] &= ~(0x18);
1456 info->pendregs[1] = info->curregs[1];
1457 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1458 ZS_CLEARFIFO(info->zs_channel);
1460 shutdown(info);
1461 if (tty->driver.flush_buffer)
1462 tty->driver.flush_buffer(tty);
1463 if (tty->ldisc.flush_buffer)
1464 tty->ldisc.flush_buffer(tty);
1465 tty->closing = 0;
1466 info->event = 0;
1467 info->tty = 0;
1468 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1469 if (tty->ldisc.close)
1470 (tty->ldisc.close)(tty);
1471 tty->ldisc = ldiscs[N_TTY];
1472 tty->termios->c_line = N_TTY;
1473 if (tty->ldisc.open)
1474 (tty->ldisc.open)(tty);
1476 if (info->blocked_open) {
1477 if (info->close_delay) {
1478 current->state = TASK_INTERRUPTIBLE;
1479 schedule_timeout(info->close_delay);
1481 wake_up_interruptible(&info->open_wait);
1483 info->flags &= ~(ZILOG_NORMAL_ACTIVE|ZILOG_CALLOUT_ACTIVE|
1484 ZILOG_CLOSING);
1485 wake_up_interruptible(&info->close_wait);
1486 restore_flags(flags);
1490 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1492 void rs_hangup(struct tty_struct *tty)
1494 struct sgi_serial * info = (struct sgi_serial *)tty->driver_data;
1496 if (serial_paranoia_check(info, tty->device, "rs_hangup"))
1497 return;
1499 rs_flush_buffer(tty);
1500 shutdown(info);
1501 info->event = 0;
1502 info->count = 0;
1503 info->flags &= ~(ZILOG_NORMAL_ACTIVE|ZILOG_CALLOUT_ACTIVE);
1504 info->tty = 0;
1505 wake_up_interruptible(&info->open_wait);
1509 * ------------------------------------------------------------
1510 * rs_open() and friends
1511 * ------------------------------------------------------------
1513 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1514 struct sgi_serial *info)
1516 DECLARE_WAITQUEUE(wait, current);
1517 int retval;
1518 int do_clocal = 0;
1521 * If the device is in the middle of being closed, then block
1522 * until it's done, and then try again.
1524 if (info->flags & ZILOG_CLOSING) {
1525 interruptible_sleep_on(&info->close_wait);
1526 #ifdef SERIAL_DO_RESTART
1527 if (info->flags & ZILOG_HUP_NOTIFY)
1528 return -EAGAIN;
1529 else
1530 return -ERESTARTSYS;
1531 #else
1532 return -EAGAIN;
1533 #endif
1537 * If this is a callout device, then just make sure the normal
1538 * device isn't being used.
1540 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
1541 if (info->flags & ZILOG_NORMAL_ACTIVE)
1542 return -EBUSY;
1543 if ((info->flags & ZILOG_CALLOUT_ACTIVE) &&
1544 (info->flags & ZILOG_SESSION_LOCKOUT) &&
1545 (info->session != current->session))
1546 return -EBUSY;
1547 if ((info->flags & ZILOG_CALLOUT_ACTIVE) &&
1548 (info->flags & ZILOG_PGRP_LOCKOUT) &&
1549 (info->pgrp != current->pgrp))
1550 return -EBUSY;
1551 info->flags |= ZILOG_CALLOUT_ACTIVE;
1552 return 0;
1556 * If non-blocking mode is set, or the port is not enabled,
1557 * then make the check up front and then exit.
1559 if ((filp->f_flags & O_NONBLOCK) ||
1560 (tty->flags & (1 << TTY_IO_ERROR))) {
1561 if (info->flags & ZILOG_CALLOUT_ACTIVE)
1562 return -EBUSY;
1563 info->flags |= ZILOG_NORMAL_ACTIVE;
1564 return 0;
1567 if (info->flags & ZILOG_CALLOUT_ACTIVE) {
1568 if (info->normal_termios.c_cflag & CLOCAL)
1569 do_clocal = 1;
1570 } else {
1571 if (tty->termios->c_cflag & CLOCAL)
1572 do_clocal = 1;
1576 * Block waiting for the carrier detect and the line to become
1577 * free (i.e., not in use by the callout). While we are in
1578 * this loop, info->count is dropped by one, so that
1579 * rs_close() knows when to free things. We restore it upon
1580 * exit, either normal or abnormal.
1582 retval = 0;
1583 add_wait_queue(&info->open_wait, &wait);
1584 #ifdef SERIAL_DEBUG_OPEN
1585 printk("block_til_ready before block: ttys%d, count = %d\n",
1586 info->line, info->count);
1587 #endif
1588 info->count--;
1589 info->blocked_open++;
1590 while (1) {
1591 cli();
1592 if (!(info->flags & ZILOG_CALLOUT_ACTIVE))
1593 zs_rtsdtr(info, 1);
1594 sti();
1595 current->state = TASK_INTERRUPTIBLE;
1596 if (tty_hung_up_p(filp) ||
1597 !(info->flags & ZILOG_INITIALIZED)) {
1598 #ifdef SERIAL_DO_RESTART
1599 if (info->flags & ZILOG_HUP_NOTIFY)
1600 retval = -EAGAIN;
1601 else
1602 retval = -ERESTARTSYS;
1603 #else
1604 retval = -EAGAIN;
1605 #endif
1606 break;
1608 if (!(info->flags & ZILOG_CALLOUT_ACTIVE) &&
1609 !(info->flags & ZILOG_CLOSING) && do_clocal)
1610 break;
1611 if (signal_pending(current)) {
1612 retval = -ERESTARTSYS;
1613 break;
1615 #ifdef SERIAL_DEBUG_OPEN
1616 printk("block_til_ready blocking: ttys%d, count = %d\n",
1617 info->line, info->count);
1618 #endif
1619 schedule();
1621 current->state = TASK_RUNNING;
1622 remove_wait_queue(&info->open_wait, &wait);
1623 if (!tty_hung_up_p(filp))
1624 info->count++;
1625 info->blocked_open--;
1626 #ifdef SERIAL_DEBUG_OPEN
1627 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1628 info->line, info->count);
1629 #endif
1630 if (retval)
1631 return retval;
1632 info->flags |= ZILOG_NORMAL_ACTIVE;
1633 return 0;
1637 * This routine is called whenever a serial port is opened. It
1638 * enables interrupts for a serial port, linking in its ZILOG structure into
1639 * the IRQ chain. It also performs the serial-specific
1640 * initialization for the tty structure.
1642 int rs_open(struct tty_struct *tty, struct file * filp)
1644 struct sgi_serial *info;
1645 int retval, line;
1647 line = MINOR(tty->device) - tty->driver.minor_start;
1648 /* The zilog lines for the mouse/keyboard must be
1649 * opened using their respective drivers.
1651 if ((line < 0) || (line >= NUM_CHANNELS))
1652 return -ENODEV;
1653 info = zs_soft + line;
1654 /* Is the kgdb running over this line? */
1655 if (info->kgdb_channel)
1656 return -ENODEV;
1657 if (serial_paranoia_check(info, tty->device, "rs_open"))
1658 return -ENODEV;
1659 #ifdef SERIAL_DEBUG_OPEN
1660 printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
1661 info->count);
1662 #endif
1663 info->count++;
1664 tty->driver_data = info;
1665 info->tty = tty;
1668 * Start up serial port
1670 retval = startup(info);
1671 if (retval)
1672 return retval;
1674 retval = block_til_ready(tty, filp, info);
1675 if (retval) {
1676 #ifdef SERIAL_DEBUG_OPEN
1677 printk("rs_open returning after block_til_ready with %d\n",
1678 retval);
1679 #endif
1680 return retval;
1683 if ((info->count == 1) && (info->flags & ZILOG_SPLIT_TERMIOS)) {
1684 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
1685 *tty->termios = info->normal_termios;
1686 else
1687 *tty->termios = info->callout_termios;
1688 change_speed(info);
1691 info->session = current->session;
1692 info->pgrp = current->pgrp;
1694 #ifdef SERIAL_DEBUG_OPEN
1695 printk("rs_open ttys%d successful...", info->line);
1696 #endif
1697 return 0;
1700 /* Finally, routines used to initialize the serial driver. */
1702 static void show_serial_version(void)
1704 printk("SGI Zilog8530 serial driver version 1.00\n");
1707 /* Return layout for the requested zs chip number. */
1708 static inline struct sgi_zslayout *get_zs(int chip)
1710 extern struct hpc3_miscregs *hpc3mregs;
1712 if(chip > 0) {
1713 prom_printf("Wheee, bogus zs chip number requested.\n");
1714 prom_getchar();
1715 romvec->imode();
1717 return (struct sgi_zslayout *) (&hpc3mregs->ser1cmd);
1722 static inline void
1723 rs_cons_check(struct sgi_serial *ss, int channel)
1725 int i, o, io;
1726 static int msg_printed = 0;
1728 i = o = io = 0;
1730 /* Is this one of the serial console lines? */
1731 if((zs_cons_chanout != channel) &&
1732 (zs_cons_chanin != channel))
1733 return;
1734 zs_conschan = ss->zs_channel;
1735 zs_consinfo = ss;
1739 /* If this is console input, we handle the break received
1740 * status interrupt on this line to mean prom_halt().
1742 if(zs_cons_chanin == channel) {
1743 ss->break_abort = 1;
1744 i = 1;
1746 if(o && i)
1747 io = 1;
1748 if(ss->zs_baud != 9562) { /* Don't ask... */
1749 prom_printf("BAD console baud rate %d\n", ss->zs_baud);
1750 prom_getchar();
1751 prom_imode();
1752 panic("Console baud rate weirdness");
1756 /* Set flag variable for this port so that it cannot be
1757 * opened for other uses by accident.
1759 ss->is_cons = 1;
1761 if(io) {
1762 if(!msg_printed) {
1763 printk("zs%d: console I/O\n", ((channel>>1)&1));
1764 msg_printed = 1;
1767 } else {
1768 printk("zs%d: console %s\n", ((channel>>1)&1),
1769 (i==1 ? "input" : (o==1 ? "output" : "WEIRD")));
1774 volatile int test_done;
1776 /* rs_init inits the driver */
1777 int rs_init(void)
1779 int chip, channel, i, flags;
1780 struct sgi_serial *info;
1783 /* Setup base handler, and timer table. */
1784 init_bh(SERIAL_BH, do_serial_bh);
1785 timer_table[RS_TIMER].fn = rs_timer;
1786 timer_table[RS_TIMER].expires = 0;
1788 show_serial_version();
1790 /* Initialize the tty_driver structure */
1791 /* SGI: Not all of this is exactly right for us. */
1793 memset(&serial_driver, 0, sizeof(struct tty_driver));
1794 serial_driver.magic = TTY_DRIVER_MAGIC;
1795 serial_driver.name = "ttyS";
1796 serial_driver.major = TTY_MAJOR;
1797 serial_driver.minor_start = 64;
1798 serial_driver.num = NUM_CHANNELS;
1799 serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
1800 serial_driver.subtype = SERIAL_TYPE_NORMAL;
1801 serial_driver.init_termios = tty_std_termios;
1803 serial_driver.init_termios.c_cflag =
1804 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1805 serial_driver.flags = TTY_DRIVER_REAL_RAW;
1806 serial_driver.refcount = &serial_refcount;
1807 serial_driver.table = serial_table;
1808 serial_driver.termios = serial_termios;
1809 serial_driver.termios_locked = serial_termios_locked;
1811 serial_driver.open = rs_open;
1812 serial_driver.close = rs_close;
1813 serial_driver.write = rs_write;
1814 serial_driver.flush_chars = rs_flush_chars;
1815 serial_driver.write_room = rs_write_room;
1816 serial_driver.chars_in_buffer = rs_chars_in_buffer;
1817 serial_driver.flush_buffer = rs_flush_buffer;
1818 serial_driver.ioctl = rs_ioctl;
1819 serial_driver.throttle = rs_throttle;
1820 serial_driver.unthrottle = rs_unthrottle;
1821 serial_driver.set_termios = rs_set_termios;
1822 serial_driver.stop = rs_stop;
1823 serial_driver.start = rs_start;
1824 serial_driver.hangup = rs_hangup;
1827 * The callout device is just like normal device except for
1828 * major number and the subtype code.
1830 callout_driver = serial_driver;
1831 callout_driver.name = "cua";
1832 callout_driver.major = TTYAUX_MAJOR;
1833 callout_driver.subtype = SERIAL_TYPE_CALLOUT;
1835 if (tty_register_driver(&serial_driver))
1836 panic("Couldn't register serial driver\n");
1837 if (tty_register_driver(&callout_driver))
1838 panic("Couldn't register callout driver\n");
1840 save_flags(flags); cli();
1842 /* Set up our interrupt linked list */
1843 zs_chain = &zs_soft[0];
1844 zs_soft[0].zs_next = &zs_soft[1];
1845 zs_soft[1].zs_next = 0;
1847 for(chip = 0; chip < NUM_SERIAL; chip++) {
1848 /* If we are doing kgdb over one of the channels on
1849 * chip zero, kgdb_channel will be set to 1 by the
1850 * rs_kgdb_hook() routine below.
1852 if(!zs_chips[chip]) {
1853 zs_chips[chip] = get_zs(chip);
1854 /* Two channels per chip */
1855 zs_channels[(chip*2)] = &zs_chips[chip]->channelB;
1856 zs_channels[(chip*2)+1] = &zs_chips[chip]->channelA;
1857 zs_soft[(chip*2)].kgdb_channel = 0;
1858 zs_soft[(chip*2)+1].kgdb_channel = 0;
1860 /* First, set up channel A on this chip. */
1861 channel = chip * 2;
1862 zs_soft[channel].zs_channel = zs_channels[channel];
1863 zs_soft[channel].change_needed = 0;
1864 zs_soft[channel].clk_divisor = 16;
1865 zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
1866 zs_soft[channel].cons_mouse = 0;
1867 /* If not keyboard/mouse and is console serial
1868 * line, then enable receiver interrupts.
1870 if(zs_soft[channel].is_cons) {
1871 write_zsreg(zs_soft[channel].zs_channel, R1,
1872 (EXT_INT_ENAB | INT_ALL_Rx));
1873 write_zsreg(zs_soft[channel].zs_channel, R9, (NV | MIE));
1874 write_zsreg(zs_soft[channel].zs_channel, R10, (NRZ));
1875 write_zsreg(zs_soft[channel].zs_channel, R3, (Rx8|RxENABLE));
1876 write_zsreg(zs_soft[channel].zs_channel, R5, (Tx8 | TxENAB));
1878 /* If this is the kgdb line, enable interrupts because we
1879 * now want to receive the 'control-c' character from the
1880 * client attached to us asynchronously.
1882 if(zs_soft[channel].kgdb_channel)
1883 kgdb_chaninit(&zs_soft[channel], 1,
1884 zs_soft[channel].zs_baud);
1886 /* Now, channel B */
1887 channel++;
1888 zs_soft[channel].zs_channel = zs_channels[channel];
1889 zs_soft[channel].change_needed = 0;
1890 zs_soft[channel].clk_divisor = 16;
1891 zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
1892 zs_soft[channel].cons_keyb = 0;
1893 /* If console serial line, then enable receiver interrupts. */
1894 if(zs_soft[channel].is_cons) {
1895 write_zsreg(zs_soft[channel].zs_channel, R1,
1896 (EXT_INT_ENAB | INT_ALL_Rx));
1897 write_zsreg(zs_soft[channel].zs_channel, R9,
1898 (NV | MIE));
1899 write_zsreg(zs_soft[channel].zs_channel, R10,
1900 (NRZ));
1901 write_zsreg(zs_soft[channel].zs_channel, R3,
1902 (Rx8|RxENABLE));
1903 write_zsreg(zs_soft[channel].zs_channel, R5,
1904 (Tx8 | TxENAB | RTS | DTR));
1908 for(info=zs_chain, i=0; info; info = info->zs_next, i++)
1910 info->magic = SERIAL_MAGIC;
1911 info->port = (int) info->zs_channel;
1912 info->line = i;
1913 info->tty = 0;
1914 info->irq = zilog_irq;
1915 info->custom_divisor = 16;
1916 info->close_delay = 50;
1917 info->closing_wait = 3000;
1918 info->x_char = 0;
1919 info->event = 0;
1920 info->count = 0;
1921 info->blocked_open = 0;
1922 info->tqueue.routine = do_softint;
1923 info->tqueue.data = info;
1924 info->tqueue_hangup.routine = do_serial_hangup;
1925 info->tqueue_hangup.data = info;
1926 info->callout_termios =callout_driver.init_termios;
1927 info->normal_termios = serial_driver.init_termios;
1928 init_waitqueue_head(&info->open_wait);
1929 init_waitqueue_head(&info->close_wait);
1930 printk("tty%02d at 0x%04x (irq = %d)", info->line,
1931 info->port, info->irq);
1932 printk(" is a Zilog8530\n");
1935 if (request_irq(zilog_irq, rs_interrupt, (SA_INTERRUPT),
1936 "Zilog8530", zs_chain))
1937 panic("Unable to attach zs intr\n");
1938 restore_flags(flags);
1940 return 0;
1944 * register_serial and unregister_serial allows for serial ports to be
1945 * configured at run-time, to support PCMCIA modems.
1947 /* SGI: Unused at this time, just here to make things link. */
1948 int register_serial(struct serial_struct *req)
1950 return -1;
1953 void unregister_serial(int line)
1955 return;
1958 /* Hooks for running a serial console. con_init() calls this if the
1959 * console is being run over one of the ttya/ttyb serial ports.
1960 * 'chip' should be zero, as chip 1 drives the mouse/keyboard.
1961 * 'channel' is decoded as 0=TTYA 1=TTYB, note that the channels
1962 * are addressed backwards, channel B is first, then channel A.
1964 void
1965 rs_cons_hook(int chip, int out, int line)
1967 int channel;
1970 if(chip)
1971 panic("rs_cons_hook called with chip not zero");
1972 if(line != 0 && line != 1)
1973 panic("rs_cons_hook called with line not ttya or ttyb");
1974 channel = line;
1975 if(!zs_chips[chip]) {
1976 zs_chips[chip] = get_zs(chip);
1977 /* Two channels per chip */
1978 zs_channels[(chip*2)] = &zs_chips[chip]->channelB;
1979 zs_channels[(chip*2)+1] = &zs_chips[chip]->channelA;
1981 zs_soft[channel].zs_channel = zs_channels[channel];
1982 zs_soft[channel].change_needed = 0;
1983 zs_soft[channel].clk_divisor = 16;
1984 zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
1985 if(out)
1986 zs_cons_chanout = ((chip * 2) + channel);
1987 else
1988 zs_cons_chanin = ((chip * 2) + channel);
1990 rs_cons_check(&zs_soft[channel], channel);
1993 /* This is called at boot time to prime the kgdb serial debugging
1994 * serial line. The 'tty_num' argument is 0 for /dev/ttyd2 and 1 for
1995 * /dev/ttyd1 (yes they are backwards on purpose) which is determined
1996 * in setup_arch() from the boot command line flags.
1998 void
1999 rs_kgdb_hook(int tty_num)
2001 int chip = 0;
2003 if(!zs_chips[chip]) {
2004 zs_chips[chip] = get_zs(chip);
2005 /* Two channels per chip */
2006 zs_channels[(chip*2)] = &zs_chips[chip]->channelA;
2007 zs_channels[(chip*2)+1] = &zs_chips[chip]->channelB;
2009 zs_soft[tty_num].zs_channel = zs_channels[tty_num];
2010 zs_kgdbchan = zs_soft[tty_num].zs_channel;
2011 zs_soft[tty_num].change_needed = 0;
2012 zs_soft[tty_num].clk_divisor = 16;
2013 zs_soft[tty_num].zs_baud = get_zsbaud(&zs_soft[tty_num]);
2014 zs_soft[tty_num].kgdb_channel = 1; /* This runs kgdb */
2015 zs_soft[tty_num ^ 1].kgdb_channel = 0; /* This does not */
2017 /* Turn on transmitter/receiver at 8-bits/char */
2018 kgdb_chaninit(&zs_soft[tty_num], 0, 9600);
2019 ZS_CLEARERR(zs_kgdbchan);
2020 udelay(5);
2021 ZS_CLEARFIFO(zs_kgdbchan);
2024 static void zs_console_write(struct console *co, const char *str, unsigned int count)
2027 while(count--) {
2028 if(*str == '\n')
2029 rs_put_char('\r');
2030 rs_put_char(*str++);
2033 /* Comment this if you want to have a strict interrupt-driven output */
2034 rs_fair_output();
2037 static int zs_console_wait_key(struct console *con)
2039 sleep_on(&keypress_wait);
2040 return 0;
2043 static kdev_t zs_console_device(struct console *con)
2045 return MKDEV(TTY_MAJOR, 64 + con->index);
2049 __initfunc(static int zs_console_setup(struct console *con, char *options))
2051 struct sgi_serial *info;
2052 int baud = 9600;
2053 int bits = 8;
2054 int parity = 'n';
2055 int cflag = CREAD | HUPCL | CLOCAL;
2056 char *s;
2057 int i, brg;
2059 if (options) {
2060 baud = simple_strtoul(options, NULL, 10);
2061 s = options;
2062 while(*s >= '0' && *s <= '9')
2063 s++;
2064 if (*s) parity = *s++;
2065 if (*s) bits = *s - '0';
2069 * Now construct a cflag setting.
2071 switch(baud) {
2072 case 1200:
2073 cflag |= B1200;
2074 break;
2075 case 2400:
2076 cflag |= B2400;
2077 break;
2078 case 4800:
2079 cflag |= B4800;
2080 break;
2081 case 19200:
2082 cflag |= B19200;
2083 break;
2084 case 38400:
2085 cflag |= B38400;
2086 break;
2087 case 57600:
2088 cflag |= B57600;
2089 break;
2090 case 115200:
2091 cflag |= B115200;
2092 break;
2093 case 9600:
2094 default:
2095 cflag |= B9600;
2096 break;
2098 switch(bits) {
2099 case 7:
2100 cflag |= CS7;
2101 break;
2102 default:
2103 case 8:
2104 cflag |= CS8;
2105 break;
2107 switch(parity) {
2108 case 'o': case 'O':
2109 cflag |= PARODD;
2110 break;
2111 case 'e': case 'E':
2112 cflag |= PARENB;
2113 break;
2115 con->cflag = cflag;
2117 rs_cons_hook(0, 0, con->index);
2118 info = zs_soft + con->index;
2119 info->is_cons = 1;
2121 printk("Console: ttyS%d (Zilog8530)\n", info->line);
2123 i = con->cflag & CBAUD;
2124 if (con->cflag & CBAUDEX) {
2125 i &= ~CBAUDEX;
2126 con->cflag &= ~CBAUDEX;
2128 info->zs_baud = baud;
2130 switch (con->cflag & CSIZE) {
2131 case CS5:
2132 zscons_regs[3] = Rx5 | RxENABLE;
2133 zscons_regs[5] = Tx5 | TxENAB;
2134 break;
2135 case CS6:
2136 zscons_regs[3] = Rx6 | RxENABLE;
2137 zscons_regs[5] = Tx6 | TxENAB;
2138 break;
2139 case CS7:
2140 zscons_regs[3] = Rx7 | RxENABLE;
2141 zscons_regs[5] = Tx7 | TxENAB;
2142 break;
2143 default:
2144 case CS8:
2145 zscons_regs[3] = Rx8 | RxENABLE;
2146 zscons_regs[5] = Tx8 | TxENAB;
2147 break;
2149 zscons_regs[5] |= DTR;
2151 if (con->cflag & PARENB)
2152 zscons_regs[4] |= PAR_ENA;
2153 if (!(con->cflag & PARODD))
2154 zscons_regs[4] |= PAR_EVEN;
2156 if (con->cflag & CSTOPB)
2157 zscons_regs[4] |= SB2;
2158 else
2159 zscons_regs[4] |= SB1;
2161 brg = BPS_TO_BRG(baud, ZS_CLOCK / info->clk_divisor);
2162 zscons_regs[12] = brg & 0xff;
2163 zscons_regs[13] = (brg >> 8) & 0xff;
2164 memcpy(info->curregs, zscons_regs, sizeof(zscons_regs));
2165 memcpy(info->pendregs, zscons_regs, sizeof(zscons_regs));
2166 load_zsregs(info->zs_channel, zscons_regs);
2167 ZS_CLEARERR(info->zs_channel);
2168 ZS_CLEARFIFO(info->zs_channel);
2169 return 0;
2172 static struct console sgi_console_driver = {
2173 "ttyS",
2174 zs_console_write, /* write */
2175 NULL, /* read */
2176 zs_console_device, /* device */
2177 zs_console_wait_key, /* wait_key */
2178 NULL, /* unblank */
2179 zs_console_setup, /* setup */
2180 CON_PRINTBUFFER,
2183 NULL
2187 * Register console.
2189 __initfunc (long serial_console_init(long kmem_start, long kmem_end))
2191 register_console(&sgi_console_driver);
2192 return kmem_start;