serial: doc: Un-document obsolete tmpbuf_sem
[deliverable/linux.git] / Documentation / serial / driver
1
2 Low Level Serial API
3 --------------------
4
5
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
10 The reference implementation is contained within amba_pl011.c.
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
39 There are two locks. A per-port spinlock, and an overall semaphore.
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
52 The port_sem semaphore is used to protect against ports being added/
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).
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.
84 - TIOCM_LOOP Set the port into loopback mode.
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:
97 - TIOCM_CAR state of DCD signal
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
106 Locking: port->lock taken.
107 Interrupts: locally disabled.
108 This call must not sleep
109
110 stop_tx(port)
111 Stop transmitting characters. This might be due to the CTS
112 line becoming inactive or the tty layer indicating we want
113 to stop transmission due to an XOFF character.
114
115 The driver should stop transmitting characters as soon as
116 possible.
117
118 Locking: port->lock taken.
119 Interrupts: locally disabled.
120 This call must not sleep
121
122 start_tx(port)
123 Start transmitting characters.
124
125 Locking: port->lock taken.
126 Interrupts: locally disabled.
127 This call must not sleep
128
129 send_xchar(port,ch)
130 Transmit a high priority character, even if the port is stopped.
131 This is used to implement XON/XOFF flow control and tcflow(). If
132 the serial driver does not implement this function, the tty core
133 will append the character to the circular buffer and then call
134 start_tx() / stop_tx() to flush the data out.
135
136 Do not transmit if ch == '\0' (__DISABLED_CHAR).
137
138 Locking: none.
139 Interrupts: caller dependent.
140
141 stop_rx(port)
142 Stop receiving characters; the port is in the process of
143 being closed.
144
145 Locking: port->lock taken.
146 Interrupts: locally disabled.
147 This call must not sleep
148
149 enable_ms(port)
150 Enable the modem status interrupts.
151
152 This method may be called multiple times. Modem status
153 interrupts should be disabled when the shutdown method is
154 called.
155
156 Locking: port->lock taken.
157 Interrupts: locally disabled.
158 This call must not sleep
159
160 break_ctl(port,ctl)
161 Control the transmission of a break signal. If ctl is
162 nonzero, the break signal should be transmitted. The signal
163 should be terminated when another call is made with a zero
164 ctl.
165
166 Locking: none.
167 Interrupts: caller dependent.
168 This call must not sleep
169
170 startup(port)
171 Grab any interrupt resources and initialise any low level driver
172 state. Enable the port for reception. It should not activate
173 RTS nor DTR; this will be done via a separate call to set_mctrl.
174
175 This method will only be called when the port is initially opened.
176
177 Locking: port_sem taken.
178 Interrupts: globally disabled.
179
180 shutdown(port)
181 Disable the port, disable any break condition that may be in
182 effect, and free any interrupt resources. It should not disable
183 RTS nor DTR; this will have already been done via a separate
184 call to set_mctrl.
185
186 Drivers must not access port->info once this call has completed.
187
188 This method will only be called when there are no more users of
189 this port.
190
191 Locking: port_sem taken.
192 Interrupts: caller dependent.
193
194 flush_buffer(port)
195 Flush any write buffers, reset any DMA state and stop any
196 ongoing DMA transfers.
197
198 This will be called whenever the port->info->xmit circular
199 buffer is cleared.
200
201 Locking: port->lock taken.
202 Interrupts: locally disabled.
203 This call must not sleep
204
205 set_termios(port,termios,oldtermios)
206 Change the port parameters, including word length, parity, stop
207 bits. Update read_status_mask and ignore_status_mask to indicate
208 the types of events we are interested in receiving. Relevant
209 termios->c_cflag bits are:
210 CSIZE - word size
211 CSTOPB - 2 stop bits
212 PARENB - parity enable
213 PARODD - odd parity (when PARENB is in force)
214 CREAD - enable reception of characters (if not set,
215 still receive characters from the port, but
216 throw them away.
217 CRTSCTS - if set, enable CTS status change reporting
218 CLOCAL - if not set, enable modem status change
219 reporting.
220 Relevant termios->c_iflag bits are:
221 INPCK - enable frame and parity error events to be
222 passed to the TTY layer.
223 BRKINT
224 PARMRK - both of these enable break events to be
225 passed to the TTY layer.
226
227 IGNPAR - ignore parity and framing errors
228 IGNBRK - ignore break errors, If IGNPAR is also
229 set, ignore overrun errors as well.
230 The interaction of the iflag bits is as follows (parity error
231 given as an example):
232 Parity error INPCK IGNPAR
233 n/a 0 n/a character received, marked as
234 TTY_NORMAL
235 None 1 n/a character received, marked as
236 TTY_NORMAL
237 Yes 1 0 character received, marked as
238 TTY_PARITY
239 Yes 1 1 character discarded
240
241 Other flags may be used (eg, xon/xoff characters) if your
242 hardware supports hardware "soft" flow control.
243
244 Locking: caller holds port->mutex
245 Interrupts: caller dependent.
246 This call must not sleep
247
248 pm(port,state,oldstate)
249 Perform any power management related activities on the specified
250 port. State indicates the new state (defined by
251 enum uart_pm_state), oldstate indicates the previous state.
252
253 This function should not be used to grab any resources.
254
255 This will be called when the port is initially opened and finally
256 closed, except when the port is also the system console. This
257 will occur even if CONFIG_PM is not set.
258
259 Locking: none.
260 Interrupts: caller dependent.
261
262 type(port)
263 Return a pointer to a string constant describing the specified
264 port, or return NULL, in which case the string 'unknown' is
265 substituted.
266
267 Locking: none.
268 Interrupts: caller dependent.
269
270 release_port(port)
271 Release any memory and IO region resources currently in use by
272 the port.
273
274 Locking: none.
275 Interrupts: caller dependent.
276
277 request_port(port)
278 Request any memory and IO region resources required by the port.
279 If any fail, no resources should be registered when this function
280 returns, and it should return -EBUSY on failure.
281
282 Locking: none.
283 Interrupts: caller dependent.
284
285 config_port(port,type)
286 Perform any autoconfiguration steps required for the port. `type`
287 contains a bit mask of the required configuration. UART_CONFIG_TYPE
288 indicates that the port requires detection and identification.
289 port->type should be set to the type found, or PORT_UNKNOWN if
290 no port was detected.
291
292 UART_CONFIG_IRQ indicates autoconfiguration of the interrupt signal,
293 which should be probed using standard kernel autoprobing techniques.
294 This is not necessary on platforms where ports have interrupts
295 internally hard wired (eg, system on a chip implementations).
296
297 Locking: none.
298 Interrupts: caller dependent.
299
300 verify_port(port,serinfo)
301 Verify the new serial port information contained within serinfo is
302 suitable for this port type.
303
304 Locking: none.
305 Interrupts: caller dependent.
306
307 ioctl(port,cmd,arg)
308 Perform any port specific IOCTLs. IOCTL commands must be defined
309 using the standard numbering system found in <asm/ioctl.h>
310
311 Locking: none.
312 Interrupts: caller dependent.
313
314 poll_init(port)
315 Called by kgdb to perform the minimal hardware initialization needed
316 to support poll_put_char() and poll_get_char(). Unlike ->startup()
317 this should not request interrupts.
318
319 Locking: tty_mutex and tty_port->mutex taken.
320 Interrupts: n/a.
321
322 poll_put_char(port,ch)
323 Called by kgdb to write a single character directly to the serial
324 port. It can and should block until there is space in the TX FIFO.
325
326 Locking: none.
327 Interrupts: caller dependent.
328 This call must not sleep
329
330 poll_get_char(port)
331 Called by kgdb to read a single character directly from the serial
332 port. If data is available, it should be returned; otherwise
333 the function should return NO_POLL_CHAR immediately.
334
335 Locking: none.
336 Interrupts: caller dependent.
337 This call must not sleep
338
339 Other functions
340 ---------------
341
342 uart_update_timeout(port,cflag,baud)
343 Update the FIFO drain timeout, port->timeout, according to the
344 number of bits, parity, stop bits and baud rate.
345
346 Locking: caller is expected to take port->lock
347 Interrupts: n/a
348
349 uart_get_baud_rate(port,termios,old,min,max)
350 Return the numeric baud rate for the specified termios, taking
351 account of the special 38400 baud "kludge". The B0 baud rate
352 is mapped to 9600 baud.
353
354 If the baud rate is not within min..max, then if old is non-NULL,
355 the original baud rate will be tried. If that exceeds the
356 min..max constraint, 9600 baud will be returned. termios will
357 be updated to the baud rate in use.
358
359 Note: min..max must always allow 9600 baud to be selected.
360
361 Locking: caller dependent.
362 Interrupts: n/a
363
364 uart_get_divisor(port,baud)
365 Return the divsor (baud_base / baud) for the specified baud
366 rate, appropriately rounded.
367
368 If 38400 baud and custom divisor is selected, return the
369 custom divisor instead.
370
371 Locking: caller dependent.
372 Interrupts: n/a
373
374 uart_match_port(port1,port2)
375 This utility function can be used to determine whether two
376 uart_port structures describe the same port.
377
378 Locking: n/a
379 Interrupts: n/a
380
381 uart_write_wakeup(port)
382 A driver is expected to call this function when the number of
383 characters in the transmit buffer have dropped below a threshold.
384
385 Locking: port->lock should be held.
386 Interrupts: n/a
387
388 uart_register_driver(drv)
389 Register a uart driver with the core driver. We in turn register
390 with the tty layer, and initialise the core driver per-port state.
391
392 drv->port should be NULL, and the per-port structures should be
393 registered using uart_add_one_port after this call has succeeded.
394
395 Locking: none
396 Interrupts: enabled
397
398 uart_unregister_driver()
399 Remove all references to a driver from the core driver. The low
400 level driver must have removed all its ports via the
401 uart_remove_one_port() if it registered them with uart_add_one_port().
402
403 Locking: none
404 Interrupts: enabled
405
406 uart_suspend_port()
407
408 uart_resume_port()
409
410 uart_add_one_port()
411
412 uart_remove_one_port()
413
414 Other notes
415 -----------
416
417 It is intended some day to drop the 'unused' entries from uart_port, and
418 allow low level drivers to register their own individual uart_port's with
419 the core. This will allow drivers to use uart_port as a pointer to a
420 structure containing both the uart_port entry with their own extensions,
421 thus:
422
423 struct my_port {
424 struct uart_port port;
425 int my_stuff;
426 };
427
428 Modem control lines via GPIO
429 ----------------------------
430
431 Some helpers are provided in order to set/get modem control lines via GPIO.
432
433 mctrl_gpio_init(port, idx):
434 This will get the {cts,rts,...}-gpios from device tree if they are
435 present and request them, set direction etc, and return an
436 allocated structure. devm_* functions are used, so there's no need
437 to call mctrl_gpio_free().
438 As this sets up the irq handling make sure to not handle changes to the
439 gpio input lines in your driver, too.
440
441 mctrl_gpio_free(dev, gpios):
442 This will free the requested gpios in mctrl_gpio_init().
443 As devm_* function are used, there's generally no need to call
444 this function.
445
446 mctrl_gpio_to_gpiod(gpios, gidx)
447 This returns the gpio structure associated to the modem line index.
448
449 mctrl_gpio_set(gpios, mctrl):
450 This will sets the gpios according to the mctrl state.
451
452 mctrl_gpio_get(gpios, mctrl):
453 This will update mctrl with the gpios values.
454
455 mctrl_gpio_enable_ms(gpios):
456 Enables irqs and handling of changes to the ms lines.
457
458 mctrl_gpio_disable_ms(gpios):
459 Disables irqs and handling of changes to the ms lines.
This page took 0.039757 seconds and 6 git commands to generate.