18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/tty.h>
24 #include <linux/string.h>
25 #include <linux/ptrace.h>
28 #include <linux/serial.h>
32 #include <linux/slab.h>
40 #include <asm/setup.h>
42 #if defined(CONFIG_SERIAL_SUNSAB_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
46 #include <linux/serial_core.h>
79 #define SAB_BASE_BAUD ( 29491200 / 16 )
81 static char *sab82532_version[16] = {
82 "V1.0",
"V2.0",
"V3.2",
"V(0x03)",
83 "V(0x04)",
"V(0x05)",
"V(0x06)",
"V(0x07)",
84 "V(0x08)",
"V(0x09)",
"V(0x0a)",
"V(0x0b)",
85 "V(0x0c)",
"V(0x0d)",
"V(0x0e)",
"V(0x0f)"
88 #define SAB82532_MAX_TEC_TIMEOUT 200000
89 #define SAB82532_MAX_CEC_TIMEOUT 50000
91 #define SAB82532_RECV_FIFO_SIZE 32
92 #define SAB82532_XMIT_FIFO_SIZE 32
115 unsigned char buf[32];
116 int saw_console_brk = 0;
122 tty = up->
port.state->port.tty;
146 for (i = 0; i <
count; i++)
157 (up->
port.line == up->
port.cons->index))
160 for (i = 0; i <
count; i++) {
161 unsigned char ch = buf[
i],
flag;
169 up->
port.icount.rx++;
181 up->
port.icount.brk++;
188 if (uart_handle_break(&up->
port))
191 up->
port.icount.parity++;
193 up->
port.icount.frame++;
195 up->
port.icount.overrun++;
200 stat->
sreg.isr0 &= (up->
port.read_status_mask & 0xff);
201 stat->
sreg.isr1 &= ((up->
port.read_status_mask >> 8) & 0xff);
214 if ((stat->
sreg.isr0 & (up->
port.ignore_status_mask & 0xff)) == 0 &&
215 (stat->
sreg.isr1 & ((up->
port.ignore_status_mask >> 8) & 0xff)) == 0)
216 tty_insert_flip_char(tty, ch, flag);
227 static void sunsab_stop_tx(
struct uart_port *);
265 for (i = 0; i < up->
port.fifosize; i++) {
267 &up->
regs->
w.xfifo[i]);
269 up->
port.icount.tx++;
282 sunsab_stop_tx(&up->
port);
298 up->
port.icount.dsr++;
326 tty = receive_chars(up, &
status);
329 check_status(up, &
status);
331 transmit_chars(up, &
status);
334 spin_unlock_irqrestore(&up->
port.lock, flags);
358 static void sunsab_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
381 static unsigned int sunsab_get_mctrl(
struct uart_port *port)
402 static void sunsab_stop_tx(
struct uart_port *port)
430 static void sunsab_start_tx(
struct uart_port *port)
445 for (i = 0; i < up->
port.fifosize; i++) {
447 &up->
regs->
w.xfifo[i]);
449 up->
port.icount.tx++;
460 static void sunsab_send_xchar(
struct uart_port *port,
char ch)
470 spin_unlock_irqrestore(&up->
port.lock, flags);
474 static void sunsab_stop_rx(
struct uart_port *port)
483 static void sunsab_enable_ms(
struct uart_port *port)
489 static void sunsab_break_ctl(
struct uart_port *port,
int break_state)
508 spin_unlock_irqrestore(&up->
port.lock, flags);
512 static int sunsab_startup(
struct uart_port *port)
577 spin_unlock_irqrestore(&up->
port.lock, flags);
583 static void sunsab_shutdown(
struct uart_port *port)
622 spin_unlock_irqrestore(&up->
port.lock, flags);
634 static void calc_ebrg(
int baud,
int *n_ret,
int *m_ret)
660 if ((m == 0) && ((n & 1) == 0)) {
670 unsigned int iflag,
unsigned int baud,
677 switch (cflag &
CSIZE) {
703 calc_ebrg(baud, &n, &m);
734 up->
port.ignore_status_mask = 0;
751 if ((cflag &
CREAD) == 0)
756 (up->
port.uartclk / (16 * quot)));
777 sunsab_convert_to_sab(up, termios->
c_cflag, termios->
c_iflag, baud, quot);
778 spin_unlock_irqrestore(&up->
port.lock, flags);
781 static const char *sunsab_type(
struct uart_port *port)
786 sprintf(buf,
"SAB82532 %s", sab82532_version[up->
type]);
790 static void sunsab_release_port(
struct uart_port *port)
794 static int sunsab_request_port(
struct uart_port *port)
799 static void sunsab_config_port(
struct uart_port *port,
int flags)
808 static struct uart_ops sunsab_pops = {
809 .tx_empty = sunsab_tx_empty,
810 .set_mctrl = sunsab_set_mctrl,
811 .get_mctrl = sunsab_get_mctrl,
812 .stop_tx = sunsab_stop_tx,
813 .start_tx = sunsab_start_tx,
814 .send_xchar = sunsab_send_xchar,
815 .stop_rx = sunsab_stop_rx,
816 .enable_ms = sunsab_enable_ms,
817 .break_ctl = sunsab_break_ctl,
818 .startup = sunsab_startup,
819 .shutdown = sunsab_shutdown,
820 .set_termios = sunsab_set_termios,
822 .release_port = sunsab_release_port,
823 .request_port = sunsab_request_port,
824 .config_port = sunsab_config_port,
825 .verify_port = sunsab_verify_port,
830 .driver_name =
"sunsab",
837 #ifdef CONFIG_SERIAL_SUNSAB_CONSOLE
839 static void sunsab_console_putchar(
struct uart_port *port,
int c)
847 static void sunsab_console_write(
struct console *
con,
const char *
s,
unsigned n)
854 if (up->
port.sysrq) {
857 locked = spin_trylock(&up->
port.lock);
859 spin_lock(&up->
port.lock);
865 spin_unlock(&up->
port.lock);
869 static int sunsab_console_setup(
struct console *con,
char *
options)
873 unsigned int baud, quot;
884 printk(
"Console: ttyS%d (SAB82532)\n",
890 case B150: baud = 150;
break;
891 case B300: baud = 300;
break;
892 case B600: baud = 600;
break;
893 case B1200: baud = 1200;
break;
894 case B2400: baud = 2400;
break;
895 case B4800: baud = 4800;
break;
896 default:
case B9600: baud = 9600;
break;
897 case B19200: baud = 19200;
break;
898 case B38400: baud = 38400;
break;
899 case B57600: baud = 57600;
break;
900 case B115200: baud = 115200;
break;
901 case B230400: baud = 230400;
break;
902 case B460800: baud = 460800;
break;
913 sunsab_startup(&up->
port);
930 sunsab_convert_to_sab(up, con->
cflag, 0, baud, quot);
931 sunsab_set_mctrl(&up->
port, TIOCM_DTR | TIOCM_RTS);
933 spin_unlock_irqrestore(&up->
port.lock, flags);
938 static struct console sunsab_console = {
940 .write = sunsab_console_write,
942 .setup = sunsab_console_setup,
950 return &sunsab_console;
953 #define SUNSAB_CONSOLE() (NULL)
954 #define sunsab_console_init() do { } while (0)
962 up->
port.line = line;
969 if (!up->
port.membase)
980 up->
port.ops = &sunsab_pops;
985 writeb(~((1 << 1) | (1 << 2) | (1 << 4)), &up->
regs->
w.pcr);
987 if ((up->
port.line & 0x1) == 0) {
996 up->
cached_pvr = (1 << 1) | (1 << 2) | (1 << 4);
1016 up = &sunsab_ports[inst * 2];
1018 err = sunsab_init_one(&up[0], op,
1024 err = sunsab_init_one(&up[1], op,
1031 &sunsab_reg, up[0].
port.line,
1035 &sunsab_reg, up[1].
port.line,
1090 .compatible =
"sab82532",
1100 .of_match_table = sab_match,
1106 static int __init sunsab_init(
void)
1112 for_each_node_by_name(dp,
"se")
1114 for_each_node_by_name(dp, "
serial") {
1127 kfree(sunsab_ports);
1128 sunsab_ports =
NULL;
1137 static void __exit sunsab_exit(
void)
1140 if (sunsab_reg.
nr) {
1144 kfree(sunsab_ports);
1145 sunsab_ports =
NULL;