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