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