Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | Low Level Serial API |
| 3 | -------------------- |
| 4 | |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | This document is meant as a brief overview of some aspects of the new serial |
| 7 | driver. It is not complete, any questions you have should be directed to |
| 8 | <rmk@arm.linux.org.uk> |
| 9 | |
Russell King | 67ab7f5 | 2006-04-15 20:46:11 +0100 | [diff] [blame] | 10 | The reference implementation is contained within amba_pl011.c. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | |
| 13 | |
| 14 | Low Level Serial Hardware Driver |
| 15 | -------------------------------- |
| 16 | |
| 17 | The low level serial hardware driver is responsible for supplying port |
| 18 | information (defined by uart_port) and a set of control methods (defined |
| 19 | by uart_ops) to the core serial driver. The low level driver is also |
| 20 | responsible for handling interrupts for the port, and providing any |
| 21 | console support. |
| 22 | |
| 23 | |
| 24 | Console Support |
| 25 | --------------- |
| 26 | |
| 27 | The serial core provides a few helper functions. This includes identifing |
| 28 | the correct port structure (via uart_get_console) and decoding command line |
| 29 | arguments (uart_parse_options). |
| 30 | |
| 31 | |
| 32 | Locking |
| 33 | ------- |
| 34 | |
| 35 | It is the responsibility of the low level hardware driver to perform the |
| 36 | necessary locking using port->lock. There are some exceptions (which |
| 37 | are described in the uart_ops listing below.) |
| 38 | |
Geert Uytterhoeven | 4895b1d | 2016-03-14 16:16:10 +0100 | [diff] [blame] | 39 | There are two locks. A per-port spinlock, and an overall semaphore. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | From the core driver perspective, the port->lock locks the following |
| 42 | data: |
| 43 | |
| 44 | port->mctrl |
| 45 | port->icount |
| 46 | info->xmit.head (circ->head) |
| 47 | info->xmit.tail (circ->tail) |
| 48 | |
| 49 | The low level driver is free to use this lock to provide any additional |
| 50 | locking. |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | The port_sem semaphore is used to protect against ports being added/ |
Peter Hurley | 7c8ab96 | 2014-10-16 16:54:20 -0400 | [diff] [blame] | 53 | removed or reconfigured at inappropriate times. Since v2.6.27, this |
| 54 | semaphore has been the 'mutex' member of the tty_port struct, and |
| 55 | commonly referred to as the port mutex (or port->mutex). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | |
| 58 | uart_ops |
| 59 | -------- |
| 60 | |
| 61 | The uart_ops structure is the main interface between serial_core and the |
| 62 | hardware specific driver. It contains all the methods to control the |
| 63 | hardware. |
| 64 | |
| 65 | tx_empty(port) |
| 66 | This function tests whether the transmitter fifo and shifter |
| 67 | for the port described by 'port' is empty. If it is empty, |
| 68 | this function should return TIOCSER_TEMT, otherwise return 0. |
| 69 | If the port does not support this operation, then it should |
| 70 | return TIOCSER_TEMT. |
| 71 | |
| 72 | Locking: none. |
| 73 | Interrupts: caller dependent. |
| 74 | This call must not sleep |
| 75 | |
| 76 | set_mctrl(port, mctrl) |
| 77 | This function sets the modem control lines for port described |
| 78 | by 'port' to the state described by mctrl. The relevant bits |
| 79 | of mctrl are: |
| 80 | - TIOCM_RTS RTS signal. |
| 81 | - TIOCM_DTR DTR signal. |
| 82 | - TIOCM_OUT1 OUT1 signal. |
| 83 | - TIOCM_OUT2 OUT2 signal. |
Russell King | 67ab7f5 | 2006-04-15 20:46:11 +0100 | [diff] [blame] | 84 | - TIOCM_LOOP Set the port into loopback mode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | If the appropriate bit is set, the signal should be driven |
| 86 | active. If the bit is clear, the signal should be driven |
| 87 | inactive. |
| 88 | |
| 89 | Locking: port->lock taken. |
| 90 | Interrupts: locally disabled. |
| 91 | This call must not sleep |
| 92 | |
| 93 | get_mctrl(port) |
| 94 | Returns the current state of modem control inputs. The state |
| 95 | of the outputs should not be returned, since the core keeps |
| 96 | track of their state. The state information should include: |
Uwe Kleine-König | 343fe40 | 2012-01-04 15:27:32 -0800 | [diff] [blame] | 97 | - TIOCM_CAR state of DCD signal |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | - TIOCM_CTS state of CTS signal |
| 99 | - TIOCM_DSR state of DSR signal |
| 100 | - TIOCM_RI state of RI signal |
| 101 | The bit is set if the signal is currently driven active. If |
| 102 | the port does not support CTS, DCD or DSR, the driver should |
| 103 | indicate that the signal is permanently active. If RI is |
| 104 | not available, the signal should not be indicated as active. |
| 105 | |
Russell King | c5f4644 | 2005-06-29 09:42:38 +0100 | [diff] [blame] | 106 | Locking: port->lock taken. |
| 107 | Interrupts: locally disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | This call must not sleep |
| 109 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 110 | stop_tx(port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | Stop transmitting characters. This might be due to the CTS |
| 112 | line becoming inactive or the tty layer indicating we want |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 113 | to stop transmission due to an XOFF character. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 115 | The driver should stop transmitting characters as soon as |
| 116 | possible. |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | Locking: port->lock taken. |
| 119 | Interrupts: locally disabled. |
| 120 | This call must not sleep |
| 121 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 122 | start_tx(port) |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 123 | Start transmitting characters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | Locking: port->lock taken. |
| 126 | Interrupts: locally disabled. |
| 127 | This call must not sleep |
| 128 | |
Geert Uytterhoeven | 39c5144 | 2016-03-14 16:16:11 +0100 | [diff] [blame] | 129 | throttle(port) |
| 130 | Notify the serial driver that input buffers for the line discipline are |
| 131 | close to full, and it should somehow signal that no more characters |
| 132 | should be sent to the serial port. |
| 133 | |
| 134 | Locking: none. |
| 135 | |
Geert Uytterhoeven | e27585c | 2016-03-14 16:16:12 +0100 | [diff] [blame] | 136 | unthrottle(port) |
| 137 | Notify the serial driver that characters can now be sent to the serial |
| 138 | port without fear of overrunning the input buffers of the line |
| 139 | disciplines. |
| 140 | |
| 141 | Locking: none. |
| 142 | |
Kevin Cernekee | e759d7c | 2012-12-26 20:43:42 -0800 | [diff] [blame] | 143 | send_xchar(port,ch) |
| 144 | Transmit a high priority character, even if the port is stopped. |
| 145 | This is used to implement XON/XOFF flow control and tcflow(). If |
| 146 | the serial driver does not implement this function, the tty core |
| 147 | will append the character to the circular buffer and then call |
| 148 | start_tx() / stop_tx() to flush the data out. |
| 149 | |
Peter Hurley | db106df | 2014-09-02 17:39:15 -0400 | [diff] [blame] | 150 | Do not transmit if ch == '\0' (__DISABLED_CHAR). |
| 151 | |
Kevin Cernekee | e759d7c | 2012-12-26 20:43:42 -0800 | [diff] [blame] | 152 | Locking: none. |
| 153 | Interrupts: caller dependent. |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | stop_rx(port) |
| 156 | Stop receiving characters; the port is in the process of |
| 157 | being closed. |
| 158 | |
| 159 | Locking: port->lock taken. |
| 160 | Interrupts: locally disabled. |
| 161 | This call must not sleep |
| 162 | |
| 163 | enable_ms(port) |
| 164 | Enable the modem status interrupts. |
| 165 | |
Russell King | 67ab7f5 | 2006-04-15 20:46:11 +0100 | [diff] [blame] | 166 | This method may be called multiple times. Modem status |
| 167 | interrupts should be disabled when the shutdown method is |
| 168 | called. |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | Locking: port->lock taken. |
| 171 | Interrupts: locally disabled. |
| 172 | This call must not sleep |
| 173 | |
| 174 | break_ctl(port,ctl) |
| 175 | Control the transmission of a break signal. If ctl is |
| 176 | nonzero, the break signal should be transmitted. The signal |
| 177 | should be terminated when another call is made with a zero |
| 178 | ctl. |
| 179 | |
Geert Uytterhoeven | fbe3128 | 2016-03-14 16:16:14 +0100 | [diff] [blame] | 180 | Locking: caller holds port->mutex |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | This call must not sleep |
| 182 | |
| 183 | startup(port) |
| 184 | Grab any interrupt resources and initialise any low level driver |
| 185 | state. Enable the port for reception. It should not activate |
| 186 | RTS nor DTR; this will be done via a separate call to set_mctrl. |
| 187 | |
Russell King | 67ab7f5 | 2006-04-15 20:46:11 +0100 | [diff] [blame] | 188 | This method will only be called when the port is initially opened. |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | Locking: port_sem taken. |
| 191 | Interrupts: globally disabled. |
| 192 | |
| 193 | shutdown(port) |
| 194 | Disable the port, disable any break condition that may be in |
| 195 | effect, and free any interrupt resources. It should not disable |
| 196 | RTS nor DTR; this will have already been done via a separate |
| 197 | call to set_mctrl. |
| 198 | |
Russell King | 67ab7f5 | 2006-04-15 20:46:11 +0100 | [diff] [blame] | 199 | Drivers must not access port->info once this call has completed. |
| 200 | |
| 201 | This method will only be called when there are no more users of |
| 202 | this port. |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | Locking: port_sem taken. |
| 205 | Interrupts: caller dependent. |
| 206 | |
Haavard Skinnemoen | 6bb0e3a | 2008-07-16 21:52:36 +0100 | [diff] [blame] | 207 | flush_buffer(port) |
| 208 | Flush any write buffers, reset any DMA state and stop any |
| 209 | ongoing DMA transfers. |
| 210 | |
| 211 | This will be called whenever the port->info->xmit circular |
| 212 | buffer is cleared. |
| 213 | |
| 214 | Locking: port->lock taken. |
| 215 | Interrupts: locally disabled. |
| 216 | This call must not sleep |
| 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | set_termios(port,termios,oldtermios) |
| 219 | Change the port parameters, including word length, parity, stop |
| 220 | bits. Update read_status_mask and ignore_status_mask to indicate |
| 221 | the types of events we are interested in receiving. Relevant |
| 222 | termios->c_cflag bits are: |
| 223 | CSIZE - word size |
| 224 | CSTOPB - 2 stop bits |
| 225 | PARENB - parity enable |
| 226 | PARODD - odd parity (when PARENB is in force) |
| 227 | CREAD - enable reception of characters (if not set, |
| 228 | still receive characters from the port, but |
| 229 | throw them away. |
| 230 | CRTSCTS - if set, enable CTS status change reporting |
| 231 | CLOCAL - if not set, enable modem status change |
| 232 | reporting. |
| 233 | Relevant termios->c_iflag bits are: |
| 234 | INPCK - enable frame and parity error events to be |
| 235 | passed to the TTY layer. |
| 236 | BRKINT |
| 237 | PARMRK - both of these enable break events to be |
| 238 | passed to the TTY layer. |
| 239 | |
| 240 | IGNPAR - ignore parity and framing errors |
| 241 | IGNBRK - ignore break errors, If IGNPAR is also |
| 242 | set, ignore overrun errors as well. |
| 243 | The interaction of the iflag bits is as follows (parity error |
| 244 | given as an example): |
| 245 | Parity error INPCK IGNPAR |
Peter Korsgaard | 89f3da3 | 2006-06-02 17:47:26 +0100 | [diff] [blame] | 246 | n/a 0 n/a character received, marked as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | TTY_NORMAL |
Peter Korsgaard | 89f3da3 | 2006-06-02 17:47:26 +0100 | [diff] [blame] | 248 | None 1 n/a character received, marked as |
| 249 | TTY_NORMAL |
| 250 | Yes 1 0 character received, marked as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | TTY_PARITY |
Peter Korsgaard | 89f3da3 | 2006-06-02 17:47:26 +0100 | [diff] [blame] | 252 | Yes 1 1 character discarded |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | Other flags may be used (eg, xon/xoff characters) if your |
| 255 | hardware supports hardware "soft" flow control. |
| 256 | |
Peter Hurley | 7c8ab96 | 2014-10-16 16:54:20 -0400 | [diff] [blame] | 257 | Locking: caller holds port->mutex |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | Interrupts: caller dependent. |
| 259 | This call must not sleep |
| 260 | |
Geert Uytterhoeven | 0adc301 | 2016-03-14 16:16:13 +0100 | [diff] [blame] | 261 | set_ldisc(port,termios) |
| 262 | Notifier for discipline change. See Documentation/serial/tty.txt. |
| 263 | |
| 264 | Locking: caller holds port->mutex |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | pm(port,state,oldstate) |
| 267 | Perform any power management related activities on the specified |
Linus Walleij | 6f538fe | 2012-12-07 11:36:08 +0100 | [diff] [blame] | 268 | port. State indicates the new state (defined by |
| 269 | enum uart_pm_state), oldstate indicates the previous state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | This function should not be used to grab any resources. |
| 272 | |
| 273 | This will be called when the port is initially opened and finally |
| 274 | closed, except when the port is also the system console. This |
| 275 | will occur even if CONFIG_PM is not set. |
| 276 | |
| 277 | Locking: none. |
| 278 | Interrupts: caller dependent. |
| 279 | |
| 280 | type(port) |
| 281 | Return a pointer to a string constant describing the specified |
| 282 | port, or return NULL, in which case the string 'unknown' is |
| 283 | substituted. |
| 284 | |
| 285 | Locking: none. |
| 286 | Interrupts: caller dependent. |
| 287 | |
| 288 | release_port(port) |
| 289 | Release any memory and IO region resources currently in use by |
| 290 | the port. |
| 291 | |
| 292 | Locking: none. |
| 293 | Interrupts: caller dependent. |
| 294 | |
| 295 | request_port(port) |
| 296 | Request any memory and IO region resources required by the port. |
| 297 | If any fail, no resources should be registered when this function |
| 298 | returns, and it should return -EBUSY on failure. |
| 299 | |
| 300 | Locking: none. |
| 301 | Interrupts: caller dependent. |
| 302 | |
| 303 | config_port(port,type) |
| 304 | Perform any autoconfiguration steps required for the port. `type` |
| 305 | contains a bit mask of the required configuration. UART_CONFIG_TYPE |
| 306 | indicates that the port requires detection and identification. |
| 307 | port->type should be set to the type found, or PORT_UNKNOWN if |
| 308 | no port was detected. |
| 309 | |
| 310 | UART_CONFIG_IRQ indicates autoconfiguration of the interrupt signal, |
| 311 | which should be probed using standard kernel autoprobing techniques. |
| 312 | This is not necessary on platforms where ports have interrupts |
| 313 | internally hard wired (eg, system on a chip implementations). |
| 314 | |
| 315 | Locking: none. |
| 316 | Interrupts: caller dependent. |
| 317 | |
| 318 | verify_port(port,serinfo) |
| 319 | Verify the new serial port information contained within serinfo is |
| 320 | suitable for this port type. |
| 321 | |
| 322 | Locking: none. |
| 323 | Interrupts: caller dependent. |
| 324 | |
| 325 | ioctl(port,cmd,arg) |
| 326 | Perform any port specific IOCTLs. IOCTL commands must be defined |
| 327 | using the standard numbering system found in <asm/ioctl.h> |
| 328 | |
| 329 | Locking: none. |
| 330 | Interrupts: caller dependent. |
| 331 | |
Kevin Cernekee | e759d7c | 2012-12-26 20:43:42 -0800 | [diff] [blame] | 332 | poll_init(port) |
| 333 | Called by kgdb to perform the minimal hardware initialization needed |
| 334 | to support poll_put_char() and poll_get_char(). Unlike ->startup() |
| 335 | this should not request interrupts. |
| 336 | |
| 337 | Locking: tty_mutex and tty_port->mutex taken. |
| 338 | Interrupts: n/a. |
| 339 | |
| 340 | poll_put_char(port,ch) |
| 341 | Called by kgdb to write a single character directly to the serial |
| 342 | port. It can and should block until there is space in the TX FIFO. |
| 343 | |
| 344 | Locking: none. |
| 345 | Interrupts: caller dependent. |
| 346 | This call must not sleep |
| 347 | |
| 348 | poll_get_char(port) |
| 349 | Called by kgdb to read a single character directly from the serial |
| 350 | port. If data is available, it should be returned; otherwise |
| 351 | the function should return NO_POLL_CHAR immediately. |
| 352 | |
| 353 | Locking: none. |
| 354 | Interrupts: caller dependent. |
| 355 | This call must not sleep |
| 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | Other functions |
| 358 | --------------- |
| 359 | |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 360 | uart_update_timeout(port,cflag,baud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | Update the FIFO drain timeout, port->timeout, according to the |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 362 | number of bits, parity, stop bits and baud rate. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
| 364 | Locking: caller is expected to take port->lock |
| 365 | Interrupts: n/a |
| 366 | |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 367 | uart_get_baud_rate(port,termios,old,min,max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | Return the numeric baud rate for the specified termios, taking |
| 369 | account of the special 38400 baud "kludge". The B0 baud rate |
| 370 | is mapped to 9600 baud. |
| 371 | |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 372 | If the baud rate is not within min..max, then if old is non-NULL, |
| 373 | the original baud rate will be tried. If that exceeds the |
| 374 | min..max constraint, 9600 baud will be returned. termios will |
| 375 | be updated to the baud rate in use. |
| 376 | |
| 377 | Note: min..max must always allow 9600 baud to be selected. |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | Locking: caller dependent. |
| 380 | Interrupts: n/a |
| 381 | |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 382 | uart_get_divisor(port,baud) |
Geert Uytterhoeven | 93a2f63 | 2016-03-14 16:16:15 +0100 | [diff] [blame^] | 383 | Return the divisor (baud_base / baud) for the specified baud |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 384 | rate, appropriately rounded. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | If 38400 baud and custom divisor is selected, return the |
| 387 | custom divisor instead. |
| 388 | |
| 389 | Locking: caller dependent. |
| 390 | Interrupts: n/a |
| 391 | |
Russell King | 6a8f8d7 | 2005-10-31 11:53:19 +0000 | [diff] [blame] | 392 | uart_match_port(port1,port2) |
| 393 | This utility function can be used to determine whether two |
| 394 | uart_port structures describe the same port. |
| 395 | |
| 396 | Locking: n/a |
| 397 | Interrupts: n/a |
| 398 | |
| 399 | uart_write_wakeup(port) |
| 400 | A driver is expected to call this function when the number of |
| 401 | characters in the transmit buffer have dropped below a threshold. |
| 402 | |
| 403 | Locking: port->lock should be held. |
| 404 | Interrupts: n/a |
| 405 | |
| 406 | uart_register_driver(drv) |
| 407 | Register a uart driver with the core driver. We in turn register |
| 408 | with the tty layer, and initialise the core driver per-port state. |
| 409 | |
| 410 | drv->port should be NULL, and the per-port structures should be |
| 411 | registered using uart_add_one_port after this call has succeeded. |
| 412 | |
| 413 | Locking: none |
| 414 | Interrupts: enabled |
| 415 | |
| 416 | uart_unregister_driver() |
| 417 | Remove all references to a driver from the core driver. The low |
| 418 | level driver must have removed all its ports via the |
| 419 | uart_remove_one_port() if it registered them with uart_add_one_port(). |
| 420 | |
| 421 | Locking: none |
| 422 | Interrupts: enabled |
| 423 | |
| 424 | uart_suspend_port() |
| 425 | |
| 426 | uart_resume_port() |
| 427 | |
| 428 | uart_add_one_port() |
| 429 | |
| 430 | uart_remove_one_port() |
| 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | Other notes |
| 433 | ----------- |
| 434 | |
| 435 | It is intended some day to drop the 'unused' entries from uart_port, and |
| 436 | allow low level drivers to register their own individual uart_port's with |
| 437 | the core. This will allow drivers to use uart_port as a pointer to a |
| 438 | structure containing both the uart_port entry with their own extensions, |
| 439 | thus: |
| 440 | |
| 441 | struct my_port { |
| 442 | struct uart_port port; |
| 443 | int my_stuff; |
| 444 | }; |
Richard Genoud | 84130aa | 2014-05-13 20:20:43 +0200 | [diff] [blame] | 445 | |
| 446 | Modem control lines via GPIO |
| 447 | ---------------------------- |
| 448 | |
| 449 | Some helpers are provided in order to set/get modem control lines via GPIO. |
| 450 | |
Uwe Kleine-König | ce59e48 | 2015-09-30 10:19:41 +0200 | [diff] [blame] | 451 | mctrl_gpio_init(port, idx): |
Richard Genoud | 84130aa | 2014-05-13 20:20:43 +0200 | [diff] [blame] | 452 | This will get the {cts,rts,...}-gpios from device tree if they are |
| 453 | present and request them, set direction etc, and return an |
| 454 | allocated structure. devm_* functions are used, so there's no need |
| 455 | to call mctrl_gpio_free(). |
Uwe Kleine-König | ce59e48 | 2015-09-30 10:19:41 +0200 | [diff] [blame] | 456 | As this sets up the irq handling make sure to not handle changes to the |
| 457 | gpio input lines in your driver, too. |
Richard Genoud | 84130aa | 2014-05-13 20:20:43 +0200 | [diff] [blame] | 458 | |
| 459 | mctrl_gpio_free(dev, gpios): |
| 460 | This will free the requested gpios in mctrl_gpio_init(). |
| 461 | As devm_* function are used, there's generally no need to call |
| 462 | this function. |
| 463 | |
| 464 | mctrl_gpio_to_gpiod(gpios, gidx) |
| 465 | This returns the gpio structure associated to the modem line index. |
| 466 | |
| 467 | mctrl_gpio_set(gpios, mctrl): |
| 468 | This will sets the gpios according to the mctrl state. |
| 469 | |
| 470 | mctrl_gpio_get(gpios, mctrl): |
| 471 | This will update mctrl with the gpios values. |
Uwe Kleine-König | ce59e48 | 2015-09-30 10:19:41 +0200 | [diff] [blame] | 472 | |
| 473 | mctrl_gpio_enable_ms(gpios): |
| 474 | Enables irqs and handling of changes to the ms lines. |
| 475 | |
| 476 | mctrl_gpio_disable_ms(gpios): |
| 477 | Disables irqs and handling of changes to the ms lines. |