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