41 #include <linux/tty.h>
43 #include <linux/serial.h>
45 #include <linux/module.h>
51 #include <linux/serial_core.h>
58 #define SN_SAL_MAX_CHARS 120
62 #define SN_SAL_BUFFER_SIZE (64 * (1 << 10))
64 #define SN_SAL_UART_FIFO_DEPTH 16
65 #define SN_SAL_UART_FIFO_SPEED_CPS (9600/10)
68 #define TRANSMIT_BUFFERED 0
69 #define TRANSMIT_RAW 1
74 #define USE_DYNAMIC_MINOR 0
77 #define DEVICE_NAME "ttySG"
78 #define DEVICE_NAME_DYNAMIC "ttySG0"
80 #define DEVICE_MAJOR 204
81 #define DEVICE_MINOR 40
83 #ifdef CONFIG_MAGIC_SYSRQ
84 static char sysrq_serial_str[] =
"\eSYS";
85 static char *sysrq_serial_ptr = sysrq_serial_str;
86 static unsigned long sysrq_requested;
107 static int sn_process_input;
116 static int sn_debug_printf(
const char *
fmt, ...);
117 #define DPRINTF(x...) sn_debug_printf(x)
119 #define DPRINTF(x...) do { } while (0)
123 static int snt_hw_puts_raw(
const char *,
int);
124 static int snt_hw_puts_buffered(
const char *,
int);
125 static int snt_poll_getc(
void);
126 static int snt_poll_input_pending(
void);
127 static int snt_intr_getc(
void);
128 static int snt_intr_input_pending(
void);
129 static void sn_transmit_chars(
struct sn_cons_port *,
int);
133 static struct sn_sal_ops poll_ops = {
134 .sal_puts_raw = snt_hw_puts_raw,
135 .sal_puts = snt_hw_puts_raw,
136 .sal_getc = snt_poll_getc,
137 .sal_input_pending = snt_poll_input_pending
141 static struct sn_sal_ops intr_ops = {
142 .sal_puts_raw = snt_hw_puts_raw,
143 .sal_puts = snt_hw_puts_buffered,
144 .sal_getc = snt_intr_getc,
145 .sal_input_pending = snt_intr_input_pending,
146 .sal_wakeup_transmit = sn_transmit_chars
166 static int snt_poll_getc(
void)
170 ia64_sn_console_getc(&ch);
178 static int snt_poll_input_pending(
void)
182 status = ia64_sn_console_check(&input);
183 return !status &&
input;
192 static int snt_intr_getc(
void)
194 return ia64_sn_console_readc();
201 static int snt_intr_input_pending(
void)
214 static int snt_hw_puts_raw(
const char *
s,
int len)
217 return ia64_sn_console_putb(s, len);
226 static int snt_hw_puts_buffered(
const char *
s,
int len)
229 return ia64_sn_console_xmit_chars((
char *)s, len);
246 return (
"SGI SN L1");
254 static unsigned int snp_tx_empty(
struct uart_port *port)
264 static void snp_stop_tx(
struct uart_port *port)
273 static void snp_release_port(
struct uart_port *port)
282 static void snp_enable_ms(
struct uart_port *port)
291 static void snp_shutdown(
struct uart_port *port)
301 static void snp_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
310 static unsigned int snp_get_mctrl(
struct uart_port *port)
320 static void snp_stop_rx(
struct uart_port *port)
329 static void snp_start_tx(
struct uart_port *port)
331 if (sal_console_port.sc_ops->sal_wakeup_transmit)
332 sal_console_port.sc_ops->sal_wakeup_transmit(&sal_console_port,
343 static void snp_break_ctl(
struct uart_port *port,
int break_state)
352 static int snp_startup(
struct uart_port *port)
375 static int snp_request_port(
struct uart_port *port)
392 static struct uart_ops sn_console_ops = {
393 .tx_empty = snp_tx_empty,
394 .set_mctrl = snp_set_mctrl,
395 .get_mctrl = snp_get_mctrl,
396 .stop_tx = snp_stop_tx,
397 .start_tx = snp_start_tx,
398 .stop_rx = snp_stop_rx,
399 .enable_ms = snp_enable_ms,
400 .break_ctl = snp_break_ctl,
401 .startup = snp_startup,
402 .shutdown = snp_shutdown,
403 .set_termios = snp_set_termios,
406 .release_port = snp_release_port,
407 .request_port = snp_request_port,
408 .config_port = snp_config_port,
424 static int sn_debug_printf(
const char *
fmt, ...)
426 static char printk_buf[1024];
431 printed_len =
vsnprintf(printk_buf,
sizeof(printk_buf), fmt, args);
433 if (!sal_console_port.sc_ops) {
434 sal_console_port.sc_ops = &poll_ops;
437 sal_console_port.sc_ops->sal_puts_raw(printk_buf, printed_len);
464 printk(
KERN_ERR "sn_receive_chars - port NULL so can't receive\n");
469 printk(
KERN_ERR "sn_receive_chars - port->sc_ops NULL so can't receive\n");
475 tty = port->
sc_port.state->port.tty;
482 while (port->
sc_ops->sal_input_pending()) {
483 ch = port->
sc_ops->sal_getc();
486 "obtaining data from the console (0x%0x)\n", ch);
489 #ifdef CONFIG_MAGIC_SYSRQ
490 if (sysrq_requested) {
491 unsigned long sysrq_timeout = sysrq_requested +
HZ*5;
495 spin_unlock_irqrestore(&port->
sc_port.lock, flags);
502 if (ch == *sysrq_serial_ptr) {
503 if (!(*++sysrq_serial_ptr)) {
505 sysrq_serial_ptr = sysrq_serial_str;
515 sysrq_serial_ptr = sysrq_serial_str;
520 if(tty_insert_flip_char(tty, ch,
TTY_NORMAL) == 0)
544 int xmit_count,
tail,
head, loops, ii;
556 xmit = &port->
sc_port.state->xmit;
577 loops = (head <
tail) ? 2 : 1;
579 for (ii = 0; ii < loops; ii++) {
580 xmit_count = (head <
tail) ?
583 if (xmit_count > 0) {
586 port->
sc_ops->sal_puts_raw(start,
590 port->
sc_ops->sal_puts(start, xmit_count);
623 int status = ia64_sn_console_intr_status();
630 sn_receive_chars(port, flags);
635 spin_unlock_irqrestore(&port->
sc_port.lock, flags);
648 static void sn_sal_timer_poll(
unsigned long data)
658 if (sn_process_input)
659 sn_receive_chars(port, flags);
661 spin_unlock_irqrestore(&port->
sc_port.lock, flags);
688 DPRINTF(
"sn_console: about to switch to asynchronous console\n");
705 port->
sc_timer.function = sn_sal_timer_poll;
719 spin_unlock_irqrestore(&port->
sc_port.lock, flags);
738 DPRINTF(
"sn_console: switching to interrupt driven console\n");
742 "SAL console driver", port) >= 0) {
749 ia64_sn_console_intr_enable(SAL_CONSOLE_INTR_RECV);
750 spin_unlock_irqrestore(&port->
sc_port.lock, flags);
754 "sn_console: console proceeding in polled mode\n");
763 static void sn_sal_console_write(
struct console *,
const char *,
unsigned);
764 static int sn_sal_console_setup(
struct console *,
char *);
768 static struct console sal_console = {
770 .write = sn_sal_console_write,
772 .setup = sn_sal_console_setup,
774 .data = &sal_console_uart,
777 #define SAL_CONSOLE &sal_console
781 .driver_name =
"sn_console",
798 static int __init sn_sal_module_init(
void)
813 "device using misc_register.\n");
828 (
"ERROR sn_sal_module_init failed uart_register_driver, line %d\n",
836 sal_console_port.sc_port.membase = (
char *)1;
839 sal_console_port.sc_port.ops = &sn_console_ops;
840 sal_console_port.sc_port.line = 0;
850 if (!sal_console_port.sc_is_asynch) {
851 sn_sal_switch_to_asynch(&sal_console_port);
856 sn_sal_switch_to_interrupts(&sal_console_port);
858 sn_process_input = 1;
866 static void __exit sn_sal_module_exit(
void)
888 static void puts_raw_fixed(
int (*puts_raw) (
const char *s,
int len),
889 const char *s,
int count)
894 while ((s1 =
memchr(s,
'\n', count)) !=
NULL) {
921 sn_sal_console_write(
struct console *co,
const char *s,
unsigned count)
923 unsigned long flags = 0;
925 static int stole_lock = 0;
934 puts_raw_fixed(port->
sc_ops->sal_puts_raw, s, count);
940 if (spin_is_locked(&port->
sc_port.lock)) {
941 int lhead = port->
sc_port.state->xmit.head;
942 int ltail = port->
sc_port.state->xmit.tail;
956 for (counter = 0; counter < 150;
mdelay(125), counter++) {
957 if (!spin_is_locked(&port->
sc_port.lock)
967 if ((lhead != port->
sc_port.state->xmit.head)
969 port->
sc_port.state->xmit.tail)) {
971 port->
sc_port.state->xmit.head;
973 port->
sc_port.state->xmit.tail;
979 sn_transmit_chars(port, 1);
981 spin_unlock_irqrestore(&port->
sc_port.lock, flags);
987 puts_raw_fixed(port->
sc_ops->sal_puts_raw, s, count);
991 sn_transmit_chars(port, 1);
992 spin_unlock_irqrestore(&port->
sc_port.lock, flags);
994 puts_raw_fixed(port->
sc_ops->sal_puts_raw, s, count);
1011 static int sn_sal_console_setup(
struct console *co,
char *
options)
1028 sn_sal_console_write_early(
struct console *co,
const char *s,
unsigned count)
1030 puts_raw_fixed(sal_console_port.sc_ops->sal_puts_raw, s, count);
1037 .write = sn_sal_console_write_early,
1056 sal_console_port.sc_ops = &poll_ops;
1076 static int __init sn_sal_serial_console_init(
void)
1079 sn_sal_switch_to_asynch(&sal_console_port);
1080 DPRINTF(
"sn_sal_serial_console_init : register console\n");