1 /* $Id: zs.c,v 1.60 2000/10/14 10:09:04 davem Exp $
2 * zs.c: Zilog serial port driver for the Sparc.
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
6 * Fixes by Pete A. Zaitcev <zaitcev@metabyte.com>.
9 #include <linux/errno.h>
10 #include <linux/signal.h>
11 #include <linux/sched.h>
12 #include <linux/timer.h>
13 #include <linux/interrupt.h>
14 #include <linux/tty.h>
15 #include <linux/tty_flip.h>
16 #include <linux/config.h>
17 #include <linux/major.h>
18 #include <linux/string.h>
19 #include <linux/fcntl.h>
21 #include <linux/kernel.h>
22 #include <linux/keyboard.h>
23 #include <linux/console.h>
24 #include <linux/delay.h>
25 #include <linux/init.h>
26 #include <linux/bootmem.h>
27 #include <linux/sysrq.h>
31 #include <asm/oplib.h>
32 #include <asm/system.h>
33 #include <asm/uaccess.h>
34 #include <asm/bitops.h>
35 #include <asm/kdebug.h>
37 #include <asm/pgtable.h>
44 #include <linux/pci.h>
47 #include "sunserial.h"
52 static int num_serial
= 2; /* sun4/sun4c/sun4m - Two chips on board. */
53 #define NUM_SERIAL num_serial
54 #define NUM_CHANNELS (NUM_SERIAL * 2)
56 #define KEYBOARD_LINE 0x2
57 #define MOUSE_LINE 0x3
59 /* On 32-bit sparcs we need to delay after register accesses
60 * to accomodate sun4 systems, but we do not need to flush writes.
61 * On 64-bit sparc we only need to flush single writes to ensure
65 #define ZSDELAY() udelay(5)
66 #define ZSDELAY_LONG() udelay(20)
67 #define ZS_WSYNC(channel) do { } while(0)
70 #define ZSDELAY_LONG()
71 #define ZS_WSYNC(__channel) \
72 sbus_readb(&((__channel)->control))
75 struct sun_zslayout
**zs_chips
;
76 struct sun_zschannel
**zs_channels
;
77 struct sun_zschannel
*zs_mousechan
;
78 struct sun_zschannel
*zs_kbdchan
;
79 struct sun_zschannel
*zs_kgdbchan
;
82 struct sun_serial
*zs_soft
;
83 struct sun_serial
*zs_chain
; /* IRQ servicing chain */
86 struct tty_struct
*zs_ttys
;
88 /* Console hooks... */
89 #ifdef CONFIG_SERIAL_CONSOLE
90 static struct console zs_console
;
91 static int zs_console_init(void);
94 * Define this to get the zs_fair_output() functionality.
96 #undef SERIAL_CONSOLE_FAIR_OUTPUT
97 #endif /* CONFIG_SERIAL_CONSOLE */
99 static unsigned char kgdb_regs
[16] = {
100 0, 0, 0, /* write 0, 1, 2 */
101 (Rx8
| RxENAB
), /* write 3 */
102 (X16CLK
| SB1
| PAR_EVEN
), /* write 4 */
103 (DTR
| Tx8
| TxENAB
), /* write 5 */
104 0, 0, 0, /* write 6, 7, 8 */
106 (NRZ
), /* write 10 */
107 (TCBR
| RCBR
), /* write 11 */
108 0, 0, /* BRG time constant, write 12 + 13 */
109 (BRSRC
| BRENAB
), /* write 14 */
110 (DCDIE
) /* write 15 */
113 static unsigned char zscons_regs
[16] = {
115 (EXT_INT_ENAB
| INT_ALL_Rx
), /* write 1 */
117 (Rx8
| RxENAB
), /* write 3 */
118 (X16CLK
), /* write 4 */
119 (DTR
| Tx8
| TxENAB
), /* write 5 */
120 0, 0, 0, /* write 6, 7, 8 */
121 (NV
| MIE
), /* write 9 */
122 (NRZ
), /* write 10 */
123 (TCBR
| RCBR
), /* write 11 */
124 0, 0, /* BRG time constant, write 12 + 13 */
125 (BRSRC
| BRENAB
), /* write 14 */
126 (DCDIE
| CTSIE
| TxUIE
| BRKIE
) /* write 15 */
129 #define ZS_CLOCK 4915200 /* Zilog input clock rate */
131 DECLARE_TASK_QUEUE(tq_serial
);
133 static struct tty_driver serial_driver
, callout_driver
;
134 static int serial_refcount
;
136 /* serial subtype definitions */
137 #define SERIAL_TYPE_NORMAL 1
138 #define SERIAL_TYPE_CALLOUT 2
140 /* number of characters left in xmit buffer before we ask for more */
141 #define WAKEUP_CHARS 256
143 #define SERIAL_DO_RESTART
145 /* Debugging... DEBUG_INTR is bad to use when one of the zs
146 * lines is your console ;(
148 #undef SERIAL_DEBUG_INTR
149 #undef SERIAL_DEBUG_OPEN
150 #undef SERIAL_DEBUG_FLOW
152 #define RS_STROBE_TIME 10
153 #define RS_ISR_PASS_LIMIT 256
155 #define _INLINE_ inline
158 static void zs_kgdb_hook(int);
160 static void change_speed(struct sun_serial
*info
);
162 static struct tty_struct
**serial_table
;
163 static struct termios
**serial_termios
;
164 static struct termios
**serial_termios_locked
;
167 #define MIN(a,b) ((a) < (b) ? (a) : (b))
179 struct zs_logent zslog
[32];
181 #define ZSLOG(__reg, __val, __write) \
182 do{ int index = zs_curlog; \
183 zslog[index].reg = (__reg); \
184 zslog[index].val = (__val); \
185 zslog[index].write = (__write); \
186 zs_curlog = (index + 1) & (32 - 1); \
188 int zs_dumplog(char *buffer
)
193 for (i
= 0; i
< 32; i
++) {
198 write
= zslog
[i
].write
;
199 len
+= sprintf(buffer
+ len
,
200 "ZSLOG[%2d]: reg %2x val %2x %s\n",
201 i
, reg
, val
, write
? "write" : "read");
203 len
+= sprintf(buffer
+ len
, "ZS current log index %d\n",
208 #define ZSLOG(x,y,z) do { } while (0)
212 * tmp_buf is used as a temporary buffer by serial_write. We need to
213 * lock it in case the memcpy_fromfs blocks while swapping in a page,
214 * and some other program tries to do a serial write at the same time.
215 * Since the lock will only come under contention when the system is
216 * swapping and available memory is low, it makes sense to share one
217 * buffer across all the serial ports, since it significantly saves
218 * memory if large numbers of serial ports are open.
220 static unsigned char tmp_buf
[4096]; /* This is cheating */
221 static DECLARE_MUTEX(tmp_buf_sem
);
223 static inline int serial_paranoia_check(struct sun_serial
*info
,
224 dev_t device
, const char *routine
)
226 #ifdef SERIAL_PARANOIA_CHECK
227 static const char *badmagic
=
228 "Warning: bad magic number for serial struct (%d, %d) in %s\n";
229 static const char *badinfo
=
230 "Warning: null sun_serial for (%d, %d) in %s\n";
233 printk(badinfo
, MAJOR(device
), MINOR(device
), routine
);
236 if (info
->magic
!= SERIAL_MAGIC
) {
237 printk(badmagic
, MAJOR(device
), MINOR(device
), routine
);
244 /* This is used to figure out the divisor speeds and the timeouts. */
245 static int baud_table
[] = {
246 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
247 9600, 19200, 38400, 76800, 0
250 /* Reading and writing Zilog8530 registers. The delays are to make this
251 * driver work on the Sun4 which needs a settling delay after each chip
252 * register access, other machines handle this in hardware via auxiliary
253 * flip-flops which implement the settle time we do in software.
255 static inline unsigned char read_zsreg(struct sun_zschannel
*channel
,
258 unsigned char retval
;
260 sbus_writeb(reg
, &channel
->control
);
262 retval
= sbus_readb(&channel
->control
);
264 ZSLOG(reg
, retval
, 0);
268 static inline void write_zsreg(struct sun_zschannel
*channel
,
269 unsigned char reg
, unsigned char value
)
271 ZSLOG(reg
, value
, 1);
272 sbus_writeb(reg
, &channel
->control
);
274 sbus_writeb(value
, &channel
->control
);
278 static inline void load_zsregs(struct sun_serial
*info
, unsigned char *regs
)
280 struct sun_zschannel
*channel
= info
->zs_channel
;
285 for (i
= 0; i
< 1000; i
++) {
286 stat
= read_zsreg(channel
, R1
);
291 write_zsreg(channel
, R3
, 0);
292 ZS_CLEARSTAT(channel
);
293 ZS_CLEARERR(channel
);
294 ZS_CLEARFIFO(channel
);
297 save_flags(flags
); cli();
299 write_zsreg(channel
, R9
, CHRA
);
301 write_zsreg(channel
, R9
, CHRB
);
303 write_zsreg(channel
, R4
, regs
[R4
]);
304 write_zsreg(channel
, R3
, regs
[R3
] & ~RxENAB
);
305 write_zsreg(channel
, R5
, regs
[R5
] & ~TxENAB
);
306 write_zsreg(channel
, R9
, regs
[R9
] & ~MIE
);
307 write_zsreg(channel
, R10
, regs
[R10
]);
308 write_zsreg(channel
, R11
, regs
[R11
]);
309 write_zsreg(channel
, R12
, regs
[R12
]);
310 write_zsreg(channel
, R13
, regs
[R13
]);
311 write_zsreg(channel
, R14
, regs
[R14
] & ~BRENAB
);
312 write_zsreg(channel
, R14
, regs
[R14
]);
313 write_zsreg(channel
, R14
, (regs
[R14
] & ~SNRZI
) | BRENAB
);
314 write_zsreg(channel
, R3
, regs
[R3
]);
315 write_zsreg(channel
, R5
, regs
[R5
]);
316 write_zsreg(channel
, R15
, regs
[R15
]);
317 write_zsreg(channel
, R0
, RES_EXT_INT
);
318 write_zsreg(channel
, R0
, ERR_RES
);
319 write_zsreg(channel
, R1
, regs
[R1
]);
320 write_zsreg(channel
, R9
, regs
[R9
]);
321 restore_flags(flags
);
324 #define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */
326 static inline void zs_put_char(struct sun_zschannel
*channel
, char ch
)
328 int loops
= ZS_PUT_CHAR_MAX_DELAY
;
330 /* Do not change this to use ZSDELAY as this is
331 * a timed polling loop and on sparc64 ZSDELAY
335 u8 val
= sbus_readb(&channel
->control
);
336 ZSLOG(REGCTRL
, val
, 0);
337 if (val
& Tx_BUF_EMP
)
342 sbus_writeb(ch
, &channel
->data
);
345 ZSLOG(REGDATA
, ch
, 1);
348 /* Sets or clears DTR/RTS on the requested line */
349 static inline void zs_rtsdtr(struct sun_serial
*ss
, int set
)
353 save_flags(flags
); cli();
355 ss
->curregs
[5] |= (RTS
| DTR
);
356 write_zsreg(ss
->zs_channel
, 5, ss
->curregs
[5]);
358 ss
->curregs
[5] &= ~(RTS
| DTR
);
359 write_zsreg(ss
->zs_channel
, 5, ss
->curregs
[5]);
361 restore_flags(flags
);
365 static inline void kgdb_chaninit(struct sun_serial
*ss
, int intson
, int bps
)
370 kgdb_regs
[R1
] = INT_ALL_Rx
;
371 kgdb_regs
[R9
] |= MIE
;
374 kgdb_regs
[R9
] &= ~MIE
;
376 brg
= BPS_TO_BRG(bps
, ZS_CLOCK
/16);
377 kgdb_regs
[R12
] = (brg
& 255);
378 kgdb_regs
[R13
] = ((brg
>> 8) & 255);
379 load_zsregs(ss
, kgdb_regs
);
383 * ------------------------------------------------------------
384 * zs_stop() and zs_start()
386 * This routines are called before setting or resetting tty->stopped.
387 * They enable or disable transmitter interrupts, as necessary.
388 * ------------------------------------------------------------
390 static void zs_stop(struct tty_struct
*tty
)
392 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
395 if (serial_paranoia_check(info
, tty
->device
, "zs_stop"))
398 save_flags(flags
); cli();
399 if (info
->curregs
[5] & TxENAB
) {
400 info
->curregs
[5] &= ~TxENAB
;
401 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
403 restore_flags(flags
);
406 static void zs_start(struct tty_struct
*tty
)
408 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
411 if (serial_paranoia_check(info
, tty
->device
, "zs_start"))
414 save_flags(flags
); cli();
415 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->curregs
[5] & TxENAB
)) {
416 info
->curregs
[5] |= TxENAB
;
417 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
419 restore_flags(flags
);
422 /* Drop into either the boot monitor or kadb upon receiving a break
423 * from keyboard/console input.
425 void batten_down_hatches(void)
429 /* If we are doing kadb, we call the debugger
430 * else we just drop into the boot monitor.
431 * Note that we must flush the user windows
432 * first before giving up control.
435 flush_user_windows();
437 if((((unsigned long)linux_dbvec
)>=DEBUG_FIRSTVADDR
) &&
438 (((unsigned long)linux_dbvec
)<=DEBUG_LASTVADDR
))
444 /* XXX We want to notify the keyboard driver that all
445 * XXX keys are in the up state or else weird things
454 * ----------------------------------------------------------------------
456 * Here starts the interrupt handling routines. All of the following
457 * subroutines are declared as inline and are folded into
458 * zs_interrupt(). They were separated out for readability's sake.
460 * Note: zs_interrupt() is a "fast" interrupt, which means that it
461 * runs with interrupts turned off. People who may want to modify
462 * zs_interrupt() should try to keep the interrupt handler as fast as
463 * possible. After you are done making modifications, it is not a bad
466 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
468 * and look at the resulting assemble code in serial.s.
470 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
471 * -----------------------------------------------------------------------
475 * This routine is used by the interrupt handler to schedule
476 * processing in the software interrupt portion of the driver.
478 static _INLINE_
void zs_sched_event(struct sun_serial
*info
,
481 info
->event
|= 1 << event
;
482 queue_task(&info
->tqueue
, &tq_serial
);
487 extern void breakpoint(void); /* For the KGDB frame character */
490 static _INLINE_
void receive_chars(struct sun_serial
*info
, struct pt_regs
*regs
)
492 struct tty_struct
*tty
= info
->tty
;
493 unsigned char ch
, stat
;
494 int do_queue_task
= 1;
497 ch
= sbus_readb(&info
->zs_channel
->data
);
498 ZSLOG(REGDATA
, ch
, 0);
499 ch
&= info
->parity_mask
;
502 /* If this is the console keyboard, we need to handle
505 if(info
->cons_keyb
) {
506 if(ch
== SUNKBD_RESET
) {
507 l1a_state
.kbd_id
= 1;
508 l1a_state
.l1_down
= 0;
509 } else if(l1a_state
.kbd_id
) {
510 l1a_state
.kbd_id
= 0;
511 } else if(ch
== SUNKBD_L1
) {
512 l1a_state
.l1_down
= 1;
513 } else if(ch
== (SUNKBD_L1
|SUNKBD_UP
)) {
514 l1a_state
.l1_down
= 0;
515 } else if(ch
== SUNKBD_A
&& l1a_state
.l1_down
) {
517 batten_down_hatches();
518 /* Continue execution... */
519 l1a_state
.l1_down
= 0;
520 l1a_state
.kbd_id
= 0;
523 sunkbd_inchar(ch
, regs
);
527 if(info
->cons_mouse
) {
528 sun_mouse_inbyte(ch
, 0);
534 /* whee, break received */
535 batten_down_hatches();
536 /* Continue execution... */
539 /* It is a 'keyboard interrupt' ;-) */
540 wake_up(&keypress_wait
);
543 /* Look for kgdb 'stop' character, consult the gdb
544 * documentation for remote target debugging and
545 * arch/sparc/kernel/sparc-stub.c to see how all this works.
547 if((info
->kgdb_channel
) && (ch
=='\003')) {
555 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
559 *tty
->flip
.flag_buf_ptr
++ = 0;
560 *tty
->flip
.char_buf_ptr
++ = ch
;
563 /* Check if we have another character... */
564 stat
= sbus_readb(&info
->zs_channel
->control
);
566 ZSLOG(REGCTRL
, stat
, 0);
567 if (!(stat
& Rx_CH_AV
))
570 /* ... and see if it is clean. */
571 stat
= read_zsreg(info
->zs_channel
, R1
);
572 } while (!(stat
& (PAR_ERR
| Rx_OVR
| CRC_ERR
)));
574 if (do_queue_task
!= 0)
575 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
578 static _INLINE_
void transmit_chars(struct sun_serial
*info
)
580 struct tty_struct
*tty
= info
->tty
;
584 zs_put_char(info
->zs_channel
, info
->x_char
);
589 if((info
->xmit_cnt
<= 0) || (tty
!= 0 && tty
->stopped
)) {
590 /* That's peculiar... */
591 sbus_writeb(RES_Tx_P
, &info
->zs_channel
->control
);
593 ZS_WSYNC(info
->zs_channel
);
594 ZSLOG(REGCTRL
, RES_Tx_P
, 1);
599 zs_put_char(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
600 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
603 if (info
->xmit_cnt
< WAKEUP_CHARS
)
604 zs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
606 if(info
->xmit_cnt
<= 0) {
607 sbus_writeb(RES_Tx_P
, &info
->zs_channel
->control
);
609 ZS_WSYNC(info
->zs_channel
);
610 ZSLOG(REGCTRL
, RES_Tx_P
, 1);
614 static _INLINE_
void status_handle(struct sun_serial
*info
)
616 unsigned char status
;
618 /* Get status from Read Register 0 */
619 status
= sbus_readb(&info
->zs_channel
->control
);
621 ZSLOG(REGCTRL
, status
, 0);
622 /* Clear status condition... */
623 sbus_writeb(RES_EXT_INT
, &info
->zs_channel
->control
);
625 ZS_WSYNC(info
->zs_channel
);
626 ZSLOG(REGCTRL
, RES_EXT_INT
, 1);
629 if((info
->tty
->termios
->c_cflag
& CRTSCTS
) &&
630 ((info
->curregs
[3] & AUTO_ENAB
)==0)) {
631 info
->curregs
[3] |= AUTO_ENAB
;
632 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
635 if((info
->curregs
[3] & AUTO_ENAB
)) {
636 info
->curregs
[3] &= ~AUTO_ENAB
;
637 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
641 /* Whee, if this is console input and this is a
642 * 'break asserted' status change interrupt, call
645 if(status
& BRK_ABRT
) {
646 if (info
->break_abort
)
647 batten_down_hatches();
648 if (info
->cons_mouse
)
649 sun_mouse_inbyte(0, 1);
652 /* XXX Whee, put in a buffer somewhere, the status information
653 * XXX whee whee whee... Where does the information go...
658 static _INLINE_
void special_receive(struct sun_serial
*info
)
660 struct tty_struct
*tty
= info
->tty
;
661 unsigned char ch
, stat
;
663 stat
= read_zsreg(info
->zs_channel
, R1
);
664 if (stat
& (PAR_ERR
| Rx_OVR
| CRC_ERR
)) {
665 ch
= sbus_readb(&info
->zs_channel
->data
);
667 ZSLOG(REGDATA
, ch
, 0);
673 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
678 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
679 else if(stat
& Rx_OVR
)
680 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
681 else if(stat
& CRC_ERR
)
682 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
685 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
687 sbus_writeb(ERR_RES
, &info
->zs_channel
->control
);
689 ZS_WSYNC(info
->zs_channel
);
690 ZSLOG(REGCTRL
, ERR_RES
, 1);
695 * This is the serial driver's generic interrupt routine
697 void zs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
699 struct sun_serial
*info
;
700 unsigned char zs_intreg
;
703 info
= (struct sun_serial
*)dev_id
;
705 for (i
= 0; i
< NUM_SERIAL
; i
++) {
706 zs_intreg
= read_zsreg(info
->zs_next
->zs_channel
, 2);
707 zs_intreg
&= STATUS_MASK
;
709 /* NOTE: The read register 2, which holds the irq status,
710 * does so for both channels on each chip. Although
711 * the status value itself must be read from the B
712 * channel and is only valid when read from channel B.
713 * When read from channel A, read register 2 contains
714 * the value written to write register 2.
717 /* Channel A -- /dev/ttya or /dev/kbd, could be the console */
718 if (zs_intreg
== CHA_Rx_AVAIL
) {
719 receive_chars(info
, regs
);
722 if(zs_intreg
== CHA_Tx_EMPTY
) {
723 transmit_chars(info
);
726 if (zs_intreg
== CHA_EXT_STAT
) {
730 if (zs_intreg
== CHA_SPECIAL
) {
731 special_receive(info
);
735 /* Channel B -- /dev/ttyb or /dev/mouse, could be the console */
736 if(zs_intreg
== CHB_Rx_AVAIL
) {
737 receive_chars(info
->zs_next
, regs
);
740 if(zs_intreg
== CHB_Tx_EMPTY
) {
741 transmit_chars(info
->zs_next
);
744 if (zs_intreg
== CHB_EXT_STAT
) {
745 status_handle(info
->zs_next
);
749 /* NOTE: The default value for the IRQ status in read register
750 * 2 in channel B is CHB_SPECIAL, so we need to look at
751 * read register 3 in channel A to check if this is a
752 * real interrupt, or just the default value.
753 * Yes... broken hardware...
756 zs_intreg
= read_zsreg(info
->zs_channel
, 3);
757 if (zs_intreg
& CHBRxIP
) {
758 special_receive(info
->zs_next
);
761 info
= info
->zs_next
->zs_next
;
766 * -------------------------------------------------------------------
767 * Here ends the serial interrupt routines.
768 * -------------------------------------------------------------------
772 * This routine is used to handle the "bottom half" processing for the
773 * serial driver, known also the "software interrupt" processing.
774 * This processing is done at the kernel interrupt level, after the
775 * zs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
776 * is where time-consuming activities which can not be done in the
777 * interrupt driver proper are done; the interrupt driver schedules
778 * them using zs_sched_event(), and they get done here.
780 static void do_serial_bh(void)
782 run_task_queue(&tq_serial
);
785 static void do_softint(void *private_
)
787 struct sun_serial
*info
= (struct sun_serial
*) private_
;
788 struct tty_struct
*tty
;
794 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
795 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
796 tty
->ldisc
.write_wakeup
)
797 (tty
->ldisc
.write_wakeup
)(tty
);
798 wake_up_interruptible(&tty
->write_wait
);
803 * This routine is called from the scheduler tqueue when the interrupt
804 * routine has signalled that a hangup has occurred. The path of
805 * hangup processing is:
807 * serial interrupt routine -> (scheduler tqueue) ->
808 * do_serial_hangup() -> tty->hangup() -> zs_hangup()
811 static void do_serial_hangup(void *private_
)
813 struct sun_serial
*info
= (struct sun_serial
*) private_
;
814 struct tty_struct
*tty
;
819 #ifdef SERIAL_DEBUG_OPEN
820 printk("do_serial_hangup<%p: tty-%d\n",
821 __builtin_return_address(0), info
->line
);
827 static int startup(struct sun_serial
* info
)
831 if (info
->flags
& ZILOG_INITIALIZED
)
834 if (!info
->xmit_buf
) {
835 info
->xmit_buf
= (unsigned char *) get_free_page(GFP_KERNEL
);
840 save_flags(flags
); cli();
842 #ifdef SERIAL_DEBUG_OPEN
843 printk("Starting up tty-%d (irq %d)...\n", info
->line
, info
->irq
);
847 * Clear the FIFO buffers and disable them
848 * (they will be reenabled in change_speed())
850 ZS_CLEARFIFO(info
->zs_channel
);
851 info
->xmit_fifo_size
= 1;
854 * Clear the interrupt registers.
856 sbus_writeb(ERR_RES
, &info
->zs_channel
->control
);
858 ZS_WSYNC(info
->zs_channel
);
859 ZSLOG(REGCTRL
, ERR_RES
, 1);
861 sbus_writeb(RES_H_IUS
, &info
->zs_channel
->control
);
863 ZS_WSYNC(info
->zs_channel
);
864 ZSLOG(REGCTRL
, RES_H_IUS
, 1);
867 * Now, initialize the Zilog
872 * Finally, enable sequencing and interrupts
874 info
->curregs
[1] |= (info
->curregs
[1] & ~(RxINT_MASK
)) |
875 (EXT_INT_ENAB
| INT_ALL_Rx
);
876 info
->curregs
[3] |= (RxENAB
| Rx8
);
877 /* We enable Tx interrupts as needed. */
878 info
->curregs
[5] |= (TxENAB
| Tx8
);
879 info
->curregs
[9] |= (NV
| MIE
);
880 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
881 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
882 write_zsreg(info
->zs_channel
, 9, info
->curregs
[9]);
885 * And clear the interrupt registers again for luck.
887 sbus_writeb(ERR_RES
, &info
->zs_channel
->control
);
889 ZS_WSYNC(info
->zs_channel
);
890 ZSLOG(REGCTRL
, ERR_RES
, 1);
892 sbus_writeb(RES_H_IUS
, &info
->zs_channel
->control
);
894 ZS_WSYNC(info
->zs_channel
);
895 ZSLOG(REGCTRL
, RES_H_IUS
, 1);
898 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
899 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
902 * and set the speed of the serial port
906 info
->flags
|= ZILOG_INITIALIZED
;
907 restore_flags(flags
);
912 * This routine will shutdown a serial port; interrupts are disabled, and
913 * DTR is dropped if the hangup on close termio flag is on.
915 static void shutdown(struct sun_serial
* info
)
919 if (!(info
->flags
& ZILOG_INITIALIZED
))
922 #ifdef SERIAL_DEBUG_OPEN
923 printk("Shutting down serial port %d (irq %d)....", info
->line
,
927 save_flags(flags
); cli(); /* Disable interrupts */
929 if (info
->xmit_buf
) {
930 free_page((unsigned long) info
->xmit_buf
);
935 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
937 info
->flags
&= ~ZILOG_INITIALIZED
;
938 restore_flags(flags
);
942 * This routine is called to set the UART divisor registers to match
943 * the specified baud rate for a serial port.
945 static void change_speed(struct sun_serial
*info
)
953 if (!info
->tty
|| !info
->tty
->termios
)
955 cflag
= info
->tty
->termios
->c_cflag
;
956 if (!(port
= info
->port
))
959 if (cflag
& CBAUDEX
) {
962 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
967 if ((info
->flags
& ZILOG_SPD_MASK
) == ZILOG_SPD_HI
)
969 if ((info
->flags
& ZILOG_SPD_MASK
) == ZILOG_SPD_CUST
)
970 quot
= info
->custom_divisor
;
973 info
->zs_baud
= info
->baud_base
/ quot
;
974 info
->clk_divisor
= 16;
976 info
->curregs
[4] = X16CLK
;
977 info
->curregs
[11] = TCBR
| RCBR
;
978 brg
= BPS_TO_BRG(info
->zs_baud
, ZS_CLOCK
/info
->clk_divisor
);
979 info
->curregs
[12] = (brg
& 255);
980 info
->curregs
[13] = ((brg
>> 8) & 255);
981 info
->curregs
[14] = BRSRC
| BRENAB
;
983 } else if (baud_table
[i
]) {
984 info
->zs_baud
= baud_table
[i
];
985 info
->clk_divisor
= 16;
987 info
->curregs
[4] = X16CLK
;
988 info
->curregs
[11] = TCBR
| RCBR
;
989 brg
= BPS_TO_BRG(info
->zs_baud
, ZS_CLOCK
/info
->clk_divisor
);
990 info
->curregs
[12] = (brg
& 255);
991 info
->curregs
[13] = ((brg
>> 8) & 255);
992 info
->curregs
[14] = BRSRC
| BRENAB
;
999 /* byte size and parity */
1000 switch (cflag
& CSIZE
) {
1002 info
->curregs
[3] &= ~(RxN_MASK
);
1003 info
->curregs
[3] |= Rx5
;
1004 info
->curregs
[5] &= ~(TxN_MASK
);
1005 info
->curregs
[5] |= Tx5
;
1006 info
->parity_mask
= 0x1f;
1009 info
->curregs
[3] &= ~(RxN_MASK
);
1010 info
->curregs
[3] |= Rx6
;
1011 info
->curregs
[5] &= ~(TxN_MASK
);
1012 info
->curregs
[5] |= Tx6
;
1013 info
->parity_mask
= 0x3f;
1016 info
->curregs
[3] &= ~(RxN_MASK
);
1017 info
->curregs
[3] |= Rx7
;
1018 info
->curregs
[5] &= ~(TxN_MASK
);
1019 info
->curregs
[5] |= Tx7
;
1020 info
->parity_mask
= 0x7f;
1023 default: /* defaults to 8 bits */
1024 info
->curregs
[3] &= ~(RxN_MASK
);
1025 info
->curregs
[3] |= Rx8
;
1026 info
->curregs
[5] &= ~(TxN_MASK
);
1027 info
->curregs
[5] |= Tx8
;
1028 info
->parity_mask
= 0xff;
1031 info
->curregs
[4] &= ~(0x0c);
1032 if (cflag
& CSTOPB
) {
1033 info
->curregs
[4] |= SB2
;
1035 info
->curregs
[4] |= SB1
;
1037 if (cflag
& PARENB
) {
1038 info
->curregs
[4] |= PAR_ENAB
;
1040 info
->curregs
[4] &= ~PAR_ENAB
;
1042 if (!(cflag
& PARODD
)) {
1043 info
->curregs
[4] |= PAR_EVEN
;
1045 info
->curregs
[4] &= ~PAR_EVEN
;
1048 /* Load up the new values */
1049 load_zsregs(info
, info
->curregs
);
1054 /* This is for mouse/keyboard output.
1055 * XXX mouse output??? can we send it commands??? XXX
1057 static void kbd_put_char(unsigned char ch
)
1059 struct sun_zschannel
*chan
= zs_kbdchan
;
1060 unsigned long flags
;
1065 save_flags(flags
); cli();
1066 zs_put_char(chan
, ch
);
1067 restore_flags(flags
);
1070 void mouse_put_char(char ch
)
1072 struct sun_zschannel
*chan
= zs_mousechan
;
1073 unsigned long flags
;
1078 save_flags(flags
); cli();
1079 zs_put_char(chan
, ch
);
1080 restore_flags(flags
);
1083 /* These are for receiving and sending characters under the kgdb
1084 * source level kernel debugger.
1086 void putDebugChar(char kgdb_char
)
1088 struct sun_zschannel
*chan
= zs_kgdbchan
;
1090 while((sbus_readb(&chan
->control
) & Tx_BUF_EMP
)==0)
1092 sbus_writeb(kgdb_char
, &chan
->data
);
1094 ZSLOG(REGDATA
, kgdb_char
, 1);
1097 char getDebugChar(void)
1099 struct sun_zschannel
*chan
= zs_kgdbchan
;
1103 val
= sbus_readb(&chan
->control
);
1104 ZSLOG(REGCTRL
, val
, 0);
1106 } while ((val
& Rx_CH_AV
) == 0);
1108 val
= sbus_readb(&chan
->data
);
1109 ZSLOG(REGDATA
, val
, 0);
1113 static void zs_flush_chars(struct tty_struct
*tty
)
1115 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
1116 unsigned long flags
;
1118 if (serial_paranoia_check(info
, tty
->device
, "zs_flush_chars"))
1121 save_flags(flags
); cli();
1122 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1126 /* Enable transmitter */
1127 info
->curregs
[1] |= TxINT_ENAB
|EXT_INT_ENAB
;
1128 write_zsreg(info
->zs_channel
, 1, info
->curregs
[1]);
1129 info
->curregs
[5] |= TxENAB
;
1130 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1133 * Send a first (bootstrapping) character. A best solution is
1134 * to call transmit_chars() here which handles output in a
1135 * generic way. Current transmit_chars() not only transmits,
1136 * but resets interrupts also what we do not desire here.
1137 * XXX Discuss with David.
1139 zs_put_char(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
1140 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
1144 restore_flags(flags
);
1147 static int zs_write(struct tty_struct
* tty
, int from_user
,
1148 const unsigned char *buf
, int count
)
1150 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
1151 unsigned long flags
;
1154 if (serial_paranoia_check(info
, tty
->device
, "zs_write"))
1157 if (!info
|| !info
->xmit_buf
)
1163 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1164 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1170 copy_from_user(tmp_buf
, buf
, c
);
1171 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1172 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1173 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1176 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1177 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1178 info
->xmit_cnt
+= c
;
1179 restore_flags(flags
);
1186 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
1187 /* Enable transmitter */
1188 info
->curregs
[1] |= TxINT_ENAB
|EXT_INT_ENAB
;
1189 write_zsreg(info
->zs_channel
, 1, info
->curregs
[1]);
1190 info
->curregs
[5] |= TxENAB
;
1191 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1193 zs_put_char(info
->zs_channel
,
1194 info
->xmit_buf
[info
->xmit_tail
++]);
1195 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
1200 restore_flags(flags
);
1204 static int zs_write_room(struct tty_struct
*tty
)
1206 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
1209 if (serial_paranoia_check(info
, tty
->device
, "zs_write_room"))
1211 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1217 static int zs_chars_in_buffer(struct tty_struct
*tty
)
1219 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
1221 if (serial_paranoia_check(info
, tty
->device
, "zs_chars_in_buffer"))
1223 return info
->xmit_cnt
;
1226 static void zs_flush_buffer(struct tty_struct
*tty
)
1228 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
1230 if (serial_paranoia_check(info
, tty
->device
, "zs_flush_buffer"))
1233 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1235 wake_up_interruptible(&tty
->write_wait
);
1236 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1237 tty
->ldisc
.write_wakeup
)
1238 (tty
->ldisc
.write_wakeup
)(tty
);
1242 * ------------------------------------------------------------
1245 * This routine is called by the upper-layer tty layer to signal that
1246 * incoming characters should be throttled.
1247 * ------------------------------------------------------------
1249 static void zs_throttle(struct tty_struct
* tty
)
1251 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
1252 #ifdef SERIAL_DEBUG_THROTTLE
1255 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
1256 tty
->ldisc
.chars_in_buffer(tty
));
1259 if (serial_paranoia_check(info
, tty
->device
, "zs_throttle"))
1263 info
->x_char
= STOP_CHAR(tty
);
1265 /* Turn off RTS line */
1267 info
->curregs
[5] &= ~RTS
;
1268 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1272 static void zs_unthrottle(struct tty_struct
* tty
)
1274 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
1275 #ifdef SERIAL_DEBUG_THROTTLE
1278 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1279 tty
->ldisc
.chars_in_buffer(tty
));
1282 if (serial_paranoia_check(info
, tty
->device
, "zs_unthrottle"))
1289 info
->x_char
= START_CHAR(tty
);
1292 /* Assert RTS line */
1294 info
->curregs
[5] |= RTS
;
1295 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1300 * ------------------------------------------------------------
1301 * zs_ioctl() and friends
1302 * ------------------------------------------------------------
1305 static int get_serial_info(struct sun_serial
* info
,
1306 struct serial_struct
* retinfo
)
1308 struct serial_struct tmp
;
1312 memset(&tmp
, 0, sizeof(tmp
));
1313 tmp
.type
= info
->type
;
1314 tmp
.line
= info
->line
;
1315 tmp
.port
= info
->port
;
1316 tmp
.irq
= info
->irq
;
1317 tmp
.flags
= info
->flags
;
1318 tmp
.baud_base
= info
->baud_base
;
1319 tmp
.close_delay
= info
->close_delay
;
1320 tmp
.closing_wait
= info
->closing_wait
;
1321 tmp
.custom_divisor
= info
->custom_divisor
;
1322 if (copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)))
1327 static int set_serial_info(struct sun_serial
* info
,
1328 struct serial_struct
* new_info
)
1330 struct serial_struct new_serial
;
1331 struct sun_serial old_info
;
1334 if (!new_info
|| copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
1338 if (!capable(CAP_SYS_ADMIN
)) {
1339 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1340 (new_serial
.type
!= info
->type
) ||
1341 (new_serial
.close_delay
!= info
->close_delay
) ||
1342 ((new_serial
.flags
& ~ZILOG_USR_MASK
) !=
1343 (info
->flags
& ~ZILOG_USR_MASK
)))
1345 info
->flags
= ((info
->flags
& ~ZILOG_USR_MASK
) |
1346 (new_serial
.flags
& ZILOG_USR_MASK
));
1347 info
->custom_divisor
= new_serial
.custom_divisor
;
1348 goto check_and_exit
;
1351 if(new_serial
.baud_base
< 9600)
1354 if (info
->count
> 1)
1358 * OK, past this point, all the error checking has been done.
1359 * At this point, we start making changes.....
1362 info
->baud_base
= new_serial
.baud_base
;
1363 info
->flags
= ((info
->flags
& ~ZILOG_FLAGS
) |
1364 (new_serial
.flags
& ZILOG_FLAGS
));
1365 info
->custom_divisor
= new_serial
.custom_divisor
;
1366 info
->type
= new_serial
.type
;
1367 info
->close_delay
= new_serial
.close_delay
;
1368 info
->closing_wait
= new_serial
.closing_wait
;
1371 retval
= startup(info
);
1376 * get_lsr_info - get line status register info
1378 * Purpose: Let user call ioctl() to get info when the UART physically
1379 * is emptied. On bus types like RS485, the transmitter must
1380 * release the bus after transmitting. This must be done when
1381 * the transmit shift register is empty, not be done when the
1382 * transmit holding register is empty. This functionality
1383 * allows an RS485 driver to be written in user space.
1385 static int get_lsr_info(struct sun_serial
* info
, unsigned int *value
)
1387 unsigned char status
;
1390 status
= sbus_readb(&info
->zs_channel
->control
);
1392 ZSLOG(REGCTRL
, status
, 0);
1394 if (put_user(status
, value
))
1399 static int get_modem_info(struct sun_serial
* info
, unsigned int *value
)
1401 unsigned char status
;
1402 unsigned int result
;
1405 status
= sbus_readb(&info
->zs_channel
->control
);
1407 ZSLOG(REGCTRL
, status
, 0);
1409 result
= ((info
->curregs
[5] & RTS
) ? TIOCM_RTS
: 0)
1410 | ((info
->curregs
[5] & DTR
) ? TIOCM_DTR
: 0)
1411 | ((status
& DCD
) ? TIOCM_CAR
: 0)
1412 | ((status
& SYNC
) ? TIOCM_DSR
: 0)
1413 | ((status
& CTS
) ? TIOCM_CTS
: 0);
1414 if (put_user(result
, value
))
1419 static int set_modem_info(struct sun_serial
* info
, unsigned int cmd
,
1420 unsigned int *value
)
1424 if (get_user(arg
, value
))
1428 if (arg
& TIOCM_RTS
)
1429 info
->curregs
[5] |= RTS
;
1430 if (arg
& TIOCM_DTR
)
1431 info
->curregs
[5] |= DTR
;
1434 if (arg
& TIOCM_RTS
)
1435 info
->curregs
[5] &= ~RTS
;
1436 if (arg
& TIOCM_DTR
)
1437 info
->curregs
[5] &= ~DTR
;
1440 info
->curregs
[5] = ((info
->curregs
[5] & ~(RTS
| DTR
))
1441 | ((arg
& TIOCM_RTS
) ? RTS
: 0)
1442 | ((arg
& TIOCM_DTR
) ? DTR
: 0));
1448 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1454 * This routine sends a break character out the serial port.
1456 static void send_break( struct sun_serial
* info
, int duration
)
1460 current
->state
= TASK_INTERRUPTIBLE
;
1462 write_zsreg(info
->zs_channel
, 5, (info
->curregs
[5] | SND_BRK
));
1463 schedule_timeout(duration
);
1464 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1468 static int zs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1469 unsigned int cmd
, unsigned long arg
)
1471 struct sun_serial
* info
= (struct sun_serial
*) tty
->driver_data
;
1474 if (serial_paranoia_check(info
, tty
->device
, "zs_ioctl"))
1477 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1478 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1479 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1480 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1485 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1486 retval
= tty_check_change(tty
);
1489 tty_wait_until_sent(tty
, 0);
1491 send_break(info
, HZ
/4); /* 1/4 second */
1493 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1494 retval
= tty_check_change(tty
);
1497 tty_wait_until_sent(tty
, 0);
1498 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
1501 if (put_user(C_CLOCAL(tty
) ? 1 : 0,
1502 (unsigned long *) arg
))
1506 if (get_user(arg
, (unsigned long *) arg
))
1508 tty
->termios
->c_cflag
=
1509 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1510 (arg
? CLOCAL
: 0));
1513 return get_modem_info(info
, (unsigned int *) arg
);
1517 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1519 return get_serial_info(info
,
1520 (struct serial_struct
*) arg
);
1522 return set_serial_info(info
,
1523 (struct serial_struct
*) arg
);
1524 case TIOCSERGETLSR
: /* Get line status register */
1525 return get_lsr_info(info
, (unsigned int *) arg
);
1527 case TIOCSERGSTRUCT
:
1528 if (copy_to_user((struct sun_serial
*) arg
,
1529 info
, sizeof(struct sun_serial
)))
1534 return -ENOIOCTLCMD
;
1539 static void zs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1541 struct sun_serial
*info
= (struct sun_serial
*) tty
->driver_data
;
1543 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1548 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1549 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1550 tty
->hw_stopped
= 0;
1556 * ------------------------------------------------------------
1559 * This routine is called when the serial port gets closed. First, we
1560 * wait for the last remaining data to be sent. Then, we unlink its
1561 * ZILOG structure from the interrupt chain if necessary, and we free
1562 * that IRQ if nothing is left in the chain.
1563 * ------------------------------------------------------------
1565 static void zs_close(struct tty_struct
*tty
, struct file
* filp
)
1567 struct sun_serial
* info
= (struct sun_serial
*) tty
->driver_data
;
1568 unsigned long flags
;
1570 if (!info
|| serial_paranoia_check(info
, tty
->device
, "zs_close"))
1573 save_flags(flags
); cli();
1575 if (tty_hung_up_p(filp
)) {
1576 restore_flags(flags
);
1580 #ifdef SERIAL_DEBUG_OPEN
1581 printk("zs_close tty-%d, count = %d\n", info
->line
, info
->count
);
1583 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1585 * Uh, oh. tty->count is 1, which means that the tty
1586 * structure will be freed. Info->count should always
1587 * be one in these conditions. If it's greater than
1588 * one, we've got real problems, since it means the
1589 * serial port won't be shutdown.
1591 printk("zs_close: bad serial port count; tty->count is 1, "
1592 "info->count is %d\n", info
->count
);
1595 if (--info
->count
< 0) {
1596 printk("zs_close: bad serial port count for ttys%d: %d\n",
1597 info
->line
, info
->count
);
1601 restore_flags(flags
);
1604 info
->flags
|= ZILOG_CLOSING
;
1606 * Save the termios structure, since this port may have
1607 * separate termios for callout and dialin.
1609 if (info
->flags
& ZILOG_NORMAL_ACTIVE
)
1610 info
->normal_termios
= *tty
->termios
;
1611 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
)
1612 info
->callout_termios
= *tty
->termios
;
1614 * Now we wait for the transmit buffer to clear; and we notify
1615 * the line discipline to only process XON/XOFF characters.
1618 if (info
->closing_wait
!= ZILOG_CLOSING_WAIT_NONE
)
1619 tty_wait_until_sent(tty
, info
->closing_wait
);
1621 * At this point we stop accepting input. To do this, we
1622 * disable the receive line status interrupts, and tell the
1623 * interrupt driver to stop checking the data ready bit in the
1624 * line status register.
1626 /** if (!info->iscons) ... **/
1627 info
->curregs
[3] &= ~RxENAB
;
1628 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
1629 info
->curregs
[1] &= ~(RxINT_MASK
);
1630 write_zsreg(info
->zs_channel
, 1, info
->curregs
[1]);
1631 ZS_CLEARFIFO(info
->zs_channel
);
1634 if (tty
->driver
.flush_buffer
)
1635 tty
->driver
.flush_buffer(tty
);
1636 if (tty
->ldisc
.flush_buffer
)
1637 tty
->ldisc
.flush_buffer(tty
);
1641 if (tty
->ldisc
.num
!= ldiscs
[N_TTY
].num
) {
1642 if (tty
->ldisc
.close
)
1643 (tty
->ldisc
.close
)(tty
);
1644 tty
->ldisc
= ldiscs
[N_TTY
];
1645 tty
->termios
->c_line
= N_TTY
;
1646 if (tty
->ldisc
.open
)
1647 (tty
->ldisc
.open
)(tty
);
1649 if (info
->blocked_open
) {
1650 if (info
->close_delay
) {
1651 current
->state
= TASK_INTERRUPTIBLE
;
1652 schedule_timeout(info
->close_delay
);
1654 wake_up_interruptible(&info
->open_wait
);
1656 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CALLOUT_ACTIVE
|
1658 wake_up_interruptible(&info
->close_wait
);
1659 #ifdef SERIAL_DEBUG_OPEN
1660 printk("zs_close tty-%d exiting, count = %d\n", info
->line
, info
->count
);
1662 restore_flags(flags
);
1666 * zs_hangup() --- called by tty_hangup() when a hangup is signaled.
1668 void zs_hangup(struct tty_struct
*tty
)
1670 struct sun_serial
* info
= (struct sun_serial
*) tty
->driver_data
;
1672 if (serial_paranoia_check(info
, tty
->device
, "zs_hangup"))
1678 #ifdef SERIAL_DEBUG_OPEN
1679 printk("zs_hangup<%p: tty-%d, count = %d bye\n",
1680 __builtin_return_address(0), info
->line
, info
->count
);
1683 zs_flush_buffer(tty
);
1687 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CALLOUT_ACTIVE
);
1689 wake_up_interruptible(&info
->open_wait
);
1693 * ------------------------------------------------------------
1694 * zs_open() and friends
1695 * ------------------------------------------------------------
1697 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1698 struct sun_serial
*info
)
1700 DECLARE_WAITQUEUE(wait
, current
);
1701 int retval
, do_clocal
= 0;
1705 * If the device is in the middle of being closed, then block
1706 * until it's done, and then try again.
1708 if (info
->flags
& ZILOG_CLOSING
) {
1709 interruptible_sleep_on(&info
->close_wait
);
1710 #ifdef SERIAL_DO_RESTART
1711 if (info
->flags
& ZILOG_HUP_NOTIFY
)
1714 return -ERESTARTSYS
;
1721 * If this is a callout device, then just make sure the normal
1722 * device isn't being used.
1724 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1725 if (info
->flags
& ZILOG_NORMAL_ACTIVE
)
1727 if ((info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1728 (info
->flags
& ZILOG_SESSION_LOCKOUT
) &&
1729 (info
->session
!= current
->session
))
1731 if ((info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1732 (info
->flags
& ZILOG_PGRP_LOCKOUT
) &&
1733 (info
->pgrp
!= current
->pgrp
))
1735 info
->flags
|= ZILOG_CALLOUT_ACTIVE
;
1740 * If non-blocking mode is set, or the port is not enabled,
1741 * then make the check up front and then exit.
1743 if ((filp
->f_flags
& O_NONBLOCK
) ||
1744 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1745 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
)
1747 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1751 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
) {
1752 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1755 if (tty
->termios
->c_cflag
& CLOCAL
)
1760 * Block waiting for the carrier detect and the line to become
1761 * free (i.e., not in use by the callout). While we are in
1762 * this loop, info->count is dropped by one, so that
1763 * zs_close() knows when to free things. We restore it upon
1764 * exit, either normal or abnormal.
1767 add_wait_queue(&info
->open_wait
, &wait
);
1768 #ifdef SERIAL_DEBUG_OPEN
1769 printk("block_til_ready before block: ttys%d, count = %d\n",
1770 info
->line
, info
->count
);
1773 if(!tty_hung_up_p(filp
))
1776 info
->blocked_open
++;
1779 if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
))
1782 set_current_state(TASK_INTERRUPTIBLE
);
1783 if (tty_hung_up_p(filp
) ||
1784 !(info
->flags
& ZILOG_INITIALIZED
)) {
1785 #ifdef SERIAL_DEBUG_OPEN
1786 printk("block_til_ready hup-ed: ttys%d, count = %d\n",
1787 info
->line
, info
->count
);
1789 #ifdef SERIAL_DO_RESTART
1790 if (info
->flags
& ZILOG_HUP_NOTIFY
)
1793 retval
= -ERESTARTSYS
;
1801 r0
= read_zsreg(info
->zs_channel
, R0
);
1803 if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1804 !(info
->flags
& ZILOG_CLOSING
) &&
1805 (do_clocal
|| (DCD
& r0
)))
1807 if (signal_pending(current
)) {
1808 retval
= -ERESTARTSYS
;
1811 #ifdef SERIAL_DEBUG_OPEN
1812 printk("block_til_ready blocking: ttys%d, count = %d\n",
1813 info
->line
, info
->count
);
1817 current
->state
= TASK_RUNNING
;
1818 remove_wait_queue(&info
->open_wait
, &wait
);
1819 if (!tty_hung_up_p(filp
))
1821 info
->blocked_open
--;
1822 #ifdef SERIAL_DEBUG_OPEN
1823 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1824 info
->line
, info
->count
);
1828 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1833 * This routine is called whenever a serial port is opened. It
1834 * enables interrupts for a serial port, linking in its ZILOG structure into
1835 * the IRQ chain. It also performs the serial-specific
1836 * initialization for the tty structure.
1838 int zs_open(struct tty_struct
*tty
, struct file
* filp
)
1840 struct sun_serial
*info
;
1843 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1845 /* The zilog lines for the mouse/keyboard must be
1846 * opened using their respective drivers.
1848 if ((line
< 0) || (line
>= NUM_CHANNELS
))
1850 if((line
== KEYBOARD_LINE
) || (line
== MOUSE_LINE
))
1852 info
= zs_soft
+ line
;
1853 /* Is the kgdb running over this line? */
1854 if (info
->kgdb_channel
)
1856 if (serial_paranoia_check(info
, tty
->device
, "zs_open"))
1858 #ifdef SERIAL_DEBUG_OPEN
1859 printk("zs_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
1862 if (info
->tty
!= 0 && info
->tty
!= tty
) {
1864 printk("zs_open %s%d, tty overwrite.\n", tty
->driver
.name
, info
->line
);
1868 tty
->driver_data
= info
;
1872 * Start up serial port
1874 retval
= startup(info
);
1878 retval
= block_til_ready(tty
, filp
, info
);
1880 #ifdef SERIAL_DEBUG_OPEN
1881 printk("zs_open returning after block_til_ready with %d\n",
1887 if ((info
->count
== 1) && (info
->flags
& ZILOG_SPLIT_TERMIOS
)) {
1888 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1889 *tty
->termios
= info
->normal_termios
;
1891 *tty
->termios
= info
->callout_termios
;
1895 #ifdef CONFIG_SERIAL_CONSOLE
1896 if (zs_console
.cflag
&& zs_console
.index
== line
) {
1897 tty
->termios
->c_cflag
= zs_console
.cflag
;
1898 zs_console
.cflag
= 0;
1903 info
->session
= current
->session
;
1904 info
->pgrp
= current
->pgrp
;
1906 #ifdef SERIAL_DEBUG_OPEN
1907 printk("zs_open ttys%d successful...", info
->line
);
1912 /* Finally, routines used to initialize the serial driver. */
1914 static void show_serial_version(void)
1916 char *revision
= "$Revision: 1.60 $";
1919 version
= strchr(revision
, ' ');
1920 p
= strchr(++version
, ' ');
1922 printk("Sparc Zilog8530 serial driver version %s\n", version
);
1926 /* Probe the PROM for the request zs chip number.
1928 * Note: The Sun Voyager shows two addresses and two intr for it's
1929 * Zilogs, what the second does, I don't know. It does work
1930 * with using only the first number of each property. Also
1931 * we have a special version for sun4u.
1934 static struct sun_zslayout
* __init
get_zs(int chip
)
1936 unsigned int vaddr
[2] = { 0, 0 };
1937 unsigned long mapped_addr
= 0;
1938 int busnode
, seen
, zsnode
, sun4u_ino
;
1941 if(chip
< 0 || chip
>= NUM_SERIAL
) {
1942 prom_printf("get_zs bogon zs chip number");
1947 busnode
= central_bus
->child
->prom_node
;
1949 busnode
= prom_searchsiblings(prom_getchild(prom_root_node
), "sbus");
1950 if(busnode
== 0 || busnode
== -1) {
1951 prom_printf("get_zs: no zs bus to search");
1954 zsnode
= prom_getchild(busnode
);
1959 zsnode
= prom_searchsiblings(zsnode
, "zs");
1960 slave
= prom_getintdefault(zsnode
, "slave", -1);
1961 if((slave
== chip
) || (seen
== chip
)) {
1962 int len
= prom_getproperty(zsnode
, "address",
1963 (void *) vaddr
, sizeof(vaddr
));
1965 if(len
== -1 || central_bus
!= NULL
) {
1966 struct sbus_bus
*sbus
= NULL
;
1967 struct sbus_dev
*sdev
= NULL
;
1969 /* "address" property is not guarenteed,
1970 * everything in I/O is implicitly mapped
1971 * anyways by our clever TLB miss handling
1972 * scheme, so don't fail here. -DaveM
1974 if (central_bus
== NULL
) {
1975 for_each_sbus(sbus
) {
1976 for_each_sbusdev(sdev
, sbus
) {
1977 if (sdev
->prom_node
== zsnode
)
1983 if (sdev
== NULL
&& central_bus
== NULL
)
1985 if (central_bus
== NULL
) {
1987 sbus_ioremap(&sdev
->resource
[0], 0,
1988 PAGE_SIZE
, "Zilog Registers");
1990 struct linux_prom_registers zsregs
[1];
1993 err
= prom_getproperty(zsnode
, "reg",
1997 prom_printf("ZS: Cannot map Zilog regs.\n");
2000 apply_fhc_ranges(central_bus
->child
, &zsregs
[0], 1);
2001 apply_central_ranges(central_bus
, &zsregs
[0], 1);
2003 ((((u64
)zsregs
[0].which_io
)<<32UL)|
2004 ((u64
)zsregs
[0].phys_addr
));
2006 } else if(len
% sizeof(unsigned int)) {
2007 prom_printf("WHOOPS: proplen for %s "
2008 "was %d, need multiple of "
2009 "%d\n", "address", len
,
2010 sizeof(unsigned int));
2011 panic("zilog: address property");
2013 zs_nodes
[chip
] = zsnode
;
2014 len
= prom_getproperty(zsnode
, "interrupts",
2015 (char *) &sun4u_ino
,
2016 (sizeof(sun4u_ino
)));
2019 unsigned long iclr
, imap
;
2021 iclr
= central_bus
->child
->fhc_regs
.uregs
+ FHC_UREGS_ICLR
;
2022 imap
= central_bus
->child
->fhc_regs
.uregs
+ FHC_UREGS_IMAP
;
2023 irq
= zilog_irq
= build_irq(12, 0, iclr
, imap
);
2026 sbus_build_irq(sbus_root
, sun4u_ino
);
2031 zsnode
= prom_getsibling(zsnode
);
2035 panic("get_zs: whee chip not found");
2036 if(!vaddr
[0] && !mapped_addr
)
2037 panic("get_zs: whee no serial chip mappable");
2038 if (mapped_addr
!= 0) {
2039 return (struct sun_zslayout
*) mapped_addr
;
2041 pgd_t
*pgd
= pgd_offset_k((unsigned long)vaddr
[0]);
2042 pmd_t
*pmd
= pmd_offset(pgd
, (unsigned long)vaddr
[0]);
2043 pte_t
*pte
= pte_offset(pmd
, (unsigned long)vaddr
[0]);
2044 unsigned long base
= pte_val(*pte
) & _PAGE_PADDR
;
2046 /* Translate PROM's mapping we captured at boot
2047 * time into physical address.
2049 base
+= ((unsigned long)vaddr
[0] & ~PAGE_MASK
);
2050 return (struct sun_zslayout
*) base
;
2053 #else /* !(__sparc_v9__) */
2054 static struct sun_zslayout
* __init
get_zs(int chip
)
2056 struct linux_prom_irqs tmp_irq
[2];
2057 unsigned int paddr
= 0;
2058 unsigned int vaddr
[2] = { 0, 0 };
2059 int zsnode
, tmpnode
, iospace
, slave
, len
;
2060 int cpunode
= 0, bbnode
= 0;
2065 if(chip
< 0 || chip
>= NUM_SERIAL
)
2066 panic("get_zs bogon zs chip number");
2068 if(sparc_cpu_model
== sun4
) {
2069 struct resource dummy_resource
;
2071 /* Grrr, these have to be hardcoded aieee */
2083 zilog_irq
= irq
= 12;
2084 dummy_resource
.start
= paddr
;
2085 dummy_resource
.end
= paddr
+ 8 - 1;
2086 dummy_resource
.flags
= IORESOURCE_IO
;
2087 vaddr
[0] = sbus_ioremap(&dummy_resource
, 0,
2090 /* Can use the prom for other machine types */
2091 zsnode
= prom_getchild(prom_root_node
);
2092 if (sparc_cpu_model
== sun4d
) {
2098 while (tmpnode
&& (tmpnode
= prom_searchsiblings(tmpnode
, "cpu-unit"))) {
2099 bbnode
= prom_getchild(tmpnode
);
2100 if (bbnode
&& (bbnode
= prom_searchsiblings(bbnode
, "bootbus"))) {
2101 if (no
== (chip
>> 1)) {
2103 zsnode
= prom_getchild(bbnode
);
2104 chipid
= (chip
& 1);
2109 tmpnode
= prom_getsibling(tmpnode
);
2112 panic ("get_zs: couldn't find %dth bootbus\n", chip
>> 1);
2114 tmpnode
= prom_searchsiblings(zsnode
, "obio");
2116 zsnode
= prom_getchild(tmpnode
);
2119 panic("get_zs no zs serial prom node");
2121 zsnode
= prom_searchsiblings(zsnode
, "zs");
2122 slave
= prom_getintdefault(zsnode
, "slave", -1);
2123 if(slave
== chipid
) {
2124 /* The one we want */
2125 if (sparc_cpu_model
!= sun4d
) {
2126 len
= prom_getproperty(zsnode
, "address",
2129 if (len
% sizeof(unsigned int)) {
2130 prom_printf("WHOOPS: proplen for %s "
2131 "was %d, need multiple of "
2132 "%d\n", "address", len
,
2133 sizeof(unsigned int));
2134 panic("zilog: address property");
2137 /* On sun4d don't have address property :( */
2138 struct linux_prom_registers zsreg
[4];
2139 struct resource res
;
2141 if (prom_getproperty(zsnode
, "reg", (char *)zsreg
, sizeof(zsreg
)) == -1) {
2142 prom_printf ("Cannot map zs regs\n");
2145 prom_apply_generic_ranges(bbnode
, cpunode
, zsreg
, 1);
2146 res
.start
= zsreg
[0].phys_addr
;
2147 res
.end
= res
.start
+ 8 - 1;
2148 res
.flags
= zsreg
[0].which_io
| IORESOURCE_IO
;
2149 vaddr
[0] = sbus_ioremap(&res
, 0,
2152 zs_nodes
[chip
] = zsnode
;
2153 len
= prom_getproperty(zsnode
, "intr",
2156 if (len
% sizeof(struct linux_prom_irqs
)) {
2158 "WHOOPS: proplen for %s "
2159 "was %d, need multiple of "
2160 "%d\n", "intr", len
,
2161 sizeof(struct linux_prom_irqs
));
2162 panic("zilog: intr property");
2165 irq
= zilog_irq
= tmp_irq
[0].pri
;
2167 if(tmp_irq
[0].pri
!= irq
)
2168 panic("zilog: bogon irqs");
2172 zsnode
= prom_getsibling(zsnode
);
2175 panic("get_zs whee chip not found");
2178 panic("get_zs whee no serial chip mappable");
2180 return (struct sun_zslayout
*)(unsigned long) vaddr
[0];
2183 /* This is for the auto baud rate detection in the mouse driver. */
2184 void zs_change_mouse_baud(int newbaud
)
2186 int channel
= MOUSE_LINE
;
2189 zs_soft
[channel
].zs_baud
= newbaud
;
2190 brg
= BPS_TO_BRG(zs_soft
[channel
].zs_baud
,
2191 (ZS_CLOCK
/ zs_soft
[channel
].clk_divisor
));
2192 write_zsreg(zs_soft
[channel
].zs_channel
, R12
, (brg
& 0xff));
2193 write_zsreg(zs_soft
[channel
].zs_channel
, R13
, ((brg
>> 8) & 0xff));
2196 void __init
zs_init_alloc_failure(const char *table_name
)
2198 prom_printf("zs_probe: Cannot alloc %s.\n", table_name
);
2202 void * __init
zs_alloc_bootmem(unsigned long size
)
2206 ret
= __alloc_bootmem(size
, SMP_CACHE_BYTES
, 0UL);
2208 memset(ret
, 0, size
);
2213 void __init
zs_alloc_tables(void)
2215 zs_chips
= (struct sun_zslayout
**)
2216 zs_alloc_bootmem(NUM_SERIAL
* sizeof(struct sun_zslayout
*));
2217 if (zs_chips
== NULL
)
2218 zs_init_alloc_failure("zs_chips");
2219 zs_channels
= (struct sun_zschannel
**)
2220 zs_alloc_bootmem(NUM_CHANNELS
* sizeof(struct sun_zschannel
*));
2221 if (zs_channels
== NULL
)
2222 zs_init_alloc_failure("zs_channels");
2224 zs_alloc_bootmem(NUM_SERIAL
* sizeof(int));
2225 if (zs_nodes
== NULL
)
2226 zs_init_alloc_failure("zs_nodes");
2227 zs_soft
= (struct sun_serial
*)
2228 zs_alloc_bootmem(NUM_CHANNELS
* sizeof(struct sun_serial
));
2229 if (zs_soft
== NULL
)
2230 zs_init_alloc_failure("zs_soft");
2231 zs_ttys
= (struct tty_struct
*)
2232 zs_alloc_bootmem(NUM_CHANNELS
* sizeof(struct tty_struct
));
2233 if (zs_ttys
== NULL
)
2234 zs_init_alloc_failure("zs_ttys");
2235 serial_table
= (struct tty_struct
**)
2236 zs_alloc_bootmem(NUM_CHANNELS
* sizeof(struct tty_struct
*));
2237 if (serial_table
== NULL
)
2238 zs_init_alloc_failure("serial_table");
2239 serial_termios
= (struct termios
**)
2240 zs_alloc_bootmem(NUM_CHANNELS
* sizeof(struct termios
*));
2241 if (serial_termios
== NULL
)
2242 zs_init_alloc_failure("serial_termios");
2243 serial_termios_locked
= (struct termios
**)
2244 zs_alloc_bootmem(NUM_CHANNELS
* sizeof(struct termios
*));
2245 if (serial_termios_locked
== NULL
)
2246 zs_init_alloc_failure("serial_termios_locked");
2249 int __init
zs_probe(void)
2253 if(sparc_cpu_model
== sun4
)
2258 node
= prom_getchild(prom_root_node
);
2259 if (sparc_cpu_model
== sun4d
) {
2262 while (node
&& (node
= prom_searchsiblings(node
, "cpu-unit"))) {
2263 bbnode
= prom_getchild(node
);
2264 if (bbnode
&& prom_searchsiblings(bbnode
, "bootbus"))
2266 node
= prom_getsibling(node
);
2271 else if (sparc_cpu_model
== sun4u
) {
2274 /* Central bus zilogs must be checked for first,
2275 * since Enterprise boxes might have SBUSes as well.
2277 central_node
= prom_finddevice("/central");
2278 if(central_node
!= 0 && central_node
!= -1)
2279 node
= prom_searchsiblings(prom_getchild(central_node
), "fhc");
2281 node
= prom_searchsiblings(node
, "sbus");
2282 if(node
!= 0 && node
!= -1)
2283 node
= prom_getchild(node
);
2284 if(node
== 0 || node
== -1)
2287 #endif /* __sparc_v9__ */
2289 node
= prom_searchsiblings(node
, "obio");
2291 node
= prom_getchild(node
);
2296 node
= prom_searchsiblings(node
, "zs");
2305 /* Fill in rs_ops struct... */
2306 #ifdef CONFIG_SERIAL_CONSOLE
2307 sunserial_setinitfunc(zs_console_init
);
2309 sunserial_setinitfunc(zs_init
);
2310 rs_ops
.rs_kgdb_hook
= zs_kgdb_hook
;
2311 rs_ops
.rs_change_mouse_baud
= zs_change_mouse_baud
;
2313 sunkbd_setinitfunc(sun_kbd_init
);
2314 kbd_ops
.compute_shiftstate
= sun_compute_shiftstate
;
2315 kbd_ops
.setledstate
= sun_setledstate
;
2316 kbd_ops
.getledstate
= sun_getledstate
;
2317 kbd_ops
.setkeycode
= sun_setkeycode
;
2318 kbd_ops
.getkeycode
= sun_getkeycode
;
2319 #if defined(__sparc_v9__) && defined(CONFIG_PCI)
2320 sunkbd_install_keymaps(sun_key_maps
, sun_keymap_count
,
2321 sun_func_buf
, sun_func_table
,
2322 sun_funcbufsize
, sun_funcbufleft
,
2323 sun_accent_table
, sun_accent_table_size
);
2328 static inline void zs_prepare(void)
2331 unsigned long flags
;
2336 save_and_cli(flags
);
2338 /* Set up our interrupt linked list */
2339 zs_chain
= &zs_soft
[0];
2340 for(channel
= 0; channel
< NUM_CHANNELS
- 1; channel
++) {
2341 zs_soft
[channel
].zs_next
= &zs_soft
[channel
+ 1];
2342 zs_soft
[channel
].line
= channel
;
2344 zs_soft
[channel
].zs_next
= 0;
2346 /* Initialize Softinfo */
2347 for(chip
= 0; chip
< NUM_SERIAL
; chip
++) {
2348 /* If we are doing kgdb over one of the channels on
2349 * chip zero, kgdb_channel will be set to 1 by the
2350 * zs_kgdb_hook() routine below.
2352 if(!zs_chips
[chip
]) {
2353 zs_chips
[chip
] = get_zs(chip
);
2354 /* Two channels per chip */
2355 zs_channels
[(chip
*2)] = &zs_chips
[chip
]->channelA
;
2356 zs_channels
[(chip
*2)+1] = &zs_chips
[chip
]->channelB
;
2357 zs_soft
[(chip
*2)].kgdb_channel
= 0;
2358 zs_soft
[(chip
*2)+1].kgdb_channel
= 0;
2361 /* First, set up channel A on this chip. */
2363 zs_soft
[channel
].zs_channel
= zs_channels
[channel
];
2364 zs_soft
[channel
].change_needed
= 0;
2365 zs_soft
[channel
].clk_divisor
= 16;
2366 zs_soft
[channel
].cons_keyb
= 0;
2367 zs_soft
[channel
].cons_mouse
= 0;
2368 zs_soft
[channel
].channelA
= 1;
2370 /* Now, channel B */
2372 zs_soft
[channel
].zs_channel
= zs_channels
[channel
];
2373 zs_soft
[channel
].change_needed
= 0;
2374 zs_soft
[channel
].clk_divisor
= 16;
2375 zs_soft
[channel
].cons_keyb
= 0;
2376 zs_soft
[channel
].cons_mouse
= 0;
2377 zs_soft
[channel
].channelA
= 0;
2380 restore_flags(flags
);
2383 int __init
zs_init(void)
2385 int channel
, brg
, i
;
2386 unsigned long flags
;
2387 struct sun_serial
*info
;
2390 /* Setup base handler, and timer table. */
2391 init_bh(SERIAL_BH
, do_serial_bh
);
2393 show_serial_version();
2395 /* Initialize the tty_driver structure */
2396 /* SPARC: Not all of this is exactly right for us. */
2398 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
2399 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
2400 serial_driver
.driver_name
= "serial";
2401 #ifdef CONFIG_DEVFS_FS
2402 serial_driver
.name
= "tts/%d";
2404 serial_driver
.name
= "ttyS";
2406 serial_driver
.major
= TTY_MAJOR
;
2407 serial_driver
.minor_start
= 64;
2408 serial_driver
.num
= NUM_CHANNELS
;
2409 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
2410 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
2411 serial_driver
.init_termios
= tty_std_termios
;
2412 serial_driver
.init_termios
.c_cflag
=
2413 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2414 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
2415 serial_driver
.refcount
= &serial_refcount
;
2416 serial_driver
.table
= serial_table
;
2417 serial_driver
.termios
= serial_termios
;
2418 serial_driver
.termios_locked
= serial_termios_locked
;
2420 serial_driver
.open
= zs_open
;
2421 serial_driver
.close
= zs_close
;
2422 serial_driver
.write
= zs_write
;
2423 serial_driver
.flush_chars
= zs_flush_chars
;
2424 serial_driver
.write_room
= zs_write_room
;
2425 serial_driver
.chars_in_buffer
= zs_chars_in_buffer
;
2426 serial_driver
.flush_buffer
= zs_flush_buffer
;
2427 serial_driver
.ioctl
= zs_ioctl
;
2428 serial_driver
.throttle
= zs_throttle
;
2429 serial_driver
.unthrottle
= zs_unthrottle
;
2430 serial_driver
.set_termios
= zs_set_termios
;
2431 serial_driver
.stop
= zs_stop
;
2432 serial_driver
.start
= zs_start
;
2433 serial_driver
.hangup
= zs_hangup
;
2435 /* I'm too lazy, someone write versions of this for us. -DaveM */
2436 serial_driver
.read_proc
= 0;
2437 serial_driver
.proc_entry
= 0;
2440 * The callout device is just like normal device except for
2441 * major number and the subtype code.
2443 callout_driver
= serial_driver
;
2444 callout_driver
.name
= "cua/%d";
2445 callout_driver
.major
= TTYAUX_MAJOR
;
2446 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
2448 if (tty_register_driver(&serial_driver
))
2449 panic("Couldn't register serial driver\n");
2450 if (tty_register_driver(&callout_driver
))
2451 panic("Couldn't register callout driver\n");
2453 save_flags(flags
); cli();
2455 /* Initialize Softinfo */
2458 /* Grab IRQ line before poking the chips so we do
2459 * not lose any interrupts.
2461 if (request_irq(zilog_irq
, zs_interrupt
,
2462 (SA_INTERRUPT
| SA_STATIC_ALLOC
),
2463 "Zilog8530", zs_chain
)) {
2464 prom_printf("Unable to attach zs intr\n");
2468 /* Initialize Hardware */
2469 for(channel
= 0; channel
< NUM_CHANNELS
; channel
++) {
2470 /* Hardware reset each chip */
2471 if (!(channel
& 1)) {
2472 write_zsreg(zs_soft
[channel
].zs_channel
, R9
, FHWRES
);
2474 dummy
= read_zsreg(zs_soft
[channel
].zs_channel
, R0
);
2477 if(channel
== KEYBOARD_LINE
) {
2478 zs_soft
[channel
].cons_keyb
= 1;
2479 zs_soft
[channel
].parity_mask
= 0xff;
2480 zs_kbdchan
= zs_soft
[channel
].zs_channel
;
2482 write_zsreg(zs_soft
[channel
].zs_channel
, R4
,
2483 (PAR_EVEN
| X16CLK
| SB1
));
2484 write_zsreg(zs_soft
[channel
].zs_channel
, R3
, Rx8
);
2485 write_zsreg(zs_soft
[channel
].zs_channel
, R5
, Tx8
);
2486 write_zsreg(zs_soft
[channel
].zs_channel
, R9
, NV
);
2487 write_zsreg(zs_soft
[channel
].zs_channel
, R10
, NRZ
);
2488 write_zsreg(zs_soft
[channel
].zs_channel
, R11
,
2490 zs_soft
[channel
].zs_baud
= 1200;
2491 brg
= BPS_TO_BRG(zs_soft
[channel
].zs_baud
,
2492 ZS_CLOCK
/zs_soft
[channel
].clk_divisor
);
2493 write_zsreg(zs_soft
[channel
].zs_channel
, R12
,
2495 write_zsreg(zs_soft
[channel
].zs_channel
, R13
,
2496 ((brg
>> 8) & 0xff));
2497 write_zsreg(zs_soft
[channel
].zs_channel
, R14
, BRSRC
);
2499 /* Enable Rx/Tx, IRQs, and inform kbd driver */
2500 write_zsreg(zs_soft
[channel
].zs_channel
, R14
,
2502 write_zsreg(zs_soft
[channel
].zs_channel
, R3
,
2504 write_zsreg(zs_soft
[channel
].zs_channel
, R5
,
2505 (Tx8
| TxENAB
| DTR
| RTS
));
2507 write_zsreg(zs_soft
[channel
].zs_channel
, R15
,
2508 (DCDIE
| CTSIE
| TxUIE
| BRKIE
));
2509 write_zsreg(zs_soft
[channel
].zs_channel
, R0
,
2511 write_zsreg(zs_soft
[channel
].zs_channel
, R0
,
2514 write_zsreg(zs_soft
[channel
].zs_channel
, R1
,
2515 (EXT_INT_ENAB
| INT_ALL_Rx
));
2516 write_zsreg(zs_soft
[channel
].zs_channel
, R9
,
2518 ZS_CLEARERR(zs_soft
[channel
].zs_channel
);
2519 ZS_CLEARFIFO(zs_soft
[channel
].zs_channel
);
2520 } else if(channel
== MOUSE_LINE
) {
2521 zs_soft
[channel
].cons_mouse
= 1;
2522 zs_soft
[channel
].parity_mask
= 0xff;
2523 zs_mousechan
= zs_soft
[channel
].zs_channel
;
2525 write_zsreg(zs_soft
[channel
].zs_channel
, R4
,
2526 (PAR_EVEN
| X16CLK
| SB1
));
2527 write_zsreg(zs_soft
[channel
].zs_channel
, R3
, Rx8
);
2528 write_zsreg(zs_soft
[channel
].zs_channel
, R5
, Tx8
);
2529 write_zsreg(zs_soft
[channel
].zs_channel
, R9
, NV
);
2530 write_zsreg(zs_soft
[channel
].zs_channel
, R10
, NRZ
);
2531 write_zsreg(zs_soft
[channel
].zs_channel
, R11
,
2534 zs_soft
[channel
].zs_baud
= 4800;
2535 brg
= BPS_TO_BRG(zs_soft
[channel
].zs_baud
,
2536 ZS_CLOCK
/zs_soft
[channel
].clk_divisor
);
2537 write_zsreg(zs_soft
[channel
].zs_channel
, R12
,
2539 write_zsreg(zs_soft
[channel
].zs_channel
, R13
,
2540 ((brg
>> 8) & 0xff));
2541 write_zsreg(zs_soft
[channel
].zs_channel
, R14
, BRSRC
);
2543 /* Enable Rx, IRQs, and inform mouse driver */
2544 write_zsreg(zs_soft
[channel
].zs_channel
, R14
,
2546 write_zsreg(zs_soft
[channel
].zs_channel
, R3
,
2548 write_zsreg(zs_soft
[channel
].zs_channel
, R5
, Tx8
);
2550 write_zsreg(zs_soft
[channel
].zs_channel
, R15
,
2551 (DCDIE
| CTSIE
| TxUIE
| BRKIE
));
2552 write_zsreg(zs_soft
[channel
].zs_channel
, R0
,
2554 write_zsreg(zs_soft
[channel
].zs_channel
, R0
,
2557 write_zsreg(zs_soft
[channel
].zs_channel
, R1
,
2558 (EXT_INT_ENAB
| INT_ALL_Rx
));
2559 write_zsreg(zs_soft
[channel
].zs_channel
, R9
,
2563 } else if (zs_soft
[channel
].is_cons
) {
2564 brg
= BPS_TO_BRG(zs_soft
[channel
].zs_baud
,
2565 ZS_CLOCK
/zs_soft
[channel
].clk_divisor
);
2566 zscons_regs
[12] = brg
& 0xff;
2567 zscons_regs
[13] = (brg
>> 8) & 0xff;
2569 memcpy(zs_soft
[channel
].curregs
, zscons_regs
, sizeof(zscons_regs
));
2570 load_zsregs(&zs_soft
[channel
], zscons_regs
);
2572 ZS_CLEARERR(zs_soft
[channel
].zs_channel
);
2573 ZS_CLEARFIFO(zs_soft
[channel
].zs_channel
);
2574 } else if (zs_soft
[channel
].kgdb_channel
) {
2575 /* If this is the kgdb line, enable interrupts because
2576 * we now want to receive the 'control-c' character
2577 * from the client attached to us asynchronously.
2579 zs_soft
[channel
].parity_mask
= 0xff;
2580 kgdb_chaninit(&zs_soft
[channel
], 1,
2581 zs_soft
[channel
].zs_baud
);
2583 zs_soft
[channel
].parity_mask
= 0xff;
2584 write_zsreg(zs_soft
[channel
].zs_channel
, R4
,
2585 (PAR_EVEN
| X16CLK
| SB1
));
2586 write_zsreg(zs_soft
[channel
].zs_channel
, R3
, Rx8
);
2587 write_zsreg(zs_soft
[channel
].zs_channel
, R5
, Tx8
);
2588 write_zsreg(zs_soft
[channel
].zs_channel
, R9
, NV
);
2589 write_zsreg(zs_soft
[channel
].zs_channel
, R10
, NRZ
);
2590 write_zsreg(zs_soft
[channel
].zs_channel
, R11
,
2592 zs_soft
[channel
].zs_baud
= 9600;
2593 brg
= BPS_TO_BRG(zs_soft
[channel
].zs_baud
,
2594 ZS_CLOCK
/zs_soft
[channel
].clk_divisor
);
2595 write_zsreg(zs_soft
[channel
].zs_channel
, R12
,
2597 write_zsreg(zs_soft
[channel
].zs_channel
, R13
,
2598 ((brg
>> 8) & 0xff));
2599 write_zsreg(zs_soft
[channel
].zs_channel
, R14
, BRSRC
);
2600 write_zsreg(zs_soft
[channel
].zs_channel
, R14
,
2602 write_zsreg(zs_soft
[channel
].zs_channel
, R3
, Rx8
);
2603 write_zsreg(zs_soft
[channel
].zs_channel
, R5
, Tx8
);
2604 write_zsreg(zs_soft
[channel
].zs_channel
, R15
, DCDIE
);
2605 write_zsreg(zs_soft
[channel
].zs_channel
, R9
, NV
| MIE
);
2606 write_zsreg(zs_soft
[channel
].zs_channel
, R0
,
2608 write_zsreg(zs_soft
[channel
].zs_channel
, R0
,
2613 for (info
= zs_chain
, i
=0; info
; info
= info
->zs_next
, i
++) {
2614 info
->magic
= SERIAL_MAGIC
;
2615 info
->port
= (long) info
->zs_channel
;
2618 info
->irq
= zilog_irq
;
2619 info
->custom_divisor
= 16;
2620 info
->close_delay
= 50;
2621 info
->closing_wait
= 3000;
2625 info
->blocked_open
= 0;
2626 info
->tqueue
.routine
= do_softint
;
2627 info
->tqueue
.data
= info
;
2628 info
->tqueue_hangup
.routine
= do_serial_hangup
;
2629 info
->tqueue_hangup
.data
= info
;
2630 info
->callout_termios
= callout_driver
.init_termios
;
2631 info
->normal_termios
= serial_driver
.init_termios
;
2632 init_waitqueue_head(&info
->open_wait
);
2633 init_waitqueue_head(&info
->close_wait
);
2634 printk("tty%02d at 0x%04x (irq = %s)", info
->line
,
2635 info
->port
, __irq_itoa(info
->irq
));
2636 printk(" is a Zilog8530\n");
2639 restore_flags(flags
);
2641 keyboard_zsinit(kbd_put_char
);
2645 /* This is called at boot time to prime the kgdb serial debugging
2646 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2647 * for /dev/ttyb which is determined in setup_arch() from the
2648 * boot command line flags.
2650 static void __init
zs_kgdb_hook(int tty_num
)
2654 if(!zs_chips
[chip
]) {
2655 zs_chips
[chip
] = get_zs(chip
);
2656 /* Two channels per chip */
2657 zs_channels
[(chip
*2)] = &zs_chips
[chip
]->channelA
;
2658 zs_channels
[(chip
*2)+1] = &zs_chips
[chip
]->channelB
;
2660 zs_soft
[tty_num
].zs_channel
= zs_channels
[tty_num
];
2661 zs_kgdbchan
= zs_soft
[tty_num
].zs_channel
;
2662 zs_soft
[tty_num
].change_needed
= 0;
2663 zs_soft
[tty_num
].clk_divisor
= 16;
2664 zs_soft
[tty_num
].zs_baud
= 9600;
2665 zs_soft
[tty_num
].kgdb_channel
= 1; /* This runs kgdb */
2666 zs_soft
[tty_num
^ 1].kgdb_channel
= 0; /* This does not */
2667 /* Turn on transmitter/receiver at 8-bits/char */
2668 kgdb_chaninit(&zs_soft
[tty_num
], 0, 9600);
2669 ZS_CLEARERR(zs_kgdbchan
);
2670 ZS_CLEARFIFO(zs_kgdbchan
);
2673 #ifdef CONFIG_SERIAL_CONSOLE
2675 /* This is for console output over ttya/ttyb */
2677 zs_console_putchar(struct sun_serial
*info
, char ch
)
2679 int loops
= ZS_PUT_CHAR_MAX_DELAY
;
2680 unsigned long flags
;
2682 if(!info
->zs_channel
)
2685 save_flags(flags
); cli();
2686 zs_put_char(info
->zs_channel
, ch
);
2687 while (!(read_zsreg(info
->zs_channel
, R1
) & ALL_SNT
) && --loops
)
2689 restore_flags(flags
);
2692 #ifdef SERIAL_CONSOLE_FAIR_OUTPUT
2694 * Fair output driver allows a process to speak.
2696 static void zs_fair_output(struct sun_serial
*info
)
2698 unsigned long flags
;
2699 int left
; /* Output no more than that */
2704 if (info
->xmit_buf
== NULL
)
2707 save_flags(flags
); cli();
2708 left
= info
->xmit_cnt
;
2710 c
= info
->xmit_buf
[info
->xmit_tail
];
2711 info
->xmit_tail
= (info
->xmit_tail
+1) & (SERIAL_XMIT_SIZE
-1);
2713 restore_flags(flags
);
2715 zs_console_putchar(info
, c
);
2718 left
= MIN(info
->xmit_cnt
, left
-1);
2721 /* Last character is being transmitted now (hopefully). */
2722 sbus_writeb(RES_Tx_P
, &info
->zs_channel
->control
);
2724 ZSLOG(REGCTRL
, RES_Tx_P
, 1);
2726 restore_flags(flags
);
2732 * zs_console_write is registered for printk.
2735 zs_console_write(struct console
*con
, const char *s
, unsigned count
)
2737 struct sun_serial
*info
;
2740 info
= zs_soft
+ con
->index
;
2742 for (i
= 0; i
< count
; i
++, s
++) {
2744 zs_console_putchar(info
, '\r');
2745 zs_console_putchar(info
, *s
);
2747 #ifdef SERIAL_CONSOLE_FAIR_OUTPUT
2748 /* Comment this if you want to have a strict interrupt-driven output */
2749 zs_fair_output(info
);
2754 zs_console_wait_key(struct console
*con
)
2756 sleep_on(&keypress_wait
);
2760 static kdev_t
zs_console_device(struct console
*con
)
2762 return MKDEV(TTY_MAJOR
, 64 + con
->index
);
2765 static int __init
zs_console_setup(struct console
*con
, char *options
)
2767 struct sun_serial
*info
;
2770 info
= zs_soft
+ con
->index
;
2773 printk("Console: ttyS%d (Zilog8530)\n", info
->line
);
2775 sunserial_console_termios(con
);
2777 i
= con
->cflag
& CBAUD
;
2778 if (con
->cflag
& CBAUDEX
) {
2780 con
->cflag
&= ~CBAUDEX
;
2782 baud
= baud_table
[i
];
2783 info
->zs_baud
= baud
;
2785 switch (con
->cflag
& CSIZE
) {
2787 zscons_regs
[3] = Rx5
| RxENAB
;
2788 zscons_regs
[5] = Tx5
| TxENAB
;
2789 info
->parity_mask
= 0x1f;
2792 zscons_regs
[3] = Rx6
| RxENAB
;
2793 zscons_regs
[5] = Tx6
| TxENAB
;
2794 info
->parity_mask
= 0x3f;
2797 zscons_regs
[3] = Rx7
| RxENAB
;
2798 zscons_regs
[5] = Tx7
| TxENAB
;
2799 info
->parity_mask
= 0x7f;
2803 zscons_regs
[3] = Rx8
| RxENAB
;
2804 zscons_regs
[5] = Tx8
| TxENAB
;
2805 info
->parity_mask
= 0xff;
2808 zscons_regs
[5] |= DTR
;
2810 if (con
->cflag
& PARENB
)
2811 zscons_regs
[4] |= PAR_ENAB
;
2812 if (!(con
->cflag
& PARODD
))
2813 zscons_regs
[4] |= PAR_EVEN
;
2815 if (con
->cflag
& CSTOPB
)
2816 zscons_regs
[4] |= SB2
;
2818 zscons_regs
[4] |= SB1
;
2820 brg
= BPS_TO_BRG(baud
, ZS_CLOCK
/ info
->clk_divisor
);
2821 zscons_regs
[12] = brg
& 0xff;
2822 zscons_regs
[13] = (brg
>> 8) & 0xff;
2824 memcpy(info
->curregs
, zscons_regs
, sizeof(zscons_regs
));
2825 load_zsregs(info
, zscons_regs
);
2827 ZS_CLEARERR(info
->zs_channel
);
2828 ZS_CLEARFIFO(info
->zs_channel
);
2832 static struct console zs_console
= {
2834 write
: zs_console_write
,
2835 device
: zs_console_device
,
2836 wait_key
: zs_console_wait_key
,
2837 setup
: zs_console_setup
,
2838 flags
: CON_PRINTBUFFER
,
2842 static int __init
zs_console_init(void)
2844 extern int con_is_present(void);
2846 if (con_is_present())
2849 zs_console
.index
= serial_console
- 1;
2850 register_console(&zs_console
);
2854 #endif /* CONFIG_SERIAL_CONSOLE */