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