2 * decserial.c: Serial port driver for IOASIC DECstations.
4 * Derived from drivers/sbus/char/sunserial.c by Paul Mackerras.
5 * Derived from drivers/macintosh/macserial.c by Harald Koerfgen.
8 * Copyright (C) 1998-2000 Harald Koerfgen
9 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Maciej W. Rozycki
11 * For the rest of the code the original Copyright applies:
12 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
13 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
16 * Note: for IOASIC systems the wiring is as follows:
19 * DIN-7 MJ-4 signal SCC
24 * DB-25 MMJ-6 signal SCC
31 * 12 DSRS(DCE) -> ~A.CTS (*)
36 * 23 DSRS(DTE) <- ~B.RTS
38 * (*) EIA-232 defines the signal at this pin to be SCD, while DSRS(DCE)
39 * is shared with DSRS(DTE) at pin 23.
42 #include <linux/config.h>
43 #include <linux/errno.h>
44 #include <linux/signal.h>
45 #include <linux/sched.h>
46 #include <linux/timer.h>
47 #include <linux/interrupt.h>
48 #include <linux/tty.h>
49 #include <linux/tty_flip.h>
50 #include <linux/major.h>
51 #include <linux/string.h>
52 #include <linux/fcntl.h>
54 #include <linux/kernel.h>
55 #include <linux/delay.h>
56 #include <linux/init.h>
57 #include <linux/ioport.h>
58 #include <linux/spinlock.h>
59 #ifdef CONFIG_SERIAL_DEC_CONSOLE
60 #include <linux/console.h>
64 #include <asm/pgtable.h>
66 #include <asm/system.h>
67 #include <asm/bootinfo.h>
69 #include <asm/dec/interrupts.h>
70 #include <asm/dec/ioasic_addrs.h>
71 #include <asm/dec/machtype.h>
72 #include <asm/dec/serial.h>
73 #include <asm/dec/system.h>
74 #include <asm/dec/tc.h>
79 #ifdef CONFIG_MAGIC_SYSRQ
80 #include <linux/sysrq.h>
86 * It would be nice to dynamically allocate everything that
87 * depends on NUM_SERIAL, so we could support any number of
88 * Z8530s, but for now...
90 #define NUM_SERIAL 2 /* Max number of ZS chips supported */
91 #define NUM_CHANNELS (NUM_SERIAL * 2) /* 2 channels per chip */
92 #define CHANNEL_A_NR (zs_parms->channel_a_offset > zs_parms->channel_b_offset)
93 /* Number of channel A in the chip */
94 #define ZS_CHAN_IO_SIZE 8
95 #define ZS_CLOCK 7372800 /* Z8530 RTxC input clock rate */
97 #define RECOVERY_DELAY udelay(2)
102 int channel_a_offset
;
103 int channel_b_offset
;
109 static struct zs_parms
*zs_parms
;
111 #ifdef CONFIG_MACH_DECSTATION
112 static struct zs_parms ds_parms
= {
115 channel_a_offset
: 1,
116 channel_b_offset
: 9,
123 #ifdef CONFIG_MACH_DECSTATION
124 #define DS_BUS_PRESENT (IOASIC)
126 #define DS_BUS_PRESENT 0
129 #define BUS_PRESENT (DS_BUS_PRESENT)
131 DEFINE_SPINLOCK(zs_lock
);
133 struct dec_zschannel zs_channels
[NUM_CHANNELS
];
134 struct dec_serial zs_soft
[NUM_CHANNELS
];
135 int zs_channels_found
;
136 struct dec_serial
*zs_chain
; /* list of all channels */
138 struct tty_struct zs_ttys
[NUM_CHANNELS
];
140 #ifdef CONFIG_SERIAL_DEC_CONSOLE
141 static struct console sercons
;
143 #if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
145 static unsigned long break_pressed
; /* break, really ... */
148 static unsigned char zs_init_regs
[16] __initdata
= {
153 (X16CLK
), /* write 4 */
155 0, 0, 0, /* write 6, 7, 8 */
156 (MIE
| DLC
| NV
), /* write 9 */
157 (NRZ
), /* write 10 */
158 (TCBR
| RCBR
), /* write 11 */
159 0, 0, /* BRG time constant, write 12 + 13 */
160 (BRSRC
| BRENABL
), /* write 14 */
164 static struct tty_driver
*serial_driver
;
166 /* serial subtype definitions */
167 #define SERIAL_TYPE_NORMAL 1
169 /* number of characters left in xmit buffer before we ask for more */
170 #define WAKEUP_CHARS 256
175 #undef SERIAL_DEBUG_OPEN
176 #undef SERIAL_DEBUG_FLOW
177 #undef SERIAL_DEBUG_THROTTLE
178 #undef SERIAL_PARANOIA_CHECK
182 #ifdef SERIAL_DEBUG_THROTTLE
183 #define _tty_name(tty,buf) tty_name(tty,buf)
186 #define RS_STROBE_TIME 10
187 #define RS_ISR_PASS_LIMIT 256
189 #define _INLINE_ inline
191 static void probe_sccs(void);
192 static void change_speed(struct dec_serial
*info
);
193 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
195 static inline int serial_paranoia_check(struct dec_serial
*info
,
196 char *name
, const char *routine
)
198 #ifdef SERIAL_PARANOIA_CHECK
199 static const char *badmagic
=
200 "Warning: bad magic number for serial struct %s in %s\n";
201 static const char *badinfo
=
202 "Warning: null mac_serial for %s in %s\n";
205 printk(badinfo
, name
, routine
);
208 if (info
->magic
!= SERIAL_MAGIC
) {
209 printk(badmagic
, name
, routine
);
217 * This is used to figure out the divisor speeds and the timeouts
219 static int baud_table
[] = {
220 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
221 9600, 19200, 38400, 57600, 115200, 0 };
224 * Reading and writing Z8530 registers.
226 static inline unsigned char read_zsreg(struct dec_zschannel
*channel
,
229 unsigned char retval
;
232 *channel
->control
= reg
& 0xf;
233 fast_iob(); RECOVERY_DELAY
;
235 retval
= *channel
->control
;
240 static inline void write_zsreg(struct dec_zschannel
*channel
,
241 unsigned char reg
, unsigned char value
)
244 *channel
->control
= reg
& 0xf;
245 fast_iob(); RECOVERY_DELAY
;
247 *channel
->control
= value
;
248 fast_iob(); RECOVERY_DELAY
;
252 static inline unsigned char read_zsdata(struct dec_zschannel
*channel
)
254 unsigned char retval
;
256 retval
= *channel
->data
;
261 static inline void write_zsdata(struct dec_zschannel
*channel
,
264 *channel
->data
= value
;
265 fast_iob(); RECOVERY_DELAY
;
269 static inline void load_zsregs(struct dec_zschannel
*channel
,
272 /* ZS_CLEARERR(channel);
273 ZS_CLEARFIFO(channel); */
275 write_zsreg(channel
, R3
, regs
[R3
] & ~RxENABLE
);
276 write_zsreg(channel
, R5
, regs
[R5
] & ~TxENAB
);
277 write_zsreg(channel
, R4
, regs
[R4
]);
278 write_zsreg(channel
, R9
, regs
[R9
]);
279 write_zsreg(channel
, R1
, regs
[R1
]);
280 write_zsreg(channel
, R2
, regs
[R2
]);
281 write_zsreg(channel
, R10
, regs
[R10
]);
282 write_zsreg(channel
, R11
, regs
[R11
]);
283 write_zsreg(channel
, R12
, regs
[R12
]);
284 write_zsreg(channel
, R13
, regs
[R13
]);
285 write_zsreg(channel
, R14
, regs
[R14
]);
286 write_zsreg(channel
, R15
, regs
[R15
]);
287 write_zsreg(channel
, R3
, regs
[R3
]);
288 write_zsreg(channel
, R5
, regs
[R5
]);
292 /* Sets or clears DTR/RTS on the requested line */
293 static inline void zs_rtsdtr(struct dec_serial
*info
, int which
, int set
)
297 spin_lock_irqsave(&zs_lock
, flags
);
298 if (info
->zs_channel
!= info
->zs_chan_a
) {
300 info
->zs_chan_a
->curregs
[5] |= (which
& (RTS
| DTR
));
302 info
->zs_chan_a
->curregs
[5] &= ~(which
& (RTS
| DTR
));
304 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
306 spin_unlock_irqrestore(&zs_lock
, flags
);
309 /* Utility routines for the Zilog */
310 static inline int get_zsbaud(struct dec_serial
*ss
)
312 struct dec_zschannel
*channel
= ss
->zs_channel
;
315 /* The baud rate is split up between two 8-bit registers in
316 * what is termed 'BRG time constant' format in my docs for
317 * the chip, it is a function of the clk rate the chip is
318 * receiving which happens to be constant.
320 brg
= (read_zsreg(channel
, 13) << 8);
321 brg
|= read_zsreg(channel
, 12);
322 return BRG_TO_BPS(brg
, (zs_parms
->clock
/(ss
->clk_divisor
)));
325 /* On receive, this clears errors and the receiver interrupts */
326 static inline void rs_recv_clear(struct dec_zschannel
*zsc
)
328 write_zsreg(zsc
, 0, ERR_RES
);
329 write_zsreg(zsc
, 0, RES_H_IUS
); /* XXX this is unnecessary */
333 * ----------------------------------------------------------------------
335 * Here starts the interrupt handling routines. All of the following
336 * subroutines are declared as inline and are folded into
337 * rs_interrupt(). They were separated out for readability's sake.
339 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
340 * -----------------------------------------------------------------------
344 * This routine is used by the interrupt handler to schedule
345 * processing in the software interrupt portion of the driver.
347 static _INLINE_
void rs_sched_event(struct dec_serial
*info
, int event
)
349 info
->event
|= 1 << event
;
350 tasklet_schedule(&info
->tlet
);
353 static _INLINE_
void receive_chars(struct dec_serial
*info
,
354 struct pt_regs
*regs
)
356 struct tty_struct
*tty
= info
->tty
;
357 unsigned char ch
, stat
, flag
;
359 while ((read_zsreg(info
->zs_channel
, R0
) & Rx_CH_AV
) != 0) {
361 stat
= read_zsreg(info
->zs_channel
, R1
);
362 ch
= read_zsdata(info
->zs_channel
);
364 if (!tty
&& (!info
->hook
|| !info
->hook
->rx_char
))
368 if (info
->tty_break
) {
371 if (info
->flags
& ZILOG_SAK
)
373 /* Ignore the null char got when BREAK is removed. */
379 } else if (stat
& FRM_ERR
) {
381 } else if (stat
& PAR_ERR
) {
384 if (flag
!= TTY_NORMAL
)
385 /* reset the error indication */
386 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
389 #if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
391 if (break_pressed
&& info
->line
== sercons
.index
) {
392 /* Ignore the null char got when BREAK is removed. */
395 if (time_before(jiffies
, break_pressed
+ HZ
* 5)) {
396 handle_sysrq(ch
, regs
, NULL
);
404 if (info
->hook
&& info
->hook
->rx_char
) {
405 (*info
->hook
->rx_char
)(ch
, flag
);
409 tty_insert_flip_char(tty
, ch
, flag
);
412 tty_flip_buffer_push(tty
);
415 static void transmit_chars(struct dec_serial
*info
)
417 if ((read_zsreg(info
->zs_channel
, R0
) & Tx_BUF_EMP
) == 0)
423 write_zsdata(info
->zs_channel
, info
->x_char
);
429 if ((info
->xmit_cnt
<= 0) || (info
->tty
&& info
->tty
->stopped
)
430 || info
->tx_stopped
) {
431 write_zsreg(info
->zs_channel
, R0
, RES_Tx_P
);
435 write_zsdata(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
436 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
440 if (info
->xmit_cnt
< WAKEUP_CHARS
)
441 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
444 static _INLINE_
void status_handle(struct dec_serial
*info
)
448 /* Get status from Read Register 0 */
449 stat
= read_zsreg(info
->zs_channel
, R0
);
451 if ((stat
& BRK_ABRT
) && !(info
->read_reg_zero
& BRK_ABRT
)) {
452 #if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
454 if (info
->line
== sercons
.index
) {
456 break_pressed
= jiffies
;
462 if (info
->zs_channel
!= info
->zs_chan_a
) {
464 /* Check for DCD transitions */
465 if (info
->tty
&& !C_CLOCAL(info
->tty
) &&
466 ((stat
^ info
->read_reg_zero
) & DCD
) != 0 ) {
468 wake_up_interruptible(&info
->open_wait
);
470 tty_hangup(info
->tty
);
474 /* Check for CTS transitions */
475 if (info
->tty
&& C_CRTSCTS(info
->tty
)) {
476 if ((stat
& CTS
) != 0) {
477 if (info
->tx_stopped
) {
478 info
->tx_stopped
= 0;
479 if (!info
->tx_active
)
480 transmit_chars(info
);
483 info
->tx_stopped
= 1;
489 /* Clear status condition... */
490 write_zsreg(info
->zs_channel
, R0
, RES_EXT_INT
);
491 info
->read_reg_zero
= stat
;
495 * This is the serial driver's generic interrupt routine
497 static irqreturn_t
rs_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
499 struct dec_serial
*info
= (struct dec_serial
*) dev_id
;
500 irqreturn_t status
= IRQ_NONE
;
501 unsigned char zs_intreg
;
504 /* NOTE: The read register 3, which holds the irq status,
505 * does so for both channels on each chip. Although
506 * the status value itself must be read from the A
507 * channel and is only valid when read from channel A.
508 * Yes... broken hardware...
510 #define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
512 if (info
->zs_chan_a
== info
->zs_channel
)
513 shift
= 3; /* Channel A */
515 shift
= 0; /* Channel B */
518 zs_intreg
= read_zsreg(info
->zs_chan_a
, R3
) >> shift
;
519 if ((zs_intreg
& CHAN_IRQMASK
) == 0)
522 status
= IRQ_HANDLED
;
524 if (zs_intreg
& CHBRxIP
) {
525 receive_chars(info
, regs
);
527 if (zs_intreg
& CHBTxIP
) {
528 transmit_chars(info
);
530 if (zs_intreg
& CHBEXT
) {
535 /* Why do we need this ? */
536 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
542 void zs_dump (void) {
544 for (i
= 0; i
< zs_channels_found
; i
++) {
545 struct dec_zschannel
*ch
= &zs_channels
[i
];
546 if ((long)ch
->control
== UNI_IO_BASE
+UNI_SCC1A_CTRL
) {
547 for (j
= 0; j
< 15; j
++) {
548 printk("W%d = 0x%x\t",
549 j
, (int)ch
->curregs
[j
]);
551 for (j
= 0; j
< 15; j
++) {
552 printk("R%d = 0x%x\t",
553 j
, (int)read_zsreg(ch
,j
));
562 * -------------------------------------------------------------------
563 * Here ends the serial interrupt routines.
564 * -------------------------------------------------------------------
568 * ------------------------------------------------------------
569 * rs_stop() and rs_start()
571 * This routines are called before setting or resetting tty->stopped.
572 * ------------------------------------------------------------
574 static void rs_stop(struct tty_struct
*tty
)
576 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
579 if (serial_paranoia_check(info
, tty
->name
, "rs_stop"))
583 spin_lock_irqsave(&zs_lock
, flags
);
584 if (info
->zs_channel
->curregs
[5] & TxENAB
) {
585 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
586 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
588 spin_unlock_irqrestore(&zs_lock
, flags
);
592 static void rs_start(struct tty_struct
*tty
)
594 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
597 if (serial_paranoia_check(info
, tty
->name
, "rs_start"))
600 spin_lock_irqsave(&zs_lock
, flags
);
602 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->zs_channel
->curregs
[5] & TxENAB
)) {
603 info
->zs_channel
->curregs
[5] |= TxENAB
;
604 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
607 if (info
->xmit_cnt
&& info
->xmit_buf
&& !info
->tx_active
) {
608 transmit_chars(info
);
611 spin_unlock_irqrestore(&zs_lock
, flags
);
615 * This routine is used to handle the "bottom half" processing for the
616 * serial driver, known also the "software interrupt" processing.
617 * This processing is done at the kernel interrupt level, after the
618 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
619 * is where time-consuming activities which can not be done in the
620 * interrupt driver proper are done; the interrupt driver schedules
621 * them using rs_sched_event(), and they get done here.
624 static void do_softint(unsigned long private_
)
626 struct dec_serial
*info
= (struct dec_serial
*) private_
;
627 struct tty_struct
*tty
;
633 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
635 wake_up_interruptible(&tty
->write_wait
);
639 static int zs_startup(struct dec_serial
* info
)
643 if (info
->flags
& ZILOG_INITIALIZED
)
646 if (!info
->xmit_buf
) {
647 info
->xmit_buf
= (unsigned char *) get_zeroed_page(GFP_KERNEL
);
652 spin_lock_irqsave(&zs_lock
, flags
);
654 #ifdef SERIAL_DEBUG_OPEN
655 printk("starting up ttyS%d (irq %d)...", info
->line
, info
->irq
);
659 * Clear the receive FIFO.
661 ZS_CLEARFIFO(info
->zs_channel
);
662 info
->xmit_fifo_size
= 1;
665 * Clear the interrupt registers.
667 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
668 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
671 * Set the speed of the serial port
676 * Turn on RTS and DTR.
678 zs_rtsdtr(info
, RTS
| DTR
, 1);
681 * Finally, enable sequencing and interrupts
683 info
->zs_channel
->curregs
[R1
] &= ~RxINT_MASK
;
684 info
->zs_channel
->curregs
[R1
] |= (RxINT_ALL
| TxINT_ENAB
|
686 info
->zs_channel
->curregs
[R3
] |= RxENABLE
;
687 info
->zs_channel
->curregs
[R5
] |= TxENAB
;
688 info
->zs_channel
->curregs
[R15
] |= (DCDIE
| CTSIE
| TxUIE
| BRKIE
);
689 write_zsreg(info
->zs_channel
, R1
, info
->zs_channel
->curregs
[R1
]);
690 write_zsreg(info
->zs_channel
, R3
, info
->zs_channel
->curregs
[R3
]);
691 write_zsreg(info
->zs_channel
, R5
, info
->zs_channel
->curregs
[R5
]);
692 write_zsreg(info
->zs_channel
, R15
, info
->zs_channel
->curregs
[R15
]);
695 * And clear the interrupt registers again for luck.
697 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
698 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
700 /* Save the current value of RR0 */
701 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, R0
);
704 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
705 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
707 info
->flags
|= ZILOG_INITIALIZED
;
708 spin_unlock_irqrestore(&zs_lock
, flags
);
713 * This routine will shutdown a serial port; interrupts are disabled, and
714 * DTR is dropped if the hangup on close termio flag is on.
716 static void shutdown(struct dec_serial
* info
)
720 if (!(info
->flags
& ZILOG_INITIALIZED
))
723 #ifdef SERIAL_DEBUG_OPEN
724 printk("Shutting down serial port %d (irq %d)....", info
->line
,
728 spin_lock_irqsave(&zs_lock
, flags
);
730 if (info
->xmit_buf
) {
731 free_page((unsigned long) info
->xmit_buf
);
735 info
->zs_channel
->curregs
[1] = 0;
736 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]); /* no interrupts */
738 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
739 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
741 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
742 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
743 if (!info
->tty
|| C_HUPCL(info
->tty
)) {
744 zs_rtsdtr(info
, RTS
| DTR
, 0);
748 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
750 info
->flags
&= ~ZILOG_INITIALIZED
;
751 spin_unlock_irqrestore(&zs_lock
, flags
);
755 * This routine is called to set the UART divisor registers to match
756 * the specified baud rate for a serial port.
758 static void change_speed(struct dec_serial
*info
)
766 if (!info
->tty
|| !info
->tty
->termios
)
768 cflag
= info
->tty
->termios
->c_cflag
;
772 cflag
= info
->hook
->cflags
;
778 if (i
< 1 || i
> 2) {
780 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
782 info
->hook
->cflags
&= ~CBAUDEX
;
787 spin_lock_irqsave(&zs_lock
, flags
);
788 info
->zs_baud
= baud_table
[i
];
790 brg
= BPS_TO_BRG(info
->zs_baud
, zs_parms
->clock
/info
->clk_divisor
);
791 info
->zs_channel
->curregs
[12] = (brg
& 255);
792 info
->zs_channel
->curregs
[13] = ((brg
>> 8) & 255);
793 zs_rtsdtr(info
, DTR
, 1);
795 zs_rtsdtr(info
, RTS
| DTR
, 0);
799 /* byte size and parity */
800 info
->zs_channel
->curregs
[3] &= ~RxNBITS_MASK
;
801 info
->zs_channel
->curregs
[5] &= ~TxNBITS_MASK
;
802 switch (cflag
& CSIZE
) {
805 info
->zs_channel
->curregs
[3] |= Rx5
;
806 info
->zs_channel
->curregs
[5] |= Tx5
;
810 info
->zs_channel
->curregs
[3] |= Rx6
;
811 info
->zs_channel
->curregs
[5] |= Tx6
;
815 info
->zs_channel
->curregs
[3] |= Rx7
;
816 info
->zs_channel
->curregs
[5] |= Tx7
;
819 default: /* defaults to 8 bits */
821 info
->zs_channel
->curregs
[3] |= Rx8
;
822 info
->zs_channel
->curregs
[5] |= Tx8
;
826 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
) / info
->zs_baud
);
827 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
829 info
->zs_channel
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
830 if (cflag
& CSTOPB
) {
831 info
->zs_channel
->curregs
[4] |= SB2
;
833 info
->zs_channel
->curregs
[4] |= SB1
;
835 if (cflag
& PARENB
) {
836 info
->zs_channel
->curregs
[4] |= PAR_ENA
;
838 if (!(cflag
& PARODD
)) {
839 info
->zs_channel
->curregs
[4] |= PAR_EVEN
;
842 if (!(cflag
& CLOCAL
)) {
843 if (!(info
->zs_channel
->curregs
[15] & DCDIE
))
844 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
845 info
->zs_channel
->curregs
[15] |= DCDIE
;
847 info
->zs_channel
->curregs
[15] &= ~DCDIE
;
848 if (cflag
& CRTSCTS
) {
849 info
->zs_channel
->curregs
[15] |= CTSIE
;
850 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) == 0)
851 info
->tx_stopped
= 1;
853 info
->zs_channel
->curregs
[15] &= ~CTSIE
;
854 info
->tx_stopped
= 0;
857 /* Load up the new values */
858 load_zsregs(info
->zs_channel
, info
->zs_channel
->curregs
);
860 spin_unlock_irqrestore(&zs_lock
, flags
);
863 static void rs_flush_chars(struct tty_struct
*tty
)
865 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
868 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_chars"))
871 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| info
->tx_stopped
||
875 /* Enable transmitter */
876 spin_lock_irqsave(&zs_lock
, flags
);
877 transmit_chars(info
);
878 spin_unlock_irqrestore(&zs_lock
, flags
);
881 static int rs_write(struct tty_struct
* tty
,
882 const unsigned char *buf
, int count
)
885 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
888 if (serial_paranoia_check(info
, tty
->name
, "rs_write"))
891 if (!tty
|| !info
->xmit_buf
)
895 spin_lock_irqsave(&zs_lock
, flags
);
896 c
= min(count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
897 SERIAL_XMIT_SIZE
- info
->xmit_head
));
901 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
902 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
904 spin_unlock_irqrestore(&zs_lock
, flags
);
910 if (info
->xmit_cnt
&& !tty
->stopped
&& !info
->tx_stopped
912 transmit_chars(info
);
913 spin_unlock_irqrestore(&zs_lock
, flags
);
917 static int rs_write_room(struct tty_struct
*tty
)
919 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
922 if (serial_paranoia_check(info
, tty
->name
, "rs_write_room"))
924 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
930 static int rs_chars_in_buffer(struct tty_struct
*tty
)
932 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
934 if (serial_paranoia_check(info
, tty
->name
, "rs_chars_in_buffer"))
936 return info
->xmit_cnt
;
939 static void rs_flush_buffer(struct tty_struct
*tty
)
941 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
943 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_buffer"))
945 spin_lock_irq(&zs_lock
);
946 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
947 spin_unlock_irq(&zs_lock
);
952 * ------------------------------------------------------------
955 * This routine is called by the upper-layer tty layer to signal that
956 * incoming characters should be throttled.
957 * ------------------------------------------------------------
959 static void rs_throttle(struct tty_struct
* tty
)
961 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
964 #ifdef SERIAL_DEBUG_THROTTLE
967 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
968 tty
->ldisc
.chars_in_buffer(tty
));
971 if (serial_paranoia_check(info
, tty
->name
, "rs_throttle"))
975 spin_lock_irqsave(&zs_lock
, flags
);
976 info
->x_char
= STOP_CHAR(tty
);
977 if (!info
->tx_active
)
978 transmit_chars(info
);
979 spin_unlock_irqrestore(&zs_lock
, flags
);
982 if (C_CRTSCTS(tty
)) {
983 zs_rtsdtr(info
, RTS
, 0);
987 static void rs_unthrottle(struct tty_struct
* tty
)
989 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
992 #ifdef SERIAL_DEBUG_THROTTLE
995 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
996 tty
->ldisc
.chars_in_buffer(tty
));
999 if (serial_paranoia_check(info
, tty
->name
, "rs_unthrottle"))
1003 spin_lock_irqsave(&zs_lock
, flags
);
1007 info
->x_char
= START_CHAR(tty
);
1008 if (!info
->tx_active
)
1009 transmit_chars(info
);
1011 spin_unlock_irqrestore(&zs_lock
, flags
);
1014 if (C_CRTSCTS(tty
)) {
1015 zs_rtsdtr(info
, RTS
, 1);
1020 * ------------------------------------------------------------
1021 * rs_ioctl() and friends
1022 * ------------------------------------------------------------
1025 static int get_serial_info(struct dec_serial
* info
,
1026 struct serial_struct
* retinfo
)
1028 struct serial_struct tmp
;
1032 memset(&tmp
, 0, sizeof(tmp
));
1033 tmp
.type
= info
->type
;
1034 tmp
.line
= info
->line
;
1035 tmp
.port
= info
->port
;
1036 tmp
.irq
= info
->irq
;
1037 tmp
.flags
= info
->flags
;
1038 tmp
.baud_base
= info
->baud_base
;
1039 tmp
.close_delay
= info
->close_delay
;
1040 tmp
.closing_wait
= info
->closing_wait
;
1041 tmp
.custom_divisor
= info
->custom_divisor
;
1042 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)) ? -EFAULT
: 0;
1045 static int set_serial_info(struct dec_serial
* info
,
1046 struct serial_struct
* new_info
)
1048 struct serial_struct new_serial
;
1049 struct dec_serial old_info
;
1054 copy_from_user(&new_serial
,new_info
,sizeof(new_serial
));
1057 if (!capable(CAP_SYS_ADMIN
)) {
1058 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1059 (new_serial
.type
!= info
->type
) ||
1060 (new_serial
.close_delay
!= info
->close_delay
) ||
1061 ((new_serial
.flags
& ~ZILOG_USR_MASK
) !=
1062 (info
->flags
& ~ZILOG_USR_MASK
)))
1064 info
->flags
= ((info
->flags
& ~ZILOG_USR_MASK
) |
1065 (new_serial
.flags
& ZILOG_USR_MASK
));
1066 info
->custom_divisor
= new_serial
.custom_divisor
;
1067 goto check_and_exit
;
1070 if (info
->count
> 1)
1074 * OK, past this point, all the error checking has been done.
1075 * At this point, we start making changes.....
1078 info
->baud_base
= new_serial
.baud_base
;
1079 info
->flags
= ((info
->flags
& ~ZILOG_FLAGS
) |
1080 (new_serial
.flags
& ZILOG_FLAGS
));
1081 info
->type
= new_serial
.type
;
1082 info
->close_delay
= new_serial
.close_delay
;
1083 info
->closing_wait
= new_serial
.closing_wait
;
1086 retval
= zs_startup(info
);
1091 * get_lsr_info - get line status register info
1093 * Purpose: Let user call ioctl() to get info when the UART physically
1094 * is emptied. On bus types like RS485, the transmitter must
1095 * release the bus after transmitting. This must be done when
1096 * the transmit shift register is empty, not be done when the
1097 * transmit holding register is empty. This functionality
1098 * allows an RS485 driver to be written in user space.
1100 static int get_lsr_info(struct dec_serial
* info
, unsigned int *value
)
1102 unsigned char status
;
1104 spin_lock(&zs_lock
);
1105 status
= read_zsreg(info
->zs_channel
, 0);
1106 spin_unlock_irq(&zs_lock
);
1107 put_user(status
,value
);
1111 static int rs_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1113 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1114 unsigned char control
, status_a
, status_b
;
1115 unsigned int result
;
1120 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1123 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1126 if (info
->zs_channel
== info
->zs_chan_a
)
1129 spin_lock(&zs_lock
);
1130 control
= info
->zs_chan_a
->curregs
[5];
1131 status_a
= read_zsreg(info
->zs_chan_a
, 0);
1132 status_b
= read_zsreg(info
->zs_channel
, 0);
1133 spin_unlock_irq(&zs_lock
);
1134 result
= ((control
& RTS
) ? TIOCM_RTS
: 0)
1135 | ((control
& DTR
) ? TIOCM_DTR
: 0)
1136 | ((status_b
& DCD
) ? TIOCM_CAR
: 0)
1137 | ((status_a
& DCD
) ? TIOCM_RNG
: 0)
1138 | ((status_a
& SYNC_HUNT
) ? TIOCM_DSR
: 0)
1139 | ((status_b
& CTS
) ? TIOCM_CTS
: 0);
1144 static int rs_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1145 unsigned int set
, unsigned int clear
)
1147 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1152 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1155 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1158 if (info
->zs_channel
== info
->zs_chan_a
)
1161 spin_lock(&zs_lock
);
1162 if (set
& TIOCM_RTS
)
1163 info
->zs_chan_a
->curregs
[5] |= RTS
;
1164 if (set
& TIOCM_DTR
)
1165 info
->zs_chan_a
->curregs
[5] |= DTR
;
1166 if (clear
& TIOCM_RTS
)
1167 info
->zs_chan_a
->curregs
[5] &= ~RTS
;
1168 if (clear
& TIOCM_DTR
)
1169 info
->zs_chan_a
->curregs
[5] &= ~DTR
;
1170 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
1171 spin_unlock_irq(&zs_lock
);
1176 * rs_break - turn transmit break condition on/off
1178 static void rs_break(struct tty_struct
*tty
, int break_state
)
1180 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1181 unsigned long flags
;
1183 if (serial_paranoia_check(info
, tty
->name
, "rs_break"))
1188 spin_lock_irqsave(&zs_lock
, flags
);
1189 if (break_state
== -1)
1190 info
->zs_channel
->curregs
[5] |= SND_BRK
;
1192 info
->zs_channel
->curregs
[5] &= ~SND_BRK
;
1193 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
1194 spin_unlock_irqrestore(&zs_lock
, flags
);
1197 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1198 unsigned int cmd
, unsigned long arg
)
1200 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1205 if (serial_paranoia_check(info
, tty
->name
, "rs_ioctl"))
1208 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1209 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1210 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1211 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1217 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1218 sizeof(struct serial_struct
)))
1220 return get_serial_info(info
, (struct serial_struct
*)arg
);
1223 return set_serial_info(info
, (struct serial_struct
*)arg
);
1225 case TIOCSERGETLSR
: /* Get line status register */
1226 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1227 sizeof(unsigned int)))
1229 return get_lsr_info(info
, (unsigned int *)arg
);
1231 case TIOCSERGSTRUCT
:
1232 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1233 sizeof(struct dec_serial
)))
1235 copy_from_user((struct dec_serial
*)arg
, info
,
1236 sizeof(struct dec_serial
));
1240 return -ENOIOCTLCMD
;
1245 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1247 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
1250 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1252 was_stopped
= info
->tx_stopped
;
1256 if (was_stopped
&& !info
->tx_stopped
)
1261 * ------------------------------------------------------------
1264 * This routine is called when the serial port gets closed.
1265 * Wait for the last remaining data to be sent.
1266 * ------------------------------------------------------------
1268 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
1270 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1271 unsigned long flags
;
1273 if (!info
|| serial_paranoia_check(info
, tty
->name
, "rs_close"))
1276 spin_lock_irqsave(&zs_lock
, flags
);
1278 if (tty_hung_up_p(filp
)) {
1279 spin_unlock_irqrestore(&zs_lock
, flags
);
1283 #ifdef SERIAL_DEBUG_OPEN
1284 printk("rs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1286 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1288 * Uh, oh. tty->count is 1, which means that the tty
1289 * structure will be freed. Info->count should always
1290 * be one in these conditions. If it's greater than
1291 * one, we've got real problems, since it means the
1292 * serial port won't be shutdown.
1294 printk("rs_close: bad serial port count; tty->count is 1, "
1295 "info->count is %d\n", info
->count
);
1298 if (--info
->count
< 0) {
1299 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1300 info
->line
, info
->count
);
1304 spin_unlock_irqrestore(&zs_lock
, flags
);
1307 info
->flags
|= ZILOG_CLOSING
;
1309 * Now we wait for the transmit buffer to clear; and we notify
1310 * the line discipline to only process XON/XOFF characters.
1313 if (info
->closing_wait
!= ZILOG_CLOSING_WAIT_NONE
)
1314 tty_wait_until_sent(tty
, info
->closing_wait
);
1316 * At this point we stop accepting input. To do this, we
1317 * disable the receiver and receive interrupts.
1319 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
1320 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
1321 info
->zs_channel
->curregs
[1] = 0; /* disable any rx ints */
1322 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]);
1323 ZS_CLEARFIFO(info
->zs_channel
);
1324 if (info
->flags
& ZILOG_INITIALIZED
) {
1326 * Before we drop DTR, make sure the SCC transmitter
1327 * has completely drained.
1329 rs_wait_until_sent(tty
, info
->timeout
);
1333 if (tty
->driver
->flush_buffer
)
1334 tty
->driver
->flush_buffer(tty
);
1335 tty_ldisc_flush(tty
);
1339 if (info
->blocked_open
) {
1340 if (info
->close_delay
) {
1341 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
1343 wake_up_interruptible(&info
->open_wait
);
1345 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CLOSING
);
1346 wake_up_interruptible(&info
->close_wait
);
1347 spin_unlock_irqrestore(&zs_lock
, flags
);
1351 * rs_wait_until_sent() --- wait until the transmitter is empty
1353 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1355 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1356 unsigned long orig_jiffies
;
1359 if (serial_paranoia_check(info
, tty
->name
, "rs_wait_until_sent"))
1362 orig_jiffies
= jiffies
;
1364 * Set the check interval to be 1/5 of the estimated time to
1365 * send a single character, and make it at least 1. The check
1366 * interval should also be less than the timeout.
1368 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1369 char_time
= char_time
/ 5;
1373 char_time
= min(char_time
, timeout
);
1374 while ((read_zsreg(info
->zs_channel
, 1) & Tx_BUF_EMP
) == 0) {
1375 msleep_interruptible(jiffies_to_msecs(char_time
));
1376 if (signal_pending(current
))
1378 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1381 current
->state
= TASK_RUNNING
;
1385 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1387 static void rs_hangup(struct tty_struct
*tty
)
1389 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1391 if (serial_paranoia_check(info
, tty
->name
, "rs_hangup"))
1394 rs_flush_buffer(tty
);
1398 info
->flags
&= ~ZILOG_NORMAL_ACTIVE
;
1400 wake_up_interruptible(&info
->open_wait
);
1404 * ------------------------------------------------------------
1405 * rs_open() and friends
1406 * ------------------------------------------------------------
1408 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1409 struct dec_serial
*info
)
1411 DECLARE_WAITQUEUE(wait
, current
);
1416 * If the device is in the middle of being closed, then block
1417 * until it's done, and then try again.
1419 if (info
->flags
& ZILOG_CLOSING
) {
1420 interruptible_sleep_on(&info
->close_wait
);
1421 #ifdef SERIAL_DO_RESTART
1422 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1423 -EAGAIN
: -ERESTARTSYS
);
1430 * If non-blocking mode is set, or the port is not enabled,
1431 * then make the check up front and then exit.
1433 if ((filp
->f_flags
& O_NONBLOCK
) ||
1434 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1435 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1439 if (tty
->termios
->c_cflag
& CLOCAL
)
1443 * Block waiting for the carrier detect and the line to become
1444 * free (i.e., not in use by the callout). While we are in
1445 * this loop, info->count is dropped by one, so that
1446 * rs_close() knows when to free things. We restore it upon
1447 * exit, either normal or abnormal.
1450 add_wait_queue(&info
->open_wait
, &wait
);
1451 #ifdef SERIAL_DEBUG_OPEN
1452 printk("block_til_ready before block: ttyS%d, count = %d\n",
1453 info
->line
, info
->count
);
1455 spin_lock(&zs_lock
);
1456 if (!tty_hung_up_p(filp
))
1458 spin_unlock_irq(&zs_lock
);
1459 info
->blocked_open
++;
1461 spin_lock(&zs_lock
);
1462 if (tty
->termios
->c_cflag
& CBAUD
)
1463 zs_rtsdtr(info
, RTS
| DTR
, 1);
1464 spin_unlock_irq(&zs_lock
);
1465 set_current_state(TASK_INTERRUPTIBLE
);
1466 if (tty_hung_up_p(filp
) ||
1467 !(info
->flags
& ZILOG_INITIALIZED
)) {
1468 #ifdef SERIAL_DO_RESTART
1469 if (info
->flags
& ZILOG_HUP_NOTIFY
)
1472 retval
= -ERESTARTSYS
;
1478 if (!(info
->flags
& ZILOG_CLOSING
) &&
1479 (do_clocal
|| (read_zsreg(info
->zs_channel
, 0) & DCD
)))
1481 if (signal_pending(current
)) {
1482 retval
= -ERESTARTSYS
;
1485 #ifdef SERIAL_DEBUG_OPEN
1486 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1487 info
->line
, info
->count
);
1491 current
->state
= TASK_RUNNING
;
1492 remove_wait_queue(&info
->open_wait
, &wait
);
1493 if (!tty_hung_up_p(filp
))
1495 info
->blocked_open
--;
1496 #ifdef SERIAL_DEBUG_OPEN
1497 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1498 info
->line
, info
->count
);
1502 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1507 * This routine is called whenever a serial port is opened. It
1508 * enables interrupts for a serial port, linking in its ZILOG structure into
1509 * the IRQ chain. It also performs the serial-specific
1510 * initialization for the tty structure.
1512 static int rs_open(struct tty_struct
*tty
, struct file
* filp
)
1514 struct dec_serial
*info
;
1518 if ((line
< 0) || (line
>= zs_channels_found
))
1520 info
= zs_soft
+ line
;
1525 if (serial_paranoia_check(info
, tty
->name
, "rs_open"))
1527 #ifdef SERIAL_DEBUG_OPEN
1528 printk("rs_open %s, count = %d\n", tty
->name
, info
->count
);
1532 tty
->driver_data
= info
;
1536 * If the port is the middle of closing, bail out now
1538 if (tty_hung_up_p(filp
) ||
1539 (info
->flags
& ZILOG_CLOSING
)) {
1540 if (info
->flags
& ZILOG_CLOSING
)
1541 interruptible_sleep_on(&info
->close_wait
);
1542 #ifdef SERIAL_DO_RESTART
1543 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1544 -EAGAIN
: -ERESTARTSYS
);
1551 * Start up serial port
1553 retval
= zs_startup(info
);
1557 retval
= block_til_ready(tty
, filp
, info
);
1559 #ifdef SERIAL_DEBUG_OPEN
1560 printk("rs_open returning after block_til_ready with %d\n",
1566 #ifdef CONFIG_SERIAL_DEC_CONSOLE
1567 if (sercons
.cflag
&& sercons
.index
== line
) {
1568 tty
->termios
->c_cflag
= sercons
.cflag
;
1574 #ifdef SERIAL_DEBUG_OPEN
1575 printk("rs_open %s successful...", tty
->name
);
1577 /* tty->low_latency = 1; */
1581 /* Finally, routines used to initialize the serial driver. */
1583 static void __init
show_serial_version(void)
1585 printk("DECstation Z8530 serial driver version 0.09\n");
1588 /* Initialize Z8530s zs_channels
1591 static void __init
probe_sccs(void)
1593 struct dec_serial
**pp
;
1594 int i
, n
, n_chips
= 0, n_channels
, chip
, channel
;
1595 unsigned long flags
;
1598 * did we get here by accident?
1601 printk("Not on JUNKIO machine, skipping probe_sccs\n");
1605 switch(mips_machtype
) {
1606 #ifdef CONFIG_MACH_DECSTATION
1607 case MACH_DS5000_2X0
:
1610 zs_parms
= &ds_parms
;
1611 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1612 zs_parms
->irq1
= dec_interrupt
[DEC_IRQ_SCC1
];
1614 case MACH_DS5000_1XX
:
1616 zs_parms
= &ds_parms
;
1617 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1618 zs_parms
->irq1
= dec_interrupt
[DEC_IRQ_SCC1
];
1620 case MACH_DS5000_XX
:
1622 zs_parms
= &ds_parms
;
1623 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1627 panic("zs: unsupported bus");
1630 panic("zs: uninitialized parms");
1636 for (chip
= 0; chip
< n_chips
; chip
++) {
1637 for (channel
= 0; channel
<= 1; channel
++) {
1639 * The sccs reside on the high byte of the 16 bit IOBUS
1641 zs_channels
[n_channels
].control
=
1642 (volatile void *)CKSEG1ADDR(dec_kn_slot_base
+
1643 (0 == chip
? zs_parms
->scc0
: zs_parms
->scc1
) +
1644 (0 == channel
? zs_parms
->channel_a_offset
:
1645 zs_parms
->channel_b_offset
));
1646 zs_channels
[n_channels
].data
=
1647 zs_channels
[n_channels
].control
+ 4;
1649 #ifndef CONFIG_SERIAL_DEC_CONSOLE
1651 * We're called early and memory managment isn't up, yet.
1652 * Thus request_region would fail.
1654 if (!request_region((unsigned long)
1655 zs_channels
[n_channels
].control
,
1656 ZS_CHAN_IO_SIZE
, "SCC"))
1657 panic("SCC I/O region is not free");
1659 zs_soft
[n_channels
].zs_channel
= &zs_channels
[n_channels
];
1662 zs_soft
[n_channels
].irq
= zs_parms
->irq0
;
1664 zs_soft
[n_channels
].irq
= zs_parms
->irq1
;
1667 * Identification of channel A. Location of channel A
1668 * inside chip depends on mapping of internal address
1669 * the chip decodes channels by.
1670 * CHANNEL_A_NR returns either 0 (in case of
1671 * DECstations) or 1 (in case of Baget).
1673 if (CHANNEL_A_NR
== channel
)
1674 zs_soft
[n_channels
].zs_chan_a
=
1675 &zs_channels
[n_channels
+1-2*CHANNEL_A_NR
];
1677 zs_soft
[n_channels
].zs_chan_a
=
1678 &zs_channels
[n_channels
];
1680 *pp
= &zs_soft
[n_channels
];
1681 pp
= &zs_soft
[n_channels
].zs_next
;
1687 zs_channels_found
= n_channels
;
1689 for (n
= 0; n
< zs_channels_found
; n
++) {
1690 for (i
= 0; i
< 16; i
++) {
1691 zs_soft
[n
].zs_channel
->curregs
[i
] = zs_init_regs
[i
];
1695 spin_lock_irqsave(&zs_lock
, flags
);
1696 for (n
= 0; n
< zs_channels_found
; n
++) {
1698 write_zsreg(zs_soft
[n
].zs_chan_a
, R9
, FHWRES
);
1700 write_zsreg(zs_soft
[n
].zs_chan_a
, R9
, 0);
1702 load_zsregs(zs_soft
[n
].zs_channel
,
1703 zs_soft
[n
].zs_channel
->curregs
);
1705 spin_unlock_irqrestore(&zs_lock
, flags
);
1708 static struct tty_operations serial_ops
= {
1712 .flush_chars
= rs_flush_chars
,
1713 .write_room
= rs_write_room
,
1714 .chars_in_buffer
= rs_chars_in_buffer
,
1715 .flush_buffer
= rs_flush_buffer
,
1717 .throttle
= rs_throttle
,
1718 .unthrottle
= rs_unthrottle
,
1719 .set_termios
= rs_set_termios
,
1722 .hangup
= rs_hangup
,
1723 .break_ctl
= rs_break
,
1724 .wait_until_sent
= rs_wait_until_sent
,
1725 .tiocmget
= rs_tiocmget
,
1726 .tiocmset
= rs_tiocmset
,
1729 /* zs_init inits the driver */
1730 int __init
zs_init(void)
1733 struct dec_serial
*info
;
1738 /* Find out how many Z8530 SCCs we have */
1741 serial_driver
= alloc_tty_driver(zs_channels_found
);
1745 show_serial_version();
1747 /* Initialize the tty_driver structure */
1748 /* Not all of this is exactly right for us. */
1750 serial_driver
->owner
= THIS_MODULE
;
1751 serial_driver
->devfs_name
= "tts/";
1752 serial_driver
->name
= "ttyS";
1753 serial_driver
->major
= TTY_MAJOR
;
1754 serial_driver
->minor_start
= 64;
1755 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1756 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1757 serial_driver
->init_termios
= tty_std_termios
;
1758 serial_driver
->init_termios
.c_cflag
=
1759 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1760 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_NO_DEVFS
;
1761 tty_set_operations(serial_driver
, &serial_ops
);
1763 if (tty_register_driver(serial_driver
))
1764 panic("Couldn't register serial driver");
1766 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++) {
1768 /* Needed before interrupts are enabled. */
1772 if (info
->hook
&& info
->hook
->init_info
) {
1773 (*info
->hook
->init_info
)(info
);
1777 info
->magic
= SERIAL_MAGIC
;
1778 info
->port
= (int) info
->zs_channel
->control
;
1780 info
->custom_divisor
= 16;
1781 info
->close_delay
= 50;
1782 info
->closing_wait
= 3000;
1785 info
->blocked_open
= 0;
1786 tasklet_init(&info
->tlet
, do_softint
, (unsigned long)info
);
1787 init_waitqueue_head(&info
->open_wait
);
1788 init_waitqueue_head(&info
->close_wait
);
1789 printk("ttyS%02d at 0x%08x (irq = %d) is a Z85C30 SCC\n",
1790 info
->line
, info
->port
, info
->irq
);
1791 tty_register_device(serial_driver
, info
->line
, NULL
);
1795 for (channel
= 0; channel
< zs_channels_found
; ++channel
) {
1796 zs_soft
[channel
].clk_divisor
= 16;
1797 zs_soft
[channel
].zs_baud
= get_zsbaud(&zs_soft
[channel
]);
1799 if (request_irq(zs_soft
[channel
].irq
, rs_interrupt
, SA_SHIRQ
,
1800 "scc", &zs_soft
[channel
]))
1801 printk(KERN_ERR
"decserial: can't get irq %d\n",
1802 zs_soft
[channel
].irq
);
1804 if (zs_soft
[channel
].hook
) {
1805 zs_startup(&zs_soft
[channel
]);
1806 if (zs_soft
[channel
].hook
->init_channel
)
1807 (*zs_soft
[channel
].hook
->init_channel
)
1808 (&zs_soft
[channel
]);
1816 * polling I/O routines
1818 static int zs_poll_tx_char(void *handle
, unsigned char ch
)
1820 struct dec_serial
*info
= handle
;
1821 struct dec_zschannel
*chan
= info
->zs_channel
;
1827 while (loops
&& !(read_zsreg(chan
, 0) & Tx_BUF_EMP
))
1831 write_zsdata(chan
, ch
);
1841 static int zs_poll_rx_char(void *handle
)
1843 struct dec_serial
*info
= handle
;
1844 struct dec_zschannel
*chan
= info
->zs_channel
;
1850 while (loops
&& !(read_zsreg(chan
, 0) & Rx_CH_AV
))
1854 ret
= read_zsdata(chan
);
1863 int register_zs_hook(unsigned int channel
, struct dec_serial_hook
*hook
)
1865 struct dec_serial
*info
= &zs_soft
[channel
];
1868 printk("%s: line %d has already a hook registered\n",
1869 __FUNCTION__
, channel
);
1873 hook
->poll_rx_char
= zs_poll_rx_char
;
1874 hook
->poll_tx_char
= zs_poll_tx_char
;
1881 int unregister_zs_hook(unsigned int channel
)
1883 struct dec_serial
*info
= &zs_soft
[channel
];
1889 printk("%s: trying to unregister hook on line %d,"
1890 " but none is registered\n", __FUNCTION__
, channel
);
1896 * ------------------------------------------------------------
1897 * Serial console driver
1898 * ------------------------------------------------------------
1900 #ifdef CONFIG_SERIAL_DEC_CONSOLE
1904 * Print a string to the serial port trying not to disturb
1905 * any possible real use of the port...
1907 static void serial_console_write(struct console
*co
, const char *s
,
1910 struct dec_serial
*info
;
1913 info
= zs_soft
+ co
->index
;
1915 for (i
= 0; i
< count
; i
++, s
++) {
1917 zs_poll_tx_char(info
, '\r');
1918 zs_poll_tx_char(info
, *s
);
1922 static struct tty_driver
*serial_console_device(struct console
*c
, int *index
)
1925 return serial_driver
;
1929 * Setup initial baud/bits/parity. We do two things here:
1930 * - construct a cflag setting for the first rs_open()
1931 * - initialize the serial port
1932 * Return non-zero if we didn't find a serial port.
1934 static int __init
serial_console_setup(struct console
*co
, char *options
)
1936 struct dec_serial
*info
;
1940 int cflag
= CREAD
| HUPCL
| CLOCAL
;
1941 int clk_divisor
= 16;
1944 unsigned long flags
;
1949 info
= zs_soft
+ co
->index
;
1957 baud
= simple_strtoul(options
, NULL
, 10);
1959 while(*s
>= '0' && *s
<= '9')
1968 * Now construct a cflag setting.
1996 * Set this to a sane value to prevent a divide error.
2020 spin_lock_irqsave(&zs_lock
, flags
);
2023 * Set up the baud rate generator.
2025 brg
= BPS_TO_BRG(baud
, zs_parms
->clock
/ clk_divisor
);
2026 info
->zs_channel
->curregs
[R12
] = (brg
& 255);
2027 info
->zs_channel
->curregs
[R13
] = ((brg
>> 8) & 255);
2030 * Set byte size and parity.
2033 info
->zs_channel
->curregs
[R3
] |= Rx7
;
2034 info
->zs_channel
->curregs
[R5
] |= Tx7
;
2036 info
->zs_channel
->curregs
[R3
] |= Rx8
;
2037 info
->zs_channel
->curregs
[R5
] |= Tx8
;
2039 if (cflag
& PARENB
) {
2040 info
->zs_channel
->curregs
[R4
] |= PAR_ENA
;
2042 if (!(cflag
& PARODD
)) {
2043 info
->zs_channel
->curregs
[R4
] |= PAR_EVEN
;
2045 info
->zs_channel
->curregs
[R4
] |= SB1
;
2048 * Turn on RTS and DTR.
2050 zs_rtsdtr(info
, RTS
| DTR
, 1);
2053 * Finally, enable sequencing.
2055 info
->zs_channel
->curregs
[R3
] |= RxENABLE
;
2056 info
->zs_channel
->curregs
[R5
] |= TxENAB
;
2059 * Clear the interrupt registers.
2061 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
2062 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
2065 * Load up the new values.
2067 load_zsregs(info
->zs_channel
, info
->zs_channel
->curregs
);
2069 /* Save the current value of RR0 */
2070 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, R0
);
2072 zs_soft
[co
->index
].clk_divisor
= clk_divisor
;
2073 zs_soft
[co
->index
].zs_baud
= get_zsbaud(&zs_soft
[co
->index
]);
2075 spin_unlock_irqrestore(&zs_lock
, flags
);
2080 static struct console sercons
= {
2082 .write
= serial_console_write
,
2083 .device
= serial_console_device
,
2084 .setup
= serial_console_setup
,
2085 .flags
= CON_PRINTBUFFER
,
2092 void __init
zs_serial_console_init(void)
2094 register_console(&sercons
);
2096 #endif /* ifdef CONFIG_SERIAL_DEC_CONSOLE */
2099 struct dec_zschannel
*zs_kgdbchan
;
2100 static unsigned char scc_inittab
[] = {
2101 9, 0x80, /* reset A side (CHRA) */
2102 13, 0, /* set baud rate divisor */
2104 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
2105 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
2106 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
2107 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
2108 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
2111 /* These are for receiving and sending characters under the kgdb
2112 * source level kernel debugger.
2114 void putDebugChar(char kgdb_char
)
2116 struct dec_zschannel
*chan
= zs_kgdbchan
;
2117 while ((read_zsreg(chan
, 0) & Tx_BUF_EMP
) == 0)
2119 write_zsdata(chan
, kgdb_char
);
2121 char getDebugChar(void)
2123 struct dec_zschannel
*chan
= zs_kgdbchan
;
2124 while((read_zsreg(chan
, 0) & Rx_CH_AV
) == 0)
2125 eieio(); /*barrier();*/
2126 return read_zsdata(chan
);
2128 void kgdb_interruptible(int yes
)
2130 struct dec_zschannel
*chan
= zs_kgdbchan
;
2132 nine
= read_zsreg(chan
, 9);
2134 one
= EXT_INT_ENAB
|RxINT_ALL
;
2136 printk("turning serial ints on\n");
2140 printk("turning serial ints off\n");
2142 write_zsreg(chan
, 1, one
);
2143 write_zsreg(chan
, 9, nine
);
2146 static int kgdbhook_init_channel(void *handle
)
2151 static void kgdbhook_init_info(void *handle
)
2155 static void kgdbhook_rx_char(void *handle
, unsigned char ch
, unsigned char fl
)
2157 struct dec_serial
*info
= handle
;
2159 if (fl
!= TTY_NORMAL
)
2161 if (ch
== 0x03 || ch
== '$')
2165 /* This sets up the serial port we're using, and turns on
2166 * interrupts for that channel, so kgdb is usable once we're done.
2168 static inline void kgdb_chaninit(struct dec_zschannel
*ms
, int intson
, int bps
)
2172 volatile char *sccc
= ms
->control
;
2173 brg
= BPS_TO_BRG(bps
, zs_parms
->clock
/16);
2174 printk("setting bps on kgdb line to %d [brg=%x]\n", bps
, brg
);
2175 for (i
= 20000; i
!= 0; --i
) {
2178 for (i
= 0; i
< sizeof(scc_inittab
); ++i
) {
2179 write_zsreg(ms
, scc_inittab
[i
], scc_inittab
[i
+1]);
2183 /* This is called at boot time to prime the kgdb serial debugging
2184 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2185 * for /dev/ttyb which is determined in setup_arch() from the
2186 * boot command line flags.
2188 struct dec_serial_hook zs_kgdbhook
= {
2189 .init_channel
= kgdbhook_init_channel
,
2190 .init_info
= kgdbhook_init_info
,
2191 .rx_char
= kgdbhook_rx_char
,
2192 .cflags
= B38400
| CS8
| CLOCAL
,
2195 void __init
zs_kgdb_hook(int tty_num
)
2197 /* Find out how many Z8530 SCCs we have */
2200 zs_soft
[tty_num
].zs_channel
= &zs_channels
[tty_num
];
2201 zs_kgdbchan
= zs_soft
[tty_num
].zs_channel
;
2202 zs_soft
[tty_num
].change_needed
= 0;
2203 zs_soft
[tty_num
].clk_divisor
= 16;
2204 zs_soft
[tty_num
].zs_baud
= 38400;
2205 zs_soft
[tty_num
].hook
= &zs_kgdbhook
; /* This runs kgdb */
2206 /* Turn on transmitter/receiver at 8-bits/char */
2207 kgdb_chaninit(zs_soft
[tty_num
].zs_channel
, 1, 38400);
2208 printk("KGDB: on channel %d initialized\n", tty_num
);
2209 set_debug_traps(); /* init stub */
2211 #endif /* ifdef CONFIG_KGDB */