18 #include <linux/module.h>
19 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/tty.h>
25 #include <linux/string.h>
26 #include <linux/ptrace.h>
29 #include <linux/serial.h>
32 #include <linux/slab.h>
34 #include <linux/serio.h>
44 #include <asm/setup.h>
46 #if defined(CONFIG_SERIAL_SUNSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
50 #include <linux/serial_core.h>
56 #define SU_BASE_BAUD (1846200 / 16)
59 static char *su_typev[] = {
"su(???)",
"su(mouse)",
"su(kbd)",
"su(serial)" };
109 offset <<= up->
port.regshift;
111 switch (up->
port.iotype) {
114 return inb(up->
port.iobase + 1);
120 return inb(up->
port.iobase + offset);
126 #ifndef CONFIG_SPARC64
138 offset <<= up->
port.regshift;
140 switch (up->
port.iotype) {
151 outb(value, up->
port.iobase + offset);
161 #define serial_inp(up, offset) serial_in(up, offset)
162 #define serial_outp(up, offset, value) serial_out(up, offset, value)
168 static void serial_icr_write(
struct uart_sunsu_port *up,
int offset,
int value)
175 static unsigned int serial_icr_read(
struct uart_sunsu_port *up,
int offset)
188 #ifdef CONFIG_SERIAL_8250_RSA
217 spin_lock_irq(&up->
port.lock);
219 spin_unlock_irq(&up->
port.lock);
239 spin_lock_irq(&up->
port.lock);
252 spin_unlock_irq(&up->
port.lock);
280 static void sunsu_start_tx(
struct uart_port *port)
298 static void sunsu_stop_rx(
struct uart_port *port)
307 static void sunsu_enable_ms(
struct uart_port *port)
315 spin_unlock_irqrestore(&up->
port.lock, flags);
322 unsigned char ch,
flag;
324 int saw_console_brk = 0;
329 up->
port.icount.rx++;
338 up->
port.icount.brk++;
340 up->
port.line == up->
port.cons->index)
348 if (uart_handle_break(&up->
port))
351 up->
port.icount.parity++;
353 up->
port.icount.frame++;
355 up->
port.icount.overrun++;
360 *status &= up->
port.read_status_mask;
363 up->
port.line == up->
port.cons->index) {
369 if (*status & UART_LSR_BI) {
371 }
else if (*status & UART_LSR_PE)
373 else if (*status & UART_LSR_FE)
378 if ((*status & up->
port.ignore_status_mask) == 0)
379 tty_insert_flip_char(tty, ch, flag);
380 if (*status & UART_LSR_OE)
389 }
while ((*status &
UART_LSR_DR) && (max_count-- > 0));
402 if (up->
port.x_char) {
404 up->
port.icount.tx++;
408 if (uart_tx_stopped(&up->
port)) {
409 sunsu_stop_tx(&up->
port);
417 count = up->
port.fifosize;
421 up->
port.icount.tx++;
424 }
while (--count > 0);
443 up->
port.icount.rng++;
445 up->
port.icount.dsr++;
467 if (status & UART_LSR_DR)
468 tty = receive_chars(up, &status);
469 check_modem_status(up);
473 spin_unlock_irqrestore(&up->
port.lock, flags);
482 spin_unlock_irqrestore(&up->
port.lock, flags);
491 unsigned int iflag,
unsigned int quot);
495 unsigned int cur_cflag = up->
cflag;
501 quot = up->
port.uartclk / (16 * new_baud);
503 sunsu_change_speed(&up->
port, up->
cflag, 0, quot);
506 static void receive_kbd_ms_chars(
struct uart_sunsu_port *up,
int is_break)
521 sunsu_change_mouse_baud(up);
533 }
while (serial_in(up,
UART_LSR) & UART_LSR_DR);
536 static irqreturn_t sunsu_kbd_ms_interrupt(
int irq,
void *dev_id)
543 if ((status & UART_LSR_DR) || (status & UART_LSR_BI))
544 receive_kbd_ms_chars(up, (status & UART_LSR_BI) != 0);
550 static unsigned int sunsu_tx_empty(
struct uart_port *port)
558 spin_unlock_irqrestore(&up->
port.lock, flags);
563 static unsigned int sunsu_get_mctrl(
struct uart_port *port)
583 static void sunsu_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
586 unsigned char mcr = 0;
602 static void sunsu_break_ctl(
struct uart_port *port,
int break_state)
608 if (break_state == -1)
613 spin_unlock_irqrestore(&up->
port.lock, flags);
616 static int sunsu_startup(
struct uart_port *port)
635 #ifdef CONFIG_SERIAL_8250_RSA
669 printk(
"ttyS%d: LSR safety check engaged!\n", up->
port.line);
681 printk(
"su: Cannot register IRQ %d\n", up->
port.irq);
694 sunsu_set_mctrl(&up->
port, up->
port.mctrl);
695 spin_unlock_irqrestore(&up->
port.lock, flags);
710 icp = (up->
port.iobase & 0xfe0) | 0x01f;
726 static void sunsu_shutdown(
struct uart_port *port)
740 inb((up->
port.iobase & 0xfe0) | 0x1f);
743 up->
port.mctrl &= ~TIOCM_OUT2;
745 sunsu_set_mctrl(&up->
port, up->
port.mctrl);
746 spin_unlock_irqrestore(&up->
port.lock, flags);
757 #ifdef CONFIG_SERIAL_8250_RSA
774 unsigned int iflag,
unsigned int quot)
777 unsigned char cval,
fcr = 0;
780 switch (cflag &
CSIZE) {
817 if ((up->
port.uartclk / quot) < (2400 * 16))
819 #ifdef CONFIG_SERIAL_8250_RSA
849 up->
port.ignore_status_mask = 0;
865 if ((cflag &
CREAD) == 0)
898 spin_unlock_irqrestore(&up->
port.lock, flags);
905 unsigned int baud, quot;
913 sunsu_change_speed(port, termios->
c_cflag, termios->
c_iflag, quot);
916 static void sunsu_release_port(
struct uart_port *port)
920 static int sunsu_request_port(
struct uart_port *port)
925 static void sunsu_config_port(
struct uart_port *port,
int flags)
955 static struct uart_ops sunsu_pops = {
956 .tx_empty = sunsu_tx_empty,
957 .set_mctrl = sunsu_set_mctrl,
958 .get_mctrl = sunsu_get_mctrl,
959 .stop_tx = sunsu_stop_tx,
960 .start_tx = sunsu_start_tx,
961 .stop_rx = sunsu_stop_rx,
962 .enable_ms = sunsu_enable_ms,
963 .break_ctl = sunsu_break_ctl,
964 .startup = sunsu_startup,
965 .shutdown = sunsu_shutdown,
966 .set_termios = sunsu_set_termios,
968 .release_port = sunsu_release_port,
969 .request_port = sunsu_request_port,
970 .config_port = sunsu_config_port,
971 .verify_port = sunsu_verify_port,
982 static int sunsu_serio_write(
struct serio *
serio,
unsigned char ch)
992 }
while (!(lsr & UART_LSR_THRE));
997 spin_unlock_irqrestore(&sunsu_serio_lock, flags);
1002 static int sunsu_serio_open(
struct serio *serio)
1005 unsigned long flags;
1009 if (!up->serio_open) {
1014 spin_unlock_irqrestore(&sunsu_serio_lock, flags);
1019 static void sunsu_serio_close(
struct serio *serio)
1022 unsigned long flags;
1026 spin_unlock_irqrestore(&sunsu_serio_lock, flags);
1034 unsigned char save_lcr, save_mcr;
1035 unsigned long flags;
1067 if (scratch2 != 0 || scratch3 != 0x0F)
1071 save_mcr = serial_in(up,
UART_MCR);
1072 save_lcr = serial_in(up,
UART_LCR);
1087 if (status1 != 0x90)
1094 scratch = serial_in(up,
UART_IIR) >> 6;
1112 if (serial_in(up,
UART_EFR) == 0) {
1125 scratch = serial_in(up,
UART_IIR) >> 5;
1137 scratch = serial_in(up,
UART_IIR) >> 5;
1152 if ((status1 != 0xa5) || (status2 != 0x5a))
1165 #ifdef CONFIG_SERIAL_8250_RSA
1178 spin_unlock_irqrestore(&up->
port.lock, flags);
1183 .driver_name =
"sunsu",
1192 struct serio *serio;
1202 quot = up->
port.uartclk / (16 *
baud);
1204 sunsu_autoconfig(up);
1208 printk(
"%s: %s port at %llx, irq %u\n",
1209 up->
port.dev->of_node->full_name,
1211 (
unsigned long long) up->
port.mapbase,
1224 serio->
id.extra = 1;
1228 (!(up->
port.line & 1) ?
"su/serio0" :
"su/serio1"),
1229 sizeof(serio->
phys));
1231 serio->
write = sunsu_serio_write;
1232 serio->
open = sunsu_serio_open;
1233 serio->
close = sunsu_serio_close;
1234 serio->
dev.parent = up->
port.dev;
1239 sunsu_change_speed(&up->
port, up->
cflag, 0, quot);
1241 sunsu_startup(&up->
port);
1251 #ifdef CONFIG_SERIAL_SUNSU_CONSOLE
1253 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
1260 unsigned int status, tmout = 10000;
1266 if (status & UART_LSR_BI)
1272 }
while ((status &
BOTH_EMPTY) != BOTH_EMPTY);
1283 static void sunsu_console_putchar(
struct uart_port *port,
int ch)
1295 static void sunsu_console_write(
struct console *co,
const char *
s,
1299 unsigned long flags;
1304 if (up->
port.sysrq) {
1307 locked = spin_trylock(&up->
port.lock);
1309 spin_lock(&up->
port.lock);
1327 spin_unlock(&up->
port.lock);
1343 printk(
"Console: ttyS%d (SU)\n",
1353 port = &sunsu_ports[co->
index].port;
1371 static struct console sunsu_console = {
1373 .write = sunsu_console_write,
1375 .setup = sunsu_console_setup,
1387 return &sunsu_console;
1390 #define SUNSU_CONSOLE() (NULL)
1391 #define sunsu_serial_console_init() do { } while (0)
1425 type = su_get_type(dp);
1429 up = &sunsu_ports[inst];
1436 up->
port.line = inst;
1446 if (!up->
port.membase) {
1461 err = sunsu_kbd_ms_init(up);
1475 sunsu_autoconfig(up);
1481 up->
port.ops = &sunsu_pops;
1483 ignore_line =
false;
1489 &sunsu_reg, up->
port.line,
1522 if (up->
port.membase)
1556 .of_match_table = su_match,
1562 static int __init sunsu_init(
void)
1568 for_each_node_by_name(dp,
"su") {
1572 for_each_node_by_name(dp,
"su_pnp") {
1576 for_each_node_by_name(dp,
"serial") {
1582 for_each_node_by_type(dp,
"serial") {
1596 if (err && num_uart)
1602 static void __exit sunsu_exit(
void)
1611 MODULE_AUTHOR(
"Eddie C. Dost, Peter Zaitcev, and David S. Miller");