driver 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. Low Level Serial API
  2. --------------------
  3. $Id: driver,v 1.10 2002/07/22 15:27:30 rmk Exp $
  4. This document is meant as a brief overview of some aspects of the new serial
  5. driver. It is not complete, any questions you have should be directed to
  6. <rmk@arm.linux.org.uk>
  7. The reference implementation is contained within serial_amba.c.
  8. Low Level Serial Hardware Driver
  9. --------------------------------
  10. The low level serial hardware driver is responsible for supplying port
  11. information (defined by uart_port) and a set of control methods (defined
  12. by uart_ops) to the core serial driver. The low level driver is also
  13. responsible for handling interrupts for the port, and providing any
  14. console support.
  15. Console Support
  16. ---------------
  17. The serial core provides a few helper functions. This includes identifing
  18. the correct port structure (via uart_get_console) and decoding command line
  19. arguments (uart_parse_options).
  20. Locking
  21. -------
  22. It is the responsibility of the low level hardware driver to perform the
  23. necessary locking using port->lock. There are some exceptions (which
  24. are described in the uart_ops listing below.)
  25. There are three locks. A per-port spinlock, a per-port tmpbuf semaphore,
  26. and an overall semaphore.
  27. From the core driver perspective, the port->lock locks the following
  28. data:
  29. port->mctrl
  30. port->icount
  31. info->xmit.head (circ->head)
  32. info->xmit.tail (circ->tail)
  33. The low level driver is free to use this lock to provide any additional
  34. locking.
  35. The core driver uses the info->tmpbuf_sem lock to prevent multi-threaded
  36. access to the info->tmpbuf bouncebuffer used for port writes.
  37. The port_sem semaphore is used to protect against ports being added/
  38. removed or reconfigured at inappropriate times.
  39. uart_ops
  40. --------
  41. The uart_ops structure is the main interface between serial_core and the
  42. hardware specific driver. It contains all the methods to control the
  43. hardware.
  44. tx_empty(port)
  45. This function tests whether the transmitter fifo and shifter
  46. for the port described by 'port' is empty. If it is empty,
  47. this function should return TIOCSER_TEMT, otherwise return 0.
  48. If the port does not support this operation, then it should
  49. return TIOCSER_TEMT.
  50. Locking: none.
  51. Interrupts: caller dependent.
  52. This call must not sleep
  53. set_mctrl(port, mctrl)
  54. This function sets the modem control lines for port described
  55. by 'port' to the state described by mctrl. The relevant bits
  56. of mctrl are:
  57. - TIOCM_RTS RTS signal.
  58. - TIOCM_DTR DTR signal.
  59. - TIOCM_OUT1 OUT1 signal.
  60. - TIOCM_OUT2 OUT2 signal.
  61. If the appropriate bit is set, the signal should be driven
  62. active. If the bit is clear, the signal should be driven
  63. inactive.
  64. Locking: port->lock taken.
  65. Interrupts: locally disabled.
  66. This call must not sleep
  67. get_mctrl(port)
  68. Returns the current state of modem control inputs. The state
  69. of the outputs should not be returned, since the core keeps
  70. track of their state. The state information should include:
  71. - TIOCM_DCD state of DCD signal
  72. - TIOCM_CTS state of CTS signal
  73. - TIOCM_DSR state of DSR signal
  74. - TIOCM_RI state of RI signal
  75. The bit is set if the signal is currently driven active. If
  76. the port does not support CTS, DCD or DSR, the driver should
  77. indicate that the signal is permanently active. If RI is
  78. not available, the signal should not be indicated as active.
  79. Locking: port->lock taken.
  80. Interrupts: locally disabled.
  81. This call must not sleep
  82. stop_tx(port,tty_stop)
  83. Stop transmitting characters. This might be due to the CTS
  84. line becoming inactive or the tty layer indicating we want
  85. to stop transmission.
  86. tty_stop: 1 if this call is due to the TTY layer issuing a
  87. TTY stop to the driver (equiv to rs_stop).
  88. Locking: port->lock taken.
  89. Interrupts: locally disabled.
  90. This call must not sleep
  91. start_tx(port,tty_start)
  92. start transmitting characters. (incidentally, nonempty will
  93. always be nonzero, and shouldn't be used - it will be dropped).
  94. tty_start: 1 if this call was due to the TTY layer issuing
  95. a TTY start to the driver (equiv to rs_start)
  96. Locking: port->lock taken.
  97. Interrupts: locally disabled.
  98. This call must not sleep
  99. stop_rx(port)
  100. Stop receiving characters; the port is in the process of
  101. being closed.
  102. Locking: port->lock taken.
  103. Interrupts: locally disabled.
  104. This call must not sleep
  105. enable_ms(port)
  106. Enable the modem status interrupts.
  107. Locking: port->lock taken.
  108. Interrupts: locally disabled.
  109. This call must not sleep
  110. break_ctl(port,ctl)
  111. Control the transmission of a break signal. If ctl is
  112. nonzero, the break signal should be transmitted. The signal
  113. should be terminated when another call is made with a zero
  114. ctl.
  115. Locking: none.
  116. Interrupts: caller dependent.
  117. This call must not sleep
  118. startup(port)
  119. Grab any interrupt resources and initialise any low level driver
  120. state. Enable the port for reception. It should not activate
  121. RTS nor DTR; this will be done via a separate call to set_mctrl.
  122. Locking: port_sem taken.
  123. Interrupts: globally disabled.
  124. shutdown(port)
  125. Disable the port, disable any break condition that may be in
  126. effect, and free any interrupt resources. It should not disable
  127. RTS nor DTR; this will have already been done via a separate
  128. call to set_mctrl.
  129. Locking: port_sem taken.
  130. Interrupts: caller dependent.
  131. set_termios(port,termios,oldtermios)
  132. Change the port parameters, including word length, parity, stop
  133. bits. Update read_status_mask and ignore_status_mask to indicate
  134. the types of events we are interested in receiving. Relevant
  135. termios->c_cflag bits are:
  136. CSIZE - word size
  137. CSTOPB - 2 stop bits
  138. PARENB - parity enable
  139. PARODD - odd parity (when PARENB is in force)
  140. CREAD - enable reception of characters (if not set,
  141. still receive characters from the port, but
  142. throw them away.
  143. CRTSCTS - if set, enable CTS status change reporting
  144. CLOCAL - if not set, enable modem status change
  145. reporting.
  146. Relevant termios->c_iflag bits are:
  147. INPCK - enable frame and parity error events to be
  148. passed to the TTY layer.
  149. BRKINT
  150. PARMRK - both of these enable break events to be
  151. passed to the TTY layer.
  152. IGNPAR - ignore parity and framing errors
  153. IGNBRK - ignore break errors, If IGNPAR is also
  154. set, ignore overrun errors as well.
  155. The interaction of the iflag bits is as follows (parity error
  156. given as an example):
  157. Parity error INPCK IGNPAR
  158. None n/a n/a character received
  159. Yes n/a 0 character discarded
  160. Yes 0 1 character received, marked as
  161. TTY_NORMAL
  162. Yes 1 1 character received, marked as
  163. TTY_PARITY
  164. Other flags may be used (eg, xon/xoff characters) if your
  165. hardware supports hardware "soft" flow control.
  166. Locking: none.
  167. Interrupts: caller dependent.
  168. This call must not sleep
  169. pm(port,state,oldstate)
  170. Perform any power management related activities on the specified
  171. port. State indicates the new state (defined by ACPI D0-D3),
  172. oldstate indicates the previous state. Essentially, D0 means
  173. fully on, D3 means powered down.
  174. This function should not be used to grab any resources.
  175. This will be called when the port is initially opened and finally
  176. closed, except when the port is also the system console. This
  177. will occur even if CONFIG_PM is not set.
  178. Locking: none.
  179. Interrupts: caller dependent.
  180. type(port)
  181. Return a pointer to a string constant describing the specified
  182. port, or return NULL, in which case the string 'unknown' is
  183. substituted.
  184. Locking: none.
  185. Interrupts: caller dependent.
  186. release_port(port)
  187. Release any memory and IO region resources currently in use by
  188. the port.
  189. Locking: none.
  190. Interrupts: caller dependent.
  191. request_port(port)
  192. Request any memory and IO region resources required by the port.
  193. If any fail, no resources should be registered when this function
  194. returns, and it should return -EBUSY on failure.
  195. Locking: none.
  196. Interrupts: caller dependent.
  197. config_port(port,type)
  198. Perform any autoconfiguration steps required for the port. `type`
  199. contains a bit mask of the required configuration. UART_CONFIG_TYPE
  200. indicates that the port requires detection and identification.
  201. port->type should be set to the type found, or PORT_UNKNOWN if
  202. no port was detected.
  203. UART_CONFIG_IRQ indicates autoconfiguration of the interrupt signal,
  204. which should be probed using standard kernel autoprobing techniques.
  205. This is not necessary on platforms where ports have interrupts
  206. internally hard wired (eg, system on a chip implementations).
  207. Locking: none.
  208. Interrupts: caller dependent.
  209. verify_port(port,serinfo)
  210. Verify the new serial port information contained within serinfo is
  211. suitable for this port type.
  212. Locking: none.
  213. Interrupts: caller dependent.
  214. ioctl(port,cmd,arg)
  215. Perform any port specific IOCTLs. IOCTL commands must be defined
  216. using the standard numbering system found in <asm/ioctl.h>
  217. Locking: none.
  218. Interrupts: caller dependent.
  219. Other functions
  220. ---------------
  221. uart_update_timeout(port,cflag,quot)
  222. Update the FIFO drain timeout, port->timeout, according to the
  223. number of bits, parity, stop bits and quotient.
  224. Locking: caller is expected to take port->lock
  225. Interrupts: n/a
  226. uart_get_baud_rate(port,termios)
  227. Return the numeric baud rate for the specified termios, taking
  228. account of the special 38400 baud "kludge". The B0 baud rate
  229. is mapped to 9600 baud.
  230. Locking: caller dependent.
  231. Interrupts: n/a
  232. uart_get_divisor(port,termios,oldtermios)
  233. Return the divsor (baud_base / baud) for the selected baud rate
  234. specified by termios. If the baud rate is out of range, try
  235. the original baud rate specified by oldtermios (if non-NULL).
  236. If that fails, try 9600 baud.
  237. If 38400 baud and custom divisor is selected, return the
  238. custom divisor instead.
  239. Locking: caller dependent.
  240. Interrupts: n/a
  241. Other notes
  242. -----------
  243. It is intended some day to drop the 'unused' entries from uart_port, and
  244. allow low level drivers to register their own individual uart_port's with
  245. the core. This will allow drivers to use uart_port as a pointer to a
  246. structure containing both the uart_port entry with their own extensions,
  247. thus:
  248. struct my_port {
  249. struct uart_port port;
  250. int my_stuff;
  251. };