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