driver 11 KB

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