Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 2 | * dz.c: Serial port driver for DECstations equipped |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * with the DZ chipset. |
| 4 | * |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 5 | * Copyright (C) 1998 Olivier A. D. Lebaillif |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Email: olivier.lebaillif@ifrsys.com |
| 8 | * |
Maciej W. Rozycki | 87cff7f | 2008-02-07 00:15:09 -0800 | [diff] [blame] | 9 | * Copyright (C) 2004, 2006, 2007 Maciej W. Rozycki |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * [31-AUG-98] triemer |
| 12 | * Changed IRQ to use Harald's dec internals interrupts.h |
| 13 | * removed base_addr code - moving address assignment to setup.c |
| 14 | * Changed name of dz_init to rs_init to be consistent with tc code |
| 15 | * [13-NOV-98] triemer fixed code to receive characters |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 16 | * after patches by harald to irq code. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * [09-JAN-99] triemer minor fix for schedule - due to removal of timeout |
| 18 | * field from "current" - somewhere between 2.1.121 and 2.1.131 |
| 19 | Qua Jun 27 15:02:26 BRT 2001 |
| 20 | * [27-JUN-2001] Arnaldo Carvalho de Melo <acme@conectiva.com.br> - cleanups |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 21 | * |
| 22 | * Parts (C) 1999 David Airlie, airlied@linux.ie |
| 23 | * [07-SEP-99] Bugfixes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * |
| 25 | * [06-Jan-2002] Russell King <rmk@arm.linux.org.uk> |
| 26 | * Converted to new serial core |
| 27 | */ |
| 28 | |
| 29 | #undef DEBUG_DZ |
| 30 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 31 | #if defined(CONFIG_SERIAL_DZ_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 32 | #define SUPPORT_SYSRQ |
| 33 | #endif |
| 34 | |
Maciej W. Rozycki | 87cff7f | 2008-02-07 00:15:09 -0800 | [diff] [blame] | 35 | #include <linux/bitops.h> |
| 36 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/console.h> |
Maciej W. Rozycki | 87cff7f | 2008-02-07 00:15:09 -0800 | [diff] [blame] | 38 | #include <linux/delay.h> |
| 39 | #include <linux/errno.h> |
| 40 | #include <linux/init.h> |
| 41 | #include <linux/interrupt.h> |
| 42 | #include <linux/kernel.h> |
| 43 | #include <linux/major.h> |
| 44 | #include <linux/module.h> |
| 45 | #include <linux/serial.h> |
| 46 | #include <linux/serial_core.h> |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 47 | #include <linux/sysrq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/tty.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #include <asm/bootinfo.h> |
Maciej W. Rozycki | 87cff7f | 2008-02-07 00:15:09 -0800 | [diff] [blame] | 51 | #include <asm/system.h> |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/dec/interrupts.h> |
| 54 | #include <asm/dec/kn01.h> |
| 55 | #include <asm/dec/kn02.h> |
| 56 | #include <asm/dec/machtype.h> |
| 57 | #include <asm/dec/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include "dz.h" |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | static char *dz_name = "DECstation DZ serial driver version "; |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 62 | static char *dz_version = "1.03"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | struct dz_port { |
| 65 | struct uart_port port; |
| 66 | unsigned int cflag; |
| 67 | }; |
| 68 | |
| 69 | static struct dz_port dz_ports[DZ_NB_PORT]; |
| 70 | |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 71 | static inline struct dz_port *to_dport(struct uart_port *uport) |
| 72 | { |
| 73 | return container_of(uport, struct dz_port, port); |
| 74 | } |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* |
| 77 | * ------------------------------------------------------------ |
| 78 | * dz_in () and dz_out () |
| 79 | * |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 80 | * These routines are used to access the registers of the DZ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * chip, hiding relocation differences between implementation. |
| 82 | * ------------------------------------------------------------ |
| 83 | */ |
| 84 | |
| 85 | static inline unsigned short dz_in(struct dz_port *dport, unsigned offset) |
| 86 | { |
| 87 | volatile unsigned short *addr = |
| 88 | (volatile unsigned short *) (dport->port.membase + offset); |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | return *addr; |
| 91 | } |
| 92 | |
| 93 | static inline void dz_out(struct dz_port *dport, unsigned offset, |
| 94 | unsigned short value) |
| 95 | { |
| 96 | volatile unsigned short *addr = |
| 97 | (volatile unsigned short *) (dport->port.membase + offset); |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | *addr = value; |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | * ------------------------------------------------------------ |
| 104 | * rs_stop () and rs_start () |
| 105 | * |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 106 | * These routines are called before setting or resetting |
| 107 | * tty->stopped. They enable or disable transmitter interrupts, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * as necessary. |
| 109 | * ------------------------------------------------------------ |
| 110 | */ |
| 111 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 112 | static void dz_stop_tx(struct uart_port *uport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 114 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | unsigned short tmp, mask = 1 << dport->port.line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | tmp = dz_in(dport, DZ_TCR); /* read the TX flag */ |
| 118 | tmp &= ~mask; /* clear the TX flag */ |
| 119 | dz_out(dport, DZ_TCR, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 122 | static void dz_start_tx(struct uart_port *uport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 124 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | unsigned short tmp, mask = 1 << dport->port.line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | tmp = dz_in(dport, DZ_TCR); /* read the TX flag */ |
| 128 | tmp |= mask; /* set the TX flag */ |
| 129 | dz_out(dport, DZ_TCR, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static void dz_stop_rx(struct uart_port *uport) |
| 133 | { |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 134 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Maciej W. Rozycki | ff11d07 | 2008-02-07 00:15:14 -0800 | [diff] [blame] | 136 | dport->cflag &= ~DZ_RXENAB; |
| 137 | dz_out(dport, DZ_LPR, dport->cflag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static void dz_enable_ms(struct uart_port *port) |
| 141 | { |
| 142 | /* nothing to do */ |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | * ------------------------------------------------------------ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | * |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 148 | * Here start the interrupt handling routines. All of the following |
| 149 | * subroutines are declared as inline and are folded into |
| 150 | * dz_interrupt. They were separated out for readability's sake. |
| 151 | * |
| 152 | * Note: dz_interrupt() is a "fast" interrupt, which means that it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | * runs with interrupts turned off. People who may want to modify |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 154 | * dz_interrupt() should try to keep the interrupt handler as fast as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | * possible. After you are done making modifications, it is not a bad |
| 156 | * idea to do: |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 157 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | * make drivers/serial/dz.s |
| 159 | * |
| 160 | * and look at the resulting assemble code in dz.s. |
| 161 | * |
| 162 | * ------------------------------------------------------------ |
| 163 | */ |
| 164 | |
| 165 | /* |
| 166 | * ------------------------------------------------------------ |
| 167 | * receive_char () |
| 168 | * |
| 169 | * This routine deals with inputs from any lines. |
| 170 | * ------------------------------------------------------------ |
| 171 | */ |
Maciej W. Rozycki | de32019 | 2007-03-05 00:30:26 -0800 | [diff] [blame] | 172 | static inline void dz_receive_chars(struct dz_port *dport_in) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 174 | struct uart_port *uport; |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 175 | struct dz_port *dport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | struct tty_struct *tty = NULL; |
| 177 | struct uart_icount *icount; |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 178 | int lines_rx[DZ_NB_PORT] = { [0 ... DZ_NB_PORT - 1] = 0 }; |
| 179 | unsigned short status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | unsigned char ch, flag; |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 181 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 183 | while ((status = dz_in(dport_in, DZ_RBUF)) & DZ_DVAL) { |
| 184 | dport = &dz_ports[LINE(status)]; |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 185 | uport = &dport->port; |
| 186 | tty = uport->info->tty; /* point to the proper dev */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 188 | ch = UCHAR(status); /* grab the char */ |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 189 | flag = TTY_NORMAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 191 | icount = &uport->icount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | icount->rx++; |
| 193 | |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 194 | if (unlikely(status & (DZ_OERR | DZ_FERR | DZ_PERR))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 196 | /* |
| 197 | * There is no separate BREAK status bit, so treat |
| 198 | * null characters with framing errors as BREAKs; |
| 199 | * normally, otherwise. For this move the Framing |
| 200 | * Error bit to a simulated BREAK bit. |
| 201 | */ |
| 202 | if (!ch) { |
| 203 | status |= (status & DZ_FERR) >> |
| 204 | (ffs(DZ_FERR) - ffs(DZ_BREAK)); |
| 205 | status &= ~DZ_FERR; |
| 206 | } |
| 207 | |
| 208 | /* Handle SysRq/SAK & keep track of the statistics. */ |
| 209 | if (status & DZ_BREAK) { |
| 210 | icount->brk++; |
| 211 | if (uart_handle_break(uport)) |
| 212 | continue; |
| 213 | } else if (status & DZ_FERR) |
| 214 | icount->frame++; |
| 215 | else if (status & DZ_PERR) |
| 216 | icount->parity++; |
| 217 | if (status & DZ_OERR) |
| 218 | icount->overrun++; |
| 219 | |
| 220 | status &= uport->read_status_mask; |
| 221 | if (status & DZ_BREAK) |
| 222 | flag = TTY_BREAK; |
| 223 | else if (status & DZ_FERR) |
| 224 | flag = TTY_FRAME; |
| 225 | else if (status & DZ_PERR) |
| 226 | flag = TTY_PARITY; |
| 227 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 230 | if (uart_handle_sysrq_char(uport, ch)) |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 231 | continue; |
| 232 | |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 233 | uart_insert_char(uport, status, DZ_OERR, ch, flag); |
| 234 | lines_rx[LINE(status)] = 1; |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 235 | } |
| 236 | for (i = 0; i < DZ_NB_PORT; i++) |
| 237 | if (lines_rx[i]) |
| 238 | tty_flip_buffer_push(dz_ports[i].port.info->tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* |
| 242 | * ------------------------------------------------------------ |
| 243 | * transmit_char () |
| 244 | * |
| 245 | * This routine deals with outputs to any lines. |
| 246 | * ------------------------------------------------------------ |
| 247 | */ |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 248 | static inline void dz_transmit_chars(struct dz_port *dport_in) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 250 | struct dz_port *dport; |
| 251 | struct circ_buf *xmit; |
| 252 | unsigned short status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | unsigned char tmp; |
| 254 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 255 | status = dz_in(dport_in, DZ_CSR); |
| 256 | dport = &dz_ports[LINE(status)]; |
| 257 | xmit = &dport->port.info->xmit; |
| 258 | |
| 259 | if (dport->port.x_char) { /* XON/XOFF chars */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | dz_out(dport, DZ_TDR, dport->port.x_char); |
| 261 | dport->port.icount.tx++; |
| 262 | dport->port.x_char = 0; |
| 263 | return; |
| 264 | } |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 265 | /* If nothing to do or stopped or hardware stopped. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | if (uart_circ_empty(xmit) || uart_tx_stopped(&dport->port)) { |
Maciej W. Rozycki | 43d46ab | 2008-02-07 00:15:11 -0800 | [diff] [blame] | 267 | spin_lock(&dport->port.lock); |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 268 | dz_stop_tx(&dport->port); |
Maciej W. Rozycki | 43d46ab | 2008-02-07 00:15:11 -0800 | [diff] [blame] | 269 | spin_unlock(&dport->port.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | return; |
| 271 | } |
| 272 | |
| 273 | /* |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 274 | * If something to do... (remember the dz has no output fifo, |
| 275 | * so we go one char at a time) :-< |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | */ |
| 277 | tmp = xmit->buf[xmit->tail]; |
| 278 | xmit->tail = (xmit->tail + 1) & (DZ_XMIT_SIZE - 1); |
| 279 | dz_out(dport, DZ_TDR, tmp); |
| 280 | dport->port.icount.tx++; |
| 281 | |
| 282 | if (uart_circ_chars_pending(xmit) < DZ_WAKEUP_CHARS) |
| 283 | uart_write_wakeup(&dport->port); |
| 284 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 285 | /* Are we are done. */ |
Maciej W. Rozycki | 43d46ab | 2008-02-07 00:15:11 -0800 | [diff] [blame] | 286 | if (uart_circ_empty(xmit)) { |
| 287 | spin_lock(&dport->port.lock); |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 288 | dz_stop_tx(&dport->port); |
Maciej W. Rozycki | 43d46ab | 2008-02-07 00:15:11 -0800 | [diff] [blame] | 289 | spin_unlock(&dport->port.lock); |
| 290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
| 294 | * ------------------------------------------------------------ |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 295 | * check_modem_status() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | * |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 297 | * DS 3100 & 5100: Only valid for the MODEM line, duh! |
| 298 | * DS 5000/200: Valid for the MODEM and PRINTER line. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | * ------------------------------------------------------------ |
| 300 | */ |
| 301 | static inline void check_modem_status(struct dz_port *dport) |
| 302 | { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 303 | /* |
| 304 | * FIXME: |
| 305 | * 1. No status change interrupt; use a timer. |
| 306 | * 2. Handle the 3100/5000 as appropriate. --macro |
| 307 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | unsigned short status; |
| 309 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 310 | /* If not the modem line just return. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (dport->port.line != DZ_MODEM) |
| 312 | return; |
| 313 | |
| 314 | status = dz_in(dport, DZ_MSR); |
| 315 | |
| 316 | /* it's easy, since DSR2 is the only bit in the register */ |
| 317 | if (status) |
| 318 | dport->port.icount.dsr++; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * ------------------------------------------------------------ |
| 323 | * dz_interrupt () |
| 324 | * |
| 325 | * this is the main interrupt routine for the DZ chip. |
| 326 | * It deals with the multiple ports. |
| 327 | * ------------------------------------------------------------ |
| 328 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 329 | static irqreturn_t dz_interrupt(int irq, void *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
Jeff Garzik | 15aafa2 | 2008-02-06 01:36:20 -0800 | [diff] [blame] | 331 | struct dz_port *dport = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | unsigned short status; |
| 333 | |
| 334 | /* get the reason why we just got an irq */ |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 335 | status = dz_in(dport, DZ_CSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 337 | if ((status & (DZ_RDONE | DZ_RIE)) == (DZ_RDONE | DZ_RIE)) |
Maciej W. Rozycki | de32019 | 2007-03-05 00:30:26 -0800 | [diff] [blame] | 338 | dz_receive_chars(dport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 340 | if ((status & (DZ_TRDY | DZ_TIE)) == (DZ_TRDY | DZ_TIE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | dz_transmit_chars(dport); |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return IRQ_HANDLED; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * ------------------------------------------------------------------- |
| 348 | * Here ends the DZ interrupt routines. |
| 349 | * ------------------------------------------------------------------- |
| 350 | */ |
| 351 | |
| 352 | static unsigned int dz_get_mctrl(struct uart_port *uport) |
| 353 | { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 354 | /* |
| 355 | * FIXME: Handle the 3100/5000 as appropriate. --macro |
| 356 | */ |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 357 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; |
| 359 | |
| 360 | if (dport->port.line == DZ_MODEM) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | if (dz_in(dport, DZ_MSR) & DZ_MODEM_DSR) |
| 362 | mctrl &= ~TIOCM_DSR; |
| 363 | } |
| 364 | |
| 365 | return mctrl; |
| 366 | } |
| 367 | |
| 368 | static void dz_set_mctrl(struct uart_port *uport, unsigned int mctrl) |
| 369 | { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 370 | /* |
| 371 | * FIXME: Handle the 3100/5000 as appropriate. --macro |
| 372 | */ |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 373 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | unsigned short tmp; |
| 375 | |
| 376 | if (dport->port.line == DZ_MODEM) { |
| 377 | tmp = dz_in(dport, DZ_TCR); |
| 378 | if (mctrl & TIOCM_DTR) |
| 379 | tmp &= ~DZ_MODEM_DTR; |
| 380 | else |
| 381 | tmp |= DZ_MODEM_DTR; |
| 382 | dz_out(dport, DZ_TCR, tmp); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * ------------------------------------------------------------------- |
| 388 | * startup () |
| 389 | * |
| 390 | * various initialization tasks |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 391 | * ------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | */ |
| 393 | static int dz_startup(struct uart_port *uport) |
| 394 | { |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 395 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | unsigned long flags; |
| 397 | unsigned short tmp; |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | spin_lock_irqsave(&dport->port.lock, flags); |
| 400 | |
| 401 | /* enable the interrupt and the scanning */ |
| 402 | tmp = dz_in(dport, DZ_CSR); |
| 403 | tmp |= DZ_RIE | DZ_TIE | DZ_MSE; |
| 404 | dz_out(dport, DZ_CSR, tmp); |
| 405 | |
| 406 | spin_unlock_irqrestore(&dport->port.lock, flags); |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 411 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | * ------------------------------------------------------------------- |
| 413 | * shutdown () |
| 414 | * |
| 415 | * This routine will shutdown a serial port; interrupts are disabled, and |
| 416 | * DTR is dropped if the hangup on close termio flag is on. |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 417 | * ------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | */ |
| 419 | static void dz_shutdown(struct uart_port *uport) |
| 420 | { |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 421 | struct dz_port *dport = to_dport(uport); |
Maciej W. Rozycki | 43d46ab | 2008-02-07 00:15:11 -0800 | [diff] [blame] | 422 | unsigned long flags; |
| 423 | |
| 424 | spin_lock_irqsave(&dport->port.lock, flags); |
| 425 | dz_stop_tx(&dport->port); |
| 426 | spin_unlock_irqrestore(&dport->port.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /* |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 430 | * ------------------------------------------------------------------- |
| 431 | * dz_tx_empty() -- get the transmitter empty status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | * |
| 433 | * Purpose: Let user call ioctl() to get info when the UART physically |
| 434 | * is emptied. On bus types like RS485, the transmitter must |
| 435 | * release the bus after transmitting. This must be done when |
| 436 | * the transmit shift register is empty, not be done when the |
| 437 | * transmit holding register is empty. This functionality |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 438 | * allows an RS485 driver to be written in user space. |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 439 | * ------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | */ |
| 441 | static unsigned int dz_tx_empty(struct uart_port *uport) |
| 442 | { |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 443 | struct dz_port *dport = to_dport(uport); |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 444 | unsigned short tmp, mask = 1 << dport->port.line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 446 | tmp = dz_in(dport, DZ_TCR); |
| 447 | tmp &= mask; |
| 448 | |
| 449 | return tmp ? 0 : TIOCSER_TEMT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void dz_break_ctl(struct uart_port *uport, int break_state) |
| 453 | { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 454 | /* |
| 455 | * FIXME: Can't access BREAK bits in TDR easily; |
| 456 | * reuse the code for polled TX. --macro |
| 457 | */ |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 458 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | unsigned long flags; |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 460 | unsigned short tmp, mask = 1 << dport->port.line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
| 462 | spin_lock_irqsave(&uport->lock, flags); |
| 463 | tmp = dz_in(dport, DZ_TCR); |
| 464 | if (break_state) |
| 465 | tmp |= mask; |
| 466 | else |
| 467 | tmp &= ~mask; |
| 468 | dz_out(dport, DZ_TCR, tmp); |
| 469 | spin_unlock_irqrestore(&uport->lock, flags); |
| 470 | } |
| 471 | |
Maciej W. Rozycki | ff11d07 | 2008-02-07 00:15:14 -0800 | [diff] [blame] | 472 | static int dz_encode_baud_rate(unsigned int baud) |
| 473 | { |
| 474 | switch (baud) { |
| 475 | case 50: |
| 476 | return DZ_B50; |
| 477 | case 75: |
| 478 | return DZ_B75; |
| 479 | case 110: |
| 480 | return DZ_B110; |
| 481 | case 134: |
| 482 | return DZ_B134; |
| 483 | case 150: |
| 484 | return DZ_B150; |
| 485 | case 300: |
| 486 | return DZ_B300; |
| 487 | case 600: |
| 488 | return DZ_B600; |
| 489 | case 1200: |
| 490 | return DZ_B1200; |
| 491 | case 1800: |
| 492 | return DZ_B1800; |
| 493 | case 2000: |
| 494 | return DZ_B2000; |
| 495 | case 2400: |
| 496 | return DZ_B2400; |
| 497 | case 3600: |
| 498 | return DZ_B3600; |
| 499 | case 4800: |
| 500 | return DZ_B4800; |
| 501 | case 7200: |
| 502 | return DZ_B7200; |
| 503 | case 9600: |
| 504 | return DZ_B9600; |
| 505 | default: |
| 506 | return -1; |
| 507 | } |
| 508 | } |
| 509 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 510 | static void dz_set_termios(struct uart_port *uport, struct ktermios *termios, |
| 511 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | { |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 513 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | unsigned long flags; |
| 515 | unsigned int cflag, baud; |
Maciej W. Rozycki | ff11d07 | 2008-02-07 00:15:14 -0800 | [diff] [blame] | 516 | int bflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | cflag = dport->port.line; |
| 519 | |
| 520 | switch (termios->c_cflag & CSIZE) { |
| 521 | case CS5: |
| 522 | cflag |= DZ_CS5; |
| 523 | break; |
| 524 | case CS6: |
| 525 | cflag |= DZ_CS6; |
| 526 | break; |
| 527 | case CS7: |
| 528 | cflag |= DZ_CS7; |
| 529 | break; |
| 530 | case CS8: |
| 531 | default: |
| 532 | cflag |= DZ_CS8; |
| 533 | } |
| 534 | |
| 535 | if (termios->c_cflag & CSTOPB) |
| 536 | cflag |= DZ_CSTOPB; |
| 537 | if (termios->c_cflag & PARENB) |
| 538 | cflag |= DZ_PARENB; |
| 539 | if (termios->c_cflag & PARODD) |
| 540 | cflag |= DZ_PARODD; |
| 541 | |
| 542 | baud = uart_get_baud_rate(uport, termios, old_termios, 50, 9600); |
Maciej W. Rozycki | ff11d07 | 2008-02-07 00:15:14 -0800 | [diff] [blame] | 543 | bflag = dz_encode_baud_rate(baud); |
| 544 | if (bflag < 0) { /* Try to keep unchanged. */ |
| 545 | baud = uart_get_baud_rate(uport, old_termios, NULL, 50, 9600); |
| 546 | bflag = dz_encode_baud_rate(baud); |
| 547 | if (bflag < 0) { /* Resort to 9600. */ |
| 548 | baud = 9600; |
| 549 | bflag = DZ_B9600; |
| 550 | } |
| 551 | tty_termios_encode_baud_rate(termios, baud, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
Maciej W. Rozycki | ff11d07 | 2008-02-07 00:15:14 -0800 | [diff] [blame] | 553 | cflag |= bflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | if (termios->c_cflag & CREAD) |
| 556 | cflag |= DZ_RXENAB; |
| 557 | |
| 558 | spin_lock_irqsave(&dport->port.lock, flags); |
| 559 | |
Maciej W. Rozycki | ff11d07 | 2008-02-07 00:15:14 -0800 | [diff] [blame] | 560 | uart_update_timeout(uport, termios->c_cflag, baud); |
| 561 | |
| 562 | dz_out(dport, DZ_LPR, cflag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | dport->cflag = cflag; |
| 564 | |
| 565 | /* setup accept flag */ |
| 566 | dport->port.read_status_mask = DZ_OERR; |
| 567 | if (termios->c_iflag & INPCK) |
| 568 | dport->port.read_status_mask |= DZ_FERR | DZ_PERR; |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 569 | if (termios->c_iflag & (BRKINT | PARMRK)) |
| 570 | dport->port.read_status_mask |= DZ_BREAK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | /* characters to ignore */ |
| 573 | uport->ignore_status_mask = 0; |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 574 | if ((termios->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) |
| 575 | dport->port.ignore_status_mask |= DZ_OERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | if (termios->c_iflag & IGNPAR) |
| 577 | dport->port.ignore_status_mask |= DZ_FERR | DZ_PERR; |
Maciej W. Rozycki | 54c0f37 | 2008-02-07 00:15:12 -0800 | [diff] [blame] | 578 | if (termios->c_iflag & IGNBRK) |
| 579 | dport->port.ignore_status_mask |= DZ_BREAK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
| 581 | spin_unlock_irqrestore(&dport->port.lock, flags); |
| 582 | } |
| 583 | |
| 584 | static const char *dz_type(struct uart_port *port) |
| 585 | { |
| 586 | return "DZ"; |
| 587 | } |
| 588 | |
| 589 | static void dz_release_port(struct uart_port *port) |
| 590 | { |
| 591 | /* nothing to do */ |
| 592 | } |
| 593 | |
| 594 | static int dz_request_port(struct uart_port *port) |
| 595 | { |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | static void dz_config_port(struct uart_port *port, int flags) |
| 600 | { |
| 601 | if (flags & UART_CONFIG_TYPE) |
| 602 | port->type = PORT_DZ; |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 | * verify the new serial_struct (for TIOCSSERIAL). |
| 607 | */ |
| 608 | static int dz_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 609 | { |
| 610 | int ret = 0; |
| 611 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_DZ) |
| 612 | ret = -EINVAL; |
| 613 | if (ser->irq != port->irq) |
| 614 | ret = -EINVAL; |
| 615 | return ret; |
| 616 | } |
| 617 | |
| 618 | static struct uart_ops dz_ops = { |
| 619 | .tx_empty = dz_tx_empty, |
| 620 | .get_mctrl = dz_get_mctrl, |
| 621 | .set_mctrl = dz_set_mctrl, |
| 622 | .stop_tx = dz_stop_tx, |
| 623 | .start_tx = dz_start_tx, |
| 624 | .stop_rx = dz_stop_rx, |
| 625 | .enable_ms = dz_enable_ms, |
| 626 | .break_ctl = dz_break_ctl, |
| 627 | .startup = dz_startup, |
| 628 | .shutdown = dz_shutdown, |
| 629 | .set_termios = dz_set_termios, |
| 630 | .type = dz_type, |
| 631 | .release_port = dz_release_port, |
| 632 | .request_port = dz_request_port, |
| 633 | .config_port = dz_config_port, |
| 634 | .verify_port = dz_verify_port, |
| 635 | }; |
| 636 | |
| 637 | static void __init dz_init_ports(void) |
| 638 | { |
| 639 | static int first = 1; |
| 640 | struct dz_port *dport; |
| 641 | unsigned long base; |
| 642 | int i; |
| 643 | |
| 644 | if (!first) |
| 645 | return; |
| 646 | first = 0; |
| 647 | |
| 648 | if (mips_machtype == MACH_DS23100 || |
| 649 | mips_machtype == MACH_DS5100) |
Ralf Baechle | 4667773 | 2005-11-12 22:00:27 +0000 | [diff] [blame] | 650 | base = CKSEG1ADDR(KN01_SLOT_BASE + KN01_DZ11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | else |
Ralf Baechle | 4667773 | 2005-11-12 22:00:27 +0000 | [diff] [blame] | 652 | base = CKSEG1ADDR(KN02_SLOT_BASE + KN02_DZ11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
| 654 | for (i = 0, dport = dz_ports; i < DZ_NB_PORT; i++, dport++) { |
| 655 | spin_lock_init(&dport->port.lock); |
| 656 | dport->port.membase = (char *) base; |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 657 | dport->port.iotype = UPIO_MEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | dport->port.irq = dec_interrupt[DEC_IRQ_DZ11]; |
| 659 | dport->port.line = i; |
| 660 | dport->port.fifosize = 1; |
| 661 | dport->port.ops = &dz_ops; |
| 662 | dport->port.flags = UPF_BOOT_AUTOCONF; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | static void dz_reset(struct dz_port *dport) |
| 667 | { |
| 668 | dz_out(dport, DZ_CSR, DZ_CLR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | while (dz_in(dport, DZ_CSR) & DZ_CLR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | iob(); |
| 671 | |
| 672 | /* enable scanning */ |
| 673 | dz_out(dport, DZ_CSR, DZ_MSE); |
| 674 | } |
| 675 | |
| 676 | #ifdef CONFIG_SERIAL_DZ_CONSOLE |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 677 | /* |
| 678 | * ------------------------------------------------------------------- |
| 679 | * dz_console_putchar() -- transmit a character |
| 680 | * |
| 681 | * Polled transmission. This is tricky. We need to mask transmit |
| 682 | * interrupts so that they do not interfere, enable the transmitter |
| 683 | * for the line requested and then wait till the transmit scanner |
| 684 | * requests data for this line. But it may request data for another |
| 685 | * line first, in which case we have to disable its transmitter and |
| 686 | * repeat waiting till our line pops up. Only then the character may |
| 687 | * be transmitted. Finally, the state of the transmitter mask is |
| 688 | * restored. Welcome to the world of PDP-11! |
| 689 | * ------------------------------------------------------------------- |
| 690 | */ |
Martin Michlmayr | d608ab9 | 2006-06-26 18:18:11 +0200 | [diff] [blame] | 691 | static void dz_console_putchar(struct uart_port *uport, int ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
Maciej W. Rozycki | f5519ca | 2008-02-07 00:15:15 -0800 | [diff] [blame^] | 693 | struct dz_port *dport = to_dport(uport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | unsigned long flags; |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 695 | unsigned short csr, tcr, trdy, mask; |
| 696 | int loops = 10000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
| 698 | spin_lock_irqsave(&dport->port.lock, flags); |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 699 | csr = dz_in(dport, DZ_CSR); |
| 700 | dz_out(dport, DZ_CSR, csr & ~DZ_TIE); |
| 701 | tcr = dz_in(dport, DZ_TCR); |
| 702 | tcr |= 1 << dport->port.line; |
| 703 | mask = tcr; |
| 704 | dz_out(dport, DZ_TCR, mask); |
| 705 | iob(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | spin_unlock_irqrestore(&dport->port.lock, flags); |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 707 | |
Maciej W. Rozycki | dbab812 | 2008-02-07 00:15:07 -0800 | [diff] [blame] | 708 | do { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 709 | trdy = dz_in(dport, DZ_CSR); |
| 710 | if (!(trdy & DZ_TRDY)) |
| 711 | continue; |
| 712 | trdy = (trdy & DZ_TLINE) >> 8; |
| 713 | if (trdy == dport->port.line) |
| 714 | break; |
| 715 | mask &= ~(1 << trdy); |
| 716 | dz_out(dport, DZ_TCR, mask); |
| 717 | iob(); |
| 718 | udelay(2); |
Maciej W. Rozycki | dbab812 | 2008-02-07 00:15:07 -0800 | [diff] [blame] | 719 | } while (loops--); |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 720 | |
| 721 | if (loops) /* Cannot send otherwise. */ |
| 722 | dz_out(dport, DZ_TDR, ch); |
| 723 | |
| 724 | dz_out(dport, DZ_TCR, tcr); |
| 725 | dz_out(dport, DZ_CSR, csr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 727 | |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 728 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | * ------------------------------------------------------------------- |
| 730 | * dz_console_print () |
| 731 | * |
| 732 | * dz_console_print is registered for printk. |
| 733 | * The console must be locked when we get here. |
Ralf Baechle | fd8c597 | 2005-11-12 21:59:59 +0000 | [diff] [blame] | 734 | * ------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | */ |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 736 | static void dz_console_print(struct console *co, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | const char *str, |
| 738 | unsigned int count) |
| 739 | { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 740 | struct dz_port *dport = &dz_ports[co->index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | #ifdef DEBUG_DZ |
| 742 | prom_printf((char *) str); |
| 743 | #endif |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 744 | uart_console_write(&dport->port, str, count, dz_console_putchar); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static int __init dz_console_setup(struct console *co, char *options) |
| 748 | { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 749 | struct dz_port *dport = &dz_ports[co->index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | int baud = 9600; |
| 751 | int bits = 8; |
| 752 | int parity = 'n'; |
| 753 | int flow = 'n'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
| 755 | if (options) |
| 756 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 757 | |
| 758 | dz_reset(dport); |
| 759 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 760 | return uart_set_options(&dport->port, co, baud, parity, bits, flow); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 763 | static struct uart_driver dz_reg; |
Maciej W. Rozycki | 6d83c06 | 2008-02-07 00:15:10 -0800 | [diff] [blame] | 764 | static struct console dz_console = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | .name = "ttyS", |
| 766 | .write = dz_console_print, |
| 767 | .device = uart_console_device, |
| 768 | .setup = dz_console_setup, |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 769 | .flags = CON_PRINTBUFFER, |
| 770 | .index = -1, |
| 771 | .data = &dz_reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | }; |
| 773 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 774 | static int __init dz_serial_console_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 776 | if (!IOASIC) { |
| 777 | dz_init_ports(); |
Maciej W. Rozycki | 6d83c06 | 2008-02-07 00:15:10 -0800 | [diff] [blame] | 778 | register_console(&dz_console); |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 779 | return 0; |
| 780 | } else |
| 781 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 784 | console_initcall(dz_serial_console_init); |
| 785 | |
Maciej W. Rozycki | 6d83c06 | 2008-02-07 00:15:10 -0800 | [diff] [blame] | 786 | #define SERIAL_DZ_CONSOLE &dz_console |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | #else |
| 788 | #define SERIAL_DZ_CONSOLE NULL |
| 789 | #endif /* CONFIG_SERIAL_DZ_CONSOLE */ |
| 790 | |
| 791 | static struct uart_driver dz_reg = { |
| 792 | .owner = THIS_MODULE, |
| 793 | .driver_name = "serial", |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 794 | .dev_name = "ttyS", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | .major = TTY_MAJOR, |
| 796 | .minor = 64, |
| 797 | .nr = DZ_NB_PORT, |
| 798 | .cons = SERIAL_DZ_CONSOLE, |
| 799 | }; |
| 800 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 801 | static int __init dz_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | int ret, i; |
| 804 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 805 | if (IOASIC) |
| 806 | return -ENXIO; |
| 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | printk("%s%s\n", dz_name, dz_version); |
| 809 | |
| 810 | dz_init_ports(); |
| 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | #ifndef CONFIG_SERIAL_DZ_CONSOLE |
| 813 | /* reset the chip */ |
| 814 | dz_reset(&dz_ports[0]); |
| 815 | #endif |
| 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | ret = uart_register_driver(&dz_reg); |
| 818 | if (ret != 0) |
Maciej W. Rozycki | 0ba137e | 2008-02-07 00:15:08 -0800 | [diff] [blame] | 819 | goto out; |
| 820 | |
| 821 | ret = request_irq(dz_ports[0].port.irq, dz_interrupt, IRQF_DISABLED, |
| 822 | "DZ", &dz_ports[0]); |
| 823 | if (ret != 0) { |
| 824 | printk(KERN_ERR "dz: Cannot get IRQ %d!\n", |
| 825 | dz_ports[0].port.irq); |
| 826 | goto out_unregister; |
| 827 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
| 829 | for (i = 0; i < DZ_NB_PORT; i++) |
| 830 | uart_add_one_port(&dz_reg, &dz_ports[i].port); |
| 831 | |
| 832 | return ret; |
Maciej W. Rozycki | 0ba137e | 2008-02-07 00:15:08 -0800 | [diff] [blame] | 833 | |
| 834 | out_unregister: |
| 835 | uart_unregister_driver(&dz_reg); |
| 836 | |
| 837 | out: |
| 838 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Maciej W. Rozycki | 9399575 | 2006-12-06 20:38:59 -0800 | [diff] [blame] | 841 | module_init(dz_init); |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | MODULE_DESCRIPTION("DECstation DZ serial driver"); |
| 844 | MODULE_LICENSE("GPL"); |