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 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 #ifdef CONFIG_SERIAL_DEC_CONSOLE
59 #include <linux/console.h>
63 #include <asm/pgtable.h>
65 #include <asm/system.h>
66 #include <asm/uaccess.h>
67 #include <asm/bootinfo.h>
68 #include <asm/dec/serial.h>
70 #ifdef CONFIG_MACH_DECSTATION
71 #include <asm/dec/interrupts.h>
72 #include <asm/dec/machtype.h>
73 #include <asm/dec/tc.h>
74 #include <asm/dec/ioasic_addrs.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 struct dec_zschannel zs_channels
[NUM_CHANNELS
];
132 struct dec_serial zs_soft
[NUM_CHANNELS
];
133 int zs_channels_found
;
134 struct dec_serial
*zs_chain
; /* list of all channels */
136 struct tty_struct zs_ttys
[NUM_CHANNELS
];
138 #ifdef CONFIG_SERIAL_DEC_CONSOLE
139 static struct console sercons
;
141 #if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
143 static unsigned long break_pressed
; /* break, really ... */
146 static unsigned char zs_init_regs
[16] __initdata
= {
151 (X16CLK
), /* write 4 */
153 0, 0, 0, /* write 6, 7, 8 */
154 (MIE
| DLC
| NV
), /* write 9 */
155 (NRZ
), /* write 10 */
156 (TCBR
| RCBR
), /* write 11 */
157 0, 0, /* BRG time constant, write 12 + 13 */
158 (BRSRC
| BRENABL
), /* write 14 */
162 DECLARE_TASK_QUEUE(tq_zs_serial
);
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
);
196 * tmp_buf is used as a temporary buffer by serial_write. We need to
197 * lock it in case the copy_from_user blocks while swapping in a page,
198 * and some other program tries to do a serial write at the same time.
199 * Since the lock will only come under contention when the system is
200 * swapping and available memory is low, it makes sense to share one
201 * buffer across all the serial ports, since it significantly saves
202 * memory if large numbers of serial ports are open.
204 static unsigned char tmp_buf
[4096]; /* This is cheating */
205 static DECLARE_MUTEX(tmp_buf_sem
);
207 static inline int serial_paranoia_check(struct dec_serial
*info
,
208 char *name
, const char *routine
)
210 #ifdef SERIAL_PARANOIA_CHECK
211 static const char *badmagic
=
212 "Warning: bad magic number for serial struct %s in %s\n";
213 static const char *badinfo
=
214 "Warning: null mac_serial for %s in %s\n";
217 printk(badinfo
, name
, routine
);
220 if (info
->magic
!= SERIAL_MAGIC
) {
221 printk(badmagic
, name
, routine
);
229 * This is used to figure out the divisor speeds and the timeouts
231 static int baud_table
[] = {
232 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
233 9600, 19200, 38400, 57600, 115200, 0 };
236 * Reading and writing Z8530 registers.
238 static inline unsigned char read_zsreg(struct dec_zschannel
*channel
,
241 unsigned char retval
;
244 *channel
->control
= reg
& 0xf;
245 fast_iob(); RECOVERY_DELAY
;
247 retval
= *channel
->control
;
252 static inline void write_zsreg(struct dec_zschannel
*channel
,
253 unsigned char reg
, unsigned char value
)
256 *channel
->control
= reg
& 0xf;
257 fast_iob(); RECOVERY_DELAY
;
259 *channel
->control
= value
;
260 fast_iob(); RECOVERY_DELAY
;
264 static inline unsigned char read_zsdata(struct dec_zschannel
*channel
)
266 unsigned char retval
;
268 retval
= *channel
->data
;
273 static inline void write_zsdata(struct dec_zschannel
*channel
,
276 *channel
->data
= value
;
277 fast_iob(); RECOVERY_DELAY
;
281 static inline void load_zsregs(struct dec_zschannel
*channel
,
284 /* ZS_CLEARERR(channel);
285 ZS_CLEARFIFO(channel); */
287 write_zsreg(channel
, R3
, regs
[R3
] & ~RxENABLE
);
288 write_zsreg(channel
, R5
, regs
[R5
] & ~TxENAB
);
289 write_zsreg(channel
, R4
, regs
[R4
]);
290 write_zsreg(channel
, R9
, regs
[R9
]);
291 write_zsreg(channel
, R1
, regs
[R1
]);
292 write_zsreg(channel
, R2
, regs
[R2
]);
293 write_zsreg(channel
, R10
, regs
[R10
]);
294 write_zsreg(channel
, R11
, regs
[R11
]);
295 write_zsreg(channel
, R12
, regs
[R12
]);
296 write_zsreg(channel
, R13
, regs
[R13
]);
297 write_zsreg(channel
, R14
, regs
[R14
]);
298 write_zsreg(channel
, R15
, regs
[R15
]);
299 write_zsreg(channel
, R3
, regs
[R3
]);
300 write_zsreg(channel
, R5
, regs
[R5
]);
304 /* Sets or clears DTR/RTS on the requested line */
305 static inline void zs_rtsdtr(struct dec_serial
*info
, int which
, int set
)
310 save_flags(flags
); cli();
311 if (info
->zs_channel
!= info
->zs_chan_a
) {
313 info
->zs_chan_a
->curregs
[5] |= (which
& (RTS
| DTR
));
315 info
->zs_chan_a
->curregs
[5] &= ~(which
& (RTS
| DTR
));
317 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
319 restore_flags(flags
);
322 /* Utility routines for the Zilog */
323 static inline int get_zsbaud(struct dec_serial
*ss
)
325 struct dec_zschannel
*channel
= ss
->zs_channel
;
328 /* The baud rate is split up between two 8-bit registers in
329 * what is termed 'BRG time constant' format in my docs for
330 * the chip, it is a function of the clk rate the chip is
331 * receiving which happens to be constant.
333 brg
= (read_zsreg(channel
, 13) << 8);
334 brg
|= read_zsreg(channel
, 12);
335 return BRG_TO_BPS(brg
, (zs_parms
->clock
/(ss
->clk_divisor
)));
338 /* On receive, this clears errors and the receiver interrupts */
339 static inline void rs_recv_clear(struct dec_zschannel
*zsc
)
341 write_zsreg(zsc
, 0, ERR_RES
);
342 write_zsreg(zsc
, 0, RES_H_IUS
); /* XXX this is unnecessary */
346 * ----------------------------------------------------------------------
348 * Here starts the interrupt handling routines. All of the following
349 * subroutines are declared as inline and are folded into
350 * rs_interrupt(). They were separated out for readability's sake.
352 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
353 * -----------------------------------------------------------------------
357 * This routine is used by the interrupt handler to schedule
358 * processing in the software interrupt portion of the driver.
360 static _INLINE_
void rs_sched_event(struct dec_serial
*info
,
363 info
->event
|= 1 << event
;
364 queue_task(&info
->tqueue
, &tq_zs_serial
);
368 static _INLINE_
void receive_chars(struct dec_serial
*info
,
369 struct pt_regs
*regs
)
371 struct tty_struct
*tty
= info
->tty
;
372 unsigned char ch
, stat
, flag
;
374 while ((read_zsreg(info
->zs_channel
, R0
) & Rx_CH_AV
) != 0) {
376 stat
= read_zsreg(info
->zs_channel
, R1
);
377 ch
= read_zsdata(info
->zs_channel
);
379 if (!tty
&& (!info
->hook
|| !info
->hook
->rx_char
))
383 if (info
->tty_break
) {
386 if (info
->flags
& ZILOG_SAK
)
388 /* Ignore the null char got when BREAK is removed. */
394 } else if (stat
& FRM_ERR
) {
396 } else if (stat
& PAR_ERR
) {
399 if (flag
!= TTY_NORMAL
)
400 /* reset the error indication */
401 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
404 #if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
406 if (break_pressed
&& info
->line
== sercons
.index
) {
407 /* Ignore the null char got when BREAK is removed. */
410 if (time_before(jiffies
, break_pressed
+ HZ
* 5)) {
411 handle_sysrq(ch
, regs
, NULL
);
419 if (info
->hook
&& info
->hook
->rx_char
) {
420 (*info
->hook
->rx_char
)(ch
, flag
);
424 tty_insert_flip_char(tty
, ch
, flag
);
427 tty_flip_buffer_push(tty
);
430 static void transmit_chars(struct dec_serial
*info
)
432 if ((read_zsreg(info
->zs_channel
, R0
) & Tx_BUF_EMP
) == 0)
438 write_zsdata(info
->zs_channel
, info
->x_char
);
444 if ((info
->xmit_cnt
<= 0) || (info
->tty
&& info
->tty
->stopped
)
445 || info
->tx_stopped
) {
446 write_zsreg(info
->zs_channel
, R0
, RES_Tx_P
);
450 write_zsdata(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
451 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
455 if (info
->xmit_cnt
< WAKEUP_CHARS
)
456 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
459 static _INLINE_
void status_handle(struct dec_serial
*info
)
463 /* Get status from Read Register 0 */
464 stat
= read_zsreg(info
->zs_channel
, R0
);
466 if ((stat
& BRK_ABRT
) && !(info
->read_reg_zero
& BRK_ABRT
)) {
467 #if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
469 if (info
->line
== sercons
.index
) {
471 break_pressed
= jiffies
;
477 if (info
->zs_channel
!= info
->zs_chan_a
) {
479 /* Check for DCD transitions */
480 if (info
->tty
&& !C_CLOCAL(info
->tty
) &&
481 ((stat
^ info
->read_reg_zero
) & DCD
) != 0 ) {
483 wake_up_interruptible(&info
->open_wait
);
485 tty_hangup(info
->tty
);
489 /* Check for CTS transitions */
490 if (info
->tty
&& C_CRTSCTS(info
->tty
)) {
491 if ((stat
& CTS
) != 0) {
492 if (info
->tx_stopped
) {
493 info
->tx_stopped
= 0;
494 if (!info
->tx_active
)
495 transmit_chars(info
);
498 info
->tx_stopped
= 1;
504 /* Clear status condition... */
505 write_zsreg(info
->zs_channel
, R0
, RES_EXT_INT
);
506 info
->read_reg_zero
= stat
;
510 * This is the serial driver's generic interrupt routine
512 void rs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
514 struct dec_serial
*info
= (struct dec_serial
*) dev_id
;
515 unsigned char zs_intreg
;
518 /* NOTE: The read register 3, which holds the irq status,
519 * does so for both channels on each chip. Although
520 * the status value itself must be read from the A
521 * channel and is only valid when read from channel A.
522 * Yes... broken hardware...
524 #define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
526 if (info
->zs_chan_a
== info
->zs_channel
)
527 shift
= 3; /* Channel A */
529 shift
= 0; /* Channel B */
532 zs_intreg
= read_zsreg(info
->zs_chan_a
, R3
) >> shift
;
533 if ((zs_intreg
& CHAN_IRQMASK
) == 0)
536 if (zs_intreg
& CHBRxIP
) {
537 receive_chars(info
, regs
);
539 if (zs_intreg
& CHBTxIP
) {
540 transmit_chars(info
);
542 if (zs_intreg
& CHBEXT
) {
547 /* Why do we need this ? */
548 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
552 void zs_dump (void) {
554 for (i
= 0; i
< zs_channels_found
; i
++) {
555 struct dec_zschannel
*ch
= &zs_channels
[i
];
556 if ((long)ch
->control
== UNI_IO_BASE
+UNI_SCC1A_CTRL
) {
557 for (j
= 0; j
< 15; j
++) {
558 printk("W%d = 0x%x\t",
559 j
, (int)ch
->curregs
[j
]);
561 for (j
= 0; j
< 15; j
++) {
562 printk("R%d = 0x%x\t",
563 j
, (int)read_zsreg(ch
,j
));
572 * -------------------------------------------------------------------
573 * Here ends the serial interrupt routines.
574 * -------------------------------------------------------------------
578 * ------------------------------------------------------------
579 * rs_stop() and rs_start()
581 * This routines are called before setting or resetting tty->stopped.
582 * ------------------------------------------------------------
584 static void rs_stop(struct tty_struct
*tty
)
586 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
589 if (serial_paranoia_check(info
, tty
->name
, "rs_stop"))
593 save_flags(flags
); cli();
594 if (info
->zs_channel
->curregs
[5] & TxENAB
) {
595 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
596 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
598 restore_flags(flags
);
602 static void rs_start(struct tty_struct
*tty
)
604 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
607 if (serial_paranoia_check(info
, tty
->name
, "rs_start"))
610 save_flags(flags
); cli();
612 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->zs_channel
->curregs
[5] & TxENAB
)) {
613 info
->zs_channel
->curregs
[5] |= TxENAB
;
614 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
617 if (info
->xmit_cnt
&& info
->xmit_buf
&& !info
->tx_active
) {
618 transmit_chars(info
);
621 restore_flags(flags
);
625 * This routine is used to handle the "bottom half" processing for the
626 * serial driver, known also the "software interrupt" processing.
627 * This processing is done at the kernel interrupt level, after the
628 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
629 * is where time-consuming activities which can not be done in the
630 * interrupt driver proper are done; the interrupt driver schedules
631 * them using rs_sched_event(), and they get done here.
633 static void do_serial_bh(void)
635 run_task_queue(&tq_zs_serial
);
638 static void do_softint(void *private_
)
640 struct dec_serial
*info
= (struct dec_serial
*) private_
;
641 struct tty_struct
*tty
;
647 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
652 int zs_startup(struct dec_serial
* info
)
656 if (info
->flags
& ZILOG_INITIALIZED
)
659 if (!info
->xmit_buf
) {
660 info
->xmit_buf
= (unsigned char *) get_zeroed_page(GFP_KERNEL
);
665 save_flags(flags
); cli();
667 #ifdef SERIAL_DEBUG_OPEN
668 printk("starting up ttyS%d (irq %d)...", info
->line
, info
->irq
);
672 * Clear the receive FIFO.
674 ZS_CLEARFIFO(info
->zs_channel
);
675 info
->xmit_fifo_size
= 1;
678 * Clear the interrupt registers.
680 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
681 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
684 * Set the speed of the serial port
689 * Turn on RTS and DTR.
691 zs_rtsdtr(info
, RTS
| DTR
, 1);
694 * Finally, enable sequencing and interrupts
696 info
->zs_channel
->curregs
[R1
] &= ~RxINT_MASK
;
697 info
->zs_channel
->curregs
[R1
] |= (RxINT_ALL
| TxINT_ENAB
|
699 info
->zs_channel
->curregs
[R3
] |= RxENABLE
;
700 info
->zs_channel
->curregs
[R5
] |= TxENAB
;
701 info
->zs_channel
->curregs
[R15
] |= (DCDIE
| CTSIE
| TxUIE
| BRKIE
);
702 write_zsreg(info
->zs_channel
, R1
, info
->zs_channel
->curregs
[R1
]);
703 write_zsreg(info
->zs_channel
, R3
, info
->zs_channel
->curregs
[R3
]);
704 write_zsreg(info
->zs_channel
, R5
, info
->zs_channel
->curregs
[R5
]);
705 write_zsreg(info
->zs_channel
, R15
, info
->zs_channel
->curregs
[R15
]);
708 * And clear the interrupt registers again for luck.
710 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
711 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
713 /* Save the current value of RR0 */
714 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, R0
);
717 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
718 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
720 info
->flags
|= ZILOG_INITIALIZED
;
721 restore_flags(flags
);
726 * This routine will shutdown a serial port; interrupts are disabled, and
727 * DTR is dropped if the hangup on close termio flag is on.
729 static void shutdown(struct dec_serial
* info
)
733 if (!(info
->flags
& ZILOG_INITIALIZED
))
736 #ifdef SERIAL_DEBUG_OPEN
737 printk("Shutting down serial port %d (irq %d)....", info
->line
,
741 save_flags(flags
); cli(); /* Disable interrupts */
743 if (info
->xmit_buf
) {
744 free_page((unsigned long) info
->xmit_buf
);
748 info
->zs_channel
->curregs
[1] = 0;
749 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]); /* no interrupts */
751 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
752 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
754 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
755 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
756 if (!info
->tty
|| C_HUPCL(info
->tty
)) {
757 zs_rtsdtr(info
, RTS
| DTR
, 0);
761 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
763 info
->flags
&= ~ZILOG_INITIALIZED
;
764 restore_flags(flags
);
768 * This routine is called to set the UART divisor registers to match
769 * the specified baud rate for a serial port.
771 static void change_speed(struct dec_serial
*info
)
779 if (!info
->tty
|| !info
->tty
->termios
)
781 cflag
= info
->tty
->termios
->c_cflag
;
785 cflag
= info
->hook
->cflags
;
791 if (i
< 1 || i
> 2) {
793 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
795 info
->hook
->cflags
&= ~CBAUDEX
;
800 save_flags(flags
); cli();
801 info
->zs_baud
= baud_table
[i
];
803 brg
= BPS_TO_BRG(info
->zs_baud
, zs_parms
->clock
/info
->clk_divisor
);
804 info
->zs_channel
->curregs
[12] = (brg
& 255);
805 info
->zs_channel
->curregs
[13] = ((brg
>> 8) & 255);
806 zs_rtsdtr(info
, DTR
, 1);
808 zs_rtsdtr(info
, RTS
| DTR
, 0);
812 /* byte size and parity */
813 info
->zs_channel
->curregs
[3] &= ~RxNBITS_MASK
;
814 info
->zs_channel
->curregs
[5] &= ~TxNBITS_MASK
;
815 switch (cflag
& CSIZE
) {
818 info
->zs_channel
->curregs
[3] |= Rx5
;
819 info
->zs_channel
->curregs
[5] |= Tx5
;
823 info
->zs_channel
->curregs
[3] |= Rx6
;
824 info
->zs_channel
->curregs
[5] |= Tx6
;
828 info
->zs_channel
->curregs
[3] |= Rx7
;
829 info
->zs_channel
->curregs
[5] |= Tx7
;
832 default: /* defaults to 8 bits */
834 info
->zs_channel
->curregs
[3] |= Rx8
;
835 info
->zs_channel
->curregs
[5] |= Tx8
;
839 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
) / info
->zs_baud
);
840 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
842 info
->zs_channel
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
843 if (cflag
& CSTOPB
) {
844 info
->zs_channel
->curregs
[4] |= SB2
;
846 info
->zs_channel
->curregs
[4] |= SB1
;
848 if (cflag
& PARENB
) {
849 info
->zs_channel
->curregs
[4] |= PAR_ENA
;
851 if (!(cflag
& PARODD
)) {
852 info
->zs_channel
->curregs
[4] |= PAR_EVEN
;
855 if (!(cflag
& CLOCAL
)) {
856 if (!(info
->zs_channel
->curregs
[15] & DCDIE
))
857 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
858 info
->zs_channel
->curregs
[15] |= DCDIE
;
860 info
->zs_channel
->curregs
[15] &= ~DCDIE
;
861 if (cflag
& CRTSCTS
) {
862 info
->zs_channel
->curregs
[15] |= CTSIE
;
863 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) == 0)
864 info
->tx_stopped
= 1;
866 info
->zs_channel
->curregs
[15] &= ~CTSIE
;
867 info
->tx_stopped
= 0;
870 /* Load up the new values */
871 load_zsregs(info
->zs_channel
, info
->zs_channel
->curregs
);
873 restore_flags(flags
);
876 static void rs_flush_chars(struct tty_struct
*tty
)
878 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
881 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_chars"))
884 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| info
->tx_stopped
||
888 /* Enable transmitter */
889 save_flags(flags
); cli();
890 transmit_chars(info
);
891 restore_flags(flags
);
894 static int rs_write(struct tty_struct
* tty
,
895 const unsigned char *buf
, int count
)
898 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
901 if (serial_paranoia_check(info
, tty
->name
, "rs_write"))
904 if (!tty
|| !info
->xmit_buf
)
910 c
= min(count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
911 SERIAL_XMIT_SIZE
- info
->xmit_head
));
917 copy_from_user(tmp_buf
, buf
, c
);
918 c
= min(c
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
919 SERIAL_XMIT_SIZE
- info
->xmit_head
));
920 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
923 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
924 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
926 restore_flags(flags
);
932 if (info
->xmit_cnt
&& !tty
->stopped
&& !info
->tx_stopped
934 transmit_chars(info
);
935 restore_flags(flags
);
939 static int rs_write_room(struct tty_struct
*tty
)
941 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
944 if (serial_paranoia_check(info
, tty
->name
, "rs_write_room"))
946 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
952 static int rs_chars_in_buffer(struct tty_struct
*tty
)
954 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
956 if (serial_paranoia_check(info
, tty
->name
, "rs_chars_in_buffer"))
958 return info
->xmit_cnt
;
961 static void rs_flush_buffer(struct tty_struct
*tty
)
963 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
965 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_buffer"))
968 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
974 * ------------------------------------------------------------
977 * This routine is called by the upper-layer tty layer to signal that
978 * incoming characters should be throttled.
979 * ------------------------------------------------------------
981 static void rs_throttle(struct tty_struct
* tty
)
983 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
986 #ifdef SERIAL_DEBUG_THROTTLE
989 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
990 tty
->ldisc
.chars_in_buffer(tty
));
993 if (serial_paranoia_check(info
, tty
->name
, "rs_throttle"))
997 save_flags(flags
); cli();
998 info
->x_char
= STOP_CHAR(tty
);
999 if (!info
->tx_active
)
1000 transmit_chars(info
);
1001 restore_flags(flags
);
1004 if (C_CRTSCTS(tty
)) {
1005 zs_rtsdtr(info
, RTS
, 0);
1009 static void rs_unthrottle(struct tty_struct
* tty
)
1011 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
1012 unsigned long flags
;
1014 #ifdef SERIAL_DEBUG_THROTTLE
1017 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1018 tty
->ldisc
.chars_in_buffer(tty
));
1021 if (serial_paranoia_check(info
, tty
->name
, "rs_unthrottle"))
1025 save_flags(flags
); cli();
1029 info
->x_char
= START_CHAR(tty
);
1030 if (!info
->tx_active
)
1031 transmit_chars(info
);
1033 restore_flags(flags
);
1036 if (C_CRTSCTS(tty
)) {
1037 zs_rtsdtr(info
, RTS
, 1);
1042 * ------------------------------------------------------------
1043 * rs_ioctl() and friends
1044 * ------------------------------------------------------------
1047 static int get_serial_info(struct dec_serial
* info
,
1048 struct serial_struct
* retinfo
)
1050 struct serial_struct tmp
;
1054 memset(&tmp
, 0, sizeof(tmp
));
1055 tmp
.type
= info
->type
;
1056 tmp
.line
= info
->line
;
1057 tmp
.port
= info
->port
;
1058 tmp
.irq
= info
->irq
;
1059 tmp
.flags
= info
->flags
;
1060 tmp
.baud_base
= info
->baud_base
;
1061 tmp
.close_delay
= info
->close_delay
;
1062 tmp
.closing_wait
= info
->closing_wait
;
1063 tmp
.custom_divisor
= info
->custom_divisor
;
1064 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)) ? -EFAULT
: 0;
1067 static int set_serial_info(struct dec_serial
* info
,
1068 struct serial_struct
* new_info
)
1070 struct serial_struct new_serial
;
1071 struct dec_serial old_info
;
1076 copy_from_user(&new_serial
,new_info
,sizeof(new_serial
));
1079 if (!capable(CAP_SYS_ADMIN
)) {
1080 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1081 (new_serial
.type
!= info
->type
) ||
1082 (new_serial
.close_delay
!= info
->close_delay
) ||
1083 ((new_serial
.flags
& ~ZILOG_USR_MASK
) !=
1084 (info
->flags
& ~ZILOG_USR_MASK
)))
1086 info
->flags
= ((info
->flags
& ~ZILOG_USR_MASK
) |
1087 (new_serial
.flags
& ZILOG_USR_MASK
));
1088 info
->custom_divisor
= new_serial
.custom_divisor
;
1089 goto check_and_exit
;
1092 if (info
->count
> 1)
1096 * OK, past this point, all the error checking has been done.
1097 * At this point, we start making changes.....
1100 info
->baud_base
= new_serial
.baud_base
;
1101 info
->flags
= ((info
->flags
& ~ZILOG_FLAGS
) |
1102 (new_serial
.flags
& ZILOG_FLAGS
));
1103 info
->type
= new_serial
.type
;
1104 info
->close_delay
= new_serial
.close_delay
;
1105 info
->closing_wait
= new_serial
.closing_wait
;
1108 retval
= zs_startup(info
);
1113 * get_lsr_info - get line status register info
1115 * Purpose: Let user call ioctl() to get info when the UART physically
1116 * is emptied. On bus types like RS485, the transmitter must
1117 * release the bus after transmitting. This must be done when
1118 * the transmit shift register is empty, not be done when the
1119 * transmit holding register is empty. This functionality
1120 * allows an RS485 driver to be written in user space.
1122 static int get_lsr_info(struct dec_serial
* info
, unsigned int *value
)
1124 unsigned char status
;
1127 status
= read_zsreg(info
->zs_channel
, 0);
1129 put_user(status
,value
);
1133 static int rs_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1135 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1136 unsigned char control
, status_a
, status_b
;
1137 unsigned int result
;
1142 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1145 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1148 if (info
->zs_channel
== info
->zs_chan_a
)
1152 control
= info
->zs_chan_a
->curregs
[5];
1153 status_a
= read_zsreg(info
->zs_chan_a
, 0);
1154 status_b
= read_zsreg(info
->zs_channel
, 0);
1156 result
= ((control
& RTS
) ? TIOCM_RTS
: 0)
1157 | ((control
& DTR
) ? TIOCM_DTR
: 0)
1158 | ((status_b
& DCD
) ? TIOCM_CAR
: 0)
1159 | ((status_a
& DCD
) ? TIOCM_RNG
: 0)
1160 | ((status_a
& SYNC_HUNT
) ? TIOCM_DSR
: 0)
1161 | ((status_b
& CTS
) ? TIOCM_CTS
: 0);
1166 static int rs_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1167 unsigned int set
, unsigned int clear
)
1169 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1171 unsigned int arg
, bits
;
1176 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1179 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1182 if (info
->zs_channel
== info
->zs_chan_a
)
1185 get_user(arg
, value
);
1187 if (set
& TIOCM_RTS
)
1188 info
->zs_chan_a
->curregs
[5] |= RTS
;
1189 if (set
& TIOCM_DTR
)
1190 info
->zs_chan_a
->curregs
[5] |= DTR
;
1191 if (clear
& TIOCM_RTS
)
1192 info
->zs_chan_a
->curregs
[5] &= ~RTS
;
1193 if (clear
& TIOCM_DTR
)
1194 info
->zs_chan_a
->curregs
[5] &= ~DTR
;
1195 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
1201 * rs_break - turn transmit break condition on/off
1203 static void rs_break(struct tty_struct
*tty
, int break_state
)
1205 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1206 unsigned long flags
;
1208 if (serial_paranoia_check(info
, tty
->name
, "rs_break"))
1213 save_flags(flags
); cli();
1214 if (break_state
== -1)
1215 info
->zs_channel
->curregs
[5] |= SND_BRK
;
1217 info
->zs_channel
->curregs
[5] &= ~SND_BRK
;
1218 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
1219 restore_flags(flags
);
1222 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1223 unsigned int cmd
, unsigned long arg
)
1226 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1231 if (serial_paranoia_check(info
, tty
->name
, "rs_ioctl"))
1234 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1235 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1236 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1237 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1243 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1244 sizeof(struct serial_struct
)))
1246 return get_serial_info(info
, (struct serial_struct
*)arg
);
1249 return set_serial_info(info
, (struct serial_struct
*)arg
);
1251 case TIOCSERGETLSR
: /* Get line status register */
1252 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1253 sizeof(unsigned int)))
1255 return get_lsr_info(info
, (unsigned int *)arg
);
1257 case TIOCSERGSTRUCT
:
1258 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1259 sizeof(struct dec_serial
)))
1261 copy_from_user((struct dec_serial
*)arg
, info
,
1262 sizeof(struct dec_serial
));
1266 return -ENOIOCTLCMD
;
1271 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1273 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
1276 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1278 was_stopped
= info
->tx_stopped
;
1282 if (was_stopped
&& !info
->tx_stopped
)
1287 * ------------------------------------------------------------
1290 * This routine is called when the serial port gets closed.
1291 * Wait for the last remaining data to be sent.
1292 * ------------------------------------------------------------
1294 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
1296 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1297 unsigned long flags
;
1299 if (!info
|| serial_paranoia_check(info
, tty
->name
, "rs_close"))
1302 save_flags(flags
); cli();
1304 if (tty_hung_up_p(filp
)) {
1305 restore_flags(flags
);
1309 #ifdef SERIAL_DEBUG_OPEN
1310 printk("rs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1312 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1314 * Uh, oh. tty->count is 1, which means that the tty
1315 * structure will be freed. Info->count should always
1316 * be one in these conditions. If it's greater than
1317 * one, we've got real problems, since it means the
1318 * serial port won't be shutdown.
1320 printk("rs_close: bad serial port count; tty->count is 1, "
1321 "info->count is %d\n", info
->count
);
1324 if (--info
->count
< 0) {
1325 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1326 info
->line
, info
->count
);
1330 restore_flags(flags
);
1333 info
->flags
|= ZILOG_CLOSING
;
1335 * Now we wait for the transmit buffer to clear; and we notify
1336 * the line discipline to only process XON/XOFF characters.
1339 if (info
->closing_wait
!= ZILOG_CLOSING_WAIT_NONE
)
1340 tty_wait_until_sent(tty
, info
->closing_wait
);
1342 * At this point we stop accepting input. To do this, we
1343 * disable the receiver and receive interrupts.
1345 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
1346 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
1347 info
->zs_channel
->curregs
[1] = 0; /* disable any rx ints */
1348 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]);
1349 ZS_CLEARFIFO(info
->zs_channel
);
1350 if (info
->flags
& ZILOG_INITIALIZED
) {
1352 * Before we drop DTR, make sure the SCC transmitter
1353 * has completely drained.
1355 rs_wait_until_sent(tty
, info
->timeout
);
1359 if (tty
->driver
->flush_buffer
)
1360 tty
->driver
->flush_buffer(tty
);
1361 tty_ldisc_flush(tty
);
1365 if (info
->blocked_open
) {
1366 if (info
->close_delay
) {
1367 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
1369 wake_up_interruptible(&info
->open_wait
);
1371 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CLOSING
);
1372 wake_up_interruptible(&info
->close_wait
);
1373 restore_flags(flags
);
1377 * rs_wait_until_sent() --- wait until the transmitter is empty
1379 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1381 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1382 unsigned long orig_jiffies
;
1385 if (serial_paranoia_check(info
, tty
->name
, "rs_wait_until_sent"))
1388 orig_jiffies
= jiffies
;
1390 * Set the check interval to be 1/5 of the estimated time to
1391 * send a single character, and make it at least 1. The check
1392 * interval should also be less than the timeout.
1394 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1395 char_time
= char_time
/ 5;
1399 char_time
= min(char_time
, timeout
);
1400 while ((read_zsreg(info
->zs_channel
, 1) & Tx_BUF_EMP
) == 0) {
1401 msleep_interruptible(jiffies_to_msecs(char_time
));
1402 if (signal_pending(current
))
1404 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1407 current
->state
= TASK_RUNNING
;
1411 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1413 void rs_hangup(struct tty_struct
*tty
)
1415 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1417 if (serial_paranoia_check(info
, tty
->name
, "rs_hangup"))
1420 rs_flush_buffer(tty
);
1424 info
->flags
&= ~ZILOG_NORMAL_ACTIVE
;
1426 wake_up_interruptible(&info
->open_wait
);
1430 * ------------------------------------------------------------
1431 * rs_open() and friends
1432 * ------------------------------------------------------------
1434 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1435 struct dec_serial
*info
)
1437 DECLARE_WAITQUEUE(wait
, current
);
1442 * If the device is in the middle of being closed, then block
1443 * until it's done, and then try again.
1445 if (info
->flags
& ZILOG_CLOSING
) {
1446 interruptible_sleep_on(&info
->close_wait
);
1447 #ifdef SERIAL_DO_RESTART
1448 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1449 -EAGAIN
: -ERESTARTSYS
);
1456 * If non-blocking mode is set, or the port is not enabled,
1457 * then make the check up front and then exit.
1459 if ((filp
->f_flags
& O_NONBLOCK
) ||
1460 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1461 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1465 if (tty
->termios
->c_cflag
& CLOCAL
)
1469 * Block waiting for the carrier detect and the line to become
1470 * free (i.e., not in use by the callout). While we are in
1471 * this loop, info->count is dropped by one, so that
1472 * rs_close() knows when to free things. We restore it upon
1473 * exit, either normal or abnormal.
1476 add_wait_queue(&info
->open_wait
, &wait
);
1477 #ifdef SERIAL_DEBUG_OPEN
1478 printk("block_til_ready before block: ttyS%d, count = %d\n",
1479 info
->line
, info
->count
);
1482 if (!tty_hung_up_p(filp
))
1485 info
->blocked_open
++;
1488 if (tty
->termios
->c_cflag
& CBAUD
)
1489 zs_rtsdtr(info
, RTS
| DTR
, 1);
1491 set_current_state(TASK_INTERRUPTIBLE
);
1492 if (tty_hung_up_p(filp
) ||
1493 !(info
->flags
& ZILOG_INITIALIZED
)) {
1494 #ifdef SERIAL_DO_RESTART
1495 if (info
->flags
& ZILOG_HUP_NOTIFY
)
1498 retval
= -ERESTARTSYS
;
1504 if (!(info
->flags
& ZILOG_CLOSING
) &&
1505 (do_clocal
|| (read_zsreg(info
->zs_channel
, 0) & DCD
)))
1507 if (signal_pending(current
)) {
1508 retval
= -ERESTARTSYS
;
1511 #ifdef SERIAL_DEBUG_OPEN
1512 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1513 info
->line
, info
->count
);
1517 current
->state
= TASK_RUNNING
;
1518 remove_wait_queue(&info
->open_wait
, &wait
);
1519 if (!tty_hung_up_p(filp
))
1521 info
->blocked_open
--;
1522 #ifdef SERIAL_DEBUG_OPEN
1523 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1524 info
->line
, info
->count
);
1528 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1533 * This routine is called whenever a serial port is opened. It
1534 * enables interrupts for a serial port, linking in its ZILOG structure into
1535 * the IRQ chain. It also performs the serial-specific
1536 * initialization for the tty structure.
1538 int rs_open(struct tty_struct
*tty
, struct file
* filp
)
1540 struct dec_serial
*info
;
1544 if ((line
< 0) || (line
>= zs_channels_found
))
1546 info
= zs_soft
+ line
;
1551 if (serial_paranoia_check(info
, tty
->name
, "rs_open"))
1553 #ifdef SERIAL_DEBUG_OPEN
1554 printk("rs_open %s, count = %d\n", tty
->name
, info
->count
);
1558 tty
->driver_data
= info
;
1562 * If the port is the middle of closing, bail out now
1564 if (tty_hung_up_p(filp
) ||
1565 (info
->flags
& ZILOG_CLOSING
)) {
1566 if (info
->flags
& ZILOG_CLOSING
)
1567 interruptible_sleep_on(&info
->close_wait
);
1568 #ifdef SERIAL_DO_RESTART
1569 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1570 -EAGAIN
: -ERESTARTSYS
);
1577 * Start up serial port
1579 retval
= zs_startup(info
);
1583 retval
= block_til_ready(tty
, filp
, info
);
1585 #ifdef SERIAL_DEBUG_OPEN
1586 printk("rs_open returning after block_til_ready with %d\n",
1592 #ifdef CONFIG_SERIAL_DEC_CONSOLE
1593 if (sercons
.cflag
&& sercons
.index
== line
) {
1594 tty
->termios
->c_cflag
= sercons
.cflag
;
1600 #ifdef SERIAL_DEBUG_OPEN
1601 printk("rs_open %s successful...", tty
->name
);
1603 /* tty->low_latency = 1; */
1607 /* Finally, routines used to initialize the serial driver. */
1609 static void __init
show_serial_version(void)
1611 printk("DECstation Z8530 serial driver version 0.09\n");
1614 /* Initialize Z8530s zs_channels
1617 static void __init
probe_sccs(void)
1619 struct dec_serial
**pp
;
1620 int i
, n
, n_chips
= 0, n_channels
, chip
, channel
;
1621 unsigned long flags
;
1624 * did we get here by accident?
1627 printk("Not on JUNKIO machine, skipping probe_sccs\n");
1632 * When serial console is activated, tc_init has not been called yet
1633 * and system_base is undefined. Unfortunately we have to hardcode
1634 * system_base for this case :-(. HK
1636 switch(mips_machtype
) {
1637 #ifdef CONFIG_MACH_DECSTATION
1638 case MACH_DS5000_2X0
:
1640 system_base
= CKSEG1ADDR(0x1f800000);
1642 zs_parms
= &ds_parms
;
1643 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1644 zs_parms
->irq1
= dec_interrupt
[DEC_IRQ_SCC1
];
1646 case MACH_DS5000_1XX
:
1647 system_base
= CKSEG1ADDR(0x1c000000);
1649 zs_parms
= &ds_parms
;
1650 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1651 zs_parms
->irq1
= dec_interrupt
[DEC_IRQ_SCC1
];
1653 case MACH_DS5000_XX
:
1654 system_base
= CKSEG1ADDR(0x1c000000);
1656 zs_parms
= &ds_parms
;
1657 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1661 panic("zs: unsupported bus");
1664 panic("zs: uninitialized parms");
1670 for (chip
= 0; chip
< n_chips
; chip
++) {
1671 for (channel
= 0; channel
<= 1; channel
++) {
1673 * The sccs reside on the high byte of the 16 bit IOBUS
1675 zs_channels
[n_channels
].control
=
1676 (volatile unsigned char *)system_base
+
1677 (0 == chip
? zs_parms
->scc0
: zs_parms
->scc1
) +
1678 (0 == channel
? zs_parms
->channel_a_offset
:
1679 zs_parms
->channel_b_offset
);
1680 zs_channels
[n_channels
].data
=
1681 zs_channels
[n_channels
].control
+ 4;
1683 #ifndef CONFIG_SERIAL_DEC_CONSOLE
1685 * We're called early and memory managment isn't up, yet.
1686 * Thus request_region would fail.
1688 if (!request_region((unsigned long)
1689 zs_channels
[n_channels
].control
,
1690 ZS_CHAN_IO_SIZE
, "SCC"))
1691 panic("SCC I/O region is not free");
1693 zs_soft
[n_channels
].zs_channel
= &zs_channels
[n_channels
];
1696 zs_soft
[n_channels
].irq
= zs_parms
->irq0
;
1698 zs_soft
[n_channels
].irq
= zs_parms
->irq1
;
1701 * Identification of channel A. Location of channel A
1702 * inside chip depends on mapping of internal address
1703 * the chip decodes channels by.
1704 * CHANNEL_A_NR returns either 0 (in case of
1705 * DECstations) or 1 (in case of Baget).
1707 if (CHANNEL_A_NR
== channel
)
1708 zs_soft
[n_channels
].zs_chan_a
=
1709 &zs_channels
[n_channels
+1-2*CHANNEL_A_NR
];
1711 zs_soft
[n_channels
].zs_chan_a
=
1712 &zs_channels
[n_channels
];
1714 *pp
= &zs_soft
[n_channels
];
1715 pp
= &zs_soft
[n_channels
].zs_next
;
1721 zs_channels_found
= n_channels
;
1723 for (n
= 0; n
< zs_channels_found
; n
++) {
1724 for (i
= 0; i
< 16; i
++) {
1725 zs_soft
[n
].zs_channel
->curregs
[i
] = zs_init_regs
[i
];
1729 save_and_cli(flags
);
1730 for (n
= 0; n
< zs_channels_found
; n
++) {
1732 write_zsreg(zs_soft
[n
].zs_chan_a
, R9
, FHWRES
);
1734 write_zsreg(zs_soft
[n
].zs_chan_a
, R9
, 0);
1736 load_zsregs(zs_soft
[n
].zs_channel
,
1737 zs_soft
[n
].zs_channel
->curregs
);
1739 restore_flags(flags
);
1742 static struct tty_operations serial_ops
= {
1746 .flush_chars
= rs_flush_chars
,
1747 .write_room
= rs_write_room
,
1748 .chars_in_buffer
= rs_chars_in_buffer
,
1749 .flush_buffer
= rs_flush_buffer
,
1751 .throttle
= rs_throttle
,
1752 .unthrottle
= rs_unthrottle
,
1753 .set_termios
= rs_set_termios
,
1756 .hangup
= rs_hangup
,
1757 .break_ctl
= rs_break
,
1758 .wait_until_sent
= rs_wait_until_sent
,
1759 .tiocmget
= rs_tiocmget
,
1760 .tiocmset
= rs_tiocmset
,
1763 /* zs_init inits the driver */
1764 int __init
zs_init(void)
1767 struct dec_serial
*info
;
1772 /* Setup base handler, and timer table. */
1773 init_bh(SERIAL_BH
, do_serial_bh
);
1775 /* Find out how many Z8530 SCCs we have */
1778 serial_driver
= alloc_tty_driver(zs_channels_found
);
1782 show_serial_version();
1784 /* Initialize the tty_driver structure */
1785 /* Not all of this is exactly right for us. */
1787 serial_driver
->owner
= THIS_MODULE
;
1788 serial_driver
->devfs_name
= "tts/";
1789 serial_driver
->name
= "ttyS";
1790 serial_driver
->major
= TTY_MAJOR
;
1791 serial_driver
->minor_start
= 64;
1792 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1793 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1794 serial_driver
->init_termios
= tty_std_termios
;
1795 serial_driver
->init_termios
.c_cflag
=
1796 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1797 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_NO_DEVFS
;
1798 tty_set_operations(serial_driver
, &serial_ops
);
1800 if (tty_register_driver(serial_driver
))
1801 panic("Couldn't register serial driver");
1803 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++) {
1805 /* Needed before interrupts are enabled. */
1809 if (info
->hook
&& info
->hook
->init_info
) {
1810 (*info
->hook
->init_info
)(info
);
1814 info
->magic
= SERIAL_MAGIC
;
1815 info
->port
= (int) info
->zs_channel
->control
;
1817 info
->custom_divisor
= 16;
1818 info
->close_delay
= 50;
1819 info
->closing_wait
= 3000;
1822 info
->blocked_open
= 0;
1823 info
->tqueue
.routine
= do_softint
;
1824 info
->tqueue
.data
= info
;
1825 init_waitqueue_head(&info
->open_wait
);
1826 init_waitqueue_head(&info
->close_wait
);
1827 printk("ttyS%02d at 0x%08x (irq = %d) is a Z85C30 SCC\n",
1828 info
->line
, info
->port
, info
->irq
);
1829 tty_register_device(serial_driver
, info
->line
, NULL
);
1833 for (channel
= 0; channel
< zs_channels_found
; ++channel
) {
1834 zs_soft
[channel
].clk_divisor
= 16;
1835 zs_soft
[channel
].zs_baud
= get_zsbaud(&zs_soft
[channel
]);
1837 if (request_irq(zs_soft
[channel
].irq
, rs_interrupt
, SA_SHIRQ
,
1838 "scc", &zs_soft
[channel
]))
1839 printk(KERN_ERR
"decserial: can't get irq %d\n",
1840 zs_soft
[channel
].irq
);
1842 if (zs_soft
[channel
].hook
) {
1843 zs_startup(&zs_soft
[channel
]);
1844 if (zs_soft
[channel
].hook
->init_channel
)
1845 (*zs_soft
[channel
].hook
->init_channel
)
1846 (&zs_soft
[channel
]);
1854 * polling I/O routines
1857 zs_poll_tx_char(void *handle
, unsigned char ch
)
1859 struct dec_serial
*info
= handle
;
1860 struct dec_zschannel
*chan
= info
->zs_channel
;
1866 while (loops
&& !(read_zsreg(chan
, 0) & Tx_BUF_EMP
))
1870 write_zsdata(chan
, ch
);
1881 zs_poll_rx_char(void *handle
)
1883 struct dec_serial
*info
= handle
;
1884 struct dec_zschannel
*chan
= info
->zs_channel
;
1890 while (loops
&& !(read_zsreg(chan
, 0) & Rx_CH_AV
))
1894 ret
= read_zsdata(chan
);
1903 int register_zs_hook(unsigned int channel
, struct dec_serial_hook
*hook
)
1905 struct dec_serial
*info
= &zs_soft
[channel
];
1908 printk("%s: line %d has already a hook registered\n",
1909 __FUNCTION__
, channel
);
1913 hook
->poll_rx_char
= zs_poll_rx_char
;
1914 hook
->poll_tx_char
= zs_poll_tx_char
;
1921 int unregister_zs_hook(unsigned int channel
)
1923 struct dec_serial
*info
= &zs_soft
[channel
];
1929 printk("%s: trying to unregister hook on line %d,"
1930 " but none is registered\n", __FUNCTION__
, channel
);
1936 * ------------------------------------------------------------
1937 * Serial console driver
1938 * ------------------------------------------------------------
1940 #ifdef CONFIG_SERIAL_DEC_CONSOLE
1944 * Print a string to the serial port trying not to disturb
1945 * any possible real use of the port...
1947 static void serial_console_write(struct console
*co
, const char *s
,
1950 struct dec_serial
*info
;
1953 info
= zs_soft
+ co
->index
;
1955 for (i
= 0; i
< count
; i
++, s
++) {
1957 zs_poll_tx_char(info
, '\r');
1958 zs_poll_tx_char(info
, *s
);
1962 static struct tty_driver
*serial_console_device(struct console
*c
, int *index
)
1965 return serial_driver
;
1969 * Setup initial baud/bits/parity. We do two things here:
1970 * - construct a cflag setting for the first rs_open()
1971 * - initialize the serial port
1972 * Return non-zero if we didn't find a serial port.
1974 static int __init
serial_console_setup(struct console
*co
, char *options
)
1976 struct dec_serial
*info
;
1980 int cflag
= CREAD
| HUPCL
| CLOCAL
;
1981 int clk_divisor
= 16;
1984 unsigned long flags
;
1989 info
= zs_soft
+ co
->index
;
1997 baud
= simple_strtoul(options
, NULL
, 10);
1999 while(*s
>= '0' && *s
<= '9')
2008 * Now construct a cflag setting.
2036 * Set this to a sane value to prevent a divide error.
2060 save_and_cli(flags
);
2063 * Set up the baud rate generator.
2065 brg
= BPS_TO_BRG(baud
, zs_parms
->clock
/ clk_divisor
);
2066 info
->zs_channel
->curregs
[R12
] = (brg
& 255);
2067 info
->zs_channel
->curregs
[R13
] = ((brg
>> 8) & 255);
2070 * Set byte size and parity.
2073 info
->zs_channel
->curregs
[R3
] |= Rx7
;
2074 info
->zs_channel
->curregs
[R5
] |= Tx7
;
2076 info
->zs_channel
->curregs
[R3
] |= Rx8
;
2077 info
->zs_channel
->curregs
[R5
] |= Tx8
;
2079 if (cflag
& PARENB
) {
2080 info
->zs_channel
->curregs
[R4
] |= PAR_ENA
;
2082 if (!(cflag
& PARODD
)) {
2083 info
->zs_channel
->curregs
[R4
] |= PAR_EVEN
;
2085 info
->zs_channel
->curregs
[R4
] |= SB1
;
2088 * Turn on RTS and DTR.
2090 zs_rtsdtr(info
, RTS
| DTR
, 1);
2093 * Finally, enable sequencing.
2095 info
->zs_channel
->curregs
[R3
] |= RxENABLE
;
2096 info
->zs_channel
->curregs
[R5
] |= TxENAB
;
2099 * Clear the interrupt registers.
2101 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
2102 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
2105 * Load up the new values.
2107 load_zsregs(info
->zs_channel
, info
->zs_channel
->curregs
);
2109 /* Save the current value of RR0 */
2110 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, R0
);
2112 zs_soft
[co
->index
].clk_divisor
= clk_divisor
;
2113 zs_soft
[co
->index
].zs_baud
= get_zsbaud(&zs_soft
[co
->index
]);
2115 restore_flags(flags
);
2120 static struct console sercons
= {
2122 .write
= serial_console_write
,
2123 .device
= serial_console_device
,
2124 .setup
= serial_console_setup
,
2125 .flags
= CON_PRINTBUFFER
,
2132 void __init
zs_serial_console_init(void)
2134 register_console(&sercons
);
2136 #endif /* ifdef CONFIG_SERIAL_DEC_CONSOLE */
2139 struct dec_zschannel
*zs_kgdbchan
;
2140 static unsigned char scc_inittab
[] = {
2141 9, 0x80, /* reset A side (CHRA) */
2142 13, 0, /* set baud rate divisor */
2144 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
2145 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
2146 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
2147 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
2148 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
2151 /* These are for receiving and sending characters under the kgdb
2152 * source level kernel debugger.
2154 void putDebugChar(char kgdb_char
)
2156 struct dec_zschannel
*chan
= zs_kgdbchan
;
2157 while ((read_zsreg(chan
, 0) & Tx_BUF_EMP
) == 0)
2159 write_zsdata(chan
, kgdb_char
);
2161 char getDebugChar(void)
2163 struct dec_zschannel
*chan
= zs_kgdbchan
;
2164 while((read_zsreg(chan
, 0) & Rx_CH_AV
) == 0)
2165 eieio(); /*barrier();*/
2166 return read_zsdata(chan
);
2168 void kgdb_interruptible(int yes
)
2170 struct dec_zschannel
*chan
= zs_kgdbchan
;
2172 nine
= read_zsreg(chan
, 9);
2174 one
= EXT_INT_ENAB
|RxINT_ALL
;
2176 printk("turning serial ints on\n");
2180 printk("turning serial ints off\n");
2182 write_zsreg(chan
, 1, one
);
2183 write_zsreg(chan
, 9, nine
);
2186 static int kgdbhook_init_channel(void *handle
)
2191 static void kgdbhook_init_info(void *handle
)
2195 static void kgdbhook_rx_char(void *handle
, unsigned char ch
, unsigned char fl
)
2197 struct dec_serial
*info
= handle
;
2199 if (fl
!= TTY_NORMAL
)
2201 if (ch
== 0x03 || ch
== '$')
2205 /* This sets up the serial port we're using, and turns on
2206 * interrupts for that channel, so kgdb is usable once we're done.
2208 static inline void kgdb_chaninit(struct dec_zschannel
*ms
, int intson
, int bps
)
2212 volatile char *sccc
= ms
->control
;
2213 brg
= BPS_TO_BRG(bps
, zs_parms
->clock
/16);
2214 printk("setting bps on kgdb line to %d [brg=%x]\n", bps
, brg
);
2215 for (i
= 20000; i
!= 0; --i
) {
2218 for (i
= 0; i
< sizeof(scc_inittab
); ++i
) {
2219 write_zsreg(ms
, scc_inittab
[i
], scc_inittab
[i
+1]);
2223 /* This is called at boot time to prime the kgdb serial debugging
2224 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2225 * for /dev/ttyb which is determined in setup_arch() from the
2226 * boot command line flags.
2228 struct dec_serial_hook zs_kgdbhook
= {
2229 .init_channel
= kgdbhook_init_channel
,
2230 .init_info
= kgdbhook_init_info
,
2231 .rx_char
= kgdbhook_rx_char
,
2232 .cflags
= B38400
| CS8
| CLOCAL
,
2235 void __init
zs_kgdb_hook(int tty_num
)
2237 /* Find out how many Z8530 SCCs we have */
2240 zs_soft
[tty_num
].zs_channel
= &zs_channels
[tty_num
];
2241 zs_kgdbchan
= zs_soft
[tty_num
].zs_channel
;
2242 zs_soft
[tty_num
].change_needed
= 0;
2243 zs_soft
[tty_num
].clk_divisor
= 16;
2244 zs_soft
[tty_num
].zs_baud
= 38400;
2245 zs_soft
[tty_num
].hook
= &zs_kgdbhook
; /* This runs kgdb */
2246 /* Turn on transmitter/receiver at 8-bits/char */
2247 kgdb_chaninit(zs_soft
[tty_num
].zs_channel
, 1, 38400);
2248 printk("KGDB: on channel %d initialized\n", tty_num
);
2249 set_debug_traps(); /* init stub */
2251 #endif /* ifdef CONFIG_KGDB */