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)
9 * Receive DMA code by Takashi Oe <toe@unlserve.unl.edu>.
11 * $Id: macserial.c,v 1.24.2.4 1999/10/19 04:36:42 paulus Exp $
14 #include <linux/config.h>
15 #include <linux/errno.h>
16 #include <linux/module.h>
17 #include <linux/signal.h>
18 #include <linux/sched.h>
19 #include <linux/timer.h>
20 #include <linux/interrupt.h>
21 #include <linux/workqueue.h>
22 #include <linux/tty.h>
23 #include <linux/tty_flip.h>
24 #include <linux/major.h>
25 #include <linux/string.h>
26 #include <linux/fcntl.h>
28 #include <linux/kernel.h>
29 #include <linux/delay.h>
30 #include <linux/init.h>
31 #ifdef CONFIG_SERIAL_CONSOLE
32 #include <linux/console.h>
34 #include <linux/slab.h>
35 #include <linux/bitops.h>
37 #include <asm/sections.h>
39 #include <asm/pgtable.h>
42 #include <asm/system.h>
43 #include <asm/segment.h>
44 #include <asm/machdep.h>
45 #include <asm/pmac_feature.h>
46 #include <linux/adb.h>
47 #include <linux/pmu.h>
51 #include <asm/dbdma.h>
53 #include "macserial.h"
55 #ifdef CONFIG_PMAC_PBOOK
56 static int serial_notify_sleep(struct pmu_sleep_notifier
*self
, int when
);
57 static struct pmu_sleep_notifier serial_sleep_notifier
= {
63 #define SUPPORT_SERIAL_DMA
64 #define MACSERIAL_VERSION "2.0"
67 * It would be nice to dynamically allocate everything that
68 * depends on NUM_SERIAL, so we could support any number of
69 * Z8530s, but for now...
71 #define NUM_SERIAL 2 /* Max number of ZS chips supported */
72 #define NUM_CHANNELS (NUM_SERIAL * 2) /* 2 channels per chip */
74 /* On PowerMacs, the hardware takes care of the SCC recovery time,
75 but we need the eieio to make sure that the accesses occur
76 in the order we want. */
77 #define RECOVERY_DELAY eieio()
79 static struct tty_driver
*serial_driver
;
81 struct mac_zschannel zs_channels
[NUM_CHANNELS
];
83 struct mac_serial zs_soft
[NUM_CHANNELS
];
84 int zs_channels_found
;
85 struct mac_serial
*zs_chain
; /* list of all channels */
87 struct tty_struct zs_ttys
[NUM_CHANNELS
];
89 static int is_powerbook
;
91 #ifdef CONFIG_SERIAL_CONSOLE
92 static struct console sercons
;
96 struct mac_zschannel
*zs_kgdbchan
;
97 static unsigned char scc_inittab
[] = {
98 9, 0x80, /* reset A side (CHRA) */
99 13, 0, /* set baud rate divisor */
101 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
102 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
103 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
104 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
105 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
108 #define ZS_CLOCK 3686400 /* Z8530 RTxC input clock rate */
110 /* serial subtype definitions */
111 #define SERIAL_TYPE_NORMAL 1
113 /* number of characters left in xmit buffer before we ask for more */
114 #define WAKEUP_CHARS 256
119 #undef SERIAL_DEBUG_INTR
120 #undef SERIAL_DEBUG_OPEN
121 #undef SERIAL_DEBUG_FLOW
122 #undef SERIAL_DEBUG_POWER
123 #undef SERIAL_DEBUG_THROTTLE
124 #undef SERIAL_DEBUG_STOP
125 #undef SERIAL_DEBUG_BAUDS
127 #define RS_STROBE_TIME 10
128 #define RS_ISR_PASS_LIMIT 256
130 #define _INLINE_ inline
132 #ifdef SERIAL_DEBUG_OPEN
133 #define OPNDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg)
135 #define OPNDBG(fmt, arg...) do { } while (0)
137 #ifdef SERIAL_DEBUG_POWER
138 #define PWRDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg)
140 #define PWRDBG(fmt, arg...) do { } while (0)
142 #ifdef SERIAL_DEBUG_BAUDS
143 #define BAUDBG(fmt, arg...) printk(fmt , ## arg)
145 #define BAUDBG(fmt, arg...) do { } while (0)
148 static void probe_sccs(void);
149 static void change_speed(struct mac_serial
*info
, struct termios
*old
);
150 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
151 static int set_scc_power(struct mac_serial
* info
, int state
);
152 static int setup_scc(struct mac_serial
* info
);
153 static void dbdma_reset(volatile struct dbdma_regs
*dma
);
154 static void dbdma_flush(volatile struct dbdma_regs
*dma
);
155 static irqreturn_t
rs_txdma_irq(int irq
, void *dev_id
, struct pt_regs
*regs
);
156 static irqreturn_t
rs_rxdma_irq(int irq
, void *dev_id
, struct pt_regs
*regs
);
157 static void dma_init(struct mac_serial
* info
);
158 static void rxdma_start(struct mac_serial
* info
, int curr
);
159 static void rxdma_to_tty(struct mac_serial
* info
);
162 * tmp_buf is used as a temporary buffer by serial_write. We need to
163 * lock it in case the copy_from_user blocks while swapping in a page,
164 * and some other program tries to do a serial write at the same time.
165 * Since the lock will only come under contention when the system is
166 * swapping and available memory is low, it makes sense to share one
167 * buffer across all the serial ports, since it significantly saves
168 * memory if large numbers of serial ports are open.
170 static unsigned char *tmp_buf
;
171 static DECLARE_MUTEX(tmp_buf_sem
);
174 static inline int __pmac
175 serial_paranoia_check(struct mac_serial
*info
,
176 char *name
, const char *routine
)
178 #ifdef SERIAL_PARANOIA_CHECK
179 static const char badmagic
[] = KERN_WARNING
180 "Warning: bad magic number for serial struct %s in %s\n";
181 static const char badinfo
[] = KERN_WARNING
182 "Warning: null mac_serial for %s in %s\n";
185 printk(badinfo
, name
, routine
);
188 if (info
->magic
!= SERIAL_MAGIC
) {
189 printk(badmagic
, name
, routine
);
197 * Reading and writing Z8530 registers.
199 static inline unsigned char __pmac
read_zsreg(struct mac_zschannel
*channel
,
202 unsigned char retval
;
206 * We have to make this atomic.
208 spin_lock_irqsave(&channel
->lock
, flags
);
210 *channel
->control
= reg
;
213 retval
= *channel
->control
;
215 spin_unlock_irqrestore(&channel
->lock
, flags
);
219 static inline void __pmac
write_zsreg(struct mac_zschannel
*channel
,
220 unsigned char reg
, unsigned char value
)
224 spin_lock_irqsave(&channel
->lock
, flags
);
226 *channel
->control
= reg
;
229 *channel
->control
= value
;
231 spin_unlock_irqrestore(&channel
->lock
, flags
);
235 static inline unsigned char __pmac
read_zsdata(struct mac_zschannel
*channel
)
237 unsigned char retval
;
239 retval
= *channel
->data
;
244 static inline void write_zsdata(struct mac_zschannel
*channel
,
247 *channel
->data
= value
;
252 static inline void load_zsregs(struct mac_zschannel
*channel
,
255 ZS_CLEARERR(channel
);
256 ZS_CLEARFIFO(channel
);
258 write_zsreg(channel
, R4
, regs
[R4
]);
259 write_zsreg(channel
, R10
, regs
[R10
]);
260 write_zsreg(channel
, R3
, regs
[R3
] & ~RxENABLE
);
261 write_zsreg(channel
, R5
, regs
[R5
] & ~TxENAB
);
262 write_zsreg(channel
, R1
, regs
[R1
]);
263 write_zsreg(channel
, R9
, regs
[R9
]);
264 write_zsreg(channel
, R11
, regs
[R11
]);
265 write_zsreg(channel
, R12
, regs
[R12
]);
266 write_zsreg(channel
, R13
, regs
[R13
]);
267 write_zsreg(channel
, R14
, regs
[R14
]);
268 write_zsreg(channel
, R15
, regs
[R15
]);
269 write_zsreg(channel
, R3
, regs
[R3
]);
270 write_zsreg(channel
, R5
, regs
[R5
]);
274 /* Sets or clears DTR/RTS on the requested line */
275 static inline void zs_rtsdtr(struct mac_serial
*ss
, int set
)
278 ss
->curregs
[5] |= (RTS
| DTR
);
280 ss
->curregs
[5] &= ~(RTS
| DTR
);
281 write_zsreg(ss
->zs_channel
, 5, ss
->curregs
[5]);
285 /* Utility routines for the Zilog */
286 static inline int get_zsbaud(struct mac_serial
*ss
)
288 struct mac_zschannel
*channel
= ss
->zs_channel
;
291 if ((ss
->curregs
[R11
] & TCBR
) == 0) {
292 /* higher rates don't use the baud rate generator */
293 return (ss
->curregs
[R4
] & X32CLK
)? ZS_CLOCK
/32: ZS_CLOCK
/16;
295 /* The baud rate is split up between two 8-bit registers in
296 * what is termed 'BRG time constant' format in my docs for
297 * the chip, it is a function of the clk rate the chip is
298 * receiving which happens to be constant.
300 brg
= (read_zsreg(channel
, 13) << 8);
301 brg
|= read_zsreg(channel
, 12);
302 return BRG_TO_BPS(brg
, (ZS_CLOCK
/(ss
->clk_divisor
)));
305 /* On receive, this clears errors and the receiver interrupts */
306 static inline void rs_recv_clear(struct mac_zschannel
*zsc
)
308 write_zsreg(zsc
, 0, ERR_RES
);
309 write_zsreg(zsc
, 0, RES_H_IUS
); /* XXX this is unnecessary */
313 * Reset a Descriptor-Based DMA channel.
315 static void dbdma_reset(volatile struct dbdma_regs
*dma
)
319 out_le32(&dma
->control
, (WAKE
|FLUSH
|PAUSE
|RUN
) << 16);
322 * Yes this looks peculiar, but apparently it needs to be this
323 * way on some machines. (We need to make sure the DBDMA
324 * engine has actually got the write above and responded
327 for (i
= 200; i
> 0; --i
)
328 if (ld_le32(&dma
->status
) & RUN
)
333 * Tells a DBDMA channel to stop and write any buffered data
334 * it might have to memory.
336 static _INLINE_
void dbdma_flush(volatile struct dbdma_regs
*dma
)
340 out_le32(&dma
->control
, (FLUSH
<< 16) | FLUSH
);
341 while (((in_le32(&dma
->status
) & FLUSH
) != 0) && (i
++ < 100))
346 * ----------------------------------------------------------------------
348 * Here starts the interrupt handling routines. All of the following
349 * subroutines are declared as inline and are folded into
350 * rs_interrupt(). They were separated out for readability's sake.
352 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
353 * -----------------------------------------------------------------------
357 * This routine is used by the interrupt handler to schedule
358 * processing in the software interrupt portion of the driver.
360 static _INLINE_
void rs_sched_event(struct mac_serial
*info
,
363 info
->event
|= 1 << event
;
364 schedule_work(&info
->tqueue
);
367 /* Work out the flag value for a z8530 status value. */
368 static _INLINE_
int stat_to_flag(int stat
)
374 } else if (stat
& FRM_ERR
) {
376 } else if (stat
& PAR_ERR
) {
383 static _INLINE_
void receive_chars(struct mac_serial
*info
,
384 struct pt_regs
*regs
)
386 struct tty_struct
*tty
= info
->tty
;
387 unsigned char ch
, stat
, flag
;
389 while ((read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
) != 0) {
391 stat
= read_zsreg(info
->zs_channel
, R1
);
392 ch
= read_zsdata(info
->zs_channel
);
395 if (info
->kgdb_channel
) {
396 if (ch
== 0x03 || ch
== '$')
398 if (stat
& (Rx_OVR
|FRM_ERR
|PAR_ERR
))
399 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
405 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
406 tty_flip_buffer_push(tty
);
408 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
409 static int flip_buf_ovf
;
410 if (++flip_buf_ovf
<= 1)
411 printk(KERN_WARNING
"FB. overflow: %d\n",
417 static int flip_max_cnt
;
418 if (flip_max_cnt
< tty
->flip
.count
)
419 flip_max_cnt
= tty
->flip
.count
;
421 flag
= stat_to_flag(stat
);
423 /* reset the error indication */
424 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
425 *tty
->flip
.flag_buf_ptr
++ = flag
;
426 *tty
->flip
.char_buf_ptr
++ = ch
;
429 tty_flip_buffer_push(tty
);
432 static void transmit_chars(struct mac_serial
*info
)
434 if ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
) == 0)
438 if (info
->x_char
&& !info
->power_wait
) {
440 write_zsdata(info
->zs_channel
, info
->x_char
);
446 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
|| info
->tx_stopped
447 || info
->power_wait
) {
448 write_zsreg(info
->zs_channel
, 0, RES_Tx_P
);
453 write_zsdata(info
->zs_channel
, info
->xmit_buf
[info
->xmit_tail
++]);
454 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
458 if (info
->xmit_cnt
< WAKEUP_CHARS
)
459 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
462 static void powerup_done(unsigned long data
)
464 struct mac_serial
*info
= (struct mac_serial
*) data
;
467 spin_lock_irqsave(&info
->lock
, flags
);
468 info
->power_wait
= 0;
469 transmit_chars(info
);
470 spin_unlock_irqrestore(&info
->lock
, flags
);
473 static _INLINE_
void status_handle(struct mac_serial
*info
)
475 unsigned char status
;
477 /* Get status from Read Register 0 */
478 status
= read_zsreg(info
->zs_channel
, 0);
480 /* Check for DCD transitions */
481 if (((status
^ info
->read_reg_zero
) & DCD
) != 0
482 && info
->tty
&& !C_CLOCAL(info
->tty
)) {
484 wake_up_interruptible(&info
->open_wait
);
487 tty_hangup(info
->tty
);
491 /* Check for CTS transitions */
492 if (info
->tty
&& C_CRTSCTS(info
->tty
)) {
494 * For some reason, on the Power Macintosh,
495 * it seems that the CTS bit is 1 when CTS is
496 * *negated* and 0 when it is asserted.
497 * The DCD bit doesn't seem to be inverted
500 if ((status
& CTS
) == 0) {
501 if (info
->tx_stopped
) {
502 #ifdef SERIAL_DEBUG_FLOW
503 printk(KERN_DEBUG
"CTS up\n");
505 info
->tx_stopped
= 0;
506 if (!info
->tx_active
)
507 transmit_chars(info
);
510 #ifdef SERIAL_DEBUG_FLOW
511 printk(KERN_DEBUG
"CTS down\n");
513 info
->tx_stopped
= 1;
517 /* Clear status condition... */
518 write_zsreg(info
->zs_channel
, 0, RES_EXT_INT
);
519 info
->read_reg_zero
= status
;
522 static _INLINE_
void receive_special_dma(struct mac_serial
*info
)
524 unsigned char stat
, flag
;
525 volatile struct dbdma_regs
*rd
= &info
->rx
->dma
;
526 int where
= RX_BUF_SIZE
;
528 spin_lock(&info
->rx_dma_lock
);
529 if ((ld_le32(&rd
->status
) & ACTIVE
) != 0)
531 if (in_le32(&rd
->cmdptr
)
532 == virt_to_bus(info
->rx_cmds
[info
->rx_cbuf
] + 1))
533 where
-= in_le16(&info
->rx
->res_count
);
536 stat
= read_zsreg(info
->zs_channel
, R1
);
538 flag
= stat_to_flag(stat
);
540 info
->rx_flag_buf
[info
->rx_cbuf
][where
] = flag
;
541 /* reset the error indication */
542 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
545 spin_unlock(&info
->rx_dma_lock
);
549 * This is the serial driver's generic interrupt routine
551 static irqreturn_t
rs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
553 struct mac_serial
*info
= (struct mac_serial
*) dev_id
;
554 unsigned char zs_intreg
;
559 if (!(info
->flags
& ZILOG_INITIALIZED
)) {
560 printk(KERN_WARNING
"rs_interrupt: irq %d, port not "
561 "initialized\n", irq
);
566 /* NOTE: The read register 3, which holds the irq status,
567 * does so for both channels on each chip. Although
568 * the status value itself must be read from the A
569 * channel and is only valid when read from channel A.
570 * Yes... broken hardware...
572 #define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
574 if (info
->zs_chan_a
== info
->zs_channel
)
575 shift
= 3; /* Channel A */
577 shift
= 0; /* Channel B */
579 spin_lock_irqsave(&info
->lock
, flags
);
581 zs_intreg
= read_zsreg(info
->zs_chan_a
, 3) >> shift
;
582 #ifdef SERIAL_DEBUG_INTR
583 printk(KERN_DEBUG
"rs_interrupt: irq %d, zs_intreg 0x%x\n",
584 irq
, (int)zs_intreg
);
587 if ((zs_intreg
& CHAN_IRQMASK
) == 0)
591 if (zs_intreg
& CHBRxIP
) {
592 /* If we are doing DMA, we only ask for interrupts
593 on characters with errors or special conditions. */
594 if (info
->dma_initted
)
595 receive_special_dma(info
);
597 receive_chars(info
, regs
);
599 if (zs_intreg
& CHBTxIP
)
600 transmit_chars(info
);
601 if (zs_intreg
& CHBEXT
)
604 spin_unlock_irqrestore(&info
->lock
, flags
);
605 return IRQ_RETVAL(handled
);
608 /* Transmit DMA interrupt - not used at present */
609 static irqreturn_t
rs_txdma_irq(int irq
, void *dev_id
, struct pt_regs
*regs
)
615 * Receive DMA interrupt.
617 static irqreturn_t
rs_rxdma_irq(int irq
, void *dev_id
, struct pt_regs
*regs
)
619 struct mac_serial
*info
= (struct mac_serial
*) dev_id
;
620 volatile struct dbdma_cmd
*cd
;
622 if (!info
->dma_initted
)
624 spin_lock(&info
->rx_dma_lock
);
625 /* First, confirm that this interrupt is, indeed, coming */
627 cd
= info
->rx_cmds
[info
->rx_cbuf
] + 2;
628 if ((in_le16(&cd
->xfer_status
) & (RUN
| ACTIVE
)) != (RUN
| ACTIVE
)) {
629 spin_unlock(&info
->rx_dma_lock
);
632 if (info
->rx_fbuf
!= RX_NO_FBUF
) {
633 info
->rx_cbuf
= info
->rx_fbuf
;
634 if (++info
->rx_fbuf
== info
->rx_nbuf
)
636 if (info
->rx_fbuf
== info
->rx_ubuf
)
637 info
->rx_fbuf
= RX_NO_FBUF
;
639 spin_unlock(&info
->rx_dma_lock
);
644 * -------------------------------------------------------------------
645 * Here ends the serial interrupt routines.
646 * -------------------------------------------------------------------
650 * ------------------------------------------------------------
651 * rs_stop() and rs_start()
653 * This routines are called before setting or resetting tty->stopped.
654 * ------------------------------------------------------------
656 static void rs_stop(struct tty_struct
*tty
)
658 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
660 #ifdef SERIAL_DEBUG_STOP
661 printk(KERN_DEBUG
"rs_stop %ld....\n",
662 tty
->ldisc
.chars_in_buffer(tty
));
665 if (serial_paranoia_check(info
, tty
->name
, "rs_stop"))
669 spin_lock_irqsave(&info
->lock
, flags
);
670 if (info
->curregs
[5] & TxENAB
) {
671 info
->curregs
[5] &= ~TxENAB
;
672 info
->pendregs
[5] &= ~TxENAB
;
673 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
675 spin_unlock_irqrestore(&info
->lock
, flags
);
679 static void rs_start(struct tty_struct
*tty
)
681 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
684 #ifdef SERIAL_DEBUG_STOP
685 printk(KERN_DEBUG
"rs_start %ld....\n",
686 tty
->ldisc
.chars_in_buffer(tty
));
689 if (serial_paranoia_check(info
, tty
->name
, "rs_start"))
692 spin_lock_irqsave(&info
->lock
, flags
);
694 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->curregs
[5] & TxENAB
)) {
695 info
->curregs
[5] |= TxENAB
;
696 info
->pendregs
[5] = info
->curregs
[5];
697 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
700 if (info
->xmit_cnt
&& info
->xmit_buf
&& !info
->tx_active
) {
701 transmit_chars(info
);
704 spin_unlock_irqrestore(&info
->lock
, flags
);
707 static void do_softint(void *private_
)
709 struct mac_serial
*info
= (struct mac_serial
*) private_
;
710 struct tty_struct
*tty
;
716 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
))
720 static int startup(struct mac_serial
* info
)
724 OPNDBG("startup() (ttyS%d, irq %d)\n", info
->line
, info
->irq
);
726 if (info
->flags
& ZILOG_INITIALIZED
) {
727 OPNDBG(" -> already inited\n");
731 if (!info
->xmit_buf
) {
732 info
->xmit_buf
= (unsigned char *) get_zeroed_page(GFP_KERNEL
);
737 OPNDBG("starting up ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
739 delay
= set_scc_power(info
, 1);
747 spin_lock_irqsave(&info
->lock
, flags
);
748 info
->power_wait
= 1;
749 mod_timer(&info
->powerup_timer
,
750 jiffies
+ (delay
* HZ
+ 999) / 1000);
751 spin_unlock_irqrestore(&info
->lock
, flags
);
754 OPNDBG("enabling IRQ on ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
756 info
->flags
|= ZILOG_INITIALIZED
;
757 enable_irq(info
->irq
);
758 if (info
->dma_initted
) {
759 enable_irq(info
->rx_dma_irq
);
765 static _INLINE_
void rxdma_start(struct mac_serial
* info
, int curr
)
767 volatile struct dbdma_regs
*rd
= &info
->rx
->dma
;
768 volatile struct dbdma_cmd
*cd
= info
->rx_cmds
[curr
];
770 //printk(KERN_DEBUG "SCC: rxdma_start\n");
772 st_le32(&rd
->cmdptr
, virt_to_bus(cd
));
773 out_le32(&rd
->control
, (RUN
<< 16) | RUN
);
776 static void rxdma_to_tty(struct mac_serial
*info
)
778 struct tty_struct
*tty
= info
->tty
;
779 volatile struct dbdma_regs
*rd
= &info
->rx
->dma
;
781 int residue
, available
, space
, do_queue
;
787 spin_lock_irqsave(&info
->rx_dma_lock
, flags
);
789 space
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
;
795 if (info
->rx_ubuf
== info
->rx_cbuf
) {
796 if ((ld_le32(&rd
->status
) & ACTIVE
) != 0) {
798 if (in_le32(&rd
->cmdptr
)
799 == virt_to_bus(info
->rx_cmds
[info
->rx_cbuf
]+1))
800 residue
= in_le16(&info
->rx
->res_count
);
803 available
= RX_BUF_SIZE
- residue
- info
->rx_done_bytes
;
804 if (available
> space
)
807 memcpy(tty
->flip
.char_buf_ptr
,
808 info
->rx_char_buf
[info
->rx_ubuf
] + info
->rx_done_bytes
,
810 memcpy(tty
->flip
.flag_buf_ptr
,
811 info
->rx_flag_buf
[info
->rx_ubuf
] + info
->rx_done_bytes
,
813 tty
->flip
.char_buf_ptr
+= available
;
814 tty
->flip
.count
+= available
;
815 tty
->flip
.flag_buf_ptr
+= available
;
816 memset(info
->rx_flag_buf
[info
->rx_ubuf
] + info
->rx_done_bytes
,
818 info
->rx_done_bytes
+= available
;
821 if (info
->rx_done_bytes
== RX_BUF_SIZE
) {
822 volatile struct dbdma_cmd
*cd
= info
->rx_cmds
[info
->rx_ubuf
];
824 if (info
->rx_ubuf
== info
->rx_cbuf
)
826 /* mark rx_char_buf[rx_ubuf] free */
827 st_le16(&cd
->command
, DBDMA_NOP
);
829 st_le32(&cd
->cmd_dep
, 0);
830 st_le32((unsigned int *)&cd
->res_count
, 0);
832 st_le16(&cd
->xfer_status
, 0);
834 if (info
->rx_fbuf
== RX_NO_FBUF
) {
835 info
->rx_fbuf
= info
->rx_ubuf
;
836 if (!(ld_le32(&rd
->status
) & ACTIVE
)) {
837 dbdma_reset(&info
->rx
->dma
);
838 rxdma_start(info
, info
->rx_ubuf
);
839 info
->rx_cbuf
= info
->rx_ubuf
;
842 info
->rx_done_bytes
= 0;
843 if (++info
->rx_ubuf
== info
->rx_nbuf
)
845 if (info
->rx_fbuf
== info
->rx_ubuf
)
846 info
->rx_fbuf
= RX_NO_FBUF
;
850 spin_unlock_irqrestore(&info
->rx_dma_lock
, flags
);
852 tty_flip_buffer_push(tty
);
855 static void poll_rxdma(unsigned long private_
)
857 struct mac_serial
*info
= (struct mac_serial
*) private_
;
861 spin_lock_irqsave(&info
->rx_dma_lock
, flags
);
862 mod_timer(&info
->poll_dma_timer
, RX_DMA_TIMER
);
863 spin_unlock_irqrestore(&info
->rx_dma_lock
, flags
);
866 static void dma_init(struct mac_serial
* info
)
869 volatile struct dbdma_cmd
*cd
;
874 /* various mem set up */
875 size
= sizeof(struct dbdma_cmd
) * (3 * info
->rx_nbuf
+ 2)
876 + (RX_BUF_SIZE
* 2 + sizeof(*info
->rx_cmds
)
877 + sizeof(*info
->rx_char_buf
) + sizeof(*info
->rx_flag_buf
))
879 info
->dma_priv
= kmalloc(size
, GFP_KERNEL
| GFP_DMA
);
880 if (info
->dma_priv
== NULL
)
882 memset(info
->dma_priv
, 0, size
);
884 info
->rx_cmds
= (volatile struct dbdma_cmd
**)info
->dma_priv
;
885 info
->rx_char_buf
= (unsigned char **) (info
->rx_cmds
+ info
->rx_nbuf
);
886 info
->rx_flag_buf
= info
->rx_char_buf
+ info
->rx_nbuf
;
887 p
= (unsigned char *) (info
->rx_flag_buf
+ info
->rx_nbuf
);
888 for (i
= 0; i
< info
->rx_nbuf
; i
++, p
+= RX_BUF_SIZE
)
889 info
->rx_char_buf
[i
] = p
;
890 for (i
= 0; i
< info
->rx_nbuf
; i
++, p
+= RX_BUF_SIZE
)
891 info
->rx_flag_buf
[i
] = p
;
893 /* a bit of DMA programming */
894 cd
= info
->rx_cmds
[0] = (volatile struct dbdma_cmd
*) DBDMA_ALIGN(p
);
895 st_le16(&cd
->command
, DBDMA_NOP
);
897 st_le16(&cd
->req_count
, RX_BUF_SIZE
);
898 st_le16(&cd
->command
, INPUT_MORE
);
899 st_le32(&cd
->phy_addr
, virt_to_bus(info
->rx_char_buf
[0]));
901 st_le16(&cd
->req_count
, 4);
902 st_le16(&cd
->command
, STORE_WORD
| INTR_ALWAYS
);
903 st_le32(&cd
->phy_addr
, virt_to_bus(cd
-2));
904 st_le32(&cd
->cmd_dep
, DBDMA_STOP
);
905 for (i
= 1; i
< info
->rx_nbuf
; i
++) {
906 info
->rx_cmds
[i
] = ++cd
;
907 st_le16(&cd
->command
, DBDMA_NOP
);
909 st_le16(&cd
->req_count
, RX_BUF_SIZE
);
910 st_le16(&cd
->command
, INPUT_MORE
);
911 st_le32(&cd
->phy_addr
, virt_to_bus(info
->rx_char_buf
[i
]));
913 st_le16(&cd
->req_count
, 4);
914 st_le16(&cd
->command
, STORE_WORD
| INTR_ALWAYS
);
915 st_le32(&cd
->phy_addr
, virt_to_bus(cd
-2));
916 st_le32(&cd
->cmd_dep
, DBDMA_STOP
);
919 st_le16(&cd
->command
, DBDMA_NOP
| BR_ALWAYS
);
920 st_le32(&cd
->cmd_dep
, virt_to_bus(info
->rx_cmds
[0]));
922 /* setup DMA to our liking */
923 dbdma_reset(&info
->rx
->dma
);
924 st_le32(&info
->rx
->dma
.intr_sel
, 0x10001);
925 st_le32(&info
->rx
->dma
.br_sel
, 0x10001);
926 out_le32(&info
->rx
->dma
.wait_sel
, 0x10001);
928 /* set various flags */
931 info
->rx_fbuf
= info
->rx_ubuf
+ 1;
932 if (info
->rx_fbuf
== info
->rx_nbuf
)
933 info
->rx_fbuf
= RX_NO_FBUF
;
934 info
->rx_done_bytes
= 0;
937 init_timer(&info
->poll_dma_timer
);
938 info
->poll_dma_timer
.function
= (void *)&poll_rxdma
;
939 info
->poll_dma_timer
.data
= (unsigned long)info
;
941 info
->dma_initted
= 1;
945 * FixZeroBug....Works around a bug in the SCC receving channel.
946 * Taken from Darwin code, 15 Sept. 2000 -DanM
948 * The following sequence prevents a problem that is seen with O'Hare ASICs
949 * (most versions -- also with some Heathrow and Hydra ASICs) where a zero
950 * at the input to the receiver becomes 'stuck' and locks up the receiver.
951 * This problem can occur as a result of a zero bit at the receiver input
952 * coincident with any of the following events:
954 * The SCC is initialized (hardware or software).
955 * A framing error is detected.
956 * The clocking option changes from synchronous or X1 asynchronous
957 * clocking to X16, X32, or X64 asynchronous clocking.
958 * The decoding mode is changed among NRZ, NRZI, FM0, or FM1.
960 * This workaround attempts to recover from the lockup condition by placing
961 * the SCC in synchronous loopback mode with a fast clock before programming
962 * any of the asynchronous modes.
964 static void fix_zero_bug_scc(struct mac_serial
* info
)
966 write_zsreg(info
->zs_channel
, 9,
967 (info
->zs_channel
== info
->zs_chan_a
? CHRA
: CHRB
));
969 write_zsreg(info
->zs_channel
, 9,
970 ((info
->zs_channel
== info
->zs_chan_a
? CHRA
: CHRB
) | NV
));
972 write_zsreg(info
->zs_channel
, 4, (X1CLK
| EXTSYNC
));
974 /* I think this is wrong....but, I just copying code....
976 write_zsreg(info
->zs_channel
, 3, (8 & ~RxENABLE
));
978 write_zsreg(info
->zs_channel
, 5, (8 & ~TxENAB
));
979 write_zsreg(info
->zs_channel
, 9, NV
); /* Didn't we already do this? */
980 write_zsreg(info
->zs_channel
, 11, (RCBR
| TCBR
));
981 write_zsreg(info
->zs_channel
, 12, 0);
982 write_zsreg(info
->zs_channel
, 13, 0);
983 write_zsreg(info
->zs_channel
, 14, (LOOPBAK
| SSBR
));
984 write_zsreg(info
->zs_channel
, 14, (LOOPBAK
| SSBR
| BRENABL
));
985 write_zsreg(info
->zs_channel
, 3, (8 | RxENABLE
));
986 write_zsreg(info
->zs_channel
, 0, RES_EXT_INT
);
987 write_zsreg(info
->zs_channel
, 0, RES_EXT_INT
); /* to kill some time */
989 /* The channel should be OK now, but it is probably receiving
991 * Switch to asynchronous mode, disable the receiver,
992 * and discard everything in the receive buffer.
994 write_zsreg(info
->zs_channel
, 9, NV
);
995 write_zsreg(info
->zs_channel
, 4, PAR_ENA
);
996 write_zsreg(info
->zs_channel
, 3, (8 & ~RxENABLE
));
998 while (read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
) {
999 (void)read_zsreg(info
->zs_channel
, 8);
1000 write_zsreg(info
->zs_channel
, 0, RES_EXT_INT
);
1001 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
1005 static int setup_scc(struct mac_serial
* info
)
1007 unsigned long flags
;
1009 OPNDBG("setting up ttyS%d SCC...\n", info
->line
);
1011 spin_lock_irqsave(&info
->lock
, flags
);
1013 /* Nice buggy HW ... */
1014 fix_zero_bug_scc(info
);
1019 write_zsreg(info
->zs_channel
, 9,
1020 (info
->zs_channel
== info
->zs_chan_a
? CHRA
: CHRB
));
1022 write_zsreg(info
->zs_channel
, 9, 0);
1025 * Clear the receive FIFO.
1027 ZS_CLEARFIFO(info
->zs_channel
);
1028 info
->xmit_fifo_size
= 1;
1037 * Clear the interrupt registers.
1039 write_zsreg(info
->zs_channel
, 0, ERR_RES
);
1040 write_zsreg(info
->zs_channel
, 0, RES_H_IUS
);
1043 * Turn on RTS and DTR.
1049 * Finally, enable sequencing and interrupts
1051 if (!info
->dma_initted
) {
1052 /* interrupt on ext/status changes, all received chars,
1054 info
->curregs
[1] = (info
->curregs
[1] & ~0x18)
1055 | (EXT_INT_ENAB
| INT_ALL_Rx
| TxINT_ENAB
);
1057 /* interrupt on ext/status changes, W/Req pin is
1058 receive DMA request */
1059 info
->curregs
[1] = (info
->curregs
[1] & ~(0x18 | TxINT_ENAB
))
1060 | (EXT_INT_ENAB
| WT_RDY_RT
| WT_FN_RDYFN
);
1061 write_zsreg(info
->zs_channel
, 1, info
->curregs
[1]);
1062 /* enable W/Req pin */
1063 info
->curregs
[1] |= WT_RDY_ENAB
;
1064 write_zsreg(info
->zs_channel
, 1, info
->curregs
[1]);
1065 /* enable interrupts on transmit ready and receive errors */
1066 info
->curregs
[1] |= INT_ERR_Rx
| TxINT_ENAB
;
1068 info
->pendregs
[1] = info
->curregs
[1];
1069 info
->curregs
[3] |= (RxENABLE
| Rx8
);
1070 info
->pendregs
[3] = info
->curregs
[3];
1071 info
->curregs
[5] |= (TxENAB
| Tx8
);
1072 info
->pendregs
[5] = info
->curregs
[5];
1073 info
->curregs
[9] |= (NV
| MIE
);
1074 info
->pendregs
[9] = info
->curregs
[9];
1075 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
1076 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1077 write_zsreg(info
->zs_channel
, 9, info
->curregs
[9]);
1080 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1081 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1083 spin_unlock_irqrestore(&info
->lock
, flags
);
1086 * Set the speed of the serial port
1088 change_speed(info
, 0);
1090 /* Save the current value of RR0 */
1091 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
1093 if (info
->dma_initted
) {
1094 spin_lock_irqsave(&info
->rx_dma_lock
, flags
);
1095 rxdma_start(info
, 0);
1096 info
->poll_dma_timer
.expires
= RX_DMA_TIMER
;
1097 add_timer(&info
->poll_dma_timer
);
1098 spin_unlock_irqrestore(&info
->rx_dma_lock
, flags
);
1105 * This routine will shutdown a serial port; interrupts are disabled, and
1106 * DTR is dropped if the hangup on close termio flag is on.
1108 static void shutdown(struct mac_serial
* info
)
1110 OPNDBG("Shutting down serial port %d (irq %d)....\n", info
->line
,
1113 if (!(info
->flags
& ZILOG_INITIALIZED
)) {
1114 OPNDBG("(already shutdown)\n");
1118 if (info
->has_dma
) {
1119 del_timer(&info
->poll_dma_timer
);
1120 dbdma_reset(info
->tx_dma
);
1121 dbdma_reset(&info
->rx
->dma
);
1122 disable_irq(info
->tx_dma_irq
);
1123 disable_irq(info
->rx_dma_irq
);
1125 disable_irq(info
->irq
);
1127 info
->pendregs
[1] = info
->curregs
[1] = 0;
1128 write_zsreg(info
->zs_channel
, 1, 0); /* no interrupts */
1130 info
->curregs
[3] &= ~RxENABLE
;
1131 info
->pendregs
[3] = info
->curregs
[3];
1132 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
1134 info
->curregs
[5] &= ~TxENAB
;
1135 if (!info
->tty
|| C_HUPCL(info
->tty
))
1136 info
->curregs
[5] &= ~DTR
;
1137 info
->pendregs
[5] = info
->curregs
[5];
1138 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1141 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1143 set_scc_power(info
, 0);
1145 if (info
->xmit_buf
) {
1146 free_page((unsigned long) info
->xmit_buf
);
1150 if (info
->has_dma
&& info
->dma_priv
) {
1151 kfree(info
->dma_priv
);
1152 info
->dma_priv
= NULL
;
1153 info
->dma_initted
= 0;
1156 memset(info
->curregs
, 0, sizeof(info
->curregs
));
1157 memset(info
->pendregs
, 0, sizeof(info
->pendregs
));
1159 info
->flags
&= ~ZILOG_INITIALIZED
;
1163 * Turn power on or off to the SCC and associated stuff
1164 * (port drivers, modem, IR port, etc.)
1165 * Returns the number of milliseconds we should wait before
1166 * trying to use the port.
1168 static int set_scc_power(struct mac_serial
* info
, int state
)
1173 PWRDBG("ttyS%d: powering up hardware\n", info
->line
);
1175 PMAC_FTR_SCC_ENABLE
,
1176 info
->dev_node
, info
->port_type
, 1);
1177 if (info
->is_internal_modem
) {
1179 PMAC_FTR_MODEM_ENABLE
,
1180 info
->dev_node
, 0, 1);
1181 delay
= 2500; /* wait for 2.5s before using */
1182 } else if (info
->is_irda
)
1183 mdelay(50); /* Do better here once the problems
1184 * with blocking have been ironed out
1187 /* TODO: Make that depend on a timer, don't power down
1190 PWRDBG("ttyS%d: shutting down hardware\n", info
->line
);
1191 if (info
->is_internal_modem
) {
1192 PWRDBG("ttyS%d: shutting down modem\n", info
->line
);
1194 PMAC_FTR_MODEM_ENABLE
,
1195 info
->dev_node
, 0, 0);
1198 PMAC_FTR_SCC_ENABLE
,
1199 info
->dev_node
, info
->port_type
, 0);
1204 static void irda_rts_pulses(struct mac_serial
*info
, int w
)
1207 write_zsreg(info
->zs_channel
, 5, Tx8
| TxENAB
);
1209 write_zsreg(info
->zs_channel
, 5, Tx8
| TxENAB
| RTS
);
1211 write_zsreg(info
->zs_channel
, 5, Tx8
| TxENAB
);
1213 write_zsreg(info
->zs_channel
, 5, Tx8
| TxENAB
| RTS
);
1217 * Set the irda codec on the imac to the specified baud rate.
1219 static void irda_setup(struct mac_serial
*info
)
1223 speed
= info
->tty
->termios
->c_cflag
& CBAUD
;
1224 if (speed
< B2400
|| speed
> B115200
)
1226 code
= 0x4d + B115200
- speed
;
1228 /* disable serial interrupts and receive DMA */
1229 write_zsreg(info
->zs_channel
, 1, info
->curregs
[1] & ~0x9f);
1231 /* wait for transmitter to drain */
1233 while ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
) == 0
1234 || (read_zsreg(info
->zs_channel
, 1) & ALL_SNT
) == 0) {
1236 printk(KERN_ERR
"transmitter didn't drain\n");
1243 /* set to 8 bits, no parity, 19200 baud, RTS on, DTR off */
1244 write_zsreg(info
->zs_channel
, 4, X16CLK
| SB1
);
1245 write_zsreg(info
->zs_channel
, 11, TCBR
| RCBR
);
1246 t
= BPS_TO_BRG(19200, ZS_CLOCK
/16);
1247 write_zsreg(info
->zs_channel
, 12, t
);
1248 write_zsreg(info
->zs_channel
, 13, t
>> 8);
1249 write_zsreg(info
->zs_channel
, 14, BRENABL
);
1250 write_zsreg(info
->zs_channel
, 3, Rx8
| RxENABLE
);
1251 write_zsreg(info
->zs_channel
, 5, Tx8
| TxENAB
| RTS
);
1253 /* set TxD low for ~104us and pulse RTS */
1255 write_zsdata(info
->zs_channel
, 0xfe);
1256 irda_rts_pulses(info
, 150);
1257 irda_rts_pulses(info
, 180);
1258 irda_rts_pulses(info
, 50);
1261 /* assert DTR, wait 30ms, talk to the chip */
1262 write_zsreg(info
->zs_channel
, 5, Tx8
| TxENAB
| RTS
| DTR
);
1264 while (read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
)
1265 read_zsdata(info
->zs_channel
);
1267 write_zsdata(info
->zs_channel
, 1);
1269 while ((read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
) == 0) {
1271 printk(KERN_ERR
"irda_setup timed out on 1st byte\n");
1276 t
= read_zsdata(info
->zs_channel
);
1278 printk(KERN_ERR
"irda_setup 1st byte = %x\n", t
);
1280 write_zsdata(info
->zs_channel
, code
);
1282 while ((read_zsreg(info
->zs_channel
, 0) & Rx_CH_AV
) == 0) {
1284 printk(KERN_ERR
"irda_setup timed out on 2nd byte\n");
1289 t
= read_zsdata(info
->zs_channel
);
1291 printk(KERN_ERR
"irda_setup 2nd byte = %x (%x)\n", t
, code
);
1293 /* Drop DTR again and do some more RTS pulses */
1296 write_zsreg(info
->zs_channel
, 5, Tx8
| TxENAB
| RTS
);
1297 irda_rts_pulses(info
, 80);
1299 /* We should be right to go now. We assume that load_zsregs
1300 will get called soon to load up the correct baud rate etc. */
1301 info
->curregs
[5] = (info
->curregs
[5] | RTS
) & ~DTR
;
1302 info
->pendregs
[5] = info
->curregs
[5];
1306 * This routine is called to set the UART divisor registers to match
1307 * the specified baud rate for a serial port.
1309 static void change_speed(struct mac_serial
*info
, struct termios
*old_termios
)
1314 unsigned long flags
;
1316 if (!info
->tty
|| !info
->tty
->termios
)
1319 cflag
= info
->tty
->termios
->c_cflag
;
1320 baud
= tty_get_baud_rate(info
->tty
);
1323 info
->tty
->termios
->c_cflag
&= ~CBAUD
;
1324 info
->tty
->termios
->c_cflag
|= (old_termios
->c_cflag
& CBAUD
);
1325 cflag
= info
->tty
->termios
->c_cflag
;
1326 baud
= tty_get_baud_rate(info
->tty
);
1329 baud
= info
->zs_baud
;
1336 spin_lock_irqsave(&info
->lock
, flags
);
1337 info
->zs_baud
= baud
;
1338 info
->clk_divisor
= 16;
1340 BAUDBG(KERN_DEBUG
"set speed to %d bds, ", baud
);
1343 case ZS_CLOCK
/16: /* 230400 */
1344 info
->curregs
[4] = X16CLK
;
1345 info
->curregs
[11] = 0;
1347 case ZS_CLOCK
/32: /* 115200 */
1348 info
->curregs
[4] = X32CLK
;
1349 info
->curregs
[11] = 0;
1352 info
->curregs
[4] = X16CLK
;
1353 info
->curregs
[11] = TCBR
| RCBR
;
1354 brg
= BPS_TO_BRG(baud
, ZS_CLOCK
/info
->clk_divisor
);
1355 info
->curregs
[12] = (brg
& 255);
1356 info
->curregs
[13] = ((brg
>> 8) & 255);
1357 info
->curregs
[14] = BRENABL
;
1360 /* byte size and parity */
1361 info
->curregs
[3] &= ~RxNBITS_MASK
;
1362 info
->curregs
[5] &= ~TxNBITS_MASK
;
1363 switch (cflag
& CSIZE
) {
1365 info
->curregs
[3] |= Rx5
;
1366 info
->curregs
[5] |= Tx5
;
1371 info
->curregs
[3] |= Rx6
;
1372 info
->curregs
[5] |= Tx6
;
1377 info
->curregs
[3] |= Rx7
;
1378 info
->curregs
[5] |= Tx7
;
1383 default: /* defaults to 8 bits */
1384 info
->curregs
[3] |= Rx8
;
1385 info
->curregs
[5] |= Tx8
;
1390 info
->pendregs
[3] = info
->curregs
[3];
1391 info
->pendregs
[5] = info
->curregs
[5];
1393 info
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
1394 if (cflag
& CSTOPB
) {
1395 info
->curregs
[4] |= SB2
;
1399 info
->curregs
[4] |= SB1
;
1402 if (cflag
& PARENB
) {
1404 info
->curregs
[4] |= PAR_ENA
;
1407 if (!(cflag
& PARODD
)) {
1408 info
->curregs
[4] |= PAR_EVEN
;
1410 info
->pendregs
[4] = info
->curregs
[4];
1412 if (!(cflag
& CLOCAL
)) {
1413 if (!(info
->curregs
[15] & DCDIE
))
1414 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
1415 info
->curregs
[15] |= DCDIE
;
1417 info
->curregs
[15] &= ~DCDIE
;
1418 if (cflag
& CRTSCTS
) {
1419 info
->curregs
[15] |= CTSIE
;
1420 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) != 0)
1421 info
->tx_stopped
= 1;
1423 info
->curregs
[15] &= ~CTSIE
;
1424 info
->tx_stopped
= 0;
1426 info
->pendregs
[15] = info
->curregs
[15];
1428 /* Calc timeout value. This is pretty broken with high baud rates with HZ=100.
1429 This code would love a larger HZ and a >1 fifo size, but this is not
1430 a priority. The resulting value must be >HZ/2
1432 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
) / baud
);
1433 info
->timeout
+= HZ
/50+1; /* Add .02 seconds of slop */
1435 BAUDBG("timeout=%d/%ds, base:%d\n", (int)info
->timeout
, (int)HZ
,
1436 (int)info
->baud_base
);
1438 /* set the irda codec to the right rate */
1442 /* Load up the new values */
1443 load_zsregs(info
->zs_channel
, info
->curregs
);
1445 spin_unlock_irqrestore(&info
->lock
, flags
);
1448 static void rs_flush_chars(struct tty_struct
*tty
)
1450 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1451 unsigned long flags
;
1453 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_chars"))
1456 spin_lock_irqsave(&info
->lock
, flags
);
1457 if (!(info
->xmit_cnt
<= 0 || tty
->stopped
|| info
->tx_stopped
||
1459 /* Enable transmitter */
1460 transmit_chars(info
);
1461 spin_unlock_irqrestore(&info
->lock
, flags
);
1464 static int rs_write(struct tty_struct
* tty
,
1465 const unsigned char *buf
, int count
)
1468 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1469 unsigned long flags
;
1471 if (serial_paranoia_check(info
, tty
->name
, "rs_write"))
1474 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
)
1478 spin_lock_irqsave(&info
->lock
, flags
);
1479 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1480 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1482 spin_unlock_irqrestore(&info
->lock
, flags
);
1485 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1486 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1487 (SERIAL_XMIT_SIZE
-1));
1488 info
->xmit_cnt
+= c
;
1489 spin_unlock_irqrestore(&info
->lock
, flags
);
1494 spin_lock_irqsave(&info
->lock
, flags
);
1495 if (info
->xmit_cnt
&& !tty
->stopped
&& !info
->tx_stopped
1496 && !info
->tx_active
)
1497 transmit_chars(info
);
1498 spin_unlock_irqrestore(&info
->lock
, flags
);
1502 static int rs_write_room(struct tty_struct
*tty
)
1504 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1507 if (serial_paranoia_check(info
, tty
->name
, "rs_write_room"))
1509 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1515 static int rs_chars_in_buffer(struct tty_struct
*tty
)
1517 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1519 if (serial_paranoia_check(info
, tty
->name
, "rs_chars_in_buffer"))
1521 return info
->xmit_cnt
;
1524 static void rs_flush_buffer(struct tty_struct
*tty
)
1526 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1527 unsigned long flags
;
1529 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_buffer"))
1531 spin_lock_irqsave(&info
->lock
, flags
);
1532 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1533 spin_unlock_irqrestore(&info
->lock
, flags
);
1538 * ------------------------------------------------------------
1541 * This routine is called by the upper-layer tty layer to signal that
1542 * incoming characters should be throttled.
1543 * ------------------------------------------------------------
1545 static void rs_throttle(struct tty_struct
* tty
)
1547 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1548 unsigned long flags
;
1549 #ifdef SERIAL_DEBUG_THROTTLE
1550 printk(KERN_DEBUG
"throttle %ld....\n",tty
->ldisc
.chars_in_buffer(tty
));
1553 if (serial_paranoia_check(info
, tty
->name
, "rs_throttle"))
1557 spin_lock_irqsave(&info
->lock
, flags
);
1558 info
->x_char
= STOP_CHAR(tty
);
1559 if (!info
->tx_active
)
1560 transmit_chars(info
);
1561 spin_unlock_irqrestore(&info
->lock
, flags
);
1564 if (C_CRTSCTS(tty
)) {
1566 * Here we want to turn off the RTS line. On Macintoshes,
1567 * the external serial ports using a DIN-8 or DIN-9
1568 * connector only have the DTR line (which is usually
1569 * wired to both RTS and DTR on an external modem in
1570 * the cable). RTS doesn't go out to the serial port
1571 * socket, it acts as an output enable for the transmit
1572 * data line. So in this case we don't drop RTS.
1574 * Macs with internal modems generally do have both RTS
1575 * and DTR wired to the modem, so in that case we do
1578 if (info
->is_internal_modem
) {
1579 spin_lock_irqsave(&info
->lock
, flags
);
1580 info
->curregs
[5] &= ~RTS
;
1581 info
->pendregs
[5] &= ~RTS
;
1582 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1583 spin_unlock_irqrestore(&info
->lock
, flags
);
1588 if (tty
->termios
->c_cflag
& CDTRCTS
) {
1589 spin_lock_irqsave(&info
->lock
, flags
);
1590 info
->curregs
[5] &= ~DTR
;
1591 info
->pendregs
[5] &= ~DTR
;
1592 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1593 spin_unlock_irqrestore(&info
->lock
, flags
);
1595 #endif /* CDTRCTS */
1598 static void rs_unthrottle(struct tty_struct
* tty
)
1600 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1601 unsigned long flags
;
1602 #ifdef SERIAL_DEBUG_THROTTLE
1603 printk(KERN_DEBUG
"unthrottle %s: %d....\n",
1604 tty
->ldisc
.chars_in_buffer(tty
));
1607 if (serial_paranoia_check(info
, tty
->name
, "rs_unthrottle"))
1611 spin_lock_irqsave(&info
->lock
, flags
);
1615 info
->x_char
= START_CHAR(tty
);
1616 if (!info
->tx_active
)
1617 transmit_chars(info
);
1619 spin_unlock_irqrestore(&info
->lock
, flags
);
1622 if (C_CRTSCTS(tty
) && info
->is_internal_modem
) {
1623 /* Assert RTS line */
1624 spin_lock_irqsave(&info
->lock
, flags
);
1625 info
->curregs
[5] |= RTS
;
1626 info
->pendregs
[5] |= RTS
;
1627 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1628 spin_unlock_irqrestore(&info
->lock
, flags
);
1632 if (tty
->termios
->c_cflag
& CDTRCTS
) {
1633 /* Assert DTR line */
1634 spin_lock_irqsave(&info
->lock
, flags
);
1635 info
->curregs
[5] |= DTR
;
1636 info
->pendregs
[5] |= DTR
;
1637 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1638 spin_unlock_irqrestore(&info
->lock
, flags
);
1644 * ------------------------------------------------------------
1645 * rs_ioctl() and friends
1646 * ------------------------------------------------------------
1649 static int get_serial_info(struct mac_serial
* info
,
1650 struct serial_struct __user
* retinfo
)
1652 struct serial_struct tmp
;
1656 memset(&tmp
, 0, sizeof(tmp
));
1657 tmp
.type
= info
->type
;
1658 tmp
.line
= info
->line
;
1659 tmp
.port
= info
->port
;
1660 tmp
.irq
= info
->irq
;
1661 tmp
.flags
= info
->flags
;
1662 tmp
.baud_base
= info
->baud_base
;
1663 tmp
.close_delay
= info
->close_delay
;
1664 tmp
.closing_wait
= info
->closing_wait
;
1665 tmp
.custom_divisor
= info
->custom_divisor
;
1666 if (copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)))
1671 static int set_serial_info(struct mac_serial
* info
,
1672 struct serial_struct __user
* new_info
)
1674 struct serial_struct new_serial
;
1675 struct mac_serial old_info
;
1678 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
1682 if (!capable(CAP_SYS_ADMIN
)) {
1683 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1684 (new_serial
.type
!= info
->type
) ||
1685 (new_serial
.close_delay
!= info
->close_delay
) ||
1686 ((new_serial
.flags
& ~ZILOG_USR_MASK
) !=
1687 (info
->flags
& ~ZILOG_USR_MASK
)))
1689 info
->flags
= ((info
->flags
& ~ZILOG_USR_MASK
) |
1690 (new_serial
.flags
& ZILOG_USR_MASK
));
1691 info
->custom_divisor
= new_serial
.custom_divisor
;
1692 goto check_and_exit
;
1695 if (info
->count
> 1)
1699 * OK, past this point, all the error checking has been done.
1700 * At this point, we start making changes.....
1703 info
->baud_base
= new_serial
.baud_base
;
1704 info
->flags
= ((info
->flags
& ~ZILOG_FLAGS
) |
1705 (new_serial
.flags
& ZILOG_FLAGS
));
1706 info
->type
= new_serial
.type
;
1707 info
->close_delay
= new_serial
.close_delay
;
1708 info
->closing_wait
= new_serial
.closing_wait
;
1711 if (info
->flags
& ZILOG_INITIALIZED
)
1712 retval
= setup_scc(info
);
1717 * get_lsr_info - get line status register info
1719 * Purpose: Let user call ioctl() to get info when the UART physically
1720 * is emptied. On bus types like RS485, the transmitter must
1721 * release the bus after transmitting. This must be done when
1722 * the transmit shift register is empty, not be done when the
1723 * transmit holding register is empty. This functionality
1724 * allows an RS485 driver to be written in user space.
1726 static int get_lsr_info(struct mac_serial
* info
, unsigned int *value
)
1728 unsigned char status
;
1729 unsigned long flags
;
1731 spin_lock_irqsave(&info
->lock
, flags
);
1732 status
= read_zsreg(info
->zs_channel
, 0);
1733 spin_unlock_irqrestore(&info
->lock
, flags
);
1734 status
= (status
& Tx_BUF_EMP
)? TIOCSER_TEMT
: 0;
1735 return put_user(status
,value
);
1738 static int rs_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1740 struct mac_serial
* info
= (struct mac_serial
*)tty
->driver_data
;
1741 unsigned char control
, status
;
1742 unsigned long flags
;
1745 if (info
->kgdb_channel
)
1748 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1751 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1754 spin_lock_irqsave(&info
->lock
, flags
);
1755 control
= info
->curregs
[5];
1756 status
= read_zsreg(info
->zs_channel
, 0);
1757 spin_unlock_irqrestore(&info
->lock
, flags
);
1758 return ((control
& RTS
) ? TIOCM_RTS
: 0)
1759 | ((control
& DTR
) ? TIOCM_DTR
: 0)
1760 | ((status
& DCD
) ? TIOCM_CAR
: 0)
1761 | ((status
& CTS
) ? 0: TIOCM_CTS
);
1764 static int rs_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1765 unsigned int set
, unsigned int clear
)
1767 struct mac_serial
* info
= (struct mac_serial
*)tty
->driver_data
;
1768 unsigned int arg
, bits
;
1769 unsigned long flags
;
1772 if (info
->kgdb_channel
)
1775 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1778 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1781 spin_lock_irqsave(&info
->lock
, flags
);
1782 if (set
& TIOCM_RTS
)
1783 info
->curregs
[5] |= RTS
;
1784 if (set
& TIOCM_DTR
)
1785 info
->curregs
[5] |= DTR
;
1786 if (clear
& TIOCM_RTS
)
1787 info
->curregs
[5] &= ~RTS
;
1788 if (clear
& TIOCM_DTR
)
1789 info
->curregs
[5] &= ~DTR
;
1791 info
->pendregs
[5] = info
->curregs
[5];
1792 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1793 spin_unlock_irqrestore(&info
->lock
, flags
);
1798 * rs_break - turn transmit break condition on/off
1800 static void rs_break(struct tty_struct
*tty
, int break_state
)
1802 struct mac_serial
*info
= (struct mac_serial
*) tty
->driver_data
;
1803 unsigned long flags
;
1805 if (serial_paranoia_check(info
, tty
->name
, "rs_break"))
1808 spin_lock_irqsave(&info
->lock
, flags
);
1809 if (break_state
== -1)
1810 info
->curregs
[5] |= SND_BRK
;
1812 info
->curregs
[5] &= ~SND_BRK
;
1813 write_zsreg(info
->zs_channel
, 5, info
->curregs
[5]);
1814 spin_unlock_irqrestore(&info
->lock
, flags
);
1817 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1818 unsigned int cmd
, unsigned long arg
)
1820 struct mac_serial
* info
= (struct mac_serial
*)tty
->driver_data
;
1823 if (info
->kgdb_channel
)
1826 if (serial_paranoia_check(info
, tty
->name
, "rs_ioctl"))
1829 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1830 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGSTRUCT
)) {
1831 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1837 return get_serial_info(info
,
1838 (struct serial_struct __user
*) arg
);
1840 return set_serial_info(info
,
1841 (struct serial_struct __user
*) arg
);
1842 case TIOCSERGETLSR
: /* Get line status register */
1843 return get_lsr_info(info
, (unsigned int *) arg
);
1845 case TIOCSERGSTRUCT
:
1846 if (copy_to_user((struct mac_serial __user
*) arg
,
1847 info
, sizeof(struct mac_serial
)))
1852 return -ENOIOCTLCMD
;
1857 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1859 struct mac_serial
*info
= (struct mac_serial
*)tty
->driver_data
;
1862 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1864 was_stopped
= info
->tx_stopped
;
1866 change_speed(info
, old_termios
);
1868 if (was_stopped
&& !info
->tx_stopped
) {
1869 tty
->hw_stopped
= 0;
1875 * ------------------------------------------------------------
1878 * This routine is called when the serial port gets closed.
1879 * Wait for the last remaining data to be sent.
1880 * ------------------------------------------------------------
1882 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
1884 struct mac_serial
* info
= (struct mac_serial
*)tty
->driver_data
;
1885 unsigned long flags
;
1887 if (!info
|| serial_paranoia_check(info
, tty
->name
, "rs_close"))
1890 spin_lock_irqsave(&info
->lock
, flags
);
1892 if (tty_hung_up_p(filp
)) {
1893 spin_unlock_irqrestore(&info
->lock
, flags
);
1897 OPNDBG("rs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1898 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1900 * Uh, oh. tty->count is 1, which means that the tty
1901 * structure will be freed. Info->count should always
1902 * be one in these conditions. If it's greater than
1903 * one, we've got real problems, since it means the
1904 * serial port won't be shutdown.
1906 printk(KERN_ERR
"rs_close: bad serial port count; tty->count "
1907 "is 1, info->count is %d\n", info
->count
);
1910 if (--info
->count
< 0) {
1911 printk(KERN_ERR
"rs_close: bad serial port count for "
1912 "ttyS%d: %d\n", info
->line
, info
->count
);
1916 spin_unlock_irqrestore(&info
->lock
, flags
);
1919 info
->flags
|= ZILOG_CLOSING
;
1921 * Now we wait for the transmit buffer to clear; and we notify
1922 * the line discipline to only process XON/XOFF characters.
1924 OPNDBG("waiting end of Tx... (timeout:%d)\n", info
->closing_wait
);
1926 if (info
->closing_wait
!= ZILOG_CLOSING_WAIT_NONE
) {
1927 spin_unlock_irqrestore(&info
->lock
, flags
);
1928 tty_wait_until_sent(tty
, info
->closing_wait
);
1929 spin_lock_irqsave(&info
->lock
, flags
);
1933 * At this point we stop accepting input. To do this, we
1934 * disable the receiver and receive interrupts.
1936 info
->curregs
[3] &= ~RxENABLE
;
1937 info
->pendregs
[3] = info
->curregs
[3];
1938 write_zsreg(info
->zs_channel
, 3, info
->curregs
[3]);
1939 info
->curregs
[1] &= ~(0x18); /* disable any rx ints */
1940 info
->pendregs
[1] = info
->curregs
[1];
1941 write_zsreg(info
->zs_channel
, 1, info
->curregs
[1]);
1942 ZS_CLEARFIFO(info
->zs_channel
);
1943 if (info
->flags
& ZILOG_INITIALIZED
) {
1945 * Before we drop DTR, make sure the SCC transmitter
1946 * has completely drained.
1948 OPNDBG("waiting end of Rx...\n");
1949 spin_unlock_irqrestore(&info
->lock
, flags
);
1950 rs_wait_until_sent(tty
, info
->timeout
);
1951 spin_lock_irqsave(&info
->lock
, flags
);
1955 /* restore flags now since shutdown() will have disabled this port's
1957 spin_unlock_irqrestore(&info
->lock
, flags
);
1959 if (tty
->driver
->flush_buffer
)
1960 tty
->driver
->flush_buffer(tty
);
1961 tty_ldisc_flush(tty
);
1966 if (info
->blocked_open
) {
1967 if (info
->close_delay
) {
1968 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
1970 wake_up_interruptible(&info
->open_wait
);
1972 info
->flags
&= ~(ZILOG_NORMAL_ACTIVE
|ZILOG_CLOSING
);
1973 wake_up_interruptible(&info
->close_wait
);
1977 * rs_wait_until_sent() --- wait until the transmitter is empty
1979 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1981 struct mac_serial
*info
= (struct mac_serial
*) tty
->driver_data
;
1982 unsigned long orig_jiffies
, char_time
;
1984 if (serial_paranoia_check(info
, tty
->name
, "rs_wait_until_sent"))
1987 /* printk("rs_wait_until_sent, timeout:%d, tty_stopped:%d, tx_stopped:%d\n",
1988 timeout, tty->stopped, info->tx_stopped);
1990 orig_jiffies
= jiffies
;
1992 * Set the check interval to be 1/5 of the estimated time to
1993 * send a single character, and make it at least 1. The check
1994 * interval should also be less than the timeout.
1996 if (info
->timeout
<= HZ
/50) {
1997 printk(KERN_INFO
"macserial: invalid info->timeout=%d\n",
1999 info
->timeout
= HZ
/50+1;
2002 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
2003 char_time
= char_time
/ 5;
2004 if (char_time
> HZ
) {
2005 printk(KERN_WARNING
"macserial: char_time %ld >HZ !!!\n",
2008 } else if (char_time
== 0)
2011 char_time
= min_t(unsigned long, char_time
, timeout
);
2012 while ((read_zsreg(info
->zs_channel
, 1) & ALL_SNT
) == 0) {
2013 msleep_interruptible(jiffies_to_msecs(char_time
));
2014 if (signal_pending(current
))
2016 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2019 current
->state
= TASK_RUNNING
;
2023 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
2025 static void rs_hangup(struct tty_struct
*tty
)
2027 struct mac_serial
* info
= (struct mac_serial
*)tty
->driver_data
;
2029 if (serial_paranoia_check(info
, tty
->name
, "rs_hangup"))
2032 rs_flush_buffer(tty
);
2036 info
->flags
&= ~ZILOG_NORMAL_ACTIVE
;
2038 wake_up_interruptible(&info
->open_wait
);
2042 * ------------------------------------------------------------
2043 * rs_open() and friends
2044 * ------------------------------------------------------------
2046 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
2047 struct mac_serial
*info
)
2049 DECLARE_WAITQUEUE(wait
,current
);
2054 * If the device is in the middle of being closed, then block
2055 * until it's done, and then try again.
2057 if (info
->flags
& ZILOG_CLOSING
) {
2058 interruptible_sleep_on(&info
->close_wait
);
2063 * If non-blocking mode is set, or the port is not enabled,
2064 * then make the check up front and then exit.
2066 if ((filp
->f_flags
& O_NONBLOCK
) ||
2067 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2068 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
2072 if (tty
->termios
->c_cflag
& CLOCAL
)
2076 * Block waiting for the carrier detect and the line to become
2077 * free (i.e., not in use by the callout). While we are in
2078 * this loop, info->count is dropped by one, so that
2079 * rs_close() knows when to free things. We restore it upon
2080 * exit, either normal or abnormal.
2083 add_wait_queue(&info
->open_wait
, &wait
);
2084 OPNDBG("block_til_ready before block: ttyS%d, count = %d\n",
2085 info
->line
, info
->count
);
2086 spin_lock_irq(&info
->lock
);
2087 if (!tty_hung_up_p(filp
))
2089 spin_unlock_irq(&info
->lock
);
2090 info
->blocked_open
++;
2092 spin_lock_irq(&info
->lock
);
2093 if ((tty
->termios
->c_cflag
& CBAUD
) &&
2096 spin_unlock_irq(&info
->lock
);
2097 set_current_state(TASK_INTERRUPTIBLE
);
2098 if (tty_hung_up_p(filp
) ||
2099 !(info
->flags
& ZILOG_INITIALIZED
)) {
2103 if (!(info
->flags
& ZILOG_CLOSING
) &&
2104 (do_clocal
|| (read_zsreg(info
->zs_channel
, 0) & DCD
)))
2106 if (signal_pending(current
)) {
2107 retval
= -ERESTARTSYS
;
2110 OPNDBG("block_til_ready blocking: ttyS%d, count = %d\n",
2111 info
->line
, info
->count
);
2114 current
->state
= TASK_RUNNING
;
2115 remove_wait_queue(&info
->open_wait
, &wait
);
2116 if (!tty_hung_up_p(filp
))
2118 info
->blocked_open
--;
2119 OPNDBG("block_til_ready after blocking: ttyS%d, count = %d\n",
2120 info
->line
, info
->count
);
2123 info
->flags
|= ZILOG_NORMAL_ACTIVE
;
2128 * This routine is called whenever a serial port is opened. It
2129 * enables interrupts for a serial port, linking in its ZILOG structure into
2130 * the IRQ chain. It also performs the serial-specific
2131 * initialization for the tty structure.
2133 static int rs_open(struct tty_struct
*tty
, struct file
* filp
)
2135 struct mac_serial
*info
;
2140 if ((line
< 0) || (line
>= zs_channels_found
)) {
2143 info
= zs_soft
+ line
;
2146 if (info
->kgdb_channel
) {
2150 if (serial_paranoia_check(info
, tty
->name
, "rs_open"))
2152 OPNDBG("rs_open %s, count = %d, tty=%p\n", tty
->name
,
2156 tty
->driver_data
= info
;
2160 page
= get_zeroed_page(GFP_KERNEL
);
2166 tmp_buf
= (unsigned char *) page
;
2170 * If the port is the middle of closing, bail out now
2172 if (tty_hung_up_p(filp
) ||
2173 (info
->flags
& ZILOG_CLOSING
)) {
2174 if (info
->flags
& ZILOG_CLOSING
)
2175 interruptible_sleep_on(&info
->close_wait
);
2180 * Start up serial port
2183 retval
= startup(info
);
2187 retval
= block_til_ready(tty
, filp
, info
);
2189 OPNDBG("rs_open returning after block_til_ready with %d\n",
2194 #ifdef CONFIG_SERIAL_CONSOLE
2195 if (sercons
.cflag
&& sercons
.index
== line
) {
2196 tty
->termios
->c_cflag
= sercons
.cflag
;
2198 change_speed(info
, 0);
2202 OPNDBG("rs_open %s successful...\n", tty
->name
);
2206 /* Finally, routines used to initialize the serial driver. */
2208 static void show_serial_version(void)
2210 printk(KERN_INFO
"PowerMac Z8530 serial driver version " MACSERIAL_VERSION
"\n");
2214 * Initialize one channel, both the mac_serial and mac_zschannel
2215 * structs. We use the dev_node field of the mac_serial struct.
2218 chan_init(struct mac_serial
*zss
, struct mac_zschannel
*zs_chan
,
2219 struct mac_zschannel
*zs_chan_a
)
2221 struct device_node
*ch
= zss
->dev_node
;
2224 struct slot_names_prop
{
2229 zss
->irq
= ch
->intrs
[0].line
;
2231 #if !defined(CONFIG_KGDB) && defined(SUPPORT_SERIAL_DMA)
2232 if (ch
->n_addrs
>= 3 && ch
->n_intrs
== 3)
2235 zss
->dma_initted
= 0;
2237 zs_chan
->control
= (volatile unsigned char *)
2238 ioremap(ch
->addrs
[0].address
, 0x1000);
2239 zs_chan
->data
= zs_chan
->control
+ 0x10;
2240 spin_lock_init(&zs_chan
->lock
);
2241 zs_chan
->parent
= zss
;
2242 zss
->zs_channel
= zs_chan
;
2243 zss
->zs_chan_a
= zs_chan_a
;
2245 /* setup misc varariables */
2246 zss
->kgdb_channel
= 0;
2248 /* For now, we assume you either have a slot-names property
2249 * with "Modem" in it, or your channel is compatible with
2250 * "cobalt". Might need additional fixups
2252 zss
->is_internal_modem
= device_is_compatible(ch
, "cobalt");
2253 conn
= get_property(ch
, "AAPL,connector", &len
);
2254 zss
->is_irda
= conn
&& (strcmp(conn
, "infrared") == 0);
2255 zss
->port_type
= PMAC_SCC_ASYNC
;
2256 /* 1999 Powerbook G3 has slot-names property instead */
2257 slots
= (struct slot_names_prop
*)get_property(ch
, "slot-names", &len
);
2258 if (slots
&& slots
->count
> 0) {
2259 if (strcmp(slots
->name
, "IrDA") == 0)
2261 else if (strcmp(slots
->name
, "Modem") == 0)
2262 zss
->is_internal_modem
= 1;
2265 zss
->port_type
= PMAC_SCC_IRDA
;
2266 if (zss
->is_internal_modem
) {
2267 struct device_node
* i2c_modem
= find_devices("i2c-modem");
2269 char* mid
= get_property(i2c_modem
, "modem-id", NULL
);
2270 if (mid
) switch(*mid
) {
2277 zss
->port_type
= PMAC_SCC_I2S1
;
2279 printk(KERN_INFO
"macserial: i2c-modem detected, id: %d\n",
2282 printk(KERN_INFO
"macserial: serial modem detected\n");
2286 while (zss
->has_dma
) {
2287 zss
->dma_priv
= NULL
;
2288 /* it seems that the last two addresses are the
2290 zss
->tx_dma
= (volatile struct dbdma_regs
*)
2291 ioremap(ch
->addrs
[ch
->n_addrs
- 2].address
, 0x100);
2292 zss
->rx
= (volatile struct mac_dma
*)
2293 ioremap(ch
->addrs
[ch
->n_addrs
- 1].address
, 0x100);
2294 zss
->tx_dma_irq
= ch
->intrs
[1].line
;
2295 zss
->rx_dma_irq
= ch
->intrs
[2].line
;
2296 spin_lock_init(&zss
->rx_dma_lock
);
2300 init_timer(&zss
->powerup_timer
);
2301 zss
->powerup_timer
.function
= powerup_done
;
2302 zss
->powerup_timer
.data
= (unsigned long) zss
;
2307 * /proc fs routines. TODO: Add status lines & error stats
2310 line_info(char *buf
, struct mac_serial
*info
)
2313 unsigned char* connector
;
2316 ret
+= sprintf(buf
, "%d: port:0x%X irq:%d", info
->line
, info
->port
, info
->irq
);
2318 connector
= get_property(info
->dev_node
, "AAPL,connector", &lenp
);
2320 ret
+=sprintf(buf
+ret
," con:%s ", connector
);
2321 if (info
->is_internal_modem
) {
2323 ret
+=sprintf(buf
+ret
," con:");
2324 ret
+=sprintf(buf
+ret
,"%s", " (internal modem)");
2326 if (info
->is_irda
) {
2328 ret
+=sprintf(buf
+ret
," con:");
2329 ret
+=sprintf(buf
+ret
,"%s", " (IrDA)");
2331 ret
+=sprintf(buf
+ret
,"\n");
2336 int macserial_read_proc(char *page
, char **start
, off_t off
, int count
,
2337 int *eof
, void *data
)
2341 struct mac_serial
*info
;
2343 len
+= sprintf(page
, "serinfo:1.0 driver:" MACSERIAL_VERSION
"\n");
2344 for (info
= zs_chain
; info
&& len
< 4000; info
= info
->zs_next
) {
2345 l
= line_info(page
+ len
, info
);
2347 if (len
+begin
> off
+count
)
2349 if (len
+begin
< off
) {
2356 if (off
>= len
+begin
)
2358 *start
= page
+ (off
-begin
);
2359 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2362 /* Ask the PROM how many Z8530s we have and initialize their zs_channels */
2366 struct device_node
*dev
, *ch
;
2367 struct mac_serial
**pp
;
2369 struct mac_zschannel
*zs_chan
;
2374 zs_chan
= zs_channels
;
2375 for (dev
= find_devices("escc"); dev
!= 0; dev
= dev
->next
) {
2378 if (n
>= NUM_CHANNELS
) {
2379 printk(KERN_WARNING
"Sorry, can't use %s: no more "
2380 "channels\n", dev
->full_name
);
2384 for (ch
= dev
->child
; ch
!= 0; ch
= ch
->sibling
) {
2386 printk(KERN_WARNING
"SCC: Only 2 channels per "
2387 "chip are supported\n");
2390 if (ch
->n_addrs
< 1 || (ch
->n_intrs
< 1)) {
2391 printk("Can't use %s: %d addrs %d intrs\n",
2392 ch
->full_name
, ch
->n_addrs
, ch
->n_intrs
);
2396 /* The channel with the higher address
2397 will be the A side. */
2399 ch
->addrs
[0].address
2400 > zs_soft
[n
-1].dev_node
->addrs
[0].address
)
2403 /* minimal initialization for now */
2404 zs_soft
[n
].dev_node
= ch
;
2406 pp
= &zs_soft
[n
].zs_next
;
2414 if (chan_init(&zs_soft
[chip
+ chan_a_index
], zs_chan
, zs_chan
))
2418 /* set up B side, if it exists */
2420 if (chan_init(&zs_soft
[chip
+ 1 - chan_a_index
],
2421 zs_chan
, zs_chan
- 1))
2427 zs_channels_found
= n
;
2428 #ifdef CONFIG_PMAC_PBOOK
2430 pmu_register_sleep_notifier(&serial_sleep_notifier
);
2431 #endif /* CONFIG_PMAC_PBOOK */
2434 static struct tty_operations serial_ops
= {
2438 .flush_chars
= rs_flush_chars
,
2439 .write_room
= rs_write_room
,
2440 .chars_in_buffer
= rs_chars_in_buffer
,
2441 .flush_buffer
= rs_flush_buffer
,
2443 .throttle
= rs_throttle
,
2444 .unthrottle
= rs_unthrottle
,
2445 .set_termios
= rs_set_termios
,
2448 .hangup
= rs_hangup
,
2449 .break_ctl
= rs_break
,
2450 .wait_until_sent
= rs_wait_until_sent
,
2451 .read_proc
= macserial_read_proc
,
2452 .tiocmget
= rs_tiocmget
,
2453 .tiocmset
= rs_tiocmset
,
2456 static int macserial_init(void)
2459 struct mac_serial
*info
;
2461 /* Find out how many Z8530 SCCs we have */
2465 serial_driver
= alloc_tty_driver(zs_channels_found
);
2469 /* XXX assume it's a powerbook if we have a via-pmu
2471 * This is OK for core99 machines as well.
2473 is_powerbook
= find_devices("via-pmu") != 0;
2475 /* Register the interrupt handler for each one
2476 * We also request the OF resources here as probe_sccs()
2477 * might be called too early for that
2479 for (i
= 0; i
< zs_channels_found
; ++i
) {
2480 struct device_node
* ch
= zs_soft
[i
].dev_node
;
2481 if (!request_OF_resource(ch
, 0, NULL
)) {
2482 printk(KERN_ERR
"macserial: can't request IO resource !\n");
2483 put_tty_driver(serial_driver
);
2486 if (zs_soft
[i
].has_dma
) {
2487 if (!request_OF_resource(ch
, ch
->n_addrs
- 2, " (tx dma)")) {
2488 printk(KERN_ERR
"macserial: can't request TX DMA resource !\n");
2489 zs_soft
[i
].has_dma
= 0;
2492 if (!request_OF_resource(ch
, ch
->n_addrs
- 1, " (rx dma)")) {
2493 release_OF_resource(ch
, ch
->n_addrs
- 2);
2494 printk(KERN_ERR
"macserial: can't request RX DMA resource !\n");
2495 zs_soft
[i
].has_dma
= 0;
2498 if (request_irq(zs_soft
[i
].tx_dma_irq
, rs_txdma_irq
, 0,
2499 "SCC-txdma", &zs_soft
[i
]))
2500 printk(KERN_ERR
"macserial: can't get irq %d\n",
2501 zs_soft
[i
].tx_dma_irq
);
2502 disable_irq(zs_soft
[i
].tx_dma_irq
);
2503 if (request_irq(zs_soft
[i
].rx_dma_irq
, rs_rxdma_irq
, 0,
2504 "SCC-rxdma", &zs_soft
[i
]))
2505 printk(KERN_ERR
"macserial: can't get irq %d\n",
2506 zs_soft
[i
].rx_dma_irq
);
2507 disable_irq(zs_soft
[i
].rx_dma_irq
);
2510 if (request_irq(zs_soft
[i
].irq
, rs_interrupt
, 0,
2511 "SCC", &zs_soft
[i
]))
2512 printk(KERN_ERR
"macserial: can't get irq %d\n",
2514 disable_irq(zs_soft
[i
].irq
);
2517 show_serial_version();
2519 /* Initialize the tty_driver structure */
2520 /* Not all of this is exactly right for us. */
2522 serial_driver
->owner
= THIS_MODULE
;
2523 serial_driver
->driver_name
= "macserial";
2524 serial_driver
->devfs_name
= "tts/";
2525 serial_driver
->name
= "ttyS";
2526 serial_driver
->major
= TTY_MAJOR
;
2527 serial_driver
->minor_start
= 64;
2528 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
2529 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
2530 serial_driver
->init_termios
= tty_std_termios
;
2531 serial_driver
->init_termios
.c_cflag
=
2532 B38400
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2533 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
2534 tty_set_operations(serial_driver
, &serial_ops
);
2536 if (tty_register_driver(serial_driver
))
2537 printk(KERN_ERR
"Error: couldn't register serial driver\n");
2539 for (channel
= 0; channel
< zs_channels_found
; ++channel
) {
2541 if (zs_soft
[channel
].kgdb_channel
) {
2542 kgdb_interruptible(1);
2546 zs_soft
[channel
].clk_divisor
= 16;
2547 /* -- we are not sure the SCC is powered ON at this point
2548 zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
2550 zs_soft
[channel
].zs_baud
= 38400;
2552 /* If console serial line, then enable interrupts. */
2553 if (zs_soft
[channel
].is_cons
) {
2554 printk(KERN_INFO
"macserial: console line, enabling "
2555 "interrupt %d\n", zs_soft
[channel
].irq
);
2556 panic("macserial: console not supported yet !");
2557 write_zsreg(zs_soft
[channel
].zs_channel
, R1
,
2558 (EXT_INT_ENAB
| INT_ALL_Rx
| TxINT_ENAB
));
2559 write_zsreg(zs_soft
[channel
].zs_channel
, R9
,
2564 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++)
2566 unsigned char* connector
;
2570 if (info
->kgdb_channel
) {
2574 info
->magic
= SERIAL_MAGIC
;
2575 info
->port
= (int) info
->zs_channel
->control
;
2578 info
->custom_divisor
= 16;
2580 info
->close_delay
= 50;
2581 info
->closing_wait
= 3000;
2585 info
->blocked_open
= 0;
2586 INIT_WORK(&info
->tqueue
, do_softint
, info
);
2587 spin_lock_init(&info
->lock
);
2588 init_waitqueue_head(&info
->open_wait
);
2589 init_waitqueue_head(&info
->close_wait
);
2591 printk(KERN_INFO
"tty%02d at 0x%08x (irq = %d)", info
->line
,
2592 info
->port
, info
->irq
);
2593 printk(" is a Z8530 ESCC");
2594 connector
= get_property(info
->dev_node
, "AAPL,connector", &lenp
);
2596 printk(", port = %s", connector
);
2597 if (info
->is_internal_modem
)
2598 printk(" (internal modem)");
2608 void macserial_cleanup(void)
2611 unsigned long flags
;
2612 struct mac_serial
*info
;
2614 for (info
= zs_chain
, i
= 0; info
; info
= info
->zs_next
, i
++)
2615 set_scc_power(info
, 0);
2616 spin_lock_irqsave(&info
->lock
, flags
);
2617 for (i
= 0; i
< zs_channels_found
; ++i
) {
2618 free_irq(zs_soft
[i
].irq
, &zs_soft
[i
]);
2619 if (zs_soft
[i
].has_dma
) {
2620 free_irq(zs_soft
[i
].tx_dma_irq
, &zs_soft
[i
]);
2621 free_irq(zs_soft
[i
].rx_dma_irq
, &zs_soft
[i
]);
2623 release_OF_resource(zs_soft
[i
].dev_node
, 0);
2624 if (zs_soft
[i
].has_dma
) {
2625 struct device_node
* ch
= zs_soft
[i
].dev_node
;
2626 release_OF_resource(ch
, ch
->n_addrs
- 2);
2627 release_OF_resource(ch
, ch
->n_addrs
- 1);
2630 spin_unlock_irqrestore(&info
->lock
, flags
);
2631 tty_unregister_driver(serial_driver
);
2632 put_tty_driver(serial_driver
);
2635 free_page((unsigned long) tmp_buf
);
2639 #ifdef CONFIG_PMAC_PBOOK
2640 if (zs_channels_found
)
2641 pmu_unregister_sleep_notifier(&serial_sleep_notifier
);
2642 #endif /* CONFIG_PMAC_PBOOK */
2645 module_init(macserial_init
);
2646 module_exit(macserial_cleanup
);
2647 MODULE_LICENSE("GPL");
2651 * register_serial and unregister_serial allows for serial ports to be
2652 * configured at run-time, to support PCMCIA modems.
2654 /* PowerMac: Unused at this time, just here to make things link. */
2655 int register_serial(struct serial_struct
*req
)
2660 void unregister_serial(int line
)
2667 * ------------------------------------------------------------
2668 * Serial console driver
2669 * ------------------------------------------------------------
2671 #ifdef CONFIG_SERIAL_CONSOLE
2674 * Print a string to the serial port trying not to disturb
2675 * any possible real use of the port...
2677 static void serial_console_write(struct console
*co
, const char *s
,
2680 struct mac_serial
*info
= zs_soft
+ co
->index
;
2683 /* Turn of interrupts and enable the transmitter. */
2684 write_zsreg(info
->zs_channel
, R1
, info
->curregs
[1] & ~TxINT_ENAB
);
2685 write_zsreg(info
->zs_channel
, R5
, info
->curregs
[5] | TxENAB
| RTS
| DTR
);
2687 for (i
=0; i
<count
; i
++) {
2688 /* Wait for the transmit buffer to empty. */
2689 while ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
) == 0) {
2693 write_zsdata(info
->zs_channel
, s
[i
]);
2695 while ((read_zsreg(info
->zs_channel
, 0) & Tx_BUF_EMP
)
2699 write_zsdata(info
->zs_channel
, 13);
2703 /* Restore the values in the registers. */
2704 write_zsreg(info
->zs_channel
, R1
, info
->curregs
[1]);
2705 /* Don't disable the transmitter. */
2708 static struct tty_driver
*serial_driver
;
2710 static struct tty_driver
*serial_console_device(struct console
*c
, int *index
)
2713 return serial_driver
;
2717 * Setup initial baud/bits/parity. We do two things here:
2718 * - construct a cflag setting for the first rs_open()
2719 * - initialize the serial port
2720 * Return non-zero if we didn't find a serial port.
2722 static int __init
serial_console_setup(struct console
*co
, char *options
)
2724 struct mac_serial
*info
;
2728 int cflag
= CREAD
| HUPCL
| CLOCAL
;
2733 /* Find out how many Z8530 SCCs we have */
2740 /* Do we have the device asked for? */
2741 if (co
->index
>= zs_channels_found
)
2743 info
= zs_soft
+ co
->index
;
2745 set_scc_power(info
, 1);
2747 /* Reset the channel */
2748 write_zsreg(info
->zs_channel
, R9
, CHRA
);
2751 baud
= simple_strtoul(options
, NULL
, 10);
2753 while(*s
>= '0' && *s
<= '9')
2762 * Now construct a cflag setting.
2802 cflag
|= PARENB
| PARODD
;
2810 spin_lock_irqsave(&info
->lock
, flags
);
2811 memset(info
->curregs
, 0, sizeof(info
->curregs
));
2813 info
->zs_baud
= baud
;
2814 info
->clk_divisor
= 16;
2815 switch (info
->zs_baud
) {
2816 case ZS_CLOCK
/16: /* 230400 */
2817 info
->curregs
[4] = X16CLK
;
2818 info
->curregs
[11] = 0;
2820 case ZS_CLOCK
/32: /* 115200 */
2821 info
->curregs
[4] = X32CLK
;
2822 info
->curregs
[11] = 0;
2825 info
->curregs
[4] = X16CLK
;
2826 info
->curregs
[11] = TCBR
| RCBR
;
2827 brg
= BPS_TO_BRG(info
->zs_baud
, ZS_CLOCK
/info
->clk_divisor
);
2828 info
->curregs
[12] = (brg
& 255);
2829 info
->curregs
[13] = ((brg
>> 8) & 255);
2830 info
->curregs
[14] = BRENABL
;
2833 /* byte size and parity */
2834 info
->curregs
[3] &= ~RxNBITS_MASK
;
2835 info
->curregs
[5] &= ~TxNBITS_MASK
;
2836 switch (cflag
& CSIZE
) {
2838 info
->curregs
[3] |= Rx5
;
2839 info
->curregs
[5] |= Tx5
;
2842 info
->curregs
[3] |= Rx6
;
2843 info
->curregs
[5] |= Tx6
;
2846 info
->curregs
[3] |= Rx7
;
2847 info
->curregs
[5] |= Tx7
;
2850 default: /* defaults to 8 bits */
2851 info
->curregs
[3] |= Rx8
;
2852 info
->curregs
[5] |= Tx8
;
2855 info
->curregs
[5] |= TxENAB
| RTS
| DTR
;
2856 info
->pendregs
[3] = info
->curregs
[3];
2857 info
->pendregs
[5] = info
->curregs
[5];
2859 info
->curregs
[4] &= ~(SB_MASK
| PAR_ENA
| PAR_EVEN
);
2860 if (cflag
& CSTOPB
) {
2861 info
->curregs
[4] |= SB2
;
2863 info
->curregs
[4] |= SB1
;
2865 if (cflag
& PARENB
) {
2866 info
->curregs
[4] |= PAR_ENA
;
2867 if (!(cflag
& PARODD
)) {
2868 info
->curregs
[4] |= PAR_EVEN
;
2871 info
->pendregs
[4] = info
->curregs
[4];
2873 if (!(cflag
& CLOCAL
)) {
2874 if (!(info
->curregs
[15] & DCDIE
))
2875 info
->read_reg_zero
= read_zsreg(info
->zs_channel
, 0);
2876 info
->curregs
[15] |= DCDIE
;
2878 info
->curregs
[15] &= ~DCDIE
;
2879 if (cflag
& CRTSCTS
) {
2880 info
->curregs
[15] |= CTSIE
;
2881 if ((read_zsreg(info
->zs_channel
, 0) & CTS
) != 0)
2882 info
->tx_stopped
= 1;
2884 info
->curregs
[15] &= ~CTSIE
;
2885 info
->tx_stopped
= 0;
2887 info
->pendregs
[15] = info
->curregs
[15];
2889 /* Load up the new values */
2890 load_zsregs(info
->zs_channel
, info
->curregs
);
2892 spin_unlock_irqrestore(&info
->lock
, flags
);
2897 static struct console sercons
= {
2899 .write
= serial_console_write
,
2900 .device
= serial_console_device
,
2901 .setup
= serial_console_setup
,
2902 .flags
= CON_PRINTBUFFER
,
2909 static void __init
mac_scc_console_init(void)
2911 register_console(&sercons
);
2913 console_initcall(mac_scc_console_init
);
2915 #endif /* ifdef CONFIG_SERIAL_CONSOLE */
2918 /* These are for receiving and sending characters under the kgdb
2919 * source level kernel debugger.
2921 void putDebugChar(char kgdb_char
)
2923 struct mac_zschannel
*chan
= zs_kgdbchan
;
2924 while ((read_zsreg(chan
, 0) & Tx_BUF_EMP
) == 0)
2926 write_zsdata(chan
, kgdb_char
);
2929 char getDebugChar(void)
2931 struct mac_zschannel
*chan
= zs_kgdbchan
;
2932 while((read_zsreg(chan
, 0) & Rx_CH_AV
) == 0)
2933 eieio(); /*barrier();*/
2934 return read_zsdata(chan
);
2937 void kgdb_interruptible(int yes
)
2939 struct mac_zschannel
*chan
= zs_kgdbchan
;
2941 nine
= read_zsreg(chan
, 9);
2943 one
= EXT_INT_ENAB
|INT_ALL_Rx
;
2945 printk("turning serial ints on\n");
2949 printk("turning serial ints off\n");
2951 write_zsreg(chan
, 1, one
);
2952 write_zsreg(chan
, 9, nine
);
2955 /* This sets up the serial port we're using, and turns on
2956 * interrupts for that channel, so kgdb is usable once we're done.
2958 static inline void kgdb_chaninit(struct mac_zschannel
*ms
, int intson
, int bps
)
2962 volatile char *sccc
= ms
->control
;
2963 brg
= BPS_TO_BRG(bps
, ZS_CLOCK
/16);
2964 printk("setting bps on kgdb line to %d [brg=%x]\n", bps
, brg
);
2965 for (i
= 20000; i
!= 0; --i
) {
2968 for (i
= 0; i
< sizeof(scc_inittab
); ++i
) {
2969 write_zsreg(ms
, scc_inittab
[i
], scc_inittab
[i
+1]);
2974 /* This is called at boot time to prime the kgdb serial debugging
2975 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2976 * for /dev/ttyb which is determined in setup_arch() from the
2977 * boot command line flags.
2978 * XXX at the moment probably only channel A will work
2980 void __init
zs_kgdb_hook(int tty_num
)
2982 /* Find out how many Z8530 SCCs we have */
2986 set_scc_power(&zs_soft
[tty_num
], 1);
2988 zs_kgdbchan
= zs_soft
[tty_num
].zs_channel
;
2989 zs_soft
[tty_num
].change_needed
= 0;
2990 zs_soft
[tty_num
].clk_divisor
= 16;
2991 zs_soft
[tty_num
].zs_baud
= 38400;
2992 zs_soft
[tty_num
].kgdb_channel
= 1; /* This runs kgdb */
2994 /* Turn on transmitter/receiver at 8-bits/char */
2995 kgdb_chaninit(zs_soft
[tty_num
].zs_channel
, 1, 38400);
2996 printk("KGDB: on channel %d initialized\n", tty_num
);
2997 set_debug_traps(); /* init stub */
2999 #endif /* ifdef CONFIG_KGDB */
3001 #ifdef CONFIG_PMAC_PBOOK
3003 * notify clients before sleep and reset bus afterwards
3006 serial_notify_sleep(struct pmu_sleep_notifier
*self
, int when
)
3011 case PBOOK_SLEEP_REQUEST
:
3012 case PBOOK_SLEEP_REJECT
:
3015 case PBOOK_SLEEP_NOW
:
3016 for (i
=0; i
<zs_channels_found
; i
++) {
3017 struct mac_serial
*info
= &zs_soft
[i
];
3018 if (info
->flags
& ZILOG_INITIALIZED
) {
3020 info
->flags
|= ZILOG_SLEEPING
;
3025 for (i
=0; i
<zs_channels_found
; i
++) {
3026 struct mac_serial
*info
= &zs_soft
[i
];
3027 if (info
->flags
& ZILOG_SLEEPING
) {
3028 info
->flags
&= ~ZILOG_SLEEPING
;
3034 return PBOOK_SLEEP_OK
;
3036 #endif /* CONFIG_PMAC_PBOOK */