Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Driver for OMAP-UART controller. |
| 3 | * Based on drivers/serial/8250.c |
| 4 | * |
| 5 | * Copyright (C) 2010 Texas Instruments. |
| 6 | * |
| 7 | * Authors: |
| 8 | * Govindraj R <govindraj.raja@ti.com> |
| 9 | * Thara Gopinath <thara@ti.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 16 | * Note: This driver is made separate from 8250 driver as we cannot |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 17 | * over load 8250 driver with omap platform specific configuration for |
| 18 | * features like DMA, it makes easier to implement features like DMA and |
| 19 | * hardware flow control and software flow control configuration with |
| 20 | * this driver as required for the omap-platform. |
| 21 | */ |
| 22 | |
Thomas Weber | 364a6ec | 2011-02-01 08:30:41 +0100 | [diff] [blame] | 23 | #if defined(CONFIG_SERIAL_OMAP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 24 | #define SUPPORT_SYSRQ |
| 25 | #endif |
| 26 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/console.h> |
| 30 | #include <linux/serial_reg.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/tty.h> |
| 34 | #include <linux/tty_flip.h> |
Felipe Balbi | d21e400 | 2012-09-06 15:45:38 +0300 | [diff] [blame^] | 35 | #include <linux/platform_device.h> |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 36 | #include <linux/io.h> |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 37 | #include <linux/clk.h> |
| 38 | #include <linux/serial_core.h> |
| 39 | #include <linux/irq.h> |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 40 | #include <linux/pm_runtime.h> |
Rajendra Nayak | d92b0df | 2011-12-14 17:25:45 +0530 | [diff] [blame] | 41 | #include <linux/of.h> |
NeilBrown | 9574f36 | 2012-07-30 10:30:26 +1000 | [diff] [blame] | 42 | #include <linux/gpio.h> |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 43 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 44 | #include <plat/omap-serial.h> |
| 45 | |
Govindraj.R | 7c77c8d | 2012-04-03 19:12:34 +0530 | [diff] [blame] | 46 | #define UART_BUILD_REVISION(x, y) (((x) << 8) | (y)) |
| 47 | |
| 48 | #define OMAP_UART_REV_42 0x0402 |
| 49 | #define OMAP_UART_REV_46 0x0406 |
| 50 | #define OMAP_UART_REV_52 0x0502 |
| 51 | #define OMAP_UART_REV_63 0x0603 |
| 52 | |
Rajendra Nayak | 8fe789d | 2011-12-14 17:25:44 +0530 | [diff] [blame] | 53 | #define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/ |
| 54 | |
Paul Walmsley | 0ba5f66 | 2012-01-25 19:50:36 -0700 | [diff] [blame] | 55 | /* SCR register bitmasks */ |
| 56 | #define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7) |
| 57 | |
| 58 | /* FCR register bitmasks */ |
| 59 | #define OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT 6 |
| 60 | #define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6) |
| 61 | |
Govindraj.R | 7c77c8d | 2012-04-03 19:12:34 +0530 | [diff] [blame] | 62 | /* MVR register bitmasks */ |
| 63 | #define OMAP_UART_MVR_SCHEME_SHIFT 30 |
| 64 | |
| 65 | #define OMAP_UART_LEGACY_MVR_MAJ_MASK 0xf0 |
| 66 | #define OMAP_UART_LEGACY_MVR_MAJ_SHIFT 4 |
| 67 | #define OMAP_UART_LEGACY_MVR_MIN_MASK 0x0f |
| 68 | |
| 69 | #define OMAP_UART_MVR_MAJ_MASK 0x700 |
| 70 | #define OMAP_UART_MVR_MAJ_SHIFT 8 |
| 71 | #define OMAP_UART_MVR_MIN_MASK 0x3f |
| 72 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 73 | static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS]; |
| 74 | |
| 75 | /* Forward declaration of functions */ |
Govindraj.R | 9473474 | 2011-11-07 19:00:33 +0530 | [diff] [blame] | 76 | static void serial_omap_mdr1_errataset(struct uart_omap_port *up, u8 mdr1); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 77 | |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 78 | static struct workqueue_struct *serial_omap_uart_wq; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 79 | |
| 80 | static inline unsigned int serial_in(struct uart_omap_port *up, int offset) |
| 81 | { |
| 82 | offset <<= up->port.regshift; |
| 83 | return readw(up->port.membase + offset); |
| 84 | } |
| 85 | |
| 86 | static inline void serial_out(struct uart_omap_port *up, int offset, int value) |
| 87 | { |
| 88 | offset <<= up->port.regshift; |
| 89 | writew(value, up->port.membase + offset); |
| 90 | } |
| 91 | |
| 92 | static inline void serial_omap_clear_fifos(struct uart_omap_port *up) |
| 93 | { |
| 94 | serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
| 95 | serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | |
| 96 | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); |
| 97 | serial_out(up, UART_FCR, 0); |
| 98 | } |
| 99 | |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 100 | static int serial_omap_get_context_loss_count(struct uart_omap_port *up) |
| 101 | { |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 102 | struct omap_uart_port_info *pdata = up->dev->platform_data; |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 103 | |
| 104 | if (!pdata->get_context_loss_count) |
| 105 | return 0; |
| 106 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 107 | return pdata->get_context_loss_count(up->dev); |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static void serial_omap_set_forceidle(struct uart_omap_port *up) |
| 111 | { |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 112 | struct omap_uart_port_info *pdata = up->dev->platform_data; |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 113 | |
| 114 | if (pdata->set_forceidle) |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 115 | pdata->set_forceidle(up->dev); |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static void serial_omap_set_noidle(struct uart_omap_port *up) |
| 119 | { |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 120 | struct omap_uart_port_info *pdata = up->dev->platform_data; |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 121 | |
| 122 | if (pdata->set_noidle) |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 123 | pdata->set_noidle(up->dev); |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable) |
| 127 | { |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 128 | struct omap_uart_port_info *pdata = up->dev->platform_data; |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 129 | |
| 130 | if (pdata->enable_wakeup) |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 131 | pdata->enable_wakeup(up->dev, enable); |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 132 | } |
| 133 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 134 | /* |
| 135 | * serial_omap_get_divisor - calculate divisor value |
| 136 | * @port: uart port info |
| 137 | * @baud: baudrate for which divisor needs to be calculated. |
| 138 | * |
| 139 | * We have written our own function to get the divisor so as to support |
| 140 | * 13x mode. 3Mbps Baudrate as an different divisor. |
| 141 | * Reference OMAP TRM Chapter 17: |
| 142 | * Table 17-1. UART Mode Baud Rates, Divisor Values, and Error Rates |
| 143 | * referring to oversampling - divisor value |
| 144 | * baudrate 460,800 to 3,686,400 all have divisor 13 |
| 145 | * except 3,000,000 which has divisor value 16 |
| 146 | */ |
| 147 | static unsigned int |
| 148 | serial_omap_get_divisor(struct uart_port *port, unsigned int baud) |
| 149 | { |
| 150 | unsigned int divisor; |
| 151 | |
| 152 | if (baud > OMAP_MODE13X_SPEED && baud != 3000000) |
| 153 | divisor = 13; |
| 154 | else |
| 155 | divisor = 16; |
| 156 | return port->uartclk/(baud * divisor); |
| 157 | } |
| 158 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 159 | static void serial_omap_enable_ms(struct uart_port *port) |
| 160 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 161 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 162 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 163 | dev_dbg(up->port.dev, "serial_omap_enable_ms+%d\n", up->port.line); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 164 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 165 | pm_runtime_get_sync(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 166 | up->ier |= UART_IER_MSI; |
| 167 | serial_out(up, UART_IER, up->ier); |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 168 | pm_runtime_mark_last_busy(up->dev); |
| 169 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static void serial_omap_stop_tx(struct uart_port *port) |
| 173 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 174 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 175 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 176 | pm_runtime_get_sync(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 177 | if (up->ier & UART_IER_THRI) { |
| 178 | up->ier &= ~UART_IER_THRI; |
| 179 | serial_out(up, UART_IER, up->ier); |
| 180 | } |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 181 | |
Felipe Balbi | 4945743 | 2012-09-06 15:45:21 +0300 | [diff] [blame] | 182 | serial_omap_set_forceidle(up); |
Paul Walmsley | be4b028 | 2012-01-25 19:50:52 -0700 | [diff] [blame] | 183 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 184 | pm_runtime_mark_last_busy(up->dev); |
| 185 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static void serial_omap_stop_rx(struct uart_port *port) |
| 189 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 190 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 191 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 192 | pm_runtime_get_sync(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 193 | up->ier &= ~UART_IER_RLSI; |
| 194 | up->port.read_status_mask &= ~UART_LSR_DR; |
| 195 | serial_out(up, UART_IER, up->ier); |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 196 | pm_runtime_mark_last_busy(up->dev); |
| 197 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 198 | } |
| 199 | |
Felipe Balbi | bf63a08 | 2012-09-06 15:45:25 +0300 | [diff] [blame] | 200 | static void transmit_chars(struct uart_omap_port *up, unsigned int lsr) |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 201 | { |
| 202 | struct circ_buf *xmit = &up->port.state->xmit; |
| 203 | int count; |
| 204 | |
Felipe Balbi | bf63a08 | 2012-09-06 15:45:25 +0300 | [diff] [blame] | 205 | if (!(lsr & UART_LSR_THRE)) |
| 206 | return; |
| 207 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 208 | if (up->port.x_char) { |
| 209 | serial_out(up, UART_TX, up->port.x_char); |
| 210 | up->port.icount.tx++; |
| 211 | up->port.x_char = 0; |
| 212 | return; |
| 213 | } |
| 214 | if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { |
| 215 | serial_omap_stop_tx(&up->port); |
| 216 | return; |
| 217 | } |
Greg Kroah-Hartman | af681ca | 2012-01-26 11:14:42 -0800 | [diff] [blame] | 218 | count = up->port.fifosize / 4; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 219 | do { |
| 220 | serial_out(up, UART_TX, xmit->buf[xmit->tail]); |
| 221 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 222 | up->port.icount.tx++; |
| 223 | if (uart_circ_empty(xmit)) |
| 224 | break; |
| 225 | } while (--count > 0); |
| 226 | |
Ruchika Kharwar | 0324a82 | 2012-09-06 15:45:34 +0300 | [diff] [blame] | 227 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) { |
| 228 | spin_unlock(&up->port.lock); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 229 | uart_write_wakeup(&up->port); |
Ruchika Kharwar | 0324a82 | 2012-09-06 15:45:34 +0300 | [diff] [blame] | 230 | spin_lock(&up->port.lock); |
| 231 | } |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 232 | |
| 233 | if (uart_circ_empty(xmit)) |
| 234 | serial_omap_stop_tx(&up->port); |
| 235 | } |
| 236 | |
| 237 | static inline void serial_omap_enable_ier_thri(struct uart_omap_port *up) |
| 238 | { |
| 239 | if (!(up->ier & UART_IER_THRI)) { |
| 240 | up->ier |= UART_IER_THRI; |
| 241 | serial_out(up, UART_IER, up->ier); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | static void serial_omap_start_tx(struct uart_port *port) |
| 246 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 247 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 248 | |
Felipe Balbi | 4945743 | 2012-09-06 15:45:21 +0300 | [diff] [blame] | 249 | pm_runtime_get_sync(up->dev); |
| 250 | serial_omap_enable_ier_thri(up); |
| 251 | serial_omap_set_noidle(up); |
| 252 | pm_runtime_mark_last_busy(up->dev); |
| 253 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static unsigned int check_modem_status(struct uart_omap_port *up) |
| 257 | { |
| 258 | unsigned int status; |
| 259 | |
| 260 | status = serial_in(up, UART_MSR); |
| 261 | status |= up->msr_saved_flags; |
| 262 | up->msr_saved_flags = 0; |
| 263 | if ((status & UART_MSR_ANY_DELTA) == 0) |
| 264 | return status; |
| 265 | |
| 266 | if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && |
| 267 | up->port.state != NULL) { |
| 268 | if (status & UART_MSR_TERI) |
| 269 | up->port.icount.rng++; |
| 270 | if (status & UART_MSR_DDSR) |
| 271 | up->port.icount.dsr++; |
| 272 | if (status & UART_MSR_DDCD) |
| 273 | uart_handle_dcd_change |
| 274 | (&up->port, status & UART_MSR_DCD); |
| 275 | if (status & UART_MSR_DCTS) |
| 276 | uart_handle_cts_change |
| 277 | (&up->port, status & UART_MSR_CTS); |
| 278 | wake_up_interruptible(&up->port.state->port.delta_msr_wait); |
| 279 | } |
| 280 | |
| 281 | return status; |
| 282 | } |
| 283 | |
Felipe Balbi | 72256cb | 2012-09-06 15:45:24 +0300 | [diff] [blame] | 284 | static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr) |
| 285 | { |
| 286 | unsigned int flag; |
| 287 | |
| 288 | up->port.icount.rx++; |
| 289 | flag = TTY_NORMAL; |
| 290 | |
| 291 | if (lsr & UART_LSR_BI) { |
| 292 | flag = TTY_BREAK; |
| 293 | lsr &= ~(UART_LSR_FE | UART_LSR_PE); |
| 294 | up->port.icount.brk++; |
| 295 | /* |
| 296 | * We do the SysRQ and SAK checking |
| 297 | * here because otherwise the break |
| 298 | * may get masked by ignore_status_mask |
| 299 | * or read_status_mask. |
| 300 | */ |
| 301 | if (uart_handle_break(&up->port)) |
| 302 | return; |
| 303 | |
| 304 | } |
| 305 | |
| 306 | if (lsr & UART_LSR_PE) { |
| 307 | flag = TTY_PARITY; |
| 308 | up->port.icount.parity++; |
| 309 | } |
| 310 | |
| 311 | if (lsr & UART_LSR_FE) { |
| 312 | flag = TTY_FRAME; |
| 313 | up->port.icount.frame++; |
| 314 | } |
| 315 | |
| 316 | if (lsr & UART_LSR_OE) |
| 317 | up->port.icount.overrun++; |
| 318 | |
| 319 | #ifdef CONFIG_SERIAL_OMAP_CONSOLE |
| 320 | if (up->port.line == up->port.cons->index) { |
| 321 | /* Recover the break flag from console xmit */ |
| 322 | lsr |= up->lsr_break_flag; |
| 323 | } |
| 324 | #endif |
| 325 | uart_insert_char(&up->port, lsr, UART_LSR_OE, 0, flag); |
| 326 | } |
| 327 | |
| 328 | static void serial_omap_rdi(struct uart_omap_port *up, unsigned int lsr) |
| 329 | { |
| 330 | unsigned char ch = 0; |
| 331 | unsigned int flag; |
| 332 | |
| 333 | if (!(lsr & UART_LSR_DR)) |
| 334 | return; |
| 335 | |
| 336 | ch = serial_in(up, UART_RX); |
| 337 | flag = TTY_NORMAL; |
| 338 | up->port.icount.rx++; |
| 339 | |
| 340 | if (uart_handle_sysrq_char(&up->port, ch)) |
| 341 | return; |
| 342 | |
| 343 | uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag); |
| 344 | } |
| 345 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 346 | /** |
| 347 | * serial_omap_irq() - This handles the interrupt from one port |
| 348 | * @irq: uart port irq number |
| 349 | * @dev_id: uart port info |
| 350 | */ |
Felipe Balbi | 52c5513 | 2012-09-06 15:45:33 +0300 | [diff] [blame] | 351 | static irqreturn_t serial_omap_irq(int irq, void *dev_id) |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 352 | { |
| 353 | struct uart_omap_port *up = dev_id; |
Felipe Balbi | 72256cb | 2012-09-06 15:45:24 +0300 | [diff] [blame] | 354 | struct tty_struct *tty = up->port.state->port.tty; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 355 | unsigned int iir, lsr; |
Felipe Balbi | 81b75ae | 2012-09-06 15:45:23 +0300 | [diff] [blame] | 356 | unsigned int type; |
Felipe Balbi | 81b75ae | 2012-09-06 15:45:23 +0300 | [diff] [blame] | 357 | irqreturn_t ret = IRQ_NONE; |
Felipe Balbi | 72256cb | 2012-09-06 15:45:24 +0300 | [diff] [blame] | 358 | int max_count = 256; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 359 | |
Felipe Balbi | 6c3a30c | 2012-09-06 15:45:30 +0300 | [diff] [blame] | 360 | spin_lock(&up->port.lock); |
Felipe Balbi | 81b75ae | 2012-09-06 15:45:23 +0300 | [diff] [blame] | 361 | pm_runtime_get_sync(up->dev); |
Felipe Balbi | 81b75ae | 2012-09-06 15:45:23 +0300 | [diff] [blame] | 362 | |
Felipe Balbi | 72256cb | 2012-09-06 15:45:24 +0300 | [diff] [blame] | 363 | do { |
Felipe Balbi | 81b75ae | 2012-09-06 15:45:23 +0300 | [diff] [blame] | 364 | iir = serial_in(up, UART_IIR); |
Felipe Balbi | 72256cb | 2012-09-06 15:45:24 +0300 | [diff] [blame] | 365 | if (iir & UART_IIR_NO_INT) |
| 366 | break; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 367 | |
Felipe Balbi | 72256cb | 2012-09-06 15:45:24 +0300 | [diff] [blame] | 368 | ret = IRQ_HANDLED; |
| 369 | lsr = serial_in(up, UART_LSR); |
| 370 | |
| 371 | /* extract IRQ type from IIR register */ |
| 372 | type = iir & 0x3e; |
| 373 | |
| 374 | switch (type) { |
| 375 | case UART_IIR_MSI: |
| 376 | check_modem_status(up); |
| 377 | break; |
| 378 | case UART_IIR_THRI: |
Felipe Balbi | bf63a08 | 2012-09-06 15:45:25 +0300 | [diff] [blame] | 379 | transmit_chars(up, lsr); |
Felipe Balbi | 72256cb | 2012-09-06 15:45:24 +0300 | [diff] [blame] | 380 | break; |
| 381 | case UART_IIR_RX_TIMEOUT: |
| 382 | /* FALLTHROUGH */ |
| 383 | case UART_IIR_RDI: |
| 384 | serial_omap_rdi(up, lsr); |
| 385 | break; |
| 386 | case UART_IIR_RLSI: |
| 387 | serial_omap_rlsi(up, lsr); |
| 388 | break; |
| 389 | case UART_IIR_CTS_RTS_DSR: |
| 390 | /* simply try again */ |
| 391 | break; |
| 392 | case UART_IIR_XOFF: |
| 393 | /* FALLTHROUGH */ |
| 394 | default: |
| 395 | break; |
| 396 | } |
| 397 | } while (!(iir & UART_IIR_NO_INT) && max_count--); |
| 398 | |
Felipe Balbi | 6c3a30c | 2012-09-06 15:45:30 +0300 | [diff] [blame] | 399 | spin_unlock(&up->port.lock); |
Felipe Balbi | 72256cb | 2012-09-06 15:45:24 +0300 | [diff] [blame] | 400 | |
| 401 | tty_flip_buffer_push(tty); |
| 402 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 403 | pm_runtime_mark_last_busy(up->dev); |
| 404 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 405 | up->port_activity = jiffies; |
Felipe Balbi | 81b75ae | 2012-09-06 15:45:23 +0300 | [diff] [blame] | 406 | |
| 407 | return ret; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static unsigned int serial_omap_tx_empty(struct uart_port *port) |
| 411 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 412 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 413 | unsigned long flags = 0; |
| 414 | unsigned int ret = 0; |
| 415 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 416 | pm_runtime_get_sync(up->dev); |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 417 | dev_dbg(up->port.dev, "serial_omap_tx_empty+%d\n", up->port.line); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 418 | spin_lock_irqsave(&up->port.lock, flags); |
| 419 | ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; |
| 420 | spin_unlock_irqrestore(&up->port.lock, flags); |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 421 | pm_runtime_mark_last_busy(up->dev); |
| 422 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | static unsigned int serial_omap_get_mctrl(struct uart_port *port) |
| 427 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 428 | struct uart_omap_port *up = to_uart_omap_port(port); |
Shubhrajyoti D | 514f31d | 2011-11-21 15:43:28 +0530 | [diff] [blame] | 429 | unsigned int status; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 430 | unsigned int ret = 0; |
| 431 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 432 | pm_runtime_get_sync(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 433 | status = check_modem_status(up); |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 434 | pm_runtime_mark_last_busy(up->dev); |
| 435 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 436 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 437 | dev_dbg(up->port.dev, "serial_omap_get_mctrl+%d\n", up->port.line); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 438 | |
| 439 | if (status & UART_MSR_DCD) |
| 440 | ret |= TIOCM_CAR; |
| 441 | if (status & UART_MSR_RI) |
| 442 | ret |= TIOCM_RNG; |
| 443 | if (status & UART_MSR_DSR) |
| 444 | ret |= TIOCM_DSR; |
| 445 | if (status & UART_MSR_CTS) |
| 446 | ret |= TIOCM_CTS; |
| 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | static void serial_omap_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 451 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 452 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 453 | unsigned char mcr = 0; |
| 454 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 455 | dev_dbg(up->port.dev, "serial_omap_set_mctrl+%d\n", up->port.line); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 456 | if (mctrl & TIOCM_RTS) |
| 457 | mcr |= UART_MCR_RTS; |
| 458 | if (mctrl & TIOCM_DTR) |
| 459 | mcr |= UART_MCR_DTR; |
| 460 | if (mctrl & TIOCM_OUT1) |
| 461 | mcr |= UART_MCR_OUT1; |
| 462 | if (mctrl & TIOCM_OUT2) |
| 463 | mcr |= UART_MCR_OUT2; |
| 464 | if (mctrl & TIOCM_LOOP) |
| 465 | mcr |= UART_MCR_LOOP; |
| 466 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 467 | pm_runtime_get_sync(up->dev); |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 468 | up->mcr = serial_in(up, UART_MCR); |
| 469 | up->mcr |= mcr; |
| 470 | serial_out(up, UART_MCR, up->mcr); |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 471 | pm_runtime_mark_last_busy(up->dev); |
| 472 | pm_runtime_put_autosuspend(up->dev); |
NeilBrown | 9574f36 | 2012-07-30 10:30:26 +1000 | [diff] [blame] | 473 | |
| 474 | if (gpio_is_valid(up->DTR_gpio) && |
| 475 | !!(mctrl & TIOCM_DTR) != up->DTR_active) { |
| 476 | up->DTR_active = !up->DTR_active; |
| 477 | if (gpio_cansleep(up->DTR_gpio)) |
| 478 | schedule_work(&up->qos_work); |
| 479 | else |
| 480 | gpio_set_value(up->DTR_gpio, |
| 481 | up->DTR_active != up->DTR_inverted); |
| 482 | } |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | static void serial_omap_break_ctl(struct uart_port *port, int break_state) |
| 486 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 487 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 488 | unsigned long flags = 0; |
| 489 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 490 | dev_dbg(up->port.dev, "serial_omap_break_ctl+%d\n", up->port.line); |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 491 | pm_runtime_get_sync(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 492 | spin_lock_irqsave(&up->port.lock, flags); |
| 493 | if (break_state == -1) |
| 494 | up->lcr |= UART_LCR_SBC; |
| 495 | else |
| 496 | up->lcr &= ~UART_LCR_SBC; |
| 497 | serial_out(up, UART_LCR, up->lcr); |
| 498 | spin_unlock_irqrestore(&up->port.lock, flags); |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 499 | pm_runtime_mark_last_busy(up->dev); |
| 500 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static int serial_omap_startup(struct uart_port *port) |
| 504 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 505 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 506 | unsigned long flags = 0; |
| 507 | int retval; |
| 508 | |
| 509 | /* |
| 510 | * Allocate the IRQ |
| 511 | */ |
| 512 | retval = request_irq(up->port.irq, serial_omap_irq, up->port.irqflags, |
| 513 | up->name, up); |
| 514 | if (retval) |
| 515 | return retval; |
| 516 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 517 | dev_dbg(up->port.dev, "serial_omap_startup+%d\n", up->port.line); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 518 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 519 | pm_runtime_get_sync(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 520 | /* |
| 521 | * Clear the FIFO buffers and disable them. |
| 522 | * (they will be reenabled in set_termios()) |
| 523 | */ |
| 524 | serial_omap_clear_fifos(up); |
| 525 | /* For Hardware flow control */ |
| 526 | serial_out(up, UART_MCR, UART_MCR_RTS); |
| 527 | |
| 528 | /* |
| 529 | * Clear the interrupt registers. |
| 530 | */ |
| 531 | (void) serial_in(up, UART_LSR); |
| 532 | if (serial_in(up, UART_LSR) & UART_LSR_DR) |
| 533 | (void) serial_in(up, UART_RX); |
| 534 | (void) serial_in(up, UART_IIR); |
| 535 | (void) serial_in(up, UART_MSR); |
| 536 | |
| 537 | /* |
| 538 | * Now, initialize the UART |
| 539 | */ |
| 540 | serial_out(up, UART_LCR, UART_LCR_WLEN8); |
| 541 | spin_lock_irqsave(&up->port.lock, flags); |
| 542 | /* |
| 543 | * Most PC uarts need OUT2 raised to enable interrupts. |
| 544 | */ |
| 545 | up->port.mctrl |= TIOCM_OUT2; |
| 546 | serial_omap_set_mctrl(&up->port, up->port.mctrl); |
| 547 | spin_unlock_irqrestore(&up->port.lock, flags); |
| 548 | |
| 549 | up->msr_saved_flags = 0; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 550 | /* |
| 551 | * Finally, enable interrupts. Note: Modem status interrupts |
| 552 | * are set via set_termios(), which will be occurring imminently |
| 553 | * anyway, so we don't enable them here. |
| 554 | */ |
| 555 | up->ier = UART_IER_RLSI | UART_IER_RDI; |
| 556 | serial_out(up, UART_IER, up->ier); |
| 557 | |
Jarkko Nikula | 7884146 | 2011-01-24 17:51:22 +0200 | [diff] [blame] | 558 | /* Enable module level wake up */ |
| 559 | serial_out(up, UART_OMAP_WER, OMAP_UART_WER_MOD_WKUP); |
| 560 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 561 | pm_runtime_mark_last_busy(up->dev); |
| 562 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 563 | up->port_activity = jiffies; |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static void serial_omap_shutdown(struct uart_port *port) |
| 568 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 569 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 570 | unsigned long flags = 0; |
| 571 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 572 | dev_dbg(up->port.dev, "serial_omap_shutdown+%d\n", up->port.line); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 573 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 574 | pm_runtime_get_sync(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 575 | /* |
| 576 | * Disable interrupts from this port |
| 577 | */ |
| 578 | up->ier = 0; |
| 579 | serial_out(up, UART_IER, 0); |
| 580 | |
| 581 | spin_lock_irqsave(&up->port.lock, flags); |
| 582 | up->port.mctrl &= ~TIOCM_OUT2; |
| 583 | serial_omap_set_mctrl(&up->port, up->port.mctrl); |
| 584 | spin_unlock_irqrestore(&up->port.lock, flags); |
| 585 | |
| 586 | /* |
| 587 | * Disable break condition and FIFOs |
| 588 | */ |
| 589 | serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC); |
| 590 | serial_omap_clear_fifos(up); |
| 591 | |
| 592 | /* |
| 593 | * Read data port to reset things, and then free the irq |
| 594 | */ |
| 595 | if (serial_in(up, UART_LSR) & UART_LSR_DR) |
| 596 | (void) serial_in(up, UART_RX); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 597 | |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 598 | pm_runtime_mark_last_busy(up->dev); |
| 599 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 600 | free_irq(up->port.irq, up); |
| 601 | } |
| 602 | |
| 603 | static inline void |
| 604 | serial_omap_configure_xonxoff |
| 605 | (struct uart_omap_port *up, struct ktermios *termios) |
| 606 | { |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 607 | up->lcr = serial_in(up, UART_LCR); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 608 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 609 | up->efr = serial_in(up, UART_EFR); |
| 610 | serial_out(up, UART_EFR, up->efr & ~UART_EFR_ECB); |
| 611 | |
| 612 | serial_out(up, UART_XON1, termios->c_cc[VSTART]); |
| 613 | serial_out(up, UART_XOFF1, termios->c_cc[VSTOP]); |
| 614 | |
| 615 | /* clear SW control mode bits */ |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 616 | up->efr &= OMAP_UART_SW_CLR; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 617 | |
| 618 | /* |
| 619 | * IXON Flag: |
Vikram Pandita | 957ee72 | 2012-09-06 15:45:37 +0300 | [diff] [blame] | 620 | * Flow control for OMAP.TX |
| 621 | * OMAP.RX should listen for XON/XOFF |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 622 | */ |
| 623 | if (termios->c_iflag & IXON) |
Vikram Pandita | 957ee72 | 2012-09-06 15:45:37 +0300 | [diff] [blame] | 624 | up->efr |= OMAP_UART_SW_RX; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 625 | |
| 626 | /* |
| 627 | * IXOFF Flag: |
Vikram Pandita | 957ee72 | 2012-09-06 15:45:37 +0300 | [diff] [blame] | 628 | * Flow control for OMAP.RX |
| 629 | * OMAP.TX should send XON/XOFF |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 630 | */ |
| 631 | if (termios->c_iflag & IXOFF) |
Vikram Pandita | 957ee72 | 2012-09-06 15:45:37 +0300 | [diff] [blame] | 632 | up->efr |= OMAP_UART_SW_TX; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 633 | |
| 634 | serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 635 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 636 | |
| 637 | up->mcr = serial_in(up, UART_MCR); |
| 638 | |
| 639 | /* |
| 640 | * IXANY Flag: |
| 641 | * Enable any character to restart output. |
| 642 | * Operation resumes after receiving any |
| 643 | * character after recognition of the XOFF character |
| 644 | */ |
| 645 | if (termios->c_iflag & IXANY) |
| 646 | up->mcr |= UART_MCR_XONANY; |
| 647 | |
| 648 | serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 649 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 650 | serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG); |
| 651 | /* Enable special char function UARTi.EFR_REG[5] and |
| 652 | * load the new software flow control mode IXON or IXOFF |
| 653 | * and restore the UARTi.EFR_REG[4] ENHANCED_EN value. |
| 654 | */ |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 655 | serial_out(up, UART_EFR, up->efr | UART_EFR_SCD); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 656 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 657 | |
| 658 | serial_out(up, UART_MCR, up->mcr & ~UART_MCR_TCRTLR); |
| 659 | serial_out(up, UART_LCR, up->lcr); |
| 660 | } |
| 661 | |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 662 | static void serial_omap_uart_qos_work(struct work_struct *work) |
| 663 | { |
| 664 | struct uart_omap_port *up = container_of(work, struct uart_omap_port, |
| 665 | qos_work); |
| 666 | |
| 667 | pm_qos_update_request(&up->pm_qos_request, up->latency); |
NeilBrown | 9574f36 | 2012-07-30 10:30:26 +1000 | [diff] [blame] | 668 | if (gpio_is_valid(up->DTR_gpio)) |
| 669 | gpio_set_value_cansleep(up->DTR_gpio, |
| 670 | up->DTR_active != up->DTR_inverted); |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 671 | } |
| 672 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 673 | static void |
| 674 | serial_omap_set_termios(struct uart_port *port, struct ktermios *termios, |
| 675 | struct ktermios *old) |
| 676 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 677 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 678 | unsigned char cval = 0; |
| 679 | unsigned char efr = 0; |
| 680 | unsigned long flags = 0; |
| 681 | unsigned int baud, quot; |
| 682 | |
| 683 | switch (termios->c_cflag & CSIZE) { |
| 684 | case CS5: |
| 685 | cval = UART_LCR_WLEN5; |
| 686 | break; |
| 687 | case CS6: |
| 688 | cval = UART_LCR_WLEN6; |
| 689 | break; |
| 690 | case CS7: |
| 691 | cval = UART_LCR_WLEN7; |
| 692 | break; |
| 693 | default: |
| 694 | case CS8: |
| 695 | cval = UART_LCR_WLEN8; |
| 696 | break; |
| 697 | } |
| 698 | |
| 699 | if (termios->c_cflag & CSTOPB) |
| 700 | cval |= UART_LCR_STOP; |
| 701 | if (termios->c_cflag & PARENB) |
| 702 | cval |= UART_LCR_PARITY; |
| 703 | if (!(termios->c_cflag & PARODD)) |
| 704 | cval |= UART_LCR_EPAR; |
| 705 | |
| 706 | /* |
| 707 | * Ask the core to calculate the divisor for us. |
| 708 | */ |
| 709 | |
| 710 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/13); |
| 711 | quot = serial_omap_get_divisor(port, baud); |
| 712 | |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 713 | /* calculate wakeup latency constraint */ |
Paul Walmsley | 1972345 | 2012-01-25 19:50:56 -0700 | [diff] [blame] | 714 | up->calc_latency = (USEC_PER_SEC * up->port.fifosize) / (baud / 8); |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 715 | up->latency = up->calc_latency; |
| 716 | schedule_work(&up->qos_work); |
| 717 | |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 718 | up->dll = quot & 0xff; |
| 719 | up->dlh = quot >> 8; |
| 720 | up->mdr1 = UART_OMAP_MDR1_DISABLE; |
| 721 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 722 | up->fcr = UART_FCR_R_TRIG_01 | UART_FCR_T_TRIG_01 | |
| 723 | UART_FCR_ENABLE_FIFO; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 724 | |
| 725 | /* |
| 726 | * Ok, we're now changing the port state. Do it with |
| 727 | * interrupts disabled. |
| 728 | */ |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 729 | pm_runtime_get_sync(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 730 | spin_lock_irqsave(&up->port.lock, flags); |
| 731 | |
| 732 | /* |
| 733 | * Update the per-port timeout. |
| 734 | */ |
| 735 | uart_update_timeout(port, termios->c_cflag, baud); |
| 736 | |
| 737 | up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; |
| 738 | if (termios->c_iflag & INPCK) |
| 739 | up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; |
| 740 | if (termios->c_iflag & (BRKINT | PARMRK)) |
| 741 | up->port.read_status_mask |= UART_LSR_BI; |
| 742 | |
| 743 | /* |
| 744 | * Characters to ignore |
| 745 | */ |
| 746 | up->port.ignore_status_mask = 0; |
| 747 | if (termios->c_iflag & IGNPAR) |
| 748 | up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; |
| 749 | if (termios->c_iflag & IGNBRK) { |
| 750 | up->port.ignore_status_mask |= UART_LSR_BI; |
| 751 | /* |
| 752 | * If we're ignoring parity and break indicators, |
| 753 | * ignore overruns too (for real raw support). |
| 754 | */ |
| 755 | if (termios->c_iflag & IGNPAR) |
| 756 | up->port.ignore_status_mask |= UART_LSR_OE; |
| 757 | } |
| 758 | |
| 759 | /* |
| 760 | * ignore all characters if CREAD is not set |
| 761 | */ |
| 762 | if ((termios->c_cflag & CREAD) == 0) |
| 763 | up->port.ignore_status_mask |= UART_LSR_DR; |
| 764 | |
| 765 | /* |
| 766 | * Modem status interrupts |
| 767 | */ |
| 768 | up->ier &= ~UART_IER_MSI; |
| 769 | if (UART_ENABLE_MS(&up->port, termios->c_cflag)) |
| 770 | up->ier |= UART_IER_MSI; |
| 771 | serial_out(up, UART_IER, up->ier); |
| 772 | serial_out(up, UART_LCR, cval); /* reset DLAB */ |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 773 | up->lcr = cval; |
Govindraj.R | 3221289 | 2011-11-07 18:58:55 +0530 | [diff] [blame] | 774 | up->scr = OMAP_UART_SCR_TX_EMPTY; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 775 | |
| 776 | /* FIFOs and DMA Settings */ |
| 777 | |
| 778 | /* FCR can be changed only when the |
| 779 | * baud clock is not running |
| 780 | * DLL_REG and DLH_REG set to 0. |
| 781 | */ |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 782 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 783 | serial_out(up, UART_DLL, 0); |
| 784 | serial_out(up, UART_DLM, 0); |
| 785 | serial_out(up, UART_LCR, 0); |
| 786 | |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 787 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 788 | |
| 789 | up->efr = serial_in(up, UART_EFR); |
| 790 | serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); |
| 791 | |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 792 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 793 | up->mcr = serial_in(up, UART_MCR); |
| 794 | serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR); |
| 795 | /* FIFO ENABLE, DMA MODE */ |
Paul Walmsley | 0ba5f66 | 2012-01-25 19:50:36 -0700 | [diff] [blame] | 796 | |
| 797 | up->scr |= OMAP_UART_SCR_RX_TRIG_GRANU1_MASK; |
Paul Walmsley | 0a697b2 | 2012-01-21 00:27:40 -0700 | [diff] [blame] | 798 | |
Felipe Balbi | 4945743 | 2012-09-06 15:45:21 +0300 | [diff] [blame] | 799 | /* Set receive FIFO threshold to 1 byte */ |
| 800 | up->fcr &= ~OMAP_UART_FCR_RX_FIFO_TRIG_MASK; |
| 801 | up->fcr |= (0x1 << OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT); |
Greg Kroah-Hartman | 8a74e9f | 2012-01-26 11:15:18 -0800 | [diff] [blame] | 802 | |
Paul Walmsley | 0ba5f66 | 2012-01-25 19:50:36 -0700 | [diff] [blame] | 803 | serial_out(up, UART_FCR, up->fcr); |
| 804 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
| 805 | |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 806 | serial_out(up, UART_OMAP_SCR, up->scr); |
| 807 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 808 | serial_out(up, UART_EFR, up->efr); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 809 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 810 | serial_out(up, UART_MCR, up->mcr); |
| 811 | |
| 812 | /* Protocol, Baud Rate, and Interrupt Settings */ |
| 813 | |
Govindraj.R | 9473474 | 2011-11-07 19:00:33 +0530 | [diff] [blame] | 814 | if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) |
| 815 | serial_omap_mdr1_errataset(up, up->mdr1); |
| 816 | else |
| 817 | serial_out(up, UART_OMAP_MDR1, up->mdr1); |
| 818 | |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 819 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 820 | |
| 821 | up->efr = serial_in(up, UART_EFR); |
| 822 | serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); |
| 823 | |
| 824 | serial_out(up, UART_LCR, 0); |
| 825 | serial_out(up, UART_IER, 0); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 826 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 827 | |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 828 | serial_out(up, UART_DLL, up->dll); /* LS of divisor */ |
| 829 | serial_out(up, UART_DLM, up->dlh); /* MS of divisor */ |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 830 | |
| 831 | serial_out(up, UART_LCR, 0); |
| 832 | serial_out(up, UART_IER, up->ier); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 833 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 834 | |
| 835 | serial_out(up, UART_EFR, up->efr); |
| 836 | serial_out(up, UART_LCR, cval); |
| 837 | |
| 838 | if (baud > 230400 && baud != 3000000) |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 839 | up->mdr1 = UART_OMAP_MDR1_13X_MODE; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 840 | else |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 841 | up->mdr1 = UART_OMAP_MDR1_16X_MODE; |
| 842 | |
Govindraj.R | 9473474 | 2011-11-07 19:00:33 +0530 | [diff] [blame] | 843 | if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) |
| 844 | serial_omap_mdr1_errataset(up, up->mdr1); |
| 845 | else |
| 846 | serial_out(up, UART_OMAP_MDR1, up->mdr1); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 847 | |
| 848 | /* Hardware Flow Control Configuration */ |
| 849 | |
| 850 | if (termios->c_cflag & CRTSCTS) { |
| 851 | efr |= (UART_EFR_CTS | UART_EFR_RTS); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 852 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 853 | |
| 854 | up->mcr = serial_in(up, UART_MCR); |
| 855 | serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR); |
| 856 | |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 857 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 858 | up->efr = serial_in(up, UART_EFR); |
| 859 | serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); |
| 860 | |
| 861 | serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG); |
| 862 | serial_out(up, UART_EFR, efr); /* Enable AUTORTS and AUTOCTS */ |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 863 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 864 | serial_out(up, UART_MCR, up->mcr | UART_MCR_RTS); |
| 865 | serial_out(up, UART_LCR, cval); |
| 866 | } |
| 867 | |
| 868 | serial_omap_set_mctrl(&up->port, up->port.mctrl); |
| 869 | /* Software Flow Control Configuration */ |
Nick Pelly | b280a97 | 2011-07-15 13:53:08 -0700 | [diff] [blame] | 870 | serial_omap_configure_xonxoff(up, termios); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 871 | |
| 872 | spin_unlock_irqrestore(&up->port.lock, flags); |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 873 | pm_runtime_mark_last_busy(up->dev); |
| 874 | pm_runtime_put_autosuspend(up->dev); |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 875 | dev_dbg(up->port.dev, "serial_omap_set_termios+%d\n", up->port.line); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 876 | } |
| 877 | |
Felipe Balbi | 9727faf | 2012-09-06 15:45:35 +0300 | [diff] [blame] | 878 | static int serial_omap_set_wake(struct uart_port *port, unsigned int state) |
| 879 | { |
| 880 | struct uart_omap_port *up = to_uart_omap_port(port); |
| 881 | |
| 882 | serial_omap_enable_wakeup(up, state); |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 887 | static void |
| 888 | serial_omap_pm(struct uart_port *port, unsigned int state, |
| 889 | unsigned int oldstate) |
| 890 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 891 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 892 | unsigned char efr; |
| 893 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 894 | dev_dbg(up->port.dev, "serial_omap_pm+%d\n", up->port.line); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 895 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 896 | pm_runtime_get_sync(up->dev); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 897 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 898 | efr = serial_in(up, UART_EFR); |
| 899 | serial_out(up, UART_EFR, efr | UART_EFR_ECB); |
| 900 | serial_out(up, UART_LCR, 0); |
| 901 | |
| 902 | serial_out(up, UART_IER, (state != 0) ? UART_IERX_SLEEP : 0); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 903 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 904 | serial_out(up, UART_EFR, efr); |
| 905 | serial_out(up, UART_LCR, 0); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 906 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 907 | if (!device_may_wakeup(up->dev)) { |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 908 | if (!state) |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 909 | pm_runtime_forbid(up->dev); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 910 | else |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 911 | pm_runtime_allow(up->dev); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 912 | } |
| 913 | |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 914 | pm_runtime_mark_last_busy(up->dev); |
| 915 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | static void serial_omap_release_port(struct uart_port *port) |
| 919 | { |
| 920 | dev_dbg(port->dev, "serial_omap_release_port+\n"); |
| 921 | } |
| 922 | |
| 923 | static int serial_omap_request_port(struct uart_port *port) |
| 924 | { |
| 925 | dev_dbg(port->dev, "serial_omap_request_port+\n"); |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | static void serial_omap_config_port(struct uart_port *port, int flags) |
| 930 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 931 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 932 | |
| 933 | dev_dbg(up->port.dev, "serial_omap_config_port+%d\n", |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 934 | up->port.line); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 935 | up->port.type = PORT_OMAP; |
| 936 | } |
| 937 | |
| 938 | static int |
| 939 | serial_omap_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 940 | { |
| 941 | /* we don't want the core code to modify any port params */ |
| 942 | dev_dbg(port->dev, "serial_omap_verify_port+\n"); |
| 943 | return -EINVAL; |
| 944 | } |
| 945 | |
| 946 | static const char * |
| 947 | serial_omap_type(struct uart_port *port) |
| 948 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 949 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 950 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 951 | dev_dbg(up->port.dev, "serial_omap_type+%d\n", up->port.line); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 952 | return up->name; |
| 953 | } |
| 954 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 955 | #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) |
| 956 | |
| 957 | static inline void wait_for_xmitr(struct uart_omap_port *up) |
| 958 | { |
| 959 | unsigned int status, tmout = 10000; |
| 960 | |
| 961 | /* Wait up to 10ms for the character(s) to be sent. */ |
| 962 | do { |
| 963 | status = serial_in(up, UART_LSR); |
| 964 | |
| 965 | if (status & UART_LSR_BI) |
| 966 | up->lsr_break_flag = UART_LSR_BI; |
| 967 | |
| 968 | if (--tmout == 0) |
| 969 | break; |
| 970 | udelay(1); |
| 971 | } while ((status & BOTH_EMPTY) != BOTH_EMPTY); |
| 972 | |
| 973 | /* Wait up to 1s for flow control if necessary */ |
| 974 | if (up->port.flags & UPF_CONS_FLOW) { |
| 975 | tmout = 1000000; |
| 976 | for (tmout = 1000000; tmout; tmout--) { |
| 977 | unsigned int msr = serial_in(up, UART_MSR); |
| 978 | |
| 979 | up->msr_saved_flags |= msr & MSR_SAVE_FLAGS; |
| 980 | if (msr & UART_MSR_CTS) |
| 981 | break; |
| 982 | |
| 983 | udelay(1); |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | |
Cosmin Cojocar | 1b41dbc | 2010-12-05 16:15:10 +0100 | [diff] [blame] | 988 | #ifdef CONFIG_CONSOLE_POLL |
| 989 | |
| 990 | static void serial_omap_poll_put_char(struct uart_port *port, unsigned char ch) |
| 991 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 992 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 993 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 994 | pm_runtime_get_sync(up->dev); |
Cosmin Cojocar | 1b41dbc | 2010-12-05 16:15:10 +0100 | [diff] [blame] | 995 | wait_for_xmitr(up); |
| 996 | serial_out(up, UART_TX, ch); |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 997 | pm_runtime_mark_last_busy(up->dev); |
| 998 | pm_runtime_put_autosuspend(up->dev); |
Cosmin Cojocar | 1b41dbc | 2010-12-05 16:15:10 +0100 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static int serial_omap_poll_get_char(struct uart_port *port) |
| 1002 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 1003 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1004 | unsigned int status; |
Cosmin Cojocar | 1b41dbc | 2010-12-05 16:15:10 +0100 | [diff] [blame] | 1005 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 1006 | pm_runtime_get_sync(up->dev); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1007 | status = serial_in(up, UART_LSR); |
Felipe Balbi | a6b19c3 | 2012-09-06 15:45:36 +0300 | [diff] [blame] | 1008 | if (!(status & UART_LSR_DR)) { |
| 1009 | status = NO_POLL_CHAR; |
| 1010 | goto out; |
| 1011 | } |
Cosmin Cojocar | 1b41dbc | 2010-12-05 16:15:10 +0100 | [diff] [blame] | 1012 | |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1013 | status = serial_in(up, UART_RX); |
Felipe Balbi | a6b19c3 | 2012-09-06 15:45:36 +0300 | [diff] [blame] | 1014 | |
| 1015 | out: |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 1016 | pm_runtime_mark_last_busy(up->dev); |
| 1017 | pm_runtime_put_autosuspend(up->dev); |
Felipe Balbi | a6b19c3 | 2012-09-06 15:45:36 +0300 | [diff] [blame] | 1018 | |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1019 | return status; |
Cosmin Cojocar | 1b41dbc | 2010-12-05 16:15:10 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | #endif /* CONFIG_CONSOLE_POLL */ |
| 1023 | |
| 1024 | #ifdef CONFIG_SERIAL_OMAP_CONSOLE |
| 1025 | |
| 1026 | static struct uart_omap_port *serial_omap_console_ports[4]; |
| 1027 | |
| 1028 | static struct uart_driver serial_omap_reg; |
| 1029 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1030 | static void serial_omap_console_putchar(struct uart_port *port, int ch) |
| 1031 | { |
Felipe Balbi | c990f35 | 2012-08-23 13:32:41 +0300 | [diff] [blame] | 1032 | struct uart_omap_port *up = to_uart_omap_port(port); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1033 | |
| 1034 | wait_for_xmitr(up); |
| 1035 | serial_out(up, UART_TX, ch); |
| 1036 | } |
| 1037 | |
| 1038 | static void |
| 1039 | serial_omap_console_write(struct console *co, const char *s, |
| 1040 | unsigned int count) |
| 1041 | { |
| 1042 | struct uart_omap_port *up = serial_omap_console_ports[co->index]; |
| 1043 | unsigned long flags; |
| 1044 | unsigned int ier; |
| 1045 | int locked = 1; |
| 1046 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 1047 | pm_runtime_get_sync(up->dev); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1048 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1049 | local_irq_save(flags); |
| 1050 | if (up->port.sysrq) |
| 1051 | locked = 0; |
| 1052 | else if (oops_in_progress) |
| 1053 | locked = spin_trylock(&up->port.lock); |
| 1054 | else |
| 1055 | spin_lock(&up->port.lock); |
| 1056 | |
| 1057 | /* |
| 1058 | * First save the IER then disable the interrupts |
| 1059 | */ |
| 1060 | ier = serial_in(up, UART_IER); |
| 1061 | serial_out(up, UART_IER, 0); |
| 1062 | |
| 1063 | uart_console_write(&up->port, s, count, serial_omap_console_putchar); |
| 1064 | |
| 1065 | /* |
| 1066 | * Finally, wait for transmitter to become empty |
| 1067 | * and restore the IER |
| 1068 | */ |
| 1069 | wait_for_xmitr(up); |
| 1070 | serial_out(up, UART_IER, ier); |
| 1071 | /* |
| 1072 | * The receive handling will happen properly because the |
| 1073 | * receive ready bit will still be set; it is not cleared |
| 1074 | * on read. However, modem control will not, we must |
| 1075 | * call it if we have saved something in the saved flags |
| 1076 | * while processing with interrupts off. |
| 1077 | */ |
| 1078 | if (up->msr_saved_flags) |
| 1079 | check_modem_status(up); |
| 1080 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 1081 | pm_runtime_mark_last_busy(up->dev); |
| 1082 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1083 | if (locked) |
| 1084 | spin_unlock(&up->port.lock); |
| 1085 | local_irq_restore(flags); |
| 1086 | } |
| 1087 | |
| 1088 | static int __init |
| 1089 | serial_omap_console_setup(struct console *co, char *options) |
| 1090 | { |
| 1091 | struct uart_omap_port *up; |
| 1092 | int baud = 115200; |
| 1093 | int bits = 8; |
| 1094 | int parity = 'n'; |
| 1095 | int flow = 'n'; |
| 1096 | |
| 1097 | if (serial_omap_console_ports[co->index] == NULL) |
| 1098 | return -ENODEV; |
| 1099 | up = serial_omap_console_ports[co->index]; |
| 1100 | |
| 1101 | if (options) |
| 1102 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1103 | |
| 1104 | return uart_set_options(&up->port, co, baud, parity, bits, flow); |
| 1105 | } |
| 1106 | |
| 1107 | static struct console serial_omap_console = { |
| 1108 | .name = OMAP_SERIAL_NAME, |
| 1109 | .write = serial_omap_console_write, |
| 1110 | .device = uart_console_device, |
| 1111 | .setup = serial_omap_console_setup, |
| 1112 | .flags = CON_PRINTBUFFER, |
| 1113 | .index = -1, |
| 1114 | .data = &serial_omap_reg, |
| 1115 | }; |
| 1116 | |
| 1117 | static void serial_omap_add_console_port(struct uart_omap_port *up) |
| 1118 | { |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 1119 | serial_omap_console_ports[up->port.line] = up; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | #define OMAP_CONSOLE (&serial_omap_console) |
| 1123 | |
| 1124 | #else |
| 1125 | |
| 1126 | #define OMAP_CONSOLE NULL |
| 1127 | |
| 1128 | static inline void serial_omap_add_console_port(struct uart_omap_port *up) |
| 1129 | {} |
| 1130 | |
| 1131 | #endif |
| 1132 | |
| 1133 | static struct uart_ops serial_omap_pops = { |
| 1134 | .tx_empty = serial_omap_tx_empty, |
| 1135 | .set_mctrl = serial_omap_set_mctrl, |
| 1136 | .get_mctrl = serial_omap_get_mctrl, |
| 1137 | .stop_tx = serial_omap_stop_tx, |
| 1138 | .start_tx = serial_omap_start_tx, |
| 1139 | .stop_rx = serial_omap_stop_rx, |
| 1140 | .enable_ms = serial_omap_enable_ms, |
| 1141 | .break_ctl = serial_omap_break_ctl, |
| 1142 | .startup = serial_omap_startup, |
| 1143 | .shutdown = serial_omap_shutdown, |
| 1144 | .set_termios = serial_omap_set_termios, |
| 1145 | .pm = serial_omap_pm, |
Felipe Balbi | 9727faf | 2012-09-06 15:45:35 +0300 | [diff] [blame] | 1146 | .set_wake = serial_omap_set_wake, |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1147 | .type = serial_omap_type, |
| 1148 | .release_port = serial_omap_release_port, |
| 1149 | .request_port = serial_omap_request_port, |
| 1150 | .config_port = serial_omap_config_port, |
| 1151 | .verify_port = serial_omap_verify_port, |
Cosmin Cojocar | 1b41dbc | 2010-12-05 16:15:10 +0100 | [diff] [blame] | 1152 | #ifdef CONFIG_CONSOLE_POLL |
| 1153 | .poll_put_char = serial_omap_poll_put_char, |
| 1154 | .poll_get_char = serial_omap_poll_get_char, |
| 1155 | #endif |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1156 | }; |
| 1157 | |
| 1158 | static struct uart_driver serial_omap_reg = { |
| 1159 | .owner = THIS_MODULE, |
| 1160 | .driver_name = "OMAP-SERIAL", |
| 1161 | .dev_name = OMAP_SERIAL_NAME, |
| 1162 | .nr = OMAP_MAX_HSUART_PORTS, |
| 1163 | .cons = OMAP_CONSOLE, |
| 1164 | }; |
| 1165 | |
Shubhrajyoti D | 3bc4f0d | 2012-01-16 15:52:36 +0530 | [diff] [blame] | 1166 | #ifdef CONFIG_PM_SLEEP |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1167 | static int serial_omap_suspend(struct device *dev) |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1168 | { |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1169 | struct uart_omap_port *up = dev_get_drvdata(dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1170 | |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 1171 | if (up) { |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1172 | uart_suspend_port(&serial_omap_reg, &up->port); |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 1173 | flush_work_sync(&up->qos_work); |
| 1174 | } |
| 1175 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1176 | return 0; |
| 1177 | } |
| 1178 | |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1179 | static int serial_omap_resume(struct device *dev) |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1180 | { |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1181 | struct uart_omap_port *up = dev_get_drvdata(dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1182 | |
| 1183 | if (up) |
| 1184 | uart_resume_port(&serial_omap_reg, &up->port); |
| 1185 | return 0; |
| 1186 | } |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1187 | #endif |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1188 | |
Felipe Balbi | 6d608ef | 2012-09-06 15:45:32 +0300 | [diff] [blame] | 1189 | static void __devinit omap_serial_fill_features_erratas(struct uart_omap_port *up) |
Govindraj.R | 7c77c8d | 2012-04-03 19:12:34 +0530 | [diff] [blame] | 1190 | { |
| 1191 | u32 mvr, scheme; |
| 1192 | u16 revision, major, minor; |
| 1193 | |
| 1194 | mvr = serial_in(up, UART_OMAP_MVER); |
| 1195 | |
| 1196 | /* Check revision register scheme */ |
| 1197 | scheme = mvr >> OMAP_UART_MVR_SCHEME_SHIFT; |
| 1198 | |
| 1199 | switch (scheme) { |
| 1200 | case 0: /* Legacy Scheme: OMAP2/3 */ |
| 1201 | /* MINOR_REV[0:4], MAJOR_REV[4:7] */ |
| 1202 | major = (mvr & OMAP_UART_LEGACY_MVR_MAJ_MASK) >> |
| 1203 | OMAP_UART_LEGACY_MVR_MAJ_SHIFT; |
| 1204 | minor = (mvr & OMAP_UART_LEGACY_MVR_MIN_MASK); |
| 1205 | break; |
| 1206 | case 1: |
| 1207 | /* New Scheme: OMAP4+ */ |
| 1208 | /* MINOR_REV[0:5], MAJOR_REV[8:10] */ |
| 1209 | major = (mvr & OMAP_UART_MVR_MAJ_MASK) >> |
| 1210 | OMAP_UART_MVR_MAJ_SHIFT; |
| 1211 | minor = (mvr & OMAP_UART_MVR_MIN_MASK); |
| 1212 | break; |
| 1213 | default: |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 1214 | dev_warn(up->dev, |
Govindraj.R | 7c77c8d | 2012-04-03 19:12:34 +0530 | [diff] [blame] | 1215 | "Unknown %s revision, defaulting to highest\n", |
| 1216 | up->name); |
| 1217 | /* highest possible revision */ |
| 1218 | major = 0xff; |
| 1219 | minor = 0xff; |
| 1220 | } |
| 1221 | |
| 1222 | /* normalize revision for the driver */ |
| 1223 | revision = UART_BUILD_REVISION(major, minor); |
| 1224 | |
| 1225 | switch (revision) { |
| 1226 | case OMAP_UART_REV_46: |
| 1227 | up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | |
| 1228 | UART_ERRATA_i291_DMA_FORCEIDLE); |
| 1229 | break; |
| 1230 | case OMAP_UART_REV_52: |
| 1231 | up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | |
| 1232 | UART_ERRATA_i291_DMA_FORCEIDLE); |
| 1233 | break; |
| 1234 | case OMAP_UART_REV_63: |
| 1235 | up->errata |= UART_ERRATA_i202_MDR1_ACCESS; |
| 1236 | break; |
| 1237 | default: |
| 1238 | break; |
| 1239 | } |
| 1240 | } |
| 1241 | |
Felipe Balbi | 6d608ef | 2012-09-06 15:45:32 +0300 | [diff] [blame] | 1242 | static __devinit struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) |
Rajendra Nayak | d92b0df | 2011-12-14 17:25:45 +0530 | [diff] [blame] | 1243 | { |
| 1244 | struct omap_uart_port_info *omap_up_info; |
| 1245 | |
| 1246 | omap_up_info = devm_kzalloc(dev, sizeof(*omap_up_info), GFP_KERNEL); |
| 1247 | if (!omap_up_info) |
| 1248 | return NULL; /* out of memory */ |
| 1249 | |
| 1250 | of_property_read_u32(dev->of_node, "clock-frequency", |
| 1251 | &omap_up_info->uartclk); |
| 1252 | return omap_up_info; |
| 1253 | } |
| 1254 | |
Felipe Balbi | 6d608ef | 2012-09-06 15:45:32 +0300 | [diff] [blame] | 1255 | static int __devinit serial_omap_probe(struct platform_device *pdev) |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1256 | { |
| 1257 | struct uart_omap_port *up; |
Felipe Balbi | 4945743 | 2012-09-06 15:45:21 +0300 | [diff] [blame] | 1258 | struct resource *mem, *irq; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1259 | struct omap_uart_port_info *omap_up_info = pdev->dev.platform_data; |
NeilBrown | 9574f36 | 2012-07-30 10:30:26 +1000 | [diff] [blame] | 1260 | int ret; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1261 | |
Rajendra Nayak | d92b0df | 2011-12-14 17:25:45 +0530 | [diff] [blame] | 1262 | if (pdev->dev.of_node) |
| 1263 | omap_up_info = of_get_uart_port_info(&pdev->dev); |
| 1264 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1265 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1266 | if (!mem) { |
| 1267 | dev_err(&pdev->dev, "no mem resource?\n"); |
| 1268 | return -ENODEV; |
| 1269 | } |
| 1270 | |
| 1271 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1272 | if (!irq) { |
| 1273 | dev_err(&pdev->dev, "no irq resource?\n"); |
| 1274 | return -ENODEV; |
| 1275 | } |
| 1276 | |
Shubhrajyoti D | 388bc26 | 2012-03-21 17:22:22 +0530 | [diff] [blame] | 1277 | if (!devm_request_mem_region(&pdev->dev, mem->start, resource_size(mem), |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 1278 | pdev->dev.driver->name)) { |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1279 | dev_err(&pdev->dev, "memory region already claimed\n"); |
| 1280 | return -EBUSY; |
| 1281 | } |
| 1282 | |
NeilBrown | 9574f36 | 2012-07-30 10:30:26 +1000 | [diff] [blame] | 1283 | if (gpio_is_valid(omap_up_info->DTR_gpio) && |
| 1284 | omap_up_info->DTR_present) { |
| 1285 | ret = gpio_request(omap_up_info->DTR_gpio, "omap-serial"); |
| 1286 | if (ret < 0) |
| 1287 | return ret; |
| 1288 | ret = gpio_direction_output(omap_up_info->DTR_gpio, |
| 1289 | omap_up_info->DTR_inverted); |
| 1290 | if (ret < 0) |
| 1291 | return ret; |
| 1292 | } |
| 1293 | |
Shubhrajyoti D | 388bc26 | 2012-03-21 17:22:22 +0530 | [diff] [blame] | 1294 | up = devm_kzalloc(&pdev->dev, sizeof(*up), GFP_KERNEL); |
| 1295 | if (!up) |
| 1296 | return -ENOMEM; |
| 1297 | |
NeilBrown | 9574f36 | 2012-07-30 10:30:26 +1000 | [diff] [blame] | 1298 | if (gpio_is_valid(omap_up_info->DTR_gpio) && |
| 1299 | omap_up_info->DTR_present) { |
| 1300 | up->DTR_gpio = omap_up_info->DTR_gpio; |
| 1301 | up->DTR_inverted = omap_up_info->DTR_inverted; |
| 1302 | } else |
| 1303 | up->DTR_gpio = -EINVAL; |
| 1304 | up->DTR_active = 0; |
| 1305 | |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 1306 | up->dev = &pdev->dev; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1307 | up->port.dev = &pdev->dev; |
| 1308 | up->port.type = PORT_OMAP; |
| 1309 | up->port.iotype = UPIO_MEM; |
| 1310 | up->port.irq = irq->start; |
| 1311 | |
| 1312 | up->port.regshift = 2; |
| 1313 | up->port.fifosize = 64; |
| 1314 | up->port.ops = &serial_omap_pops; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1315 | |
Rajendra Nayak | d92b0df | 2011-12-14 17:25:45 +0530 | [diff] [blame] | 1316 | if (pdev->dev.of_node) |
| 1317 | up->port.line = of_alias_get_id(pdev->dev.of_node, "serial"); |
| 1318 | else |
| 1319 | up->port.line = pdev->id; |
| 1320 | |
| 1321 | if (up->port.line < 0) { |
| 1322 | dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", |
| 1323 | up->port.line); |
| 1324 | ret = -ENODEV; |
Shubhrajyoti D | 388bc26 | 2012-03-21 17:22:22 +0530 | [diff] [blame] | 1325 | goto err_port_line; |
Rajendra Nayak | d92b0df | 2011-12-14 17:25:45 +0530 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | sprintf(up->name, "OMAP UART%d", up->port.line); |
Govindraj.R | edd70ad | 2011-10-11 14:55:41 +0530 | [diff] [blame] | 1329 | up->port.mapbase = mem->start; |
Shubhrajyoti D | 388bc26 | 2012-03-21 17:22:22 +0530 | [diff] [blame] | 1330 | up->port.membase = devm_ioremap(&pdev->dev, mem->start, |
| 1331 | resource_size(mem)); |
Govindraj.R | edd70ad | 2011-10-11 14:55:41 +0530 | [diff] [blame] | 1332 | if (!up->port.membase) { |
| 1333 | dev_err(&pdev->dev, "can't ioremap UART\n"); |
| 1334 | ret = -ENOMEM; |
Shubhrajyoti D | 388bc26 | 2012-03-21 17:22:22 +0530 | [diff] [blame] | 1335 | goto err_ioremap; |
Govindraj.R | edd70ad | 2011-10-11 14:55:41 +0530 | [diff] [blame] | 1336 | } |
| 1337 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1338 | up->port.flags = omap_up_info->flags; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1339 | up->port.uartclk = omap_up_info->uartclk; |
Rajendra Nayak | 8fe789d | 2011-12-14 17:25:44 +0530 | [diff] [blame] | 1340 | if (!up->port.uartclk) { |
| 1341 | up->port.uartclk = DEFAULT_CLK_SPEED; |
| 1342 | dev_warn(&pdev->dev, "No clock speed specified: using default:" |
| 1343 | "%d\n", DEFAULT_CLK_SPEED); |
| 1344 | } |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1345 | |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 1346 | up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
| 1347 | up->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
| 1348 | pm_qos_add_request(&up->pm_qos_request, |
| 1349 | PM_QOS_CPU_DMA_LATENCY, up->latency); |
| 1350 | serial_omap_uart_wq = create_singlethread_workqueue(up->name); |
| 1351 | INIT_WORK(&up->qos_work, serial_omap_uart_qos_work); |
| 1352 | |
Felipe Balbi | 93220dc | 2012-09-06 15:45:27 +0300 | [diff] [blame] | 1353 | platform_set_drvdata(pdev, up); |
Ruchika Kharwar | 856e35b | 2012-09-06 15:45:31 +0300 | [diff] [blame] | 1354 | pm_runtime_enable(&pdev->dev); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1355 | pm_runtime_use_autosuspend(&pdev->dev); |
| 1356 | pm_runtime_set_autosuspend_delay(&pdev->dev, |
Deepak K | c86845db | 2011-11-09 17:33:38 +0530 | [diff] [blame] | 1357 | omap_up_info->autosuspend_timeout); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1358 | |
| 1359 | pm_runtime_irq_safe(&pdev->dev); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1360 | pm_runtime_get_sync(&pdev->dev); |
| 1361 | |
Govindraj.R | 7c77c8d | 2012-04-03 19:12:34 +0530 | [diff] [blame] | 1362 | omap_serial_fill_features_erratas(up); |
| 1363 | |
Rajendra Nayak | ba77433 | 2011-12-14 17:25:43 +0530 | [diff] [blame] | 1364 | ui[up->port.line] = up; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1365 | serial_omap_add_console_port(up); |
| 1366 | |
| 1367 | ret = uart_add_one_port(&serial_omap_reg, &up->port); |
| 1368 | if (ret != 0) |
Shubhrajyoti D | 388bc26 | 2012-03-21 17:22:22 +0530 | [diff] [blame] | 1369 | goto err_add_port; |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1370 | |
Felipe Balbi | 660ac5f | 2012-09-06 15:45:26 +0300 | [diff] [blame] | 1371 | pm_runtime_mark_last_busy(up->dev); |
| 1372 | pm_runtime_put_autosuspend(up->dev); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1373 | return 0; |
Shubhrajyoti D | 388bc26 | 2012-03-21 17:22:22 +0530 | [diff] [blame] | 1374 | |
| 1375 | err_add_port: |
| 1376 | pm_runtime_put(&pdev->dev); |
| 1377 | pm_runtime_disable(&pdev->dev); |
| 1378 | err_ioremap: |
| 1379 | err_port_line: |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1380 | dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n", |
| 1381 | pdev->id, __func__, ret); |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1382 | return ret; |
| 1383 | } |
| 1384 | |
Felipe Balbi | 6d608ef | 2012-09-06 15:45:32 +0300 | [diff] [blame] | 1385 | static int __devexit serial_omap_remove(struct platform_device *dev) |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1386 | { |
| 1387 | struct uart_omap_port *up = platform_get_drvdata(dev); |
| 1388 | |
Felipe Balbi | 7e9c8e7 | 2012-09-06 15:45:29 +0300 | [diff] [blame] | 1389 | pm_runtime_put_sync(up->dev); |
Felipe Balbi | 1b42c8b | 2012-09-06 15:45:28 +0300 | [diff] [blame] | 1390 | pm_runtime_disable(up->dev); |
| 1391 | uart_remove_one_port(&serial_omap_reg, &up->port); |
| 1392 | pm_qos_remove_request(&up->pm_qos_request); |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1393 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1394 | return 0; |
| 1395 | } |
| 1396 | |
Govindraj.R | 9473474 | 2011-11-07 19:00:33 +0530 | [diff] [blame] | 1397 | /* |
| 1398 | * Work Around for Errata i202 (2430, 3430, 3630, 4430 and 4460) |
| 1399 | * The access to uart register after MDR1 Access |
| 1400 | * causes UART to corrupt data. |
| 1401 | * |
| 1402 | * Need a delay = |
| 1403 | * 5 L4 clock cycles + 5 UART functional clock cycle (@48MHz = ~0.2uS) |
| 1404 | * give 10 times as much |
| 1405 | */ |
| 1406 | static void serial_omap_mdr1_errataset(struct uart_omap_port *up, u8 mdr1) |
| 1407 | { |
| 1408 | u8 timeout = 255; |
| 1409 | |
| 1410 | serial_out(up, UART_OMAP_MDR1, mdr1); |
| 1411 | udelay(2); |
| 1412 | serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_XMIT | |
| 1413 | UART_FCR_CLEAR_RCVR); |
| 1414 | /* |
| 1415 | * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and |
| 1416 | * TX_FIFO_E bit is 1. |
| 1417 | */ |
| 1418 | while (UART_LSR_THRE != (serial_in(up, UART_LSR) & |
| 1419 | (UART_LSR_THRE | UART_LSR_DR))) { |
| 1420 | timeout--; |
| 1421 | if (!timeout) { |
| 1422 | /* Should *never* happen. we warn and carry on */ |
Felipe Balbi | d8ee4ea | 2012-09-06 15:45:20 +0300 | [diff] [blame] | 1423 | dev_crit(up->dev, "Errata i202: timedout %x\n", |
Govindraj.R | 9473474 | 2011-11-07 19:00:33 +0530 | [diff] [blame] | 1424 | serial_in(up, UART_LSR)); |
| 1425 | break; |
| 1426 | } |
| 1427 | udelay(1); |
| 1428 | } |
| 1429 | } |
| 1430 | |
Shubhrajyoti D | b514885 | 2012-01-16 15:52:37 +0530 | [diff] [blame] | 1431 | #ifdef CONFIG_PM_RUNTIME |
Govindraj.R | 9f9ac1e | 2011-11-07 18:56:12 +0530 | [diff] [blame] | 1432 | static void serial_omap_restore_context(struct uart_omap_port *up) |
| 1433 | { |
Govindraj.R | 9473474 | 2011-11-07 19:00:33 +0530 | [diff] [blame] | 1434 | if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) |
| 1435 | serial_omap_mdr1_errataset(up, UART_OMAP_MDR1_DISABLE); |
| 1436 | else |
| 1437 | serial_out(up, UART_OMAP_MDR1, UART_OMAP_MDR1_DISABLE); |
| 1438 | |
Govindraj.R | 9f9ac1e | 2011-11-07 18:56:12 +0530 | [diff] [blame] | 1439 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */ |
| 1440 | serial_out(up, UART_EFR, UART_EFR_ECB); |
| 1441 | serial_out(up, UART_LCR, 0x0); /* Operational mode */ |
| 1442 | serial_out(up, UART_IER, 0x0); |
| 1443 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */ |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 1444 | serial_out(up, UART_DLL, up->dll); |
| 1445 | serial_out(up, UART_DLM, up->dlh); |
Govindraj.R | 9f9ac1e | 2011-11-07 18:56:12 +0530 | [diff] [blame] | 1446 | serial_out(up, UART_LCR, 0x0); /* Operational mode */ |
| 1447 | serial_out(up, UART_IER, up->ier); |
| 1448 | serial_out(up, UART_FCR, up->fcr); |
| 1449 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); |
| 1450 | serial_out(up, UART_MCR, up->mcr); |
| 1451 | serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */ |
Govindraj.R | c538d20 | 2011-11-07 18:57:03 +0530 | [diff] [blame] | 1452 | serial_out(up, UART_OMAP_SCR, up->scr); |
Govindraj.R | 9f9ac1e | 2011-11-07 18:56:12 +0530 | [diff] [blame] | 1453 | serial_out(up, UART_EFR, up->efr); |
| 1454 | serial_out(up, UART_LCR, up->lcr); |
Govindraj.R | 9473474 | 2011-11-07 19:00:33 +0530 | [diff] [blame] | 1455 | if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) |
| 1456 | serial_omap_mdr1_errataset(up, up->mdr1); |
| 1457 | else |
| 1458 | serial_out(up, UART_OMAP_MDR1, up->mdr1); |
Govindraj.R | 9f9ac1e | 2011-11-07 18:56:12 +0530 | [diff] [blame] | 1459 | } |
| 1460 | |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1461 | static int serial_omap_runtime_suspend(struct device *dev) |
| 1462 | { |
Govindraj.R | ec3bebc | 2011-10-11 19:11:27 +0530 | [diff] [blame] | 1463 | struct uart_omap_port *up = dev_get_drvdata(dev); |
| 1464 | struct omap_uart_port_info *pdata = dev->platform_data; |
| 1465 | |
| 1466 | if (!up) |
| 1467 | return -EINVAL; |
| 1468 | |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 1469 | if (!pdata) |
Govindraj.R | 62f3ec5f | 2011-10-13 14:11:09 +0530 | [diff] [blame] | 1470 | return 0; |
| 1471 | |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 1472 | up->context_loss_cnt = serial_omap_get_context_loss_count(up); |
Govindraj.R | ec3bebc | 2011-10-11 19:11:27 +0530 | [diff] [blame] | 1473 | |
Govindraj.R | 62f3ec5f | 2011-10-13 14:11:09 +0530 | [diff] [blame] | 1474 | if (device_may_wakeup(dev)) { |
| 1475 | if (!up->wakeups_enabled) { |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 1476 | serial_omap_enable_wakeup(up, true); |
Govindraj.R | 62f3ec5f | 2011-10-13 14:11:09 +0530 | [diff] [blame] | 1477 | up->wakeups_enabled = true; |
| 1478 | } |
| 1479 | } else { |
| 1480 | if (up->wakeups_enabled) { |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 1481 | serial_omap_enable_wakeup(up, false); |
Govindraj.R | 62f3ec5f | 2011-10-13 14:11:09 +0530 | [diff] [blame] | 1482 | up->wakeups_enabled = false; |
| 1483 | } |
| 1484 | } |
| 1485 | |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 1486 | up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; |
| 1487 | schedule_work(&up->qos_work); |
| 1488 | |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | static int serial_omap_runtime_resume(struct device *dev) |
| 1493 | { |
Govindraj.R | 9f9ac1e | 2011-11-07 18:56:12 +0530 | [diff] [blame] | 1494 | struct uart_omap_port *up = dev_get_drvdata(dev); |
Govindraj.R | ec3bebc | 2011-10-11 19:11:27 +0530 | [diff] [blame] | 1495 | struct omap_uart_port_info *pdata = dev->platform_data; |
Govindraj.R | 9f9ac1e | 2011-11-07 18:56:12 +0530 | [diff] [blame] | 1496 | |
Cousson, Benoit | a5f4313 | 2012-02-28 18:22:12 +0100 | [diff] [blame] | 1497 | if (up && pdata) { |
Felipe Balbi | e5b57c0 | 2012-08-23 13:32:42 +0300 | [diff] [blame] | 1498 | u32 loss_cnt = serial_omap_get_context_loss_count(up); |
Govindraj.R | ec3bebc | 2011-10-11 19:11:27 +0530 | [diff] [blame] | 1499 | |
| 1500 | if (up->context_loss_cnt != loss_cnt) |
| 1501 | serial_omap_restore_context(up); |
Govindraj.R | 9473474 | 2011-11-07 19:00:33 +0530 | [diff] [blame] | 1502 | |
Govindraj.R | 2fd1496 | 2011-11-09 17:41:21 +0530 | [diff] [blame] | 1503 | up->latency = up->calc_latency; |
| 1504 | schedule_work(&up->qos_work); |
Govindraj.R | ec3bebc | 2011-10-11 19:11:27 +0530 | [diff] [blame] | 1505 | } |
Govindraj.R | 9f9ac1e | 2011-11-07 18:56:12 +0530 | [diff] [blame] | 1506 | |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1507 | return 0; |
| 1508 | } |
| 1509 | #endif |
| 1510 | |
| 1511 | static const struct dev_pm_ops serial_omap_dev_pm_ops = { |
| 1512 | SET_SYSTEM_SLEEP_PM_OPS(serial_omap_suspend, serial_omap_resume) |
| 1513 | SET_RUNTIME_PM_OPS(serial_omap_runtime_suspend, |
| 1514 | serial_omap_runtime_resume, NULL) |
| 1515 | }; |
| 1516 | |
Rajendra Nayak | d92b0df | 2011-12-14 17:25:45 +0530 | [diff] [blame] | 1517 | #if defined(CONFIG_OF) |
| 1518 | static const struct of_device_id omap_serial_of_match[] = { |
| 1519 | { .compatible = "ti,omap2-uart" }, |
| 1520 | { .compatible = "ti,omap3-uart" }, |
| 1521 | { .compatible = "ti,omap4-uart" }, |
| 1522 | {}, |
| 1523 | }; |
| 1524 | MODULE_DEVICE_TABLE(of, omap_serial_of_match); |
| 1525 | #endif |
| 1526 | |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1527 | static struct platform_driver serial_omap_driver = { |
| 1528 | .probe = serial_omap_probe, |
Felipe Balbi | 6d608ef | 2012-09-06 15:45:32 +0300 | [diff] [blame] | 1529 | .remove = __devexit_p(serial_omap_remove), |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1530 | .driver = { |
| 1531 | .name = DRIVER_NAME, |
Govindraj.R | fcdca75 | 2011-02-28 18:12:23 +0530 | [diff] [blame] | 1532 | .pm = &serial_omap_dev_pm_ops, |
Rajendra Nayak | d92b0df | 2011-12-14 17:25:45 +0530 | [diff] [blame] | 1533 | .of_match_table = of_match_ptr(omap_serial_of_match), |
Govindraj.R | b612633 | 2010-09-27 20:20:49 +0530 | [diff] [blame] | 1534 | }, |
| 1535 | }; |
| 1536 | |
| 1537 | static int __init serial_omap_init(void) |
| 1538 | { |
| 1539 | int ret; |
| 1540 | |
| 1541 | ret = uart_register_driver(&serial_omap_reg); |
| 1542 | if (ret != 0) |
| 1543 | return ret; |
| 1544 | ret = platform_driver_register(&serial_omap_driver); |
| 1545 | if (ret != 0) |
| 1546 | uart_unregister_driver(&serial_omap_reg); |
| 1547 | return ret; |
| 1548 | } |
| 1549 | |
| 1550 | static void __exit serial_omap_exit(void) |
| 1551 | { |
| 1552 | platform_driver_unregister(&serial_omap_driver); |
| 1553 | uart_unregister_driver(&serial_omap_reg); |
| 1554 | } |
| 1555 | |
| 1556 | module_init(serial_omap_init); |
| 1557 | module_exit(serial_omap_exit); |
| 1558 | |
| 1559 | MODULE_DESCRIPTION("OMAP High Speed UART driver"); |
| 1560 | MODULE_LICENSE("GPL"); |
| 1561 | MODULE_AUTHOR("Texas Instruments Inc"); |