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/dec/interrupts.h>
46 #include <asm/dec/machtype.h>
47 #include <asm/dec/tc.h>
48 #include <asm/dec/ioasic_addrs.h>
57 * It would be nice to dynamically allocate everything that
58 * depends on NUM_SERIAL, so we could support any number of
59 * Z8530s, but for now...
61 #define NUM_SERIAL 2 /* Max number of ZS chips supported */
62 #define NUM_CHANNELS (NUM_SERIAL * 2) /* 2 channels per chip */
64 #define RECOVERY_DELAY udelay(2)
66 struct dec_zschannel zs_channels
[NUM_CHANNELS
];
68 struct dec_serial zs_soft
[NUM_CHANNELS
];
69 int zs_channels_found
;
70 struct dec_serial
*zs_chain
; /* list of all channels */
72 struct tty_struct zs_ttys
[NUM_CHANNELS
];
74 #ifdef CONFIG_SERIAL_CONSOLE
75 static struct console sercons
;
79 struct dec_zschannel
*zs_kgdbchan
;
80 static unsigned char scc_inittab
[] = {
81 9, 0x80, /* reset A side (CHRA) */
82 13, 0, /* set baud rate divisor */
84 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
85 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
86 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
87 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
88 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
92 static unsigned char zs_init_regs
[16] __initdata
= {
97 (X16CLK
| SB1
), /* write 4 */
99 0, 0, 0, /* write 6, 7, 8 */
101 (NRZ
), /* write 10 */
102 (TCBR
| RCBR
), /* write 11 */
103 0, 0, /* BRG time constant, write 12 + 13 */
104 (BRSRC
| BRENABL
), /* write 14 */
108 #define ZS_CLOCK 7372800 /* Z8530 RTxC input clock rate */
110 DECLARE_TASK_QUEUE(tq_zs_serial
);
112 struct tty_driver serial_driver
, callout_driver
;
113 static int serial_refcount
;
115 /* serial subtype definitions */
116 #define SERIAL_TYPE_NORMAL 1
117 #define SERIAL_TYPE_CALLOUT 2
119 /* number of characters left in xmit buffer before we ask for more */
120 #define WAKEUP_CHARS 256
125 #undef SERIAL_DEBUG_INTR
126 #undef SERIAL_DEBUG_OPEN
127 #undef SERIAL_DEBUG_FLOW
128 #undef SERIAL_DEBUG_THROTTLE
129 #undef SERIAL_PARANOIA_CHECK
131 #define RS_STROBE_TIME 10
132 #define RS_ISR_PASS_LIMIT 256
134 #define _INLINE_ inline
136 static void probe_sccs(void);
137 static void change_speed(struct dec_serial
*info
);
138 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
140 static struct tty_struct
*serial_table
[NUM_CHANNELS
];
141 static struct termios
*serial_termios
[NUM_CHANNELS
];
142 static struct termios
*serial_termios_locked
[NUM_CHANNELS
];
145 #define MIN(a,b) ((a) < (b) ? (a) : (b))
149 * tmp_buf is used as a temporary buffer by serial_write. We need to
150 * lock it in case the copy_from_user blocks while swapping in a page,
151 * and some other program tries to do a serial write at the same time.
152 * Since the lock will only come under contention when the system is
153 * swapping and available memory is low, it makes sense to share one
154 * buffer across all the serial ports, since it significantly saves
155 * memory if large numbers of serial ports are open.
157 static unsigned char tmp_buf
[4096]; /* This is cheating */
158 static struct semaphore tmp_buf_sem
= MUTEX
;
160 static inline int serial_paranoia_check(struct dec_serial
*info
,
161 dev_t device
, const char *routine
)
163 #ifdef SERIAL_PARANOIA_CHECK
164 static const char *badmagic
=
165 "Warning: bad magic number for serial struct (%d, %d) in %s\n";
166 static const char *badinfo
=
167 "Warning: null mac_serial for (%d, %d) in %s\n";
170 printk(badinfo
, MAJOR(device
), MINOR(device
), routine
);
173 if (info
->magic
!= SERIAL_MAGIC
) {
174 printk(badmagic
, MAJOR(device
), MINOR(device
), routine
);
182 * This is used to figure out the divisor speeds and the timeouts
184 static int baud_table
[] = {
185 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
186 9600, 19200, 38400, 57600, 0, 0 };
189 * Reading and writing Z8530 registers.
191 static inline unsigned char read_zsreg(struct dec_zschannel
*channel
,
194 unsigned char retval
;
197 *channel
->control
= reg
& 0xf;
200 retval
= *channel
->control
;
205 static inline void write_zsreg(struct dec_zschannel
*channel
,
206 unsigned char reg
, unsigned char value
)
209 *channel
->control
= reg
& 0xf;
212 *channel
->control
= value
;
217 static inline unsigned char read_zsdata(struct dec_zschannel
*channel
)
219 unsigned char retval
;
221 retval
= *channel
->data
;
226 static inline void write_zsdata(struct dec_zschannel
*channel
,
229 *channel
->data
= value
;
234 static inline void load_zsregs(struct dec_zschannel
*channel
,
237 /* ZS_CLEARERR(channel);
238 ZS_CLEARFIFO(channel); */
240 write_zsreg(channel
, R4
, regs
[R4
]);
241 write_zsreg(channel
, R3
, regs
[R3
] & ~RxENABLE
);
242 write_zsreg(channel
, R5
, regs
[R5
] & ~TxENAB
);
243 write_zsreg(channel
, R9
, regs
[R9
]);
244 write_zsreg(channel
, R1
, regs
[R1
]);
245 write_zsreg(channel
, R2
, regs
[R2
]);
246 write_zsreg(channel
, R10
, regs
[R10
]);
247 write_zsreg(channel
, R11
, regs
[R11
]);
248 write_zsreg(channel
, R12
, regs
[R12
]);
249 write_zsreg(channel
, R13
, regs
[R13
]);
250 write_zsreg(channel
, R14
, regs
[R14
]);
251 write_zsreg(channel
, R15
, regs
[R15
]);
252 write_zsreg(channel
, R3
, regs
[R3
]);
253 write_zsreg(channel
, R5
, regs
[R5
]);
257 /* Sets or clears DTR/RTS on the requested line */
258 static inline void zs_rtsdtr(struct dec_serial
*ss
, int set
)
260 if (ss
->zs_channel
!= ss
->zs_chan_a
) {
262 ss
->zs_chan_a
->curregs
[5] |= (RTS
| DTR
);
264 ss
->zs_chan_a
->curregs
[5] &= ~(RTS
| DTR
);
265 write_zsreg(ss
->zs_chan_a
, 5, ss
->zs_chan_a
->curregs
[5]);
270 /* Utility routines for the Zilog */
271 static inline int get_zsbaud(struct dec_serial
*ss
)
273 struct dec_zschannel
*channel
= ss
->zs_channel
;
276 /* The baud rate is split up between two 8-bit registers in
277 * what is termed 'BRG time constant' format in my docs for
278 * the chip, it is a function of the clk rate the chip is
279 * receiving which happens to be constant.
281 brg
= (read_zsreg(channel
, 13) << 8);
282 brg
|= read_zsreg(channel
, 12);
283 return BRG_TO_BPS(brg
, (ZS_CLOCK
/(ss
->clk_divisor
)));
286 /* On receive, this clears errors and the receiver interrupts */
287 static inline void rs_recv_clear(struct dec_zschannel
*zsc
)
289 write_zsreg(zsc
, 0, ERR_RES
);
290 write_zsreg(zsc
, 0, RES_H_IUS
); /* XXX this is unnecessary */
294 * ----------------------------------------------------------------------
296 * Here starts the interrupt handling routines. All of the following
297 * subroutines are declared as inline and are folded into
298 * rs_interrupt(). They were separated out for readability's sake.
300 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
301 * -----------------------------------------------------------------------
305 * This routine is used by the interrupt handler to schedule
306 * processing in the software interrupt portion of the driver.
308 static _INLINE_
void rs_sched_event(struct dec_serial
*info
,
311 info
->event
|= 1 << event
;
312 queue_task(&info
->tqueue
, &tq_zs_serial
);
316 static _INLINE_
void receive_chars(struct dec_serial
*info
,
317 struct pt_regs
*regs
)
319 struct tty_struct
*tty
= info
->tty
;
320 unsigned char ch
, stat
, flag
;
322 while ((read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
) != 0) {
324 stat
= read_zsreg(info
->zs_channel
, R1
);
325 ch
= read_zsdata(info
->zs_channel
);
328 if (info
->kgdb_channel
) {
329 if (ch
== 0x03 || ch
== '$')
331 if (stat
& (Rx_OVR
|FRM_ERR
|PAR_ERR
))
332 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
339 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
340 static int flip_buf_ovf
;
346 static int flip_max_cnt
;
347 if (flip_max_cnt
< tty
->flip
.count
)
348 flip_max_cnt
= tty
->flip
.count
;
352 } else if (stat
& FRM_ERR
) {
354 } else if (stat
& PAR_ERR
) {
359 /* reset the error indication */
360 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
361 *tty
->flip
.flag_buf_ptr
++ = flag
;
362 *tty
->flip
.char_buf_ptr
++ = ch
;
364 tty_flip_buffer_push(tty
);
367 static void transmit_chars(struct dec_serial
*info
)
369 if ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
) == 0)
375 write_zsdata(info
->zs_channel
, info
->x_char
);
381 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
|| info
->tx_stopped
) {
382 write_zsreg(info
->zs_channel
, 0, RES_Tx_P
);
386 write_zsdata(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
387 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
391 if (info
->xmit_cnt
< WAKEUP_CHARS
)
392 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
395 static _INLINE_
void status_handle(struct dec_serial
*info
)
397 unsigned char status
;
399 /* Get status from Read Register 0 */
400 status
= read_zsreg(info
->zs_channel
, 0);
402 /* FIXEM: Check for DCD transitions */
403 if (((status
^ info
->read_reg_zero
) & DCD
) != 0
404 && info
->tty
&& !C_CLOCAL(info
->tty
)) {
406 wake_up_interruptible(&info
->open_wait
);
407 } else if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
)) {
409 tty_hangup(info
->tty
);
413 /* Check for CTS transitions */
414 if (info
->tty
&& C_CRTSCTS(info
->tty
)) {
416 * For some reason, on the Power Macintosh,
417 * it seems that the CTS bit is 1 when CTS is
418 * *negated* and 0 when it is asserted.
419 * The DCD bit doesn't seem to be inverted
422 if ((status
& CTS
) != 0) {
423 if (info
->tx_stopped
) {
424 info
->tx_stopped
= 0;
425 if (!info
->tx_active
)
426 transmit_chars(info
);
429 info
->tx_stopped
= 1;
433 /* Clear status condition... */
434 write_zsreg(info
->zs_channel
, 0, RES_EXT_INT
);
435 info
->read_reg_zero
= status
;
439 * This is the serial driver's generic interrupt routine
441 void rs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
443 struct dec_serial
*info
= (struct dec_serial
*) dev_id
;
444 unsigned char zs_intreg
;
447 /* NOTE: The read register 3, which holds the irq status,
448 * does so for both channels on each chip. Although
449 * the status value itself must be read from the A
450 * channel and is only valid when read from channel A.
451 * Yes... broken hardware...
453 #define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
455 if (info
->zs_chan_a
== info
->zs_channel
)
456 shift
= 3; /* Channel A */
458 shift
= 0; /* Channel B */
461 zs_intreg
= read_zsreg(info
->zs_chan_a
, 3) >> shift
;
462 if ((zs_intreg
& CHAN_IRQMASK
) == 0)
465 if (zs_intreg
& CHBRxIP
) {
466 receive_chars(info
, regs
);
468 if (zs_intreg
& CHBTxIP
) {
469 transmit_chars(info
);
471 if (zs_intreg
& CHBEXT
) {
478 * -------------------------------------------------------------------
479 * Here ends the serial interrupt routines.
480 * -------------------------------------------------------------------
484 * ------------------------------------------------------------
485 * rs_stop() and rs_start()
487 * This routines are called before setting or resetting tty->stopped.
488 * ------------------------------------------------------------
490 static void rs_stop(struct tty_struct
*tty
)
492 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
495 if (serial_paranoia_check(info
, tty
->device
, "rs_stop"))
499 save_flags(flags
); cli();
500 if (info
->zs_channel
->curregs
[5] & TxENAB
) {
501 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
502 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
504 restore_flags(flags
);
508 static void rs_start(struct tty_struct
*tty
)
510 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
513 if (serial_paranoia_check(info
, tty
->device
, "rs_start"))
516 save_flags(flags
); cli();
518 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->zs_channel
->curregs
[5] & TxENAB
)) {
519 info
->zs_channel
->curregs
[5] |= TxENAB
;
520 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
523 if (info
->xmit_cnt
&& info
->xmit_buf
&& !info
->tx_active
) {
524 transmit_chars(info
);
527 restore_flags(flags
);
531 * This routine is used to handle the "bottom half" processing for the
532 * serial driver, known also the "software interrupt" processing.
533 * This processing is done at the kernel interrupt level, after the
534 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
535 * is where time-consuming activities which can not be done in the
536 * interrupt driver proper are done; the interrupt driver schedules
537 * them using rs_sched_event(), and they get done here.
539 static void do_serial_bh(void)
541 run_task_queue(&tq_zs_serial
);
544 static void do_softint(void *private_
)
546 struct dec_serial
*info
= (struct dec_serial
*) private_
;
547 struct tty_struct
*tty
;
553 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
554 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
555 tty
->ldisc
.write_wakeup
)
556 (tty
->ldisc
.write_wakeup
)(tty
);
557 wake_up_interruptible(&tty
->write_wait
);
561 static void rs_timer(void)
565 static int startup(struct dec_serial
* info
)
569 if (info
->flags
& ZILOG_INITIALIZED
)
572 if (!info
->xmit_buf
) {
573 info
->xmit_buf
= (unsigned char *) get_free_page(GFP_KERNEL
);
578 save_flags(flags
); cli();
580 #ifdef SERIAL_DEBUG_OPEN
581 printk("starting up ttyS%d (irq %d)...", info
->line
, info
->irq
);
585 * Clear the receive FIFO.
587 ZS_CLEARFIFO(info
->zs_channel
);
588 info
->xmit_fifo_size
= 1;
591 * Clear the interrupt registers.
593 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
594 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
597 * Turn on RTS and DTR.
602 * Finally, enable sequencing and interrupts
604 info
->zs_channel
->curregs
[1] = (info
->zs_channel
->curregs
[1] & ~0x18) | (EXT_INT_ENAB
| INT_ALL_Rx
| TxINT_ENAB
);
605 info
->zs_channel
->curregs
[3] |= (RxENABLE
| Rx8
);
606 info
->zs_channel
->curregs
[5] |= (TxENAB
| Tx8
);
607 info
->zs_channel
->curregs
[15] |= (DCDIE
| CTSIE
| TxUIE
| BRKIE
);
608 info
->zs_channel
->curregs
[9] |= (VIS
| MIE
);
609 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]);
610 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
611 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
612 write_zsreg(info
->zs_channel
, 15, info
->zs_channel
->curregs
[15]);
613 write_zsreg(info
->zs_channel
, 9, info
->zs_channel
->curregs
[9]);
616 * And clear the interrupt registers again for luck.
618 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
619 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
622 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
623 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
626 * Set the speed of the serial port
630 /* Save the current value of RR0 */
631 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
633 info
->flags
|= ZILOG_INITIALIZED
;
634 restore_flags(flags
);
639 * This routine will shutdown a serial port; interrupts are disabled, and
640 * DTR is dropped if the hangup on close termio flag is on.
642 static void shutdown(struct dec_serial
* info
)
646 if (!(info
->flags
& ZILOG_INITIALIZED
))
649 #ifdef SERIAL_DEBUG_OPEN
650 printk("Shutting down serial port %d (irq %d)....", info
->line
,
654 save_flags(flags
); cli(); /* Disable interrupts */
656 if (info
->xmit_buf
) {
657 free_page((unsigned long) info
->xmit_buf
);
661 info
->zs_channel
->curregs
[1] = 0;
662 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]); /* no interrupts */
664 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
665 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
667 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
668 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
669 if (!info
->tty
|| C_HUPCL(info
->tty
)) {
670 info
->zs_chan_a
->curregs
[5] &= ~(DTR
| RTS
);
671 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
675 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
677 info
->flags
&= ~ZILOG_INITIALIZED
;
678 restore_flags(flags
);
682 * This routine is called to set the UART divisor registers to match
683 * the specified baud rate for a serial port.
685 static void change_speed(struct dec_serial
*info
)
693 if (!info
->tty
|| !info
->tty
->termios
)
695 cflag
= info
->tty
->termios
->c_cflag
;
696 if (!(port
= info
->port
))
700 save_flags(flags
); cli();
701 info
->zs_baud
= baud_table
[i
];
702 info
->clk_divisor
= 16;
704 switch (info
->zs_baud
) {
706 info
->zs_channel
->curregs
[4] = X16CLK
;
707 brg
= BPS_TO_BRG(info
->zs_baud
, ZS_CLOCK
/info
->clk_divisor
);
708 info
->zs_channel
->curregs
[12] = (brg
& 255);
709 info
->zs_channel
->curregs
[13] = ((brg
>> 8) & 255);
712 /* byte size and parity */
713 info
->zs_channel
->curregs
[3] &= ~RxNBITS_MASK
;
714 info
->zs_channel
->curregs
[5] &= ~TxNBITS_MASK
;
715 switch (cflag
& CSIZE
) {
717 info
->zs_channel
->curregs
[3] |= Rx5
;
718 info
->zs_channel
->curregs
[5] |= Tx5
;
721 info
->zs_channel
->curregs
[3] |= Rx6
;
722 info
->zs_channel
->curregs
[5] |= Tx6
;
725 info
->zs_channel
->curregs
[3] |= Rx7
;
726 info
->zs_channel
->curregs
[5] |= Tx7
;
729 default: /* defaults to 8 bits */
730 info
->zs_channel
->curregs
[3] |= Rx8
;
731 info
->zs_channel
->curregs
[5] |= Tx8
;
735 info
->zs_channel
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
736 if (cflag
& CSTOPB
) {
737 info
->zs_channel
->curregs
[4] |= SB2
;
739 info
->zs_channel
->curregs
[4] |= SB1
;
741 if (cflag
& PARENB
) {
742 info
->zs_channel
->curregs
[4] |= PAR_ENA
;
744 if (!(cflag
& PARODD
)) {
745 info
->zs_channel
->curregs
[4] |= PAR_EVEN
;
748 if (!(cflag
& CLOCAL
)) {
749 if (!(info
->zs_channel
->curregs
[15] & DCDIE
))
750 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
751 info
->zs_channel
->curregs
[15] |= DCDIE
;
753 info
->zs_channel
->curregs
[15] &= ~DCDIE
;
754 if (cflag
& CRTSCTS
) {
755 info
->zs_channel
->curregs
[15] |= CTSIE
;
756 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) != 0)
757 info
->tx_stopped
= 1;
759 info
->zs_channel
->curregs
[15] &= ~CTSIE
;
760 info
->tx_stopped
= 0;
763 /* Load up the new values */
764 load_zsregs(info
->zs_channel
, info
->zs_channel
->curregs
);
766 restore_flags(flags
);
769 static void rs_flush_chars(struct tty_struct
*tty
)
771 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
774 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_chars"))
777 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| info
->tx_stopped
||
781 /* Enable transmitter */
782 save_flags(flags
); cli();
783 transmit_chars(info
);
784 restore_flags(flags
);
787 static int rs_write(struct tty_struct
* tty
, int from_user
,
788 const unsigned char *buf
, int count
)
791 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
794 if (serial_paranoia_check(info
, tty
->device
, "rs_write"))
797 if (!tty
|| !info
->xmit_buf
)
803 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
804 SERIAL_XMIT_SIZE
- info
->xmit_head
));
810 copy_from_user(tmp_buf
, buf
, c
);
811 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
812 SERIAL_XMIT_SIZE
- info
->xmit_head
));
813 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
816 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
817 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
819 restore_flags(flags
);
825 if (info
->xmit_cnt
&& !tty
->stopped
&& !info
->tx_stopped
827 transmit_chars(info
);
828 restore_flags(flags
);
832 static int rs_write_room(struct tty_struct
*tty
)
834 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
837 if (serial_paranoia_check(info
, tty
->device
, "rs_write_room"))
839 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
845 static int rs_chars_in_buffer(struct tty_struct
*tty
)
847 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
849 if (serial_paranoia_check(info
, tty
->device
, "rs_chars_in_buffer"))
851 return info
->xmit_cnt
;
854 static void rs_flush_buffer(struct tty_struct
*tty
)
856 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
858 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_buffer"))
861 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
863 wake_up_interruptible(&tty
->write_wait
);
864 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
865 tty
->ldisc
.write_wakeup
)
866 (tty
->ldisc
.write_wakeup
)(tty
);
870 * ------------------------------------------------------------
873 * This routine is called by the upper-layer tty layer to signal that
874 * incoming characters should be throttled.
875 * ------------------------------------------------------------
877 static void rs_throttle(struct tty_struct
* tty
)
879 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
882 #ifdef SERIAL_DEBUG_THROTTLE
885 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
886 tty
->ldisc
.chars_in_buffer(tty
));
889 if (serial_paranoia_check(info
, tty
->device
, "rs_throttle"))
893 save_flags(flags
); cli();
894 info
->x_char
= STOP_CHAR(tty
);
895 if (!info
->tx_active
)
896 transmit_chars(info
);
897 restore_flags(flags
);
900 if (C_CRTSCTS(tty
)) {
902 * Here we want to turn off the RTS line. On Macintoshes,
903 * we only get the DTR line, which goes to both DTR and
904 * RTS on the modem. RTS doesn't go out to the serial
905 * port socket. So you should make sure your modem is
906 * set to ignore DTR if you're using CRTSCTS.
908 save_flags(flags
); cli();
909 info
->zs_chan_a
->curregs
[5] &= ~(DTR
| RTS
);
910 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
911 restore_flags(flags
);
915 static void rs_unthrottle(struct tty_struct
* tty
)
917 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
920 #ifdef SERIAL_DEBUG_THROTTLE
923 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
924 tty
->ldisc
.chars_in_buffer(tty
));
927 if (serial_paranoia_check(info
, tty
->device
, "rs_unthrottle"))
931 save_flags(flags
); cli();
935 info
->x_char
= START_CHAR(tty
);
936 if (!info
->tx_active
)
937 transmit_chars(info
);
939 restore_flags(flags
);
942 if (C_CRTSCTS(tty
)) {
943 /* Assert RTS and DTR lines */
944 save_flags(flags
); cli();
945 info
->zs_chan_a
->curregs
[5] |= DTR
| RTS
;
946 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
947 restore_flags(flags
);
952 * ------------------------------------------------------------
953 * rs_ioctl() and friends
954 * ------------------------------------------------------------
957 static int get_serial_info(struct dec_serial
* info
,
958 struct serial_struct
* retinfo
)
960 struct serial_struct tmp
;
964 memset(&tmp
, 0, sizeof(tmp
));
965 tmp
.type
= info
->type
;
966 tmp
.line
= info
->line
;
967 tmp
.port
= info
->port
;
969 tmp
.flags
= info
->flags
;
970 tmp
.baud_base
= info
->baud_base
;
971 tmp
.close_delay
= info
->close_delay
;
972 tmp
.closing_wait
= info
->closing_wait
;
973 tmp
.custom_divisor
= info
->custom_divisor
;
974 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
));
977 static int set_serial_info(struct dec_serial
* info
,
978 struct serial_struct
* new_info
)
980 struct serial_struct new_serial
;
981 struct dec_serial old_info
;
986 copy_from_user(&new_serial
,new_info
,sizeof(new_serial
));
990 if ((new_serial
.baud_base
!= info
->baud_base
) ||
991 (new_serial
.type
!= info
->type
) ||
992 (new_serial
.close_delay
!= info
->close_delay
) ||
993 ((new_serial
.flags
& ~ZILOG_USR_MASK
) !=
994 (info
->flags
& ~ZILOG_USR_MASK
)))
996 info
->flags
= ((info
->flags
& ~ZILOG_USR_MASK
) |
997 (new_serial
.flags
& ZILOG_USR_MASK
));
998 info
->custom_divisor
= new_serial
.custom_divisor
;
1002 if (info
->count
> 1)
1006 * OK, past this point, all the error checking has been done.
1007 * At this point, we start making changes.....
1010 info
->baud_base
= new_serial
.baud_base
;
1011 info
->flags
= ((info
->flags
& ~ZILOG_FLAGS
) |
1012 (new_serial
.flags
& ZILOG_FLAGS
));
1013 info
->type
= new_serial
.type
;
1014 info
->close_delay
= new_serial
.close_delay
;
1015 info
->closing_wait
= new_serial
.closing_wait
;
1018 retval
= startup(info
);
1023 * get_lsr_info - get line status register info
1025 * Purpose: Let user call ioctl() to get info when the UART physically
1026 * is emptied. On bus types like RS485, the transmitter must
1027 * release the bus after transmitting. This must be done when
1028 * the transmit shift register is empty, not be done when the
1029 * transmit holding register is empty. This functionality
1030 * allows an RS485 driver to be written in user space.
1032 static int get_lsr_info(struct dec_serial
* info
, unsigned int *value
)
1034 unsigned char status
;
1037 status
= read_zsreg(info
->zs_channel
, 0);
1039 put_user(status
,value
);
1043 static int get_modem_info(struct dec_serial
*info
, unsigned int *value
)
1045 unsigned char control
, status
;
1046 unsigned int result
;
1049 control
= info
->zs_chan_a
->curregs
[5];
1050 status
= read_zsreg(info
->zs_channel
, 0);
1052 result
= ((control
& RTS
) ? TIOCM_RTS
: 0)
1053 | ((control
& DTR
) ? TIOCM_DTR
: 0)
1054 | ((status
& DCD
) ? TIOCM_CAR
: 0)
1055 | ((status
& CTS
) ? 0: TIOCM_CTS
);
1056 put_user(result
,value
);
1060 static int set_modem_info(struct dec_serial
*info
, unsigned int cmd
,
1061 unsigned int *value
)
1064 unsigned int arg
, bits
;
1066 error
= verify_area(VERIFY_READ
, value
, sizeof(int));
1069 get_user(arg
, value
);
1070 bits
= (arg
& TIOCM_RTS
? RTS
: 0) + (arg
& TIOCM_DTR
? DTR
: 0);
1074 info
->zs_chan_a
->curregs
[5] |= bits
;
1077 info
->zs_chan_a
->curregs
[5] &= ~bits
;
1080 info
->zs_chan_a
->curregs
[5] = (info
->zs_chan_a
->curregs
[5] & ~(DTR
| RTS
)) | bits
;
1086 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
1092 * rs_break - turn transmit break condition on/off
1094 static void rs_break(struct tty_struct
*tty
, int break_state
)
1096 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1097 unsigned long flags
;
1099 if (serial_paranoia_check(info
, tty
->device
, "rs_break"))
1104 save_flags(flags
); cli();
1105 if (break_state
== -1)
1106 info
->zs_channel
->curregs
[5] |= SND_BRK
;
1108 info
->zs_channel
->curregs
[5] &= ~SND_BRK
;
1109 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
1110 restore_flags(flags
);
1113 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1114 unsigned int cmd
, unsigned long arg
)
1117 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1120 if (info
->kgdb_channel
)
1123 if (serial_paranoia_check(info
, tty
->device
, "rs_ioctl"))
1126 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1127 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1128 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1129 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1135 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1136 sizeof(unsigned int));
1139 return get_modem_info(info
, (unsigned int *) arg
);
1143 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1145 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1146 sizeof(struct serial_struct
));
1149 return get_serial_info(info
,
1150 (struct serial_struct
*) arg
);
1152 return set_serial_info(info
,
1153 (struct serial_struct
*) arg
);
1154 case TIOCSERGETLSR
: /* Get line status register */
1155 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1156 sizeof(unsigned int));
1160 return get_lsr_info(info
, (unsigned int *) arg
);
1162 case TIOCSERGSTRUCT
:
1163 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1164 sizeof(struct dec_serial
));
1167 copy_from_user((struct dec_serial
*) arg
,
1168 info
, sizeof(struct dec_serial
));
1172 return -ENOIOCTLCMD
;
1177 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1179 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
1182 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1184 was_stopped
= info
->tx_stopped
;
1188 if (was_stopped
&& !info
->tx_stopped
)
1193 * ------------------------------------------------------------
1196 * This routine is called when the serial port gets closed.
1197 * Wait for the last remaining data to be sent.
1198 * ------------------------------------------------------------
1200 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
1202 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1203 unsigned long flags
;
1205 if (!info
|| serial_paranoia_check(info
, tty
->device
, "rs_close"))
1208 save_flags(flags
); cli();
1210 if (tty_hung_up_p(filp
)) {
1211 restore_flags(flags
);
1215 #ifdef SERIAL_DEBUG_OPEN
1216 printk("rs_close ttys%d, count = %d\n", info
->line
, info
->count
);
1218 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1220 * Uh, oh. tty->count is 1, which means that the tty
1221 * structure will be freed. Info->count should always
1222 * be one in these conditions. If it's greater than
1223 * one, we've got real problems, since it means the
1224 * serial port won't be shutdown.
1226 printk("rs_close: bad serial port count; tty->count is 1, "
1227 "info->count is %d\n", info
->count
);
1230 if (--info
->count
< 0) {
1231 printk("rs_close: bad serial port count for ttys%d: %d\n",
1232 info
->line
, info
->count
);
1236 restore_flags(flags
);
1239 info
->flags
|= ZILOG_CLOSING
;
1241 * Save the termios structure, since this port may have
1242 * separate termios for callout and dialin.
1244 if (info
->flags
& ZILOG_NORMAL_ACTIVE
)
1245 info
->normal_termios
= *tty
->termios
;
1246 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
)
1247 info
->callout_termios
= *tty
->termios
;
1249 * Now we wait for the transmit buffer to clear; and we notify
1250 * the line discipline to only process XON/XOFF characters.
1253 if (info
->closing_wait
!= ZILOG_CLOSING_WAIT_NONE
)
1254 tty_wait_until_sent(tty
, info
->closing_wait
);
1256 * At this point we stop accepting input. To do this, we
1257 * disable the receiver and receive interrupts.
1259 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
1260 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
1261 info
->zs_channel
->curregs
[1] = 0; /* disable any rx ints */
1262 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]);
1263 ZS_CLEARFIFO(info
->zs_channel
);
1264 if (info
->flags
& ZILOG_INITIALIZED
) {
1266 * Before we drop DTR, make sure the SCC transmitter
1267 * has completely drained.
1269 rs_wait_until_sent(tty
, info
->timeout
);
1273 if (tty
->driver
.flush_buffer
)
1274 tty
->driver
.flush_buffer(tty
);
1275 if (tty
->ldisc
.flush_buffer
)
1276 tty
->ldisc
.flush_buffer(tty
);
1280 if (info
->blocked_open
) {
1281 if (info
->close_delay
) {
1282 current
->state
= TASK_INTERRUPTIBLE
;
1283 schedule_timeout(info
->close_delay
);
1285 wake_up_interruptible(&info
->open_wait
);
1287 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CALLOUT_ACTIVE
|
1289 wake_up_interruptible(&info
->close_wait
);
1290 restore_flags(flags
);
1294 * rs_wait_until_sent() --- wait until the transmitter is empty
1296 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1298 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1299 unsigned long orig_jiffies
, char_time
;
1301 if (serial_paranoia_check(info
, tty
->device
, "rs_wait_until_sent"))
1304 orig_jiffies
= jiffies
;
1306 * Set the check interval to be 1/5 of the estimated time to
1307 * send a single character, and make it at least 1. The check
1308 * interval should also be less than the timeout.
1310 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1311 char_time
= char_time
/ 5;
1315 char_time
= MIN(char_time
, timeout
);
1316 while ((read_zsreg(info
->zs_channel
, 1) & ALL_SNT
) == 0) {
1317 current
->state
= TASK_INTERRUPTIBLE
;
1318 schedule_timeout(char_time
);
1319 if (signal_pending(current
))
1321 if (timeout
&& ((orig_jiffies
+ timeout
) < jiffies
))
1324 current
->state
= TASK_RUNNING
;
1328 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1330 void rs_hangup(struct tty_struct
*tty
)
1332 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1334 if (serial_paranoia_check(info
, tty
->device
, "rs_hangup"))
1337 rs_flush_buffer(tty
);
1341 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CALLOUT_ACTIVE
);
1343 wake_up_interruptible(&info
->open_wait
);
1347 * ------------------------------------------------------------
1348 * rs_open() and friends
1349 * ------------------------------------------------------------
1351 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1352 struct dec_serial
*info
)
1354 struct wait_queue wait
= { current
, NULL
};
1359 * If the device is in the middle of being closed, then block
1360 * until it's done, and then try again.
1362 if (info
->flags
& ZILOG_CLOSING
) {
1363 interruptible_sleep_on(&info
->close_wait
);
1364 #ifdef SERIAL_DO_RESTART
1365 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1366 -EAGAIN
: -ERESTARTSYS
);
1373 * If this is a callout device, then just make sure the normal
1374 * device isn't being used.
1376 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1377 if (info
->flags
& ZILOG_NORMAL_ACTIVE
)
1379 if ((info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1380 (info
->flags
& ZILOG_SESSION_LOCKOUT
) &&
1381 (info
->session
!= current
->session
))
1383 if ((info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1384 (info
->flags
& ZILOG_PGRP_LOCKOUT
) &&
1385 (info
->pgrp
!= current
->pgrp
))
1387 info
->flags
|= ZILOG_CALLOUT_ACTIVE
;
1392 * If non-blocking mode is set, or the port is not enabled,
1393 * then make the check up front and then exit.
1395 if ((filp
->f_flags
& O_NONBLOCK
) ||
1396 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1397 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
)
1399 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1403 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
) {
1404 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1407 if (tty
->termios
->c_cflag
& CLOCAL
)
1412 * Block waiting for the carrier detect and the line to become
1413 * free (i.e., not in use by the callout). While we are in
1414 * this loop, info->count is dropped by one, so that
1415 * rs_close() knows when to free things. We restore it upon
1416 * exit, either normal or abnormal.
1419 add_wait_queue(&info
->open_wait
, &wait
);
1420 #ifdef SERIAL_DEBUG_OPEN
1421 printk("block_til_ready before block: ttys%d, count = %d\n",
1422 info
->line
, info
->count
);
1425 if (!tty_hung_up_p(filp
))
1428 info
->blocked_open
++;
1431 if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1432 (tty
->termios
->c_cflag
& CBAUD
))
1435 set_current_state(TASK_INTERRUPTIBLE
);
1436 if (tty_hung_up_p(filp
) ||
1437 !(info
->flags
& ZILOG_INITIALIZED
)) {
1438 #ifdef SERIAL_DO_RESTART
1439 if (info
->flags
& ZILOG_HUP_NOTIFY
)
1442 retval
= -ERESTARTSYS
;
1448 if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1449 !(info
->flags
& ZILOG_CLOSING
) &&
1450 (do_clocal
|| (read_zsreg(info
->zs_channel
, 0) & DCD
)))
1452 if (signal_pending(current
)) {
1453 retval
= -ERESTARTSYS
;
1456 #ifdef SERIAL_DEBUG_OPEN
1457 printk("block_til_ready blocking: ttys%d, count = %d\n",
1458 info
->line
, info
->count
);
1462 current
->state
= TASK_RUNNING
;
1463 remove_wait_queue(&info
->open_wait
, &wait
);
1464 if (!tty_hung_up_p(filp
))
1466 info
->blocked_open
--;
1467 #ifdef SERIAL_DEBUG_OPEN
1468 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1469 info
->line
, info
->count
);
1473 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1478 * This routine is called whenever a serial port is opened. It
1479 * enables interrupts for a serial port, linking in its ZILOG structure into
1480 * the IRQ chain. It also performs the serial-specific
1481 * initialization for the tty structure.
1483 int rs_open(struct tty_struct
*tty
, struct file
* filp
)
1485 struct dec_serial
*info
;
1488 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1489 if ((line
< 0) || (line
>= zs_channels_found
))
1491 info
= zs_soft
+ line
;
1494 if (info
->kgdb_channel
)
1497 if (serial_paranoia_check(info
, tty
->device
, "rs_open"))
1499 #ifdef SERIAL_DEBUG_OPEN
1500 printk("rs_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
1505 tty
->driver_data
= info
;
1509 * If the port is the middle of closing, bail out now
1511 if (tty_hung_up_p(filp
) ||
1512 (info
->flags
& ZILOG_CLOSING
)) {
1513 if (info
->flags
& ZILOG_CLOSING
)
1514 interruptible_sleep_on(&info
->close_wait
);
1515 #ifdef SERIAL_DO_RESTART
1516 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1517 -EAGAIN
: -ERESTARTSYS
);
1524 * Start up serial port
1526 retval
= startup(info
);
1530 retval
= block_til_ready(tty
, filp
, info
);
1532 #ifdef SERIAL_DEBUG_OPEN
1533 printk("rs_open returning after block_til_ready with %d\n",
1539 if ((info
->count
== 1) && (info
->flags
& ZILOG_SPLIT_TERMIOS
)) {
1540 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1541 *tty
->termios
= info
->normal_termios
;
1543 *tty
->termios
= info
->callout_termios
;
1546 #ifdef CONFIG_SERIAL_CONSOLE
1547 if (sercons
.cflag
&& sercons
.index
== line
) {
1548 tty
->termios
->c_cflag
= sercons
.cflag
;
1554 info
->session
= current
->session
;
1555 info
->pgrp
= current
->pgrp
;
1557 #ifdef SERIAL_DEBUG_OPEN
1558 printk("rs_open ttys%d successful...", info
->line
);
1560 /* tty->low_latency = 1; */
1564 /* Finally, routines used to initialize the serial driver. */
1566 static void __init
show_serial_version(void)
1568 printk("DECstation Z8530 serial driver version 0.03\n");
1571 /* Initialize Z8530s zs_channels
1574 static void __init
probe_sccs(void)
1576 struct dec_serial
**pp
;
1577 int i
, n
, n_chips
= 0, n_channels
, chip
, channel
;
1578 unsigned long flags
;
1581 * did we get here by accident?
1584 printk("Not on JUNKIO machine, skipping probe_sccs\n");
1589 * When serial console is activated, tc_init has not been called yet
1590 * and system_base is undefined. Unfortunately we have to hardcode
1591 * system_base for this case :-(. HK
1593 switch(mips_machtype
) {
1594 case MACH_DS5000_2X0
:
1595 system_base
= 0xbf800000;
1598 case MACH_DS5000_1XX
:
1599 system_base
= 0xbc000000;
1602 case MACH_DS5000_XX
:
1603 system_base
= 0xbc000000;
1612 for (chip
= 0; chip
< n_chips
; chip
++) {
1613 for (channel
= 0; channel
<= 1; channel
++) {
1615 * The sccs reside on the high byte of the 16 bit IOBUS
1617 zs_channels
[n_channels
].control
= (volatile unsigned char *)
1618 system_base
+ (0 == chip
? SCC0
: SCC1
) + (0 == channel
? 1 : 9);
1619 zs_channels
[n_channels
].data
= zs_channels
[n_channels
].control
+ 4;
1620 zs_soft
[n_channels
].zs_channel
= &zs_channels
[n_channels
];
1621 zs_soft
[n_channels
].irq
= SERIAL
;
1624 zs_soft
[n_channels
].zs_chan_a
= &zs_channels
[n_channels
+1];
1626 zs_soft
[n_channels
].zs_chan_a
= &zs_channels
[n_channels
];
1628 *pp
= &zs_soft
[n_channels
];
1629 pp
= &zs_soft
[n_channels
].zs_next
;
1635 zs_channels_found
= n_channels
;
1637 for (n
= 0; n
< zs_channels_found
; n
++) {
1638 for (i
= 0; i
< 16; i
++) {
1639 zs_soft
[n
].zs_channel
->curregs
[i
] = zs_init_regs
[i
];
1643 /* save_and_cli(flags);
1644 for (n = 0; n < zs_channels_found; n++) {
1645 if (((int)zs_channels[n].control & 0xf) == 1) {
1646 write_zsreg(zs_soft[channel].zs_chan_a, R9, FHWRES);
1648 write_zsreg(zs_soft[channel].zs_chan_a, R9, 0);
1650 load_zsregs(zs_soft[n].zs_channel, zs_soft[n].zs_channel->curregs);
1652 restore_flags(flags); */
1655 /* zs_init inits the driver */
1656 int __init
zs_init(void)
1659 unsigned long flags
;
1660 struct dec_serial
*info
;
1665 /* Setup base handler, and timer table. */
1666 init_bh(SERIAL_BH
, do_serial_bh
);
1667 timer_table
[RS_TIMER
].fn
= rs_timer
;
1668 timer_table
[RS_TIMER
].expires
= 0;
1670 /* Find out how many Z8530 SCCs we have */
1674 show_serial_version();
1676 /* Initialize the tty_driver structure */
1677 /* Not all of this is exactly right for us. */
1679 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
1680 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
1681 serial_driver
.name
= "ttyS";
1682 serial_driver
.major
= TTY_MAJOR
;
1683 serial_driver
.minor_start
= 64;
1684 serial_driver
.num
= zs_channels_found
;
1685 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
1686 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
1687 serial_driver
.init_termios
= tty_std_termios
;
1689 serial_driver
.init_termios
.c_cflag
=
1690 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1691 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
1692 serial_driver
.refcount
= &serial_refcount
;
1693 serial_driver
.table
= serial_table
;
1694 serial_driver
.termios
= serial_termios
;
1695 serial_driver
.termios_locked
= serial_termios_locked
;
1697 serial_driver
.open
= rs_open
;
1698 serial_driver
.close
= rs_close
;
1699 serial_driver
.write
= rs_write
;
1700 serial_driver
.flush_chars
= rs_flush_chars
;
1701 serial_driver
.write_room
= rs_write_room
;
1702 serial_driver
.chars_in_buffer
= rs_chars_in_buffer
;
1703 serial_driver
.flush_buffer
= rs_flush_buffer
;
1704 serial_driver
.ioctl
= rs_ioctl
;
1705 serial_driver
.throttle
= rs_throttle
;
1706 serial_driver
.unthrottle
= rs_unthrottle
;
1707 serial_driver
.set_termios
= rs_set_termios
;
1708 serial_driver
.stop
= rs_stop
;
1709 serial_driver
.start
= rs_start
;
1710 serial_driver
.hangup
= rs_hangup
;
1711 serial_driver
.break_ctl
= rs_break
;
1712 serial_driver
.wait_until_sent
= rs_wait_until_sent
;
1715 * The callout device is just like normal device except for
1716 * major number and the subtype code.
1718 callout_driver
= serial_driver
;
1719 callout_driver
.name
= "cua";
1720 callout_driver
.major
= TTYAUX_MAJOR
;
1721 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
1723 if (tty_register_driver(&serial_driver
))
1724 panic("Couldn't register serial driver\n");
1725 if (tty_register_driver(&callout_driver
))
1726 panic("Couldn't register callout driver\n");
1728 save_flags(flags
); cli();
1730 for (channel
= 0; channel
< zs_channels_found
; ++channel
) {
1732 if (zs_soft
[channel
].kgdb_channel
) {
1736 zs_soft
[channel
].clk_divisor
= 16;
1737 zs_soft
[channel
].zs_baud
= get_zsbaud(&zs_soft
[channel
]);
1739 if (request_irq(SERIAL
, rs_interrupt
, SA_SHIRQ
,
1740 "SCC", &zs_soft
[channel
]))
1741 printk(KERN_ERR
"decserial: can't get irq %d\n",
1744 /* If console serial line, then enable interrupts. */
1745 /* if (zs_soft[channel].is_cons) {
1746 write_zsreg(zs_soft[channel].zs_channel, R1,
1747 (EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB));
1748 write_zsreg(zs_soft[channel].zs_channel, R9,
1754 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++)
1757 if (info
->kgdb_channel
) {
1761 info
->magic
= SERIAL_MAGIC
;
1762 info
->port
= (int) info
->zs_channel
->control
;
1765 info
->custom_divisor
= 16;
1766 info
->close_delay
= 50;
1767 info
->closing_wait
= 3000;
1771 info
->blocked_open
= 0;
1772 info
->tqueue
.routine
= do_softint
;
1773 info
->tqueue
.data
= info
;
1774 info
->callout_termios
=callout_driver
.init_termios
;
1775 info
->normal_termios
= serial_driver
.init_termios
;
1776 info
->open_wait
= 0;
1777 info
->close_wait
= 0;
1778 printk("tty%02d at 0x%08x (irq = %d)", info
->line
,
1779 info
->port
, info
->irq
);
1780 printk(" is a Z85C30 SCC\n");
1783 restore_flags(flags
);
1789 * register_serial and unregister_serial allows for serial ports to be
1790 * configured at run-time, to support PCMCIA modems.
1792 /* PowerMac: Unused at this time, just here to make things link. */
1793 int register_serial(struct serial_struct
*req
)
1798 void unregister_serial(int line
)
1804 * ------------------------------------------------------------
1805 * Serial console driver
1806 * ------------------------------------------------------------
1808 #ifdef CONFIG_SERIAL_CONSOLE
1812 * Print a string to the serial port trying not to disturb
1813 * any possible real use of the port...
1816 /* This is for console output */
1818 zs_console_putchar(struct dec_serial
*info
, char ch
)
1821 unsigned long flags
;
1823 if(!info
->zs_channel
)
1826 save_flags(flags
); cli();
1828 while (!(*(info
->zs_channel
->control
) & Tx_BUF_EMP
) && --loops
)
1830 *(info
->zs_channel
->data
) = ch
;
1833 restore_flags(flags
);
1836 static void serial_console_write(struct console
*co
, const char *s
,
1839 struct dec_serial
*info
;
1843 info
= zs_soft
+ co
->index
;
1847 * disable master interrupt if necessary
1849 nine
= info
->zs_channel
->curregs
[9];
1851 write_zsreg(info
->zs_channel
, R9
, nine
& ~MIE
);
1856 for (i
= 0; i
< count
; i
++, s
++) {
1858 zs_console_putchar(info
, '\r');
1859 zs_console_putchar(info
, *s
);
1862 * restore master interrupt enable
1865 write_zsreg(info
->zs_channel
, R9
, nine
);
1870 * Receive character from the serial port
1872 static int serial_console_wait_key(struct console
*co
)
1877 static kdev_t
serial_console_device(struct console
*c
)
1879 return MKDEV(TTY_MAJOR
, 64 + c
->index
);
1883 * Setup initial baud/bits/parity. We do two things here:
1884 * - construct a cflag setting for the first rs_open()
1885 * - initialize the serial port
1886 * Return non-zero if we didn't find a serial port.
1888 static int __init
serial_console_setup(struct console
*co
, char *options
)
1890 struct dec_serial
*info
;
1894 int cflag
= CREAD
| HUPCL
| CLOCAL
;
1896 unsigned long flags
;
1901 info
= zs_soft
+ co
->index
;
1909 baud
= simple_strtoul(options
, NULL
, 10);
1911 while(*s
>= '0' && *s
<= '9')
1920 * Now construct a cflag setting.
1968 save_and_cli(flags
);
1971 * Turn on RTS and DTR.
1976 * Finally, enable sequencing
1978 info
->zs_channel
->curregs
[3] |= (RxENABLE
| Rx8
);
1979 info
->zs_channel
->curregs
[5] |= (TxENAB
| Tx8
);
1980 info
->zs_channel
->curregs
[9] |= (VIS
);
1981 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
1982 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
1983 write_zsreg(info
->zs_channel
, 9, info
->zs_channel
->curregs
[9]);
1986 * Clear the interrupt registers.
1988 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
1989 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
1992 * Set the speed of the serial port
1996 /* Save the current value of RR0 */
1997 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
1999 zs_soft
[co
->index
].clk_divisor
= 16;
2000 zs_soft
[co
->index
].zs_baud
= get_zsbaud(&zs_soft
[co
->index
]);
2002 restore_flags(flags
);
2007 static struct console sercons
= {
2009 serial_console_write
,
2011 serial_console_device
,
2012 serial_console_wait_key
,
2014 serial_console_setup
,
2024 long __init
zs_serial_console_init(long kmem_start
, long kmem_end
)
2026 register_console(&sercons
);
2029 #endif /* ifdef CONFIG_SERIAL_CONSOLE */
2032 /* These are for receiving and sending characters under the kgdb
2033 * source level kernel debugger.
2035 void putDebugChar(char kgdb_char
)
2037 struct dec_zschannel
*chan
= zs_kgdbchan
;
2038 while ((read_zsreg(chan
, 0) & Tx_BUF_EMP
) == 0)
2040 write_zsdata(chan
, kgdb_char
);
2042 char getDebugChar(void)
2044 struct dec_zschannel
*chan
= zs_kgdbchan
;
2045 while((read_zsreg(chan
, 0) & Rx_CH_AV
) == 0)
2046 eieio(); /*barrier();*/
2047 return read_zsdata(chan
);
2049 void kgdb_interruptible(int yes
)
2051 struct dec_zschannel
*chan
= zs_kgdbchan
;
2053 nine
= read_zsreg(chan
, 9);
2055 one
= EXT_INT_ENAB
|INT_ALL_Rx
;
2057 printk("turning serial ints on\n");
2061 printk("turning serial ints off\n");
2063 write_zsreg(chan
, 1, one
);
2064 write_zsreg(chan
, 9, nine
);
2066 /* This sets up the serial port we're using, and turns on
2067 * interrupts for that channel, so kgdb is usable once we're done.
2069 static inline void kgdb_chaninit(struct dec_zschannel
*ms
, int intson
, int bps
)
2073 volatile char *sccc
= ms
->control
;
2074 brg
= BPS_TO_BRG(bps
, ZS_CLOCK
/16);
2075 printk("setting bps on kgdb line to %d [brg=%x]\n", bps
, brg
);
2076 for (i
= 20000; i
!= 0; --i
) {
2079 for (i
= 0; i
< sizeof(scc_inittab
); ++i
) {
2080 write_zsreg(ms
, scc_inittab
[i
], scc_inittab
[i
+1]);
2084 /* This is called at boot time to prime the kgdb serial debugging
2085 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2086 * for /dev/ttyb which is determined in setup_arch() from the
2087 * boot command line flags.
2089 void __init
zs_kgdb_hook(int tty_num
)
2091 /* Find out how many Z8530 SCCs we have */
2094 zs_soft
[tty_num
].zs_channel
= &zs_channels
[tty_num
];
2095 zs_kgdbchan
= zs_soft
[tty_num
].zs_channel
;
2096 zs_soft
[tty_num
].change_needed
= 0;
2097 zs_soft
[tty_num
].clk_divisor
= 16;
2098 zs_soft
[tty_num
].zs_baud
= 38400;
2099 zs_soft
[tty_num
].kgdb_channel
= 1; /* This runs kgdb */
2100 zs_soft
[tty_num
^ 1].kgdb_channel
= 0; /* This does not */
2101 /* Turn on transmitter/receiver at 8-bits/char */
2102 kgdb_chaninit(zs_soft
[tty_num
].zs_channel
, 1, 38400);
2103 printk("KGDB: on channel %d initialized\n", tty_num
);
2104 set_debug_traps(); /* init stub */
2106 #endif /* ifdef CONFIG_KGDB */