2 * macserial.c: Serial port driver for Power Macintoshes.
4 * Derived from drivers/sbus/char/sunserial.c by Paul Mackerras.
6 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
10 #include <linux/config.h>
11 #include <linux/errno.h>
12 #include <linux/module.h>
13 #include <linux/signal.h>
14 #include <linux/sched.h>
15 #include <linux/timer.h>
16 #include <linux/interrupt.h>
17 #include <linux/tty.h>
18 #include <linux/tty_flip.h>
19 #include <linux/major.h>
20 #include <linux/string.h>
21 #include <linux/fcntl.h>
23 #include <linux/kernel.h>
24 #include <linux/delay.h>
25 #include <linux/init.h>
26 #ifdef CONFIG_SERIAL_CONSOLE
27 #include <linux/console.h>
32 #include <asm/pgtable.h>
35 #include <asm/system.h>
36 #include <asm/segment.h>
37 #include <asm/bitops.h>
38 #include <asm/feature.h>
45 #include "macserial.h"
48 * It would be nice to dynamically allocate everything that
49 * depends on NUM_SERIAL, so we could support any number of
50 * Z8530s, but for now...
52 #define NUM_SERIAL 2 /* Max number of ZS chips supported */
53 #define NUM_CHANNELS (NUM_SERIAL * 2) /* 2 channels per chip */
55 /* On PowerMacs, the hardware takes care of the SCC recovery time,
56 but we need the eieio to make sure that the accesses occur
57 in the order we want. */
58 #define RECOVERY_DELAY eieio()
60 struct mac_zschannel zs_channels
[NUM_CHANNELS
];
62 struct mac_serial zs_soft
[NUM_CHANNELS
];
63 int zs_channels_found
;
64 struct mac_serial
*zs_chain
; /* list of all channels */
66 struct tty_struct zs_ttys
[NUM_CHANNELS
];
68 static int is_powerbook
;
70 #ifdef CONFIG_SERIAL_CONSOLE
71 static struct console sercons
;
75 struct mac_zschannel
*zs_kgdbchan
;
76 static unsigned char scc_inittab
[] = {
77 9, 0x80, /* reset A side (CHRA) */
78 13, 0, /* set baud rate divisor */
80 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
81 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
82 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
83 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
84 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
87 #define ZS_CLOCK 3686400 /* Z8530 RTxC input clock rate */
89 static DECLARE_TASK_QUEUE(tq_serial
);
91 static struct tty_driver serial_driver
, callout_driver
;
92 static int serial_refcount
;
94 /* serial subtype definitions */
95 #define SERIAL_TYPE_NORMAL 1
96 #define SERIAL_TYPE_CALLOUT 2
98 /* number of characters left in xmit buffer before we ask for more */
99 #define WAKEUP_CHARS 256
104 #undef SERIAL_DEBUG_INTR
105 #undef SERIAL_DEBUG_OPEN
106 #undef SERIAL_DEBUG_FLOW
107 #undef SERIAL_DEBUG_POWER
108 #undef SERIAL_DEBUG_THROTTLE
109 #undef SERIAL_DEBUG_STOP
110 #undef SERIAL_DEBUG_BAUDS
112 #define RS_STROBE_TIME 10
113 #define RS_ISR_PASS_LIMIT 256
115 #define _INLINE_ inline
117 static void probe_sccs(void);
118 static void change_speed(struct mac_serial
*info
, struct termios
*old
);
119 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
120 static int set_scc_power(struct mac_serial
* info
, int state
);
121 static int setup_scc(struct mac_serial
* info
);
123 static struct tty_struct
*serial_table
[NUM_CHANNELS
];
124 static struct termios
*serial_termios
[NUM_CHANNELS
];
125 static struct termios
*serial_termios_locked
[NUM_CHANNELS
];
128 #define MIN(a,b) ((a) < (b) ? (a) : (b))
132 * tmp_buf is used as a temporary buffer by serial_write. We need to
133 * lock it in case the copy_from_user blocks while swapping in a page,
134 * and some other program tries to do a serial write at the same time.
135 * Since the lock will only come under contention when the system is
136 * swapping and available memory is low, it makes sense to share one
137 * buffer across all the serial ports, since it significantly saves
138 * memory if large numbers of serial ports are open.
140 static unsigned char *tmp_buf
;
141 static DECLARE_MUTEX(tmp_buf_sem
);
144 static inline int __pmac
145 serial_paranoia_check(struct mac_serial
*info
,
146 dev_t device
, const char *routine
)
148 #ifdef SERIAL_PARANOIA_CHECK
149 static const char *badmagic
=
150 "Warning: bad magic number for serial struct (%d, %d) in %s\n";
151 static const char *badinfo
=
152 "Warning: null mac_serial for (%d, %d) in %s\n";
155 printk(badinfo
, MAJOR(device
), MINOR(device
), routine
);
158 if (info
->magic
!= SERIAL_MAGIC
) {
159 printk(badmagic
, MAJOR(device
), MINOR(device
), routine
);
167 * Reading and writing Z8530 registers.
169 static inline unsigned char __pmac
read_zsreg(struct mac_zschannel
*channel
,
172 unsigned char retval
;
176 * We have to make this atomic.
178 spin_lock_irqsave(&channel
->lock
, flags
);
180 *channel
->control
= reg
;
183 retval
= *channel
->control
;
185 spin_unlock_irqrestore(&channel
->lock
, flags
);
189 static inline void __pmac
write_zsreg(struct mac_zschannel
*channel
,
190 unsigned char reg
, unsigned char value
)
194 spin_lock_irqsave(&channel
->lock
, flags
);
196 *channel
->control
= reg
;
199 *channel
->control
= value
;
201 spin_unlock_irqrestore(&channel
->lock
, flags
);
205 static inline unsigned char __pmac
read_zsdata(struct mac_zschannel
*channel
)
207 unsigned char retval
;
209 retval
= *channel
->data
;
214 static inline void write_zsdata(struct mac_zschannel
*channel
,
217 *channel
->data
= value
;
222 static inline void load_zsregs(struct mac_zschannel
*channel
,
225 ZS_CLEARERR(channel
);
226 ZS_CLEARFIFO(channel
);
228 write_zsreg(channel
, R4
, regs
[R4
]);
229 write_zsreg(channel
, R10
, regs
[R10
]);
230 write_zsreg(channel
, R3
, regs
[R3
] & ~RxENABLE
);
231 write_zsreg(channel
, R5
, regs
[R5
] & ~TxENAB
);
232 write_zsreg(channel
, R1
, regs
[R1
]);
233 write_zsreg(channel
, R9
, regs
[R9
]);
234 write_zsreg(channel
, R11
, regs
[R11
]);
235 write_zsreg(channel
, R12
, regs
[R12
]);
236 write_zsreg(channel
, R13
, regs
[R13
]);
237 write_zsreg(channel
, R14
, regs
[R14
]);
238 write_zsreg(channel
, R15
, regs
[R15
]);
239 write_zsreg(channel
, R3
, regs
[R3
]);
240 write_zsreg(channel
, R5
, regs
[R5
]);
244 /* Sets or clears DTR/RTS on the requested line */
245 static inline void zs_rtsdtr(struct mac_serial
*ss
, int set
)
248 ss
->curregs
[5] |= (RTS
| DTR
);
250 ss
->curregs
[5] &= ~(RTS
| DTR
);
251 write_zsreg(ss
->zs_channel
, 5, ss
->curregs
[5]);
255 /* Utility routines for the Zilog */
256 static inline int get_zsbaud(struct mac_serial
*ss
)
258 struct mac_zschannel
*channel
= ss
->zs_channel
;
261 if ((ss
->curregs
[R11
] & TCBR
) == 0) {
262 /* higher rates don't use the baud rate generator */
263 return (ss
->curregs
[R4
] & X32CLK
)? ZS_CLOCK
/32: ZS_CLOCK
/16;
265 /* The baud rate is split up between two 8-bit registers in
266 * what is termed 'BRG time constant' format in my docs for
267 * the chip, it is a function of the clk rate the chip is
268 * receiving which happens to be constant.
270 brg
= (read_zsreg(channel
, 13) << 8);
271 brg
|= read_zsreg(channel
, 12);
272 return BRG_TO_BPS(brg
, (ZS_CLOCK
/(ss
->clk_divisor
)));
275 /* On receive, this clears errors and the receiver interrupts */
276 static inline void rs_recv_clear(struct mac_zschannel
*zsc
)
278 write_zsreg(zsc
, 0, ERR_RES
);
279 write_zsreg(zsc
, 0, RES_H_IUS
); /* XXX this is unnecessary */
283 * ----------------------------------------------------------------------
285 * Here starts the interrupt handling routines. All of the following
286 * subroutines are declared as inline and are folded into
287 * rs_interrupt(). They were separated out for readability's sake.
289 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
290 * -----------------------------------------------------------------------
294 * This routine is used by the interrupt handler to schedule
295 * processing in the software interrupt portion of the driver.
297 static _INLINE_
void rs_sched_event(struct mac_serial
*info
,
300 info
->event
|= 1 << event
;
301 queue_task(&info
->tqueue
, &tq_serial
);
302 mark_bh(MACSERIAL_BH
);
305 static _INLINE_
void receive_chars(struct mac_serial
*info
,
306 struct pt_regs
*regs
)
308 struct tty_struct
*tty
= info
->tty
;
309 unsigned char ch
, stat
, flag
;
311 while ((read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
) != 0) {
313 stat
= read_zsreg(info
->zs_channel
, R1
);
314 ch
= read_zsdata(info
->zs_channel
);
317 if (info
->kgdb_channel
) {
318 if (ch
== 0x03 || ch
== '$')
320 if (stat
& (Rx_OVR
|FRM_ERR
|PAR_ERR
))
321 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
327 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
328 tty_flip_buffer_push(tty
);
330 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
331 static int flip_buf_ovf
;
332 if (++flip_buf_ovf
<= 1)
333 printk("FB. overflow: %d\n", flip_buf_ovf
);
338 static int flip_max_cnt
;
339 if (flip_max_cnt
< tty
->flip
.count
)
340 flip_max_cnt
= tty
->flip
.count
;
344 } else if (stat
& FRM_ERR
) {
346 } else if (stat
& PAR_ERR
) {
351 /* reset the error indication */
352 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
353 *tty
->flip
.flag_buf_ptr
++ = flag
;
354 *tty
->flip
.char_buf_ptr
++ = ch
;
357 tty_flip_buffer_push(tty
);
360 static void transmit_chars(struct mac_serial
*info
)
366 if ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
) == 0)
372 write_zsdata(info
->zs_channel
, info
->x_char
);
378 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
|| info
->tx_stopped
) {
379 write_zsreg(info
->zs_channel
, 0, RES_Tx_P
);
384 write_zsdata(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
385 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
389 if (info
->xmit_cnt
< WAKEUP_CHARS
)
390 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
393 restore_flags(flags
);
396 static _INLINE_
void status_handle(struct mac_serial
*info
)
398 unsigned char status
;
400 /* Get status from Read Register 0 */
401 status
= read_zsreg(info
->zs_channel
, 0);
403 /* Check for DCD transitions */
404 if (((status
^ info
->read_reg_zero
) & DCD
) != 0
405 && info
->tty
&& !C_CLOCAL(info
->tty
)) {
407 wake_up_interruptible(&info
->open_wait
);
408 } else if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
)) {
410 tty_hangup(info
->tty
);
414 /* Check for CTS transitions */
415 if (info
->tty
&& C_CRTSCTS(info
->tty
)) {
417 * For some reason, on the Power Macintosh,
418 * it seems that the CTS bit is 1 when CTS is
419 * *negated* and 0 when it is asserted.
420 * The DCD bit doesn't seem to be inverted
423 if ((status
& CTS
) == 0) {
424 if (info
->tx_stopped
) {
425 #ifdef SERIAL_DEBUG_FLOW
428 info
->tx_stopped
= 0;
429 if (!info
->tx_active
)
430 transmit_chars(info
);
433 #ifdef SERIAL_DEBUG_FLOW
434 printk("CTS down\n");
436 info
->tx_stopped
= 1;
440 /* Clear status condition... */
441 write_zsreg(info
->zs_channel
, 0, RES_EXT_INT
);
442 info
->read_reg_zero
= status
;
446 * This is the serial driver's generic interrupt routine
448 static void rs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
450 struct mac_serial
*info
= (struct mac_serial
*) dev_id
;
451 unsigned char zs_intreg
;
454 /* NOTE: The read register 3, which holds the irq status,
455 * does so for both channels on each chip. Although
456 * the status value itself must be read from the A
457 * channel and is only valid when read from channel A.
458 * Yes... broken hardware...
460 #define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
462 if (info
->zs_chan_a
== info
->zs_channel
)
463 shift
= 3; /* Channel A */
465 shift
= 0; /* Channel B */
468 zs_intreg
= read_zsreg(info
->zs_chan_a
, 3) >> shift
;
469 #ifdef SERIAL_DEBUG_INTR
470 printk("rs_interrupt: irq %d, zs_intreg 0x%x\n", irq
, (int)zs_intreg
);
473 if ((zs_intreg
& CHAN_IRQMASK
) == 0)
476 if (!(info
->flags
& ZILOG_INITIALIZED
)) {
477 printk("rs_interrupt: irq %d, port not initialized\n", irq
);
481 if (zs_intreg
& CHBRxIP
)
482 receive_chars(info
, regs
);
483 if (zs_intreg
& CHBTxIP
)
484 transmit_chars(info
);
485 if (zs_intreg
& CHBEXT
)
491 * -------------------------------------------------------------------
492 * Here ends the serial interrupt routines.
493 * -------------------------------------------------------------------
497 * ------------------------------------------------------------
498 * rs_stop() and rs_start()
500 * This routines are called before setting or resetting tty->stopped.
501 * ------------------------------------------------------------
503 static void rs_stop(struct tty_struct
*tty
)
505 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
507 #ifdef SERIAL_DEBUG_STOP
508 printk("rs_stop %ld....\n",
509 tty
->ldisc
.chars_in_buffer(tty
));
512 if (serial_paranoia_check(info
, tty
->device
, "rs_stop"))
516 save_flags(flags
); cli();
517 if (info
->curregs
[5] & TxENAB
) {
518 info
->curregs
[5] &= ~TxENAB
;
519 info
->pendregs
[5] &= ~TxENAB
;
520 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
522 restore_flags(flags
);
526 static void rs_start(struct tty_struct
*tty
)
528 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
531 #ifdef SERIAL_DEBUG_STOP
532 printk("rs_start %ld....\n",
533 tty
->ldisc
.chars_in_buffer(tty
));
536 if (serial_paranoia_check(info
, tty
->device
, "rs_start"))
539 save_flags(flags
); cli();
541 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->curregs
[5] & TxENAB
)) {
542 info
->curregs
[5] |= TxENAB
;
543 info
->pendregs
[5] = info
->curregs
[5];
544 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
547 if (info
->xmit_cnt
&& info
->xmit_buf
&& !info
->tx_active
) {
548 transmit_chars(info
);
551 restore_flags(flags
);
555 * This routine is used to handle the "bottom half" processing for the
556 * serial driver, known also the "software interrupt" processing.
557 * This processing is done at the kernel interrupt level, after the
558 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
559 * is where time-consuming activities which can not be done in the
560 * interrupt driver proper are done; the interrupt driver schedules
561 * them using rs_sched_event(), and they get done here.
563 static void do_serial_bh(void)
565 run_task_queue(&tq_serial
);
568 static void do_softint(void *private_
)
570 struct mac_serial
*info
= (struct mac_serial
*) private_
;
571 struct tty_struct
*tty
;
577 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
578 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
579 tty
->ldisc
.write_wakeup
)
580 (tty
->ldisc
.write_wakeup
)(tty
);
581 wake_up_interruptible(&tty
->write_wait
);
585 static void rs_timer(void)
589 static int startup(struct mac_serial
* info
, int can_sleep
)
593 #ifdef SERIAL_DEBUG_OPEN
594 printk("startup() (ttyS%d, irq %d)\n", info
->line
, info
->irq
);
597 if (info
->flags
& ZILOG_INITIALIZED
) {
598 #ifdef SERIAL_DEBUG_OPEN
599 printk(" -> already inited\n");
604 if (!info
->xmit_buf
) {
605 info
->xmit_buf
= (unsigned char *) get_free_page(GFP_KERNEL
);
610 #ifdef SERIAL_DEBUG_OPEN
611 printk("starting up ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
614 delay
= set_scc_power(info
, 1);
618 #ifdef SERIAL_DEBUG_OPEN
619 printk("enabling IRQ on ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
622 info
->flags
|= ZILOG_INITIALIZED
;
623 enable_irq(info
->irq
);
627 /* we need to wait a bit before using the port */
628 current
->state
= TASK_INTERRUPTIBLE
;
629 schedule_timeout(delay
* HZ
/ 1000);
637 static int setup_scc(struct mac_serial
* info
)
641 #ifdef SERIAL_DEBUG_OPEN
642 printk("setting up ttys%d SCC...\n", info
->line
);
645 save_flags(flags
); cli(); /* Disable interrupts */
650 write_zsreg(info
->zs_channel
, 9,
651 (info
->zs_channel
== info
->zs_chan_a
? CHRA
: CHRB
));
653 write_zsreg(info
->zs_channel
, 9, 0);
656 * Clear the receive FIFO.
658 ZS_CLEARFIFO(info
->zs_channel
);
659 info
->xmit_fifo_size
= 1;
662 * Clear the interrupt registers.
664 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
665 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
668 * Turn on RTS and DTR.
673 * Finally, enable sequencing and interrupts
675 info
->curregs
[1] = (info
->curregs
[1] & ~0x18) | (EXT_INT_ENAB
| INT_ALL_Rx
| TxINT_ENAB
);
676 info
->pendregs
[1] = info
->curregs
[1];
677 info
->curregs
[3] |= (RxENABLE
| Rx8
);
678 info
->pendregs
[3] = info
->curregs
[3];
679 info
->curregs
[5] |= (TxENAB
| Tx8
);
680 info
->pendregs
[5] = info
->curregs
[5];
681 info
->curregs
[9] |= (NV
| MIE
);
682 info
->pendregs
[9] = info
->curregs
[9];
683 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
684 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
685 write_zsreg(info
->zs_channel
, 9, info
->curregs
[9]);
688 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
689 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
692 * Set the speed of the serial port
694 change_speed(info
, 0);
696 /* Save the current value of RR0 */
697 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
699 restore_flags(flags
);
705 * This routine will shutdown a serial port; interrupts are disabled, and
706 * DTR is dropped if the hangup on close termio flag is on.
708 static void shutdown(struct mac_serial
* info
)
710 #ifdef SERIAL_DEBUG_OPEN
711 printk("Shutting down serial port %d (irq %d)....\n", info
->line
,
715 if (!(info
->flags
& ZILOG_INITIALIZED
)) {
716 #ifdef SERIAL_DEBUG_OPEN
717 printk("(already shutdown)\n");
723 disable_irq(info
->irq
);
725 info
->pendregs
[1] = info
->curregs
[1] = 0;
726 write_zsreg(info
->zs_channel
, 1, 0); /* no interrupts */
728 info
->curregs
[3] &= ~RxENABLE
;
729 info
->pendregs
[3] = info
->curregs
[3];
730 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
732 info
->curregs
[5] &= ~TxENAB
;
733 if (!info
->tty
|| C_HUPCL(info
->tty
))
734 info
->curregs
[5] &= ~(DTR
| RTS
);
735 info
->pendregs
[5] = info
->curregs
[5];
736 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
739 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
741 set_scc_power(info
, 0);
743 if (info
->xmit_buf
) {
744 free_page((unsigned long) info
->xmit_buf
);
748 memset(info
->curregs
, 0, sizeof(info
->curregs
));
749 memset(info
->curregs
, 0, sizeof(info
->pendregs
));
751 info
->flags
&= ~ZILOG_INITIALIZED
;
755 * Turn power on or off to the SCC and associated stuff
756 * (port drivers, modem, IR port, etc.)
757 * Returns the number of milliseconds we should wait before
758 * trying to use the port.
760 static int set_scc_power(struct mac_serial
* info
, int state
)
764 if (feature_test(info
->dev_node
, FEATURE_Serial_enable
) < 0)
765 return 0; /* don't have serial power control */
767 /* The timings looks strange but that's the ones MacOS seems
768 to use for the internal modem. I think we can use a lot faster
769 ones, at least whe not using the modem, this should be tested.
772 #ifdef SERIAL_DEBUG_POWER
773 printk(KERN_INFO
"ttyS%02d: powering up hardware\n", info
->line
);
775 if (feature_test(info
->dev_node
, FEATURE_Serial_enable
) == 0) {
776 feature_clear(info
->dev_node
, FEATURE_Serial_reset
);
778 feature_set(info
->dev_node
, FEATURE_Serial_enable
);
780 if (info
->zs_chan_a
== info
->zs_channel
)
781 feature_set(info
->dev_node
, FEATURE_Serial_IO_A
);
783 feature_set(info
->dev_node
, FEATURE_Serial_IO_B
);
786 if (info
->is_cobalt_modem
){
787 feature_set(info
->dev_node
, FEATURE_Modem_Reset
);
789 feature_clear(info
->dev_node
, FEATURE_Modem_Reset
);
790 delay
= 1000; /* wait for 1s before using */
792 #ifdef CONFIG_PMAC_PBOOK
793 if (info
->is_pwbk_ir
)
795 #endif /* CONFIG_PMAC_PBOOK */
797 #ifdef SERIAL_DEBUG_POWER
798 printk(KERN_INFO
"ttyS%02d: shutting down hardware\n", info
->line
);
801 if (info
->kgdb_channel
) {
802 #ifdef SERIAL_DEBUG_POWER
803 printk(KERN_INFO
" (canceled by KGDB)\n");
809 if (!info
->is_cobalt_modem
) {
810 #ifdef SERIAL_DEBUG_POWER
811 printk(KERN_INFO
" (canceled by XMON)\n");
816 if (info
->is_cobalt_modem
) {
817 #ifdef SERIAL_DEBUG_POWER
818 printk(KERN_INFO
"ttyS%02d: shutting down modem\n", info
->line
);
820 feature_set(info
->dev_node
, FEATURE_Modem_Reset
);
822 feature_clear(info
->dev_node
, FEATURE_Modem_Reset
);
825 #ifdef CONFIG_PMAC_PBOOK
826 if (info
->is_pwbk_ir
)
828 #endif /* CONFIG_PMAC_PBOOK */
830 if (info
->zs_chan_a
== info
->zs_channel
) {
831 #ifdef SERIAL_DEBUG_POWER
832 printk(KERN_INFO
"ttyS%02d: shutting down SCC channel A\n", info
->line
);
834 feature_clear(info
->dev_node
, FEATURE_Serial_IO_A
);
836 #ifdef SERIAL_DEBUG_POWER
837 printk(KERN_INFO
"ttyS%02d: shutting down SCC channel B\n", info
->line
);
839 feature_clear(info
->dev_node
, FEATURE_Serial_IO_B
);
841 /* XXX for now, shut down SCC core only on powerbooks */
843 && !(feature_test(info
->dev_node
, FEATURE_Serial_IO_A
) ||
844 feature_test(info
->dev_node
, FEATURE_Serial_IO_B
))) {
845 #ifdef SERIAL_DEBUG_POWER
846 printk(KERN_INFO
"ttyS%02d: shutting down SCC core\n", info
->line
);
848 feature_set(info
->dev_node
, FEATURE_Serial_reset
);
850 feature_clear(info
->dev_node
, FEATURE_Serial_enable
);
859 * This routine is called to set the UART divisor registers to match
860 * the specified baud rate for a serial port.
862 static void change_speed(struct mac_serial
*info
, struct termios
*old_termios
)
870 if (!info
->tty
|| !info
->tty
->termios
)
872 if (!(port
= info
->port
))
875 cflag
= info
->tty
->termios
->c_cflag
;
876 baud
= tty_get_baud_rate(info
->tty
);
879 info
->tty
->termios
->c_cflag
&= ~CBAUD
;
880 info
->tty
->termios
->c_cflag
|= (old_termios
->c_cflag
& CBAUD
);
881 cflag
= info
->tty
->termios
->c_cflag
;
882 baud
= tty_get_baud_rate(info
->tty
);
885 baud
= info
->zs_baud
;
892 save_flags(flags
); cli();
893 info
->zs_baud
= baud
;
894 info
->clk_divisor
= 16;
896 #ifdef SERIAL_DEBUG_BAUDS
897 printk("set speed to %d bds, ", baud
);
901 case ZS_CLOCK
/16: /* 230400 */
902 info
->curregs
[4] = X16CLK
;
903 info
->curregs
[11] = 0;
905 case ZS_CLOCK
/32: /* 115200 */
906 info
->curregs
[4] = X32CLK
;
907 info
->curregs
[11] = 0;
910 info
->curregs
[4] = X16CLK
;
911 info
->curregs
[11] = TCBR
| RCBR
;
912 brg
= BPS_TO_BRG(baud
, ZS_CLOCK
/info
->clk_divisor
);
913 info
->curregs
[12] = (brg
& 255);
914 info
->curregs
[13] = ((brg
>> 8) & 255);
915 info
->curregs
[14] = BRENABL
;
918 /* byte size and parity */
919 info
->curregs
[3] &= ~RxNBITS_MASK
;
920 info
->curregs
[5] &= ~TxNBITS_MASK
;
921 switch (cflag
& CSIZE
) {
923 info
->curregs
[3] |= Rx5
;
924 info
->curregs
[5] |= Tx5
;
925 #ifdef SERIAL_DEBUG_BAUDS
931 info
->curregs
[3] |= Rx6
;
932 info
->curregs
[5] |= Tx6
;
933 #ifdef SERIAL_DEBUG_BAUDS
939 info
->curregs
[3] |= Rx7
;
940 info
->curregs
[5] |= Tx7
;
941 #ifdef SERIAL_DEBUG_BAUDS
947 default: /* defaults to 8 bits */
948 info
->curregs
[3] |= Rx8
;
949 info
->curregs
[5] |= Tx8
;
950 #ifdef SERIAL_DEBUG_BAUDS
956 info
->pendregs
[3] = info
->curregs
[3];
957 info
->pendregs
[5] = info
->curregs
[5];
959 info
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
960 if (cflag
& CSTOPB
) {
961 info
->curregs
[4] |= SB2
;
963 #ifdef SERIAL_DEBUG_BAUDS
967 info
->curregs
[4] |= SB1
;
968 #ifdef SERIAL_DEBUG_BAUDS
972 if (cflag
& PARENB
) {
974 info
->curregs
[4] |= PAR_ENA
;
975 #ifdef SERIAL_DEBUG_BAUDS
979 if (!(cflag
& PARODD
)) {
980 info
->curregs
[4] |= PAR_EVEN
;
982 info
->pendregs
[4] = info
->curregs
[4];
984 if (!(cflag
& CLOCAL
)) {
985 if (!(info
->curregs
[15] & DCDIE
))
986 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
987 info
->curregs
[15] |= DCDIE
;
989 info
->curregs
[15] &= ~DCDIE
;
990 if (cflag
& CRTSCTS
) {
991 info
->curregs
[15] |= CTSIE
;
992 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) != 0)
993 info
->tx_stopped
= 1;
995 info
->curregs
[15] &= ~CTSIE
;
996 info
->tx_stopped
= 0;
998 info
->pendregs
[15] = info
->curregs
[15];
1000 /* Calc timeout value. This is pretty broken with high baud rates with HZ=100.
1001 This code would love a larger HZ and a >1 fifo size, but this is not
1002 a priority. The resulting value must be >HZ/2
1004 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
) / baud
);
1005 info
->timeout
+= HZ
/50+1; /* Add .02 seconds of slop */
1007 #ifdef SERIAL_DEBUG_BAUDS
1008 printk("timeout=%d/%ds, base:%d\n", (int)info
->timeout
, (int)HZ
, (int)info
->baud_base
);
1011 /* Load up the new values */
1012 load_zsregs(info
->zs_channel
, info
->curregs
);
1014 restore_flags(flags
);
1017 static void rs_flush_chars(struct tty_struct
*tty
)
1019 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1021 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_chars"))
1024 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| info
->tx_stopped
||
1028 /* Enable transmitter */
1029 transmit_chars(info
);
1032 static int rs_write(struct tty_struct
* tty
, int from_user
,
1033 const unsigned char *buf
, int count
)
1036 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1037 unsigned long flags
;
1039 if (serial_paranoia_check(info
, tty
->device
, "rs_write"))
1042 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
)
1050 MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1051 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1055 c
-= copy_from_user(tmp_buf
, buf
, c
);
1062 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1063 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1064 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1065 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1066 (SERIAL_XMIT_SIZE
-1));
1067 info
->xmit_cnt
+= c
;
1068 restore_flags(flags
);
1078 MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1079 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1081 restore_flags(flags
);
1084 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1085 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1086 (SERIAL_XMIT_SIZE
-1));
1087 info
->xmit_cnt
+= c
;
1088 restore_flags(flags
);
1094 if (info
->xmit_cnt
&& !tty
->stopped
&& !info
->tx_stopped
1095 && !info
->tx_active
)
1096 transmit_chars(info
);
1097 restore_flags(flags
);
1101 static int rs_write_room(struct tty_struct
*tty
)
1103 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1106 if (serial_paranoia_check(info
, tty
->device
, "rs_write_room"))
1108 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1114 static int rs_chars_in_buffer(struct tty_struct
*tty
)
1116 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1118 if (serial_paranoia_check(info
, tty
->device
, "rs_chars_in_buffer"))
1120 return info
->xmit_cnt
;
1123 static void rs_flush_buffer(struct tty_struct
*tty
)
1125 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1127 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_buffer"))
1130 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1132 wake_up_interruptible(&tty
->write_wait
);
1133 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1134 tty
->ldisc
.write_wakeup
)
1135 (tty
->ldisc
.write_wakeup
)(tty
);
1139 * ------------------------------------------------------------
1142 * This routine is called by the upper-layer tty layer to signal that
1143 * incoming characters should be throttled.
1144 * ------------------------------------------------------------
1146 static void rs_throttle(struct tty_struct
* tty
)
1148 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1149 unsigned long flags
;
1150 #ifdef SERIAL_DEBUG_THROTTLE
1153 printk("throttle %ld....\n",tty
->ldisc
.chars_in_buffer(tty
));
1156 if (serial_paranoia_check(info
, tty
->device
, "rs_throttle"))
1160 save_flags(flags
); cli();
1161 info
->x_char
= STOP_CHAR(tty
);
1162 if (!info
->tx_active
)
1163 transmit_chars(info
);
1164 restore_flags(flags
);
1167 if (C_CRTSCTS(tty
)) {
1169 * Here we want to turn off the RTS line. On Macintoshes,
1170 * we only get the DTR line, which goes to both DTR and
1171 * RTS on the modem. RTS doesn't go out to the serial
1172 * port socket. So you should make sure your modem is
1173 * set to ignore DTR if you're using CRTSCTS.
1175 save_flags(flags
); cli();
1176 info
->curregs
[5] &= ~(DTR
| RTS
);
1177 info
->pendregs
[5] &= ~(DTR
| RTS
);
1178 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1179 restore_flags(flags
);
1183 static void rs_unthrottle(struct tty_struct
* tty
)
1185 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1186 unsigned long flags
;
1187 #ifdef SERIAL_DEBUG_THROTTLE
1190 printk("unthrottle %s: %d....\n",tty
->ldisc
.chars_in_buffer(tty
));
1193 if (serial_paranoia_check(info
, tty
->device
, "rs_unthrottle"))
1197 save_flags(flags
); cli();
1201 info
->x_char
= START_CHAR(tty
);
1202 if (!info
->tx_active
)
1203 transmit_chars(info
);
1205 restore_flags(flags
);
1208 if (C_CRTSCTS(tty
)) {
1209 /* Assert RTS and DTR lines */
1210 save_flags(flags
); cli();
1211 info
->curregs
[5] |= DTR
| RTS
;
1212 info
->pendregs
[5] |= DTR
| RTS
;
1213 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1214 restore_flags(flags
);
1219 * ------------------------------------------------------------
1220 * rs_ioctl() and friends
1221 * ------------------------------------------------------------
1224 static int get_serial_info(struct mac_serial
* info
,
1225 struct serial_struct
* retinfo
)
1227 struct serial_struct tmp
;
1231 memset(&tmp
, 0, sizeof(tmp
));
1232 tmp
.type
= info
->type
;
1233 tmp
.line
= info
->line
;
1234 tmp
.port
= info
->port
;
1235 tmp
.irq
= info
->irq
;
1236 tmp
.flags
= info
->flags
;
1237 tmp
.baud_base
= info
->baud_base
;
1238 tmp
.close_delay
= info
->close_delay
;
1239 tmp
.closing_wait
= info
->closing_wait
;
1240 tmp
.custom_divisor
= info
->custom_divisor
;
1241 if (copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)))
1246 static int set_serial_info(struct mac_serial
* info
,
1247 struct serial_struct
* new_info
)
1249 struct serial_struct new_serial
;
1250 struct mac_serial old_info
;
1253 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
1257 if (!capable(CAP_SYS_ADMIN
)) {
1258 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1259 (new_serial
.type
!= info
->type
) ||
1260 (new_serial
.close_delay
!= info
->close_delay
) ||
1261 ((new_serial
.flags
& ~ZILOG_USR_MASK
) !=
1262 (info
->flags
& ~ZILOG_USR_MASK
)))
1264 info
->flags
= ((info
->flags
& ~ZILOG_USR_MASK
) |
1265 (new_serial
.flags
& ZILOG_USR_MASK
));
1266 info
->custom_divisor
= new_serial
.custom_divisor
;
1267 goto check_and_exit
;
1270 if (info
->count
> 1)
1274 * OK, past this point, all the error checking has been done.
1275 * At this point, we start making changes.....
1278 info
->baud_base
= new_serial
.baud_base
;
1279 info
->flags
= ((info
->flags
& ~ZILOG_FLAGS
) |
1280 (new_serial
.flags
& ZILOG_FLAGS
));
1281 info
->type
= new_serial
.type
;
1282 info
->close_delay
= new_serial
.close_delay
;
1283 info
->closing_wait
= new_serial
.closing_wait
;
1286 if (info
->flags
& ZILOG_INITIALIZED
)
1287 retval
= setup_scc(info
);
1292 * get_lsr_info - get line status register info
1294 * Purpose: Let user call ioctl() to get info when the UART physically
1295 * is emptied. On bus types like RS485, the transmitter must
1296 * release the bus after transmitting. This must be done when
1297 * the transmit shift register is empty, not be done when the
1298 * transmit holding register is empty. This functionality
1299 * allows an RS485 driver to be written in user space.
1301 static int get_lsr_info(struct mac_serial
* info
, unsigned int *value
)
1303 unsigned char status
;
1304 unsigned long flags
;
1306 save_flags(flags
); cli();
1307 status
= read_zsreg(info
->zs_channel
, 0);
1308 restore_flags(flags
);
1309 status
= (status
& Tx_BUF_EMP
)? TIOCSER_TEMT
: 0;
1310 return put_user(status
,value
);
1313 static int get_modem_info(struct mac_serial
*info
, unsigned int *value
)
1315 unsigned char control
, status
;
1316 unsigned int result
;
1317 unsigned long flags
;
1319 save_flags(flags
); cli();
1320 control
= info
->curregs
[5];
1321 status
= read_zsreg(info
->zs_channel
, 0);
1322 restore_flags(flags
);
1323 result
= ((control
& RTS
) ? TIOCM_RTS
: 0)
1324 | ((control
& DTR
) ? TIOCM_DTR
: 0)
1325 | ((status
& DCD
) ? TIOCM_CAR
: 0)
1326 | ((status
& CTS
) ? 0: TIOCM_CTS
);
1327 return put_user(result
,value
);
1330 static int set_modem_info(struct mac_serial
*info
, unsigned int cmd
,
1331 unsigned int *value
)
1334 unsigned int arg
, bits
;
1335 unsigned long flags
;
1337 error
= get_user(arg
, value
);
1340 bits
= (arg
& TIOCM_RTS
? RTS
: 0) + (arg
& TIOCM_DTR
? DTR
: 0);
1341 save_flags(flags
); cli();
1344 info
->curregs
[5] |= bits
;
1347 info
->curregs
[5] &= ~bits
;
1350 info
->curregs
[5] = (info
->curregs
[5] & ~(DTR
| RTS
)) | bits
;
1353 restore_flags(flags
);
1356 info
->pendregs
[5] = info
->curregs
[5];
1357 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1358 restore_flags(flags
);
1363 * rs_break - turn transmit break condition on/off
1365 static void rs_break(struct tty_struct
*tty
, int break_state
)
1367 struct mac_serial
*info
= (struct mac_serial
*) tty
->driver_data
;
1368 unsigned long flags
;
1370 if (serial_paranoia_check(info
, tty
->device
, "rs_break"))
1375 save_flags(flags
); cli();
1376 if (break_state
== -1)
1377 info
->curregs
[5] |= SND_BRK
;
1379 info
->curregs
[5] &= ~SND_BRK
;
1380 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1381 restore_flags(flags
);
1384 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1385 unsigned int cmd
, unsigned long arg
)
1387 struct mac_serial
* info
= (struct mac_serial
*)tty
->driver_data
;
1390 if (info
->kgdb_channel
)
1393 if (serial_paranoia_check(info
, tty
->device
, "rs_ioctl"))
1396 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1397 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGSTRUCT
)) {
1398 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1404 return get_modem_info(info
, (unsigned int *) arg
);
1408 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1410 return get_serial_info(info
,
1411 (struct serial_struct
*) arg
);
1413 return set_serial_info(info
,
1414 (struct serial_struct
*) arg
);
1415 case TIOCSERGETLSR
: /* Get line status register */
1416 return get_lsr_info(info
, (unsigned int *) arg
);
1418 case TIOCSERGSTRUCT
:
1419 if (copy_to_user((struct mac_serial
*) arg
,
1420 info
, sizeof(struct mac_serial
)))
1425 return -ENOIOCTLCMD
;
1430 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1432 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1435 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1437 was_stopped
= info
->tx_stopped
;
1439 change_speed(info
, old_termios
);
1441 if (was_stopped
&& !info
->tx_stopped
) {
1442 tty
->hw_stopped
= 0;
1448 * ------------------------------------------------------------
1451 * This routine is called when the serial port gets closed.
1452 * Wait for the last remaining data to be sent.
1453 * ------------------------------------------------------------
1455 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
1457 struct mac_serial
* info
= (struct mac_serial
*)tty
->driver_data
;
1458 unsigned long flags
;
1460 if (!info
|| serial_paranoia_check(info
, tty
->device
, "rs_close"))
1463 save_flags(flags
); cli();
1465 if (tty_hung_up_p(filp
)) {
1466 restore_flags(flags
);
1470 #ifdef SERIAL_DEBUG_OPEN
1471 printk("rs_close ttys%d, count = %d\n", info
->line
, info
->count
);
1473 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1475 * Uh, oh. tty->count is 1, which means that the tty
1476 * structure will be freed. Info->count should always
1477 * be one in these conditions. If it's greater than
1478 * one, we've got real problems, since it means the
1479 * serial port won't be shutdown.
1481 printk("rs_close: bad serial port count; tty->count is 1, "
1482 "info->count is %d\n", info
->count
);
1485 if (--info
->count
< 0) {
1486 printk("rs_close: bad serial port count for ttys%d: %d\n",
1487 info
->line
, info
->count
);
1491 restore_flags(flags
);
1494 info
->flags
|= ZILOG_CLOSING
;
1496 * Save the termios structure, since this port may have
1497 * separate termios for callout and dialin.
1499 if (info
->flags
& ZILOG_NORMAL_ACTIVE
)
1500 info
->normal_termios
= *tty
->termios
;
1501 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
)
1502 info
->callout_termios
= *tty
->termios
;
1504 * Now we wait for the transmit buffer to clear; and we notify
1505 * the line discipline to only process XON/XOFF characters.
1507 #ifdef SERIAL_DEBUG_OPEN
1508 printk("waiting end of Tx... (timeout:%d)\n", info
->closing_wait
);
1511 if (info
->closing_wait
!= ZILOG_CLOSING_WAIT_NONE
)
1512 tty_wait_until_sent(tty
, info
->closing_wait
);
1514 * At this point we stop accepting input. To do this, we
1515 * disable the receiver and receive interrupts.
1517 info
->curregs
[3] &= ~RxENABLE
;
1518 info
->pendregs
[3] = info
->curregs
[3];
1519 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
1520 info
->curregs
[1] &= ~(0x18); /* disable any rx ints */
1521 info
->pendregs
[1] = info
->curregs
[1];
1522 write_zsreg(info
->zs_channel
, 1, info
->curregs
[1]);
1523 ZS_CLEARFIFO(info
->zs_channel
);
1524 if (info
->flags
& ZILOG_INITIALIZED
) {
1526 * Before we drop DTR, make sure the SCC transmitter
1527 * has completely drained.
1529 #ifdef SERIAL_DEBUG_OPEN
1530 printk("waiting end of Rx...\n");
1532 rs_wait_until_sent(tty
, info
->timeout
);
1536 /* restore flags now since shutdown() will have disabled this port's
1538 restore_flags(flags
);
1540 if (tty
->driver
.flush_buffer
)
1541 tty
->driver
.flush_buffer(tty
);
1542 if (tty
->ldisc
.flush_buffer
)
1543 tty
->ldisc
.flush_buffer(tty
);
1548 if (info
->blocked_open
) {
1549 if (info
->close_delay
) {
1550 current
->state
= TASK_INTERRUPTIBLE
;
1551 schedule_timeout(info
->close_delay
);
1553 wake_up_interruptible(&info
->open_wait
);
1555 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CALLOUT_ACTIVE
|
1557 wake_up_interruptible(&info
->close_wait
);
1561 * rs_wait_until_sent() --- wait until the transmitter is empty
1563 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1565 struct mac_serial
*info
= (struct mac_serial
*) tty
->driver_data
;
1566 unsigned long orig_jiffies
, char_time
;
1568 if (serial_paranoia_check(info
, tty
->device
, "rs_wait_until_sent"))
1571 /* printk("rs_wait_until_sent, timeout:%d, tty_stopped:%d, tx_stopped:%d\n",
1572 timeout, tty->stopped, info->tx_stopped);
1574 orig_jiffies
= jiffies
;
1576 * Set the check interval to be 1/5 of the estimated time to
1577 * send a single character, and make it at least 1. The check
1578 * interval should also be less than the timeout.
1580 if (info
->timeout
<= HZ
/50) {
1581 printk("macserial: invalid info->timeout=%d\n", info
->timeout
);
1582 info
->timeout
= HZ
/50+1;
1585 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1586 char_time
= char_time
/ 5;
1587 if (char_time
> HZ
) {
1588 printk("macserial: char_time %ld >HZ !!!\n", char_time
);
1590 } else if (char_time
== 0)
1593 char_time
= MIN(char_time
, timeout
);
1594 while ((read_zsreg(info
->zs_channel
, 1) & ALL_SNT
) == 0) {
1595 current
->state
= TASK_INTERRUPTIBLE
;
1596 schedule_timeout(char_time
);
1597 if (signal_pending(current
))
1599 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1602 current
->state
= TASK_RUNNING
;
1606 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1608 static void rs_hangup(struct tty_struct
*tty
)
1610 struct mac_serial
* info
= (struct mac_serial
*)tty
->driver_data
;
1612 if (serial_paranoia_check(info
, tty
->device
, "rs_hangup"))
1615 rs_flush_buffer(tty
);
1619 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CALLOUT_ACTIVE
);
1621 wake_up_interruptible(&info
->open_wait
);
1625 * ------------------------------------------------------------
1626 * rs_open() and friends
1627 * ------------------------------------------------------------
1629 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1630 struct mac_serial
*info
)
1632 DECLARE_WAITQUEUE(wait
,current
);
1637 * If the device is in the middle of being closed, then block
1638 * until it's done, and then try again.
1640 if (info
->flags
& ZILOG_CLOSING
) {
1641 interruptible_sleep_on(&info
->close_wait
);
1642 #ifdef SERIAL_DO_RESTART
1643 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1644 -EAGAIN
: -ERESTARTSYS
);
1651 * If this is a callout device, then just make sure the normal
1652 * device isn't being used.
1654 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1655 if (info
->flags
& ZILOG_NORMAL_ACTIVE
)
1657 if ((info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1658 (info
->flags
& ZILOG_SESSION_LOCKOUT
) &&
1659 (info
->session
!= current
->session
))
1661 if ((info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1662 (info
->flags
& ZILOG_PGRP_LOCKOUT
) &&
1663 (info
->pgrp
!= current
->pgrp
))
1665 info
->flags
|= ZILOG_CALLOUT_ACTIVE
;
1670 * If non-blocking mode is set, or the port is not enabled,
1671 * then make the check up front and then exit.
1673 if ((filp
->f_flags
& O_NONBLOCK
) ||
1674 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1675 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
)
1677 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1681 if (info
->flags
& ZILOG_CALLOUT_ACTIVE
) {
1682 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1685 if (tty
->termios
->c_cflag
& CLOCAL
)
1690 * Block waiting for the carrier detect and the line to become
1691 * free (i.e., not in use by the callout). While we are in
1692 * this loop, info->count is dropped by one, so that
1693 * rs_close() knows when to free things. We restore it upon
1694 * exit, either normal or abnormal.
1697 add_wait_queue(&info
->open_wait
, &wait
);
1698 #ifdef SERIAL_DEBUG_OPEN
1699 printk("block_til_ready before block: ttys%d, count = %d\n",
1700 info
->line
, info
->count
);
1703 if (!tty_hung_up_p(filp
))
1706 info
->blocked_open
++;
1709 if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1710 (tty
->termios
->c_cflag
& CBAUD
))
1713 set_current_state(TASK_INTERRUPTIBLE
);
1714 if (tty_hung_up_p(filp
) ||
1715 !(info
->flags
& ZILOG_INITIALIZED
)) {
1716 #ifdef SERIAL_DO_RESTART
1717 if (info
->flags
& ZILOG_HUP_NOTIFY
)
1720 retval
= -ERESTARTSYS
;
1726 if (!(info
->flags
& ZILOG_CALLOUT_ACTIVE
) &&
1727 !(info
->flags
& ZILOG_CLOSING
) &&
1728 (do_clocal
|| (read_zsreg(info
->zs_channel
, 0) & DCD
)))
1730 if (signal_pending(current
)) {
1731 retval
= -ERESTARTSYS
;
1734 #ifdef SERIAL_DEBUG_OPEN
1735 printk("block_til_ready blocking: ttys%d, count = %d\n",
1736 info
->line
, info
->count
);
1740 current
->state
= TASK_RUNNING
;
1741 remove_wait_queue(&info
->open_wait
, &wait
);
1742 if (!tty_hung_up_p(filp
))
1744 info
->blocked_open
--;
1745 #ifdef SERIAL_DEBUG_OPEN
1746 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1747 info
->line
, info
->count
);
1751 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
1756 * This routine is called whenever a serial port is opened. It
1757 * enables interrupts for a serial port, linking in its ZILOG structure into
1758 * the IRQ chain. It also performs the serial-specific
1759 * initialization for the tty structure.
1761 static int rs_open(struct tty_struct
*tty
, struct file
* filp
)
1763 struct mac_serial
*info
;
1767 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1768 if ((line
< 0) || (line
>= zs_channels_found
))
1770 info
= zs_soft
+ line
;
1773 if (info
->kgdb_channel
)
1776 if (serial_paranoia_check(info
, tty
->device
, "rs_open"))
1778 #ifdef SERIAL_DEBUG_OPEN
1779 printk("rs_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
1784 tty
->driver_data
= info
;
1788 page
= get_free_page(GFP_KERNEL
);
1794 tmp_buf
= (unsigned char *) page
;
1798 * If the port is the middle of closing, bail out now
1800 if (tty_hung_up_p(filp
) ||
1801 (info
->flags
& ZILOG_CLOSING
)) {
1802 if (info
->flags
& ZILOG_CLOSING
)
1803 interruptible_sleep_on(&info
->close_wait
);
1804 #ifdef SERIAL_DO_RESTART
1805 return ((info
->flags
& ZILOG_HUP_NOTIFY
) ?
1806 -EAGAIN
: -ERESTARTSYS
);
1813 * Start up serial port
1816 retval
= startup(info
, 1);
1820 retval
= block_til_ready(tty
, filp
, info
);
1822 #ifdef SERIAL_DEBUG_OPEN
1823 printk("rs_open returning after block_til_ready with %d\n",
1829 if ((info
->count
== 1) && (info
->flags
& ZILOG_SPLIT_TERMIOS
)) {
1830 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1831 *tty
->termios
= info
->normal_termios
;
1833 *tty
->termios
= info
->callout_termios
;
1834 change_speed(info
, 0);
1836 #ifdef CONFIG_SERIAL_CONSOLE
1837 if (sercons
.cflag
&& sercons
.index
== line
) {
1838 tty
->termios
->c_cflag
= sercons
.cflag
;
1840 change_speed(info
, 0);
1844 info
->session
= current
->session
;
1845 info
->pgrp
= current
->pgrp
;
1847 #ifdef SERIAL_DEBUG_OPEN
1848 printk("rs_open ttys%d successful...\n", info
->line
);
1853 /* Finally, routines used to initialize the serial driver. */
1855 static void show_serial_version(void)
1857 printk("PowerMac Z8530 serial driver version 1.01\n");
1860 /* Ask the PROM how many Z8530s we have and initialize their zs_channels */
1864 struct device_node
*dev
, *ch
;
1865 struct mac_serial
**pp
;
1871 for (dev
= find_devices("escc"); dev
!= 0; dev
= dev
->next
) {
1872 if (n
>= NUM_CHANNELS
) {
1873 printk("Sorry, can't use %s: no more channels\n",
1877 for (ch
= dev
->child
; ch
!= 0; ch
= ch
->sibling
) {
1878 if (ch
->n_addrs
< 1 || (ch
->n_intrs
< 1)) {
1879 printk("Can't use %s: %d addrs %d intrs\n",
1880 ch
->full_name
, ch
->n_addrs
, ch
->n_intrs
);
1883 zs_channels
[n
].control
= (volatile unsigned char *)
1884 ioremap(ch
->addrs
[0].address
, 0x1000);
1885 zs_channels
[n
].data
= zs_channels
[n
].control
+ 0x10;
1886 spin_lock_init(&zs_channels
[n
].lock
);
1887 zs_soft
[n
].zs_channel
= &zs_channels
[n
];
1888 zs_soft
[n
].dev_node
= ch
;
1889 zs_soft
[n
].irq
= ch
->intrs
[0].line
;
1890 zs_soft
[n
].zs_channel
->parent
= &zs_soft
[n
];
1891 zs_soft
[n
].is_cobalt_modem
= device_is_compatible(ch
, "cobalt");
1893 /* XXX tested only with wallstreet PowerBook,
1894 should do no harm anyway */
1895 conn
= get_property(ch
, "AAPL,connector", &lenp
);
1896 zs_soft
[n
].is_pwbk_ir
=
1897 conn
&& (strcmp(conn
, "infrared") == 0);
1899 /* XXX this assumes the prom puts chan A before B */
1901 zs_soft
[n
].zs_chan_a
= &zs_channels
[n
-1];
1903 zs_soft
[n
].zs_chan_a
= &zs_channels
[n
];
1906 pp
= &zs_soft
[n
].zs_next
;
1911 zs_channels_found
= n
;
1914 /* rs_init inits the driver */
1915 int macserial_init(void)
1918 unsigned long flags
;
1919 struct mac_serial
*info
;
1921 /* Setup base handler, and timer table. */
1922 init_bh(MACSERIAL_BH
, do_serial_bh
);
1923 timer_table
[RS_TIMER
].fn
= rs_timer
;
1924 timer_table
[RS_TIMER
].expires
= 0;
1926 /* Find out how many Z8530 SCCs we have */
1930 /* XXX assume it's a powerbook if we have a via-pmu */
1931 is_powerbook
= find_devices("via-pmu") != 0;
1933 /* Register the interrupt handler for each one */
1934 save_flags(flags
); cli();
1935 for (i
= 0; i
< zs_channels_found
; ++i
) {
1936 if (request_irq(zs_soft
[i
].irq
, rs_interrupt
, 0,
1937 "SCC", &zs_soft
[i
]))
1938 printk(KERN_ERR
"macserial: can't get irq %d\n",
1940 disable_irq(zs_soft
[i
].irq
);
1942 restore_flags(flags
);
1944 show_serial_version();
1946 /* Initialize the tty_driver structure */
1947 /* Not all of this is exactly right for us. */
1949 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
1950 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
1951 serial_driver
.name
= "ttyS";
1952 serial_driver
.major
= TTY_MAJOR
;
1953 serial_driver
.minor_start
= 64;
1954 serial_driver
.num
= zs_channels_found
;
1955 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
1956 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
1957 serial_driver
.init_termios
= tty_std_termios
;
1959 serial_driver
.init_termios
.c_cflag
=
1960 B38400
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1961 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
1962 serial_driver
.refcount
= &serial_refcount
;
1963 serial_driver
.table
= serial_table
;
1964 serial_driver
.termios
= serial_termios
;
1965 serial_driver
.termios_locked
= serial_termios_locked
;
1967 serial_driver
.open
= rs_open
;
1968 serial_driver
.close
= rs_close
;
1969 serial_driver
.write
= rs_write
;
1970 serial_driver
.flush_chars
= rs_flush_chars
;
1971 serial_driver
.write_room
= rs_write_room
;
1972 serial_driver
.chars_in_buffer
= rs_chars_in_buffer
;
1973 serial_driver
.flush_buffer
= rs_flush_buffer
;
1974 serial_driver
.ioctl
= rs_ioctl
;
1975 serial_driver
.throttle
= rs_throttle
;
1976 serial_driver
.unthrottle
= rs_unthrottle
;
1977 serial_driver
.set_termios
= rs_set_termios
;
1978 serial_driver
.stop
= rs_stop
;
1979 serial_driver
.start
= rs_start
;
1980 serial_driver
.hangup
= rs_hangup
;
1981 serial_driver
.break_ctl
= rs_break
;
1982 serial_driver
.wait_until_sent
= rs_wait_until_sent
;
1985 * The callout device is just like normal device except for
1986 * major number and the subtype code.
1988 callout_driver
= serial_driver
;
1989 callout_driver
.name
= "cua";
1990 callout_driver
.major
= TTYAUX_MAJOR
;
1991 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
1993 if (tty_register_driver(&serial_driver
))
1994 panic("Couldn't register serial driver\n");
1995 if (tty_register_driver(&callout_driver
))
1996 panic("Couldn't register callout driver\n");
1998 for (channel
= 0; channel
< zs_channels_found
; ++channel
) {
2000 if (zs_soft
[channel
].kgdb_channel
) {
2001 kgdb_interruptible(1);
2005 zs_soft
[channel
].clk_divisor
= 16;
2006 /* -- we are not sure the SCC is powered ON at this point
2007 zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
2009 zs_soft
[channel
].zs_baud
= 38400;
2011 /* If console serial line, then enable interrupts. */
2012 if (zs_soft
[channel
].is_cons
) {
2013 printk("macserial: console line, enabling interrupt %d\n", zs_soft
[channel
].irq
);
2014 panic("macserial: console not supported yet !");
2015 write_zsreg(zs_soft
[channel
].zs_channel
, R1
,
2016 (EXT_INT_ENAB
| INT_ALL_Rx
| TxINT_ENAB
));
2017 write_zsreg(zs_soft
[channel
].zs_channel
, R9
,
2022 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++)
2024 unsigned char* connector
;
2028 if (info
->kgdb_channel
) {
2032 info
->magic
= SERIAL_MAGIC
;
2033 info
->port
= (int) info
->zs_channel
->control
;
2036 info
->custom_divisor
= 16;
2038 info
->close_delay
= 50;
2039 info
->closing_wait
= 3000;
2043 info
->blocked_open
= 0;
2044 info
->tqueue
.routine
= do_softint
;
2045 info
->tqueue
.data
= info
;
2046 info
->callout_termios
=callout_driver
.init_termios
;
2047 info
->normal_termios
= serial_driver
.init_termios
;
2048 init_waitqueue_head(&info
->open_wait
);
2049 init_waitqueue_head(&info
->close_wait
);
2051 printk("tty%02d at 0x%08x (irq = %d)", info
->line
,
2052 info
->port
, info
->irq
);
2053 printk(" is a Z8530 ESCC");
2054 connector
= get_property(info
->dev_node
, "AAPL,connector", &lenp
);
2056 printk(", port = %s", connector
);
2057 if (info
->is_cobalt_modem
)
2058 printk(" (cobalt modem)");
2059 if (info
->is_pwbk_ir
)
2060 printk(" (powerbook IR)");
2064 if (info
->kgdb_channel
)
2068 if (!info
->is_cobalt_modem
)
2071 /* By default, disable the port */
2072 set_scc_power(info
, 0);
2079 int init_module(void)
2085 void cleanup_module(void)
2088 unsigned long flags
;
2089 struct mac_serial
*info
;
2091 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++)
2092 set_scc_power(info
, 0);
2093 save_flags(flags
); cli();
2094 for (i
= 0; i
< zs_channels_found
; ++i
)
2095 free_irq(zs_soft
[i
].irq
, &zs_soft
[i
]);
2096 restore_flags(flags
);
2097 tty_unregister_driver(&callout_driver
);
2098 tty_unregister_driver(&serial_driver
);
2104 * register_serial and unregister_serial allows for serial ports to be
2105 * configured at run-time, to support PCMCIA modems.
2107 /* PowerMac: Unused at this time, just here to make things link. */
2108 int register_serial(struct serial_struct
*req
)
2113 void unregister_serial(int line
)
2120 * ------------------------------------------------------------
2121 * Serial console driver
2122 * ------------------------------------------------------------
2124 #ifdef CONFIG_SERIAL_CONSOLE
2128 * Print a string to the serial port trying not to disturb
2129 * any possible real use of the port...
2131 static void serial_console_write(struct console
*co
, const char *s
,
2134 struct mac_serial
*info
= zs_soft
+ co
->index
;
2137 /* Turn of interrupts and enable the transmitter. */
2138 write_zsreg(info
->zs_channel
, R1
, info
->curregs
[1] & ~TxINT_ENAB
);
2139 write_zsreg(info
->zs_channel
, R5
, info
->curregs
[5] | TxENAB
| RTS
| DTR
);
2141 for (i
=0; i
<count
; i
++) {
2142 /* Wait for the transmit buffer to empty. */
2143 while ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
) == 0) {
2147 write_zsdata(info
->zs_channel
, s
[i
]);
2149 while ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
)
2153 write_zsdata(info
->zs_channel
, 13);
2157 /* Restore the values in the registers. */
2158 write_zsreg(info
->zs_channel
, R1
, info
->curregs
[1]);
2159 /* Don't disable the transmitter. */
2163 * Receive character from the serial port
2165 static int serial_console_wait_key(struct console
*co
)
2167 struct mac_serial
*info
= zs_soft
+ co
->index
;
2170 /* Turn of interrupts and enable the transmitter. */
2171 write_zsreg(info
->zs_channel
, R1
, info
->curregs
[1] & ~INT_ALL_Rx
);
2172 write_zsreg(info
->zs_channel
, R3
, info
->curregs
[3] | RxENABLE
);
2174 /* Wait for something in the receive buffer. */
2175 while((read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
) == 0)
2177 val
= read_zsdata(info
->zs_channel
);
2179 /* Restore the values in the registers. */
2180 write_zsreg(info
->zs_channel
, R1
, info
->curregs
[1]);
2181 write_zsreg(info
->zs_channel
, R3
, info
->curregs
[3]);
2186 static kdev_t
serial_console_device(struct console
*c
)
2188 return MKDEV(TTY_MAJOR
, 64 + c
->index
);
2192 * Setup initial baud/bits/parity. We do two things here:
2193 * - construct a cflag setting for the first rs_open()
2194 * - initialize the serial port
2195 * Return non-zero if we didn't find a serial port.
2197 static int __init
serial_console_setup(struct console
*co
, char *options
)
2199 struct mac_serial
*info
= zs_soft
+ co
->index
;
2203 int cflag
= CREAD
| HUPCL
| CLOCAL
;
2208 /* Find out how many Z8530 SCCs we have */
2215 /* Reset the channel */
2216 write_zsreg(info
->zs_channel
, R9
, CHRA
);
2219 baud
= simple_strtoul(options
, NULL
, 10);
2221 while(*s
>= '0' && *s
<= '9')
2230 * Now construct a cflag setting.
2270 cflag
|= PARENB
| PARODD
;
2278 save_flags(flags
); cli();
2279 memset(info
->curregs
, 0, sizeof(info
->curregs
));
2281 info
->zs_baud
= baud
;
2282 info
->clk_divisor
= 16;
2283 switch (info
->zs_baud
) {
2284 case ZS_CLOCK
/16: /* 230400 */
2285 info
->curregs
[4] = X16CLK
;
2286 info
->curregs
[11] = 0;
2288 case ZS_CLOCK
/32: /* 115200 */
2289 info
->curregs
[4] = X32CLK
;
2290 info
->curregs
[11] = 0;
2293 info
->curregs
[4] = X16CLK
;
2294 info
->curregs
[11] = TCBR
| RCBR
;
2295 brg
= BPS_TO_BRG(info
->zs_baud
, ZS_CLOCK
/info
->clk_divisor
);
2296 info
->curregs
[12] = (brg
& 255);
2297 info
->curregs
[13] = ((brg
>> 8) & 255);
2298 info
->curregs
[14] = BRENABL
;
2301 /* byte size and parity */
2302 info
->curregs
[3] &= ~RxNBITS_MASK
;
2303 info
->curregs
[5] &= ~TxNBITS_MASK
;
2304 switch (cflag
& CSIZE
) {
2306 info
->curregs
[3] |= Rx5
;
2307 info
->curregs
[5] |= Tx5
;
2310 info
->curregs
[3] |= Rx6
;
2311 info
->curregs
[5] |= Tx6
;
2314 info
->curregs
[3] |= Rx7
;
2315 info
->curregs
[5] |= Tx7
;
2318 default: /* defaults to 8 bits */
2319 info
->curregs
[3] |= Rx8
;
2320 info
->curregs
[5] |= Tx8
;
2323 info
->curregs
[5] |= TxENAB
| RTS
| DTR
;
2324 info
->pendregs
[3] = info
->curregs
[3];
2325 info
->pendregs
[5] = info
->curregs
[5];
2327 info
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
2328 if (cflag
& CSTOPB
) {
2329 info
->curregs
[4] |= SB2
;
2331 info
->curregs
[4] |= SB1
;
2333 if (cflag
& PARENB
) {
2334 info
->curregs
[4] |= PAR_ENA
;
2335 if (!(cflag
& PARODD
)) {
2336 info
->curregs
[4] |= PAR_EVEN
;
2339 info
->pendregs
[4] = info
->curregs
[4];
2341 if (!(cflag
& CLOCAL
)) {
2342 if (!(info
->curregs
[15] & DCDIE
))
2343 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
2344 info
->curregs
[15] |= DCDIE
;
2346 info
->curregs
[15] &= ~DCDIE
;
2347 if (cflag
& CRTSCTS
) {
2348 info
->curregs
[15] |= CTSIE
;
2349 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) != 0)
2350 info
->tx_stopped
= 1;
2352 info
->curregs
[15] &= ~CTSIE
;
2353 info
->tx_stopped
= 0;
2355 info
->pendregs
[15] = info
->curregs
[15];
2357 /* Load up the new values */
2358 load_zsregs(info
->zs_channel
, info
->curregs
);
2360 restore_flags(flags
);
2365 static struct console sercons
= {
2367 serial_console_write
,
2369 serial_console_device
,
2370 serial_console_wait_key
,
2372 serial_console_setup
,
2382 long __init
serial_console_init(long kmem_start
, long kmem_end
)
2384 register_console(&sercons
);
2387 #endif /* ifdef CONFIG_SERIAL_CONSOLE */
2390 /* These are for receiving and sending characters under the kgdb
2391 * source level kernel debugger.
2393 void putDebugChar(char kgdb_char
)
2395 struct mac_zschannel
*chan
= zs_kgdbchan
;
2396 while ((read_zsreg(chan
, 0) & Tx_BUF_EMP
) == 0)
2398 write_zsdata(chan
, kgdb_char
);
2401 char getDebugChar(void)
2403 struct mac_zschannel
*chan
= zs_kgdbchan
;
2404 while((read_zsreg(chan
, 0) & Rx_CH_AV
) == 0)
2405 eieio(); /*barrier();*/
2406 return read_zsdata(chan
);
2409 void kgdb_interruptible(int yes
)
2411 struct mac_zschannel
*chan
= zs_kgdbchan
;
2413 nine
= read_zsreg(chan
, 9);
2415 one
= EXT_INT_ENAB
|INT_ALL_Rx
;
2417 printk("turning serial ints on\n");
2421 printk("turning serial ints off\n");
2423 write_zsreg(chan
, 1, one
);
2424 write_zsreg(chan
, 9, nine
);
2427 /* This sets up the serial port we're using, and turns on
2428 * interrupts for that channel, so kgdb is usable once we're done.
2430 static inline void kgdb_chaninit(struct mac_zschannel
*ms
, int intson
, int bps
)
2434 volatile char *sccc
= ms
->control
;
2435 brg
= BPS_TO_BRG(bps
, ZS_CLOCK
/16);
2436 printk("setting bps on kgdb line to %d [brg=%x]\n", bps
, brg
);
2437 for (i
= 20000; i
!= 0; --i
) {
2440 for (i
= 0; i
< sizeof(scc_inittab
); ++i
) {
2441 write_zsreg(ms
, scc_inittab
[i
], scc_inittab
[i
+1]);
2446 /* This is called at boot time to prime the kgdb serial debugging
2447 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2448 * for /dev/ttyb which is determined in setup_arch() from the
2449 * boot command line flags.
2450 * XXX at the moment probably only channel A will work
2452 void __init
zs_kgdb_hook(int tty_num
)
2454 /* Find out how many Z8530 SCCs we have */
2458 set_scc_power(&zs_soft
[n
], 1);
2460 zs_kgdbchan
= zs_soft
[tty_num
].zs_channel
;
2461 zs_soft
[tty_num
].change_needed
= 0;
2462 zs_soft
[tty_num
].clk_divisor
= 16;
2463 zs_soft
[tty_num
].zs_baud
= 38400;
2464 zs_soft
[tty_num
].kgdb_channel
= 1; /* This runs kgdb */
2465 zs_soft
[tty_num
^ 1].kgdb_channel
= 0; /* This does not */
2467 /* Turn on transmitter/receiver at 8-bits/char */
2468 kgdb_chaninit(zs_soft
[tty_num
].zs_channel
, 1, 38400);
2469 printk("KGDB: on channel %d initialized\n", tty_num
);
2470 set_debug_traps(); /* init stub */
2472 #endif /* ifdef CONFIG_KGDB */