]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - Documentation/serial/driver
serial: doc: Spelling s/divsor/divisor/
[mirror_ubuntu-artful-kernel.git] / Documentation / serial / driver
CommitLineData
1da177e4
LT
1
2 Low Level Serial API
3 --------------------
4
5
1da177e4
LT
6This 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
67ab7f59 10The reference implementation is contained within amba_pl011.c.
1da177e4
LT
11
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
31
32Locking
33-------
34
35It is the responsibility of the low level hardware driver to perform the
36necessary locking using port->lock. There are some exceptions (which
37are described in the uart_ops listing below.)
38
4895b1d7 39There are two locks. A per-port spinlock, and an overall semaphore.
1da177e4
LT
40
41From the core driver perspective, the port->lock locks the following
42data:
43
44 port->mctrl
45 port->icount
46 info->xmit.head (circ->head)
47 info->xmit.tail (circ->tail)
48
49The low level driver is free to use this lock to provide any additional
50locking.
51
1da177e4 52The port_sem semaphore is used to protect against ports being added/
7c8ab967
PH
53removed or reconfigured at inappropriate times. Since v2.6.27, this
54semaphore has been the 'mutex' member of the tty_port struct, and
55commonly referred to as the port mutex (or port->mutex).
1da177e4
LT
56
57
58uart_ops
59--------
60
61The uart_ops structure is the main interface between serial_core and the
62hardware specific driver. It contains all the methods to control the
63hardware.
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.
67ab7f59 84 - TIOCM_LOOP Set the port into loopback mode.
1da177e4
LT
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:
343fe407 97 - TIOCM_CAR state of DCD signal
1da177e4
LT
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
c5f4644e
RK
106 Locking: port->lock taken.
107 Interrupts: locally disabled.
1da177e4
LT
108 This call must not sleep
109
b129a8cc 110 stop_tx(port)
1da177e4
LT
111 Stop transmitting characters. This might be due to the CTS
112 line becoming inactive or the tty layer indicating we want
b129a8cc 113 to stop transmission due to an XOFF character.
1da177e4 114
6a8f8d72
RK
115 The driver should stop transmitting characters as soon as
116 possible.
117
1da177e4
LT
118 Locking: port->lock taken.
119 Interrupts: locally disabled.
120 This call must not sleep
121
b129a8cc 122 start_tx(port)
6a8f8d72 123 Start transmitting characters.
1da177e4
LT
124
125 Locking: port->lock taken.
126 Interrupts: locally disabled.
127 This call must not sleep
128
39c5144e
GU
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
e27585c7
GU
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
e759d7c5
KC
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
db106df3
PH
150 Do not transmit if ch == '\0' (__DISABLED_CHAR).
151
e759d7c5
KC
152 Locking: none.
153 Interrupts: caller dependent.
154
1da177e4
LT
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
67ab7f59
RK
166 This method may be called multiple times. Modem status
167 interrupts should be disabled when the shutdown method is
168 called.
169
1da177e4
LT
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
fbe3128b 180 Locking: caller holds port->mutex
1da177e4
LT
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
67ab7f59
RK
188 This method will only be called when the port is initially opened.
189
1da177e4
LT
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
67ab7f59
RK
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
1da177e4
LT
204 Locking: port_sem taken.
205 Interrupts: caller dependent.
206
6bb0e3a5
HS
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
1da177e4
LT
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
89f3da3e 246 n/a 0 n/a character received, marked as
1da177e4 247 TTY_NORMAL
89f3da3e
PK
248 None 1 n/a character received, marked as
249 TTY_NORMAL
250 Yes 1 0 character received, marked as
1da177e4 251 TTY_PARITY
89f3da3e 252 Yes 1 1 character discarded
1da177e4
LT
253
254 Other flags may be used (eg, xon/xoff characters) if your
255 hardware supports hardware "soft" flow control.
256
7c8ab967 257 Locking: caller holds port->mutex
1da177e4
LT
258 Interrupts: caller dependent.
259 This call must not sleep
260
0adc301e
GU
261 set_ldisc(port,termios)
262 Notifier for discipline change. See Documentation/serial/tty.txt.
263
264 Locking: caller holds port->mutex
265
1da177e4
LT
266 pm(port,state,oldstate)
267 Perform any power management related activities on the specified
6f538fe3
LW
268 port. State indicates the new state (defined by
269 enum uart_pm_state), oldstate indicates the previous state.
1da177e4
LT
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
e759d7c5
KC
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
1da177e4
LT
357Other functions
358---------------
359
6a8f8d72 360uart_update_timeout(port,cflag,baud)
1da177e4 361 Update the FIFO drain timeout, port->timeout, according to the
6a8f8d72 362 number of bits, parity, stop bits and baud rate.
1da177e4
LT
363
364 Locking: caller is expected to take port->lock
365 Interrupts: n/a
366
6a8f8d72 367uart_get_baud_rate(port,termios,old,min,max)
1da177e4
LT
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
6a8f8d72
RK
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
1da177e4
LT
379 Locking: caller dependent.
380 Interrupts: n/a
381
6a8f8d72 382uart_get_divisor(port,baud)
93a2f632 383 Return the divisor (baud_base / baud) for the specified baud
6a8f8d72 384 rate, appropriately rounded.
1da177e4
LT
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
6a8f8d72
RK
392uart_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
399uart_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
406uart_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
416uart_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
424uart_suspend_port()
425
426uart_resume_port()
427
428uart_add_one_port()
429
430uart_remove_one_port()
431
1da177e4
LT
432Other notes
433-----------
434
435It is intended some day to drop the 'unused' entries from uart_port, and
436allow low level drivers to register their own individual uart_port's with
437the core. This will allow drivers to use uart_port as a pointer to a
438structure containing both the uart_port entry with their own extensions,
439thus:
440
441 struct my_port {
442 struct uart_port port;
443 int my_stuff;
444 };
84130aac
RG
445
446Modem control lines via GPIO
447----------------------------
448
449Some helpers are provided in order to set/get modem control lines via GPIO.
450
ce59e48f 451mctrl_gpio_init(port, idx):
84130aac
RG
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().
ce59e48f
UKK
456 As this sets up the irq handling make sure to not handle changes to the
457 gpio input lines in your driver, too.
84130aac
RG
458
459mctrl_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
464mctrl_gpio_to_gpiod(gpios, gidx)
465 This returns the gpio structure associated to the modem line index.
466
467mctrl_gpio_set(gpios, mctrl):
468 This will sets the gpios according to the mctrl state.
469
470mctrl_gpio_get(gpios, mctrl):
471 This will update mctrl with the gpios values.
ce59e48f
UKK
472
473mctrl_gpio_enable_ms(gpios):
474 Enables irqs and handling of changes to the ms lines.
475
476mctrl_gpio_disable_ms(gpios):
477 Disables irqs and handling of changes to the ms lines.