4 * Driver for Zilog serial chips found on Sun workstations and
5 * servers. This driver could actually be made more generic.
7 * This is based on the old drivers/sbus/char/zs.c code. A lot
8 * of code has been simply moved over directly from there but
9 * much has been rewritten. Credits therefore go out to Eddie
10 * C. Dost, Pete Zaitcev, Ted Ts'o and Alex Buell for their
13 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
16 #include <linux/config.h>
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/errno.h>
21 #include <linux/delay.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/ptrace.h>
27 #include <linux/ioport.h>
28 #include <linux/slab.h>
29 #include <linux/circ_buf.h>
30 #include <linux/serial.h>
31 #include <linux/console.h>
32 #include <linux/spinlock.h>
34 #include <linux/serio.h>
36 #include <linux/init.h>
45 #include <linux/serial_core.h>
50 /* On 32-bit sparcs we need to delay after register accesses
51 * to accommodate sun4 systems, but we do not need to flush writes.
52 * On 64-bit sparc we only need to flush single writes to ensure
55 #ifndef CONFIG_SPARC64
56 #define ZSDELAY() udelay(5)
57 #define ZSDELAY_LONG() udelay(20)
58 #define ZS_WSYNC(channel) do { } while (0)
61 #define ZSDELAY_LONG()
62 #define ZS_WSYNC(__channel) \
63 sbus_readb(&((__channel)->control))
66 static int num_sunzilog
;
67 #define NUM_SUNZILOG num_sunzilog
68 #define NUM_CHANNELS (NUM_SUNZILOG * 2)
70 #define KEYBOARD_LINE 0x2
71 #define MOUSE_LINE 0x3
73 #define ZS_CLOCK 4915200 /* Zilog input clock rate. */
74 #define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
77 * We wrap our port structure around the generic uart_port.
79 struct uart_sunzilog_port
{
80 struct uart_port port
;
82 /* IRQ servicing chain. */
83 struct uart_sunzilog_port
*next
;
85 /* Current values of Zilog write registers. */
86 unsigned char curregs
[NUM_ZSREGS
];
89 #define SUNZILOG_FLAG_CONS_KEYB 0x00000001
90 #define SUNZILOG_FLAG_CONS_MOUSE 0x00000002
91 #define SUNZILOG_FLAG_IS_CONS 0x00000004
92 #define SUNZILOG_FLAG_IS_KGDB 0x00000008
93 #define SUNZILOG_FLAG_MODEM_STATUS 0x00000010
94 #define SUNZILOG_FLAG_IS_CHANNEL_A 0x00000020
95 #define SUNZILOG_FLAG_REGS_HELD 0x00000040
96 #define SUNZILOG_FLAG_TX_STOPPED 0x00000080
97 #define SUNZILOG_FLAG_TX_ACTIVE 0x00000100
101 /* L1-A keyboard break state. */
105 unsigned char parity_mask
;
106 unsigned char prev_status
;
113 #define ZILOG_CHANNEL_FROM_PORT(PORT) ((struct zilog_channel *)((PORT)->membase))
114 #define UART_ZILOG(PORT) ((struct uart_sunzilog_port *)(PORT))
116 #define ZS_IS_KEYB(UP) ((UP)->flags & SUNZILOG_FLAG_CONS_KEYB)
117 #define ZS_IS_MOUSE(UP) ((UP)->flags & SUNZILOG_FLAG_CONS_MOUSE)
118 #define ZS_IS_CONS(UP) ((UP)->flags & SUNZILOG_FLAG_IS_CONS)
119 #define ZS_IS_KGDB(UP) ((UP)->flags & SUNZILOG_FLAG_IS_KGDB)
120 #define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & SUNZILOG_FLAG_MODEM_STATUS)
121 #define ZS_IS_CHANNEL_A(UP) ((UP)->flags & SUNZILOG_FLAG_IS_CHANNEL_A)
122 #define ZS_REGS_HELD(UP) ((UP)->flags & SUNZILOG_FLAG_REGS_HELD)
123 #define ZS_TX_STOPPED(UP) ((UP)->flags & SUNZILOG_FLAG_TX_STOPPED)
124 #define ZS_TX_ACTIVE(UP) ((UP)->flags & SUNZILOG_FLAG_TX_ACTIVE)
126 /* Reading and writing Zilog8530 registers. The delays are to make this
127 * driver work on the Sun4 which needs a settling delay after each chip
128 * register access, other machines handle this in hardware via auxiliary
129 * flip-flops which implement the settle time we do in software.
131 * The port lock must be held and local IRQs must be disabled
132 * when {read,write}_zsreg is invoked.
134 static unsigned char read_zsreg(struct zilog_channel
*channel
,
137 unsigned char retval
;
139 sbus_writeb(reg
, &channel
->control
);
141 retval
= sbus_readb(&channel
->control
);
147 static void write_zsreg(struct zilog_channel
*channel
,
148 unsigned char reg
, unsigned char value
)
150 sbus_writeb(reg
, &channel
->control
);
152 sbus_writeb(value
, &channel
->control
);
156 static void sunzilog_clear_fifo(struct zilog_channel
*channel
)
160 for (i
= 0; i
< 32; i
++) {
161 unsigned char regval
;
163 regval
= sbus_readb(&channel
->control
);
165 if (regval
& Rx_CH_AV
)
168 regval
= read_zsreg(channel
, R1
);
169 sbus_readb(&channel
->data
);
172 if (regval
& (PAR_ERR
| Rx_OVR
| CRC_ERR
)) {
173 sbus_writeb(ERR_RES
, &channel
->control
);
180 /* This function must only be called when the TX is not busy. The UART
181 * port lock must be held and local interrupts disabled.
183 static void __load_zsregs(struct zilog_channel
*channel
, unsigned char *regs
)
187 /* Let pending transmits finish. */
188 for (i
= 0; i
< 1000; i
++) {
189 unsigned char stat
= read_zsreg(channel
, R1
);
195 sbus_writeb(ERR_RES
, &channel
->control
);
199 sunzilog_clear_fifo(channel
);
201 /* Disable all interrupts. */
202 write_zsreg(channel
, R1
,
203 regs
[R1
] & ~(RxINT_MASK
| TxINT_ENAB
| EXT_INT_ENAB
));
205 /* Set parity, sync config, stop bits, and clock divisor. */
206 write_zsreg(channel
, R4
, regs
[R4
]);
208 /* Set misc. TX/RX control bits. */
209 write_zsreg(channel
, R10
, regs
[R10
]);
211 /* Set TX/RX controls sans the enable bits. */
212 write_zsreg(channel
, R3
, regs
[R3
] & ~RxENAB
);
213 write_zsreg(channel
, R5
, regs
[R5
] & ~TxENAB
);
215 /* Synchronous mode config. */
216 write_zsreg(channel
, R6
, regs
[R6
]);
217 write_zsreg(channel
, R7
, regs
[R7
]);
219 /* Don't mess with the interrupt vector (R2, unused by us) and
220 * master interrupt control (R9). We make sure this is setup
221 * properly at probe time then never touch it again.
224 /* Disable baud generator. */
225 write_zsreg(channel
, R14
, regs
[R14
] & ~BRENAB
);
227 /* Clock mode control. */
228 write_zsreg(channel
, R11
, regs
[R11
]);
230 /* Lower and upper byte of baud rate generator divisor. */
231 write_zsreg(channel
, R12
, regs
[R12
]);
232 write_zsreg(channel
, R13
, regs
[R13
]);
234 /* Now rewrite R14, with BRENAB (if set). */
235 write_zsreg(channel
, R14
, regs
[R14
]);
237 /* External status interrupt control. */
238 write_zsreg(channel
, R15
, regs
[R15
]);
240 /* Reset external status interrupts. */
241 write_zsreg(channel
, R0
, RES_EXT_INT
);
242 write_zsreg(channel
, R0
, RES_EXT_INT
);
244 /* Rewrite R3/R5, this time without enables masked. */
245 write_zsreg(channel
, R3
, regs
[R3
]);
246 write_zsreg(channel
, R5
, regs
[R5
]);
248 /* Rewrite R1, this time without IRQ enabled masked. */
249 write_zsreg(channel
, R1
, regs
[R1
]);
252 /* Reprogram the Zilog channel HW registers with the copies found in the
253 * software state struct. If the transmitter is busy, we defer this update
254 * until the next TX complete interrupt. Else, we do it right now.
256 * The UART port lock must be held and local interrupts disabled.
258 static void sunzilog_maybe_update_regs(struct uart_sunzilog_port
*up
,
259 struct zilog_channel
*channel
)
261 if (!ZS_REGS_HELD(up
)) {
262 if (ZS_TX_ACTIVE(up
)) {
263 up
->flags
|= SUNZILOG_FLAG_REGS_HELD
;
265 __load_zsregs(channel
, up
->curregs
);
270 static void sunzilog_change_mouse_baud(struct uart_sunzilog_port
*up
)
272 unsigned int cur_cflag
= up
->cflag
;
276 up
->cflag
|= suncore_mouse_baud_cflag_next(cur_cflag
, &new_baud
);
278 brg
= BPS_TO_BRG(new_baud
, ZS_CLOCK
/ ZS_CLOCK_DIVISOR
);
279 up
->curregs
[R12
] = (brg
& 0xff);
280 up
->curregs
[R13
] = (brg
>> 8) & 0xff;
281 sunzilog_maybe_update_regs(up
, ZILOG_CHANNEL_FROM_PORT(&up
->port
));
284 static void sunzilog_kbdms_receive_chars(struct uart_sunzilog_port
*up
,
285 unsigned char ch
, int is_break
,
286 struct pt_regs
*regs
)
288 if (ZS_IS_KEYB(up
)) {
289 if (ch
== SUNKBD_RESET
) {
292 } else if (up
->kbd_id
) {
294 } else if (ch
== SUNKBD_L1
) {
296 } else if (ch
== (SUNKBD_L1
| SUNKBD_UP
)) {
298 } else if (ch
== SUNKBD_A
&& up
->l1_down
) {
305 serio_interrupt(&up
->serio
, ch
, 0, regs
);
307 } else if (ZS_IS_MOUSE(up
)) {
308 int ret
= suncore_mouse_baud_detection(ch
, is_break
);
312 sunzilog_change_mouse_baud(up
);
319 serio_interrupt(&up
->serio
, ch
, 0, regs
);
326 static void sunzilog_receive_chars(struct uart_sunzilog_port
*up
,
327 struct zilog_channel
*channel
,
328 struct pt_regs
*regs
)
330 struct tty_struct
*tty
= up
->port
.info
->tty
; /* XXX info==NULL? */
333 unsigned char ch
, r1
;
335 if (unlikely(tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)) {
336 tty
->flip
.work
.func((void *)tty
);
337 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
338 return; /* XXX Ignores SysRq when we need it most. Fix. */
341 r1
= read_zsreg(channel
, R1
);
342 if (r1
& (PAR_ERR
| Rx_OVR
| CRC_ERR
)) {
343 sbus_writeb(ERR_RES
, &channel
->control
);
348 ch
= sbus_readb(&channel
->control
);
351 /* This funny hack depends upon BRK_ABRT not interfering
352 * with the other bits we care about in R1.
357 ch
= sbus_readb(&channel
->data
);
360 ch
&= up
->parity_mask
;
362 if (unlikely(ZS_IS_KEYB(up
)) || unlikely(ZS_IS_MOUSE(up
))) {
363 sunzilog_kbdms_receive_chars(up
, ch
, 0, regs
);
367 if (ZS_IS_CONS(up
) && (r1
& BRK_ABRT
)) {
368 /* Wait for BREAK to deassert to avoid potentially
369 * confusing the PROM.
372 ch
= sbus_readb(&channel
->control
);
374 if (!(ch
& BRK_ABRT
))
381 /* A real serial line, record the character and status. */
382 *tty
->flip
.char_buf_ptr
= ch
;
383 *tty
->flip
.flag_buf_ptr
= TTY_NORMAL
;
384 up
->port
.icount
.rx
++;
385 if (r1
& (BRK_ABRT
| PAR_ERR
| Rx_OVR
| CRC_ERR
)) {
387 r1
&= ~(PAR_ERR
| CRC_ERR
);
388 up
->port
.icount
.brk
++;
389 if (uart_handle_break(&up
->port
))
392 else if (r1
& PAR_ERR
)
393 up
->port
.icount
.parity
++;
394 else if (r1
& CRC_ERR
)
395 up
->port
.icount
.frame
++;
397 up
->port
.icount
.overrun
++;
398 r1
&= up
->port
.read_status_mask
;
400 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
401 else if (r1
& PAR_ERR
)
402 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
403 else if (r1
& CRC_ERR
)
404 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
406 if (uart_handle_sysrq_char(&up
->port
, ch
, regs
))
409 if (up
->port
.ignore_status_mask
== 0xff ||
410 (r1
& up
->port
.ignore_status_mask
) == 0) {
411 tty
->flip
.flag_buf_ptr
++;
412 tty
->flip
.char_buf_ptr
++;
416 tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
417 *tty
->flip
.flag_buf_ptr
= TTY_OVERRUN
;
418 tty
->flip
.flag_buf_ptr
++;
419 tty
->flip
.char_buf_ptr
++;
423 ch
= sbus_readb(&channel
->control
);
425 if (!(ch
& Rx_CH_AV
))
429 tty_flip_buffer_push(tty
);
432 static void sunzilog_status_handle(struct uart_sunzilog_port
*up
,
433 struct zilog_channel
*channel
,
434 struct pt_regs
*regs
)
436 unsigned char status
;
438 status
= sbus_readb(&channel
->control
);
441 sbus_writeb(RES_EXT_INT
, &channel
->control
);
445 if ((status
& BRK_ABRT
) && ZS_IS_MOUSE(up
))
446 sunzilog_kbdms_receive_chars(up
, 0, 1, regs
);
448 if (ZS_WANTS_MODEM_STATUS(up
)) {
450 up
->port
.icount
.dsr
++;
452 /* The Zilog just gives us an interrupt when DCD/CTS/etc. change.
453 * But it does not tell us which bit has changed, we have to keep
454 * track of this ourselves.
456 if ((status
& DCD
) ^ up
->prev_status
)
457 uart_handle_dcd_change(&up
->port
,
459 if ((status
& CTS
) ^ up
->prev_status
)
460 uart_handle_cts_change(&up
->port
,
463 wake_up_interruptible(&up
->port
.info
->delta_msr_wait
);
466 up
->prev_status
= status
;
469 static void sunzilog_transmit_chars(struct uart_sunzilog_port
*up
,
470 struct zilog_channel
*channel
)
472 struct circ_buf
*xmit
;
474 if (ZS_IS_CONS(up
)) {
475 unsigned char status
= sbus_readb(&channel
->control
);
478 /* TX still busy? Just wait for the next TX done interrupt.
480 * It can occur because of how we do serial console writes. It would
481 * be nice to transmit console writes just like we normally would for
482 * a TTY line. (ie. buffered and TX interrupt driven). That is not
483 * easy because console writes cannot sleep. One solution might be
484 * to poll on enough port->xmit space becomming free. -DaveM
486 if (!(status
& Tx_BUF_EMP
))
490 up
->flags
&= ~SUNZILOG_FLAG_TX_ACTIVE
;
492 if (ZS_REGS_HELD(up
)) {
493 __load_zsregs(channel
, up
->curregs
);
494 up
->flags
&= ~SUNZILOG_FLAG_REGS_HELD
;
497 if (ZS_TX_STOPPED(up
)) {
498 up
->flags
&= ~SUNZILOG_FLAG_TX_STOPPED
;
502 if (up
->port
.x_char
) {
503 up
->flags
|= SUNZILOG_FLAG_TX_ACTIVE
;
504 sbus_writeb(up
->port
.x_char
, &channel
->data
);
508 up
->port
.icount
.tx
++;
513 if (up
->port
.info
== NULL
)
515 xmit
= &up
->port
.info
->xmit
;
516 if (uart_circ_empty(xmit
)) {
517 uart_write_wakeup(&up
->port
);
520 if (uart_tx_stopped(&up
->port
))
523 up
->flags
|= SUNZILOG_FLAG_TX_ACTIVE
;
524 sbus_writeb(xmit
->buf
[xmit
->tail
], &channel
->data
);
528 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
529 up
->port
.icount
.tx
++;
531 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
532 uart_write_wakeup(&up
->port
);
537 sbus_writeb(RES_Tx_P
, &channel
->control
);
542 static irqreturn_t
sunzilog_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
544 struct uart_sunzilog_port
*up
= dev_id
;
547 struct zilog_channel
*channel
548 = ZILOG_CHANNEL_FROM_PORT(&up
->port
);
551 spin_lock(&up
->port
.lock
);
552 r3
= read_zsreg(channel
, R3
);
555 if (r3
& (CHAEXT
| CHATxIP
| CHARxIP
)) {
556 sbus_writeb(RES_H_IUS
, &channel
->control
);
561 sunzilog_receive_chars(up
, channel
, regs
);
563 sunzilog_status_handle(up
, channel
, regs
);
565 sunzilog_transmit_chars(up
, channel
);
567 spin_unlock(&up
->port
.lock
);
571 channel
= ZILOG_CHANNEL_FROM_PORT(&up
->port
);
573 spin_lock(&up
->port
.lock
);
574 if (r3
& (CHBEXT
| CHBTxIP
| CHBRxIP
)) {
575 sbus_writeb(RES_H_IUS
, &channel
->control
);
580 sunzilog_receive_chars(up
, channel
, regs
);
582 sunzilog_status_handle(up
, channel
, regs
);
584 sunzilog_transmit_chars(up
, channel
);
586 spin_unlock(&up
->port
.lock
);
594 /* A convenient way to quickly get R0 status. The caller must _not_ hold the
595 * port lock, it is acquired here.
597 static __inline__
unsigned char sunzilog_read_channel_status(struct uart_port
*port
)
599 struct zilog_channel
*channel
;
601 unsigned char status
;
603 spin_lock_irqsave(&port
->lock
, flags
);
605 channel
= ZILOG_CHANNEL_FROM_PORT(port
);
606 status
= sbus_readb(&channel
->control
);
609 spin_unlock_irqrestore(&port
->lock
, flags
);
614 /* The port lock is not held. */
615 static unsigned int sunzilog_tx_empty(struct uart_port
*port
)
617 unsigned char status
;
620 status
= sunzilog_read_channel_status(port
);
621 if (status
& Tx_BUF_EMP
)
629 /* The port lock is not held. */
630 static unsigned int sunzilog_get_mctrl(struct uart_port
*port
)
632 unsigned char status
;
635 status
= sunzilog_read_channel_status(port
);
648 /* The port lock is held and interrupts are disabled. */
649 static void sunzilog_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
651 struct uart_sunzilog_port
*up
= (struct uart_sunzilog_port
*) port
;
652 struct zilog_channel
*channel
= ZILOG_CHANNEL_FROM_PORT(port
);
653 unsigned char set_bits
, clear_bits
;
655 set_bits
= clear_bits
= 0;
657 if (mctrl
& TIOCM_RTS
)
661 if (mctrl
& TIOCM_DTR
)
666 /* NOTE: Not subject to 'transmitter active' rule. */
667 up
->curregs
[R5
] |= set_bits
;
668 up
->curregs
[R5
] &= ~clear_bits
;
669 write_zsreg(channel
, R5
, up
->curregs
[R5
]);
672 /* The port lock is held and interrupts are disabled. */
673 static void sunzilog_stop_tx(struct uart_port
*port
, unsigned int tty_stop
)
675 struct uart_sunzilog_port
*up
= (struct uart_sunzilog_port
*) port
;
677 up
->flags
|= SUNZILOG_FLAG_TX_STOPPED
;
680 /* The port lock is held and interrupts are disabled. */
681 static void sunzilog_start_tx(struct uart_port
*port
, unsigned int tty_start
)
683 struct uart_sunzilog_port
*up
= (struct uart_sunzilog_port
*) port
;
684 struct zilog_channel
*channel
= ZILOG_CHANNEL_FROM_PORT(port
);
685 unsigned char status
;
687 up
->flags
|= SUNZILOG_FLAG_TX_ACTIVE
;
688 up
->flags
&= ~SUNZILOG_FLAG_TX_STOPPED
;
690 status
= sbus_readb(&channel
->control
);
693 /* TX busy? Just wait for the TX done interrupt. */
694 if (!(status
& Tx_BUF_EMP
))
697 /* Send the first character to jump-start the TX done
698 * IRQ sending engine.
701 sbus_writeb(port
->x_char
, &channel
->data
);
708 struct circ_buf
*xmit
= &port
->info
->xmit
;
710 sbus_writeb(xmit
->buf
[xmit
->tail
], &channel
->data
);
714 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
717 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
718 uart_write_wakeup(&up
->port
);
722 /* The port lock is not held. */
723 static void sunzilog_stop_rx(struct uart_port
*port
)
725 struct uart_sunzilog_port
*up
= UART_ZILOG(port
);
726 struct zilog_channel
*channel
;
732 spin_lock_irqsave(&port
->lock
, flags
);
734 channel
= ZILOG_CHANNEL_FROM_PORT(port
);
736 /* Disable all RX interrupts. */
737 up
->curregs
[R1
] &= ~RxINT_MASK
;
738 sunzilog_maybe_update_regs(up
, channel
);
740 spin_unlock_irqrestore(&port
->lock
, flags
);
743 /* The port lock is not held. */
744 static void sunzilog_enable_ms(struct uart_port
*port
)
746 struct uart_sunzilog_port
*up
= (struct uart_sunzilog_port
*) port
;
747 struct zilog_channel
*channel
= ZILOG_CHANNEL_FROM_PORT(port
);
748 unsigned char new_reg
;
751 spin_lock_irqsave(&port
->lock
, flags
);
753 new_reg
= up
->curregs
[R15
] | (DCDIE
| SYNCIE
| CTSIE
);
754 if (new_reg
!= up
->curregs
[R15
]) {
755 up
->curregs
[R15
] = new_reg
;
757 /* NOTE: Not subject to 'transmitter active' rule. */
758 write_zsreg(channel
, R15
, up
->curregs
[R15
]);
761 spin_unlock_irqrestore(&port
->lock
, flags
);
764 /* The port lock is not held. */
765 static void sunzilog_break_ctl(struct uart_port
*port
, int break_state
)
767 struct uart_sunzilog_port
*up
= (struct uart_sunzilog_port
*) port
;
768 struct zilog_channel
*channel
= ZILOG_CHANNEL_FROM_PORT(port
);
769 unsigned char set_bits
, clear_bits
, new_reg
;
772 set_bits
= clear_bits
= 0;
777 clear_bits
|= SND_BRK
;
779 spin_lock_irqsave(&port
->lock
, flags
);
781 new_reg
= (up
->curregs
[R5
] | set_bits
) & ~clear_bits
;
782 if (new_reg
!= up
->curregs
[R5
]) {
783 up
->curregs
[R5
] = new_reg
;
785 /* NOTE: Not subject to 'transmitter active' rule. */
786 write_zsreg(channel
, R5
, up
->curregs
[R5
]);
789 spin_unlock_irqrestore(&port
->lock
, flags
);
792 static void __sunzilog_startup(struct uart_sunzilog_port
*up
)
794 struct zilog_channel
*channel
;
796 channel
= ZILOG_CHANNEL_FROM_PORT(&up
->port
);
797 up
->prev_status
= sbus_readb(&channel
->control
);
799 /* Enable receiver and transmitter. */
800 up
->curregs
[R3
] |= RxENAB
;
801 up
->curregs
[R5
] |= TxENAB
;
803 up
->curregs
[R1
] |= EXT_INT_ENAB
| INT_ALL_Rx
| TxINT_ENAB
;
804 sunzilog_maybe_update_regs(up
, channel
);
807 static int sunzilog_startup(struct uart_port
*port
)
809 struct uart_sunzilog_port
*up
= UART_ZILOG(port
);
815 spin_lock_irqsave(&port
->lock
, flags
);
816 __sunzilog_startup(up
);
817 spin_unlock_irqrestore(&port
->lock
, flags
);
822 * The test for ZS_IS_CONS is explained by the following e-mail:
824 * From: Russell King <rmk@arm.linux.org.uk>
825 * Date: Sun, 8 Dec 2002 10:18:38 +0000
827 * On Sun, Dec 08, 2002 at 02:43:36AM -0500, Pete Zaitcev wrote:
828 * > I boot my 2.5 boxes using "console=ttyS0,9600" argument,
829 * > and I noticed that something is not right with reference
830 * > counting in this case. It seems that when the console
831 * > is open by kernel initially, this is not accounted
832 * > as an open, and uart_startup is not called.
834 * That is correct. We are unable to call uart_startup when the serial
835 * console is initialised because it may need to allocate memory (as
836 * request_irq does) and the memory allocators may not have been
839 * 1. initialise the port into a state where it can send characters in the
840 * console write method.
842 * 2. don't do the actual hardware shutdown in your shutdown() method (but
843 * do the normal software shutdown - ie, free irqs etc)
846 static void sunzilog_shutdown(struct uart_port
*port
)
848 struct uart_sunzilog_port
*up
= UART_ZILOG(port
);
849 struct zilog_channel
*channel
;
855 spin_lock_irqsave(&port
->lock
, flags
);
857 channel
= ZILOG_CHANNEL_FROM_PORT(port
);
859 /* Disable receiver and transmitter. */
860 up
->curregs
[R3
] &= ~RxENAB
;
861 up
->curregs
[R5
] &= ~TxENAB
;
863 /* Disable all interrupts and BRK assertion. */
864 up
->curregs
[R1
] &= ~(EXT_INT_ENAB
| TxINT_ENAB
| RxINT_MASK
);
865 up
->curregs
[R5
] &= ~SND_BRK
;
866 sunzilog_maybe_update_regs(up
, channel
);
868 spin_unlock_irqrestore(&port
->lock
, flags
);
871 /* Shared by TTY driver and serial console setup. The port lock is held
872 * and local interrupts are disabled.
875 sunzilog_convert_to_zs(struct uart_sunzilog_port
*up
, unsigned int cflag
,
876 unsigned int iflag
, int brg
)
879 up
->curregs
[R10
] = NRZ
;
880 up
->curregs
[R11
] = TCBR
| RCBR
;
882 /* Program BAUD and clock source. */
883 up
->curregs
[R4
] &= ~XCLK_MASK
;
884 up
->curregs
[R4
] |= X16CLK
;
885 up
->curregs
[R12
] = brg
& 0xff;
886 up
->curregs
[R13
] = (brg
>> 8) & 0xff;
887 up
->curregs
[R14
] = BRSRC
| BRENAB
;
889 /* Character size, stop bits, and parity. */
890 up
->curregs
[3] &= ~RxN_MASK
;
891 up
->curregs
[5] &= ~TxN_MASK
;
892 switch (cflag
& CSIZE
) {
894 up
->curregs
[3] |= Rx5
;
895 up
->curregs
[5] |= Tx5
;
896 up
->parity_mask
= 0x1f;
899 up
->curregs
[3] |= Rx6
;
900 up
->curregs
[5] |= Tx6
;
901 up
->parity_mask
= 0x3f;
904 up
->curregs
[3] |= Rx7
;
905 up
->curregs
[5] |= Tx7
;
906 up
->parity_mask
= 0x7f;
910 up
->curregs
[3] |= Rx8
;
911 up
->curregs
[5] |= Tx8
;
912 up
->parity_mask
= 0xff;
915 up
->curregs
[4] &= ~0x0c;
917 up
->curregs
[4] |= SB2
;
919 up
->curregs
[4] |= SB1
;
921 up
->curregs
[4] |= PAR_ENAB
;
923 up
->curregs
[4] &= ~PAR_ENAB
;
924 if (!(cflag
& PARODD
))
925 up
->curregs
[4] |= PAR_EVEN
;
927 up
->curregs
[4] &= ~PAR_EVEN
;
929 up
->port
.read_status_mask
= Rx_OVR
;
931 up
->port
.read_status_mask
|= CRC_ERR
| PAR_ERR
;
932 if (iflag
& (BRKINT
| PARMRK
))
933 up
->port
.read_status_mask
|= BRK_ABRT
;
935 up
->port
.ignore_status_mask
= 0;
937 up
->port
.ignore_status_mask
|= CRC_ERR
| PAR_ERR
;
938 if (iflag
& IGNBRK
) {
939 up
->port
.ignore_status_mask
|= BRK_ABRT
;
941 up
->port
.ignore_status_mask
|= Rx_OVR
;
944 if ((cflag
& CREAD
) == 0)
945 up
->port
.ignore_status_mask
= 0xff;
948 /* The port lock is not held. */
950 sunzilog_set_termios(struct uart_port
*port
, struct termios
*termios
,
953 struct uart_sunzilog_port
*up
= (struct uart_sunzilog_port
*) port
;
957 baud
= uart_get_baud_rate(port
, termios
, old
, 1200, 76800);
959 spin_lock_irqsave(&up
->port
.lock
, flags
);
961 brg
= BPS_TO_BRG(baud
, ZS_CLOCK
/ ZS_CLOCK_DIVISOR
);
963 sunzilog_convert_to_zs(up
, termios
->c_cflag
, termios
->c_iflag
, brg
);
965 if (UART_ENABLE_MS(&up
->port
, termios
->c_cflag
))
966 up
->flags
|= SUNZILOG_FLAG_MODEM_STATUS
;
968 up
->flags
&= ~SUNZILOG_FLAG_MODEM_STATUS
;
970 up
->cflag
= termios
->c_cflag
;
972 sunzilog_maybe_update_regs(up
, ZILOG_CHANNEL_FROM_PORT(port
));
974 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
977 static const char *sunzilog_type(struct uart_port
*port
)
982 /* We do not request/release mappings of the registers here, this
983 * happens at early serial probe time.
985 static void sunzilog_release_port(struct uart_port
*port
)
989 static int sunzilog_request_port(struct uart_port
*port
)
994 /* These do not need to do anything interesting either. */
995 static void sunzilog_config_port(struct uart_port
*port
, int flags
)
999 /* We do not support letting the user mess with the divisor, IRQ, etc. */
1000 static int sunzilog_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
1005 static struct uart_ops sunzilog_pops
= {
1006 .tx_empty
= sunzilog_tx_empty
,
1007 .set_mctrl
= sunzilog_set_mctrl
,
1008 .get_mctrl
= sunzilog_get_mctrl
,
1009 .stop_tx
= sunzilog_stop_tx
,
1010 .start_tx
= sunzilog_start_tx
,
1011 .stop_rx
= sunzilog_stop_rx
,
1012 .enable_ms
= sunzilog_enable_ms
,
1013 .break_ctl
= sunzilog_break_ctl
,
1014 .startup
= sunzilog_startup
,
1015 .shutdown
= sunzilog_shutdown
,
1016 .set_termios
= sunzilog_set_termios
,
1017 .type
= sunzilog_type
,
1018 .release_port
= sunzilog_release_port
,
1019 .request_port
= sunzilog_request_port
,
1020 .config_port
= sunzilog_config_port
,
1021 .verify_port
= sunzilog_verify_port
,
1024 static struct uart_sunzilog_port
*sunzilog_port_table
;
1025 static struct zilog_layout
**sunzilog_chip_regs
;
1027 static struct uart_sunzilog_port
*sunzilog_irq_chain
;
1028 static int zilog_irq
= -1;
1030 static struct uart_driver sunzilog_reg
= {
1031 .owner
= THIS_MODULE
,
1032 .driver_name
= "ttyS",
1033 .devfs_name
= "tts/",
1038 static void * __init
alloc_one_table(unsigned long size
)
1042 ret
= kmalloc(size
, GFP_KERNEL
);
1044 memset(ret
, 0, size
);
1049 static void __init
sunzilog_alloc_tables(void)
1051 sunzilog_port_table
= (struct uart_sunzilog_port
*)
1052 alloc_one_table(NUM_CHANNELS
* sizeof(struct uart_sunzilog_port
));
1053 sunzilog_chip_regs
= (struct zilog_layout
**)
1054 alloc_one_table(NUM_SUNZILOG
* sizeof(struct zilog_layout
*));
1056 if (sunzilog_port_table
== NULL
|| sunzilog_chip_regs
== NULL
) {
1057 prom_printf("SunZilog: Cannot allocate tables.\n");
1062 #ifdef CONFIG_SPARC64
1064 /* We used to attempt to use the address property of the Zilog device node
1065 * but that totally is not necessary on sparc64.
1067 static struct zilog_layout
* __init
get_zs_sun4u(int chip
, int zsnode
)
1069 unsigned long mapped_addr
;
1070 unsigned int sun4u_ino
;
1071 struct sbus_bus
*sbus
= NULL
;
1072 struct sbus_dev
*sdev
= NULL
;
1075 if (central_bus
== NULL
) {
1076 for_each_sbus(sbus
) {
1077 for_each_sbusdev(sdev
, sbus
) {
1078 if (sdev
->prom_node
== zsnode
)
1084 if (sdev
== NULL
&& central_bus
== NULL
) {
1085 prom_printf("SunZilog: sdev&¢ral == NULL for "
1086 "Zilog %d in get_zs_sun4u.\n", chip
);
1089 if (central_bus
== NULL
) {
1091 sbus_ioremap(&sdev
->resource
[0], 0,
1095 struct linux_prom_registers zsregs
[1];
1097 err
= prom_getproperty(zsnode
, "reg",
1098 (char *) &zsregs
[0],
1101 prom_printf("SunZilog: Cannot map "
1103 "central bus.\n", chip
);
1106 apply_fhc_ranges(central_bus
->child
,
1108 apply_central_ranges(central_bus
, &zsregs
[0], 1);
1110 (((u64
)zsregs
[0].which_io
)<<32UL) |
1111 ((u64
)zsregs
[0].phys_addr
);
1114 if (zilog_irq
== -1) {
1116 unsigned long iclr
, imap
;
1118 iclr
= central_bus
->child
->fhc_regs
.uregs
1120 imap
= central_bus
->child
->fhc_regs
.uregs
1122 zilog_irq
= build_irq(12, 0, iclr
, imap
);
1124 err
= prom_getproperty(zsnode
, "interrupts",
1125 (char *) &sun4u_ino
,
1127 zilog_irq
= sbus_build_irq(sbus_root
, sun4u_ino
);
1131 return (struct zilog_layout
*) mapped_addr
;
1133 #else /* CONFIG_SPARC64 */
1136 * XXX The sun4d case is utterly screwed: it tries to re-walk the tree
1137 * (for the 3rd time) in order to find bootbus and cpu. Streamline it.
1139 static struct zilog_layout
* __init
get_zs_sun4cmd(int chip
, int node
)
1141 struct linux_prom_irqs irq_info
[2];
1142 unsigned long mapped_addr
= 0;
1143 int zsnode
, cpunode
, bbnode
;
1144 struct linux_prom_registers zsreg
[4];
1145 struct resource res
;
1147 if (sparc_cpu_model
== sun4d
) {
1153 for (walk
= prom_getchild(prom_root_node
);
1154 (walk
= prom_searchsiblings(walk
, "cpu-unit")) != 0;
1155 walk
= prom_getsibling(walk
)) {
1156 bbnode
= prom_getchild(walk
);
1158 (bbnode
= prom_searchsiblings(bbnode
, "bootbus"))) {
1159 if ((zsnode
= prom_getchild(bbnode
)) == node
) {
1166 prom_printf("SunZilog: Cannot find the %d'th bootbus on sun4d.\n",
1171 if (prom_getproperty(zsnode
, "reg",
1172 (char *) zsreg
, sizeof(zsreg
)) == -1) {
1173 prom_printf("SunZilog: Cannot map Zilog %d\n", chip
);
1176 /* XXX Looks like an off by one? */
1177 prom_apply_generic_ranges(bbnode
, cpunode
, zsreg
, 1);
1178 res
.start
= zsreg
[0].phys_addr
;
1179 res
.end
= res
.start
+ (8 - 1);
1180 res
.flags
= zsreg
[0].which_io
| IORESOURCE_IO
;
1181 mapped_addr
= sbus_ioremap(&res
, 0, 8, "Zilog Serial");
1186 #if 0 /* XXX When was this used? */
1187 if (prom_getintdefault(zsnode
, "slave", -1) != chipid
) {
1188 zsnode
= prom_getsibling(zsnode
);
1194 * "address" is only present on ports that OBP opened
1195 * (from Mitch Bradley's "Hitchhiker's Guide to OBP").
1199 if (prom_getproperty(zsnode
, "reg",
1200 (char *) zsreg
, sizeof(zsreg
)) == -1) {
1201 prom_printf("SunZilog: Cannot map Zilog %d\n", chip
);
1204 if (sparc_cpu_model
== sun4m
) /* Crude. Pass parent. XXX */
1205 prom_apply_obio_ranges(zsreg
, 1);
1206 res
.start
= zsreg
[0].phys_addr
;
1207 res
.end
= res
.start
+ (8 - 1);
1208 res
.flags
= zsreg
[0].which_io
| IORESOURCE_IO
;
1209 mapped_addr
= sbus_ioremap(&res
, 0, 8, "Zilog Serial");
1212 if (prom_getproperty(zsnode
, "intr",
1213 (char *) irq_info
, sizeof(irq_info
))
1214 % sizeof(struct linux_prom_irqs
)) {
1215 prom_printf("SunZilog: Cannot get IRQ property for Zilog %d.\n",
1219 if (zilog_irq
== -1) {
1220 zilog_irq
= irq_info
[0].pri
;
1221 } else if (zilog_irq
!= irq_info
[0].pri
) {
1222 /* XXX. Dumb. Should handle per-chip IRQ, for add-ons. */
1223 prom_printf("SunZilog: Inconsistent IRQ layout for Zilog %d.\n",
1228 return (struct zilog_layout
*) mapped_addr
;
1230 #endif /* !(CONFIG_SPARC64) */
1232 /* Get the address of the registers for SunZilog instance CHIP. */
1233 static struct zilog_layout
* __init
get_zs(int chip
, int node
)
1235 if (chip
< 0 || chip
>= NUM_SUNZILOG
) {
1236 prom_printf("SunZilog: Illegal chip number %d in get_zs.\n", chip
);
1240 #ifdef CONFIG_SPARC64
1241 return get_zs_sun4u(chip
, node
);
1244 if (sparc_cpu_model
== sun4
) {
1245 struct resource res
;
1247 /* Not probe-able, hard code it. */
1250 res
.start
= 0xf1000000;
1253 res
.start
= 0xf0000000;
1257 res
.end
= (res
.start
+ (8 - 1));
1258 res
.flags
= IORESOURCE_IO
;
1259 return (struct zilog_layout
*) sbus_ioremap(&res
, 0, 8, "SunZilog");
1262 return get_zs_sun4cmd(chip
, node
);
1266 #define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */
1268 static void sunzilog_put_char(struct zilog_channel
*channel
, unsigned char ch
)
1270 int loops
= ZS_PUT_CHAR_MAX_DELAY
;
1272 /* This is a timed polling loop so do not switch the explicit
1273 * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM
1276 unsigned char val
= sbus_readb(&channel
->control
);
1277 if (val
& Tx_BUF_EMP
) {
1284 sbus_writeb(ch
, &channel
->data
);
1291 static spinlock_t sunzilog_serio_lock
= SPIN_LOCK_UNLOCKED
;
1293 static int sunzilog_serio_write(struct serio
*serio
, unsigned char ch
)
1295 struct uart_sunzilog_port
*up
= serio
->driver
;
1296 unsigned long flags
;
1298 spin_lock_irqsave(&sunzilog_serio_lock
, flags
);
1300 sunzilog_put_char(ZILOG_CHANNEL_FROM_PORT(&up
->port
), ch
);
1302 spin_unlock_irqrestore(&sunzilog_serio_lock
, flags
);
1307 static int sunzilog_serio_open(struct serio
*serio
)
1309 unsigned long flags
;
1312 spin_lock_irqsave(&sunzilog_serio_lock
, flags
);
1313 if (serio
->private == NULL
) {
1314 serio
->private = (void *) -1L;
1318 spin_unlock_irqrestore(&sunzilog_serio_lock
, flags
);
1323 static void sunzilog_serio_close(struct serio
*serio
)
1325 unsigned long flags
;
1327 spin_lock_irqsave(&sunzilog_serio_lock
, flags
);
1328 serio
->private = NULL
;
1329 spin_unlock_irqrestore(&sunzilog_serio_lock
, flags
);
1332 #endif /* CONFIG_SERIO */
1335 sunzilog_console_write(struct console
*con
, const char *s
, unsigned int count
)
1337 struct uart_sunzilog_port
*up
= &sunzilog_port_table
[con
->index
];
1338 struct zilog_channel
*channel
= ZILOG_CHANNEL_FROM_PORT(&up
->port
);
1339 unsigned long flags
;
1342 spin_lock_irqsave(&up
->port
.lock
, flags
);
1343 for (i
= 0; i
< count
; i
++, s
++) {
1344 sunzilog_put_char(channel
, *s
);
1346 sunzilog_put_char(channel
, 13);
1349 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
1352 static int __init
sunzilog_console_setup(struct console
*con
, char *options
)
1354 struct uart_sunzilog_port
*up
= &sunzilog_port_table
[con
->index
];
1355 unsigned long flags
;
1358 printk("Console: ttyS%d (SunZilog)\n",
1359 (sunzilog_reg
.minor
- 64) + con
->index
);
1361 /* Get firmware console settings. */
1362 sunserial_console_termios(con
);
1364 /* Firmware console speed is limited to 150-->38400 baud so
1365 * this hackish cflag thing is OK.
1367 switch (con
->cflag
& CBAUD
) {
1368 case B150
: baud
= 150; break;
1369 case B300
: baud
= 300; break;
1370 case B600
: baud
= 600; break;
1371 case B1200
: baud
= 1200; break;
1372 case B2400
: baud
= 2400; break;
1373 case B4800
: baud
= 4800; break;
1374 default: case B9600
: baud
= 9600; break;
1375 case B19200
: baud
= 19200; break;
1376 case B38400
: baud
= 38400; break;
1379 brg
= BPS_TO_BRG(baud
, ZS_CLOCK
/ ZS_CLOCK_DIVISOR
);
1381 spin_lock_irqsave(&up
->port
.lock
, flags
);
1383 up
->curregs
[R15
] = BRKIE
;
1384 sunzilog_convert_to_zs(up
, con
->cflag
, 0, brg
);
1386 sunzilog_set_mctrl(&up
->port
, TIOCM_DTR
| TIOCM_RTS
);
1387 __sunzilog_startup(up
);
1389 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
1394 static struct console sunzilog_console
= {
1396 .write
= sunzilog_console_write
,
1397 .device
= uart_console_device
,
1398 .setup
= sunzilog_console_setup
,
1399 .flags
= CON_PRINTBUFFER
,
1401 .data
= &sunzilog_reg
,
1404 static int __init
sunzilog_console_init(void)
1408 if (con_is_present())
1411 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1412 int this_minor
= sunzilog_reg
.minor
+ i
;
1414 if ((this_minor
- 64) == (serial_console
- 1))
1417 if (i
== NUM_CHANNELS
)
1420 sunzilog_console
.index
= i
;
1421 sunzilog_port_table
[i
].flags
|= SUNZILOG_FLAG_IS_CONS
;
1422 register_console(&sunzilog_console
);
1427 * We scan the PROM tree recursively. This is the most reliable way
1428 * to find Zilog nodes on various platforms. However, we face an extreme
1429 * shortage of kernel stack, so we must be very careful. To that end,
1430 * we scan only to a certain depth, and we use a common property buffer
1431 * in the scan structure.
1433 #define ZS_PROPSIZE 128
1434 #define ZS_SCAN_DEPTH 5
1436 struct zs_probe_scan
{
1438 void (*scanner
)(struct zs_probe_scan
*t
, int node
);
1441 char prop
[ZS_PROPSIZE
];
1444 static int __inline__
sunzilog_node_ok(int node
, const char *name
, int len
)
1446 if (strncmp(name
, "zs", len
) == 0)
1448 /* Don't fold this procedure just yet. Compare to su_node_ok(). */
1452 static void __init
sunzilog_scan(struct zs_probe_scan
*t
, int node
)
1456 for (; node
!= 0; node
= prom_getsibling(node
)) {
1457 len
= prom_getproperty(node
, "name", t
->prop
, ZS_PROPSIZE
);
1459 continue; /* Broken PROM node */
1460 if (sunzilog_node_ok(node
, t
->prop
, len
)) {
1461 (*t
->scanner
)(t
, node
);
1463 if (t
->depth
< ZS_SCAN_DEPTH
) {
1465 sunzilog_scan(t
, prom_getchild(node
));
1472 static void __init
sunzilog_prepare(void)
1474 struct uart_sunzilog_port
*up
;
1475 struct zilog_layout
*rp
;
1481 for (channel
= 0; channel
< NUM_CHANNELS
; channel
++)
1482 spin_lock_init(&sunzilog_port_table
[channel
].port
.lock
);
1484 sunzilog_irq_chain
= up
= &sunzilog_port_table
[0];
1485 for (channel
= 0; channel
< NUM_CHANNELS
- 1; channel
++)
1486 up
[channel
].next
= &up
[channel
+ 1];
1487 up
[channel
].next
= NULL
;
1489 for (chip
= 0; chip
< NUM_SUNZILOG
; chip
++) {
1490 rp
= sunzilog_chip_regs
[chip
];
1491 up
[(chip
* 2) + 0].port
.membase
= (char *) &rp
->channelA
;
1492 up
[(chip
* 2) + 1].port
.membase
= (char *) &rp
->channelB
;
1495 up
[(chip
* 2) + 0].port
.iotype
= SERIAL_IO_MEM
;
1496 up
[(chip
* 2) + 0].port
.irq
= zilog_irq
;
1497 up
[(chip
* 2) + 0].port
.uartclk
= ZS_CLOCK
;
1498 up
[(chip
* 2) + 0].port
.fifosize
= 1;
1499 up
[(chip
* 2) + 0].port
.ops
= &sunzilog_pops
;
1500 up
[(chip
* 2) + 0].port
.type
= PORT_SUNZILOG
;
1501 up
[(chip
* 2) + 0].port
.flags
= 0;
1502 up
[(chip
* 2) + 0].port
.line
= (chip
* 2) + 0;
1503 up
[(chip
* 2) + 0].flags
|= SUNZILOG_FLAG_IS_CHANNEL_A
;
1506 up
[(chip
* 2) + 1].port
.iotype
= SERIAL_IO_MEM
;
1507 up
[(chip
* 2) + 1].port
.irq
= zilog_irq
;
1508 up
[(chip
* 2) + 1].port
.uartclk
= ZS_CLOCK
;
1509 up
[(chip
* 2) + 1].port
.fifosize
= 1;
1510 up
[(chip
* 2) + 1].port
.ops
= &sunzilog_pops
;
1511 up
[(chip
* 2) + 1].port
.type
= PORT_SUNZILOG
;
1512 up
[(chip
* 2) + 1].port
.flags
= 0;
1513 up
[(chip
* 2) + 1].port
.line
= (chip
* 2) + 1;
1514 up
[(chip
* 2) + 1].flags
|= 0;
1518 static void __init
sunzilog_init_kbdms(struct uart_sunzilog_port
*up
, int channel
)
1522 if (channel
== KEYBOARD_LINE
) {
1523 up
->flags
|= SUNZILOG_FLAG_CONS_KEYB
;
1524 up
->cflag
= B1200
| CS8
| CLOCAL
| CREAD
;
1527 up
->flags
|= SUNZILOG_FLAG_CONS_MOUSE
;
1528 up
->cflag
= B4800
| CS8
| CLOCAL
| CREAD
;
1531 printk(KERN_INFO
"zs%d at 0x%p (irq = %s) is a SunZilog\n",
1532 channel
, up
->port
.membase
, __irq_itoa(zilog_irq
));
1534 up
->curregs
[R15
] = BRKIE
;
1535 brg
= BPS_TO_BRG(baud
, ZS_CLOCK
/ ZS_CLOCK_DIVISOR
);
1536 sunzilog_convert_to_zs(up
, up
->cflag
, 0, brg
);
1539 memset(&up
->serio
, 0, sizeof(up
->serio
));
1541 up
->serio
.driver
= up
;
1543 up
->serio
.type
= SERIO_RS232
;
1544 if (channel
== KEYBOARD_LINE
) {
1545 up
->serio
.type
|= SERIO_SUNKBD
;
1546 up
->serio
.name
= "zskbd";
1548 up
->serio
.type
|= SERIO_SUN
;
1549 up
->serio
.name
= "zsms";
1551 up
->serio
.phys
= (channel
== KEYBOARD_LINE
?
1552 "zs/serio0" : "zs/serio1");
1554 up
->serio
.write
= sunzilog_serio_write
;
1555 up
->serio
.open
= sunzilog_serio_open
;
1556 up
->serio
.close
= sunzilog_serio_close
;
1558 serio_register_port(&up
->serio
);
1561 sunzilog_set_mctrl(&up
->port
, TIOCM_DTR
| TIOCM_RTS
);
1562 __sunzilog_startup(up
);
1565 static void __init
sunzilog_init_hw(void)
1569 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1570 struct uart_sunzilog_port
*up
= &sunzilog_port_table
[i
];
1571 struct zilog_channel
*channel
= ZILOG_CHANNEL_FROM_PORT(&up
->port
);
1572 unsigned long flags
;
1575 spin_lock_irqsave(&up
->port
.lock
, flags
);
1577 if (ZS_IS_CHANNEL_A(up
)) {
1578 write_zsreg(channel
, R9
, FHWRES
);
1580 (void) read_zsreg(channel
, R0
);
1583 if (i
== KEYBOARD_LINE
|| i
== MOUSE_LINE
) {
1584 sunzilog_init_kbdms(up
, i
);
1586 /* Normal serial TTY. */
1587 up
->parity_mask
= 0xff;
1588 up
->curregs
[R1
] = EXT_INT_ENAB
| INT_ALL_Rx
| TxINT_ENAB
;
1589 up
->curregs
[R4
] = PAR_EVEN
| X16CLK
| SB1
;
1590 up
->curregs
[R3
] = RxENAB
| Rx8
;
1591 up
->curregs
[R5
] = TxENAB
| Tx8
;
1592 up
->curregs
[R9
] = NV
| MIE
;
1593 up
->curregs
[R10
] = NRZ
;
1594 up
->curregs
[R11
] = TCBR
| RCBR
;
1596 brg
= BPS_TO_BRG(baud
, ZS_CLOCK
/ ZS_CLOCK_DIVISOR
);
1597 up
->curregs
[R12
] = (brg
& 0xff);
1598 up
->curregs
[R13
] = (brg
>> 8) & 0xff;
1599 up
->curregs
[R14
] = BRSRC
| BRENAB
;
1600 __load_zsregs(channel
, up
->curregs
);
1601 write_zsreg(channel
, R9
, up
->curregs
[R9
]);
1604 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
1608 static struct zilog_layout
* __init
get_zs(int chip
, int node
);
1610 static void __init
sunzilog_scan_probe(struct zs_probe_scan
*t
, int node
)
1612 sunzilog_chip_regs
[t
->devices
] = get_zs(t
->devices
, node
);
1616 static int __init
sunzilog_ports_init(void)
1618 struct zs_probe_scan scan
;
1621 printk(KERN_INFO
"Serial: Sun Zilog driver (%d chips).\n", NUM_SUNZILOG
);
1623 scan
.scanner
= sunzilog_scan_probe
;
1626 sunzilog_scan(&scan
, prom_getchild(prom_root_node
));
1630 if (request_irq(zilog_irq
, sunzilog_interrupt
, SA_SHIRQ
,
1631 "SunZilog", sunzilog_irq_chain
)) {
1632 prom_printf("SunZilog: Unable to register zs interrupt handler.\n");
1638 /* We can only init this once we have probed the Zilogs
1641 sunzilog_reg
.nr
= NUM_CHANNELS
;
1642 sunzilog_reg
.cons
= &sunzilog_console
;
1644 sunzilog_reg
.minor
= sunserial_current_minor
;
1645 sunserial_current_minor
+= NUM_CHANNELS
;
1647 ret
= uart_register_driver(&sunzilog_reg
);
1651 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1652 struct uart_sunzilog_port
*up
= &sunzilog_port_table
[i
];
1654 if (ZS_IS_KEYB(up
) || ZS_IS_MOUSE(up
))
1657 uart_add_one_port(&sunzilog_reg
, &up
->port
);
1664 static void __init
sunzilog_scan_count(struct zs_probe_scan
*t
, int node
)
1669 static int __init
sunzilog_ports_count(void)
1671 struct zs_probe_scan scan
;
1673 /* Sun4 Zilog setup is hard coded, no probing to do. */
1674 if (sparc_cpu_model
== sun4
)
1677 scan
.scanner
= sunzilog_scan_count
;
1681 sunzilog_scan(&scan
, prom_getchild(prom_root_node
));
1683 return scan
.devices
;
1686 static int __init
sunzilog_init(void)
1689 NUM_SUNZILOG
= sunzilog_ports_count();
1690 if (NUM_SUNZILOG
== 0)
1693 sunzilog_alloc_tables();
1695 sunzilog_ports_init();
1696 sunzilog_console_init();
1701 static void __exit
sunzilog_exit(void)
1705 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1706 struct uart_sunzilog_port
*up
= &sunzilog_port_table
[i
];
1708 if (ZS_IS_KEYB(up
) || ZS_IS_MOUSE(up
))
1711 uart_remove_one_port(&sunzilog_reg
, &up
->port
);
1714 uart_unregister_driver(&sunzilog_reg
);
1717 module_init(sunzilog_init
);
1718 module_exit(sunzilog_exit
);
1720 MODULE_AUTHOR("David S. Miller");
1721 MODULE_DESCRIPTION("Sun Zilog serial port driver");
1722 MODULE_LICENSE("GPL");