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>
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 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
);
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
)
298 save_flags(flags
); cli();
299 if (info
->zs_channel
!= info
->zs_chan_a
) {
301 info
->zs_chan_a
->curregs
[5] |= (which
& (RTS
| DTR
));
303 info
->zs_chan_a
->curregs
[5] &= ~(which
& (RTS
| DTR
));
305 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
307 restore_flags(flags
);
310 /* Utility routines for the Zilog */
311 static inline int get_zsbaud(struct dec_serial
*ss
)
313 struct dec_zschannel
*channel
= ss
->zs_channel
;
316 /* The baud rate is split up between two 8-bit registers in
317 * what is termed 'BRG time constant' format in my docs for
318 * the chip, it is a function of the clk rate the chip is
319 * receiving which happens to be constant.
321 brg
= (read_zsreg(channel
, 13) << 8);
322 brg
|= read_zsreg(channel
, 12);
323 return BRG_TO_BPS(brg
, (zs_parms
->clock
/(ss
->clk_divisor
)));
326 /* On receive, this clears errors and the receiver interrupts */
327 static inline void rs_recv_clear(struct dec_zschannel
*zsc
)
329 write_zsreg(zsc
, 0, ERR_RES
);
330 write_zsreg(zsc
, 0, RES_H_IUS
); /* XXX this is unnecessary */
334 * ----------------------------------------------------------------------
336 * Here starts the interrupt handling routines. All of the following
337 * subroutines are declared as inline and are folded into
338 * rs_interrupt(). They were separated out for readability's sake.
340 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
341 * -----------------------------------------------------------------------
345 * This routine is used by the interrupt handler to schedule
346 * processing in the software interrupt portion of the driver.
348 static _INLINE_
void rs_sched_event(struct dec_serial
*info
,
351 info
->event
|= 1 << event
;
352 queue_task(&info
->tqueue
, &tq_zs_serial
);
356 static _INLINE_
void receive_chars(struct dec_serial
*info
,
357 struct pt_regs
*regs
)
359 struct tty_struct
*tty
= info
->tty
;
360 unsigned char ch
, stat
, flag
;
362 while ((read_zsreg(info
->zs_channel
, R0
) & Rx_CH_AV
) != 0) {
364 stat
= read_zsreg(info
->zs_channel
, R1
);
365 ch
= read_zsdata(info
->zs_channel
);
367 if (!tty
&& (!info
->hook
|| !info
->hook
->rx_char
))
371 if (info
->tty_break
) {
374 if (info
->flags
& ZILOG_SAK
)
376 /* Ignore the null char got when BREAK is removed. */
382 } else if (stat
& FRM_ERR
) {
384 } else if (stat
& PAR_ERR
) {
387 if (flag
!= TTY_NORMAL
)
388 /* reset the error indication */
389 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
392 #if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
394 if (break_pressed
&& info
->line
== sercons
.index
) {
395 /* Ignore the null char got when BREAK is removed. */
398 if (time_before(jiffies
, break_pressed
+ HZ
* 5)) {
399 handle_sysrq(ch
, regs
, NULL
);
407 if (info
->hook
&& info
->hook
->rx_char
) {
408 (*info
->hook
->rx_char
)(ch
, flag
);
412 tty_insert_flip_char(tty
, ch
, flag
);
415 tty_flip_buffer_push(tty
);
418 static void transmit_chars(struct dec_serial
*info
)
420 if ((read_zsreg(info
->zs_channel
, R0
) & Tx_BUF_EMP
) == 0)
426 write_zsdata(info
->zs_channel
, info
->x_char
);
432 if ((info
->xmit_cnt
<= 0) || (info
->tty
&& info
->tty
->stopped
)
433 || info
->tx_stopped
) {
434 write_zsreg(info
->zs_channel
, R0
, RES_Tx_P
);
438 write_zsdata(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
439 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
443 if (info
->xmit_cnt
< WAKEUP_CHARS
)
444 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
447 static _INLINE_
void status_handle(struct dec_serial
*info
)
451 /* Get status from Read Register 0 */
452 stat
= read_zsreg(info
->zs_channel
, R0
);
454 if ((stat
& BRK_ABRT
) && !(info
->read_reg_zero
& BRK_ABRT
)) {
455 #if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
457 if (info
->line
== sercons
.index
) {
459 break_pressed
= jiffies
;
465 if (info
->zs_channel
!= info
->zs_chan_a
) {
467 /* Check for DCD transitions */
468 if (info
->tty
&& !C_CLOCAL(info
->tty
) &&
469 ((stat
^ info
->read_reg_zero
) & DCD
) != 0 ) {
471 wake_up_interruptible(&info
->open_wait
);
473 tty_hangup(info
->tty
);
477 /* Check for CTS transitions */
478 if (info
->tty
&& C_CRTSCTS(info
->tty
)) {
479 if ((stat
& CTS
) != 0) {
480 if (info
->tx_stopped
) {
481 info
->tx_stopped
= 0;
482 if (!info
->tx_active
)
483 transmit_chars(info
);
486 info
->tx_stopped
= 1;
492 /* Clear status condition... */
493 write_zsreg(info
->zs_channel
, R0
, RES_EXT_INT
);
494 info
->read_reg_zero
= stat
;
498 * This is the serial driver's generic interrupt routine
500 void rs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
502 struct dec_serial
*info
= (struct dec_serial
*) dev_id
;
503 unsigned char zs_intreg
;
506 /* NOTE: The read register 3, which holds the irq status,
507 * does so for both channels on each chip. Although
508 * the status value itself must be read from the A
509 * channel and is only valid when read from channel A.
510 * Yes... broken hardware...
512 #define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
514 if (info
->zs_chan_a
== info
->zs_channel
)
515 shift
= 3; /* Channel A */
517 shift
= 0; /* Channel B */
520 zs_intreg
= read_zsreg(info
->zs_chan_a
, R3
) >> shift
;
521 if ((zs_intreg
& CHAN_IRQMASK
) == 0)
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
);
540 void zs_dump (void) {
542 for (i
= 0; i
< zs_channels_found
; i
++) {
543 struct dec_zschannel
*ch
= &zs_channels
[i
];
544 if ((long)ch
->control
== UNI_IO_BASE
+UNI_SCC1A_CTRL
) {
545 for (j
= 0; j
< 15; j
++) {
546 printk("W%d = 0x%x\t",
547 j
, (int)ch
->curregs
[j
]);
549 for (j
= 0; j
< 15; j
++) {
550 printk("R%d = 0x%x\t",
551 j
, (int)read_zsreg(ch
,j
));
560 * -------------------------------------------------------------------
561 * Here ends the serial interrupt routines.
562 * -------------------------------------------------------------------
566 * ------------------------------------------------------------
567 * rs_stop() and rs_start()
569 * This routines are called before setting or resetting tty->stopped.
570 * ------------------------------------------------------------
572 static void rs_stop(struct tty_struct
*tty
)
574 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
577 if (serial_paranoia_check(info
, tty
->name
, "rs_stop"))
581 save_flags(flags
); cli();
582 if (info
->zs_channel
->curregs
[5] & TxENAB
) {
583 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
584 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
586 restore_flags(flags
);
590 static void rs_start(struct tty_struct
*tty
)
592 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
595 if (serial_paranoia_check(info
, tty
->name
, "rs_start"))
598 save_flags(flags
); cli();
600 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->zs_channel
->curregs
[5] & TxENAB
)) {
601 info
->zs_channel
->curregs
[5] |= TxENAB
;
602 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
605 if (info
->xmit_cnt
&& info
->xmit_buf
&& !info
->tx_active
) {
606 transmit_chars(info
);
609 restore_flags(flags
);
613 * This routine is used to handle the "bottom half" processing for the
614 * serial driver, known also the "software interrupt" processing.
615 * This processing is done at the kernel interrupt level, after the
616 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
617 * is where time-consuming activities which can not be done in the
618 * interrupt driver proper are done; the interrupt driver schedules
619 * them using rs_sched_event(), and they get done here.
621 static void do_serial_bh(void)
623 run_task_queue(&tq_zs_serial
);
626 static void do_softint(void *private_
)
628 struct dec_serial
*info
= (struct dec_serial
*) private_
;
629 struct tty_struct
*tty
;
635 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
640 int zs_startup(struct dec_serial
* info
)
644 if (info
->flags
& ZILOG_INITIALIZED
)
647 if (!info
->xmit_buf
) {
648 info
->xmit_buf
= (unsigned char *) get_zeroed_page(GFP_KERNEL
);
653 save_flags(flags
); cli();
655 #ifdef SERIAL_DEBUG_OPEN
656 printk("starting up ttyS%d (irq %d)...", info
->line
, info
->irq
);
660 * Clear the receive FIFO.
662 ZS_CLEARFIFO(info
->zs_channel
);
663 info
->xmit_fifo_size
= 1;
666 * Clear the interrupt registers.
668 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
669 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
672 * Set the speed of the serial port
677 * Turn on RTS and DTR.
679 zs_rtsdtr(info
, RTS
| DTR
, 1);
682 * Finally, enable sequencing and interrupts
684 info
->zs_channel
->curregs
[R1
] &= ~RxINT_MASK
;
685 info
->zs_channel
->curregs
[R1
] |= (RxINT_ALL
| TxINT_ENAB
|
687 info
->zs_channel
->curregs
[R3
] |= RxENABLE
;
688 info
->zs_channel
->curregs
[R5
] |= TxENAB
;
689 info
->zs_channel
->curregs
[R15
] |= (DCDIE
| CTSIE
| TxUIE
| BRKIE
);
690 write_zsreg(info
->zs_channel
, R1
, info
->zs_channel
->curregs
[R1
]);
691 write_zsreg(info
->zs_channel
, R3
, info
->zs_channel
->curregs
[R3
]);
692 write_zsreg(info
->zs_channel
, R5
, info
->zs_channel
->curregs
[R5
]);
693 write_zsreg(info
->zs_channel
, R15
, info
->zs_channel
->curregs
[R15
]);
696 * And clear the interrupt registers again for luck.
698 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
699 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
701 /* Save the current value of RR0 */
702 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, R0
);
705 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
706 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
708 info
->flags
|= ZILOG_INITIALIZED
;
709 restore_flags(flags
);
714 * This routine will shutdown a serial port; interrupts are disabled, and
715 * DTR is dropped if the hangup on close termio flag is on.
717 static void shutdown(struct dec_serial
* info
)
721 if (!(info
->flags
& ZILOG_INITIALIZED
))
724 #ifdef SERIAL_DEBUG_OPEN
725 printk("Shutting down serial port %d (irq %d)....", info
->line
,
729 save_flags(flags
); cli(); /* Disable interrupts */
731 if (info
->xmit_buf
) {
732 free_page((unsigned long) info
->xmit_buf
);
736 info
->zs_channel
->curregs
[1] = 0;
737 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]); /* no interrupts */
739 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
740 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
742 info
->zs_channel
->curregs
[5] &= ~TxENAB
;
743 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
744 if (!info
->tty
|| C_HUPCL(info
->tty
)) {
745 zs_rtsdtr(info
, RTS
| DTR
, 0);
749 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
751 info
->flags
&= ~ZILOG_INITIALIZED
;
752 restore_flags(flags
);
756 * This routine is called to set the UART divisor registers to match
757 * the specified baud rate for a serial port.
759 static void change_speed(struct dec_serial
*info
)
767 if (!info
->tty
|| !info
->tty
->termios
)
769 cflag
= info
->tty
->termios
->c_cflag
;
773 cflag
= info
->hook
->cflags
;
779 if (i
< 1 || i
> 2) {
781 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
783 info
->hook
->cflags
&= ~CBAUDEX
;
788 save_flags(flags
); cli();
789 info
->zs_baud
= baud_table
[i
];
791 brg
= BPS_TO_BRG(info
->zs_baud
, zs_parms
->clock
/info
->clk_divisor
);
792 info
->zs_channel
->curregs
[12] = (brg
& 255);
793 info
->zs_channel
->curregs
[13] = ((brg
>> 8) & 255);
794 zs_rtsdtr(info
, DTR
, 1);
796 zs_rtsdtr(info
, RTS
| DTR
, 0);
800 /* byte size and parity */
801 info
->zs_channel
->curregs
[3] &= ~RxNBITS_MASK
;
802 info
->zs_channel
->curregs
[5] &= ~TxNBITS_MASK
;
803 switch (cflag
& CSIZE
) {
806 info
->zs_channel
->curregs
[3] |= Rx5
;
807 info
->zs_channel
->curregs
[5] |= Tx5
;
811 info
->zs_channel
->curregs
[3] |= Rx6
;
812 info
->zs_channel
->curregs
[5] |= Tx6
;
816 info
->zs_channel
->curregs
[3] |= Rx7
;
817 info
->zs_channel
->curregs
[5] |= Tx7
;
820 default: /* defaults to 8 bits */
822 info
->zs_channel
->curregs
[3] |= Rx8
;
823 info
->zs_channel
->curregs
[5] |= Tx8
;
827 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
) / info
->zs_baud
);
828 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
830 info
->zs_channel
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
831 if (cflag
& CSTOPB
) {
832 info
->zs_channel
->curregs
[4] |= SB2
;
834 info
->zs_channel
->curregs
[4] |= SB1
;
836 if (cflag
& PARENB
) {
837 info
->zs_channel
->curregs
[4] |= PAR_ENA
;
839 if (!(cflag
& PARODD
)) {
840 info
->zs_channel
->curregs
[4] |= PAR_EVEN
;
843 if (!(cflag
& CLOCAL
)) {
844 if (!(info
->zs_channel
->curregs
[15] & DCDIE
))
845 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
846 info
->zs_channel
->curregs
[15] |= DCDIE
;
848 info
->zs_channel
->curregs
[15] &= ~DCDIE
;
849 if (cflag
& CRTSCTS
) {
850 info
->zs_channel
->curregs
[15] |= CTSIE
;
851 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) == 0)
852 info
->tx_stopped
= 1;
854 info
->zs_channel
->curregs
[15] &= ~CTSIE
;
855 info
->tx_stopped
= 0;
858 /* Load up the new values */
859 load_zsregs(info
->zs_channel
, info
->zs_channel
->curregs
);
861 restore_flags(flags
);
864 static void rs_flush_chars(struct tty_struct
*tty
)
866 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
869 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_chars"))
872 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| info
->tx_stopped
||
876 /* Enable transmitter */
877 save_flags(flags
); cli();
878 transmit_chars(info
);
879 restore_flags(flags
);
882 static int rs_write(struct tty_struct
* tty
,
883 const unsigned char *buf
, int count
)
886 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
889 if (serial_paranoia_check(info
, tty
->name
, "rs_write"))
892 if (!tty
|| !info
->xmit_buf
)
898 c
= min(count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
899 SERIAL_XMIT_SIZE
- info
->xmit_head
));
905 copy_from_user(tmp_buf
, buf
, c
);
906 c
= min(c
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
907 SERIAL_XMIT_SIZE
- info
->xmit_head
));
908 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
911 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
912 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
914 restore_flags(flags
);
920 if (info
->xmit_cnt
&& !tty
->stopped
&& !info
->tx_stopped
922 transmit_chars(info
);
923 restore_flags(flags
);
927 static int rs_write_room(struct tty_struct
*tty
)
929 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
932 if (serial_paranoia_check(info
, tty
->name
, "rs_write_room"))
934 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
940 static int rs_chars_in_buffer(struct tty_struct
*tty
)
942 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
944 if (serial_paranoia_check(info
, tty
->name
, "rs_chars_in_buffer"))
946 return info
->xmit_cnt
;
949 static void rs_flush_buffer(struct tty_struct
*tty
)
951 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
953 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_buffer"))
956 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
962 * ------------------------------------------------------------
965 * This routine is called by the upper-layer tty layer to signal that
966 * incoming characters should be throttled.
967 * ------------------------------------------------------------
969 static void rs_throttle(struct tty_struct
* tty
)
971 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
974 #ifdef SERIAL_DEBUG_THROTTLE
977 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
978 tty
->ldisc
.chars_in_buffer(tty
));
981 if (serial_paranoia_check(info
, tty
->name
, "rs_throttle"))
985 save_flags(flags
); cli();
986 info
->x_char
= STOP_CHAR(tty
);
987 if (!info
->tx_active
)
988 transmit_chars(info
);
989 restore_flags(flags
);
992 if (C_CRTSCTS(tty
)) {
993 zs_rtsdtr(info
, RTS
, 0);
997 static void rs_unthrottle(struct tty_struct
* tty
)
999 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
1000 unsigned long flags
;
1002 #ifdef SERIAL_DEBUG_THROTTLE
1005 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1006 tty
->ldisc
.chars_in_buffer(tty
));
1009 if (serial_paranoia_check(info
, tty
->name
, "rs_unthrottle"))
1013 save_flags(flags
); cli();
1017 info
->x_char
= START_CHAR(tty
);
1018 if (!info
->tx_active
)
1019 transmit_chars(info
);
1021 restore_flags(flags
);
1024 if (C_CRTSCTS(tty
)) {
1025 zs_rtsdtr(info
, RTS
, 1);
1030 * ------------------------------------------------------------
1031 * rs_ioctl() and friends
1032 * ------------------------------------------------------------
1035 static int get_serial_info(struct dec_serial
* info
,
1036 struct serial_struct
* retinfo
)
1038 struct serial_struct tmp
;
1042 memset(&tmp
, 0, sizeof(tmp
));
1043 tmp
.type
= info
->type
;
1044 tmp
.line
= info
->line
;
1045 tmp
.port
= info
->port
;
1046 tmp
.irq
= info
->irq
;
1047 tmp
.flags
= info
->flags
;
1048 tmp
.baud_base
= info
->baud_base
;
1049 tmp
.close_delay
= info
->close_delay
;
1050 tmp
.closing_wait
= info
->closing_wait
;
1051 tmp
.custom_divisor
= info
->custom_divisor
;
1052 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)) ? -EFAULT
: 0;
1055 static int set_serial_info(struct dec_serial
* info
,
1056 struct serial_struct
* new_info
)
1058 struct serial_struct new_serial
;
1059 struct dec_serial old_info
;
1064 copy_from_user(&new_serial
,new_info
,sizeof(new_serial
));
1067 if (!capable(CAP_SYS_ADMIN
)) {
1068 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1069 (new_serial
.type
!= info
->type
) ||
1070 (new_serial
.close_delay
!= info
->close_delay
) ||
1071 ((new_serial
.flags
& ~ZILOG_USR_MASK
) !=
1072 (info
->flags
& ~ZILOG_USR_MASK
)))
1074 info
->flags
= ((info
->flags
& ~ZILOG_USR_MASK
) |
1075 (new_serial
.flags
& ZILOG_USR_MASK
));
1076 info
->custom_divisor
= new_serial
.custom_divisor
;
1077 goto check_and_exit
;
1080 if (info
->count
> 1)
1084 * OK, past this point, all the error checking has been done.
1085 * At this point, we start making changes.....
1088 info
->baud_base
= new_serial
.baud_base
;
1089 info
->flags
= ((info
->flags
& ~ZILOG_FLAGS
) |
1090 (new_serial
.flags
& ZILOG_FLAGS
));
1091 info
->type
= new_serial
.type
;
1092 info
->close_delay
= new_serial
.close_delay
;
1093 info
->closing_wait
= new_serial
.closing_wait
;
1096 retval
= zs_startup(info
);
1101 * get_lsr_info - get line status register info
1103 * Purpose: Let user call ioctl() to get info when the UART physically
1104 * is emptied. On bus types like RS485, the transmitter must
1105 * release the bus after transmitting. This must be done when
1106 * the transmit shift register is empty, not be done when the
1107 * transmit holding register is empty. This functionality
1108 * allows an RS485 driver to be written in user space.
1110 static int get_lsr_info(struct dec_serial
* info
, unsigned int *value
)
1112 unsigned char status
;
1115 status
= read_zsreg(info
->zs_channel
, 0);
1117 put_user(status
,value
);
1121 static int rs_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1123 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1124 unsigned char control
, status_a
, status_b
;
1125 unsigned int result
;
1130 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1133 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1136 if (info
->zs_channel
== info
->zs_chan_a
)
1140 control
= info
->zs_chan_a
->curregs
[5];
1141 status_a
= read_zsreg(info
->zs_chan_a
, 0);
1142 status_b
= read_zsreg(info
->zs_channel
, 0);
1144 result
= ((control
& RTS
) ? TIOCM_RTS
: 0)
1145 | ((control
& DTR
) ? TIOCM_DTR
: 0)
1146 | ((status_b
& DCD
) ? TIOCM_CAR
: 0)
1147 | ((status_a
& DCD
) ? TIOCM_RNG
: 0)
1148 | ((status_a
& SYNC_HUNT
) ? TIOCM_DSR
: 0)
1149 | ((status_b
& CTS
) ? TIOCM_CTS
: 0);
1154 static int rs_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1155 unsigned int set
, unsigned int clear
)
1157 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1159 unsigned int arg
, bits
;
1164 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1167 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1170 if (info
->zs_channel
== info
->zs_chan_a
)
1173 get_user(arg
, value
);
1175 if (set
& TIOCM_RTS
)
1176 info
->zs_chan_a
->curregs
[5] |= RTS
;
1177 if (set
& TIOCM_DTR
)
1178 info
->zs_chan_a
->curregs
[5] |= DTR
;
1179 if (clear
& TIOCM_RTS
)
1180 info
->zs_chan_a
->curregs
[5] &= ~RTS
;
1181 if (clear
& TIOCM_DTR
)
1182 info
->zs_chan_a
->curregs
[5] &= ~DTR
;
1183 write_zsreg(info
->zs_chan_a
, 5, info
->zs_chan_a
->curregs
[5]);
1189 * rs_break - turn transmit break condition on/off
1191 static void rs_break(struct tty_struct
*tty
, int break_state
)
1193 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1194 unsigned long flags
;
1196 if (serial_paranoia_check(info
, tty
->name
, "rs_break"))
1201 save_flags(flags
); cli();
1202 if (break_state
== -1)
1203 info
->zs_channel
->curregs
[5] |= SND_BRK
;
1205 info
->zs_channel
->curregs
[5] &= ~SND_BRK
;
1206 write_zsreg(info
->zs_channel
, 5, info
->zs_channel
->curregs
[5]);
1207 restore_flags(flags
);
1210 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1211 unsigned int cmd
, unsigned long arg
)
1214 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1219 if (serial_paranoia_check(info
, tty
->name
, "rs_ioctl"))
1222 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1223 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1224 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1225 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1231 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1232 sizeof(struct serial_struct
)))
1234 return get_serial_info(info
, (struct serial_struct
*)arg
);
1237 return set_serial_info(info
, (struct serial_struct
*)arg
);
1239 case TIOCSERGETLSR
: /* Get line status register */
1240 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1241 sizeof(unsigned int)))
1243 return get_lsr_info(info
, (unsigned int *)arg
);
1245 case TIOCSERGSTRUCT
:
1246 if (!access_ok(VERIFY_WRITE
, (void *)arg
,
1247 sizeof(struct dec_serial
)))
1249 copy_from_user((struct dec_serial
*)arg
, info
,
1250 sizeof(struct dec_serial
));
1254 return -ENOIOCTLCMD
;
1259 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1261 struct dec_serial
*info
= (struct dec_serial
*)tty
->driver_data
;
1264 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1266 was_stopped
= info
->tx_stopped
;
1270 if (was_stopped
&& !info
->tx_stopped
)
1275 * ------------------------------------------------------------
1278 * This routine is called when the serial port gets closed.
1279 * Wait for the last remaining data to be sent.
1280 * ------------------------------------------------------------
1282 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
1284 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1285 unsigned long flags
;
1287 if (!info
|| serial_paranoia_check(info
, tty
->name
, "rs_close"))
1290 save_flags(flags
); cli();
1292 if (tty_hung_up_p(filp
)) {
1293 restore_flags(flags
);
1297 #ifdef SERIAL_DEBUG_OPEN
1298 printk("rs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1300 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1302 * Uh, oh. tty->count is 1, which means that the tty
1303 * structure will be freed. Info->count should always
1304 * be one in these conditions. If it's greater than
1305 * one, we've got real problems, since it means the
1306 * serial port won't be shutdown.
1308 printk("rs_close: bad serial port count; tty->count is 1, "
1309 "info->count is %d\n", info
->count
);
1312 if (--info
->count
< 0) {
1313 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1314 info
->line
, info
->count
);
1318 restore_flags(flags
);
1321 info
->flags
|= ZILOG_CLOSING
;
1323 * Now we wait for the transmit buffer to clear; and we notify
1324 * the line discipline to only process XON/XOFF characters.
1327 if (info
->closing_wait
!= ZILOG_CLOSING_WAIT_NONE
)
1328 tty_wait_until_sent(tty
, info
->closing_wait
);
1330 * At this point we stop accepting input. To do this, we
1331 * disable the receiver and receive interrupts.
1333 info
->zs_channel
->curregs
[3] &= ~RxENABLE
;
1334 write_zsreg(info
->zs_channel
, 3, info
->zs_channel
->curregs
[3]);
1335 info
->zs_channel
->curregs
[1] = 0; /* disable any rx ints */
1336 write_zsreg(info
->zs_channel
, 1, info
->zs_channel
->curregs
[1]);
1337 ZS_CLEARFIFO(info
->zs_channel
);
1338 if (info
->flags
& ZILOG_INITIALIZED
) {
1340 * Before we drop DTR, make sure the SCC transmitter
1341 * has completely drained.
1343 rs_wait_until_sent(tty
, info
->timeout
);
1347 if (tty
->driver
->flush_buffer
)
1348 tty
->driver
->flush_buffer(tty
);
1349 tty_ldisc_flush(tty
);
1353 if (info
->blocked_open
) {
1354 if (info
->close_delay
) {
1355 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
1357 wake_up_interruptible(&info
->open_wait
);
1359 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CLOSING
);
1360 wake_up_interruptible(&info
->close_wait
);
1361 restore_flags(flags
);
1365 * rs_wait_until_sent() --- wait until the transmitter is empty
1367 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1369 struct dec_serial
*info
= (struct dec_serial
*) tty
->driver_data
;
1370 unsigned long orig_jiffies
;
1373 if (serial_paranoia_check(info
, tty
->name
, "rs_wait_until_sent"))
1376 orig_jiffies
= jiffies
;
1378 * Set the check interval to be 1/5 of the estimated time to
1379 * send a single character, and make it at least 1. The check
1380 * interval should also be less than the timeout.
1382 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1383 char_time
= char_time
/ 5;
1387 char_time
= min(char_time
, timeout
);
1388 while ((read_zsreg(info
->zs_channel
, 1) & Tx_BUF_EMP
) == 0) {
1389 msleep_interruptible(jiffies_to_msecs(char_time
));
1390 if (signal_pending(current
))
1392 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1395 current
->state
= TASK_RUNNING
;
1399 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1401 void rs_hangup(struct tty_struct
*tty
)
1403 struct dec_serial
* info
= (struct dec_serial
*)tty
->driver_data
;
1405 if (serial_paranoia_check(info
, tty
->name
, "rs_hangup"))
1408 rs_flush_buffer(tty
);
1412 info
->flags
&= ~ZILOG_NORMAL_ACTIVE
;
1414 wake_up_interruptible(&info
->open_wait
);
1418 * ------------------------------------------------------------
1419 * rs_open() and friends
1420 * ------------------------------------------------------------
1422 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1423 struct dec_serial
*info
)
1425 DECLARE_WAITQUEUE(wait
, current
);
1430 * If the device is in the middle of being closed, then block
1431 * until it's done, and then try again.
1433 if (info
->flags
& ZILOG_CLOSING
) {
1434 interruptible_sleep_on(&info
->close_wait
);
1435 #ifdef SERIAL_DO_RESTART
1436 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1437 -EAGAIN
: -ERESTARTSYS
);
1444 * If non-blocking mode is set, or the port is not enabled,
1445 * then make the check up front and then exit.
1447 if ((filp
->f_flags
& O_NONBLOCK
) ||
1448 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1449 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1453 if (tty
->termios
->c_cflag
& CLOCAL
)
1457 * Block waiting for the carrier detect and the line to become
1458 * free (i.e., not in use by the callout). While we are in
1459 * this loop, info->count is dropped by one, so that
1460 * rs_close() knows when to free things. We restore it upon
1461 * exit, either normal or abnormal.
1464 add_wait_queue(&info
->open_wait
, &wait
);
1465 #ifdef SERIAL_DEBUG_OPEN
1466 printk("block_til_ready before block: ttyS%d, count = %d\n",
1467 info
->line
, info
->count
);
1470 if (!tty_hung_up_p(filp
))
1473 info
->blocked_open
++;
1476 if (tty
->termios
->c_cflag
& CBAUD
)
1477 zs_rtsdtr(info
, RTS
| DTR
, 1);
1479 set_current_state(TASK_INTERRUPTIBLE
);
1480 if (tty_hung_up_p(filp
) ||
1481 !(info
->flags
& ZILOG_INITIALIZED
)) {
1482 #ifdef SERIAL_DO_RESTART
1483 if (info
->flags
& ZILOG_HUP_NOTIFY
)
1486 retval
= -ERESTARTSYS
;
1492 if (!(info
->flags
& ZILOG_CLOSING
) &&
1493 (do_clocal
|| (read_zsreg(info
->zs_channel
, 0) & DCD
)))
1495 if (signal_pending(current
)) {
1496 retval
= -ERESTARTSYS
;
1499 #ifdef SERIAL_DEBUG_OPEN
1500 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1501 info
->line
, info
->count
);
1505 current
->state
= TASK_RUNNING
;
1506 remove_wait_queue(&info
->open_wait
, &wait
);
1507 if (!tty_hung_up_p(filp
))
1509 info
->blocked_open
--;
1510 #ifdef SERIAL_DEBUG_OPEN
1511 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1512 info
->line
, info
->count
);
1516 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1521 * This routine is called whenever a serial port is opened. It
1522 * enables interrupts for a serial port, linking in its ZILOG structure into
1523 * the IRQ chain. It also performs the serial-specific
1524 * initialization for the tty structure.
1526 int rs_open(struct tty_struct
*tty
, struct file
* filp
)
1528 struct dec_serial
*info
;
1532 if ((line
< 0) || (line
>= zs_channels_found
))
1534 info
= zs_soft
+ line
;
1539 if (serial_paranoia_check(info
, tty
->name
, "rs_open"))
1541 #ifdef SERIAL_DEBUG_OPEN
1542 printk("rs_open %s, count = %d\n", tty
->name
, info
->count
);
1546 tty
->driver_data
= info
;
1550 * If the port is the middle of closing, bail out now
1552 if (tty_hung_up_p(filp
) ||
1553 (info
->flags
& ZILOG_CLOSING
)) {
1554 if (info
->flags
& ZILOG_CLOSING
)
1555 interruptible_sleep_on(&info
->close_wait
);
1556 #ifdef SERIAL_DO_RESTART
1557 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1558 -EAGAIN
: -ERESTARTSYS
);
1565 * Start up serial port
1567 retval
= zs_startup(info
);
1571 retval
= block_til_ready(tty
, filp
, info
);
1573 #ifdef SERIAL_DEBUG_OPEN
1574 printk("rs_open returning after block_til_ready with %d\n",
1580 #ifdef CONFIG_SERIAL_DEC_CONSOLE
1581 if (sercons
.cflag
&& sercons
.index
== line
) {
1582 tty
->termios
->c_cflag
= sercons
.cflag
;
1588 #ifdef SERIAL_DEBUG_OPEN
1589 printk("rs_open %s successful...", tty
->name
);
1591 /* tty->low_latency = 1; */
1595 /* Finally, routines used to initialize the serial driver. */
1597 static void __init
show_serial_version(void)
1599 printk("DECstation Z8530 serial driver version 0.09\n");
1602 /* Initialize Z8530s zs_channels
1605 static void __init
probe_sccs(void)
1607 struct dec_serial
**pp
;
1608 int i
, n
, n_chips
= 0, n_channels
, chip
, channel
;
1609 unsigned long flags
;
1612 * did we get here by accident?
1615 printk("Not on JUNKIO machine, skipping probe_sccs\n");
1619 switch(mips_machtype
) {
1620 #ifdef CONFIG_MACH_DECSTATION
1621 case MACH_DS5000_2X0
:
1624 zs_parms
= &ds_parms
;
1625 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1626 zs_parms
->irq1
= dec_interrupt
[DEC_IRQ_SCC1
];
1628 case MACH_DS5000_1XX
:
1630 zs_parms
= &ds_parms
;
1631 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1632 zs_parms
->irq1
= dec_interrupt
[DEC_IRQ_SCC1
];
1634 case MACH_DS5000_XX
:
1636 zs_parms
= &ds_parms
;
1637 zs_parms
->irq0
= dec_interrupt
[DEC_IRQ_SCC0
];
1641 panic("zs: unsupported bus");
1644 panic("zs: uninitialized parms");
1650 for (chip
= 0; chip
< n_chips
; chip
++) {
1651 for (channel
= 0; channel
<= 1; channel
++) {
1653 * The sccs reside on the high byte of the 16 bit IOBUS
1655 zs_channels
[n_channels
].control
=
1656 (volatile void *)CKSEG1ADDR(dec_kn_slot_base
+
1657 (0 == chip
? zs_parms
->scc0
: zs_parms
->scc1
) +
1658 (0 == channel
? zs_parms
->channel_a_offset
:
1659 zs_parms
->channel_b_offset
));
1660 zs_channels
[n_channels
].data
=
1661 zs_channels
[n_channels
].control
+ 4;
1663 #ifndef CONFIG_SERIAL_DEC_CONSOLE
1665 * We're called early and memory managment isn't up, yet.
1666 * Thus request_region would fail.
1668 if (!request_region((unsigned long)
1669 zs_channels
[n_channels
].control
,
1670 ZS_CHAN_IO_SIZE
, "SCC"))
1671 panic("SCC I/O region is not free");
1673 zs_soft
[n_channels
].zs_channel
= &zs_channels
[n_channels
];
1676 zs_soft
[n_channels
].irq
= zs_parms
->irq0
;
1678 zs_soft
[n_channels
].irq
= zs_parms
->irq1
;
1681 * Identification of channel A. Location of channel A
1682 * inside chip depends on mapping of internal address
1683 * the chip decodes channels by.
1684 * CHANNEL_A_NR returns either 0 (in case of
1685 * DECstations) or 1 (in case of Baget).
1687 if (CHANNEL_A_NR
== channel
)
1688 zs_soft
[n_channels
].zs_chan_a
=
1689 &zs_channels
[n_channels
+1-2*CHANNEL_A_NR
];
1691 zs_soft
[n_channels
].zs_chan_a
=
1692 &zs_channels
[n_channels
];
1694 *pp
= &zs_soft
[n_channels
];
1695 pp
= &zs_soft
[n_channels
].zs_next
;
1701 zs_channels_found
= n_channels
;
1703 for (n
= 0; n
< zs_channels_found
; n
++) {
1704 for (i
= 0; i
< 16; i
++) {
1705 zs_soft
[n
].zs_channel
->curregs
[i
] = zs_init_regs
[i
];
1709 save_and_cli(flags
);
1710 for (n
= 0; n
< zs_channels_found
; n
++) {
1712 write_zsreg(zs_soft
[n
].zs_chan_a
, R9
, FHWRES
);
1714 write_zsreg(zs_soft
[n
].zs_chan_a
, R9
, 0);
1716 load_zsregs(zs_soft
[n
].zs_channel
,
1717 zs_soft
[n
].zs_channel
->curregs
);
1719 restore_flags(flags
);
1722 static struct tty_operations serial_ops
= {
1726 .flush_chars
= rs_flush_chars
,
1727 .write_room
= rs_write_room
,
1728 .chars_in_buffer
= rs_chars_in_buffer
,
1729 .flush_buffer
= rs_flush_buffer
,
1731 .throttle
= rs_throttle
,
1732 .unthrottle
= rs_unthrottle
,
1733 .set_termios
= rs_set_termios
,
1736 .hangup
= rs_hangup
,
1737 .break_ctl
= rs_break
,
1738 .wait_until_sent
= rs_wait_until_sent
,
1739 .tiocmget
= rs_tiocmget
,
1740 .tiocmset
= rs_tiocmset
,
1743 /* zs_init inits the driver */
1744 int __init
zs_init(void)
1747 struct dec_serial
*info
;
1752 /* Setup base handler, and timer table. */
1753 init_bh(SERIAL_BH
, do_serial_bh
);
1755 /* Find out how many Z8530 SCCs we have */
1758 serial_driver
= alloc_tty_driver(zs_channels_found
);
1762 show_serial_version();
1764 /* Initialize the tty_driver structure */
1765 /* Not all of this is exactly right for us. */
1767 serial_driver
->owner
= THIS_MODULE
;
1768 serial_driver
->devfs_name
= "tts/";
1769 serial_driver
->name
= "ttyS";
1770 serial_driver
->major
= TTY_MAJOR
;
1771 serial_driver
->minor_start
= 64;
1772 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1773 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1774 serial_driver
->init_termios
= tty_std_termios
;
1775 serial_driver
->init_termios
.c_cflag
=
1776 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1777 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_NO_DEVFS
;
1778 tty_set_operations(serial_driver
, &serial_ops
);
1780 if (tty_register_driver(serial_driver
))
1781 panic("Couldn't register serial driver");
1783 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++) {
1785 /* Needed before interrupts are enabled. */
1789 if (info
->hook
&& info
->hook
->init_info
) {
1790 (*info
->hook
->init_info
)(info
);
1794 info
->magic
= SERIAL_MAGIC
;
1795 info
->port
= (int) info
->zs_channel
->control
;
1797 info
->custom_divisor
= 16;
1798 info
->close_delay
= 50;
1799 info
->closing_wait
= 3000;
1802 info
->blocked_open
= 0;
1803 info
->tqueue
.routine
= do_softint
;
1804 info
->tqueue
.data
= info
;
1805 init_waitqueue_head(&info
->open_wait
);
1806 init_waitqueue_head(&info
->close_wait
);
1807 printk("ttyS%02d at 0x%08x (irq = %d) is a Z85C30 SCC\n",
1808 info
->line
, info
->port
, info
->irq
);
1809 tty_register_device(serial_driver
, info
->line
, NULL
);
1813 for (channel
= 0; channel
< zs_channels_found
; ++channel
) {
1814 zs_soft
[channel
].clk_divisor
= 16;
1815 zs_soft
[channel
].zs_baud
= get_zsbaud(&zs_soft
[channel
]);
1817 if (request_irq(zs_soft
[channel
].irq
, rs_interrupt
, SA_SHIRQ
,
1818 "scc", &zs_soft
[channel
]))
1819 printk(KERN_ERR
"decserial: can't get irq %d\n",
1820 zs_soft
[channel
].irq
);
1822 if (zs_soft
[channel
].hook
) {
1823 zs_startup(&zs_soft
[channel
]);
1824 if (zs_soft
[channel
].hook
->init_channel
)
1825 (*zs_soft
[channel
].hook
->init_channel
)
1826 (&zs_soft
[channel
]);
1834 * polling I/O routines
1837 zs_poll_tx_char(void *handle
, unsigned char ch
)
1839 struct dec_serial
*info
= handle
;
1840 struct dec_zschannel
*chan
= info
->zs_channel
;
1846 while (loops
&& !(read_zsreg(chan
, 0) & Tx_BUF_EMP
))
1850 write_zsdata(chan
, ch
);
1861 zs_poll_rx_char(void *handle
)
1863 struct dec_serial
*info
= handle
;
1864 struct dec_zschannel
*chan
= info
->zs_channel
;
1870 while (loops
&& !(read_zsreg(chan
, 0) & Rx_CH_AV
))
1874 ret
= read_zsdata(chan
);
1883 int register_zs_hook(unsigned int channel
, struct dec_serial_hook
*hook
)
1885 struct dec_serial
*info
= &zs_soft
[channel
];
1888 printk("%s: line %d has already a hook registered\n",
1889 __FUNCTION__
, channel
);
1893 hook
->poll_rx_char
= zs_poll_rx_char
;
1894 hook
->poll_tx_char
= zs_poll_tx_char
;
1901 int unregister_zs_hook(unsigned int channel
)
1903 struct dec_serial
*info
= &zs_soft
[channel
];
1909 printk("%s: trying to unregister hook on line %d,"
1910 " but none is registered\n", __FUNCTION__
, channel
);
1916 * ------------------------------------------------------------
1917 * Serial console driver
1918 * ------------------------------------------------------------
1920 #ifdef CONFIG_SERIAL_DEC_CONSOLE
1924 * Print a string to the serial port trying not to disturb
1925 * any possible real use of the port...
1927 static void serial_console_write(struct console
*co
, const char *s
,
1930 struct dec_serial
*info
;
1933 info
= zs_soft
+ co
->index
;
1935 for (i
= 0; i
< count
; i
++, s
++) {
1937 zs_poll_tx_char(info
, '\r');
1938 zs_poll_tx_char(info
, *s
);
1942 static struct tty_driver
*serial_console_device(struct console
*c
, int *index
)
1945 return serial_driver
;
1949 * Setup initial baud/bits/parity. We do two things here:
1950 * - construct a cflag setting for the first rs_open()
1951 * - initialize the serial port
1952 * Return non-zero if we didn't find a serial port.
1954 static int __init
serial_console_setup(struct console
*co
, char *options
)
1956 struct dec_serial
*info
;
1960 int cflag
= CREAD
| HUPCL
| CLOCAL
;
1961 int clk_divisor
= 16;
1964 unsigned long flags
;
1969 info
= zs_soft
+ co
->index
;
1977 baud
= simple_strtoul(options
, NULL
, 10);
1979 while(*s
>= '0' && *s
<= '9')
1988 * Now construct a cflag setting.
2016 * Set this to a sane value to prevent a divide error.
2040 save_and_cli(flags
);
2043 * Set up the baud rate generator.
2045 brg
= BPS_TO_BRG(baud
, zs_parms
->clock
/ clk_divisor
);
2046 info
->zs_channel
->curregs
[R12
] = (brg
& 255);
2047 info
->zs_channel
->curregs
[R13
] = ((brg
>> 8) & 255);
2050 * Set byte size and parity.
2053 info
->zs_channel
->curregs
[R3
] |= Rx7
;
2054 info
->zs_channel
->curregs
[R5
] |= Tx7
;
2056 info
->zs_channel
->curregs
[R3
] |= Rx8
;
2057 info
->zs_channel
->curregs
[R5
] |= Tx8
;
2059 if (cflag
& PARENB
) {
2060 info
->zs_channel
->curregs
[R4
] |= PAR_ENA
;
2062 if (!(cflag
& PARODD
)) {
2063 info
->zs_channel
->curregs
[R4
] |= PAR_EVEN
;
2065 info
->zs_channel
->curregs
[R4
] |= SB1
;
2068 * Turn on RTS and DTR.
2070 zs_rtsdtr(info
, RTS
| DTR
, 1);
2073 * Finally, enable sequencing.
2075 info
->zs_channel
->curregs
[R3
] |= RxENABLE
;
2076 info
->zs_channel
->curregs
[R5
] |= TxENAB
;
2079 * Clear the interrupt registers.
2081 write_zsreg(info
->zs_channel
, R0
, ERR_RES
);
2082 write_zsreg(info
->zs_channel
, R0
, RES_H_IUS
);
2085 * Load up the new values.
2087 load_zsregs(info
->zs_channel
, info
->zs_channel
->curregs
);
2089 /* Save the current value of RR0 */
2090 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, R0
);
2092 zs_soft
[co
->index
].clk_divisor
= clk_divisor
;
2093 zs_soft
[co
->index
].zs_baud
= get_zsbaud(&zs_soft
[co
->index
]);
2095 restore_flags(flags
);
2100 static struct console sercons
= {
2102 .write
= serial_console_write
,
2103 .device
= serial_console_device
,
2104 .setup
= serial_console_setup
,
2105 .flags
= CON_PRINTBUFFER
,
2112 void __init
zs_serial_console_init(void)
2114 register_console(&sercons
);
2116 #endif /* ifdef CONFIG_SERIAL_DEC_CONSOLE */
2119 struct dec_zschannel
*zs_kgdbchan
;
2120 static unsigned char scc_inittab
[] = {
2121 9, 0x80, /* reset A side (CHRA) */
2122 13, 0, /* set baud rate divisor */
2124 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
2125 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
2126 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
2127 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
2128 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
2131 /* These are for receiving and sending characters under the kgdb
2132 * source level kernel debugger.
2134 void putDebugChar(char kgdb_char
)
2136 struct dec_zschannel
*chan
= zs_kgdbchan
;
2137 while ((read_zsreg(chan
, 0) & Tx_BUF_EMP
) == 0)
2139 write_zsdata(chan
, kgdb_char
);
2141 char getDebugChar(void)
2143 struct dec_zschannel
*chan
= zs_kgdbchan
;
2144 while((read_zsreg(chan
, 0) & Rx_CH_AV
) == 0)
2145 eieio(); /*barrier();*/
2146 return read_zsdata(chan
);
2148 void kgdb_interruptible(int yes
)
2150 struct dec_zschannel
*chan
= zs_kgdbchan
;
2152 nine
= read_zsreg(chan
, 9);
2154 one
= EXT_INT_ENAB
|RxINT_ALL
;
2156 printk("turning serial ints on\n");
2160 printk("turning serial ints off\n");
2162 write_zsreg(chan
, 1, one
);
2163 write_zsreg(chan
, 9, nine
);
2166 static int kgdbhook_init_channel(void *handle
)
2171 static void kgdbhook_init_info(void *handle
)
2175 static void kgdbhook_rx_char(void *handle
, unsigned char ch
, unsigned char fl
)
2177 struct dec_serial
*info
= handle
;
2179 if (fl
!= TTY_NORMAL
)
2181 if (ch
== 0x03 || ch
== '$')
2185 /* This sets up the serial port we're using, and turns on
2186 * interrupts for that channel, so kgdb is usable once we're done.
2188 static inline void kgdb_chaninit(struct dec_zschannel
*ms
, int intson
, int bps
)
2192 volatile char *sccc
= ms
->control
;
2193 brg
= BPS_TO_BRG(bps
, zs_parms
->clock
/16);
2194 printk("setting bps on kgdb line to %d [brg=%x]\n", bps
, brg
);
2195 for (i
= 20000; i
!= 0; --i
) {
2198 for (i
= 0; i
< sizeof(scc_inittab
); ++i
) {
2199 write_zsreg(ms
, scc_inittab
[i
], scc_inittab
[i
+1]);
2203 /* This is called at boot time to prime the kgdb serial debugging
2204 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2205 * for /dev/ttyb which is determined in setup_arch() from the
2206 * boot command line flags.
2208 struct dec_serial_hook zs_kgdbhook
= {
2209 .init_channel
= kgdbhook_init_channel
,
2210 .init_info
= kgdbhook_init_info
,
2211 .rx_char
= kgdbhook_rx_char
,
2212 .cflags
= B38400
| CS8
| CLOCAL
,
2215 void __init
zs_kgdb_hook(int tty_num
)
2217 /* Find out how many Z8530 SCCs we have */
2220 zs_soft
[tty_num
].zs_channel
= &zs_channels
[tty_num
];
2221 zs_kgdbchan
= zs_soft
[tty_num
].zs_channel
;
2222 zs_soft
[tty_num
].change_needed
= 0;
2223 zs_soft
[tty_num
].clk_divisor
= 16;
2224 zs_soft
[tty_num
].zs_baud
= 38400;
2225 zs_soft
[tty_num
].hook
= &zs_kgdbhook
; /* This runs kgdb */
2226 /* Turn on transmitter/receiver at 8-bits/char */
2227 kgdb_chaninit(zs_soft
[tty_num
].zs_channel
, 1, 38400);
2228 printk("KGDB: on channel %d initialized\n", tty_num
);
2229 set_debug_traps(); /* init stub */
2231 #endif /* ifdef CONFIG_KGDB */