18 #if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
22 #include <linux/module.h>
28 #include <linux/pci.h>
29 #include <linux/serial_core.h>
30 #include <linux/serial.h>
31 #include <linux/tty.h>
36 static char *serial_version =
"1.11";
37 static char *serial_name =
"TX39/49 Serial driver";
39 #define PASS_LIMIT 256
41 #if !defined(CONFIG_SERIAL_TXX9_STDSERIAL)
43 #define TXX9_TTY_NAME "ttyTX"
44 #define TXX9_TTY_MINOR_START 196
45 #define TXX9_TTY_MAJOR 204
48 #define TXX9_TTY_NAME "ttyS"
49 #define TXX9_TTY_MINOR_START 64
50 #define TXX9_TTY_MAJOR TTY_MAJOR
54 #define UPF_TXX9_HAVE_CTS_LINE UPF_BUGGY_UART
55 #define UPF_TXX9_USE_SCLK UPF_MAGIC_MULTIPLIER
59 #define ENABLE_SERIAL_TXX9_PCI
65 #define UART_NR CONFIG_SERIAL_TXX9_NR_UARTS
72 #define TXX9_REGION_SIZE 0x24
75 #define TXX9_SILCR 0x00
76 #define TXX9_SIDICR 0x04
77 #define TXX9_SIDISR 0x08
78 #define TXX9_SICISR 0x0c
79 #define TXX9_SIFCR 0x10
80 #define TXX9_SIFLCR 0x14
81 #define TXX9_SIBGR 0x18
82 #define TXX9_SITFIFO 0x1c
83 #define TXX9_SIRFIFO 0x20
86 #define TXX9_SILCR_SCS_MASK 0x00000060
87 #define TXX9_SILCR_SCS_IMCLK 0x00000000
88 #define TXX9_SILCR_SCS_IMCLK_BG 0x00000020
89 #define TXX9_SILCR_SCS_SCLK 0x00000040
90 #define TXX9_SILCR_SCS_SCLK_BG 0x00000060
91 #define TXX9_SILCR_UEPS 0x00000010
92 #define TXX9_SILCR_UPEN 0x00000008
93 #define TXX9_SILCR_USBL_MASK 0x00000004
94 #define TXX9_SILCR_USBL_1BIT 0x00000000
95 #define TXX9_SILCR_USBL_2BIT 0x00000004
96 #define TXX9_SILCR_UMODE_MASK 0x00000003
97 #define TXX9_SILCR_UMODE_8BIT 0x00000000
98 #define TXX9_SILCR_UMODE_7BIT 0x00000001
101 #define TXX9_SIDICR_TDE 0x00008000
102 #define TXX9_SIDICR_RDE 0x00004000
103 #define TXX9_SIDICR_TIE 0x00002000
104 #define TXX9_SIDICR_RIE 0x00001000
105 #define TXX9_SIDICR_SPIE 0x00000800
106 #define TXX9_SIDICR_CTSAC 0x00000600
107 #define TXX9_SIDICR_STIE_MASK 0x0000003f
108 #define TXX9_SIDICR_STIE_OERS 0x00000020
109 #define TXX9_SIDICR_STIE_CTSS 0x00000010
110 #define TXX9_SIDICR_STIE_RBRKD 0x00000008
111 #define TXX9_SIDICR_STIE_TRDY 0x00000004
112 #define TXX9_SIDICR_STIE_TXALS 0x00000002
113 #define TXX9_SIDICR_STIE_UBRKD 0x00000001
116 #define TXX9_SIDISR_UBRK 0x00008000
117 #define TXX9_SIDISR_UVALID 0x00004000
118 #define TXX9_SIDISR_UFER 0x00002000
119 #define TXX9_SIDISR_UPER 0x00001000
120 #define TXX9_SIDISR_UOER 0x00000800
121 #define TXX9_SIDISR_ERI 0x00000400
122 #define TXX9_SIDISR_TOUT 0x00000200
123 #define TXX9_SIDISR_TDIS 0x00000100
124 #define TXX9_SIDISR_RDIS 0x00000080
125 #define TXX9_SIDISR_STIS 0x00000040
126 #define TXX9_SIDISR_RFDN_MASK 0x0000001f
129 #define TXX9_SICISR_OERS 0x00000020
130 #define TXX9_SICISR_CTSS 0x00000010
131 #define TXX9_SICISR_RBRKD 0x00000008
132 #define TXX9_SICISR_TRDY 0x00000004
133 #define TXX9_SICISR_TXALS 0x00000002
134 #define TXX9_SICISR_UBRKD 0x00000001
137 #define TXX9_SIFCR_SWRST 0x00008000
138 #define TXX9_SIFCR_RDIL_MASK 0x00000180
139 #define TXX9_SIFCR_RDIL_1 0x00000000
140 #define TXX9_SIFCR_RDIL_4 0x00000080
141 #define TXX9_SIFCR_RDIL_8 0x00000100
142 #define TXX9_SIFCR_RDIL_12 0x00000180
143 #define TXX9_SIFCR_RDIL_MAX 0x00000180
144 #define TXX9_SIFCR_TDIL_MASK 0x00000018
145 #define TXX9_SIFCR_TDIL_MASK 0x00000018
146 #define TXX9_SIFCR_TDIL_1 0x00000000
147 #define TXX9_SIFCR_TDIL_4 0x00000001
148 #define TXX9_SIFCR_TDIL_8 0x00000010
149 #define TXX9_SIFCR_TDIL_MAX 0x00000010
150 #define TXX9_SIFCR_TFRST 0x00000004
151 #define TXX9_SIFCR_RFRST 0x00000002
152 #define TXX9_SIFCR_FRSTE 0x00000001
153 #define TXX9_SIO_TX_FIFO 8
154 #define TXX9_SIO_RX_FIFO 16
157 #define TXX9_SIFLCR_RCS 0x00001000
158 #define TXX9_SIFLCR_TES 0x00000800
159 #define TXX9_SIFLCR_RTSSC 0x00000200
160 #define TXX9_SIFLCR_RSDE 0x00000100
161 #define TXX9_SIFLCR_TSDE 0x00000080
162 #define TXX9_SIFLCR_RTSTL_MASK 0x0000001e
163 #define TXX9_SIFLCR_RTSTL_MAX 0x0000001e
164 #define TXX9_SIFLCR_TBRK 0x00000001
167 #define TXX9_SIBGR_BCLK_MASK 0x00000300
168 #define TXX9_SIBGR_BCLK_T0 0x00000000
169 #define TXX9_SIBGR_BCLK_T2 0x00000100
170 #define TXX9_SIBGR_BCLK_T4 0x00000200
171 #define TXX9_SIBGR_BCLK_T6 0x00000300
172 #define TXX9_SIBGR_BRD_MASK 0x000000ff
176 switch (up->
port.iotype) {
180 return inl(up->
port.iobase + offset);
187 switch (up->
port.iotype) {
192 outl(value, up->
port.iobase + offset);
198 sio_mask(
struct uart_txx9_port *up,
int offset,
unsigned int value)
200 sio_out(up, offset, sio_in(up, offset) & ~value);
203 sio_set(
struct uart_txx9_port *up,
int offset,
unsigned int value)
205 sio_out(up, offset, sio_in(up, offset) | value);
214 else if (quot < (256 << 2))
216 else if (quot < (256 << 4))
218 else if (quot < (256 << 6))
255 unsigned int tmout = 10000;
282 unsigned int disr = *
status;
285 unsigned int next_ignore_status_mask;
290 up->
port.icount.rx++;
293 next_ignore_status_mask =
302 up->
port.icount.brk++;
309 if (uart_handle_break(&up->
port))
312 up->
port.icount.parity++;
314 up->
port.icount.frame++;
316 up->
port.icount.overrun++;
323 next_ignore_status_mask |=
330 disr &= up->
port.read_status_mask;
332 if (disr & TXX9_SIDISR_UBRK) {
334 }
else if (disr & TXX9_SIDISR_UPER)
336 else if (disr & TXX9_SIDISR_UFER)
345 up->
port.ignore_status_mask = next_ignore_status_mask;
348 spin_unlock(&up->
port.lock);
350 spin_lock(&up->
port.lock);
359 if (up->
port.x_char) {
361 up->
port.icount.tx++;
366 serial_txx9_stop_tx(&up->
port);
374 up->
port.icount.tx++;
377 }
while (--count > 0);
383 serial_txx9_stop_tx(&up->
port);
388 int pass_counter = 0;
393 spin_lock(&up->
port.lock);
399 spin_unlock(&up->
port.lock);
404 receive_chars(up, &status);
409 TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
411 spin_unlock(&up->
port.lock);
420 static unsigned int serial_txx9_tx_empty(
struct uart_port *port)
428 spin_unlock_irqrestore(&up->
port.lock, flags);
433 static unsigned int serial_txx9_get_mctrl(
struct uart_port *port)
446 static void serial_txx9_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
456 static void serial_txx9_break_ctl(
struct uart_port *port,
int break_state)
462 if (break_state == -1)
466 spin_unlock_irqrestore(&up->
port.lock, flags);
469 #if defined(CONFIG_SERIAL_TXX9_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
475 unsigned int tmout = 10000;
492 #ifdef CONFIG_CONSOLE_POLL
498 static int serial_txx9_get_poll_char(
struct uart_port *port)
510 while (sio_in(up,
TXX9_SIDISR) & TXX9_SIDISR_UVALID)
525 static void serial_txx9_put_poll_char(
struct uart_port *port,
unsigned char c)
557 static int serial_txx9_startup(
struct uart_port *port)
588 serial_txx9_set_mctrl(&up->
port, up->
port.mctrl);
589 spin_unlock_irqrestore(&up->
port.lock, flags);
602 static void serial_txx9_shutdown(
struct uart_port *port)
613 serial_txx9_set_mctrl(&up->
port, up->
port.mctrl);
614 spin_unlock_irqrestore(&up->
port.lock, flags);
621 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
622 if (up->
port.cons && up->
port.line == up->
port.cons->index) {
645 unsigned int cval,
fcr = 0;
647 unsigned int baud, quot;
702 up->
port.read_status_mask = TXX9_SIDISR_UOER |
712 up->
port.ignore_status_mask = 0;
742 sio_quot_set(up, quot);
745 serial_txx9_set_mctrl(&up->
port, up->
port.mctrl);
746 spin_unlock_irqrestore(&up->
port.lock, flags);
751 unsigned int oldstate)
761 if (state == 0 && oldstate != -1)
762 serial_txx9_initialize(port);
765 static int serial_txx9_request_resource(
struct uart_txx9_port *up)
770 switch (up->
port.iotype) {
772 if (!up->
port.mapbase)
782 if (!up->
port.membase) {
797 static void serial_txx9_release_resource(
struct uart_txx9_port *up)
801 switch (up->
port.iotype) {
803 if (!up->
port.mapbase)
820 static void serial_txx9_release_port(
struct uart_port *port)
823 serial_txx9_release_resource(up);
826 static int serial_txx9_request_port(
struct uart_port *port)
829 return serial_txx9_request_resource(up);
832 static void serial_txx9_config_port(
struct uart_port *port,
int uflags)
841 ret = serial_txx9_request_resource(up);
847 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
848 if (up->
port.line == up->
port.cons->index)
851 serial_txx9_initialize(port);
860 static struct uart_ops serial_txx9_pops = {
861 .tx_empty = serial_txx9_tx_empty,
862 .set_mctrl = serial_txx9_set_mctrl,
863 .get_mctrl = serial_txx9_get_mctrl,
864 .stop_tx = serial_txx9_stop_tx,
865 .start_tx = serial_txx9_start_tx,
866 .stop_rx = serial_txx9_stop_rx,
867 .enable_ms = serial_txx9_enable_ms,
868 .break_ctl = serial_txx9_break_ctl,
869 .startup = serial_txx9_startup,
870 .shutdown = serial_txx9_shutdown,
871 .set_termios = serial_txx9_set_termios,
872 .pm = serial_txx9_pm,
873 .type = serial_txx9_type,
874 .release_port = serial_txx9_release_port,
875 .request_port = serial_txx9_request_port,
876 .config_port = serial_txx9_config_port,
877 #ifdef CONFIG_CONSOLE_POLL
878 .poll_get_char = serial_txx9_get_poll_char,
879 .poll_put_char = serial_txx9_put_poll_char,
890 for (i = 0; i <
UART_NR; i++) {
894 up->
port.ops = &serial_txx9_pops;
896 if (up->
port.iobase || up->
port.mapbase)
901 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
903 static void serial_txx9_console_putchar(
struct uart_port *port,
int ch)
918 serial_txx9_console_write(
struct console *co,
const char *
s,
unsigned int count)
921 unsigned int ier, flcr;
960 if (co->
index >= UART_NR)
962 up = &serial_txx9_ports[co->
index];
967 serial_txx9_initialize(&up->
port);
976 static struct console serial_txx9_console = {
978 .write = serial_txx9_console_write,
980 .setup = serial_txx9_console_setup,
983 .data = &serial_txx9_reg,
986 static int __init serial_txx9_console_init(
void)
993 #define SERIAL_TXX9_CONSOLE &serial_txx9_console
995 #define SERIAL_TXX9_CONSOLE NULL
1000 .driver_name =
"serial_txx9",
1013 serial_txx9_ports[port->
line].port = *
port;
1014 serial_txx9_ports[port->
line].port.ops = &serial_txx9_pops;
1015 serial_txx9_ports[port->
line].port.flags |=
1040 for (i = 0; i <
UART_NR; i++) {
1041 uart = &serial_txx9_ports[
i];
1049 for (i = 0; i <
UART_NR; i++) {
1050 uart = &serial_txx9_ports[
i];
1051 if (!(uart->
port.iobase || uart->
port.mapbase))
1068 ret = uart->
port.line;
1087 uart->
port.flags = 0;
1089 uart->
port.iobase = 0;
1090 uart->
port.mapbase = 0;
1106 for (i = 0; p && p->
uartclk != 0; p++, i++) {
1115 ret = serial_txx9_register_port(&port);
1117 dev_err(&dev->
dev,
"unable to register port at index %d "
1118 "(IO%lx MEM%llx IRQ%d): %d\n", i,
1133 for (i = 0; i <
UART_NR; i++) {
1136 if (up->
port.dev == &dev->
dev)
1137 serial_txx9_unregister_port(i);
1147 for (i = 0; i <
UART_NR; i++) {
1161 for (i = 0; i <
UART_NR; i++) {
1173 .probe = serial_txx9_probe,
1176 .suspend = serial_txx9_suspend,
1177 .resume = serial_txx9_resume,
1180 .name =
"serial_txx9",
1185 #ifdef ENABLE_SERIAL_TXX9_PCI
1201 memset(&port, 0,
sizeof(port));
1202 port.
ops = &serial_txx9_pops;
1209 line = serial_txx9_register_port(&port);
1215 pci_set_drvdata(dev, &serial_txx9_ports[line]);
1224 pci_set_drvdata(dev,
NULL);
1227 serial_txx9_unregister_port(up->
port.line);
1244 static int pciserial_txx9_resume_one(
struct pci_dev *dev)
1261 static struct pci_driver serial_txx9_pci_driver = {
1262 .
name =
"serial_txx9",
1263 .probe = pciserial_txx9_init_one,
1266 .suspend = pciserial_txx9_suspend_one,
1267 .resume = pciserial_txx9_resume_one,
1269 .id_table = serial_txx9_pci_tbl,
1277 static int __init serial_txx9_init(
void)
1288 if (!serial_txx9_plat_devs) {
1290 goto unreg_uart_drv;
1297 serial_txx9_register_ports(&serial_txx9_reg,
1298 &serial_txx9_plat_devs->
dev);
1304 #ifdef ENABLE_SERIAL_TXX9_PCI
1305 ret = pci_register_driver(&serial_txx9_pci_driver);
1320 static void __exit serial_txx9_exit(
void)
1324 #ifdef ENABLE_SERIAL_TXX9_PCI
1329 for (i = 0; i <
UART_NR; i++) {
1331 if (up->
port.iobase || up->
port.mapbase)