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