Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/drivers/char/serial_core.h |
| 4 | * |
| 5 | * Copyright (C) 2000 Deep Blue Solutions Ltd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #ifndef LINUX_SERIAL_CORE_H |
| 8 | #define LINUX_SERIAL_CORE_H |
| 9 | |
Andy Shevchenko | c7ac15ce | 2017-07-25 20:39:58 +0300 | [diff] [blame] | 10 | #include <linux/bitops.h> |
Russell King | 661f83a | 2005-07-16 09:30:53 +0100 | [diff] [blame] | 11 | #include <linux/compiler.h> |
Douglas Anderson | 3e6f880 | 2018-10-30 15:11:06 -0700 | [diff] [blame] | 12 | #include <linux/console.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/circ_buf.h> |
| 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/tty.h> |
Ingo Molnar | e2862f6 | 2006-01-13 21:37:07 +0000 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Maciej W. Rozycki | b11115c | 2007-06-01 00:47:07 -0700 | [diff] [blame] | 19 | #include <linux/sysrq.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 20 | #include <uapi/linux/serial_core.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Sourav Poddar | cf0ebee0 | 2013-05-15 21:05:37 +0530 | [diff] [blame] | 22 | #ifdef CONFIG_SERIAL_CORE_CONSOLE |
| 23 | #define uart_console(port) \ |
| 24 | ((port)->cons && (port)->cons->index == (port)->line) |
| 25 | #else |
Peter Hurley | 6b3cddc | 2015-04-11 11:02:36 -0400 | [diff] [blame] | 26 | #define uart_console(port) ({ (void)port; 0; }) |
Sourav Poddar | cf0ebee0 | 2013-05-15 21:05:37 +0530 | [diff] [blame] | 27 | #endif |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | struct uart_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | struct serial_struct; |
| 31 | struct device; |
Johan Hovold | 167cbce | 2020-06-10 17:51:21 +0200 | [diff] [blame] | 32 | struct gpio_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Jiri Slaby | e60a723 | 2022-07-28 08:10:51 +0200 | [diff] [blame] | 34 | /** |
| 35 | * struct uart_ops -- interface between serial_core and the driver |
| 36 | * |
Kevin Cernekee | e759d7c | 2012-12-26 20:43:42 -0800 | [diff] [blame] | 37 | * This structure describes all the operations that can be done on the |
Jiri Slaby | e60a723 | 2022-07-28 08:10:51 +0200 | [diff] [blame] | 38 | * physical hardware. |
| 39 | * |
| 40 | * @tx_empty: ``unsigned int ()(struct uart_port *port)`` |
| 41 | * |
| 42 | * This function tests whether the transmitter fifo and shifter for the |
| 43 | * @port is empty. If it is empty, this function should return |
| 44 | * %TIOCSER_TEMT, otherwise return 0. If the port does not support this |
| 45 | * operation, then it should return %TIOCSER_TEMT. |
| 46 | * |
| 47 | * Locking: none. |
| 48 | * Interrupts: caller dependent. |
| 49 | * This call must not sleep |
| 50 | * |
| 51 | * @set_mctrl: ``void ()(struct uart_port *port, unsigned int mctrl)`` |
| 52 | * |
| 53 | * This function sets the modem control lines for @port to the state |
| 54 | * described by @mctrl. The relevant bits of @mctrl are: |
| 55 | * |
| 56 | * - %TIOCM_RTS RTS signal. |
| 57 | * - %TIOCM_DTR DTR signal. |
| 58 | * - %TIOCM_OUT1 OUT1 signal. |
| 59 | * - %TIOCM_OUT2 OUT2 signal. |
| 60 | * - %TIOCM_LOOP Set the port into loopback mode. |
| 61 | * |
| 62 | * If the appropriate bit is set, the signal should be driven |
| 63 | * active. If the bit is clear, the signal should be driven |
| 64 | * inactive. |
| 65 | * |
| 66 | * Locking: @port->lock taken. |
| 67 | * Interrupts: locally disabled. |
| 68 | * This call must not sleep |
| 69 | * |
| 70 | * @get_mctrl: ``unsigned int ()(struct uart_port *port)`` |
| 71 | * |
| 72 | * Returns the current state of modem control inputs of @port. The state |
| 73 | * of the outputs should not be returned, since the core keeps track of |
| 74 | * their state. The state information should include: |
| 75 | * |
| 76 | * - %TIOCM_CAR state of DCD signal |
| 77 | * - %TIOCM_CTS state of CTS signal |
| 78 | * - %TIOCM_DSR state of DSR signal |
| 79 | * - %TIOCM_RI state of RI signal |
| 80 | * |
| 81 | * The bit is set if the signal is currently driven active. If |
| 82 | * the port does not support CTS, DCD or DSR, the driver should |
| 83 | * indicate that the signal is permanently active. If RI is |
| 84 | * not available, the signal should not be indicated as active. |
| 85 | * |
| 86 | * Locking: @port->lock taken. |
| 87 | * Interrupts: locally disabled. |
| 88 | * This call must not sleep |
| 89 | * |
| 90 | * @stop_tx: ``void ()(struct uart_port *port)`` |
| 91 | * |
| 92 | * Stop transmitting characters. This might be due to the CTS line |
| 93 | * becoming inactive or the tty layer indicating we want to stop |
| 94 | * transmission due to an %XOFF character. |
| 95 | * |
| 96 | * The driver should stop transmitting characters as soon as possible. |
| 97 | * |
| 98 | * Locking: @port->lock taken. |
| 99 | * Interrupts: locally disabled. |
| 100 | * This call must not sleep |
| 101 | * |
| 102 | * @start_tx: ``void ()(struct uart_port *port)`` |
| 103 | * |
| 104 | * Start transmitting characters. |
| 105 | * |
| 106 | * Locking: @port->lock taken. |
| 107 | * Interrupts: locally disabled. |
| 108 | * This call must not sleep |
| 109 | * |
| 110 | * @throttle: ``void ()(struct uart_port *port)`` |
| 111 | * |
| 112 | * Notify the serial driver that input buffers for the line discipline are |
| 113 | * close to full, and it should somehow signal that no more characters |
| 114 | * should be sent to the serial port. |
| 115 | * This will be called only if hardware assisted flow control is enabled. |
| 116 | * |
| 117 | * Locking: serialized with @unthrottle() and termios modification by the |
| 118 | * tty layer. |
| 119 | * |
| 120 | * @unthrottle: ``void ()(struct uart_port *port)`` |
| 121 | * |
| 122 | * Notify the serial driver that characters can now be sent to the serial |
| 123 | * port without fear of overrunning the input buffers of the line |
| 124 | * disciplines. |
| 125 | * |
| 126 | * This will be called only if hardware assisted flow control is enabled. |
| 127 | * |
| 128 | * Locking: serialized with @throttle() and termios modification by the |
| 129 | * tty layer. |
| 130 | * |
| 131 | * @send_xchar: ``void ()(struct uart_port *port, char ch)`` |
| 132 | * |
| 133 | * Transmit a high priority character, even if the port is stopped. This |
| 134 | * is used to implement XON/XOFF flow control and tcflow(). If the serial |
| 135 | * driver does not implement this function, the tty core will append the |
| 136 | * character to the circular buffer and then call start_tx() / stop_tx() |
| 137 | * to flush the data out. |
| 138 | * |
| 139 | * Do not transmit if @ch == '\0' (%__DISABLED_CHAR). |
| 140 | * |
| 141 | * Locking: none. |
| 142 | * Interrupts: caller dependent. |
| 143 | * |
Mauro Carvalho Chehab | b5a5b9d | 2022-08-18 15:38:58 +0200 | [diff] [blame] | 144 | * @start_rx: ``void ()(struct uart_port *port)`` |
| 145 | * |
| 146 | * Start receiving characters. |
| 147 | * |
| 148 | * Locking: @port->lock taken. |
| 149 | * Interrupts: locally disabled. |
| 150 | * This call must not sleep |
| 151 | * |
Jiri Slaby | e60a723 | 2022-07-28 08:10:51 +0200 | [diff] [blame] | 152 | * @stop_rx: ``void ()(struct uart_port *port)`` |
| 153 | * |
| 154 | * Stop receiving characters; the @port is in the process of being closed. |
| 155 | * |
| 156 | * Locking: @port->lock taken. |
| 157 | * Interrupts: locally disabled. |
| 158 | * This call must not sleep |
| 159 | * |
| 160 | * @enable_ms: ``void ()(struct uart_port *port)`` |
| 161 | * |
| 162 | * Enable the modem status interrupts. |
| 163 | * |
| 164 | * This method may be called multiple times. Modem status interrupts |
| 165 | * should be disabled when the @shutdown() method is called. |
| 166 | * |
| 167 | * Locking: @port->lock taken. |
| 168 | * Interrupts: locally disabled. |
| 169 | * This call must not sleep |
| 170 | * |
| 171 | * @break_ctl: ``void ()(struct uart_port *port, int ctl)`` |
| 172 | * |
| 173 | * Control the transmission of a break signal. If @ctl is nonzero, the |
| 174 | * break signal should be transmitted. The signal should be terminated |
| 175 | * when another call is made with a zero @ctl. |
| 176 | * |
| 177 | * Locking: caller holds tty_port->mutex |
| 178 | * |
| 179 | * @startup: ``int ()(struct uart_port *port)`` |
| 180 | * |
| 181 | * Grab any interrupt resources and initialise any low level driver state. |
| 182 | * Enable the port for reception. It should not activate RTS nor DTR; |
| 183 | * this will be done via a separate call to @set_mctrl(). |
| 184 | * |
| 185 | * This method will only be called when the port is initially opened. |
| 186 | * |
| 187 | * Locking: port_sem taken. |
| 188 | * Interrupts: globally disabled. |
| 189 | * |
| 190 | * @shutdown: ``void ()(struct uart_port *port)`` |
| 191 | * |
| 192 | * Disable the @port, disable any break condition that may be in effect, |
| 193 | * and free any interrupt resources. It should not disable RTS nor DTR; |
| 194 | * this will have already been done via a separate call to @set_mctrl(). |
| 195 | * |
| 196 | * Drivers must not access @port->state once this call has completed. |
| 197 | * |
| 198 | * This method will only be called when there are no more users of this |
| 199 | * @port. |
| 200 | * |
| 201 | * Locking: port_sem taken. |
| 202 | * Interrupts: caller dependent. |
| 203 | * |
| 204 | * @flush_buffer: ``void ()(struct uart_port *port)`` |
| 205 | * |
| 206 | * Flush any write buffers, reset any DMA state and stop any ongoing DMA |
| 207 | * transfers. |
| 208 | * |
| 209 | * This will be called whenever the @port->state->xmit circular buffer is |
| 210 | * cleared. |
| 211 | * |
| 212 | * Locking: @port->lock taken. |
| 213 | * Interrupts: locally disabled. |
| 214 | * This call must not sleep |
| 215 | * |
| 216 | * @set_termios: ``void ()(struct uart_port *port, struct ktermios *new, |
| 217 | * struct ktermios *old)`` |
| 218 | * |
| 219 | * Change the @port parameters, including word length, parity, stop bits. |
| 220 | * Update @port->read_status_mask and @port->ignore_status_mask to |
| 221 | * indicate the types of events we are interested in receiving. Relevant |
| 222 | * ktermios::c_cflag bits are: |
| 223 | * |
| 224 | * - %CSIZE - word size |
| 225 | * - %CSTOPB - 2 stop bits |
| 226 | * - %PARENB - parity enable |
| 227 | * - %PARODD - odd parity (when %PARENB is in force) |
| 228 | * - %ADDRB - address bit (changed through uart_port::rs485_config()). |
| 229 | * - %CREAD - enable reception of characters (if not set, still receive |
| 230 | * characters from the port, but throw them away). |
| 231 | * - %CRTSCTS - if set, enable CTS status change reporting. |
| 232 | * - %CLOCAL - if not set, enable modem status change reporting. |
| 233 | * |
| 234 | * Relevant ktermios::c_iflag bits are: |
| 235 | * |
| 236 | * - %INPCK - enable frame and parity error events to be passed to the TTY |
| 237 | * layer. |
| 238 | * - %BRKINT / %PARMRK - both of these enable break events to be passed to |
| 239 | * the TTY layer. |
| 240 | * - %IGNPAR - ignore parity and framing errors. |
| 241 | * - %IGNBRK - ignore break errors. If %IGNPAR is also set, ignore overrun |
| 242 | * errors as well. |
| 243 | * |
| 244 | * The interaction of the ktermios::c_iflag bits is as follows (parity |
| 245 | * error given as an example): |
| 246 | * |
| 247 | * ============ ======= ======= ========================================= |
| 248 | * Parity error INPCK IGNPAR |
| 249 | * ============ ======= ======= ========================================= |
| 250 | * n/a 0 n/a character received, marked as %TTY_NORMAL |
| 251 | * None 1 n/a character received, marked as %TTY_NORMAL |
| 252 | * Yes 1 0 character received, marked as %TTY_PARITY |
| 253 | * Yes 1 1 character discarded |
| 254 | * ============ ======= ======= ========================================= |
| 255 | * |
| 256 | * Other flags may be used (eg, xon/xoff characters) if your hardware |
| 257 | * supports hardware "soft" flow control. |
| 258 | * |
| 259 | * Locking: caller holds tty_port->mutex |
| 260 | * Interrupts: caller dependent. |
| 261 | * This call must not sleep |
| 262 | * |
| 263 | * @set_ldisc: ``void ()(struct uart_port *port, struct ktermios *termios)`` |
| 264 | * |
| 265 | * Notifier for discipline change. See |
| 266 | * Documentation/driver-api/tty/tty_ldisc.rst. |
| 267 | * |
| 268 | * Locking: caller holds tty_port->mutex |
| 269 | * |
| 270 | * @pm: ``void ()(struct uart_port *port, unsigned int state, |
| 271 | * unsigned int oldstate)`` |
| 272 | * |
| 273 | * Perform any power management related activities on the specified @port. |
| 274 | * @state indicates the new state (defined by enum uart_pm_state), |
| 275 | * @oldstate indicates the previous state. |
| 276 | * |
| 277 | * This function should not be used to grab any resources. |
| 278 | * |
| 279 | * This will be called when the @port is initially opened and finally |
| 280 | * closed, except when the @port is also the system console. This will |
| 281 | * occur even if %CONFIG_PM is not set. |
| 282 | * |
| 283 | * Locking: none. |
| 284 | * Interrupts: caller dependent. |
| 285 | * |
| 286 | * @type: ``const char *()(struct uart_port *port)`` |
| 287 | * |
| 288 | * Return a pointer to a string constant describing the specified @port, |
| 289 | * or return %NULL, in which case the string 'unknown' is substituted. |
| 290 | * |
| 291 | * Locking: none. |
| 292 | * Interrupts: caller dependent. |
| 293 | * |
| 294 | * @release_port: ``void ()(struct uart_port *port)`` |
| 295 | * |
| 296 | * Release any memory and IO region resources currently in use by the |
| 297 | * @port. |
| 298 | * |
| 299 | * Locking: none. |
| 300 | * Interrupts: caller dependent. |
| 301 | * |
| 302 | * @request_port: ``int ()(struct uart_port *port)`` |
| 303 | * |
| 304 | * Request any memory and IO region resources required by the port. If any |
| 305 | * fail, no resources should be registered when this function returns, and |
| 306 | * it should return -%EBUSY on failure. |
| 307 | * |
| 308 | * Locking: none. |
| 309 | * Interrupts: caller dependent. |
| 310 | * |
| 311 | * @config_port: ``void ()(struct uart_port *port, int type)`` |
| 312 | * |
| 313 | * Perform any autoconfiguration steps required for the @port. @type |
| 314 | * contains a bit mask of the required configuration. %UART_CONFIG_TYPE |
| 315 | * indicates that the port requires detection and identification. |
| 316 | * @port->type should be set to the type found, or %PORT_UNKNOWN if no |
| 317 | * port was detected. |
| 318 | * |
| 319 | * %UART_CONFIG_IRQ indicates autoconfiguration of the interrupt signal, |
| 320 | * which should be probed using standard kernel autoprobing techniques. |
| 321 | * This is not necessary on platforms where ports have interrupts |
| 322 | * internally hard wired (eg, system on a chip implementations). |
| 323 | * |
| 324 | * Locking: none. |
| 325 | * Interrupts: caller dependent. |
| 326 | * |
| 327 | * @verify_port: ``int ()(struct uart_port *port, |
| 328 | * struct serial_struct *serinfo)`` |
| 329 | * |
| 330 | * Verify the new serial port information contained within @serinfo is |
| 331 | * suitable for this port type. |
| 332 | * |
| 333 | * Locking: none. |
| 334 | * Interrupts: caller dependent. |
| 335 | * |
| 336 | * @ioctl: ``int ()(struct uart_port *port, unsigned int cmd, |
| 337 | * unsigned long arg)`` |
| 338 | * |
| 339 | * Perform any port specific IOCTLs. IOCTL commands must be defined using |
| 340 | * the standard numbering system found in <asm/ioctl.h>. |
| 341 | * |
| 342 | * Locking: none. |
| 343 | * Interrupts: caller dependent. |
| 344 | * |
| 345 | * @poll_init: ``int ()(struct uart_port *port)`` |
| 346 | * |
| 347 | * Called by kgdb to perform the minimal hardware initialization needed to |
| 348 | * support @poll_put_char() and @poll_get_char(). Unlike @startup(), this |
| 349 | * should not request interrupts. |
| 350 | * |
| 351 | * Locking: %tty_mutex and tty_port->mutex taken. |
| 352 | * Interrupts: n/a. |
| 353 | * |
| 354 | * @poll_put_char: ``void ()(struct uart_port *port, unsigned char ch)`` |
| 355 | * |
| 356 | * Called by kgdb to write a single character @ch directly to the serial |
| 357 | * @port. It can and should block until there is space in the TX FIFO. |
| 358 | * |
| 359 | * Locking: none. |
| 360 | * Interrupts: caller dependent. |
| 361 | * This call must not sleep |
| 362 | * |
| 363 | * @poll_get_char: ``int ()(struct uart_port *port)`` |
| 364 | * |
| 365 | * Called by kgdb to read a single character directly from the serial |
| 366 | * port. If data is available, it should be returned; otherwise the |
| 367 | * function should return %NO_POLL_CHAR immediately. |
| 368 | * |
| 369 | * Locking: none. |
| 370 | * Interrupts: caller dependent. |
| 371 | * This call must not sleep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | */ |
| 373 | struct uart_ops { |
| 374 | unsigned int (*tx_empty)(struct uart_port *); |
| 375 | void (*set_mctrl)(struct uart_port *, unsigned int mctrl); |
| 376 | unsigned int (*get_mctrl)(struct uart_port *); |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 377 | void (*stop_tx)(struct uart_port *); |
| 378 | void (*start_tx)(struct uart_port *); |
Russell King | 9aba8d5b | 2012-04-17 17:23:14 +0100 | [diff] [blame] | 379 | void (*throttle)(struct uart_port *); |
| 380 | void (*unthrottle)(struct uart_port *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | void (*send_xchar)(struct uart_port *, char ch); |
| 382 | void (*stop_rx)(struct uart_port *); |
Vijaya Krishna Nivarthi | cfab87c | 2022-06-08 00:22:44 +0530 | [diff] [blame] | 383 | void (*start_rx)(struct uart_port *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | void (*enable_ms)(struct uart_port *); |
| 385 | void (*break_ctl)(struct uart_port *, int ctl); |
| 386 | int (*startup)(struct uart_port *); |
| 387 | void (*shutdown)(struct uart_port *); |
Haavard Skinnemoen | 6bb0e3a | 2008-07-16 21:52:36 +0100 | [diff] [blame] | 388 | void (*flush_buffer)(struct uart_port *); |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 389 | void (*set_termios)(struct uart_port *, struct ktermios *new, |
Ilpo Järvinen | bec5b81 | 2022-08-16 14:57:37 +0300 | [diff] [blame] | 390 | const struct ktermios *old); |
Peter Hurley | 732a84a | 2014-11-05 13:11:43 -0500 | [diff] [blame] | 391 | void (*set_ldisc)(struct uart_port *, struct ktermios *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | void (*pm)(struct uart_port *, unsigned int state, |
| 393 | unsigned int oldstate); |
Kevin Cernekee | e759d7c | 2012-12-26 20:43:42 -0800 | [diff] [blame] | 394 | const char *(*type)(struct uart_port *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | void (*release_port)(struct uart_port *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | int (*request_port)(struct uart_port *); |
| 397 | void (*config_port)(struct uart_port *, int); |
| 398 | int (*verify_port)(struct uart_port *, struct serial_struct *); |
| 399 | int (*ioctl)(struct uart_port *, unsigned int, unsigned long); |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 400 | #ifdef CONFIG_CONSOLE_POLL |
Anton Vorontsov | c7f3e70 | 2012-09-24 14:27:53 -0700 | [diff] [blame] | 401 | int (*poll_init)(struct uart_port *); |
Kevin Cernekee | e759d7c | 2012-12-26 20:43:42 -0800 | [diff] [blame] | 402 | void (*poll_put_char)(struct uart_port *, unsigned char); |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 403 | int (*poll_get_char)(struct uart_port *); |
| 404 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | }; |
| 406 | |
Jason Wessel | f5316b4 | 2010-05-20 21:04:22 -0500 | [diff] [blame] | 407 | #define NO_POLL_CHAR 0x00ff0000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | #define UART_CONFIG_TYPE (1 << 0) |
| 409 | #define UART_CONFIG_IRQ (1 << 1) |
| 410 | |
| 411 | struct uart_icount { |
| 412 | __u32 cts; |
| 413 | __u32 dsr; |
| 414 | __u32 rng; |
| 415 | __u32 dcd; |
| 416 | __u32 rx; |
| 417 | __u32 tx; |
| 418 | __u32 frame; |
| 419 | __u32 overrun; |
| 420 | __u32 parity; |
| 421 | __u32 brk; |
| 422 | __u32 buf_overrun; |
| 423 | }; |
| 424 | |
Maciej W. Rozycki | 9906890 | 2022-09-21 00:35:32 +0100 | [diff] [blame] | 425 | typedef u64 __bitwise upf_t; |
Michael S. Tsirkin | 9efecca | 2016-12-11 06:34:53 +0200 | [diff] [blame] | 426 | typedef unsigned int __bitwise upstat_t; |
Russell King | 0077d45 | 2006-01-21 23:03:28 +0000 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | struct uart_port { |
| 429 | spinlock_t lock; /* port lock */ |
David Miller | 0c8946d | 2008-10-13 10:35:23 +0100 | [diff] [blame] | 430 | unsigned long iobase; /* in/out[bwl] */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | unsigned char __iomem *membase; /* read/write[bwl] */ |
David Daney | 7d6a07d | 2009-01-02 13:49:47 +0000 | [diff] [blame] | 432 | unsigned int (*serial_in)(struct uart_port *, int); |
| 433 | void (*serial_out)(struct uart_port *, int, int); |
Philippe Langlais | 235dae5 | 2010-07-29 17:13:57 +0200 | [diff] [blame] | 434 | void (*set_termios)(struct uart_port *, |
| 435 | struct ktermios *new, |
Ilpo Järvinen | bec5b81 | 2022-08-16 14:57:37 +0300 | [diff] [blame] | 436 | const struct ktermios *old); |
Ed Blake | db405a8 | 2016-11-10 18:07:55 +0000 | [diff] [blame] | 437 | void (*set_ldisc)(struct uart_port *, |
| 438 | struct ktermios *); |
Wan Ahmad Zainie | 144ef5c2 | 2016-04-06 12:06:51 +0800 | [diff] [blame] | 439 | unsigned int (*get_mctrl)(struct uart_port *); |
Peter Hurley | 4bf4ea9 | 2014-12-30 20:28:15 -0500 | [diff] [blame] | 440 | void (*set_mctrl)(struct uart_port *, unsigned int); |
Jisheng Zhang | 0238d2b | 2018-07-12 09:57:00 +0800 | [diff] [blame] | 441 | unsigned int (*get_divisor)(struct uart_port *, |
| 442 | unsigned int baud, |
| 443 | unsigned int *frac); |
| 444 | void (*set_divisor)(struct uart_port *, |
| 445 | unsigned int baud, |
| 446 | unsigned int quot, |
| 447 | unsigned int quot_frac); |
Sebastian Andrzej Siewior | b99b121 | 2014-09-05 21:02:37 +0200 | [diff] [blame] | 448 | int (*startup)(struct uart_port *port); |
| 449 | void (*shutdown)(struct uart_port *port); |
Sebastian Andrzej Siewior | 234abab | 2014-09-10 21:29:56 +0200 | [diff] [blame] | 450 | void (*throttle)(struct uart_port *port); |
| 451 | void (*unthrottle)(struct uart_port *port); |
Jamie Iles | a74036f | 2011-08-15 10:17:51 +0100 | [diff] [blame] | 452 | int (*handle_irq)(struct uart_port *); |
Manuel Lauss | c161afe | 2010-09-25 15:13:45 +0200 | [diff] [blame] | 453 | void (*pm)(struct uart_port *, unsigned int state, |
| 454 | unsigned int old); |
Dan Williams | bf03f65 | 2012-04-10 14:10:53 -0700 | [diff] [blame] | 455 | void (*handle_break)(struct uart_port *); |
Ricardo Ribalda Delgado | a5f276f | 2014-11-06 22:46:13 +0100 | [diff] [blame] | 456 | int (*rs485_config)(struct uart_port *, |
Ilpo Järvinen | ae50bb2 | 2022-06-24 23:42:08 +0300 | [diff] [blame] | 457 | struct ktermios *termios, |
Ricardo Ribalda Delgado | a5f276f | 2014-11-06 22:46:13 +0100 | [diff] [blame] | 458 | struct serial_rs485 *rs485); |
Nicolas Ferre | ad8c0ea | 2018-09-26 14:58:47 +0200 | [diff] [blame] | 459 | int (*iso7816_config)(struct uart_port *, |
| 460 | struct serial_iso7816 *iso7816); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | unsigned int irq; /* irq number */ |
Vikram Pandita | 1c2f049 | 2009-09-19 13:13:19 -0700 | [diff] [blame] | 462 | unsigned long irqflags; /* irq flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | unsigned int uartclk; /* base uart clock */ |
Russell King | 947deee | 2006-07-02 20:45:51 +0100 | [diff] [blame] | 464 | unsigned int fifosize; /* tx fifo size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | unsigned char x_char; /* xon/xoff char */ |
| 466 | unsigned char regshift; /* reg offset shift */ |
| 467 | unsigned char iotype; /* io access style */ |
Andy Shevchenko | c7ac15ce | 2017-07-25 20:39:58 +0300 | [diff] [blame] | 468 | unsigned char quirks; /* internal quirks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Andy Shevchenko | ae91751 | 2024-03-04 14:27:03 +0200 | [diff] [blame] | 470 | #define UPIO_UNKNOWN ((unsigned char)~0U) /* UCHAR_MAX */ |
Peter Hurley | 647f162 | 2015-03-01 10:24:28 -0500 | [diff] [blame] | 471 | #define UPIO_PORT (SERIAL_IO_PORT) /* 8b I/O port access */ |
| 472 | #define UPIO_HUB6 (SERIAL_IO_HUB6) /* Hub6 ISA card */ |
Peter Hurley | 858965d | 2015-11-27 21:29:24 -0500 | [diff] [blame] | 473 | #define UPIO_MEM (SERIAL_IO_MEM) /* driver-specific */ |
Peter Hurley | 647f162 | 2015-03-01 10:24:28 -0500 | [diff] [blame] | 474 | #define UPIO_MEM32 (SERIAL_IO_MEM32) /* 32b little endian */ |
| 475 | #define UPIO_AU (SERIAL_IO_AU) /* Au1x00 and RT288x type IO */ |
| 476 | #define UPIO_TSI (SERIAL_IO_TSI) /* Tsi108/109 type IO */ |
| 477 | #define UPIO_MEM32BE (SERIAL_IO_MEM32BE) /* 32b big endian */ |
Masahiro Yamada | bd94c40 | 2015-10-28 12:46:05 +0900 | [diff] [blame] | 478 | #define UPIO_MEM16 (SERIAL_IO_MEM16) /* 16b little endian */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Andy Shevchenko | c7ac15ce | 2017-07-25 20:39:58 +0300 | [diff] [blame] | 480 | /* quirks must be updated while holding port mutex */ |
| 481 | #define UPQ_NO_TXEN_TEST BIT(0) |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | unsigned int read_status_mask; /* driver specific */ |
| 484 | unsigned int ignore_status_mask; /* driver specific */ |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 485 | struct uart_state *state; /* pointer to parent state */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | struct uart_icount icount; /* statistics */ |
| 487 | |
| 488 | struct console *cons; /* struct console, if any */ |
Peter Hurley | 8a949b0 | 2014-09-02 17:39:19 -0400 | [diff] [blame] | 489 | /* flags must be updated while holding port mutex */ |
Russell King | 0077d45 | 2006-01-21 23:03:28 +0000 | [diff] [blame] | 490 | upf_t flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Peter Hurley | 904326ec | 2014-10-16 16:54:21 -0400 | [diff] [blame] | 492 | /* |
| 493 | * These flags must be equivalent to the flags defined in |
| 494 | * include/uapi/linux/tty_flags.h which are the userspace definitions |
| 495 | * assigned from the serial_struct flags in uart_set_info() |
| 496 | * [for bit definitions in the UPF_CHANGE_MASK] |
| 497 | * |
Andy Shevchenko | 916acbf | 2022-02-03 16:45:21 +0200 | [diff] [blame] | 498 | * Bits [0..ASYNCB_LAST_USER] are userspace defined/visible/changeable |
Peter Hurley | 904326ec | 2014-10-16 16:54:21 -0400 | [diff] [blame] | 499 | * The remaining bits are serial-core specific and not modifiable by |
| 500 | * userspace. |
| 501 | */ |
| 502 | #define UPF_FOURPORT ((__force upf_t) ASYNC_FOURPORT /* 1 */ ) |
| 503 | #define UPF_SAK ((__force upf_t) ASYNC_SAK /* 2 */ ) |
| 504 | #define UPF_SPD_HI ((__force upf_t) ASYNC_SPD_HI /* 4 */ ) |
| 505 | #define UPF_SPD_VHI ((__force upf_t) ASYNC_SPD_VHI /* 5 */ ) |
| 506 | #define UPF_SPD_CUST ((__force upf_t) ASYNC_SPD_CUST /* 0x0030 */ ) |
| 507 | #define UPF_SPD_WARP ((__force upf_t) ASYNC_SPD_WARP /* 0x1010 */ ) |
| 508 | #define UPF_SPD_MASK ((__force upf_t) ASYNC_SPD_MASK /* 0x1030 */ ) |
| 509 | #define UPF_SKIP_TEST ((__force upf_t) ASYNC_SKIP_TEST /* 6 */ ) |
| 510 | #define UPF_AUTO_IRQ ((__force upf_t) ASYNC_AUTO_IRQ /* 7 */ ) |
| 511 | #define UPF_HARDPPS_CD ((__force upf_t) ASYNC_HARDPPS_CD /* 11 */ ) |
| 512 | #define UPF_SPD_SHI ((__force upf_t) ASYNC_SPD_SHI /* 12 */ ) |
| 513 | #define UPF_LOW_LATENCY ((__force upf_t) ASYNC_LOW_LATENCY /* 13 */ ) |
| 514 | #define UPF_BUGGY_UART ((__force upf_t) ASYNC_BUGGY_UART /* 14 */ ) |
Peter Hurley | 904326ec | 2014-10-16 16:54:21 -0400 | [diff] [blame] | 515 | #define UPF_MAGIC_MULTIPLIER ((__force upf_t) ASYNC_MAGIC_MULTIPLIER /* 16 */ ) |
| 516 | |
Maciej W. Rozycki | 46a8973 | 2022-09-21 00:35:42 +0100 | [diff] [blame] | 517 | #define UPF_NO_THRE_TEST ((__force upf_t) BIT_ULL(19)) |
Peter Hurley | 391f93f | 2015-01-25 14:44:51 -0500 | [diff] [blame] | 518 | /* Port has hardware-assisted h/w flow control */ |
Maciej W. Rozycki | 46a8973 | 2022-09-21 00:35:42 +0100 | [diff] [blame] | 519 | #define UPF_AUTO_CTS ((__force upf_t) BIT_ULL(20)) |
| 520 | #define UPF_AUTO_RTS ((__force upf_t) BIT_ULL(21)) |
Peter Hurley | 391f93f | 2015-01-25 14:44:51 -0500 | [diff] [blame] | 521 | #define UPF_HARD_FLOW ((__force upf_t) (UPF_AUTO_CTS | UPF_AUTO_RTS)) |
Russell King | 2cbacaf | 2012-04-17 16:34:13 +0100 | [diff] [blame] | 522 | /* Port has hardware-assisted s/w flow control */ |
Maciej W. Rozycki | 46a8973 | 2022-09-21 00:35:42 +0100 | [diff] [blame] | 523 | #define UPF_SOFT_FLOW ((__force upf_t) BIT_ULL(22)) |
| 524 | #define UPF_CONS_FLOW ((__force upf_t) BIT_ULL(23)) |
| 525 | #define UPF_SHARE_IRQ ((__force upf_t) BIT_ULL(24)) |
| 526 | #define UPF_EXAR_EFR ((__force upf_t) BIT_ULL(25)) |
| 527 | #define UPF_BUG_THRE ((__force upf_t) BIT_ULL(26)) |
David Daney | 8e23fcc | 2009-01-02 13:49:54 +0000 | [diff] [blame] | 528 | /* The exact UART type is known and should not be probed. */ |
Maciej W. Rozycki | 46a8973 | 2022-09-21 00:35:42 +0100 | [diff] [blame] | 529 | #define UPF_FIXED_TYPE ((__force upf_t) BIT_ULL(27)) |
| 530 | #define UPF_BOOT_AUTOCONF ((__force upf_t) BIT_ULL(28)) |
| 531 | #define UPF_FIXED_PORT ((__force upf_t) BIT_ULL(29)) |
| 532 | #define UPF_DEAD ((__force upf_t) BIT_ULL(30)) |
| 533 | #define UPF_IOREMAP ((__force upf_t) BIT_ULL(31)) |
| 534 | #define UPF_FULL_PROBE ((__force upf_t) BIT_ULL(32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Peter Hurley | 904326ec | 2014-10-16 16:54:21 -0400 | [diff] [blame] | 536 | #define __UPF_CHANGE_MASK 0x17fff |
| 537 | #define UPF_CHANGE_MASK ((__force upf_t) __UPF_CHANGE_MASK) |
Russell King | 0077d45 | 2006-01-21 23:03:28 +0000 | [diff] [blame] | 538 | #define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Peter Hurley | 904326ec | 2014-10-16 16:54:21 -0400 | [diff] [blame] | 540 | #if __UPF_CHANGE_MASK > ASYNC_FLAGS |
| 541 | #error Change mask not equivalent to userspace-visible bit defines |
| 542 | #endif |
| 543 | |
Peter Hurley | 391f93f | 2015-01-25 14:44:51 -0500 | [diff] [blame] | 544 | /* |
| 545 | * Must hold termios_rwsem, port mutex and port lock to change; |
| 546 | * can hold any one lock to read. |
| 547 | */ |
Peter Hurley | 299245a | 2014-09-10 15:06:24 -0400 | [diff] [blame] | 548 | upstat_t status; |
| 549 | |
| 550 | #define UPSTAT_CTS_ENABLE ((__force upstat_t) (1 << 0)) |
| 551 | #define UPSTAT_DCD_ENABLE ((__force upstat_t) (1 << 1)) |
Peter Hurley | 391f93f | 2015-01-25 14:44:51 -0500 | [diff] [blame] | 552 | #define UPSTAT_AUTORTS ((__force upstat_t) (1 << 2)) |
| 553 | #define UPSTAT_AUTOCTS ((__force upstat_t) (1 << 3)) |
| 554 | #define UPSTAT_AUTOXOFF ((__force upstat_t) (1 << 4)) |
Jeremy Kerr | c5f78b1 | 2018-03-27 11:48:24 +0800 | [diff] [blame] | 555 | #define UPSTAT_SYNC_FIFO ((__force upstat_t) (1 << 5)) |
Peter Hurley | 299245a | 2014-09-10 15:06:24 -0400 | [diff] [blame] | 556 | |
Peter Hurley | d01f4d1 | 2014-09-10 15:06:26 -0400 | [diff] [blame] | 557 | int hw_stopped; /* sw-assisted CTS flow state */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | unsigned int mctrl; /* current modem ctrl settings */ |
Ilpo Järvinen | 31f6bd7 | 2022-04-25 17:33:58 +0300 | [diff] [blame] | 559 | unsigned int frame_time; /* frame timing in ns */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | unsigned int type; /* port type */ |
Russell King | ba899db | 2006-01-21 22:45:50 +0000 | [diff] [blame] | 561 | const struct uart_ops *ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | unsigned int custom_divisor; |
| 563 | unsigned int line; /* port index */ |
Peter Hurley | 959801f | 2015-02-24 14:25:00 -0500 | [diff] [blame] | 564 | unsigned int minor; |
Josh Boyer | 4f640ef | 2007-07-23 18:43:44 -0700 | [diff] [blame] | 565 | resource_size_t mapbase; /* for ioremap */ |
Mans Rullgard | ee97d0e | 2015-03-08 14:30:04 +0000 | [diff] [blame] | 566 | resource_size_t mapsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | struct device *dev; /* parent device */ |
Dmitry Safonov | 7e5ed9f | 2019-12-13 00:06:01 +0000 | [diff] [blame] | 568 | |
Dmitry Safonov | 7e5ed9f | 2019-12-13 00:06:01 +0000 | [diff] [blame] | 569 | unsigned long sysrq; /* sysrq timeout */ |
| 570 | unsigned int sysrq_ch; /* char for sysrq */ |
Dmitry Safonov | 1997e9d | 2019-12-13 00:06:02 +0000 | [diff] [blame] | 571 | unsigned char has_sysrq; |
Dmitry Safonov | 68af431 | 2020-03-02 17:51:35 +0000 | [diff] [blame] | 572 | unsigned char sysrq_seq; /* index in sysrq_toggle_seq */ |
Dmitry Safonov | 7e5ed9f | 2019-12-13 00:06:01 +0000 | [diff] [blame] | 573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | unsigned char hub6; /* this should be in the 8250 driver */ |
Guennadi Liakhovetski | b3b708f | 2007-10-16 01:24:02 -0700 | [diff] [blame] | 575 | unsigned char suspended; |
Johan Hovold | e0830dbf | 2020-09-09 16:31:01 +0200 | [diff] [blame] | 576 | unsigned char console_reinit; |
Andy Shevchenko | 2e94d5a | 2017-03-31 21:35:17 +0300 | [diff] [blame] | 577 | const char *name; /* port name */ |
Greg Kroah-Hartman | 266dcff | 2014-07-16 01:19:34 +0000 | [diff] [blame] | 578 | struct attribute_group *attr_group; /* port specific attributes */ |
| 579 | const struct attribute_group **tty_groups; /* all attributes (serial core use only) */ |
Ricardo Ribalda Delgado | a5f276f | 2014-11-06 22:46:13 +0100 | [diff] [blame] | 580 | struct serial_rs485 rs485; |
Ilpo Järvinen | 0139da5 | 2022-07-04 12:45:14 +0300 | [diff] [blame] | 581 | struct serial_rs485 rs485_supported; /* Supported mask for serial_rs485 */ |
Lukas Wunner | d58a2df | 2020-05-18 16:45:02 +0200 | [diff] [blame] | 582 | struct gpio_desc *rs485_term_gpio; /* enable RS485 bus termination */ |
Nicolas Ferre | ad8c0ea | 2018-09-26 14:58:47 +0200 | [diff] [blame] | 583 | struct serial_iso7816 iso7816; |
Marc St-Jean | beab697 | 2007-05-06 14:48:45 -0700 | [diff] [blame] | 584 | void *private_data; /* generic platform data pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | }; |
| 586 | |
Thomas Gleixner | 4fd9a02 | 2023-09-14 20:43:18 +0206 | [diff] [blame] | 587 | /** |
| 588 | * uart_port_lock - Lock the UART port |
| 589 | * @up: Pointer to UART port structure |
| 590 | */ |
| 591 | static inline void uart_port_lock(struct uart_port *up) |
| 592 | { |
| 593 | spin_lock(&up->lock); |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * uart_port_lock_irq - Lock the UART port and disable interrupts |
| 598 | * @up: Pointer to UART port structure |
| 599 | */ |
| 600 | static inline void uart_port_lock_irq(struct uart_port *up) |
| 601 | { |
| 602 | spin_lock_irq(&up->lock); |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * uart_port_lock_irqsave - Lock the UART port, save and disable interrupts |
| 607 | * @up: Pointer to UART port structure |
| 608 | * @flags: Pointer to interrupt flags storage |
| 609 | */ |
| 610 | static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags) |
| 611 | { |
| 612 | spin_lock_irqsave(&up->lock, *flags); |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * uart_port_trylock - Try to lock the UART port |
| 617 | * @up: Pointer to UART port structure |
| 618 | * |
| 619 | * Returns: True if lock was acquired, false otherwise |
| 620 | */ |
| 621 | static inline bool uart_port_trylock(struct uart_port *up) |
| 622 | { |
| 623 | return spin_trylock(&up->lock); |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * uart_port_trylock_irqsave - Try to lock the UART port, save and disable interrupts |
| 628 | * @up: Pointer to UART port structure |
| 629 | * @flags: Pointer to interrupt flags storage |
| 630 | * |
| 631 | * Returns: True if lock was acquired, false otherwise |
| 632 | */ |
| 633 | static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigned long *flags) |
| 634 | { |
| 635 | return spin_trylock_irqsave(&up->lock, *flags); |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * uart_port_unlock - Unlock the UART port |
| 640 | * @up: Pointer to UART port structure |
| 641 | */ |
| 642 | static inline void uart_port_unlock(struct uart_port *up) |
| 643 | { |
| 644 | spin_unlock(&up->lock); |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * uart_port_unlock_irq - Unlock the UART port and re-enable interrupts |
| 649 | * @up: Pointer to UART port structure |
| 650 | */ |
| 651 | static inline void uart_port_unlock_irq(struct uart_port *up) |
| 652 | { |
| 653 | spin_unlock_irq(&up->lock); |
| 654 | } |
| 655 | |
| 656 | /** |
Randy Dunlap | e90c7d2 | 2023-09-26 21:41:28 -0700 | [diff] [blame] | 657 | * uart_port_unlock_irqrestore - Unlock the UART port, restore interrupts |
Thomas Gleixner | 4fd9a02 | 2023-09-14 20:43:18 +0206 | [diff] [blame] | 658 | * @up: Pointer to UART port structure |
| 659 | * @flags: The saved interrupt flags for restore |
| 660 | */ |
| 661 | static inline void uart_port_unlock_irqrestore(struct uart_port *up, unsigned long flags) |
| 662 | { |
| 663 | spin_unlock_irqrestore(&up->lock, flags); |
| 664 | } |
| 665 | |
Paul Gortmaker | 927353a | 2012-03-08 19:12:12 -0500 | [diff] [blame] | 666 | static inline int serial_port_in(struct uart_port *up, int offset) |
| 667 | { |
| 668 | return up->serial_in(up, offset); |
| 669 | } |
| 670 | |
| 671 | static inline void serial_port_out(struct uart_port *up, int offset, int value) |
| 672 | { |
| 673 | up->serial_out(up, offset, value); |
| 674 | } |
| 675 | |
Linus Walleij | 6f538fe | 2012-12-07 11:36:08 +0100 | [diff] [blame] | 676 | /** |
| 677 | * enum uart_pm_state - power states for UARTs |
| 678 | * @UART_PM_STATE_ON: UART is powered, up and operational |
| 679 | * @UART_PM_STATE_OFF: UART is powered off |
| 680 | * @UART_PM_STATE_UNDEFINED: sentinel |
| 681 | */ |
| 682 | enum uart_pm_state { |
| 683 | UART_PM_STATE_ON = 0, |
| 684 | UART_PM_STATE_OFF = 3, /* number taken from ACPI */ |
| 685 | UART_PM_STATE_UNDEFINED, |
| 686 | }; |
| 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | /* |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 689 | * This is the state information which is persistent across opens. |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 690 | */ |
| 691 | struct uart_state { |
Alan Cox | df4f4dd | 2008-07-16 21:53:50 +0100 | [diff] [blame] | 692 | struct tty_port port; |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 693 | |
Linus Walleij | 6f538fe | 2012-12-07 11:36:08 +0100 | [diff] [blame] | 694 | enum uart_pm_state pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | struct circ_buf xmit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Peter Hurley | 9ed1942 | 2016-04-09 18:56:34 -0700 | [diff] [blame] | 697 | atomic_t refcount; |
| 698 | wait_queue_head_t remove_wait; |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 699 | struct uart_port *uart_port; |
Alan Cox | f751928 | 2009-01-02 13:49:21 +0000 | [diff] [blame] | 700 | }; |
| 701 | |
| 702 | #define UART_XMIT_SIZE PAGE_SIZE |
| 703 | |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | /* number of characters left in xmit buffer before we ask for more */ |
| 706 | #define WAKEUP_CHARS 256 |
| 707 | |
Ilpo Järvinen | e77cab7 | 2022-09-01 17:39:32 +0300 | [diff] [blame] | 708 | /** |
| 709 | * uart_xmit_advance - Advance xmit buffer and account Tx'ed chars |
| 710 | * @up: uart_port structure describing the port |
| 711 | * @chars: number of characters sent |
| 712 | * |
| 713 | * This function advances the tail of circular xmit buffer by the number of |
| 714 | * @chars transmitted and handles accounting of transmitted bytes (into |
| 715 | * @up's icount.tx). |
| 716 | */ |
| 717 | static inline void uart_xmit_advance(struct uart_port *up, unsigned int chars) |
| 718 | { |
| 719 | struct circ_buf *xmit = &up->state->xmit; |
| 720 | |
| 721 | xmit->tail = (xmit->tail + chars) & (UART_XMIT_SIZE - 1); |
| 722 | up->icount.tx += chars; |
| 723 | } |
| 724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | struct module; |
| 726 | struct tty_driver; |
| 727 | |
| 728 | struct uart_driver { |
| 729 | struct module *owner; |
| 730 | const char *driver_name; |
| 731 | const char *dev_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | int major; |
| 733 | int minor; |
| 734 | int nr; |
| 735 | struct console *cons; |
| 736 | |
| 737 | /* |
| 738 | * these are private; the low level driver should not |
| 739 | * touch these; they should be initialised to NULL |
| 740 | */ |
| 741 | struct uart_state *state; |
| 742 | struct tty_driver *tty_driver; |
| 743 | }; |
| 744 | |
| 745 | void uart_write_wakeup(struct uart_port *port); |
| 746 | |
| 747 | /* |
| 748 | * Baud rate helpers. |
| 749 | */ |
| 750 | void uart_update_timeout(struct uart_port *port, unsigned int cflag, |
| 751 | unsigned int baud); |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 752 | unsigned int uart_get_baud_rate(struct uart_port *port, struct ktermios *termios, |
Ilpo Järvinen | bec5b81 | 2022-08-16 14:57:37 +0300 | [diff] [blame] | 753 | const struct ktermios *old, unsigned int min, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | unsigned int max); |
| 755 | unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud); |
| 756 | |
Ilpo Järvinen | f900828 | 2022-06-13 14:39:05 +0300 | [diff] [blame] | 757 | /* |
| 758 | * Calculates FIFO drain time. |
| 759 | */ |
| 760 | static inline unsigned long uart_fifo_timeout(struct uart_port *port) |
| 761 | { |
| 762 | u64 fifo_timeout = (u64)READ_ONCE(port->frame_time) * port->fifosize; |
| 763 | |
| 764 | /* Add .02 seconds of slop */ |
| 765 | fifo_timeout += 20 * NSEC_PER_MSEC; |
| 766 | |
| 767 | return max(nsecs_to_jiffies(fifo_timeout), 1UL); |
| 768 | } |
| 769 | |
Anton Vorontsov | 5438106 | 2010-10-01 17:21:25 +0400 | [diff] [blame] | 770 | /* Base timer interval for polling */ |
| 771 | static inline int uart_poll_timeout(struct uart_port *port) |
| 772 | { |
Ilpo Järvinen | f900828 | 2022-06-13 14:39:05 +0300 | [diff] [blame] | 773 | int timeout = uart_fifo_timeout(port); |
Anton Vorontsov | 5438106 | 2010-10-01 17:21:25 +0400 | [diff] [blame] | 774 | |
| 775 | return timeout > 6 ? (timeout / 2 - 2) : 1; |
| 776 | } |
| 777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | /* |
| 779 | * Console helpers. |
| 780 | */ |
Rob Herring | 9aac588 | 2014-04-18 17:19:55 -0500 | [diff] [blame] | 781 | struct earlycon_device { |
| 782 | struct console *con; |
| 783 | struct uart_port port; |
| 784 | char options[16]; /* e.g., 115200n8 */ |
| 785 | unsigned int baud; |
| 786 | }; |
Rob Herring | 9aac588 | 2014-04-18 17:19:55 -0500 | [diff] [blame] | 787 | |
Peter Hurley | 470ca0d | 2015-03-09 16:27:21 -0400 | [diff] [blame] | 788 | struct earlycon_id { |
Douglas Anderson | c1c734c | 2018-03-23 10:58:31 -0700 | [diff] [blame] | 789 | char name[15]; |
| 790 | char name_term; /* In case compiler didn't '\0' term name */ |
Peter Hurley | 2eaa790 | 2016-01-16 15:23:39 -0800 | [diff] [blame] | 791 | char compatible[128]; |
Peter Hurley | 470ca0d | 2015-03-09 16:27:21 -0400 | [diff] [blame] | 792 | int (*setup)(struct earlycon_device *, const char *options); |
Daniel Kurtz | dd709e7 | 2018-04-06 17:21:53 -0600 | [diff] [blame] | 793 | }; |
Peter Hurley | 470ca0d | 2015-03-09 16:27:21 -0400 | [diff] [blame] | 794 | |
Johan Hovold | 62dcd9c | 2020-11-23 11:23:13 +0100 | [diff] [blame] | 795 | extern const struct earlycon_id __earlycon_table[]; |
| 796 | extern const struct earlycon_id __earlycon_table_end[]; |
Peter Hurley | 2eaa790 | 2016-01-16 15:23:39 -0800 | [diff] [blame] | 797 | |
Masahiro Yamada | f8ba364 | 2016-06-06 18:41:00 +0900 | [diff] [blame] | 798 | #if defined(CONFIG_SERIAL_EARLYCON) && !defined(MODULE) |
| 799 | #define EARLYCON_USED_OR_UNUSED __used |
| 800 | #else |
| 801 | #define EARLYCON_USED_OR_UNUSED __maybe_unused |
| 802 | #endif |
| 803 | |
Johan Hovold | 62dcd9c | 2020-11-23 11:23:13 +0100 | [diff] [blame] | 804 | #define OF_EARLYCON_DECLARE(_name, compat, fn) \ |
| 805 | static const struct earlycon_id __UNIQUE_ID(__earlycon_##_name) \ |
| 806 | EARLYCON_USED_OR_UNUSED __section("__earlycon_table") \ |
| 807 | __aligned(__alignof__(struct earlycon_id)) \ |
Peter Hurley | 2eaa790 | 2016-01-16 15:23:39 -0800 | [diff] [blame] | 808 | = { .name = __stringify(_name), \ |
| 809 | .compatible = compat, \ |
Johan Hovold | 76437b3 | 2020-12-07 10:16:01 +0100 | [diff] [blame] | 810 | .setup = fn } |
Peter Hurley | 2eaa790 | 2016-01-16 15:23:39 -0800 | [diff] [blame] | 811 | |
| 812 | #define EARLYCON_DECLARE(_name, fn) OF_EARLYCON_DECLARE(_name, "", fn) |
| 813 | |
Peter Hurley | c90fe9c | 2016-01-16 15:23:44 -0800 | [diff] [blame] | 814 | extern int of_setup_earlycon(const struct earlycon_id *match, |
Peter Hurley | 088da2a | 2016-01-16 15:23:43 -0800 | [diff] [blame] | 815 | unsigned long node, |
Peter Hurley | 4d118c9 | 2016-01-16 15:23:42 -0800 | [diff] [blame] | 816 | const char *options); |
Rob Herring | b0b6abd | 2014-03-27 08:06:16 -0500 | [diff] [blame] | 817 | |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 818 | #ifdef CONFIG_SERIAL_EARLYCON |
Prarit Bhargava | 0231d00 | 2018-01-18 10:09:51 -0500 | [diff] [blame] | 819 | extern bool earlycon_acpi_spcr_enable __initdata; |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 820 | int setup_earlycon(char *buf); |
| 821 | #else |
Mathieu Malaterre | 219c7b0 | 2018-03-10 19:06:45 +0100 | [diff] [blame] | 822 | static const bool earlycon_acpi_spcr_enable EARLYCON_USED_OR_UNUSED; |
Aleksey Makarov | ad1696f | 2016-09-27 23:54:13 +0300 | [diff] [blame] | 823 | static inline int setup_earlycon(char *buf) { return 0; } |
| 824 | #endif |
| 825 | |
Ilpo Järvinen | f9b1122 | 2022-06-29 12:48:41 +0300 | [diff] [blame] | 826 | static inline bool uart_console_enabled(struct uart_port *port) |
| 827 | { |
| 828 | return uart_console(port) && (port->cons->flags & CON_ENABLED); |
| 829 | } |
| 830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | struct uart_port *uart_get_console(struct uart_port *ports, int nr, |
| 832 | struct console *c); |
Alexander Sverdlin | 46e3668 | 2016-09-02 13:20:21 +0200 | [diff] [blame] | 833 | int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr, |
Peter Hurley | 73abaf8 | 2015-03-01 11:05:46 -0500 | [diff] [blame] | 834 | char **options); |
Paul Cercueil | 0f646b6 | 2017-12-28 14:07:07 +0100 | [diff] [blame] | 835 | void uart_parse_options(const char *options, int *baud, int *parity, int *bits, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | int *flow); |
| 837 | int uart_set_options(struct uart_port *port, struct console *co, int baud, |
| 838 | int parity, int bits, int flow); |
| 839 | struct tty_driver *uart_console_device(struct console *co, int *index); |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 840 | void uart_console_write(struct uart_port *port, const char *s, |
| 841 | unsigned int count, |
Jiri Slaby | 3f8bab1 | 2022-03-03 09:08:31 +0100 | [diff] [blame] | 842 | void (*putchar)(struct uart_port *, unsigned char)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | /* |
| 845 | * Port/driver registration/removal |
| 846 | */ |
| 847 | int uart_register_driver(struct uart_driver *uart); |
| 848 | void uart_unregister_driver(struct uart_driver *uart); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | int uart_add_one_port(struct uart_driver *reg, struct uart_port *port); |
| 850 | int uart_remove_one_port(struct uart_driver *reg, struct uart_port *port); |
Jiri Slaby | b8be5db | 2021-05-19 09:21:50 +0200 | [diff] [blame] | 851 | bool uart_match_port(const struct uart_port *port1, |
| 852 | const struct uart_port *port2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
| 854 | /* |
| 855 | * Power Management |
| 856 | */ |
| 857 | int uart_suspend_port(struct uart_driver *reg, struct uart_port *port); |
| 858 | int uart_resume_port(struct uart_driver *reg, struct uart_port *port); |
| 859 | |
| 860 | #define uart_circ_empty(circ) ((circ)->head == (circ)->tail) |
| 861 | #define uart_circ_clear(circ) ((circ)->head = (circ)->tail = 0) |
| 862 | |
| 863 | #define uart_circ_chars_pending(circ) \ |
| 864 | (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE)) |
| 865 | |
| 866 | #define uart_circ_chars_free(circ) \ |
| 867 | (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE)) |
| 868 | |
Alan Cox | f751928 | 2009-01-02 13:49:21 +0000 | [diff] [blame] | 869 | static inline int uart_tx_stopped(struct uart_port *port) |
| 870 | { |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 871 | struct tty_struct *tty = port->state->port.tty; |
Jiri Slaby | 6e94dbc | 2021-05-05 11:19:05 +0200 | [diff] [blame] | 872 | if ((tty && tty->flow.stopped) || port->hw_stopped) |
Alan Cox | f751928 | 2009-01-02 13:49:21 +0000 | [diff] [blame] | 873 | return 1; |
| 874 | return 0; |
| 875 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Peter Hurley | 299245a | 2014-09-10 15:06:24 -0400 | [diff] [blame] | 877 | static inline bool uart_cts_enabled(struct uart_port *uport) |
| 878 | { |
Peter Hurley | d4260b5 | 2014-10-16 14:19:47 -0400 | [diff] [blame] | 879 | return !!(uport->status & UPSTAT_CTS_ENABLE); |
Peter Hurley | 299245a | 2014-09-10 15:06:24 -0400 | [diff] [blame] | 880 | } |
| 881 | |
Peter Hurley | 391f93f | 2015-01-25 14:44:51 -0500 | [diff] [blame] | 882 | static inline bool uart_softcts_mode(struct uart_port *uport) |
| 883 | { |
| 884 | upstat_t mask = UPSTAT_CTS_ENABLE | UPSTAT_AUTOCTS; |
| 885 | |
| 886 | return ((uport->status & mask) == UPSTAT_CTS_ENABLE); |
| 887 | } |
| 888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | /* |
| 890 | * The following are helper functions for the low level drivers. |
| 891 | */ |
Jiri Slaby | 027d7da | 2011-11-09 21:33:43 +0100 | [diff] [blame] | 892 | |
| 893 | extern void uart_handle_dcd_change(struct uart_port *uport, |
| 894 | unsigned int status); |
| 895 | extern void uart_handle_cts_change(struct uart_port *uport, |
| 896 | unsigned int status); |
| 897 | |
| 898 | extern void uart_insert_char(struct uart_port *port, unsigned int status, |
| 899 | unsigned int overrun, unsigned int ch, unsigned int flag); |
| 900 | |
Ilpo Järvinen | f58c252 | 2022-03-14 11:14:32 +0200 | [diff] [blame] | 901 | void uart_xchar_out(struct uart_port *uport, int offset); |
| 902 | |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 903 | #ifdef CONFIG_MAGIC_SYSRQ_SERIAL |
| 904 | #define SYSRQ_TIMEOUT (HZ * 5) |
| 905 | |
| 906 | bool uart_try_toggle_sysrq(struct uart_port *port, unsigned int ch); |
| 907 | |
| 908 | static inline int uart_handle_sysrq_char(struct uart_port *port, unsigned int ch) |
| 909 | { |
Johan Hovold | 2253856 | 2020-06-10 17:22:32 +0200 | [diff] [blame] | 910 | if (!port->sysrq) |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 911 | return 0; |
| 912 | |
| 913 | if (ch && time_before(jiffies, port->sysrq)) { |
| 914 | if (sysrq_mask()) { |
| 915 | handle_sysrq(ch); |
| 916 | port->sysrq = 0; |
| 917 | return 1; |
| 918 | } |
| 919 | if (uart_try_toggle_sysrq(port, ch)) |
| 920 | return 1; |
| 921 | } |
| 922 | port->sysrq = 0; |
| 923 | |
| 924 | return 0; |
| 925 | } |
| 926 | |
| 927 | static inline int uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch) |
| 928 | { |
Johan Hovold | 2253856 | 2020-06-10 17:22:32 +0200 | [diff] [blame] | 929 | if (!port->sysrq) |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 930 | return 0; |
| 931 | |
| 932 | if (ch && time_before(jiffies, port->sysrq)) { |
| 933 | if (sysrq_mask()) { |
| 934 | port->sysrq_ch = ch; |
| 935 | port->sysrq = 0; |
| 936 | return 1; |
| 937 | } |
| 938 | if (uart_try_toggle_sysrq(port, ch)) |
| 939 | return 1; |
| 940 | } |
| 941 | port->sysrq = 0; |
| 942 | |
| 943 | return 0; |
| 944 | } |
| 945 | |
Johan Hovold | 75f4e83 | 2021-04-16 16:05:55 +0200 | [diff] [blame] | 946 | static inline void uart_unlock_and_check_sysrq(struct uart_port *port) |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 947 | { |
| 948 | int sysrq_ch; |
| 949 | |
| 950 | if (!port->has_sysrq) { |
Johan Hovold | 75f4e83 | 2021-04-16 16:05:55 +0200 | [diff] [blame] | 951 | spin_unlock(&port->lock); |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 952 | return; |
| 953 | } |
| 954 | |
| 955 | sysrq_ch = port->sysrq_ch; |
| 956 | port->sysrq_ch = 0; |
| 957 | |
Johan Hovold | 75f4e83 | 2021-04-16 16:05:55 +0200 | [diff] [blame] | 958 | spin_unlock(&port->lock); |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 959 | |
| 960 | if (sysrq_ch) |
| 961 | handle_sysrq(sysrq_ch); |
| 962 | } |
Johan Hovold | 853a9ae | 2021-07-14 10:04:27 +0200 | [diff] [blame] | 963 | |
| 964 | static inline void uart_unlock_and_check_sysrq_irqrestore(struct uart_port *port, |
| 965 | unsigned long flags) |
| 966 | { |
| 967 | int sysrq_ch; |
| 968 | |
| 969 | if (!port->has_sysrq) { |
| 970 | spin_unlock_irqrestore(&port->lock, flags); |
| 971 | return; |
| 972 | } |
| 973 | |
| 974 | sysrq_ch = port->sysrq_ch; |
| 975 | port->sysrq_ch = 0; |
| 976 | |
| 977 | spin_unlock_irqrestore(&port->lock, flags); |
| 978 | |
| 979 | if (sysrq_ch) |
| 980 | handle_sysrq(sysrq_ch); |
| 981 | } |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 982 | #else /* CONFIG_MAGIC_SYSRQ_SERIAL */ |
| 983 | static inline int uart_handle_sysrq_char(struct uart_port *port, unsigned int ch) |
| 984 | { |
| 985 | return 0; |
| 986 | } |
| 987 | static inline int uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch) |
| 988 | { |
| 989 | return 0; |
| 990 | } |
Johan Hovold | 75f4e83 | 2021-04-16 16:05:55 +0200 | [diff] [blame] | 991 | static inline void uart_unlock_and_check_sysrq(struct uart_port *port) |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 992 | { |
Johan Hovold | 75f4e83 | 2021-04-16 16:05:55 +0200 | [diff] [blame] | 993 | spin_unlock(&port->lock); |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 994 | } |
Johan Hovold | 853a9ae | 2021-07-14 10:04:27 +0200 | [diff] [blame] | 995 | static inline void uart_unlock_and_check_sysrq_irqrestore(struct uart_port *port, |
| 996 | unsigned long flags) |
| 997 | { |
| 998 | spin_unlock_irqrestore(&port->lock, flags); |
| 999 | } |
Johan Hovold | 08d5470 | 2020-06-10 17:22:31 +0200 | [diff] [blame] | 1000 | #endif /* CONFIG_MAGIC_SYSRQ_SERIAL */ |
| 1001 | |
| 1002 | /* |
| 1003 | * We do the SysRQ and SAK checking like this... |
| 1004 | */ |
| 1005 | static inline int uart_handle_break(struct uart_port *port) |
| 1006 | { |
| 1007 | struct uart_state *state = port->state; |
| 1008 | |
| 1009 | if (port->handle_break) |
| 1010 | port->handle_break(port); |
| 1011 | |
| 1012 | #ifdef CONFIG_MAGIC_SYSRQ_SERIAL |
| 1013 | if (port->has_sysrq && uart_console(port)) { |
| 1014 | if (!port->sysrq) { |
| 1015 | port->sysrq = jiffies + SYSRQ_TIMEOUT; |
| 1016 | return 1; |
| 1017 | } |
| 1018 | port->sysrq = 0; |
| 1019 | } |
| 1020 | #endif |
| 1021 | if (port->flags & UPF_SAK) |
| 1022 | do_SAK(state->port.tty); |
| 1023 | return 0; |
| 1024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | /* |
| 1027 | * UART_ENABLE_MS - determine if port should enable modem status irqs |
| 1028 | */ |
| 1029 | #define UART_ENABLE_MS(port,cflag) ((port)->flags & UPF_HARDPPS_CD || \ |
| 1030 | (cflag) & CRTSCTS || \ |
| 1031 | !((cflag) & CLOCAL)) |
| 1032 | |
Lukas Wunner | c150c0f | 2020-05-12 14:40:02 +0200 | [diff] [blame] | 1033 | int uart_get_rs485_mode(struct uart_port *port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | #endif /* LINUX_SERIAL_CORE_H */ |