driver.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ====================
  2. Low Level Serial API
  3. ====================
  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 amba-pl011.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
  18. decoding command line arguments (uart_parse_options()).
  19. There is also a helper function (uart_console_write()) which performs a
  20. character by character write, translating newlines to CRLF sequences.
  21. Driver writers are recommended to use this function rather than implementing
  22. their own version.
  23. Locking
  24. -------
  25. It is the responsibility of the low level hardware driver to perform the
  26. necessary locking using port->lock. There are some exceptions (which
  27. are described in the struct uart_ops listing below.)
  28. There are two locks. A per-port spinlock, and an overall semaphore.
  29. From the core driver perspective, the port->lock locks the following
  30. data::
  31. port->mctrl
  32. port->icount
  33. port->state->xmit.head (circ_buf->head)
  34. port->state->xmit.tail (circ_buf->tail)
  35. The low level driver is free to use this lock to provide any additional
  36. locking.
  37. The port_sem semaphore is used to protect against ports being added/
  38. removed or reconfigured at inappropriate times. Since v2.6.27, this
  39. semaphore has been the 'mutex' member of the tty_port struct, and
  40. commonly referred to as the port mutex.
  41. uart_ops
  42. --------
  43. .. kernel-doc:: include/linux/serial_core.h
  44. :identifiers: uart_ops
  45. Other functions
  46. ---------------
  47. .. kernel-doc:: drivers/tty/serial/serial_core.c
  48. :identifiers: uart_update_timeout uart_get_baud_rate uart_get_divisor
  49. uart_match_port uart_write_wakeup uart_register_driver
  50. uart_unregister_driver uart_suspend_port uart_resume_port
  51. uart_add_one_port uart_remove_one_port uart_console_write
  52. uart_parse_earlycon uart_parse_options uart_set_options
  53. uart_get_lsr_info uart_handle_dcd_change uart_handle_cts_change
  54. uart_try_toggle_sysrq
  55. .. kernel-doc:: include/linux/serial_core.h
  56. :identifiers: uart_port_tx_limited uart_port_tx
  57. Other notes
  58. -----------
  59. It is intended some day to drop the 'unused' entries from uart_port, and
  60. allow low level drivers to register their own individual uart_port's with
  61. the core. This will allow drivers to use uart_port as a pointer to a
  62. structure containing both the uart_port entry with their own extensions,
  63. thus::
  64. struct my_port {
  65. struct uart_port port;
  66. int my_stuff;
  67. };
  68. Modem control lines via GPIO
  69. ----------------------------
  70. Some helpers are provided in order to set/get modem control lines via GPIO.
  71. .. kernel-doc:: drivers/tty/serial/serial_mctrl_gpio.c
  72. :identifiers: mctrl_gpio_init mctrl_gpio_to_gpiod
  73. mctrl_gpio_set mctrl_gpio_get mctrl_gpio_enable_ms
  74. mctrl_gpio_disable_ms_sync mctrl_gpio_disable_ms_no_sync