Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1 | /* |
Mike Frysinger | 1ba7a3e | 2008-01-11 15:56:26 +0800 | [diff] [blame] | 2 | * Blackfin On-Chip Serial Driver |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 3 | * |
Mike Frysinger | d273e201 | 2008-10-13 10:33:06 +0100 | [diff] [blame] | 4 | * Copyright 2006-2008 Analog Devices Inc. |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 5 | * |
Mike Frysinger | 1ba7a3e | 2008-01-11 15:56:26 +0800 | [diff] [blame] | 6 | * Enter bugs at http://blackfin.uclinux.org/ |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 7 | * |
Mike Frysinger | 1ba7a3e | 2008-01-11 15:56:26 +0800 | [diff] [blame] | 8 | * Licensed under the GPL-2 or later. |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #if defined(CONFIG_SERIAL_BFIN_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 12 | #define SUPPORT_SYSRQ |
| 13 | #endif |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/console.h> |
| 19 | #include <linux/sysrq.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/tty.h> |
| 22 | #include <linux/tty_flip.h> |
| 23 | #include <linux/serial_core.h> |
| 24 | |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 25 | #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ |
| 26 | defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) |
Sonic Zhang | 474f1a6 | 2007-06-29 16:35:17 +0800 | [diff] [blame] | 27 | #include <linux/kgdb.h> |
| 28 | #include <asm/irq_regs.h> |
| 29 | #endif |
| 30 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 31 | #include <asm/gpio.h> |
Bryan Wu | 639f657 | 2008-08-27 10:51:02 +0800 | [diff] [blame] | 32 | #include <mach/bfin_serial_5xx.h> |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 33 | |
| 34 | #ifdef CONFIG_SERIAL_BFIN_DMA |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <asm/io.h> |
| 37 | #include <asm/irq.h> |
| 38 | #include <asm/cacheflush.h> |
| 39 | #endif |
| 40 | |
| 41 | /* UART name and device definitions */ |
| 42 | #define BFIN_SERIAL_NAME "ttyBF" |
| 43 | #define BFIN_SERIAL_MAJOR 204 |
| 44 | #define BFIN_SERIAL_MINOR 64 |
| 45 | |
Mike Frysinger | c9607ec | 2008-10-13 10:33:16 +0100 | [diff] [blame] | 46 | static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS]; |
| 47 | static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource); |
| 48 | |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 49 | #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ |
| 50 | defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) |
| 51 | |
| 52 | # ifndef CONFIG_SERIAL_BFIN_PIO |
| 53 | # error KGDB only support UART in PIO mode. |
| 54 | # endif |
| 55 | |
| 56 | static int kgdboc_port_line; |
| 57 | static int kgdboc_break_enabled; |
| 58 | #endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 59 | /* |
| 60 | * Setup for console. Argument comes from the menuconfig |
| 61 | */ |
| 62 | #define DMA_RX_XCOUNT 512 |
| 63 | #define DMA_RX_YCOUNT (PAGE_SIZE / DMA_RX_XCOUNT) |
| 64 | |
Sonic Zhang | 0aef456 | 2008-02-29 12:08:42 +0800 | [diff] [blame] | 65 | #define DMA_RX_FLUSH_JIFFIES (HZ / 50) |
Sonic Zhang | f30ac0c | 2008-06-19 17:46:39 +0800 | [diff] [blame] | 66 | #define CTS_CHECK_JIFFIES (HZ / 50) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 67 | |
| 68 | #ifdef CONFIG_SERIAL_BFIN_DMA |
| 69 | static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart); |
| 70 | #else |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 71 | static void bfin_serial_tx_chars(struct bfin_serial_port *uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 72 | #endif |
| 73 | |
| 74 | static void bfin_serial_mctrl_check(struct bfin_serial_port *uart); |
| 75 | |
Graf Yang | 80d5c47 | 2009-01-02 13:40:22 +0000 | [diff] [blame] | 76 | static void bfin_serial_reset_irda(struct uart_port *port); |
| 77 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 78 | /* |
| 79 | * interrupts are disabled on entry |
| 80 | */ |
| 81 | static void bfin_serial_stop_tx(struct uart_port *port) |
| 82 | { |
| 83 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
Sonic Zhang | 68a784c | 2009-01-02 13:40:38 +0000 | [diff] [blame^] | 84 | #ifdef CONFIG_SERIAL_BFIN_DMA |
Sonic Zhang | 0711d85 | 2008-02-25 15:16:50 +0800 | [diff] [blame] | 85 | struct circ_buf *xmit = &uart->port.info->xmit; |
Sonic Zhang | 68a784c | 2009-01-02 13:40:38 +0000 | [diff] [blame^] | 86 | #endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 87 | |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 88 | while (!(UART_GET_LSR(uart) & TEMT)) |
Sonic Zhang | 0711d85 | 2008-02-25 15:16:50 +0800 | [diff] [blame] | 89 | cpu_relax(); |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 90 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 91 | #ifdef CONFIG_SERIAL_BFIN_DMA |
| 92 | disable_dma(uart->tx_dma_channel); |
Sonic Zhang | 0711d85 | 2008-02-25 15:16:50 +0800 | [diff] [blame] | 93 | xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); |
| 94 | uart->port.icount.tx += uart->tx_count; |
| 95 | uart->tx_count = 0; |
| 96 | uart->tx_done = 1; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 97 | #else |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 98 | #ifdef CONFIG_BF54x |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 99 | /* Clear TFI bit */ |
| 100 | UART_PUT_LSR(uart, TFI); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 101 | #endif |
Mike Frysinger | 89bf6dc5 | 2008-05-07 11:41:26 +0800 | [diff] [blame] | 102 | UART_CLEAR_IER(uart, ETBEI); |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 103 | #endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* |
| 107 | * port is locked and interrupts are disabled |
| 108 | */ |
| 109 | static void bfin_serial_start_tx(struct uart_port *port) |
| 110 | { |
| 111 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
Graf Yang | 80d5c47 | 2009-01-02 13:40:22 +0000 | [diff] [blame] | 112 | struct tty_struct *tty = uart->port.info->port.tty; |
| 113 | |
| 114 | /* |
| 115 | * To avoid losting RX interrupt, we reset IR function |
| 116 | * before sending data. |
| 117 | */ |
| 118 | if (tty->termios->c_line == N_IRDA) |
| 119 | bfin_serial_reset_irda(port); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 120 | |
| 121 | #ifdef CONFIG_SERIAL_BFIN_DMA |
Sonic Zhang | 0711d85 | 2008-02-25 15:16:50 +0800 | [diff] [blame] | 122 | if (uart->tx_done) |
| 123 | bfin_serial_dma_tx_chars(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 124 | #else |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 125 | UART_SET_IER(uart, ETBEI); |
Sonic Zhang | a359cca | 2007-10-10 16:47:58 +0800 | [diff] [blame] | 126 | bfin_serial_tx_chars(uart); |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 127 | #endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Interrupts are enabled |
| 132 | */ |
| 133 | static void bfin_serial_stop_rx(struct uart_port *port) |
| 134 | { |
| 135 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 136 | |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 137 | UART_CLEAR_IER(uart, ERBFI); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Set the modem control timer to fire immediately. |
| 142 | */ |
| 143 | static void bfin_serial_enable_ms(struct uart_port *port) |
| 144 | { |
| 145 | } |
| 146 | |
Sonic Zhang | 474f1a6 | 2007-06-29 16:35:17 +0800 | [diff] [blame] | 147 | |
Mike Frysinger | 50e2e15 | 2008-04-25 03:03:03 +0800 | [diff] [blame] | 148 | #if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO) |
Mike Frysinger | 8851c71 | 2007-12-24 19:48:04 +0800 | [diff] [blame] | 149 | # define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold) |
| 150 | # define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v)) |
| 151 | #else |
| 152 | # define UART_GET_ANOMALY_THRESHOLD(uart) 0 |
| 153 | # define UART_SET_ANOMALY_THRESHOLD(uart, v) |
| 154 | #endif |
| 155 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 156 | #ifdef CONFIG_SERIAL_BFIN_PIO |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 157 | static void bfin_serial_rx_chars(struct bfin_serial_port *uart) |
| 158 | { |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 159 | struct tty_struct *tty = NULL; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 160 | unsigned int status, ch, flg; |
Mike Frysinger | 8851c71 | 2007-12-24 19:48:04 +0800 | [diff] [blame] | 161 | static struct timeval anomaly_start = { .tv_sec = 0 }; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 162 | |
Sonic Zhang | 759eb04 | 2007-11-21 17:00:32 +0800 | [diff] [blame] | 163 | status = UART_GET_LSR(uart); |
Mike Frysinger | 0bcfd70 | 2007-12-24 19:40:05 +0800 | [diff] [blame] | 164 | UART_CLEAR_LSR(uart); |
| 165 | |
| 166 | ch = UART_GET_CHAR(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 167 | uart->port.icount.rx++; |
| 168 | |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 169 | #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ |
| 170 | defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) |
| 171 | if (kgdb_connected && kgdboc_port_line == uart->port.line) |
| 172 | if (ch == 0x3) {/* Ctrl + C */ |
| 173 | kgdb_breakpoint(); |
Sonic Zhang | 474f1a6 | 2007-06-29 16:35:17 +0800 | [diff] [blame] | 174 | return; |
Sonic Zhang | 474f1a6 | 2007-06-29 16:35:17 +0800 | [diff] [blame] | 175 | } |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 176 | |
| 177 | if (!uart->port.info || !uart->port.info->tty) |
| 178 | return; |
Sonic Zhang | 474f1a6 | 2007-06-29 16:35:17 +0800 | [diff] [blame] | 179 | #endif |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 180 | tty = uart->port.info->tty; |
Mike Frysinger | bbf275f | 2007-08-05 16:48:08 +0800 | [diff] [blame] | 181 | |
Mike Frysinger | 50e2e15 | 2008-04-25 03:03:03 +0800 | [diff] [blame] | 182 | if (ANOMALY_05000363) { |
Mike Frysinger | 8851c71 | 2007-12-24 19:48:04 +0800 | [diff] [blame] | 183 | /* The BF533 (and BF561) family of processors have a nice anomaly |
| 184 | * where they continuously generate characters for a "single" break. |
Mike Frysinger | bbf275f | 2007-08-05 16:48:08 +0800 | [diff] [blame] | 185 | * We have to basically ignore this flood until the "next" valid |
Mike Frysinger | 8851c71 | 2007-12-24 19:48:04 +0800 | [diff] [blame] | 186 | * character comes across. Due to the nature of the flood, it is |
| 187 | * not possible to reliably catch bytes that are sent too quickly |
| 188 | * after this break. So application code talking to the Blackfin |
| 189 | * which sends a break signal must allow at least 1.5 character |
| 190 | * times after the end of the break for things to stabilize. This |
| 191 | * timeout was picked as it must absolutely be larger than 1 |
| 192 | * character time +/- some percent. So 1.5 sounds good. All other |
| 193 | * Blackfin families operate properly. Woo. |
Mike Frysinger | bbf275f | 2007-08-05 16:48:08 +0800 | [diff] [blame] | 194 | */ |
Mike Frysinger | 8851c71 | 2007-12-24 19:48:04 +0800 | [diff] [blame] | 195 | if (anomaly_start.tv_sec) { |
| 196 | struct timeval curr; |
| 197 | suseconds_t usecs; |
| 198 | |
| 199 | if ((~ch & (~ch + 1)) & 0xff) |
| 200 | goto known_good_char; |
| 201 | |
| 202 | do_gettimeofday(&curr); |
| 203 | if (curr.tv_sec - anomaly_start.tv_sec > 1) |
| 204 | goto known_good_char; |
| 205 | |
| 206 | usecs = 0; |
| 207 | if (curr.tv_sec != anomaly_start.tv_sec) |
| 208 | usecs += USEC_PER_SEC; |
| 209 | usecs += curr.tv_usec - anomaly_start.tv_usec; |
| 210 | |
| 211 | if (usecs > UART_GET_ANOMALY_THRESHOLD(uart)) |
| 212 | goto known_good_char; |
| 213 | |
| 214 | if (ch) |
| 215 | anomaly_start.tv_sec = 0; |
| 216 | else |
| 217 | anomaly_start = curr; |
| 218 | |
| 219 | return; |
| 220 | |
| 221 | known_good_char: |
| 222 | anomaly_start.tv_sec = 0; |
Mike Frysinger | bbf275f | 2007-08-05 16:48:08 +0800 | [diff] [blame] | 223 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 224 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 225 | |
| 226 | if (status & BI) { |
Mike Frysinger | 50e2e15 | 2008-04-25 03:03:03 +0800 | [diff] [blame] | 227 | if (ANOMALY_05000363) |
Mike Frysinger | 8851c71 | 2007-12-24 19:48:04 +0800 | [diff] [blame] | 228 | if (bfin_revid() < 5) |
| 229 | do_gettimeofday(&anomaly_start); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 230 | uart->port.icount.brk++; |
| 231 | if (uart_handle_break(&uart->port)) |
| 232 | goto ignore_char; |
Mike Frysinger | 9808901 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 233 | status &= ~(PE | FE); |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 234 | } |
| 235 | if (status & PE) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 236 | uart->port.icount.parity++; |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 237 | if (status & OE) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 238 | uart->port.icount.overrun++; |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 239 | if (status & FE) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 240 | uart->port.icount.frame++; |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 241 | |
| 242 | status &= uart->port.read_status_mask; |
| 243 | |
| 244 | if (status & BI) |
| 245 | flg = TTY_BREAK; |
| 246 | else if (status & PE) |
| 247 | flg = TTY_PARITY; |
| 248 | else if (status & FE) |
| 249 | flg = TTY_FRAME; |
| 250 | else |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 251 | flg = TTY_NORMAL; |
| 252 | |
| 253 | if (uart_handle_sysrq_char(&uart->port, ch)) |
| 254 | goto ignore_char; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 255 | |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 256 | uart_insert_char(&uart->port, status, OE, ch, flg); |
| 257 | |
| 258 | ignore_char: |
| 259 | tty_flip_buffer_push(tty); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static void bfin_serial_tx_chars(struct bfin_serial_port *uart) |
| 263 | { |
| 264 | struct circ_buf *xmit = &uart->port.info->xmit; |
| 265 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 266 | /* |
| 267 | * Check the modem control lines before |
| 268 | * transmitting anything. |
| 269 | */ |
| 270 | bfin_serial_mctrl_check(uart); |
| 271 | |
| 272 | if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) { |
Sonic Zhang | 5ffdeea2 | 2008-10-13 10:33:33 +0100 | [diff] [blame] | 273 | #ifdef CONFIG_BF54x |
| 274 | /* Clear TFI bit */ |
| 275 | UART_PUT_LSR(uart, TFI); |
| 276 | #endif |
| 277 | UART_CLEAR_IER(uart, ETBEI); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 278 | return; |
| 279 | } |
| 280 | |
Sonic Zhang | f30ac0c | 2008-06-19 17:46:39 +0800 | [diff] [blame] | 281 | if (uart->port.x_char) { |
| 282 | UART_PUT_CHAR(uart, uart->port.x_char); |
| 283 | uart->port.icount.tx++; |
| 284 | uart->port.x_char = 0; |
| 285 | } |
| 286 | |
Sonic Zhang | 759eb04 | 2007-11-21 17:00:32 +0800 | [diff] [blame] | 287 | while ((UART_GET_LSR(uart) & THRE) && xmit->tail != xmit->head) { |
| 288 | UART_PUT_CHAR(uart, xmit->buf[xmit->tail]); |
| 289 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 290 | uart->port.icount.tx++; |
| 291 | SSYNC(); |
| 292 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 293 | |
| 294 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 295 | uart_write_wakeup(&uart->port); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Aubrey Li | 5c4e472 | 2007-05-21 18:09:38 +0800 | [diff] [blame] | 298 | static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id) |
| 299 | { |
| 300 | struct bfin_serial_port *uart = dev_id; |
| 301 | |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 302 | spin_lock(&uart->port.lock); |
Mike Frysinger | 0bcfd70 | 2007-12-24 19:40:05 +0800 | [diff] [blame] | 303 | while (UART_GET_LSR(uart) & DR) |
Aubrey Li | 5c4e472 | 2007-05-21 18:09:38 +0800 | [diff] [blame] | 304 | bfin_serial_rx_chars(uart); |
| 305 | spin_unlock(&uart->port.lock); |
Sonic Zhang | 759eb04 | 2007-11-21 17:00:32 +0800 | [diff] [blame] | 306 | |
Aubrey Li | 5c4e472 | 2007-05-21 18:09:38 +0800 | [diff] [blame] | 307 | return IRQ_HANDLED; |
| 308 | } |
| 309 | |
| 310 | static irqreturn_t bfin_serial_tx_int(int irq, void *dev_id) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 311 | { |
| 312 | struct bfin_serial_port *uart = dev_id; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 313 | |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 314 | spin_lock(&uart->port.lock); |
Mike Frysinger | 0bcfd70 | 2007-12-24 19:40:05 +0800 | [diff] [blame] | 315 | if (UART_GET_LSR(uart) & THRE) |
Aubrey Li | 5c4e472 | 2007-05-21 18:09:38 +0800 | [diff] [blame] | 316 | bfin_serial_tx_chars(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 317 | spin_unlock(&uart->port.lock); |
Sonic Zhang | 759eb04 | 2007-11-21 17:00:32 +0800 | [diff] [blame] | 318 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 319 | return IRQ_HANDLED; |
| 320 | } |
Sonic Zhang | 4cb4f22 | 2008-02-02 14:29:25 +0800 | [diff] [blame] | 321 | #endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 322 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 323 | #ifdef CONFIG_SERIAL_BFIN_DMA |
| 324 | static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart) |
| 325 | { |
| 326 | struct circ_buf *xmit = &uart->port.info->xmit; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 327 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 328 | uart->tx_done = 0; |
| 329 | |
Sonic Zhang | f30ac0c | 2008-06-19 17:46:39 +0800 | [diff] [blame] | 330 | /* |
| 331 | * Check the modem control lines before |
| 332 | * transmitting anything. |
| 333 | */ |
| 334 | bfin_serial_mctrl_check(uart); |
| 335 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 336 | if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) { |
Sonic Zhang | 0711d85 | 2008-02-25 15:16:50 +0800 | [diff] [blame] | 337 | uart->tx_count = 0; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 338 | uart->tx_done = 1; |
| 339 | return; |
| 340 | } |
| 341 | |
Sonic Zhang | 1b73351 | 2007-12-21 16:45:12 +0800 | [diff] [blame] | 342 | if (uart->port.x_char) { |
| 343 | UART_PUT_CHAR(uart, uart->port.x_char); |
| 344 | uart->port.icount.tx++; |
| 345 | uart->port.x_char = 0; |
| 346 | } |
| 347 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 348 | uart->tx_count = CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE); |
| 349 | if (uart->tx_count > (UART_XMIT_SIZE - xmit->tail)) |
| 350 | uart->tx_count = UART_XMIT_SIZE - xmit->tail; |
| 351 | blackfin_dcache_flush_range((unsigned long)(xmit->buf+xmit->tail), |
| 352 | (unsigned long)(xmit->buf+xmit->tail+uart->tx_count)); |
| 353 | set_dma_config(uart->tx_dma_channel, |
| 354 | set_bfin_dma_config(DIR_READ, DMA_FLOW_STOP, |
| 355 | INTR_ON_BUF, |
| 356 | DIMENSION_LINEAR, |
Michael Hennerich | 2047e40 | 2008-01-22 15:29:18 +0800 | [diff] [blame] | 357 | DATA_SIZE_8, |
| 358 | DMA_SYNC_RESTART)); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 359 | set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail)); |
| 360 | set_dma_x_count(uart->tx_dma_channel, uart->tx_count); |
| 361 | set_dma_x_modify(uart->tx_dma_channel, 1); |
| 362 | enable_dma(uart->tx_dma_channel); |
Sonic Zhang | 99ee7b5 | 2007-12-21 17:12:55 +0800 | [diff] [blame] | 363 | |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 364 | UART_SET_IER(uart, ETBEI); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 367 | static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 368 | { |
Takashi Iwai | a88487c | 2008-07-16 21:54:42 +0100 | [diff] [blame] | 369 | struct tty_struct *tty = uart->port.info->port.tty; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 370 | int i, flg, status; |
| 371 | |
| 372 | status = UART_GET_LSR(uart); |
Mike Frysinger | 0bcfd70 | 2007-12-24 19:40:05 +0800 | [diff] [blame] | 373 | UART_CLEAR_LSR(uart); |
| 374 | |
Sonic Zhang | 56f5de8 | 2008-02-25 15:19:09 +0800 | [diff] [blame] | 375 | uart->port.icount.rx += |
| 376 | CIRC_CNT(uart->rx_dma_buf.head, uart->rx_dma_buf.tail, |
| 377 | UART_XMIT_SIZE); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 378 | |
| 379 | if (status & BI) { |
| 380 | uart->port.icount.brk++; |
| 381 | if (uart_handle_break(&uart->port)) |
| 382 | goto dma_ignore_char; |
Mike Frysinger | 9808901 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 383 | status &= ~(PE | FE); |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 384 | } |
| 385 | if (status & PE) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 386 | uart->port.icount.parity++; |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 387 | if (status & OE) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 388 | uart->port.icount.overrun++; |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 389 | if (status & FE) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 390 | uart->port.icount.frame++; |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 391 | |
| 392 | status &= uart->port.read_status_mask; |
| 393 | |
| 394 | if (status & BI) |
| 395 | flg = TTY_BREAK; |
| 396 | else if (status & PE) |
| 397 | flg = TTY_PARITY; |
| 398 | else if (status & FE) |
| 399 | flg = TTY_FRAME; |
| 400 | else |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 401 | flg = TTY_NORMAL; |
| 402 | |
Sonic Zhang | 56f5de8 | 2008-02-25 15:19:09 +0800 | [diff] [blame] | 403 | for (i = uart->rx_dma_buf.tail; i != uart->rx_dma_buf.head; i++) { |
| 404 | if (i >= UART_XMIT_SIZE) |
| 405 | i = 0; |
| 406 | if (!uart_handle_sysrq_char(&uart->port, uart->rx_dma_buf.buf[i])) |
| 407 | uart_insert_char(&uart->port, status, OE, |
| 408 | uart->rx_dma_buf.buf[i], flg); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 409 | } |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 410 | |
| 411 | dma_ignore_char: |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 412 | tty_flip_buffer_push(tty); |
| 413 | } |
| 414 | |
| 415 | void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart) |
| 416 | { |
Sonic Zhang | 68a784c | 2009-01-02 13:40:38 +0000 | [diff] [blame^] | 417 | int x_pos, pos, flags; |
| 418 | |
| 419 | spin_lock_irqsave(&uart->port.lock, flags); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 420 | |
Sonic Zhang | 56f5de8 | 2008-02-25 15:19:09 +0800 | [diff] [blame] | 421 | uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); |
| 422 | x_pos = get_dma_curr_xcount(uart->rx_dma_channel); |
| 423 | uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows; |
| 424 | if (uart->rx_dma_nrows == DMA_RX_YCOUNT) |
| 425 | uart->rx_dma_nrows = 0; |
| 426 | x_pos = DMA_RX_XCOUNT - x_pos; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 427 | if (x_pos == DMA_RX_XCOUNT) |
| 428 | x_pos = 0; |
| 429 | |
| 430 | pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos; |
Sonic Zhang | 56f5de8 | 2008-02-25 15:19:09 +0800 | [diff] [blame] | 431 | if (pos != uart->rx_dma_buf.tail) { |
| 432 | uart->rx_dma_buf.head = pos; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 433 | bfin_serial_dma_rx_chars(uart); |
Sonic Zhang | 56f5de8 | 2008-02-25 15:19:09 +0800 | [diff] [blame] | 434 | uart->rx_dma_buf.tail = uart->rx_dma_buf.head; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 435 | } |
Sonic Zhang | 0aef456 | 2008-02-29 12:08:42 +0800 | [diff] [blame] | 436 | |
Sonic Zhang | 68a784c | 2009-01-02 13:40:38 +0000 | [diff] [blame^] | 437 | spin_unlock_irqrestore(&uart->port.lock, flags); |
| 438 | |
Sonic Zhang | 0a27842 | 2008-04-25 04:36:47 +0800 | [diff] [blame] | 439 | mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id) |
| 443 | { |
| 444 | struct bfin_serial_port *uart = dev_id; |
| 445 | struct circ_buf *xmit = &uart->port.info->xmit; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 446 | |
| 447 | spin_lock(&uart->port.lock); |
| 448 | if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) { |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 449 | disable_dma(uart->tx_dma_channel); |
Sonic Zhang | 0711d85 | 2008-02-25 15:16:50 +0800 | [diff] [blame] | 450 | clear_dma_irqstat(uart->tx_dma_channel); |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 451 | UART_CLEAR_IER(uart, ETBEI); |
Sonic Zhang | 0711d85 | 2008-02-25 15:16:50 +0800 | [diff] [blame] | 452 | xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); |
| 453 | uart->port.icount.tx += uart->tx_count; |
Sonic Zhang | 1b73351 | 2007-12-21 16:45:12 +0800 | [diff] [blame] | 454 | |
Sonic Zhang | 56f5de8 | 2008-02-25 15:19:09 +0800 | [diff] [blame] | 455 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 456 | uart_write_wakeup(&uart->port); |
| 457 | |
Sonic Zhang | 1b73351 | 2007-12-21 16:45:12 +0800 | [diff] [blame] | 458 | bfin_serial_dma_tx_chars(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | spin_unlock(&uart->port.lock); |
| 462 | return IRQ_HANDLED; |
| 463 | } |
| 464 | |
| 465 | static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id) |
| 466 | { |
| 467 | struct bfin_serial_port *uart = dev_id; |
| 468 | unsigned short irqstat; |
Sonic Zhang | 0711d85 | 2008-02-25 15:16:50 +0800 | [diff] [blame] | 469 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 470 | spin_lock(&uart->port.lock); |
| 471 | irqstat = get_dma_curr_irqstat(uart->rx_dma_channel); |
| 472 | clear_dma_irqstat(uart->rx_dma_channel); |
Sonic Zhang | 68a784c | 2009-01-02 13:40:38 +0000 | [diff] [blame^] | 473 | bfin_serial_dma_rx_chars(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 474 | spin_unlock(&uart->port.lock); |
Sonic Zhang | 0aef456 | 2008-02-29 12:08:42 +0800 | [diff] [blame] | 475 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 476 | return IRQ_HANDLED; |
| 477 | } |
| 478 | #endif |
| 479 | |
| 480 | /* |
| 481 | * Return TIOCSER_TEMT when transmitter is not busy. |
| 482 | */ |
| 483 | static unsigned int bfin_serial_tx_empty(struct uart_port *port) |
| 484 | { |
| 485 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 486 | unsigned short lsr; |
| 487 | |
| 488 | lsr = UART_GET_LSR(uart); |
| 489 | if (lsr & TEMT) |
| 490 | return TIOCSER_TEMT; |
| 491 | else |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static unsigned int bfin_serial_get_mctrl(struct uart_port *port) |
| 496 | { |
| 497 | #ifdef CONFIG_SERIAL_BFIN_CTSRTS |
| 498 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 499 | if (uart->cts_pin < 0) |
| 500 | return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; |
| 501 | |
Sonic Zhang | 1feaa51 | 2008-06-03 12:19:45 +0800 | [diff] [blame] | 502 | if (UART_GET_CTS(uart)) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 503 | return TIOCM_DSR | TIOCM_CAR; |
| 504 | else |
| 505 | #endif |
| 506 | return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; |
| 507 | } |
| 508 | |
| 509 | static void bfin_serial_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 510 | { |
| 511 | #ifdef CONFIG_SERIAL_BFIN_CTSRTS |
| 512 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 513 | if (uart->rts_pin < 0) |
| 514 | return; |
| 515 | |
| 516 | if (mctrl & TIOCM_RTS) |
Sonic Zhang | 1feaa51 | 2008-06-03 12:19:45 +0800 | [diff] [blame] | 517 | UART_CLEAR_RTS(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 518 | else |
Sonic Zhang | 1feaa51 | 2008-06-03 12:19:45 +0800 | [diff] [blame] | 519 | UART_SET_RTS(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 520 | #endif |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Handle any change of modem status signal since we were last called. |
| 525 | */ |
| 526 | static void bfin_serial_mctrl_check(struct bfin_serial_port *uart) |
| 527 | { |
| 528 | #ifdef CONFIG_SERIAL_BFIN_CTSRTS |
| 529 | unsigned int status; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 530 | struct uart_info *info = uart->port.info; |
Takashi Iwai | a88487c | 2008-07-16 21:54:42 +0100 | [diff] [blame] | 531 | struct tty_struct *tty = info->port.tty; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 532 | |
| 533 | status = bfin_serial_get_mctrl(&uart->port); |
Sonic Zhang | 4cb4f22 | 2008-02-02 14:29:25 +0800 | [diff] [blame] | 534 | uart_handle_cts_change(&uart->port, status & TIOCM_CTS); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 535 | if (!(status & TIOCM_CTS)) { |
| 536 | tty->hw_stopped = 1; |
Sonic Zhang | f30ac0c | 2008-06-19 17:46:39 +0800 | [diff] [blame] | 537 | uart->cts_timer.data = (unsigned long)(uart); |
| 538 | uart->cts_timer.function = (void *)bfin_serial_mctrl_check; |
| 539 | uart->cts_timer.expires = jiffies + CTS_CHECK_JIFFIES; |
| 540 | add_timer(&(uart->cts_timer)); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 541 | } else { |
| 542 | tty->hw_stopped = 0; |
| 543 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 544 | #endif |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Interrupts are always disabled. |
| 549 | */ |
| 550 | static void bfin_serial_break_ctl(struct uart_port *port, int break_state) |
| 551 | { |
Mike Frysinger | cf68676 | 2007-06-11 16:12:49 +0800 | [diff] [blame] | 552 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 553 | u16 lcr = UART_GET_LCR(uart); |
| 554 | if (break_state) |
| 555 | lcr |= SB; |
| 556 | else |
| 557 | lcr &= ~SB; |
| 558 | UART_PUT_LCR(uart, lcr); |
| 559 | SSYNC(); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static int bfin_serial_startup(struct uart_port *port) |
| 563 | { |
| 564 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 565 | |
| 566 | #ifdef CONFIG_SERIAL_BFIN_DMA |
| 567 | dma_addr_t dma_handle; |
| 568 | |
| 569 | if (request_dma(uart->rx_dma_channel, "BFIN_UART_RX") < 0) { |
| 570 | printk(KERN_NOTICE "Unable to attach Blackfin UART RX DMA channel\n"); |
| 571 | return -EBUSY; |
| 572 | } |
| 573 | |
| 574 | if (request_dma(uart->tx_dma_channel, "BFIN_UART_TX") < 0) { |
| 575 | printk(KERN_NOTICE "Unable to attach Blackfin UART TX DMA channel\n"); |
| 576 | free_dma(uart->rx_dma_channel); |
| 577 | return -EBUSY; |
| 578 | } |
| 579 | |
| 580 | set_dma_callback(uart->rx_dma_channel, bfin_serial_dma_rx_int, uart); |
| 581 | set_dma_callback(uart->tx_dma_channel, bfin_serial_dma_tx_int, uart); |
| 582 | |
| 583 | uart->rx_dma_buf.buf = (unsigned char *)dma_alloc_coherent(NULL, PAGE_SIZE, &dma_handle, GFP_DMA); |
| 584 | uart->rx_dma_buf.head = 0; |
| 585 | uart->rx_dma_buf.tail = 0; |
| 586 | uart->rx_dma_nrows = 0; |
| 587 | |
| 588 | set_dma_config(uart->rx_dma_channel, |
| 589 | set_bfin_dma_config(DIR_WRITE, DMA_FLOW_AUTO, |
| 590 | INTR_ON_ROW, DIMENSION_2D, |
Michael Hennerich | 2047e40 | 2008-01-22 15:29:18 +0800 | [diff] [blame] | 591 | DATA_SIZE_8, |
| 592 | DMA_SYNC_RESTART)); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 593 | set_dma_x_count(uart->rx_dma_channel, DMA_RX_XCOUNT); |
| 594 | set_dma_x_modify(uart->rx_dma_channel, 1); |
| 595 | set_dma_y_count(uart->rx_dma_channel, DMA_RX_YCOUNT); |
| 596 | set_dma_y_modify(uart->rx_dma_channel, 1); |
| 597 | set_dma_start_addr(uart->rx_dma_channel, (unsigned long)uart->rx_dma_buf.buf); |
| 598 | enable_dma(uart->rx_dma_channel); |
| 599 | |
| 600 | uart->rx_dma_timer.data = (unsigned long)(uart); |
| 601 | uart->rx_dma_timer.function = (void *)bfin_serial_rx_dma_timeout; |
| 602 | uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES; |
| 603 | add_timer(&(uart->rx_dma_timer)); |
| 604 | #else |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 605 | #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ |
| 606 | defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) |
| 607 | if (kgdboc_port_line == uart->port.line && kgdboc_break_enabled) |
| 608 | kgdboc_break_enabled = 0; |
| 609 | else { |
| 610 | # endif |
Sonic Zhang | a359cca | 2007-10-10 16:47:58 +0800 | [diff] [blame] | 611 | if (request_irq(uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED, |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 612 | "BFIN_UART_RX", uart)) { |
| 613 | printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n"); |
| 614 | return -EBUSY; |
| 615 | } |
| 616 | |
| 617 | if (request_irq |
Aubrey Li | 5c4e472 | 2007-05-21 18:09:38 +0800 | [diff] [blame] | 618 | (uart->port.irq+1, bfin_serial_tx_int, IRQF_DISABLED, |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 619 | "BFIN_UART_TX", uart)) { |
| 620 | printk(KERN_NOTICE "Unable to attach BlackFin UART TX interrupt\n"); |
| 621 | free_irq(uart->port.irq, uart); |
| 622 | return -EBUSY; |
| 623 | } |
Sonic Zhang | ab2375f | 2008-10-13 10:33:51 +0100 | [diff] [blame] | 624 | |
| 625 | # ifdef CONFIG_BF54x |
| 626 | { |
| 627 | unsigned uart_dma_ch_rx, uart_dma_ch_tx; |
| 628 | |
| 629 | switch (uart->port.irq) { |
| 630 | case IRQ_UART3_RX: |
| 631 | uart_dma_ch_rx = CH_UART3_RX; |
| 632 | uart_dma_ch_tx = CH_UART3_TX; |
| 633 | break; |
| 634 | case IRQ_UART2_RX: |
| 635 | uart_dma_ch_rx = CH_UART2_RX; |
| 636 | uart_dma_ch_tx = CH_UART2_TX; |
| 637 | break; |
| 638 | default: |
| 639 | uart_dma_ch_rx = uart_dma_ch_tx = 0; |
| 640 | break; |
| 641 | }; |
| 642 | |
| 643 | if (uart_dma_ch_rx && |
| 644 | request_dma(uart_dma_ch_rx, "BFIN_UART_RX") < 0) { |
| 645 | printk(KERN_NOTICE"Fail to attach UART interrupt\n"); |
| 646 | free_irq(uart->port.irq, uart); |
| 647 | free_irq(uart->port.irq + 1, uart); |
| 648 | return -EBUSY; |
| 649 | } |
| 650 | if (uart_dma_ch_tx && |
| 651 | request_dma(uart_dma_ch_tx, "BFIN_UART_TX") < 0) { |
| 652 | printk(KERN_NOTICE "Fail to attach UART interrupt\n"); |
| 653 | free_dma(uart_dma_ch_rx); |
| 654 | free_irq(uart->port.irq, uart); |
| 655 | free_irq(uart->port.irq + 1, uart); |
| 656 | return -EBUSY; |
| 657 | } |
| 658 | } |
| 659 | # endif |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 660 | #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ |
| 661 | defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) |
| 662 | } |
| 663 | # endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 664 | #endif |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 665 | UART_SET_IER(uart, ERBFI); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | static void bfin_serial_shutdown(struct uart_port *port) |
| 670 | { |
| 671 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 672 | |
| 673 | #ifdef CONFIG_SERIAL_BFIN_DMA |
| 674 | disable_dma(uart->tx_dma_channel); |
| 675 | free_dma(uart->tx_dma_channel); |
| 676 | disable_dma(uart->rx_dma_channel); |
| 677 | free_dma(uart->rx_dma_channel); |
| 678 | del_timer(&(uart->rx_dma_timer)); |
Sonic Zhang | 75b780b | 2007-12-21 17:03:39 +0800 | [diff] [blame] | 679 | dma_free_coherent(NULL, PAGE_SIZE, uart->rx_dma_buf.buf, 0); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 680 | #else |
Sonic Zhang | ab2375f | 2008-10-13 10:33:51 +0100 | [diff] [blame] | 681 | #ifdef CONFIG_BF54x |
| 682 | switch (uart->port.irq) { |
| 683 | case IRQ_UART3_RX: |
| 684 | free_dma(CH_UART3_RX); |
| 685 | free_dma(CH_UART3_TX); |
| 686 | break; |
| 687 | case IRQ_UART2_RX: |
| 688 | free_dma(CH_UART2_RX); |
| 689 | free_dma(CH_UART2_TX); |
| 690 | break; |
| 691 | default: |
| 692 | break; |
| 693 | }; |
| 694 | #endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 695 | free_irq(uart->port.irq, uart); |
| 696 | free_irq(uart->port.irq+1, uart); |
| 697 | #endif |
| 698 | } |
| 699 | |
| 700 | static void |
| 701 | bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios, |
| 702 | struct ktermios *old) |
| 703 | { |
| 704 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 705 | unsigned long flags; |
| 706 | unsigned int baud, quot; |
Mike Frysinger | 0c44a86 | 2008-04-24 04:56:02 +0800 | [diff] [blame] | 707 | unsigned short val, ier, lcr = 0; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 708 | |
| 709 | switch (termios->c_cflag & CSIZE) { |
| 710 | case CS8: |
| 711 | lcr = WLS(8); |
| 712 | break; |
| 713 | case CS7: |
| 714 | lcr = WLS(7); |
| 715 | break; |
| 716 | case CS6: |
| 717 | lcr = WLS(6); |
| 718 | break; |
| 719 | case CS5: |
| 720 | lcr = WLS(5); |
| 721 | break; |
| 722 | default: |
| 723 | printk(KERN_ERR "%s: word lengh not supported\n", |
Harvey Harrison | 71cc2c2 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 724 | __func__); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | if (termios->c_cflag & CSTOPB) |
| 728 | lcr |= STB; |
Mike Frysinger | 19aa638 | 2007-06-11 16:16:45 +0800 | [diff] [blame] | 729 | if (termios->c_cflag & PARENB) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 730 | lcr |= PEN; |
Mike Frysinger | 19aa638 | 2007-06-11 16:16:45 +0800 | [diff] [blame] | 731 | if (!(termios->c_cflag & PARODD)) |
| 732 | lcr |= EPS; |
| 733 | if (termios->c_cflag & CMSPAR) |
| 734 | lcr |= STP; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 735 | |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 736 | port->read_status_mask = OE; |
| 737 | if (termios->c_iflag & INPCK) |
| 738 | port->read_status_mask |= (FE | PE); |
| 739 | if (termios->c_iflag & (BRKINT | PARMRK)) |
| 740 | port->read_status_mask |= BI; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 741 | |
Mike Frysinger | 2ac5ee4 | 2007-05-21 18:09:39 +0800 | [diff] [blame] | 742 | /* |
| 743 | * Characters to ignore |
| 744 | */ |
| 745 | port->ignore_status_mask = 0; |
| 746 | if (termios->c_iflag & IGNPAR) |
| 747 | port->ignore_status_mask |= FE | PE; |
| 748 | if (termios->c_iflag & IGNBRK) { |
| 749 | port->ignore_status_mask |= BI; |
| 750 | /* |
| 751 | * If we're ignoring parity and break indicators, |
| 752 | * ignore overruns too (for real raw support). |
| 753 | */ |
| 754 | if (termios->c_iflag & IGNPAR) |
| 755 | port->ignore_status_mask |= OE; |
| 756 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 757 | |
| 758 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); |
| 759 | quot = uart_get_divisor(port, baud); |
| 760 | spin_lock_irqsave(&uart->port.lock, flags); |
| 761 | |
Mike Frysinger | 8851c71 | 2007-12-24 19:48:04 +0800 | [diff] [blame] | 762 | UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15); |
| 763 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 764 | /* Disable UART */ |
| 765 | ier = UART_GET_IER(uart); |
Sonic Zhang | 1feaa51 | 2008-06-03 12:19:45 +0800 | [diff] [blame] | 766 | UART_DISABLE_INTS(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 767 | |
| 768 | /* Set DLAB in LCR to Access DLL and DLH */ |
Mike Frysinger | 45828b8 | 2008-05-07 11:41:26 +0800 | [diff] [blame] | 769 | UART_SET_DLAB(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 770 | |
| 771 | UART_PUT_DLL(uart, quot & 0xFF); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 772 | UART_PUT_DLH(uart, (quot >> 8) & 0xFF); |
| 773 | SSYNC(); |
| 774 | |
| 775 | /* Clear DLAB in LCR to Access THR RBR IER */ |
Mike Frysinger | 45828b8 | 2008-05-07 11:41:26 +0800 | [diff] [blame] | 776 | UART_CLEAR_DLAB(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 777 | |
| 778 | UART_PUT_LCR(uart, lcr); |
| 779 | |
| 780 | /* Enable UART */ |
Sonic Zhang | 1feaa51 | 2008-06-03 12:19:45 +0800 | [diff] [blame] | 781 | UART_ENABLE_INTS(uart, ier); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 782 | |
| 783 | val = UART_GET_GCTL(uart); |
| 784 | val |= UCEN; |
| 785 | UART_PUT_GCTL(uart, val); |
| 786 | |
Graf Yang | b3ef5ab | 2008-10-13 10:33:42 +0100 | [diff] [blame] | 787 | /* Port speed changed, update the per-port timeout. */ |
| 788 | uart_update_timeout(port, termios->c_cflag, baud); |
| 789 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 790 | spin_unlock_irqrestore(&uart->port.lock, flags); |
| 791 | } |
| 792 | |
| 793 | static const char *bfin_serial_type(struct uart_port *port) |
| 794 | { |
| 795 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 796 | |
| 797 | return uart->port.type == PORT_BFIN ? "BFIN-UART" : NULL; |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Release the memory region(s) being used by 'port'. |
| 802 | */ |
| 803 | static void bfin_serial_release_port(struct uart_port *port) |
| 804 | { |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Request the memory region(s) being used by 'port'. |
| 809 | */ |
| 810 | static int bfin_serial_request_port(struct uart_port *port) |
| 811 | { |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * Configure/autoconfigure the port. |
| 817 | */ |
| 818 | static void bfin_serial_config_port(struct uart_port *port, int flags) |
| 819 | { |
| 820 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 821 | |
| 822 | if (flags & UART_CONFIG_TYPE && |
| 823 | bfin_serial_request_port(&uart->port) == 0) |
| 824 | uart->port.type = PORT_BFIN; |
| 825 | } |
| 826 | |
| 827 | /* |
| 828 | * Verify the new serial_struct (for TIOCSSERIAL). |
| 829 | * The only change we allow are to the flags and type, and |
| 830 | * even then only between PORT_BFIN and PORT_UNKNOWN |
| 831 | */ |
| 832 | static int |
| 833 | bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 834 | { |
| 835 | return 0; |
| 836 | } |
| 837 | |
Graf Yang | 7d01b47 | 2008-02-29 11:31:08 +0800 | [diff] [blame] | 838 | /* |
| 839 | * Enable the IrDA function if tty->ldisc.num is N_IRDA. |
| 840 | * In other cases, disable IrDA function. |
| 841 | */ |
Graf Yang | 3b8458a | 2008-06-07 15:36:33 +0800 | [diff] [blame] | 842 | static void bfin_serial_set_ldisc(struct uart_port *port) |
Graf Yang | 7d01b47 | 2008-02-29 11:31:08 +0800 | [diff] [blame] | 843 | { |
Graf Yang | 3b8458a | 2008-06-07 15:36:33 +0800 | [diff] [blame] | 844 | int line = port->line; |
Graf Yang | 7d01b47 | 2008-02-29 11:31:08 +0800 | [diff] [blame] | 845 | unsigned short val; |
| 846 | |
Takashi Iwai | a88487c | 2008-07-16 21:54:42 +0100 | [diff] [blame] | 847 | if (line >= port->info->port.tty->driver->num) |
Graf Yang | 7d01b47 | 2008-02-29 11:31:08 +0800 | [diff] [blame] | 848 | return; |
| 849 | |
Alan Cox | b1cbefe | 2008-08-04 17:22:11 +0100 | [diff] [blame] | 850 | switch (port->info->port.tty->termios->c_line) { |
Graf Yang | 7d01b47 | 2008-02-29 11:31:08 +0800 | [diff] [blame] | 851 | case N_IRDA: |
| 852 | val = UART_GET_GCTL(&bfin_serial_ports[line]); |
| 853 | val |= (IREN | RPOLC); |
| 854 | UART_PUT_GCTL(&bfin_serial_ports[line], val); |
| 855 | break; |
| 856 | default: |
| 857 | val = UART_GET_GCTL(&bfin_serial_ports[line]); |
| 858 | val &= ~(IREN | RPOLC); |
| 859 | UART_PUT_GCTL(&bfin_serial_ports[line], val); |
| 860 | } |
| 861 | } |
| 862 | |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 863 | #ifdef CONFIG_CONSOLE_POLL |
| 864 | static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr) |
| 865 | { |
| 866 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 867 | |
| 868 | while (!(UART_GET_LSR(uart) & THRE)) |
| 869 | cpu_relax(); |
| 870 | |
| 871 | UART_CLEAR_DLAB(uart); |
| 872 | UART_PUT_CHAR(uart, (unsigned char)chr); |
| 873 | } |
| 874 | |
| 875 | static int bfin_serial_poll_get_char(struct uart_port *port) |
| 876 | { |
| 877 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 878 | unsigned char chr; |
| 879 | |
| 880 | while (!(UART_GET_LSR(uart) & DR)) |
| 881 | cpu_relax(); |
| 882 | |
| 883 | UART_CLEAR_DLAB(uart); |
| 884 | chr = UART_GET_CHAR(uart); |
| 885 | |
| 886 | return chr; |
| 887 | } |
| 888 | #endif |
| 889 | |
| 890 | #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ |
| 891 | defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) |
| 892 | static void bfin_kgdboc_port_shutdown(struct uart_port *port) |
| 893 | { |
| 894 | if (kgdboc_break_enabled) { |
| 895 | kgdboc_break_enabled = 0; |
| 896 | bfin_serial_shutdown(port); |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | static int bfin_kgdboc_port_startup(struct uart_port *port) |
| 901 | { |
| 902 | kgdboc_port_line = port->line; |
| 903 | kgdboc_break_enabled = !bfin_serial_startup(port); |
| 904 | return 0; |
| 905 | } |
| 906 | #endif |
| 907 | |
Graf Yang | 80d5c47 | 2009-01-02 13:40:22 +0000 | [diff] [blame] | 908 | static void bfin_serial_reset_irda(struct uart_port *port) |
| 909 | { |
| 910 | int line = port->line; |
| 911 | unsigned short val; |
| 912 | |
| 913 | val = UART_GET_GCTL(&bfin_serial_ports[line]); |
| 914 | val &= ~(IREN | RPOLC); |
| 915 | UART_PUT_GCTL(&bfin_serial_ports[line], val); |
| 916 | SSYNC(); |
| 917 | val |= (IREN | RPOLC); |
| 918 | UART_PUT_GCTL(&bfin_serial_ports[line], val); |
| 919 | SSYNC(); |
| 920 | } |
| 921 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 922 | static struct uart_ops bfin_serial_pops = { |
| 923 | .tx_empty = bfin_serial_tx_empty, |
| 924 | .set_mctrl = bfin_serial_set_mctrl, |
| 925 | .get_mctrl = bfin_serial_get_mctrl, |
| 926 | .stop_tx = bfin_serial_stop_tx, |
| 927 | .start_tx = bfin_serial_start_tx, |
| 928 | .stop_rx = bfin_serial_stop_rx, |
| 929 | .enable_ms = bfin_serial_enable_ms, |
| 930 | .break_ctl = bfin_serial_break_ctl, |
| 931 | .startup = bfin_serial_startup, |
| 932 | .shutdown = bfin_serial_shutdown, |
| 933 | .set_termios = bfin_serial_set_termios, |
Graf Yang | 3b8458a | 2008-06-07 15:36:33 +0800 | [diff] [blame] | 934 | .set_ldisc = bfin_serial_set_ldisc, |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 935 | .type = bfin_serial_type, |
| 936 | .release_port = bfin_serial_release_port, |
| 937 | .request_port = bfin_serial_request_port, |
| 938 | .config_port = bfin_serial_config_port, |
| 939 | .verify_port = bfin_serial_verify_port, |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 940 | #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \ |
| 941 | defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE) |
| 942 | .kgdboc_port_startup = bfin_kgdboc_port_startup, |
| 943 | .kgdboc_port_shutdown = bfin_kgdboc_port_shutdown, |
| 944 | #endif |
| 945 | #ifdef CONFIG_CONSOLE_POLL |
| 946 | .poll_put_char = bfin_serial_poll_put_char, |
| 947 | .poll_get_char = bfin_serial_poll_get_char, |
| 948 | #endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 949 | }; |
| 950 | |
| 951 | static void __init bfin_serial_init_ports(void) |
| 952 | { |
| 953 | static int first = 1; |
| 954 | int i; |
| 955 | |
| 956 | if (!first) |
| 957 | return; |
| 958 | first = 0; |
| 959 | |
Mike Frysinger | c9607ec | 2008-10-13 10:33:16 +0100 | [diff] [blame] | 960 | for (i = 0; i < nr_active_ports; i++) { |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 961 | bfin_serial_ports[i].port.uartclk = get_sclk(); |
Graf Yang | b3ef5ab | 2008-10-13 10:33:42 +0100 | [diff] [blame] | 962 | bfin_serial_ports[i].port.fifosize = BFIN_UART_TX_FIFO_SIZE; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 963 | bfin_serial_ports[i].port.ops = &bfin_serial_pops; |
| 964 | bfin_serial_ports[i].port.line = i; |
| 965 | bfin_serial_ports[i].port.iotype = UPIO_MEM; |
| 966 | bfin_serial_ports[i].port.membase = |
| 967 | (void __iomem *)bfin_serial_resource[i].uart_base_addr; |
| 968 | bfin_serial_ports[i].port.mapbase = |
| 969 | bfin_serial_resource[i].uart_base_addr; |
| 970 | bfin_serial_ports[i].port.irq = |
| 971 | bfin_serial_resource[i].uart_irq; |
| 972 | bfin_serial_ports[i].port.flags = UPF_BOOT_AUTOCONF; |
| 973 | #ifdef CONFIG_SERIAL_BFIN_DMA |
| 974 | bfin_serial_ports[i].tx_done = 1; |
| 975 | bfin_serial_ports[i].tx_count = 0; |
| 976 | bfin_serial_ports[i].tx_dma_channel = |
| 977 | bfin_serial_resource[i].uart_tx_dma_channel; |
| 978 | bfin_serial_ports[i].rx_dma_channel = |
| 979 | bfin_serial_resource[i].uart_rx_dma_channel; |
| 980 | init_timer(&(bfin_serial_ports[i].rx_dma_timer)); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 981 | #endif |
| 982 | #ifdef CONFIG_SERIAL_BFIN_CTSRTS |
Sonic Zhang | f30ac0c | 2008-06-19 17:46:39 +0800 | [diff] [blame] | 983 | init_timer(&(bfin_serial_ports[i].cts_timer)); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 984 | bfin_serial_ports[i].cts_pin = |
| 985 | bfin_serial_resource[i].uart_cts_pin; |
| 986 | bfin_serial_ports[i].rts_pin = |
| 987 | bfin_serial_resource[i].uart_rts_pin; |
| 988 | #endif |
| 989 | bfin_serial_hw_init(&bfin_serial_ports[i]); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 990 | } |
Roy Huang | f4d640c9 | 2007-07-12 16:43:46 +0800 | [diff] [blame] | 991 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Sonic Zhang | b6efa1e | 2009-01-02 13:40:31 +0000 | [diff] [blame] | 994 | #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 995 | /* |
| 996 | * If the port was already initialised (eg, by a boot loader), |
| 997 | * try to determine the current setup. |
| 998 | */ |
| 999 | static void __init |
| 1000 | bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud, |
| 1001 | int *parity, int *bits) |
| 1002 | { |
| 1003 | unsigned short status; |
| 1004 | |
| 1005 | status = UART_GET_IER(uart) & (ERBFI | ETBEI); |
| 1006 | if (status == (ERBFI | ETBEI)) { |
| 1007 | /* ok, the port was enabled */ |
Mike Frysinger | 45828b8 | 2008-05-07 11:41:26 +0800 | [diff] [blame] | 1008 | u16 lcr, dlh, dll; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1009 | |
| 1010 | lcr = UART_GET_LCR(uart); |
| 1011 | |
| 1012 | *parity = 'n'; |
| 1013 | if (lcr & PEN) { |
| 1014 | if (lcr & EPS) |
| 1015 | *parity = 'e'; |
| 1016 | else |
| 1017 | *parity = 'o'; |
| 1018 | } |
| 1019 | switch (lcr & 0x03) { |
| 1020 | case 0: *bits = 5; break; |
| 1021 | case 1: *bits = 6; break; |
| 1022 | case 2: *bits = 7; break; |
| 1023 | case 3: *bits = 8; break; |
| 1024 | } |
| 1025 | /* Set DLAB in LCR to Access DLL and DLH */ |
Mike Frysinger | 45828b8 | 2008-05-07 11:41:26 +0800 | [diff] [blame] | 1026 | UART_SET_DLAB(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1027 | |
| 1028 | dll = UART_GET_DLL(uart); |
| 1029 | dlh = UART_GET_DLH(uart); |
| 1030 | |
| 1031 | /* Clear DLAB in LCR to Access THR RBR IER */ |
Mike Frysinger | 45828b8 | 2008-05-07 11:41:26 +0800 | [diff] [blame] | 1032 | UART_CLEAR_DLAB(uart); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1033 | |
| 1034 | *baud = get_sclk() / (16*(dll | dlh << 8)); |
| 1035 | } |
Harvey Harrison | 71cc2c2 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 1036 | pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1037 | } |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1038 | |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1039 | static struct uart_driver bfin_serial_reg; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1040 | |
| 1041 | static int __init |
| 1042 | bfin_serial_console_setup(struct console *co, char *options) |
| 1043 | { |
| 1044 | struct bfin_serial_port *uart; |
| 1045 | int baud = 57600; |
| 1046 | int bits = 8; |
| 1047 | int parity = 'n'; |
Sonic Zhang | b6efa1e | 2009-01-02 13:40:31 +0000 | [diff] [blame] | 1048 | # ifdef CONFIG_SERIAL_BFIN_CTSRTS |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1049 | int flow = 'r'; |
Sonic Zhang | b6efa1e | 2009-01-02 13:40:31 +0000 | [diff] [blame] | 1050 | # else |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1051 | int flow = 'n'; |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1052 | # endif |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1053 | |
| 1054 | /* |
| 1055 | * Check whether an invalid uart number has been specified, and |
| 1056 | * if so, search for the first available port that does have |
| 1057 | * console support. |
| 1058 | */ |
Mike Frysinger | c9607ec | 2008-10-13 10:33:16 +0100 | [diff] [blame] | 1059 | if (co->index == -1 || co->index >= nr_active_ports) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1060 | co->index = 0; |
| 1061 | uart = &bfin_serial_ports[co->index]; |
| 1062 | |
| 1063 | if (options) |
| 1064 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1065 | else |
| 1066 | bfin_serial_console_get_options(uart, &baud, &parity, &bits); |
| 1067 | |
| 1068 | return uart_set_options(&uart->port, co, baud, parity, bits, flow); |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1069 | } |
| 1070 | #endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) || |
| 1071 | defined (CONFIG_EARLY_PRINTK) */ |
| 1072 | |
| 1073 | #ifdef CONFIG_SERIAL_BFIN_CONSOLE |
| 1074 | static void bfin_serial_console_putchar(struct uart_port *port, int ch) |
| 1075 | { |
| 1076 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 1077 | while (!(UART_GET_LSR(uart) & THRE)) |
| 1078 | barrier(); |
| 1079 | UART_PUT_CHAR(uart, ch); |
| 1080 | SSYNC(); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1083 | /* |
| 1084 | * Interrupts are disabled on entering |
| 1085 | */ |
| 1086 | static void |
| 1087 | bfin_serial_console_write(struct console *co, const char *s, unsigned int count) |
| 1088 | { |
| 1089 | struct bfin_serial_port *uart = &bfin_serial_ports[co->index]; |
| 1090 | int flags = 0; |
| 1091 | |
| 1092 | spin_lock_irqsave(&uart->port.lock, flags); |
| 1093 | uart_console_write(&uart->port, s, count, bfin_serial_console_putchar); |
| 1094 | spin_unlock_irqrestore(&uart->port.lock, flags); |
| 1095 | |
| 1096 | } |
| 1097 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1098 | static struct console bfin_serial_console = { |
| 1099 | .name = BFIN_SERIAL_NAME, |
| 1100 | .write = bfin_serial_console_write, |
| 1101 | .device = uart_console_device, |
| 1102 | .setup = bfin_serial_console_setup, |
| 1103 | .flags = CON_PRINTBUFFER, |
| 1104 | .index = -1, |
| 1105 | .data = &bfin_serial_reg, |
| 1106 | }; |
| 1107 | |
| 1108 | static int __init bfin_serial_rs_console_init(void) |
| 1109 | { |
| 1110 | bfin_serial_init_ports(); |
| 1111 | register_console(&bfin_serial_console); |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 1112 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1113 | return 0; |
| 1114 | } |
| 1115 | console_initcall(bfin_serial_rs_console_init); |
| 1116 | |
| 1117 | #define BFIN_SERIAL_CONSOLE &bfin_serial_console |
| 1118 | #else |
| 1119 | #define BFIN_SERIAL_CONSOLE NULL |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1120 | #endif /* CONFIG_SERIAL_BFIN_CONSOLE */ |
| 1121 | |
| 1122 | |
| 1123 | #ifdef CONFIG_EARLY_PRINTK |
| 1124 | static __init void early_serial_putc(struct uart_port *port, int ch) |
| 1125 | { |
| 1126 | unsigned timeout = 0xffff; |
| 1127 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
| 1128 | |
| 1129 | while ((!(UART_GET_LSR(uart) & THRE)) && --timeout) |
| 1130 | cpu_relax(); |
| 1131 | UART_PUT_CHAR(uart, ch); |
| 1132 | } |
| 1133 | |
| 1134 | static __init void early_serial_write(struct console *con, const char *s, |
| 1135 | unsigned int n) |
| 1136 | { |
| 1137 | struct bfin_serial_port *uart = &bfin_serial_ports[con->index]; |
| 1138 | unsigned int i; |
| 1139 | |
| 1140 | for (i = 0; i < n; i++, s++) { |
| 1141 | if (*s == '\n') |
| 1142 | early_serial_putc(&uart->port, '\r'); |
| 1143 | early_serial_putc(&uart->port, *s); |
| 1144 | } |
| 1145 | } |
| 1146 | |
Mike Frysinger | c111340 | 2008-10-13 10:32:35 +0100 | [diff] [blame] | 1147 | static struct __initdata console bfin_early_serial_console = { |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1148 | .name = "early_BFuart", |
| 1149 | .write = early_serial_write, |
| 1150 | .device = uart_console_device, |
| 1151 | .flags = CON_PRINTBUFFER, |
| 1152 | .setup = bfin_serial_console_setup, |
| 1153 | .index = -1, |
| 1154 | .data = &bfin_serial_reg, |
| 1155 | }; |
| 1156 | |
| 1157 | struct console __init *bfin_earlyserial_init(unsigned int port, |
| 1158 | unsigned int cflag) |
| 1159 | { |
| 1160 | struct bfin_serial_port *uart; |
| 1161 | struct ktermios t; |
| 1162 | |
Mike Frysinger | c9607ec | 2008-10-13 10:33:16 +0100 | [diff] [blame] | 1163 | if (port == -1 || port >= nr_active_ports) |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1164 | port = 0; |
| 1165 | bfin_serial_init_ports(); |
| 1166 | bfin_early_serial_console.index = port; |
Robin Getz | 0ae5364 | 2007-10-09 17:24:49 +0800 | [diff] [blame] | 1167 | uart = &bfin_serial_ports[port]; |
| 1168 | t.c_cflag = cflag; |
| 1169 | t.c_iflag = 0; |
| 1170 | t.c_oflag = 0; |
| 1171 | t.c_lflag = ICANON; |
| 1172 | t.c_line = port; |
| 1173 | bfin_serial_set_termios(&uart->port, &t, &t); |
| 1174 | return &bfin_early_serial_console; |
| 1175 | } |
| 1176 | |
Sonic Zhang | b6efa1e | 2009-01-02 13:40:31 +0000 | [diff] [blame] | 1177 | #endif /* CONFIG_EARLY_PRINTK */ |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1178 | |
| 1179 | static struct uart_driver bfin_serial_reg = { |
| 1180 | .owner = THIS_MODULE, |
| 1181 | .driver_name = "bfin-uart", |
| 1182 | .dev_name = BFIN_SERIAL_NAME, |
| 1183 | .major = BFIN_SERIAL_MAJOR, |
| 1184 | .minor = BFIN_SERIAL_MINOR, |
Graf Yang | 2ade972 | 2008-04-25 02:55:49 +0800 | [diff] [blame] | 1185 | .nr = BFIN_UART_NR_PORTS, |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1186 | .cons = BFIN_SERIAL_CONSOLE, |
| 1187 | }; |
| 1188 | |
| 1189 | static int bfin_serial_suspend(struct platform_device *dev, pm_message_t state) |
| 1190 | { |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1191 | int i; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1192 | |
Mike Frysinger | c9607ec | 2008-10-13 10:33:16 +0100 | [diff] [blame] | 1193 | for (i = 0; i < nr_active_ports; i++) { |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1194 | if (bfin_serial_ports[i].port.dev != &dev->dev) |
| 1195 | continue; |
| 1196 | uart_suspend_port(&bfin_serial_reg, &bfin_serial_ports[i].port); |
| 1197 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
| 1202 | static int bfin_serial_resume(struct platform_device *dev) |
| 1203 | { |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1204 | int i; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1205 | |
Mike Frysinger | c9607ec | 2008-10-13 10:33:16 +0100 | [diff] [blame] | 1206 | for (i = 0; i < nr_active_ports; i++) { |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1207 | if (bfin_serial_ports[i].port.dev != &dev->dev) |
| 1208 | continue; |
| 1209 | uart_resume_port(&bfin_serial_reg, &bfin_serial_ports[i].port); |
| 1210 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1211 | |
| 1212 | return 0; |
| 1213 | } |
| 1214 | |
| 1215 | static int bfin_serial_probe(struct platform_device *dev) |
| 1216 | { |
| 1217 | struct resource *res = dev->resource; |
| 1218 | int i; |
| 1219 | |
| 1220 | for (i = 0; i < dev->num_resources; i++, res++) |
| 1221 | if (res->flags & IORESOURCE_MEM) |
| 1222 | break; |
| 1223 | |
| 1224 | if (i < dev->num_resources) { |
Mike Frysinger | c9607ec | 2008-10-13 10:33:16 +0100 | [diff] [blame] | 1225 | for (i = 0; i < nr_active_ports; i++, res++) { |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1226 | if (bfin_serial_ports[i].port.mapbase != res->start) |
| 1227 | continue; |
| 1228 | bfin_serial_ports[i].port.dev = &dev->dev; |
| 1229 | uart_add_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1236 | static int bfin_serial_remove(struct platform_device *dev) |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1237 | { |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1238 | int i; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1239 | |
Mike Frysinger | c9607ec | 2008-10-13 10:33:16 +0100 | [diff] [blame] | 1240 | for (i = 0; i < nr_active_ports; i++) { |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1241 | if (bfin_serial_ports[i].port.dev != &dev->dev) |
| 1242 | continue; |
| 1243 | uart_remove_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port); |
| 1244 | bfin_serial_ports[i].port.dev = NULL; |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1245 | #ifdef CONFIG_SERIAL_BFIN_CTSRTS |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1246 | gpio_free(bfin_serial_ports[i].cts_pin); |
| 1247 | gpio_free(bfin_serial_ports[i].rts_pin); |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1248 | #endif |
Sonic Zhang | ccfbc3e | 2008-10-13 10:32:44 +0100 | [diff] [blame] | 1249 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1250 | |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
| 1254 | static struct platform_driver bfin_serial_driver = { |
| 1255 | .probe = bfin_serial_probe, |
| 1256 | .remove = bfin_serial_remove, |
| 1257 | .suspend = bfin_serial_suspend, |
| 1258 | .resume = bfin_serial_resume, |
| 1259 | .driver = { |
| 1260 | .name = "bfin-uart", |
Kay Sievers | e169c13 | 2008-04-15 14:34:35 -0700 | [diff] [blame] | 1261 | .owner = THIS_MODULE, |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1262 | }, |
| 1263 | }; |
| 1264 | |
| 1265 | static int __init bfin_serial_init(void) |
| 1266 | { |
| 1267 | int ret; |
| 1268 | |
| 1269 | pr_info("Serial: Blackfin serial driver\n"); |
| 1270 | |
| 1271 | bfin_serial_init_ports(); |
| 1272 | |
| 1273 | ret = uart_register_driver(&bfin_serial_reg); |
| 1274 | if (ret == 0) { |
| 1275 | ret = platform_driver_register(&bfin_serial_driver); |
| 1276 | if (ret) { |
| 1277 | pr_debug("uart register failed\n"); |
| 1278 | uart_unregister_driver(&bfin_serial_reg); |
| 1279 | } |
| 1280 | } |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1281 | return ret; |
| 1282 | } |
| 1283 | |
| 1284 | static void __exit bfin_serial_exit(void) |
| 1285 | { |
| 1286 | platform_driver_unregister(&bfin_serial_driver); |
| 1287 | uart_unregister_driver(&bfin_serial_reg); |
| 1288 | } |
| 1289 | |
Sonic Zhang | 52e15f0e | 2009-01-02 13:40:14 +0000 | [diff] [blame] | 1290 | |
Bryan Wu | 194de56 | 2007-05-06 14:50:30 -0700 | [diff] [blame] | 1291 | module_init(bfin_serial_init); |
| 1292 | module_exit(bfin_serial_exit); |
| 1293 | |
| 1294 | MODULE_AUTHOR("Aubrey.Li <aubrey.li@analog.com>"); |
| 1295 | MODULE_DESCRIPTION("Blackfin generic serial port driver"); |
| 1296 | MODULE_LICENSE("GPL"); |
| 1297 | MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR); |
Kay Sievers | e169c13 | 2008-04-15 14:34:35 -0700 | [diff] [blame] | 1298 | MODULE_ALIAS("platform:bfin-uart"); |