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