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