2 * decserial.c: Serial port driver for IOASIC DECsatations.
4 * Derived from drivers/macintosh/macserial.c by Harald Koerfgen.
5 * Derived from drivers/sbus/char/sunserial.c by Paul Mackerras.
8 * Copyright (C) 1998 Harald Koerfgen (Harald.Koerfgen@home.ivm.de)
10 * For the rest of the code the original Copyright applies:
11 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
12 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
14 * Keyboard and mouse are not supported right now. If you want to change this,
15 * you might want to have a look at drivers/sbus/char/sunserial.c to see
16 * how this might be done. HK
19 #include <linux/config.h>
20 #include <linux/errno.h>
21 #include <linux/signal.h>
22 #include <linux/sched.h>
23 #include <linux/timer.h>
24 #include <linux/interrupt.h>
25 #include <linux/tty.h>
26 #include <linux/tty_flip.h>
27 #include <linux/major.h>
28 #include <linux/string.h>
29 #include <linux/fcntl.h>
31 #include <linux/kernel.h>
32 #include <linux/delay.h>
33 #include <linux/init.h>
34 #ifdef CONFIG_SERIAL_CONSOLE
35 #include <linux/console.h>
39 #include <asm/pgtable.h>
41 #include <asm/system.h>
42 #include <asm/segment.h>
43 #include <asm/bitops.h>
44 #include <asm/uaccess.h>
45 #include <asm/wbflush.h>
46 #include <asm/dec/interrupts.h>
47 #include <asm/dec/machtype.h>
48 #include <asm/dec/tc.h>
49 #include <asm/dec/ioasic_addrs.h>
58 * It would be nice to dynamically allocate everything that
59 * depends on NUM_SERIAL, so we could support any number of
60 * Z8530s, but for now...
62 #define NUM_SERIAL 2 /* Max number of ZS chips supported */
63 #define NUM_CHANNELS (NUM_SERIAL * 2) /* 2 channels per chip */
65 #define RECOVERY_DELAY udelay(2)
67 struct dec_zschannel zs_channels
[NUM_CHANNELS
];
69 struct dec_serial zs_soft
[NUM_CHANNELS
];
70 int zs_channels_found
;
71 struct dec_serial
*zs_chain
; /* list of all channels */
73 struct tty_struct zs_ttys
[NUM_CHANNELS
];
75 #ifdef CONFIG_SERIAL_CONSOLE
76 static struct console sercons
;
80 struct dec_zschannel
*zs_kgdbchan
;
81 static unsigned char scc_inittab
[] = {
82 9, 0x80, /* reset A side (CHRA) */
83 13, 0, /* set baud rate divisor */
85 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
86 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
87 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
88 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
89 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
93 static unsigned char zs_init_regs
[16] __initdata
= {
98 (X16CLK
| SB1
), /* write 4 */
100 0, 0, 0, /* write 6, 7, 8 */
102 (NRZ
), /* write 10 */
103 (TCBR
| RCBR
), /* write 11 */
104 0, 0, /* BRG time constant, write 12 + 13 */
105 (BRSRC
| BRENABL
), /* write 14 */
109 #define ZS_CLOCK 7372800 /* Z8530 RTxC input clock rate */
111 DECLARE_TASK_QUEUE(tq_zs_serial
);
113 struct tty_driver serial_driver
, callout_driver
;
114 static int serial_refcount
;
116 /* serial subtype definitions */
117 #define SERIAL_TYPE_NORMAL 1
118 #define SERIAL_TYPE_CALLOUT 2
120 /* number of characters left in xmit buffer before we ask for more */
121 #define WAKEUP_CHARS 256
126 #undef SERIAL_DEBUG_INTR
127 #undef SERIAL_DEBUG_OPEN
128 #undef SERIAL_DEBUG_FLOW
129 #undef SERIAL_DEBUG_THROTTLE
130 #undef SERIAL_PARANOIA_CHECK
132 #define RS_STROBE_TIME 10
133 #define RS_ISR_PASS_LIMIT 256
135 #define _INLINE_ inline
137 static void probe_sccs(void);
138 static void change_speed(struct dec_serial
*info
);
139 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
141 static struct tty_struct
*serial_table
[NUM_CHANNELS
];
142 static struct termios
*serial_termios
[NUM_CHANNELS
];
143 static struct termios
*serial_termios_locked
[NUM_CHANNELS
];
146 #define MIN(a,b) ((a) < (b) ? (a) : (b))
150 * tmp_buf is used as a temporary buffer by serial_write. We need to
151 * lock it in case the copy_from_user blocks while swapping in a page,
152 * and some other program tries to do a serial write at the same time.
153 * Since the lock will only come under contention when the system is
154 * swapping and available memory is low, it makes sense to share one
155 * buffer across all the serial ports, since it significantly saves
156 * memory if large numbers of serial ports are open.
158 static unsigned char tmp_buf
[4096]; /* This is cheating */
159 static DECLARE_MUTEX(tmp_buf_sem
);
161 static inline int serial_paranoia_check(struct dec_serial
*info
,
162 dev_t device
, const char *routine
)
164 #ifdef SERIAL_PARANOIA_CHECK
165 static const char *badmagic
=
166 "Warning: bad magic number for serial struct (%d, %d) in %s\n";
167 static const char *badinfo
=
168 "Warning: null mac_serial for (%d, %d) in %s\n";
171 printk(badinfo
, MAJOR(device
), MINOR(device
), routine
);
174 if (info
->magic
!= SERIAL_MAGIC
) {
175 printk(badmagic
, MAJOR(device
), MINOR(device
), routine
);
183 * This is used to figure out the divisor speeds and the timeouts
185 static int baud_table
[] = {
186 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
187 9600, 19200, 38400, 57600, 0, 0 };
190 * Reading and writing Z8530 registers.
192 static inline unsigned char read_zsreg(struct dec_zschannel
*channel
,
195 unsigned char retval
;
198 *channel
->control
= reg
& 0xf;
199 wbflush(); RECOVERY_DELAY
;
201 retval
= *channel
->control
;
206 static inline void write_zsreg(struct dec_zschannel
*channel
,
207 unsigned char reg
, unsigned char value
)
210 *channel
->control
= reg
& 0xf;
211 wbflush(); RECOVERY_DELAY
;
213 *channel
->control
= value
;
214 wbflush(); RECOVERY_DELAY
;
218 static inline unsigned char read_zsdata(struct dec_zschannel
*channel
)
220 unsigned char retval
;
222 retval
= *channel
->data
;
227 static inline void write_zsdata(struct dec_zschannel
*channel
,
230 *channel
->data
= value
;
231 wbflush(); RECOVERY_DELAY
;
235 static inline void load_zsregs(struct dec_zschannel
*channel
,
238 /* ZS_CLEARERR(channel);
239 ZS_CLEARFIFO(channel); */
241 write_zsreg(channel
, R4
, regs
[R4
]);
242 write_zsreg(channel
, R3
, regs
[R3
] & ~RxENABLE
);
243 write_zsreg(channel
, R5
, regs
[R5
] & ~TxENAB
);
244 write_zsreg(channel
, R9
, regs
[R9
]);
245 write_zsreg(channel
, R1
, regs
[R1
]);
246 write_zsreg(channel
, R2
, regs
[R2
]);
247 write_zsreg(channel
, R10
, regs
[R10
]);
248 write_zsreg(channel
, R11
, regs
[R11
]);
249 write_zsreg(channel
, R12
, regs
[R12
]);
250 write_zsreg(channel
, R13
, regs
[R13
]);
251 write_zsreg(channel
, R14
, regs
[R14
]);
252 write_zsreg(channel
, R15
, regs
[R15
]);
253 write_zsreg(channel
, R3
, regs
[R3
]);
254 write_zsreg(channel
, R5
, regs
[R5
]);
258 /* Sets or clears DTR/RTS on the requested line */
259 static inline void zs_rtsdtr(struct dec_serial
*ss
, int set
)
261 if (ss
->zs_channel
!= ss
->zs_chan_a
) {
263 ss
->zs_chan_a
->curregs
[5] |= (RTS
| DTR
);
265 ss
->zs_chan_a
->curregs
[5] &= ~(RTS
| DTR
);
266 write_zsreg(ss
->zs_chan_a
, 5, ss
->zs_chan_a
->curregs
[5]);
271 /* Utility routines for the Zilog */
272 static inline int get_zsbaud(struct dec_serial
*ss
)
274 struct dec_zschannel
*channel
= ss
->zs_channel
;
277 /* The baud rate is split up between two 8-bit registers in
278 * what is termed 'BRG time constant' format in my docs for
279 * the chip, it is a function of the clk rate the chip is
280 * receiving which happens to be constant.
282 brg
= (read_zsreg(channel
, 13) << 8);
283 brg
|= read_zsreg(channel
, 12);
284 return BRG_TO_BPS(brg
, (ZS_CLOCK
/(ss
->clk_divisor
)));
287 /* On receive, this clears errors and the receiver interrupts */
288 static inline void rs_recv_clear(struct dec_zschannel
*zsc
)
290 write_zsreg(zsc
, 0, ERR_RES
);
291 write_zsreg(zsc
, 0, RES_H_IUS
); /* XXX this is unnecessary */
295 * ----------------------------------------------------------------------
297 * Here starts the interrupt handling routines. All of the following
298 * subroutines are declared as inline and are folded into
299 * rs_interrupt(). They were separated out for readability's sake.
301 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
302 * -----------------------------------------------------------------------
306 * This routine is used by the interrupt handler to schedule
307 * processing in the software interrupt portion of the driver.
309 static _INLINE_
void rs_sched_event(struct dec_serial
*info
,
312 info
->event
|= 1 << event
;
313 queue_task(&info
->tqueue
, &tq_zs_serial
);
317 static _INLINE_
void receive_chars(struct dec_serial
*info
,
318 struct pt_regs
*regs
)
320 struct tty_struct
*tty
= info
->tty
;
321 unsigned char ch
, stat
, flag
;
323 while ((read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
) != 0) {
325 stat
= read_zsreg(info
->zs_channel
, R1
);
326 ch
= read_zsdata(info
->zs_channel
);
329 if (info
->kgdb_channel
) {
330 if (ch
== 0x03 || ch
== '$')
332 if (stat
& (Rx_OVR
|FRM_ERR
|PAR_ERR
))
333 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
340 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
341 static int flip_buf_ovf
;
347 static int flip_max_cnt
;
348 if (flip_max_cnt
< tty
->flip
.count
)
349 flip_max_cnt
= tty
->flip
.count
;
353 } else if (stat
& FRM_ERR
) {
355 } else if (stat
& PAR_ERR
) {
360 /* reset the error indication */
361 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
362 *tty
->flip
.flag_buf_ptr
++ = flag
;
363 *tty
->flip
.char_buf_ptr
++ = ch
;
365 tty_flip_buffer_push(tty
);
368 static void transmit_chars(struct dec_serial
*info
)
370 if ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
) == 0)
376 write_zsdata(info
->zs_channel
, info
->x_char
);
382 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
|| info
->tx_stopped
) {
383 write_zsreg(info
->zs_channel
, 0, RES_Tx_P
);
387 write_zsdata(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
388 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
392 if (info
->xmit_cnt
< WAKEUP_CHARS
)
393 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
396 static _INLINE_
void status_handle(struct dec_serial
*info
)
398 unsigned char status
;
400 /* Get status from Read Register 0 */
401 status
= read_zsreg(info
->zs_channel
, 0);
403 /* FIXEM: Check for DCD transitions */
404 if (((status
^ info
->read_reg_zero
) & DCD
) != 0
405 && info
->tty
&& !C_CLOCAL(info
->tty
)) {
407 wake_up_interruptible(&info
->open_wait
);
408 } else if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
)) {
410 tty_hangup(info
->tty
);
414 /* Check for CTS transitions */
415 if (info
->tty
&& C_CRTSCTS(info
->tty
)) {
417 * For some reason, on the Power Macintosh,
418 * it seems that the CTS bit is 1 when CTS is
419 * *negated* and 0 when it is asserted.
420 * The DCD bit doesn't seem to be inverted
423 if ((status
& CTS
) != 0) {
424 if (info
->tx_stopped
) {
425 info
->tx_stopped
= 0;
426 if (!info
->tx_active
)
427 transmit_chars(info
);
430 info
->tx_stopped
= 1;
434 /* Clear status condition... */
435 write_zsreg(info
->zs_channel
, 0, RES_EXT_INT
);
436 info
->read_reg_zero
= status
;
440 * This is the serial driver's generic interrupt routine
442 void rs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
444 struct dec_serial
*info
= (struct dec_serial
*) dev_id
;
445 unsigned char zs_intreg
;
448 /* NOTE: The read register 3, which holds the irq status,
449 * does so for both channels on each chip. Although
450 * the status value itself must be read from the A
451 * channel and is only valid when read from channel A.
452 * Yes... broken hardware...
454 #define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
456 if (info
->zs_chan_a
== info
->zs_channel
)
457 shift
= 3; /* Channel A */
459 shift
= 0; /* Channel B */
462 zs_intreg
= read_zsreg(info
->zs_chan_a
, 3) >> shift
;
463 if ((zs_intreg
& CHAN_IRQMASK
) == 0)
466 if (zs_intreg
& CHBRxIP
) {
467 receive_chars(info
, regs
);
469 if (zs_intreg
& CHBTxIP
) {
470 transmit_chars(info
);
472 if (zs_intreg
& CHBEXT
) {
479 * -------------------------------------------------------------------
480 * Here ends the serial interrupt routines.
481 * -------------------------------------------------------------------
485 * ------------------------------------------------------------
486 * rs_stop() and rs_start()
488 * This routines are called before setting or resetting tty->stopped.
489 * ------------------------------------------------------------
491 static void rs_stop(struct tty_struct
*tty
)
493 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
496 if (serial_paranoia_check(info
, tty
->device
, "rs_stop"))
500 save_flags(flags
); cli();
501 if (info
->zs_channel
->curregs
[5] & TxENAB
) {
502 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
503 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
505 restore_flags(flags
);
509 static void rs_start(struct tty_struct
*tty
)
511 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
514 if (serial_paranoia_check(info
, tty
->device
, "rs_start"))
517 save_flags(flags
); cli();
519 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->zs_channel
->curregs
[5] & TxENAB
)) {
520 info
->zs_channel
->curregs
[5] |= TxENAB
;
521 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
524 if (info
->xmit_cnt
&& info
->xmit_buf
&& !info
->tx_active
) {
525 transmit_chars(info
);
528 restore_flags(flags
);
532 * This routine is used to handle the "bottom half" processing for the
533 * serial driver, known also the "software interrupt" processing.
534 * This processing is done at the kernel interrupt level, after the
535 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
536 * is where time-consuming activities which can not be done in the
537 * interrupt driver proper are done; the interrupt driver schedules
538 * them using rs_sched_event(), and they get done here.
540 static void do_serial_bh(void)
542 run_task_queue(&tq_zs_serial
);
545 static void do_softint(void *private_
)
547 struct dec_serial
*info
= (struct dec_serial
*) private_
;
548 struct tty_struct
*tty
;
554 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
555 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
556 tty
->ldisc
.write_wakeup
)
557 (tty
->ldisc
.write_wakeup
)(tty
);
558 wake_up_interruptible(&tty
->write_wait
);
562 static int startup(struct dec_serial
* info
)
566 if (info
->flags
& ZILOG_INITIALIZED
)
569 if (!info
->xmit_buf
) {
570 info
->xmit_buf
= (unsigned char *) get_free_page(GFP_KERNEL
);
575 save_flags(flags
); cli();
577 #ifdef SERIAL_DEBUG_OPEN
578 printk("starting up ttyS%d (irq %d)...", info
->line
, info
->irq
);
582 * Clear the receive FIFO.
584 ZS_CLEARFIFO(info
->zs_channel
);
585 info
->xmit_fifo_size
= 1;
588 * Clear the interrupt registers.
590 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
591 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
594 * Turn on RTS and DTR.
599 * Finally, enable sequencing and interrupts
601 info
->zs_channel
->curregs
[1] = (info
->zs_channel
->curregs
[1] & ~0x18) | (EXT_INT_ENAB
| INT_ALL_Rx
| TxINT_ENAB
);
602 info
->zs_channel
->curregs
[3] |= (RxENABLE
| Rx8
);
603 info
->zs_channel
->curregs
[5] |= (TxENAB
| Tx8
);
604 info
->zs_channel
->curregs
[15] |= (DCDIE
| CTSIE
| TxUIE
| BRKIE
);
605 info
->zs_channel
->curregs
[9] |= (VIS
| MIE
);
606 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]);
607 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
608 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
609 write_zsreg(info
->zs_channel
, 15, info
->zs_channel
->curregs
[15]);
610 write_zsreg(info
->zs_channel
, 9, info
->zs_channel
->curregs
[9]);
613 * And clear the interrupt registers again for luck.
615 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
616 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
619 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
620 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
623 * Set the speed of the serial port
627 /* Save the current value of RR0 */
628 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
630 info
->flags
|= ZILOG_INITIALIZED
;
631 restore_flags(flags
);
636 * This routine will shutdown a serial port; interrupts are disabled, and
637 * DTR is dropped if the hangup on close termio flag is on.
639 static void shutdown(struct dec_serial
* info
)
643 if (!(info
->flags
& ZILOG_INITIALIZED
))
646 #ifdef SERIAL_DEBUG_OPEN
647 printk("Shutting down serial port %d (irq %d)....", info
->line
,
651 save_flags(flags
); cli(); /* Disable interrupts */
653 if (info
->xmit_buf
) {
654 free_page((unsigned long) info
->xmit_buf
);
658 info
->zs_channel
->curregs
[1] = 0;
659 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]); /* no interrupts */
661 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
662 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
664 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
665 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
666 if (!info
->tty
|| C_HUPCL(info
->tty
)) {
667 info
->zs_chan_a
->curregs
[5] &= ~(DTR
| RTS
);
668 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
672 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
674 info
->flags
&= ~ZILOG_INITIALIZED
;
675 restore_flags(flags
);
679 * This routine is called to set the UART divisor registers to match
680 * the specified baud rate for a serial port.
682 static void change_speed(struct dec_serial
*info
)
690 if (!info
->tty
|| !info
->tty
->termios
)
692 cflag
= info
->tty
->termios
->c_cflag
;
693 if (!(port
= info
->port
))
697 save_flags(flags
); cli();
698 info
->zs_baud
= baud_table
[i
];
699 info
->clk_divisor
= 16;
701 switch (info
->zs_baud
) {
703 info
->zs_channel
->curregs
[4] = X16CLK
;
704 brg
= BPS_TO_BRG(info
->zs_baud
, ZS_CLOCK
/info
->clk_divisor
);
705 info
->zs_channel
->curregs
[12] = (brg
& 255);
706 info
->zs_channel
->curregs
[13] = ((brg
>> 8) & 255);
709 /* byte size and parity */
710 info
->zs_channel
->curregs
[3] &= ~RxNBITS_MASK
;
711 info
->zs_channel
->curregs
[5] &= ~TxNBITS_MASK
;
712 switch (cflag
& CSIZE
) {
714 info
->zs_channel
->curregs
[3] |= Rx5
;
715 info
->zs_channel
->curregs
[5] |= Tx5
;
718 info
->zs_channel
->curregs
[3] |= Rx6
;
719 info
->zs_channel
->curregs
[5] |= Tx6
;
722 info
->zs_channel
->curregs
[3] |= Rx7
;
723 info
->zs_channel
->curregs
[5] |= Tx7
;
726 default: /* defaults to 8 bits */
727 info
->zs_channel
->curregs
[3] |= Rx8
;
728 info
->zs_channel
->curregs
[5] |= Tx8
;
732 info
->zs_channel
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
733 if (cflag
& CSTOPB
) {
734 info
->zs_channel
->curregs
[4] |= SB2
;
736 info
->zs_channel
->curregs
[4] |= SB1
;
738 if (cflag
& PARENB
) {
739 info
->zs_channel
->curregs
[4] |= PAR_ENA
;
741 if (!(cflag
& PARODD
)) {
742 info
->zs_channel
->curregs
[4] |= PAR_EVEN
;
745 if (!(cflag
& CLOCAL
)) {
746 if (!(info
->zs_channel
->curregs
[15] & DCDIE
))
747 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
748 info
->zs_channel
->curregs
[15] |= DCDIE
;
750 info
->zs_channel
->curregs
[15] &= ~DCDIE
;
751 if (cflag
& CRTSCTS
) {
752 info
->zs_channel
->curregs
[15] |= CTSIE
;
753 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) != 0)
754 info
->tx_stopped
= 1;
756 info
->zs_channel
->curregs
[15] &= ~CTSIE
;
757 info
->tx_stopped
= 0;
760 /* Load up the new values */
761 load_zsregs(info
->zs_channel
, info
->zs_channel
->curregs
);
763 restore_flags(flags
);
766 static void rs_flush_chars(struct tty_struct
*tty
)
768 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
771 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_chars"))
774 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| info
->tx_stopped
||
778 /* Enable transmitter */
779 save_flags(flags
); cli();
780 transmit_chars(info
);
781 restore_flags(flags
);
784 static int rs_write(struct tty_struct
* tty
, int from_user
,
785 const unsigned char *buf
, int count
)
788 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
791 if (serial_paranoia_check(info
, tty
->device
, "rs_write"))
794 if (!tty
|| !info
->xmit_buf
)
800 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
801 SERIAL_XMIT_SIZE
- info
->xmit_head
));
807 copy_from_user(tmp_buf
, buf
, c
);
808 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
809 SERIAL_XMIT_SIZE
- info
->xmit_head
));
810 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
813 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
814 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
816 restore_flags(flags
);
822 if (info
->xmit_cnt
&& !tty
->stopped
&& !info
->tx_stopped
824 transmit_chars(info
);
825 restore_flags(flags
);
829 static int rs_write_room(struct tty_struct
*tty
)
831 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
834 if (serial_paranoia_check(info
, tty
->device
, "rs_write_room"))
836 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
842 static int rs_chars_in_buffer(struct tty_struct
*tty
)
844 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
846 if (serial_paranoia_check(info
, tty
->device
, "rs_chars_in_buffer"))
848 return info
->xmit_cnt
;
851 static void rs_flush_buffer(struct tty_struct
*tty
)
853 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
855 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_buffer"))
858 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
860 wake_up_interruptible(&tty
->write_wait
);
861 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
862 tty
->ldisc
.write_wakeup
)
863 (tty
->ldisc
.write_wakeup
)(tty
);
867 * ------------------------------------------------------------
870 * This routine is called by the upper-layer tty layer to signal that
871 * incoming characters should be throttled.
872 * ------------------------------------------------------------
874 static void rs_throttle(struct tty_struct
* tty
)
876 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
879 #ifdef SERIAL_DEBUG_THROTTLE
882 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
883 tty
->ldisc
.chars_in_buffer(tty
));
886 if (serial_paranoia_check(info
, tty
->device
, "rs_throttle"))
890 save_flags(flags
); cli();
891 info
->x_char
= STOP_CHAR(tty
);
892 if (!info
->tx_active
)
893 transmit_chars(info
);
894 restore_flags(flags
);
897 if (C_CRTSCTS(tty
)) {
899 * Here we want to turn off the RTS line. On Macintoshes,
900 * we only get the DTR line, which goes to both DTR and
901 * RTS on the modem. RTS doesn't go out to the serial
902 * port socket. So you should make sure your modem is
903 * set to ignore DTR if you're using CRTSCTS.
905 save_flags(flags
); cli();
906 info
->zs_chan_a
->curregs
[5] &= ~(DTR
| RTS
);
907 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
908 restore_flags(flags
);
912 static void rs_unthrottle(struct tty_struct
* tty
)
914 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
917 #ifdef SERIAL_DEBUG_THROTTLE
920 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
921 tty
->ldisc
.chars_in_buffer(tty
));
924 if (serial_paranoia_check(info
, tty
->device
, "rs_unthrottle"))
928 save_flags(flags
); cli();
932 info
->x_char
= START_CHAR(tty
);
933 if (!info
->tx_active
)
934 transmit_chars(info
);
936 restore_flags(flags
);
939 if (C_CRTSCTS(tty
)) {
940 /* Assert RTS and DTR lines */
941 save_flags(flags
); cli();
942 info
->zs_chan_a
->curregs
[5] |= DTR
| RTS
;
943 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
944 restore_flags(flags
);
949 * ------------------------------------------------------------
950 * rs_ioctl() and friends
951 * ------------------------------------------------------------
954 static int get_serial_info(struct dec_serial
* info
,
955 struct serial_struct
* retinfo
)
957 struct serial_struct tmp
;
961 memset(&tmp
, 0, sizeof(tmp
));
962 tmp
.type
= info
->type
;
963 tmp
.line
= info
->line
;
964 tmp
.port
= info
->port
;
966 tmp
.flags
= info
->flags
;
967 tmp
.baud_base
= info
->baud_base
;
968 tmp
.close_delay
= info
->close_delay
;
969 tmp
.closing_wait
= info
->closing_wait
;
970 tmp
.custom_divisor
= info
->custom_divisor
;
971 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
));
974 static int set_serial_info(struct dec_serial
* info
,
975 struct serial_struct
* new_info
)
977 struct serial_struct new_serial
;
978 struct dec_serial old_info
;
983 copy_from_user(&new_serial
,new_info
,sizeof(new_serial
));
987 if ((new_serial
.baud_base
!= info
->baud_base
) ||
988 (new_serial
.type
!= info
->type
) ||
989 (new_serial
.close_delay
!= info
->close_delay
) ||
990 ((new_serial
.flags
& ~ZILOG_USR_MASK
) !=
991 (info
->flags
& ~ZILOG_USR_MASK
)))
993 info
->flags
= ((info
->flags
& ~ZILOG_USR_MASK
) |
994 (new_serial
.flags
& ZILOG_USR_MASK
));
995 info
->custom_divisor
= new_serial
.custom_divisor
;
1003 * OK, past this point, all the error checking has been done.
1004 * At this point, we start making changes.....
1007 info
->baud_base
= new_serial
.baud_base
;
1008 info
->flags
= ((info
->flags
& ~ZILOG_FLAGS
) |
1009 (new_serial
.flags
& ZILOG_FLAGS
));
1010 info
->type
= new_serial
.type
;
1011 info
->close_delay
= new_serial
.close_delay
;
1012 info
->closing_wait
= new_serial
.closing_wait
;
1015 retval
= startup(info
);
1020 * get_lsr_info - get line status register info
1022 * Purpose: Let user call ioctl() to get info when the UART physically
1023 * is emptied. On bus types like RS485, the transmitter must
1024 * release the bus after transmitting. This must be done when
1025 * the transmit shift register is empty, not be done when the
1026 * transmit holding register is empty. This functionality
1027 * allows an RS485 driver to be written in user space.
1029 static int get_lsr_info(struct dec_serial
* info
, unsigned int *value
)
1031 unsigned char status
;
1034 status
= read_zsreg(info
->zs_channel
, 0);
1036 put_user(status
,value
);
1040 static int get_modem_info(struct dec_serial
*info
, unsigned int *value
)
1042 unsigned char control
, status
;
1043 unsigned int result
;
1046 control
= info
->zs_chan_a
->curregs
[5];
1047 status
= read_zsreg(info
->zs_channel
, 0);
1049 result
= ((control
& RTS
) ? TIOCM_RTS
: 0)
1050 | ((control
& DTR
) ? TIOCM_DTR
: 0)
1051 | ((status
& DCD
) ? TIOCM_CAR
: 0)
1052 | ((status
& CTS
) ? 0: TIOCM_CTS
);
1053 put_user(result
,value
);
1057 static int set_modem_info(struct dec_serial
*info
, unsigned int cmd
,
1058 unsigned int *value
)
1061 unsigned int arg
, bits
;
1063 error
= verify_area(VERIFY_READ
, value
, sizeof(int));
1066 get_user(arg
, value
);
1067 bits
= (arg
& TIOCM_RTS
? RTS
: 0) + (arg
& TIOCM_DTR
? DTR
: 0);
1071 info
->zs_chan_a
->curregs
[5] |= bits
;
1074 info
->zs_chan_a
->curregs
[5] &= ~bits
;
1077 info
->zs_chan_a
->curregs
[5] = (info
->zs_chan_a
->curregs
[5] & ~(DTR
| RTS
)) | bits
;
1083 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
1089 * rs_break - turn transmit break condition on/off
1091 static void rs_break(struct tty_struct
*tty
, int break_state
)
1093 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1094 unsigned long flags
;
1096 if (serial_paranoia_check(info
, tty
->device
, "rs_break"))
1101 save_flags(flags
); cli();
1102 if (break_state
== -1)
1103 info
->zs_channel
->curregs
[5] |= SND_BRK
;
1105 info
->zs_channel
->curregs
[5] &= ~SND_BRK
;
1106 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
1107 restore_flags(flags
);
1110 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1111 unsigned int cmd
, unsigned long arg
)
1114 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1117 if (info
->kgdb_channel
)
1120 if (serial_paranoia_check(info
, tty
->device
, "rs_ioctl"))
1123 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1124 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1125 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1126 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1132 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1133 sizeof(unsigned int));
1136 return get_modem_info(info
, (unsigned int *) arg
);
1140 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1142 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1143 sizeof(struct serial_struct
));
1146 return get_serial_info(info
,
1147 (struct serial_struct
*) arg
);
1149 return set_serial_info(info
,
1150 (struct serial_struct
*) arg
);
1151 case TIOCSERGETLSR
: /* Get line status register */
1152 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1153 sizeof(unsigned int));
1157 return get_lsr_info(info
, (unsigned int *) arg
);
1159 case TIOCSERGSTRUCT
:
1160 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1161 sizeof(struct dec_serial
));
1164 copy_from_user((struct dec_serial
*) arg
,
1165 info
, sizeof(struct dec_serial
));
1169 return -ENOIOCTLCMD
;
1174 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1176 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
1179 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1181 was_stopped
= info
->tx_stopped
;
1185 if (was_stopped
&& !info
->tx_stopped
)
1190 * ------------------------------------------------------------
1193 * This routine is called when the serial port gets closed.
1194 * Wait for the last remaining data to be sent.
1195 * ------------------------------------------------------------
1197 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
1199 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1200 unsigned long flags
;
1202 if (!info
|| serial_paranoia_check(info
, tty
->device
, "rs_close"))
1205 save_flags(flags
); cli();
1207 if (tty_hung_up_p(filp
)) {
1208 restore_flags(flags
);
1212 #ifdef SERIAL_DEBUG_OPEN
1213 printk("rs_close ttys%d, count = %d\n", info
->line
, info
->count
);
1215 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1217 * Uh, oh. tty->count is 1, which means that the tty
1218 * structure will be freed. Info->count should always
1219 * be one in these conditions. If it's greater than
1220 * one, we've got real problems, since it means the
1221 * serial port won't be shutdown.
1223 printk("rs_close: bad serial port count; tty->count is 1, "
1224 "info->count is %d\n", info
->count
);
1227 if (--info
->count
< 0) {
1228 printk("rs_close: bad serial port count for ttys%d: %d\n",
1229 info
->line
, info
->count
);
1233 restore_flags(flags
);
1236 info
->flags
|= ZILOG_CLOSING
;
1238 * Save the termios structure, since this port may have
1239 * separate termios for callout and dialin.
1241 if (info
->flags
& ZILOG_NORMAL_ACTIVE
)
1242 info
->normal_termios
= *tty
->termios
;
1243 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
)
1244 info
->callout_termios
= *tty
->termios
;
1246 * Now we wait for the transmit buffer to clear; and we notify
1247 * the line discipline to only process XON/XOFF characters.
1250 if (info
->closing_wait
!= ZILOG_CLOSING_WAIT_NONE
)
1251 tty_wait_until_sent(tty
, info
->closing_wait
);
1253 * At this point we stop accepting input. To do this, we
1254 * disable the receiver and receive interrupts.
1256 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
1257 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
1258 info
->zs_channel
->curregs
[1] = 0; /* disable any rx ints */
1259 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]);
1260 ZS_CLEARFIFO(info
->zs_channel
);
1261 if (info
->flags
& ZILOG_INITIALIZED
) {
1263 * Before we drop DTR, make sure the SCC transmitter
1264 * has completely drained.
1266 rs_wait_until_sent(tty
, info
->timeout
);
1270 if (tty
->driver
.flush_buffer
)
1271 tty
->driver
.flush_buffer(tty
);
1272 if (tty
->ldisc
.flush_buffer
)
1273 tty
->ldisc
.flush_buffer(tty
);
1277 if (info
->blocked_open
) {
1278 if (info
->close_delay
) {
1279 current
->state
= TASK_INTERRUPTIBLE
;
1280 schedule_timeout(info
->close_delay
);
1282 wake_up_interruptible(&info
->open_wait
);
1284 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CALLOUT_ACTIVE
|
1286 wake_up_interruptible(&info
->close_wait
);
1287 restore_flags(flags
);
1291 * rs_wait_until_sent() --- wait until the transmitter is empty
1293 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1295 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1296 unsigned long orig_jiffies
, char_time
;
1298 if (serial_paranoia_check(info
, tty
->device
, "rs_wait_until_sent"))
1301 orig_jiffies
= jiffies
;
1303 * Set the check interval to be 1/5 of the estimated time to
1304 * send a single character, and make it at least 1. The check
1305 * interval should also be less than the timeout.
1307 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1308 char_time
= char_time
/ 5;
1312 char_time
= MIN(char_time
, timeout
);
1313 while ((read_zsreg(info
->zs_channel
, 1) & Tx_BUF_EMP
) == 0) {
1314 current
->state
= TASK_INTERRUPTIBLE
;
1315 schedule_timeout(char_time
);
1316 if (signal_pending(current
))
1318 if (timeout
&& ((orig_jiffies
+ timeout
) < jiffies
))
1321 current
->state
= TASK_RUNNING
;
1325 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1327 void rs_hangup(struct tty_struct
*tty
)
1329 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1331 if (serial_paranoia_check(info
, tty
->device
, "rs_hangup"))
1334 rs_flush_buffer(tty
);
1338 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CALLOUT_ACTIVE
);
1340 wake_up_interruptible(&info
->open_wait
);
1344 * ------------------------------------------------------------
1345 * rs_open() and friends
1346 * ------------------------------------------------------------
1348 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1349 struct dec_serial
*info
)
1351 DECLARE_WAITQUEUE(wait
, current
);
1356 * If the device is in the middle of being closed, then block
1357 * until it's done, and then try again.
1359 if (info
->flags
& ZILOG_CLOSING
) {
1360 interruptible_sleep_on(&info
->close_wait
);
1361 #ifdef SERIAL_DO_RESTART
1362 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1363 -EAGAIN
: -ERESTARTSYS
);
1370 * If this is a callout device, then just make sure the normal
1371 * device isn't being used.
1373 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1374 if (info
->flags
& ZILOG_NORMAL_ACTIVE
)
1376 if ((info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1377 (info
->flags
& ZILOG_SESSION_LOCKOUT
) &&
1378 (info
->session
!= current
->session
))
1380 if ((info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1381 (info
->flags
& ZILOG_PGRP_LOCKOUT
) &&
1382 (info
->pgrp
!= current
->pgrp
))
1384 info
->flags
|= ZILOG_CALLOUT_ACTIVE
;
1389 * If non-blocking mode is set, or the port is not enabled,
1390 * then make the check up front and then exit.
1392 if ((filp
->f_flags
& O_NONBLOCK
) ||
1393 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1394 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
)
1396 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1400 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
) {
1401 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1404 if (tty
->termios
->c_cflag
& CLOCAL
)
1409 * Block waiting for the carrier detect and the line to become
1410 * free (i.e., not in use by the callout). While we are in
1411 * this loop, info->count is dropped by one, so that
1412 * rs_close() knows when to free things. We restore it upon
1413 * exit, either normal or abnormal.
1416 add_wait_queue(&info
->open_wait
, &wait
);
1417 #ifdef SERIAL_DEBUG_OPEN
1418 printk("block_til_ready before block: ttys%d, count = %d\n",
1419 info
->line
, info
->count
);
1422 if (!tty_hung_up_p(filp
))
1425 info
->blocked_open
++;
1428 if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1429 (tty
->termios
->c_cflag
& CBAUD
))
1432 set_current_state(TASK_INTERRUPTIBLE
);
1433 if (tty_hung_up_p(filp
) ||
1434 !(info
->flags
& ZILOG_INITIALIZED
)) {
1435 #ifdef SERIAL_DO_RESTART
1436 if (info
->flags
& ZILOG_HUP_NOTIFY
)
1439 retval
= -ERESTARTSYS
;
1445 if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1446 !(info
->flags
& ZILOG_CLOSING
) &&
1447 (do_clocal
|| (read_zsreg(info
->zs_channel
, 0) & DCD
)))
1449 if (signal_pending(current
)) {
1450 retval
= -ERESTARTSYS
;
1453 #ifdef SERIAL_DEBUG_OPEN
1454 printk("block_til_ready blocking: ttys%d, count = %d\n",
1455 info
->line
, info
->count
);
1459 current
->state
= TASK_RUNNING
;
1460 remove_wait_queue(&info
->open_wait
, &wait
);
1461 if (!tty_hung_up_p(filp
))
1463 info
->blocked_open
--;
1464 #ifdef SERIAL_DEBUG_OPEN
1465 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1466 info
->line
, info
->count
);
1470 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1475 * This routine is called whenever a serial port is opened. It
1476 * enables interrupts for a serial port, linking in its ZILOG structure into
1477 * the IRQ chain. It also performs the serial-specific
1478 * initialization for the tty structure.
1480 int rs_open(struct tty_struct
*tty
, struct file
* filp
)
1482 struct dec_serial
*info
;
1485 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1486 if ((line
< 0) || (line
>= zs_channels_found
))
1488 info
= zs_soft
+ line
;
1491 if (info
->kgdb_channel
)
1494 if (serial_paranoia_check(info
, tty
->device
, "rs_open"))
1496 #ifdef SERIAL_DEBUG_OPEN
1497 printk("rs_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
1502 tty
->driver_data
= info
;
1506 * If the port is the middle of closing, bail out now
1508 if (tty_hung_up_p(filp
) ||
1509 (info
->flags
& ZILOG_CLOSING
)) {
1510 if (info
->flags
& ZILOG_CLOSING
)
1511 interruptible_sleep_on(&info
->close_wait
);
1512 #ifdef SERIAL_DO_RESTART
1513 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1514 -EAGAIN
: -ERESTARTSYS
);
1521 * Start up serial port
1523 retval
= startup(info
);
1527 retval
= block_til_ready(tty
, filp
, info
);
1529 #ifdef SERIAL_DEBUG_OPEN
1530 printk("rs_open returning after block_til_ready with %d\n",
1536 if ((info
->count
== 1) && (info
->flags
& ZILOG_SPLIT_TERMIOS
)) {
1537 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1538 *tty
->termios
= info
->normal_termios
;
1540 *tty
->termios
= info
->callout_termios
;
1543 #ifdef CONFIG_SERIAL_CONSOLE
1544 if (sercons
.cflag
&& sercons
.index
== line
) {
1545 tty
->termios
->c_cflag
= sercons
.cflag
;
1551 info
->session
= current
->session
;
1552 info
->pgrp
= current
->pgrp
;
1554 #ifdef SERIAL_DEBUG_OPEN
1555 printk("rs_open ttys%d successful...", info
->line
);
1557 /* tty->low_latency = 1; */
1561 /* Finally, routines used to initialize the serial driver. */
1563 static void __init
show_serial_version(void)
1565 printk("DECstation Z8530 serial driver version 0.03\n");
1568 /* Initialize Z8530s zs_channels
1571 static void __init
probe_sccs(void)
1573 struct dec_serial
**pp
;
1574 int i
, n
, n_chips
= 0, n_channels
, chip
, channel
;
1577 * did we get here by accident?
1580 printk("Not on JUNKIO machine, skipping probe_sccs\n");
1585 * When serial console is activated, tc_init has not been called yet
1586 * and system_base is undefined. Unfortunately we have to hardcode
1587 * system_base for this case :-(. HK
1589 switch(mips_machtype
) {
1590 case MACH_DS5000_2X0
:
1591 system_base
= 0xbf800000;
1594 case MACH_DS5000_1XX
:
1595 system_base
= 0xbc000000;
1598 case MACH_DS5000_XX
:
1599 system_base
= 0xbc000000;
1608 for (chip
= 0; chip
< n_chips
; chip
++) {
1609 for (channel
= 0; channel
<= 1; channel
++) {
1611 * The sccs reside on the high byte of the 16 bit IOBUS
1613 zs_channels
[n_channels
].control
= (volatile unsigned char *)
1614 system_base
+ (0 == chip
? SCC0
: SCC1
) + (0 == channel
? 1 : 9);
1615 zs_channels
[n_channels
].data
= zs_channels
[n_channels
].control
+ 4;
1616 zs_soft
[n_channels
].zs_channel
= &zs_channels
[n_channels
];
1617 zs_soft
[n_channels
].irq
= SERIAL
;
1620 zs_soft
[n_channels
].zs_chan_a
= &zs_channels
[n_channels
+1];
1622 zs_soft
[n_channels
].zs_chan_a
= &zs_channels
[n_channels
];
1624 *pp
= &zs_soft
[n_channels
];
1625 pp
= &zs_soft
[n_channels
].zs_next
;
1631 zs_channels_found
= n_channels
;
1633 for (n
= 0; n
< zs_channels_found
; n
++) {
1634 for (i
= 0; i
< 16; i
++) {
1635 zs_soft
[n
].zs_channel
->curregs
[i
] = zs_init_regs
[i
];
1639 /* save_and_cli(flags);
1640 for (n = 0; n < zs_channels_found; n++) {
1641 if (((int)zs_channels[n].control & 0xf) == 1) {
1642 write_zsreg(zs_soft[channel].zs_chan_a, R9, FHWRES);
1644 write_zsreg(zs_soft[channel].zs_chan_a, R9, 0);
1646 load_zsregs(zs_soft[n].zs_channel, zs_soft[n].zs_channel->curregs);
1648 restore_flags(flags); */
1651 /* zs_init inits the driver */
1652 int __init
zs_init(void)
1655 unsigned long flags
;
1656 struct dec_serial
*info
;
1661 /* Setup base handler, and timer table. */
1662 init_bh(SERIAL_BH
, do_serial_bh
);
1664 /* Find out how many Z8530 SCCs we have */
1668 show_serial_version();
1670 /* Initialize the tty_driver structure */
1671 /* Not all of this is exactly right for us. */
1673 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
1674 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
1675 serial_driver
.name
= "ttyS";
1676 serial_driver
.major
= TTY_MAJOR
;
1677 serial_driver
.minor_start
= 64;
1678 serial_driver
.num
= zs_channels_found
;
1679 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
1680 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
1681 serial_driver
.init_termios
= tty_std_termios
;
1683 serial_driver
.init_termios
.c_cflag
=
1684 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1685 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
1686 serial_driver
.refcount
= &serial_refcount
;
1687 serial_driver
.table
= serial_table
;
1688 serial_driver
.termios
= serial_termios
;
1689 serial_driver
.termios_locked
= serial_termios_locked
;
1691 serial_driver
.open
= rs_open
;
1692 serial_driver
.close
= rs_close
;
1693 serial_driver
.write
= rs_write
;
1694 serial_driver
.flush_chars
= rs_flush_chars
;
1695 serial_driver
.write_room
= rs_write_room
;
1696 serial_driver
.chars_in_buffer
= rs_chars_in_buffer
;
1697 serial_driver
.flush_buffer
= rs_flush_buffer
;
1698 serial_driver
.ioctl
= rs_ioctl
;
1699 serial_driver
.throttle
= rs_throttle
;
1700 serial_driver
.unthrottle
= rs_unthrottle
;
1701 serial_driver
.set_termios
= rs_set_termios
;
1702 serial_driver
.stop
= rs_stop
;
1703 serial_driver
.start
= rs_start
;
1704 serial_driver
.hangup
= rs_hangup
;
1705 serial_driver
.break_ctl
= rs_break
;
1706 serial_driver
.wait_until_sent
= rs_wait_until_sent
;
1709 * The callout device is just like normal device except for
1710 * major number and the subtype code.
1712 callout_driver
= serial_driver
;
1713 callout_driver
.name
= "cua";
1714 callout_driver
.major
= TTYAUX_MAJOR
;
1715 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
1717 if (tty_register_driver(&serial_driver
))
1718 panic("Couldn't register serial driver\n");
1719 if (tty_register_driver(&callout_driver
))
1720 panic("Couldn't register callout driver\n");
1722 save_flags(flags
); cli();
1724 for (channel
= 0; channel
< zs_channels_found
; ++channel
) {
1726 if (zs_soft
[channel
].kgdb_channel
) {
1730 zs_soft
[channel
].clk_divisor
= 16;
1731 zs_soft
[channel
].zs_baud
= get_zsbaud(&zs_soft
[channel
]);
1733 if (request_irq(SERIAL
, rs_interrupt
, SA_SHIRQ
,
1734 "SCC", &zs_soft
[channel
]))
1735 printk(KERN_ERR
"decserial: can't get irq %d\n",
1738 /* If console serial line, then enable interrupts. */
1739 /* if (zs_soft[channel].is_cons) {
1740 write_zsreg(zs_soft[channel].zs_channel, R1,
1741 (EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB));
1742 write_zsreg(zs_soft[channel].zs_channel, R9,
1748 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++)
1751 if (info
->kgdb_channel
) {
1755 info
->magic
= SERIAL_MAGIC
;
1756 info
->port
= (int) info
->zs_channel
->control
;
1759 info
->custom_divisor
= 16;
1760 info
->close_delay
= 50;
1761 info
->closing_wait
= 3000;
1765 info
->blocked_open
= 0;
1766 info
->tqueue
.routine
= do_softint
;
1767 info
->tqueue
.data
= info
;
1768 info
->callout_termios
=callout_driver
.init_termios
;
1769 info
->normal_termios
= serial_driver
.init_termios
;
1770 init_waitqueue_head(&info
->open_wait
);
1771 init_waitqueue_head(&info
->close_wait
);
1772 printk("tty%02d at 0x%08x (irq = %d)", info
->line
,
1773 info
->port
, info
->irq
);
1774 printk(" is a Z85C30 SCC\n");
1777 restore_flags(flags
);
1783 * register_serial and unregister_serial allows for serial ports to be
1784 * configured at run-time, to support PCMCIA modems.
1786 /* PowerMac: Unused at this time, just here to make things link. */
1787 int register_serial(struct serial_struct
*req
)
1792 void unregister_serial(int line
)
1798 * ------------------------------------------------------------
1799 * Serial console driver
1800 * ------------------------------------------------------------
1802 #ifdef CONFIG_SERIAL_CONSOLE
1806 * Print a string to the serial port trying not to disturb
1807 * any possible real use of the port...
1810 /* This is for console output */
1812 zs_console_putchar(struct dec_serial
*info
, char ch
)
1815 unsigned long flags
;
1817 if(!info
->zs_channel
)
1820 save_flags(flags
); cli();
1822 while (!(*(info
->zs_channel
->control
) & Tx_BUF_EMP
) && --loops
)
1824 *(info
->zs_channel
->data
) = ch
;
1825 wbflush(); RECOVERY_DELAY
;
1827 restore_flags(flags
);
1830 static void serial_console_write(struct console
*co
, const char *s
,
1833 struct dec_serial
*info
;
1836 info
= zs_soft
+ co
->index
;
1840 * disable master interrupt if necessary
1842 nine
= info
->zs_channel
->curregs
[9];
1844 write_zsreg(info
->zs_channel
, R9
, nine
& ~MIE
);
1849 for (i
= 0; i
< count
; i
++, s
++) {
1851 zs_console_putchar(info
, '\r');
1852 zs_console_putchar(info
, *s
);
1855 * restore master interrupt enable
1858 write_zsreg(info
->zs_channel
, R9
, nine
);
1863 * Receive character from the serial port
1865 static int serial_console_wait_key(struct console
*co
)
1870 static kdev_t
serial_console_device(struct console
*c
)
1872 return MKDEV(TTY_MAJOR
, 64 + c
->index
);
1876 * Setup initial baud/bits/parity. We do two things here:
1877 * - construct a cflag setting for the first rs_open()
1878 * - initialize the serial port
1879 * Return non-zero if we didn't find a serial port.
1881 static int __init
serial_console_setup(struct console
*co
, char *options
)
1883 struct dec_serial
*info
;
1887 int cflag
= CREAD
| HUPCL
| CLOCAL
;
1889 unsigned long flags
;
1894 info
= zs_soft
+ co
->index
;
1902 baud
= simple_strtoul(options
, NULL
, 10);
1904 while(*s
>= '0' && *s
<= '9')
1913 * Now construct a cflag setting.
1961 save_and_cli(flags
);
1964 * Turn on RTS and DTR.
1969 * Finally, enable sequencing
1971 info
->zs_channel
->curregs
[3] |= (RxENABLE
| Rx8
);
1972 info
->zs_channel
->curregs
[5] |= (TxENAB
| Tx8
);
1973 info
->zs_channel
->curregs
[9] |= (VIS
);
1974 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
1975 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
1976 write_zsreg(info
->zs_channel
, 9, info
->zs_channel
->curregs
[9]);
1979 * Clear the interrupt registers.
1981 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
1982 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
1985 * Set the speed of the serial port
1989 /* Save the current value of RR0 */
1990 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
1992 zs_soft
[co
->index
].clk_divisor
= 16;
1993 zs_soft
[co
->index
].zs_baud
= get_zsbaud(&zs_soft
[co
->index
]);
1995 restore_flags(flags
);
2000 static struct console sercons
= {
2002 write
: serial_console_write
,
2003 device
: serial_console_device
,
2004 wait_key
: serial_console_wait_key
,
2005 setup
: serial_console_setup
,
2006 flags
: CON_PRINTBUFFER
,
2013 void __init
zs_serial_console_init(void)
2015 register_console(&sercons
);
2017 #endif /* ifdef CONFIG_SERIAL_CONSOLE */
2020 /* These are for receiving and sending characters under the kgdb
2021 * source level kernel debugger.
2023 void putDebugChar(char kgdb_char
)
2025 struct dec_zschannel
*chan
= zs_kgdbchan
;
2026 while ((read_zsreg(chan
, 0) & Tx_BUF_EMP
) == 0)
2028 write_zsdata(chan
, kgdb_char
);
2030 char getDebugChar(void)
2032 struct dec_zschannel
*chan
= zs_kgdbchan
;
2033 while((read_zsreg(chan
, 0) & Rx_CH_AV
) == 0)
2034 eieio(); /*barrier();*/
2035 return read_zsdata(chan
);
2037 void kgdb_interruptible(int yes
)
2039 struct dec_zschannel
*chan
= zs_kgdbchan
;
2041 nine
= read_zsreg(chan
, 9);
2043 one
= EXT_INT_ENAB
|INT_ALL_Rx
;
2045 printk("turning serial ints on\n");
2049 printk("turning serial ints off\n");
2051 write_zsreg(chan
, 1, one
);
2052 write_zsreg(chan
, 9, nine
);
2054 /* This sets up the serial port we're using, and turns on
2055 * interrupts for that channel, so kgdb is usable once we're done.
2057 static inline void kgdb_chaninit(struct dec_zschannel
*ms
, int intson
, int bps
)
2061 volatile char *sccc
= ms
->control
;
2062 brg
= BPS_TO_BRG(bps
, ZS_CLOCK
/16);
2063 printk("setting bps on kgdb line to %d [brg=%x]\n", bps
, brg
);
2064 for (i
= 20000; i
!= 0; --i
) {
2067 for (i
= 0; i
< sizeof(scc_inittab
); ++i
) {
2068 write_zsreg(ms
, scc_inittab
[i
], scc_inittab
[i
+1]);
2072 /* This is called at boot time to prime the kgdb serial debugging
2073 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2074 * for /dev/ttyb which is determined in setup_arch() from the
2075 * boot command line flags.
2077 void __init
zs_kgdb_hook(int tty_num
)
2079 /* Find out how many Z8530 SCCs we have */
2082 zs_soft
[tty_num
].zs_channel
= &zs_channels
[tty_num
];
2083 zs_kgdbchan
= zs_soft
[tty_num
].zs_channel
;
2084 zs_soft
[tty_num
].change_needed
= 0;
2085 zs_soft
[tty_num
].clk_divisor
= 16;
2086 zs_soft
[tty_num
].zs_baud
= 38400;
2087 zs_soft
[tty_num
].kgdb_channel
= 1; /* This runs kgdb */
2088 zs_soft
[tty_num
^ 1].kgdb_channel
= 0; /* This does not */
2089 /* Turn on transmitter/receiver at 8-bits/char */
2090 kgdb_chaninit(zs_soft
[tty_num
].zs_channel
, 1, 38400);
2091 printk("KGDB: on channel %d initialized\n", tty_num
);
2092 set_debug_traps(); /* init stub */
2094 #endif /* ifdef CONFIG_KGDB */