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