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