2 * linux/drivers/serial/serial98.c
4 * Driver for NEC PC-9801/PC-9821 standard serial ports
6 * Based on drivers/serial/8250.c, by Russell King.
7 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
9 * Copyright (C) 2002 Osamu Tomita <tomita@cinet.co.jp>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/tty.h>
20 #include <linux/ioport.h>
21 #include <linux/init.h>
22 #include <linux/serial.h>
23 #include <linux/console.h>
24 #include <linux/sysrq.h>
25 #include <linux/serial_reg.h>
26 #include <linux/delay.h>
30 #include <asm/pc9800.h>
31 #include <asm/pc9800_sca.h>
33 #if defined(CONFIG_SERIAL98_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
37 #include <linux/serial_core.h>
40 #define SERIAL98_ISR_PASS_LIMIT 256
41 #define SERIAL98_EXT 0x434
43 //#define RX_8251F 0x130 /* In: Receive buffer */
44 //#define TX_8251F 0x130 /* Out: Transmit buffer */
45 //#define LSR_8251F 0x132 /* In: Line Status Register */
46 //#define MSR_8251F 0x134 /* In: Modem Status Register */
47 #define IIR_8251F 0x136 /* In: Interrupt ID Register */
48 #define FCR_8251F 0x138 /* I/O: FIFO Control Register */
49 #define VFAST_8251F 0x13a /* I/O: VFAST mode Register */
51 #define CMD_8251F 0x32 /* Out: 8251 Command Resister */
52 #define IER2_8251F 0x34 /* I/O: Interrupt Enable Register */
53 #define IER1_8251F 0x35 /* I/O: Interrupt Enable Register */
54 #define IER1_CTL 0x37 /* Out: Interrupt Enable Register */
55 #define DIS_RXR_INT 0x00 /* disable RxRDY Interrupt */
56 #define ENA_RXR_INT 0x01 /* enable RxRDY Interrupt */
57 #define DIS_TXE_INT 0x02 /* disable TxEMPTY Interrupt */
58 #define ENA_TXE_INT 0x03 /* enable TxEMPTY Interrupt */
59 #define DIS_TXR_INT 0x04 /* disable TxRDY Interrupt */
60 #define ENA_TXR_INT 0x05 /* enable TxRDY Interrupt */
62 #define CMD_RESET 0x40 /* Reset Command */
63 #define CMD_RTS 0x20 /* Set RTS line */
64 #define CMD_CLR_ERR 0x10 /* Clear error flag */
65 #define CMD_BREAK 0x08 /* Send Break */
66 #define CMD_RXE 0x04 /* Enable receive */
67 #define CMD_DTR 0x02 /* Set DTR line */
68 #define CMD_TXE 0x01 /* Enable send */
69 #define CMD_DUMMY 0x00 /* Dummy Command */
71 #define VFAST_ENABLE 0x80 /* V.Fast mode Enable */
74 #define INTR_8251_TXRE 0x04
75 #define INTR_8251_TXEE 0x02
76 #define INTR_8251_RXRE 0x01
78 //#define PORT_8251_DATA 0
79 //#define PORT_8251_CMD 2
80 //#define PORT_8251_MOD 2
81 //#define PORT_8251_STS 2
83 #define STAT_8251_TXRDY 0x01
84 #define STAT_8251_RXRDY 0x02
85 #define STAT_8251_TXEMP 0x04
86 #define STAT_8251_PER 0x08
87 #define STAT_8251_OER 0x10
88 #define STAT_8251_FER 0x20
89 #define STAT_8251_BRK 0x40
90 #define STAT_8251_DSR 0x80
92 #define STAT_8251F_TXEMP 0x01
93 #define STAT_8251F_TXRDY 0x02
94 #define STAT_8251F_RXRDY 0x04
95 #define STAT_8251F_DSR 0x08
96 #define STAT_8251F_OER 0x10
97 #define STAT_8251F_PER 0x20
98 #define STAT_8251F_FER 0x40
99 #define STAT_8251F_BRK 0x80
101 #define STAT_8251F_TXEMP 0x01
102 #define STAT_8251F_TEMT 0x01
103 #define STAT_8251F_TXRDY 0x02
104 #define STAT_8251F_THRE 0x02
105 #define STAT_8251F_RXRDY 0x04
106 #define STAT_8251F_DSR 0x04
107 #define STAT_8251F_PER 0x08
108 #define STAT_8251F_OER 0x10
109 #define STAT_8251F_FER 0x20
110 #define STAT_8251F_BRK 0x40
114 * We wrap our port structure around the generic uart_port.
116 struct serial98_port
{
117 struct uart_port port
;
120 unsigned int lsr_break_flag
;
136 #ifdef CONFIG_SERIAL98_CONSOLE
138 serial98_console_write(struct console
*co
, const char *s
, unsigned int count
);
139 static int __init
serial98_console_setup(struct console
*co
, char *options
);
141 extern struct uart_driver serial98_reg
;
142 static struct console serial98_console
= {
144 .write
= serial98_console_write
,
145 .device
= uart_console_device
,
146 .setup
= serial98_console_setup
,
147 .flags
= CON_PRINTBUFFER
,
149 .data
= &serial98_reg
,
152 #define SERIAL98_CONSOLE &serial98_console
154 #define SERIAL98_CONSOLE NULL
157 static struct uart_driver serial98_reg
= {
158 .owner
= THIS_MODULE
,
159 .driver_name
= "serial98",
164 .cons
= SERIAL98_CONSOLE
,
167 static int serial98_clk
;
168 static char type_str
[48];
170 #define PORT98 ((struct serial98_port *)port)
171 #define PORT (PORT98->port)
173 static void serial98_fifo_enable(struct uart_port
*port
, int enable
)
177 if (PORT
.type
== PORT_FIFO_PC98
|| PORT
.type
== PORT_VFAST_PC98
) {
178 fcr
= inb(FCR_8251F
);
180 fcr
|= UART_FCR_ENABLE_FIFO
;
182 fcr
&= ~UART_FCR_ENABLE_FIFO
;
183 outb(fcr
, FCR_8251F
);
189 outb(0, 0x5f); /* wait */
195 static void serial98_cmd_out(struct uart_port
*port
, unsigned char cmd
)
197 serial98_fifo_enable(port
, 0);
198 outb(cmd
, CMD_8251F
);
199 serial98_fifo_enable(port
, 1);
202 static void serial98_mode_set(struct uart_port
*port
)
204 serial98_cmd_out(port
, CMD_DUMMY
);
205 serial98_cmd_out(port
, CMD_DUMMY
);
206 serial98_cmd_out(port
, CMD_DUMMY
);
207 serial98_cmd_out(port
, CMD_RESET
);
208 serial98_cmd_out(port
, PORT98
->mode
);
211 static unsigned char serial98_msr_in(struct uart_port
*port
)
217 spin_lock_irqsave(&PORT
.lock
, flags
);
218 if (PORT
.type
== PORT_FIFO_PC98
|| PORT
.type
== PORT_VFAST_PC98
) {
219 PORT98
->msr
= inb(PORT
.iobase
+ 4);
228 PORT98
->msr
|= UART_MSR_RI
;
234 PORT98
->msr
= ((PORT98
->msr
^ tmp
) >> 4) | tmp
;
237 spin_unlock_irqrestore(&PORT
.lock
, flags
);
241 static void serial98_stop_tx(struct uart_port
*port
, unsigned int tty_stop
)
243 unsigned int ier
= inb(IER1_8251F
);
245 ier
&= ~(INTR_8251_TXRE
| INTR_8251_TXEE
);
246 outb(ier
, IER1_8251F
);
249 static void serial98_start_tx(struct uart_port
*port
, unsigned int tty_start
)
251 unsigned int ier
= inb(IER1_8251F
);
253 ier
|= INTR_8251_TXRE
| INTR_8251_TXEE
;
254 outb(ier
, IER1_8251F
);
257 static void serial98_stop_rx(struct uart_port
*port
)
259 PORT
.read_status_mask
&= ~PORT98
->dr
;
260 outb(DIS_RXR_INT
, IER1_CTL
);
263 static void serial98_enable_ms(struct uart_port
*port
)
265 outb(PORT98
->ier
| 0x80, IER2_8251F
);
268 static void serial98_rx_chars(struct uart_port
*port
, int *status
,
269 struct pt_regs
*regs
)
271 struct tty_struct
*tty
= PORT
.info
->tty
;
276 if (unlikely(tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)) {
277 tty
->flip
.work
.func((void *)tty
);
278 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
279 return; // if TTY_DONT_FLIP is set
281 ch
= inb(PORT
.iobase
);
282 *tty
->flip
.char_buf_ptr
= ch
;
283 *tty
->flip
.flag_buf_ptr
= TTY_NORMAL
;
286 if (unlikely(*status
& (PORT98
->brk
| PORT98
->pe
|
287 PORT98
->fe
| PORT98
->oe
))) {
289 * For statistics only
291 if (*status
& PORT98
->brk
) {
292 *status
&= ~(PORT98
->fe
| PORT98
->pe
);
295 * We do the SysRQ and SAK checking
296 * here because otherwise the break
297 * may get masked by ignore_status_mask
298 * or read_status_mask.
300 if (uart_handle_break(&PORT
))
302 } else if (*status
& PORT98
->pe
)
303 PORT
.icount
.parity
++;
304 else if (*status
& PORT98
->fe
)
306 if (*status
& PORT98
->oe
)
307 PORT
.icount
.overrun
++;
310 * Mask off conditions which should be ingored.
312 *status
&= PORT
.read_status_mask
;
314 #ifdef CONFIG_SERIAL98_CONSOLE
315 if (PORT
.line
== PORT
.cons
->index
) {
316 /* Recover the break flag from console xmit */
317 *status
|= PORT98
->lsr_break_flag
;
318 PORT98
->lsr_break_flag
= 0;
321 if (*status
& PORT98
->brk
) {
322 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
323 } else if (*status
& PORT98
->pe
)
324 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
325 else if (*status
& PORT98
->fe
)
326 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
328 if (uart_handle_sysrq_char(&PORT
, ch
, regs
))
330 if ((*status
& PORT
.ignore_status_mask
) == 0) {
331 tty
->flip
.flag_buf_ptr
++;
332 tty
->flip
.char_buf_ptr
++;
335 if ((*status
& PORT98
->oe
) &&
336 tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
338 * Overrun is special, since it's reported
339 * immediately, and doesn't affect the current
342 *tty
->flip
.flag_buf_ptr
= TTY_OVERRUN
;
343 tty
->flip
.flag_buf_ptr
++;
344 tty
->flip
.char_buf_ptr
++;
348 *status
= inb(PORT
.iobase
+ 2);
349 } while ((*status
& PORT98
->rxchk
) && (max_count
-- > 0));
350 tty_flip_buffer_push(tty
);
353 static void serial98_tx_chars(struct uart_port
*port
)
355 struct circ_buf
*xmit
= &PORT
.info
->xmit
;
359 outb(PORT
.x_char
, PORT
.iobase
);
364 if (uart_circ_empty(xmit
) || uart_tx_stopped(&PORT
)) {
365 serial98_stop_tx(port
, 0);
369 count
= PORT
.fifosize
;
371 outb(xmit
->buf
[xmit
->tail
], PORT
.iobase
);
372 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
374 if (uart_circ_empty(xmit
))
376 } while (--count
> 0);
378 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
379 uart_write_wakeup(&PORT
);
381 if (uart_circ_empty(xmit
))
382 serial98_stop_tx(&PORT
, 0);
385 static void serial98_modem_status(struct uart_port
*port
)
389 status
= serial98_msr_in(port
);
391 if ((status
& UART_MSR_ANY_DELTA
) == 0)
394 if (status
& UART_MSR_TERI
)
396 if (status
& UART_MSR_DDSR
)
398 if (status
& UART_MSR_DDCD
)
399 uart_handle_dcd_change(&PORT
, status
& UART_MSR_DCD
);
400 if (status
& UART_MSR_DCTS
)
401 uart_handle_cts_change(&PORT
, status
& UART_MSR_CTS
);
403 wake_up_interruptible(&PORT
.info
->delta_msr_wait
);
406 static void serial98_int(int irq
, void *port
, struct pt_regs
*regs
)
410 spin_lock(&PORT
.lock
);
411 status
= inb(PORT
.iobase
+ 2);
412 if (status
& PORT98
->rxrdy
) {
413 serial98_rx_chars(port
, &status
, regs
);
415 serial98_modem_status(port
);
416 if (status
& PORT98
->txrdy
) {
417 serial98_tx_chars(port
);
419 spin_unlock(&PORT
.lock
);
422 static unsigned int serial98_tx_empty(struct uart_port
*port
)
425 unsigned int ret
= 0;
427 spin_lock_irqsave(&PORT
.lock
, flags
);
428 if (inb(PORT
.iobase
+ 2) & PORT98
->txemp
)
431 spin_unlock_irqrestore(&PORT
.lock
, flags
);
435 static unsigned int serial98_get_mctrl(struct uart_port
*port
)
437 unsigned char status
;
438 unsigned int ret
= 0;
440 status
= serial98_msr_in(port
);
441 if (status
& UART_MSR_DCD
)
443 if (status
& UART_MSR_RI
)
445 if (status
& UART_MSR_DSR
)
447 if (status
& UART_MSR_CTS
)
452 static void serial98_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
455 if (mctrl
& TIOCM_RTS
)
456 PORT98
->cmd
|= CMD_RTS
;
458 if (mctrl
& TIOCM_DTR
)
459 PORT98
->cmd
|= CMD_DTR
;
461 serial98_cmd_out(port
, PORT98
->cmd
);
464 static void serial98_break_ctl(struct uart_port
*port
, int break_state
)
468 spin_lock_irqsave(&PORT
.lock
, flags
);
469 if (break_state
== -1)
470 PORT98
->cmd
|= CMD_BREAK
;
472 PORT98
->cmd
&= ~CMD_BREAK
;
474 serial98_cmd_out(port
, PORT98
->cmd
);
475 spin_unlock_irqrestore(&PORT
.lock
, flags
);
478 static int serial98_startup(struct uart_port
*port
)
482 if (PORT
.type
== PORT_8251_PC98
) {
485 serial98_mode_set(port
);
486 outb(DIS_RXR_INT
, IER1_CTL
);
487 outb(DIS_TXE_INT
, IER1_CTL
);
488 outb(DIS_TXR_INT
, IER1_CTL
);
490 serial98_mode_set(port
);
494 * Clear the FIFO buffers and disable them.
495 * (they will be reeanbled in set_termios())
497 if (PORT
.type
== PORT_FIFO_PC98
|| PORT
.type
== PORT_VFAST_PC98
) {
498 outb(UART_FCR_ENABLE_FIFO
, FCR_8251F
);
499 outb((UART_FCR_ENABLE_FIFO
500 | UART_FCR_CLEAR_RCVR
501 | UART_FCR_CLEAR_XMIT
), FCR_8251F
);
505 /* Clear the interrupt registers. */
508 if (PORT
.type
== PORT_FIFO_PC98
|| PORT
.type
== PORT_VFAST_PC98
) {
510 inb(PORT
.iobase
+ 2);
511 inb(PORT
.iobase
+ 4);
512 inb(PORT
.iobase
+ 6);
515 /* Allocate the IRQ */
516 retval
= request_irq(PORT
.irq
, serial98_int
, 0,
517 serial98_reg
.driver_name
, port
);
522 * Now, initialize the UART
525 serial98_mode_set(port
);
527 serial98_cmd_out(port
, PORT98
->cmd
);
531 * Finally, enable interrupts
533 outb(0x00, IER2_8251F
);
534 outb(ENA_RXR_INT
, IER1_CTL
);
537 * And clear the interrupt registers again for luck.
541 if (PORT
.type
== PORT_FIFO_PC98
|| PORT
.type
== PORT_VFAST_PC98
) {
543 inb(PORT
.iobase
+ 2);
544 inb(PORT
.iobase
+ 4);
545 inb(PORT
.iobase
+ 6);
551 static void serial98_shutdown(struct uart_port
*port
)
556 * disable all interrupts
558 spin_lock_irqsave(&PORT
.lock
, flags
);
559 if (PORT
.type
== PORT_VFAST_PC98
)
560 outb(0, VFAST_8251F
); /* V.FAST mode off */
562 /* disnable all modem status interrupt */
563 outb(0x80, IER2_8251F
);
565 /* disnable TX/RX interrupt */
566 outb(0x00, IER2_8251F
);
567 outb(DIS_RXR_INT
, IER1_CTL
);
568 outb(DIS_TXE_INT
, IER1_CTL
);
569 outb(DIS_TXR_INT
, IER1_CTL
);
572 spin_unlock_irqrestore(&PORT
.lock
, flags
);
577 free_irq(PORT
.irq
, port
);
579 /* disable break condition and disable the port */
580 serial98_mode_set(port
);
583 if (PORT
.type
== PORT_FIFO_PC98
|| PORT
.type
== PORT_VFAST_PC98
) {
584 outb((UART_FCR_ENABLE_FIFO
585 | UART_FCR_CLEAR_RCVR
586 | UART_FCR_CLEAR_XMIT
), FCR_8251F
);
594 serial98_set_termios(struct uart_port
*port
, struct termios
*termios
,
597 unsigned char stopbit
, cval
, fcr
= 0, ier
= 0;
599 unsigned int baud
, quot
;
602 switch (termios
->c_cflag
& CSIZE
) {
619 if (termios
->c_cflag
& CSTOPB
)
621 if (termios
->c_cflag
& PARENB
)
623 if (!(termios
->c_cflag
& PARODD
))
627 * Ask the core to calculate the divisor for us.
629 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
630 quot
= uart_get_divisor(port
, baud
);
632 if (PORT
.type
== PORT_FIFO_PC98
|| PORT
.type
== PORT_VFAST_PC98
) {
633 if ((PORT
.uartclk
/ quot
) < (2400 * 16))
634 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_1
;
636 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_8
;
640 * Ok, we're now changing the port state. Do it with
641 * interrupts disabled.
643 spin_lock_irqsave(&PORT
.lock
, flags
);
646 * Update the per-port timeout.
648 uart_update_timeout(port
, termios
->c_cflag
, baud
);
650 PORT
.read_status_mask
= PORT98
->oe
| PORT98
->txemp
| PORT98
->dr
;
651 if (termios
->c_iflag
& INPCK
)
652 PORT
.read_status_mask
|= PORT98
->fe
| PORT98
->pe
;
654 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
655 PORT
.read_status_mask
|= PORT98
->brk
;
657 * Characters to ignore
659 PORT
.ignore_status_mask
= 0;
660 if (termios
->c_iflag
& IGNPAR
)
661 PORT
.ignore_status_mask
|= PORT98
->fe
| PORT98
->pe
;
663 if (termios
->c_iflag
& IGNBRK
) {
664 PORT
.ignore_status_mask
|= PORT98
->brk
;
666 * If we're ignoring parity and break indicators,
667 * ignore overruns too (for real raw support).
669 if (termios
->c_iflag
& IGNPAR
)
670 PORT
.ignore_status_mask
|= PORT98
->oe
;
674 * ignore all characters if CREAD is not set
676 if ((termios
->c_cflag
& CREAD
) == 0)
677 PORT
.ignore_status_mask
|= PORT98
->dr
;
680 * CTS flow control flag and modem status interrupts
682 if (PORT
.flags
& UPF_HARDPPS_CD
)
683 ier
|= 0x80; /* enable modem status interrupt */
684 if (termios
->c_cflag
& CRTSCTS
) {
685 ier
|= 0x08; /* enable CTS interrupt */
686 ier
|= 0x80; /* enable modem status interrupt */
688 if (!(termios
->c_cflag
& CLOCAL
)) {
689 ier
|= 0x20; /* enable CD interrupt */
690 ier
|= 0x80; /* enable modem status interrupt */
695 serial98_mode_set(port
);
696 if (PORT
.type
== PORT_VFAST_PC98
&& quot
<= 48) {
700 outb(quot
| VFAST_ENABLE
, VFAST_8251F
);
705 if (PORT
.type
== PORT_VFAST_PC98
)
706 outb(0, VFAST_8251F
); /* V.FAST mode off */
708 outb(quot
& 0xff, 0x75); /* LS of divisor */
709 outb(quot
>> 8, 0x75); /* MS of divisor */
712 if (fcr
& UART_FCR_ENABLE_FIFO
) {
713 outb(UART_FCR_ENABLE_FIFO
, FCR_8251F
);
714 outb(fcr
, FCR_8251F
);
719 serial98_cmd_out(port
, PORT98
->cmd
);
721 /* enable interrupts */
722 outb(0x00, IER2_8251F
);
723 outb(ENA_RXR_INT
, IER1_CTL
);
724 spin_unlock_irqrestore(&PORT
.lock
, flags
);
727 static const char *serial98_type(struct uart_port
*port
)
733 p
= "PC98 onboard legacy 8251";
736 p
= "PC98 onboard max 19200bps";
739 p
= "PC98 onboard with FIFO";
741 case PORT_VFAST_PC98
:
742 p
= "PC98 onboard V.FAST";
745 p
= "PC-9861K RS-232C ext. board";
747 case PORT_PC9801_101
:
748 p
= "PC-9801-101 RS-232C ext. board";
754 sprintf(type_str
, "%s Clock %dMHz", p
, serial98_clk
);
758 /* Release the region(s) being used by 'port' */
759 static void serial98_release_port(struct uart_port
*port
)
762 case PORT_VFAST_PC98
:
763 release_region(PORT
.iobase
+ 0xa, 1);
765 release_region(PORT
.iobase
+ 8, 1);
766 release_region(PORT
.iobase
+ 6, 1);
767 release_region(PORT
.iobase
+ 4, 1);
768 release_region(PORT
.iobase
+ 2, 1);
769 release_region(PORT
.iobase
, 1);
771 release_region(SERIAL98_EXT
, 1);
772 release_region(0x34, 1);
774 release_region(0x32, 1);
775 release_region(0x30, 1);
779 /* Request the region(s) being used by 'port' */
780 #define REQ_REGION98(base) (request_region((base), 1, serial98_reg.driver_name))
781 static int serial98_request_region(unsigned int type
)
783 if (!REQ_REGION98(0x30))
785 if (REQ_REGION98(0x32)) {
786 if (type
== PORT_8251_PC98
)
788 if (REQ_REGION98(0x34)) {
789 if (REQ_REGION98(SERIAL98_EXT
)) {
792 if (type
== PORT_19K_PC98
)
794 for (base
= 0x130; base
<= 0x138; base
+= 2) {
795 if (!REQ_REGION98(base
)) {
800 if (type
== PORT_FIFO_PC98
)
802 if (type
== PORT_VFAST_PC98
) {
803 if (REQ_REGION98(0x13a))
807 while (base
>= 0x130) {
808 release_region(base
, 1);
811 release_region(SERIAL98_EXT
, 1);
813 release_region(0x34, 1);
815 release_region(0x32, 1);
817 release_region(0x30, 1);
821 static int serial98_request_port(struct uart_port
*port
)
823 return serial98_request_region(PORT
.type
);
827 * Configure/autoconfigure the port.
829 static void serial98_config_port(struct uart_port
*port
, int flags
)
831 if (flags
& UART_CONFIG_TYPE
)
832 PORT
.type
= PORT98
->type
;
836 * verify the new serial_struct (for TIOCSSERIAL).
838 static int serial98_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
841 case PORT_VFAST_PC98
:
845 /* not implemented yet
847 case PORT_PC9801_101:
854 if (ser
->irq
< 0 || ser
->irq
>= NR_IRQS
)
856 if (ser
->baud_base
< 9600)
861 static struct uart_ops serial98_ops
= {
862 .tx_empty
= serial98_tx_empty
,
863 .set_mctrl
= serial98_set_mctrl
,
864 .get_mctrl
= serial98_get_mctrl
,
865 .stop_tx
= serial98_stop_tx
,
866 .start_tx
= serial98_start_tx
,
867 .stop_rx
= serial98_stop_rx
,
868 .enable_ms
= serial98_enable_ms
,
869 .break_ctl
= serial98_break_ctl
,
870 .startup
= serial98_startup
,
871 .shutdown
= serial98_shutdown
,
872 .set_termios
= serial98_set_termios
,
873 .type
= serial98_type
,
874 .release_port
= serial98_release_port
,
875 .request_port
= serial98_request_port
,
876 .config_port
= serial98_config_port
,
877 .verify_port
= serial98_verify_port
,
880 static struct serial98_port serial98_ports
[SERIAL98_NR
] = {
884 .iotype
= SERIAL_IO_PORT
,
887 .ops
= &serial98_ops
,
888 .flags
= ASYNC_BOOT_AUTOCONF
,
891 .rxchk
= STAT_8251_RXRDY
,
892 .txemp
= STAT_8251_TXEMP
,
893 .txrdy
= STAT_8251_TXRDY
,
894 .rxrdy
= STAT_8251_RXRDY
,
895 .brk
= STAT_8251_BRK
,
903 #ifdef CONFIG_SERIAL98_CONSOLE
905 #define BOTH_EMPTY (PORT98->txemp | PORT98->txrdy)
908 * Wait for transmitter & holding register to empty
910 static inline void wait_for_xmitr(struct uart_port
*port
)
912 unsigned int status
, tmout
= 10000;
914 /* Wait up to 10ms for the character(s) to be sent. */
916 status
= inb(PORT
.iobase
+ 2);
918 if (status
& PORT98
->brk
)
919 PORT98
->lsr_break_flag
= PORT98
->brk
;
924 } while ((status
& BOTH_EMPTY
) != BOTH_EMPTY
);
926 /* Wait up to 1s for flow control if necessary */
927 if (PORT
.flags
& UPF_CONS_FLOW
) {
930 ((serial98_msr_in(port
) & UART_MSR_CTS
) == 0))
936 * Print a string to the serial port trying not to disturb
937 * any possible real use of the port...
939 * The console_lock must be held when we get here.
942 serial98_console_write(struct console
*co
, const char *s
, unsigned int count
)
944 struct uart_port
*port
= (struct uart_port
*)&serial98_ports
[co
->index
];
945 unsigned int ier1
, ier2
;
949 * First save the UER then disable the interrupts
951 ier1
= inb(IER1_8251F
);
952 ier2
= inb(IER2_8251F
);
953 /* disnable all modem status interrupt */
954 outb(0x80, IER2_8251F
);
956 /* disnable TX/RX interrupt */
957 outb(0x00, IER2_8251F
);
958 outb(DIS_RXR_INT
, IER1_CTL
);
959 outb(DIS_TXE_INT
, IER1_CTL
);
960 outb(DIS_TXR_INT
, IER1_CTL
);
963 * Now, do each character
965 for (i
= 0; i
< count
; i
++, s
++) {
966 wait_for_xmitr(port
);
969 * Send the character out.
970 * If a LF, also do CR...
972 outb(*s
, PORT
.iobase
);
974 wait_for_xmitr(port
);
975 outb(13, PORT
.iobase
);
980 * Finally, wait for transmitter to become empty
981 * and restore the IER
983 wait_for_xmitr(port
);
985 /* restore TX/RX interrupt */
986 outb(0x00, IER2_8251F
);
988 outb(ENA_RXR_INT
, IER1_CTL
);
990 outb(ENA_TXE_INT
, IER1_CTL
);
992 outb(ENA_TXR_INT
, IER1_CTL
);
994 /* restore modem status interrupt */
995 outb(ier2
, IER2_8251F
);
998 static int __init
serial98_console_setup(struct console
*co
, char *options
)
1000 struct uart_port
*port
;
1007 * Check whether an invalid uart number has been specified, and
1008 * if so, search for the first available port that does have
1011 if (co
->index
>= SERIAL98_NR
)
1013 port
= &serial98_ports
[co
->index
].port
;
1018 spin_lock_init(&port
->lock
);
1021 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1023 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
1026 void __init
serial98_console_init(void)
1028 register_console(&serial98_console
);
1031 #endif /* CONFIG_SERIAL98_CONSOLE */
1034 static int __init
serial98_init(void)
1037 unsigned char iir1
, iir2
;
1039 if (PC9800_8MHz_P()) {
1041 serial98_ports
[0].port
.uartclk
= 374400 * 16;
1044 serial98_ports
[0].port
.uartclk
= 460800 * 16;
1047 printk(KERN_INFO
"serial98: PC-9801 standard serial port driver Version 0.1alpha\n");
1048 serial98_ports
[0].type
= PORT_8251_PC98
;
1049 /* Check FIFO exist */
1050 iir1
= inb(IIR_8251F
);
1051 iir2
= inb(IIR_8251F
);
1052 if ((iir1
& 0x40) != (iir2
& 0x40) && (iir1
& 0x20) == (iir2
& 0x20)) {
1053 serial98_ports
[0].port
.iobase
= 0x130;
1054 serial98_ports
[0].port
.fifosize
= 16;
1055 serial98_ports
[0].rxchk
= STAT_8251F_DSR
;
1056 serial98_ports
[0].txemp
= STAT_8251F_TXEMP
;
1057 serial98_ports
[0].txrdy
= STAT_8251F_TXRDY
;
1058 serial98_ports
[0].rxrdy
= STAT_8251F_RXRDY
;
1059 serial98_ports
[0].brk
= STAT_8251F_BRK
;
1060 serial98_ports
[0].fe
= STAT_8251F_FER
;
1061 serial98_ports
[0].oe
= STAT_8251F_OER
;
1062 serial98_ports
[0].pe
= STAT_8251F_PER
;
1063 serial98_ports
[0].dr
= STAT_8251F_DSR
;
1065 if (*(unsigned char*)__va(PC9821SCA_RSFLAGS
) & 0x10)
1066 serial98_ports
[0].type
= PORT_VFAST_PC98
;
1068 outb(serial98_ports
[0].ext
| 0x40, SERIAL98_EXT
);
1069 serial98_ports
[0].port
.uartclk
*= 4;
1070 serial98_ports
[0].type
= PORT_FIFO_PC98
;
1072 } else if ((serial98_ports
[0].ext
= inb(SERIAL98_EXT
)) != 0xff) {
1073 outb(serial98_ports
[0].ext
| 0x40, SERIAL98_EXT
);
1074 if (inb(SERIAL98_EXT
) == (serial98_ports
[0].ext
| 0x40)) {
1075 serial98_ports
[0].port
.uartclk
*= 4;
1076 serial98_ports
[0].type
= PORT_19K_PC98
;
1078 serial98_ops
.enable_ms
= NULL
;
1079 outb(serial98_ports
[0].ext
, SERIAL98_EXT
);
1083 if (serial98_request_region(serial98_ports
[0].type
))
1086 ret
= uart_register_driver(&serial98_reg
);
1090 for (i
= 0; i
< SERIAL98_NR
; i
++) {
1091 uart_add_one_port(&serial98_reg
,
1092 (struct uart_port
*)&serial98_ports
[i
]);
1099 static void __exit
serial98_exit(void)
1103 if (serial98_ports
[0].type
== PORT_19K_PC98
1104 || serial98_ports
[0].type
== PORT_FIFO_PC98
)
1105 outb(serial98_ports
[0].ext
, SERIAL98_EXT
);
1107 for (i
= 0; i
< SERIAL98_NR
; i
++) {
1108 uart_remove_one_port(&serial98_reg
,
1109 (struct uart_port
*)&serial98_ports
[i
]);
1112 uart_unregister_driver(&serial98_reg
);
1115 module_init(serial98_init
);
1116 module_exit(serial98_exit
);
1118 MODULE_AUTHOR("Osamu Tomita <tomita@cinet.co.jp>");
1119 MODULE_DESCRIPTION("PC-9801 standard serial port driver Version 0.1alpha");
1120 MODULE_LICENSE("GPL");