31 #if defined(CONFIG_SERIAL_DZ_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
35 #include <linux/bitops.h>
36 #include <linux/compiler.h>
39 #include <linux/errno.h>
43 #include <linux/kernel.h>
45 #include <linux/module.h>
46 #include <linux/serial.h>
47 #include <linux/serial_core.h>
49 #include <linux/tty.h>
53 #include <asm/bootinfo.h>
70 static char dz_name[]
__initdata =
"DECstation DZ serial driver version ";
126 static void dz_stop_tx(
struct uart_port *uport)
128 struct dz_port *dport = to_dport(uport);
131 tmp = dz_in(dport,
DZ_TCR);
133 dz_out(dport,
DZ_TCR, tmp);
136 static void dz_start_tx(
struct uart_port *uport)
138 struct dz_port *dport = to_dport(uport);
141 tmp = dz_in(dport,
DZ_TCR);
143 dz_out(dport,
DZ_TCR, tmp);
146 static void dz_stop_rx(
struct uart_port *uport)
148 struct dz_port *dport = to_dport(uport);
154 static void dz_enable_ms(
struct uart_port *uport)
186 static inline void dz_receive_chars(
struct dz_mux *
mux)
193 unsigned char ch,
flag;
199 uport = &dport->
port;
200 tty = uport->
state->port.tty;
217 status |= (status &
DZ_FERR) >>
225 if (uart_handle_break(uport))
235 if (status & DZ_BREAK)
237 else if (status & DZ_FERR)
239 else if (status & DZ_PERR)
248 lines_rx[
LINE(status)] = 1;
262 static inline void dz_transmit_chars(
struct dz_mux *mux)
269 status = dz_in(dport,
DZ_CSR);
271 xmit = &dport->
port.state->xmit;
273 if (dport->
port.x_char) {
275 dport->
port.icount.tx++;
276 dport->
port.x_char = 0;
281 spin_lock(&dport->
port.lock);
282 dz_stop_tx(&dport->
port);
283 spin_unlock(&dport->
port.lock);
293 dz_out(dport,
DZ_TDR, tmp);
294 dport->
port.icount.tx++;
301 spin_lock(&dport->
port.lock);
302 dz_stop_tx(&dport->
port);
303 spin_unlock(&dport->
port.lock);
315 static inline void check_modem_status(
struct dz_port *dport)
328 status = dz_in(dport,
DZ_MSR);
332 dport->
port.icount.dsr++;
350 status = dz_in(dport,
DZ_CSR);
353 dz_receive_chars(mux);
356 dz_transmit_chars(mux);
367 static unsigned int dz_get_mctrl(
struct uart_port *uport)
372 struct dz_port *dport = to_dport(uport);
383 static void dz_set_mctrl(
struct uart_port *uport,
unsigned int mctrl)
388 struct dz_port *dport = to_dport(uport);
392 tmp = dz_in(dport,
DZ_TCR);
397 dz_out(dport,
DZ_TCR, tmp);
408 static int dz_startup(
struct uart_port *uport)
410 struct dz_port *dport = to_dport(uport);
432 tmp = dz_in(dport,
DZ_CSR);
434 dz_out(dport,
DZ_CSR, tmp);
436 spin_unlock_irqrestore(&dport->
port.lock, flags);
449 static void dz_shutdown(
struct uart_port *uport)
451 struct dz_port *dport = to_dport(uport);
458 dz_stop_tx(&dport->
port);
459 spin_unlock_irqrestore(&dport->
port.lock, flags);
464 tmp = dz_in(dport,
DZ_CSR);
466 dz_out(dport,
DZ_CSR, tmp);
484 static unsigned int dz_tx_empty(
struct uart_port *uport)
486 struct dz_port *dport = to_dport(uport);
489 tmp = dz_in(dport,
DZ_TCR);
495 static void dz_break_ctl(
struct uart_port *uport,
int break_state)
501 struct dz_port *dport = to_dport(uport);
506 tmp = dz_in(dport,
DZ_TCR);
511 dz_out(dport,
DZ_TCR, tmp);
512 spin_unlock_irqrestore(&uport->
lock, flags);
515 static int dz_encode_baud_rate(
unsigned int baud)
554 static void dz_reset(
struct dz_port *dport)
574 struct dz_port *dport = to_dport(uport);
579 cflag = dport->
port.line;
604 bflag = dz_encode_baud_rate(baud);
607 bflag = dz_encode_baud_rate(baud);
623 dz_out(dport,
DZ_LPR, cflag);
638 dport->
port.ignore_status_mask |= DZ_FERR |
DZ_PERR;
642 spin_unlock_irqrestore(&dport->
port.lock, flags);
651 unsigned int oldstate)
653 struct dz_port *dport = to_dport(uport);
658 dz_start_tx(&dport->
port);
660 dz_stop_tx(&dport->
port);
661 spin_unlock_irqrestore(&dport->
port.lock, flags);
665 static const char *dz_type(
struct uart_port *uport)
670 static void dz_release_port(
struct uart_port *uport)
672 struct dz_mux *mux = to_dport(uport)->mux;
683 static int dz_map_port(
struct uart_port *uport)
695 static int dz_request_port(
struct uart_port *uport)
697 struct dz_mux *mux = to_dport(uport)->mux;
702 if (map_guard == 1) {
707 "dz: Unable to reserve MMIO resource\n");
711 ret = dz_map_port(uport);
721 static void dz_config_port(
struct uart_port *uport,
int flags)
723 struct dz_port *dport = to_dport(uport);
726 if (dz_request_port(uport))
744 if (ser->
irq != uport->
irq)
750 .tx_empty = dz_tx_empty,
751 .get_mctrl = dz_get_mctrl,
752 .set_mctrl = dz_set_mctrl,
753 .stop_tx = dz_stop_tx,
754 .start_tx = dz_start_tx,
755 .stop_rx = dz_stop_rx,
756 .enable_ms = dz_enable_ms,
757 .break_ctl = dz_break_ctl,
758 .startup = dz_startup,
759 .shutdown = dz_shutdown,
760 .set_termios = dz_set_termios,
763 .release_port = dz_release_port,
764 .request_port = dz_request_port,
765 .config_port = dz_config_port,
766 .verify_port = dz_verify_port,
769 static void __init dz_init_ports(
void)
771 static int first = 1;
794 uport->
ops = &dz_ops;
800 #ifdef CONFIG_SERIAL_DZ_CONSOLE
815 static void dz_console_putchar(
struct uart_port *uport,
int ch)
817 struct dz_port *dport = to_dport(uport);
823 csr = dz_in(dport,
DZ_CSR);
825 tcr = dz_in(dport,
DZ_TCR);
826 tcr |= 1 << dport->
port.line;
828 dz_out(dport,
DZ_TCR, mask);
830 spin_unlock_irqrestore(&dport->
port.lock, flags);
833 trdy = dz_in(dport,
DZ_CSR);
837 if (trdy == dport->
port.line)
839 mask &= ~(1 << trdy);
840 dz_out(dport,
DZ_TCR, mask);
846 dz_out(dport,
DZ_TDR, ch);
848 dz_out(dport,
DZ_TCR, tcr);
849 dz_out(dport,
DZ_CSR, csr);
860 static void dz_console_print(
struct console *co,
881 ret = dz_map_port(uport);
897 static struct console dz_console = {
899 .write = dz_console_print,
901 .setup = dz_console_setup,
907 static int __init dz_serial_console_init(
void)
919 #define SERIAL_DZ_CONSOLE &dz_console
921 #define SERIAL_DZ_CONSOLE NULL
926 .driver_name =
"serial",
934 static int __init dz_init(
void)
941 printk(
"%s%s\n", dz_name, dz_version);