blob: 4537119bf6240bd494e2a92013a907b2ff7424b9 [file] [log] [blame]
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -03001====================
2Low Level Serial API
3====================
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006This document is meant as a brief overview of some aspects of the new serial
7driver. It is not complete, any questions you have should be directed to
8<rmk@arm.linux.org.uk>
9
Tobin C. Hardingc1a02c22018-09-13 16:23:38 +100010The reference implementation is contained within amba-pl011.c.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12
13
14Low Level Serial Hardware Driver
15--------------------------------
16
17The low level serial hardware driver is responsible for supplying port
18information (defined by uart_port) and a set of control methods (defined
19by uart_ops) to the core serial driver. The low level driver is also
20responsible for handling interrupts for the port, and providing any
21console support.
22
23
24Console Support
25---------------
26
27The serial core provides a few helper functions. This includes identifing
28the correct port structure (via uart_get_console) and decoding command line
29arguments (uart_parse_options).
30
Geert Uytterhoevend124fd32016-04-14 11:08:08 +020031There is also a helper function (uart_console_write) which performs a
32character by character write, translating newlines to CRLF sequences.
33Driver writers are recommended to use this function rather than implementing
34their own version.
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37Locking
38-------
39
40It is the responsibility of the low level hardware driver to perform the
41necessary locking using port->lock. There are some exceptions (which
42are described in the uart_ops listing below.)
43
Geert Uytterhoeven4895b1d2016-03-14 16:16:10 +010044There are two locks. A per-port spinlock, and an overall semaphore.
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46From the core driver perspective, the port->lock locks the following
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -030047data::
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 port->mctrl
50 port->icount
Geert Uytterhoevenb79ef072016-05-11 13:56:05 +020051 port->state->xmit.head (circ_buf->head)
52 port->state->xmit.tail (circ_buf->tail)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54The low level driver is free to use this lock to provide any additional
55locking.
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057The port_sem semaphore is used to protect against ports being added/
Peter Hurley7c8ab962014-10-16 16:54:20 -040058removed or reconfigured at inappropriate times. Since v2.6.27, this
59semaphore has been the 'mutex' member of the tty_port struct, and
Geert Uytterhoeven95f981f2016-05-11 13:56:04 +020060commonly referred to as the port mutex.
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62
63uart_ops
64--------
65
66The uart_ops structure is the main interface between serial_core and the
67hardware specific driver. It contains all the methods to control the
68hardware.
69
70 tx_empty(port)
71 This function tests whether the transmitter fifo and shifter
72 for the port described by 'port' is empty. If it is empty,
73 this function should return TIOCSER_TEMT, otherwise return 0.
74 If the port does not support this operation, then it should
75 return TIOCSER_TEMT.
76
77 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -030078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 Interrupts: caller dependent.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -030080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 This call must not sleep
82
83 set_mctrl(port, mctrl)
84 This function sets the modem control lines for port described
85 by 'port' to the state described by mctrl. The relevant bits
86 of mctrl are:
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -030087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 - TIOCM_RTS RTS signal.
89 - TIOCM_DTR DTR signal.
90 - TIOCM_OUT1 OUT1 signal.
91 - TIOCM_OUT2 OUT2 signal.
Russell King67ab7f52006-04-15 20:46:11 +010092 - TIOCM_LOOP Set the port into loopback mode.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -030093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 If the appropriate bit is set, the signal should be driven
95 active. If the bit is clear, the signal should be driven
96 inactive.
97
98 Locking: port->lock taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -030099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 Interrupts: locally disabled.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 This call must not sleep
103
104 get_mctrl(port)
105 Returns the current state of modem control inputs. The state
106 of the outputs should not be returned, since the core keeps
107 track of their state. The state information should include:
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300108
Uwe Kleine-König343fe402012-01-04 15:27:32 -0800109 - TIOCM_CAR state of DCD signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 - TIOCM_CTS state of CTS signal
111 - TIOCM_DSR state of DSR signal
112 - TIOCM_RI state of RI signal
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 The bit is set if the signal is currently driven active. If
115 the port does not support CTS, DCD or DSR, the driver should
116 indicate that the signal is permanently active. If RI is
117 not available, the signal should not be indicated as active.
118
Russell Kingc5f46442005-06-29 09:42:38 +0100119 Locking: port->lock taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300120
Russell Kingc5f46442005-06-29 09:42:38 +0100121 Interrupts: locally disabled.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 This call must not sleep
124
Russell Kingb129a8c2005-08-31 10:12:14 +0100125 stop_tx(port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 Stop transmitting characters. This might be due to the CTS
127 line becoming inactive or the tty layer indicating we want
Russell Kingb129a8c2005-08-31 10:12:14 +0100128 to stop transmission due to an XOFF character.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Russell King6a8f8d72005-10-31 11:53:19 +0000130 The driver should stop transmitting characters as soon as
131 possible.
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 Locking: port->lock taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 Interrupts: locally disabled.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 This call must not sleep
138
Russell Kingb129a8c2005-08-31 10:12:14 +0100139 start_tx(port)
Russell King6a8f8d72005-10-31 11:53:19 +0000140 Start transmitting characters.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 Locking: port->lock taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 Interrupts: locally disabled.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 This call must not sleep
147
Geert Uytterhoeven39c51442016-03-14 16:16:11 +0100148 throttle(port)
149 Notify the serial driver that input buffers for the line discipline are
150 close to full, and it should somehow signal that no more characters
151 should be sent to the serial port.
Geert Uytterhoevena3bedc32016-04-14 11:08:09 +0200152 This will be called only if hardware assisted flow control is enabled.
Geert Uytterhoeven39c51442016-03-14 16:16:11 +0100153
Geert Uytterhoeven18717b02016-04-14 11:08:10 +0200154 Locking: serialized with .unthrottle() and termios modification by the
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300155 tty layer.
Geert Uytterhoeven39c51442016-03-14 16:16:11 +0100156
Geert Uytterhoevene27585c72016-03-14 16:16:12 +0100157 unthrottle(port)
158 Notify the serial driver that characters can now be sent to the serial
159 port without fear of overrunning the input buffers of the line
160 disciplines.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300161
Geert Uytterhoevena3bedc32016-04-14 11:08:09 +0200162 This will be called only if hardware assisted flow control is enabled.
Geert Uytterhoevene27585c72016-03-14 16:16:12 +0100163
Geert Uytterhoeven18717b02016-04-14 11:08:10 +0200164 Locking: serialized with .throttle() and termios modification by the
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300165 tty layer.
Geert Uytterhoevene27585c72016-03-14 16:16:12 +0100166
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800167 send_xchar(port,ch)
168 Transmit a high priority character, even if the port is stopped.
169 This is used to implement XON/XOFF flow control and tcflow(). If
170 the serial driver does not implement this function, the tty core
171 will append the character to the circular buffer and then call
172 start_tx() / stop_tx() to flush the data out.
173
Peter Hurleydb106df2014-09-02 17:39:15 -0400174 Do not transmit if ch == '\0' (__DISABLED_CHAR).
175
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800176 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300177
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800178 Interrupts: caller dependent.
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 stop_rx(port)
181 Stop receiving characters; the port is in the process of
182 being closed.
183
184 Locking: port->lock taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 Interrupts: locally disabled.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 This call must not sleep
189
190 enable_ms(port)
191 Enable the modem status interrupts.
192
Russell King67ab7f52006-04-15 20:46:11 +0100193 This method may be called multiple times. Modem status
194 interrupts should be disabled when the shutdown method is
195 called.
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 Locking: port->lock taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 Interrupts: locally disabled.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 This call must not sleep
202
203 break_ctl(port,ctl)
204 Control the transmission of a break signal. If ctl is
205 nonzero, the break signal should be transmitted. The signal
206 should be terminated when another call is made with a zero
207 ctl.
208
Geert Uytterhoeven95f981f2016-05-11 13:56:04 +0200209 Locking: caller holds tty_port->mutex
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 startup(port)
212 Grab any interrupt resources and initialise any low level driver
213 state. Enable the port for reception. It should not activate
214 RTS nor DTR; this will be done via a separate call to set_mctrl.
215
Russell King67ab7f52006-04-15 20:46:11 +0100216 This method will only be called when the port is initially opened.
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 Locking: port_sem taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 Interrupts: globally disabled.
221
222 shutdown(port)
223 Disable the port, disable any break condition that may be in
224 effect, and free any interrupt resources. It should not disable
225 RTS nor DTR; this will have already been done via a separate
226 call to set_mctrl.
227
Geert Uytterhoevenb79ef072016-05-11 13:56:05 +0200228 Drivers must not access port->state once this call has completed.
Russell King67ab7f52006-04-15 20:46:11 +0100229
230 This method will only be called when there are no more users of
231 this port.
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 Locking: port_sem taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 Interrupts: caller dependent.
236
Haavard Skinnemoen6bb0e3a2008-07-16 21:52:36 +0100237 flush_buffer(port)
238 Flush any write buffers, reset any DMA state and stop any
239 ongoing DMA transfers.
240
Geert Uytterhoevenb79ef072016-05-11 13:56:05 +0200241 This will be called whenever the port->state->xmit circular
Haavard Skinnemoen6bb0e3a2008-07-16 21:52:36 +0100242 buffer is cleared.
243
244 Locking: port->lock taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300245
Haavard Skinnemoen6bb0e3a2008-07-16 21:52:36 +0100246 Interrupts: locally disabled.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300247
Haavard Skinnemoen6bb0e3a2008-07-16 21:52:36 +0100248 This call must not sleep
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 set_termios(port,termios,oldtermios)
251 Change the port parameters, including word length, parity, stop
252 bits. Update read_status_mask and ignore_status_mask to indicate
253 the types of events we are interested in receiving. Relevant
254 termios->c_cflag bits are:
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300255
256 CSIZE
257 - word size
258 CSTOPB
259 - 2 stop bits
260 PARENB
261 - parity enable
262 PARODD
263 - odd parity (when PARENB is in force)
264 CREAD
265 - enable reception of characters (if not set,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 still receive characters from the port, but
267 throw them away.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300268 CRTSCTS
269 - if set, enable CTS status change reporting
270 CLOCAL
271 - if not set, enable modem status change
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 reporting.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 Relevant termios->c_iflag bits are:
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300275
276 INPCK
277 - enable frame and parity error events to be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 passed to the TTY layer.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300279 BRKINT / PARMRK
280 - both of these enable break events to be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 passed to the TTY layer.
282
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300283 IGNPAR
284 - ignore parity and framing errors
285 IGNBRK
286 - ignore break errors, If IGNPAR is also
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 set, ignore overrun errors as well.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 The interaction of the iflag bits is as follows (parity error
290 given as an example):
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300291
292 =============== ======= ====== =============================
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 Parity error INPCK IGNPAR
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300294 =============== ======= ====== =============================
Peter Korsgaard89f3da32006-06-02 17:47:26 +0100295 n/a 0 n/a character received, marked as
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 TTY_NORMAL
Peter Korsgaard89f3da32006-06-02 17:47:26 +0100297 None 1 n/a character received, marked as
298 TTY_NORMAL
299 Yes 1 0 character received, marked as
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 TTY_PARITY
Peter Korsgaard89f3da32006-06-02 17:47:26 +0100301 Yes 1 1 character discarded
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300302 =============== ======= ====== =============================
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 Other flags may be used (eg, xon/xoff characters) if your
305 hardware supports hardware "soft" flow control.
306
Geert Uytterhoeven95f981f2016-05-11 13:56:04 +0200307 Locking: caller holds tty_port->mutex
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 Interrupts: caller dependent.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 This call must not sleep
312
Geert Uytterhoeven0adc3012016-03-14 16:16:13 +0100313 set_ldisc(port,termios)
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300314 Notifier for discipline change. See Documentation/serial/tty.rst.
Geert Uytterhoeven0adc3012016-03-14 16:16:13 +0100315
Geert Uytterhoeven95f981f2016-05-11 13:56:04 +0200316 Locking: caller holds tty_port->mutex
Geert Uytterhoeven0adc3012016-03-14 16:16:13 +0100317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 pm(port,state,oldstate)
319 Perform any power management related activities on the specified
Linus Walleij6f538fe2012-12-07 11:36:08 +0100320 port. State indicates the new state (defined by
321 enum uart_pm_state), oldstate indicates the previous state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 This function should not be used to grab any resources.
324
325 This will be called when the port is initially opened and finally
326 closed, except when the port is also the system console. This
327 will occur even if CONFIG_PM is not set.
328
329 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 Interrupts: caller dependent.
332
333 type(port)
334 Return a pointer to a string constant describing the specified
335 port, or return NULL, in which case the string 'unknown' is
336 substituted.
337
338 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 Interrupts: caller dependent.
341
342 release_port(port)
343 Release any memory and IO region resources currently in use by
344 the port.
345
346 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 Interrupts: caller dependent.
349
350 request_port(port)
351 Request any memory and IO region resources required by the port.
352 If any fail, no resources should be registered when this function
353 returns, and it should return -EBUSY on failure.
354
355 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 Interrupts: caller dependent.
358
359 config_port(port,type)
360 Perform any autoconfiguration steps required for the port. `type`
361 contains a bit mask of the required configuration. UART_CONFIG_TYPE
362 indicates that the port requires detection and identification.
363 port->type should be set to the type found, or PORT_UNKNOWN if
364 no port was detected.
365
366 UART_CONFIG_IRQ indicates autoconfiguration of the interrupt signal,
367 which should be probed using standard kernel autoprobing techniques.
368 This is not necessary on platforms where ports have interrupts
369 internally hard wired (eg, system on a chip implementations).
370
371 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 Interrupts: caller dependent.
374
375 verify_port(port,serinfo)
376 Verify the new serial port information contained within serinfo is
377 suitable for this port type.
378
379 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 Interrupts: caller dependent.
382
383 ioctl(port,cmd,arg)
384 Perform any port specific IOCTLs. IOCTL commands must be defined
385 using the standard numbering system found in <asm/ioctl.h>
386
387 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 Interrupts: caller dependent.
390
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800391 poll_init(port)
392 Called by kgdb to perform the minimal hardware initialization needed
393 to support poll_put_char() and poll_get_char(). Unlike ->startup()
394 this should not request interrupts.
395
396 Locking: tty_mutex and tty_port->mutex taken.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300397
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800398 Interrupts: n/a.
399
400 poll_put_char(port,ch)
401 Called by kgdb to write a single character directly to the serial
402 port. It can and should block until there is space in the TX FIFO.
403
404 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300405
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800406 Interrupts: caller dependent.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300407
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800408 This call must not sleep
409
410 poll_get_char(port)
411 Called by kgdb to read a single character directly from the serial
412 port. If data is available, it should be returned; otherwise
413 the function should return NO_POLL_CHAR immediately.
414
415 Locking: none.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300416
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800417 Interrupts: caller dependent.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300418
Kevin Cernekeee759d7c2012-12-26 20:43:42 -0800419 This call must not sleep
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421Other functions
422---------------
423
Russell King6a8f8d72005-10-31 11:53:19 +0000424uart_update_timeout(port,cflag,baud)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 Update the FIFO drain timeout, port->timeout, according to the
Russell King6a8f8d72005-10-31 11:53:19 +0000426 number of bits, parity, stop bits and baud rate.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 Locking: caller is expected to take port->lock
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 Interrupts: n/a
431
Russell King6a8f8d72005-10-31 11:53:19 +0000432uart_get_baud_rate(port,termios,old,min,max)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 Return the numeric baud rate for the specified termios, taking
434 account of the special 38400 baud "kludge". The B0 baud rate
435 is mapped to 9600 baud.
436
Russell King6a8f8d72005-10-31 11:53:19 +0000437 If the baud rate is not within min..max, then if old is non-NULL,
438 the original baud rate will be tried. If that exceeds the
439 min..max constraint, 9600 baud will be returned. termios will
440 be updated to the baud rate in use.
441
442 Note: min..max must always allow 9600 baud to be selected.
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 Locking: caller dependent.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 Interrupts: n/a
447
Russell King6a8f8d72005-10-31 11:53:19 +0000448uart_get_divisor(port,baud)
Geert Uytterhoeven93a2f632016-03-14 16:16:15 +0100449 Return the divisor (baud_base / baud) for the specified baud
Russell King6a8f8d72005-10-31 11:53:19 +0000450 rate, appropriately rounded.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 If 38400 baud and custom divisor is selected, return the
453 custom divisor instead.
454
455 Locking: caller dependent.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 Interrupts: n/a
458
Russell King6a8f8d72005-10-31 11:53:19 +0000459uart_match_port(port1,port2)
460 This utility function can be used to determine whether two
461 uart_port structures describe the same port.
462
463 Locking: n/a
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300464
Russell King6a8f8d72005-10-31 11:53:19 +0000465 Interrupts: n/a
466
467uart_write_wakeup(port)
468 A driver is expected to call this function when the number of
469 characters in the transmit buffer have dropped below a threshold.
470
471 Locking: port->lock should be held.
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300472
Russell King6a8f8d72005-10-31 11:53:19 +0000473 Interrupts: n/a
474
475uart_register_driver(drv)
476 Register a uart driver with the core driver. We in turn register
477 with the tty layer, and initialise the core driver per-port state.
478
479 drv->port should be NULL, and the per-port structures should be
480 registered using uart_add_one_port after this call has succeeded.
481
482 Locking: none
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300483
Russell King6a8f8d72005-10-31 11:53:19 +0000484 Interrupts: enabled
485
486uart_unregister_driver()
487 Remove all references to a driver from the core driver. The low
488 level driver must have removed all its ports via the
489 uart_remove_one_port() if it registered them with uart_add_one_port().
490
491 Locking: none
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300492
Russell King6a8f8d72005-10-31 11:53:19 +0000493 Interrupts: enabled
494
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300495**uart_suspend_port()**
Russell King6a8f8d72005-10-31 11:53:19 +0000496
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300497**uart_resume_port()**
Russell King6a8f8d72005-10-31 11:53:19 +0000498
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300499**uart_add_one_port()**
Russell King6a8f8d72005-10-31 11:53:19 +0000500
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300501**uart_remove_one_port()**
Russell King6a8f8d72005-10-31 11:53:19 +0000502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503Other notes
504-----------
505
506It is intended some day to drop the 'unused' entries from uart_port, and
507allow low level drivers to register their own individual uart_port's with
508the core. This will allow drivers to use uart_port as a pointer to a
509structure containing both the uart_port entry with their own extensions,
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300510thus::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 struct my_port {
513 struct uart_port port;
514 int my_stuff;
515 };
Richard Genoud84130aa2014-05-13 20:20:43 +0200516
517Modem control lines via GPIO
518----------------------------
519
520Some helpers are provided in order to set/get modem control lines via GPIO.
521
Uwe Kleine-Königce59e482015-09-30 10:19:41 +0200522mctrl_gpio_init(port, idx):
Richard Genoud84130aa2014-05-13 20:20:43 +0200523 This will get the {cts,rts,...}-gpios from device tree if they are
524 present and request them, set direction etc, and return an
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300525 allocated structure. `devm_*` functions are used, so there's no need
Richard Genoud84130aa2014-05-13 20:20:43 +0200526 to call mctrl_gpio_free().
Uwe Kleine-Königce59e482015-09-30 10:19:41 +0200527 As this sets up the irq handling make sure to not handle changes to the
528 gpio input lines in your driver, too.
Richard Genoud84130aa2014-05-13 20:20:43 +0200529
530mctrl_gpio_free(dev, gpios):
531 This will free the requested gpios in mctrl_gpio_init().
Mauro Carvalho Chehabf1374012019-04-22 10:27:22 -0300532 As `devm_*` functions are used, there's generally no need to call
Richard Genoud84130aa2014-05-13 20:20:43 +0200533 this function.
534
535mctrl_gpio_to_gpiod(gpios, gidx)
Geert Uytterhoeven4817ebb12016-03-14 16:16:17 +0100536 This returns the gpio_desc structure associated to the modem line
537 index.
Richard Genoud84130aa2014-05-13 20:20:43 +0200538
539mctrl_gpio_set(gpios, mctrl):
540 This will sets the gpios according to the mctrl state.
541
542mctrl_gpio_get(gpios, mctrl):
543 This will update mctrl with the gpios values.
Uwe Kleine-Königce59e482015-09-30 10:19:41 +0200544
545mctrl_gpio_enable_ms(gpios):
546 Enables irqs and handling of changes to the ms lines.
547
548mctrl_gpio_disable_ms(gpios):
549 Disables irqs and handling of changes to the ms lines.