driver 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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)
  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 due to an XOFF character.
  86. Locking: port->lock taken.
  87. Interrupts: locally disabled.
  88. This call must not sleep
  89. start_tx(port)
  90. start transmitting characters.
  91. Locking: port->lock taken.
  92. Interrupts: locally disabled.
  93. This call must not sleep
  94. stop_rx(port)
  95. Stop receiving characters; the port is in the process of
  96. being closed.
  97. Locking: port->lock taken.
  98. Interrupts: locally disabled.
  99. This call must not sleep
  100. enable_ms(port)
  101. Enable the modem status interrupts.
  102. Locking: port->lock taken.
  103. Interrupts: locally disabled.
  104. This call must not sleep
  105. break_ctl(port,ctl)
  106. Control the transmission of a break signal. If ctl is
  107. nonzero, the break signal should be transmitted. The signal
  108. should be terminated when another call is made with a zero
  109. ctl.
  110. Locking: none.
  111. Interrupts: caller dependent.
  112. This call must not sleep
  113. startup(port)
  114. Grab any interrupt resources and initialise any low level driver
  115. state. Enable the port for reception. It should not activate
  116. RTS nor DTR; this will be done via a separate call to set_mctrl.
  117. Locking: port_sem taken.
  118. Interrupts: globally disabled.
  119. shutdown(port)
  120. Disable the port, disable any break condition that may be in
  121. effect, and free any interrupt resources. It should not disable
  122. RTS nor DTR; this will have already been done via a separate
  123. call to set_mctrl.
  124. Locking: port_sem taken.
  125. Interrupts: caller dependent.
  126. set_termios(port,termios,oldtermios)
  127. Change the port parameters, including word length, parity, stop
  128. bits. Update read_status_mask and ignore_status_mask to indicate
  129. the types of events we are interested in receiving. Relevant
  130. termios->c_cflag bits are:
  131. CSIZE - word size
  132. CSTOPB - 2 stop bits
  133. PARENB - parity enable
  134. PARODD - odd parity (when PARENB is in force)
  135. CREAD - enable reception of characters (if not set,
  136. still receive characters from the port, but
  137. throw them away.
  138. CRTSCTS - if set, enable CTS status change reporting
  139. CLOCAL - if not set, enable modem status change
  140. reporting.
  141. Relevant termios->c_iflag bits are:
  142. INPCK - enable frame and parity error events to be
  143. passed to the TTY layer.
  144. BRKINT
  145. PARMRK - both of these enable break events to be
  146. passed to the TTY layer.
  147. IGNPAR - ignore parity and framing errors
  148. IGNBRK - ignore break errors, If IGNPAR is also
  149. set, ignore overrun errors as well.
  150. The interaction of the iflag bits is as follows (parity error
  151. given as an example):
  152. Parity error INPCK IGNPAR
  153. None n/a n/a character received
  154. Yes n/a 0 character discarded
  155. Yes 0 1 character received, marked as
  156. TTY_NORMAL
  157. Yes 1 1 character received, marked as
  158. TTY_PARITY
  159. Other flags may be used (eg, xon/xoff characters) if your
  160. hardware supports hardware "soft" flow control.
  161. Locking: none.
  162. Interrupts: caller dependent.
  163. This call must not sleep
  164. pm(port,state,oldstate)
  165. Perform any power management related activities on the specified
  166. port. State indicates the new state (defined by ACPI D0-D3),
  167. oldstate indicates the previous state. Essentially, D0 means
  168. fully on, D3 means powered down.
  169. This function should not be used to grab any resources.
  170. This will be called when the port is initially opened and finally
  171. closed, except when the port is also the system console. This
  172. will occur even if CONFIG_PM is not set.
  173. Locking: none.
  174. Interrupts: caller dependent.
  175. type(port)
  176. Return a pointer to a string constant describing the specified
  177. port, or return NULL, in which case the string 'unknown' is
  178. substituted.
  179. Locking: none.
  180. Interrupts: caller dependent.
  181. release_port(port)
  182. Release any memory and IO region resources currently in use by
  183. the port.
  184. Locking: none.
  185. Interrupts: caller dependent.
  186. request_port(port)
  187. Request any memory and IO region resources required by the port.
  188. If any fail, no resources should be registered when this function
  189. returns, and it should return -EBUSY on failure.
  190. Locking: none.
  191. Interrupts: caller dependent.
  192. config_port(port,type)
  193. Perform any autoconfiguration steps required for the port. `type`
  194. contains a bit mask of the required configuration. UART_CONFIG_TYPE
  195. indicates that the port requires detection and identification.
  196. port->type should be set to the type found, or PORT_UNKNOWN if
  197. no port was detected.
  198. UART_CONFIG_IRQ indicates autoconfiguration of the interrupt signal,
  199. which should be probed using standard kernel autoprobing techniques.
  200. This is not necessary on platforms where ports have interrupts
  201. internally hard wired (eg, system on a chip implementations).
  202. Locking: none.
  203. Interrupts: caller dependent.
  204. verify_port(port,serinfo)
  205. Verify the new serial port information contained within serinfo is
  206. suitable for this port type.
  207. Locking: none.
  208. Interrupts: caller dependent.
  209. ioctl(port,cmd,arg)
  210. Perform any port specific IOCTLs. IOCTL commands must be defined
  211. using the standard numbering system found in <asm/ioctl.h>
  212. Locking: none.
  213. Interrupts: caller dependent.
  214. Other functions
  215. ---------------
  216. uart_update_timeout(port,cflag,quot)
  217. Update the FIFO drain timeout, port->timeout, according to the
  218. number of bits, parity, stop bits and quotient.
  219. Locking: caller is expected to take port->lock
  220. Interrupts: n/a
  221. uart_get_baud_rate(port,termios)
  222. Return the numeric baud rate for the specified termios, taking
  223. account of the special 38400 baud "kludge". The B0 baud rate
  224. is mapped to 9600 baud.
  225. Locking: caller dependent.
  226. Interrupts: n/a
  227. uart_get_divisor(port,termios,oldtermios)
  228. Return the divsor (baud_base / baud) for the selected baud rate
  229. specified by termios. If the baud rate is out of range, try
  230. the original baud rate specified by oldtermios (if non-NULL).
  231. If that fails, try 9600 baud.
  232. If 38400 baud and custom divisor is selected, return the
  233. custom divisor instead.
  234. Locking: caller dependent.
  235. Interrupts: n/a
  236. Other notes
  237. -----------
  238. It is intended some day to drop the 'unused' entries from uart_port, and
  239. allow low level drivers to register their own individual uart_port's with
  240. the core. This will allow drivers to use uart_port as a pointer to a
  241. structure containing both the uart_port entry with their own extensions,
  242. thus:
  243. struct my_port {
  244. struct uart_port port;
  245. int my_stuff;
  246. };