index.rst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===
  3. TTY
  4. ===
  5. Teletypewriter (TTY) layer takes care of all those serial devices. Including
  6. the virtual ones like pseudoterminal (PTY).
  7. TTY structures
  8. ==============
  9. There are several major TTY structures. Every TTY device in a system has a
  10. corresponding struct tty_port. These devices are maintained by a TTY driver
  11. which is struct tty_driver. This structure describes the driver but also
  12. contains a reference to operations which could be performed on the TTYs. It is
  13. struct tty_operations. Then, upon open, a struct tty_struct is allocated and
  14. lives until the final close. During this time, several callbacks from struct
  15. tty_operations are invoked by the TTY layer.
  16. Every character received by the kernel (both from devices and users) is passed
  17. through a preselected :doc:`tty_ldisc` (in
  18. short ldisc; in C, struct tty_ldisc_ops). Its task is to transform characters
  19. as defined by a particular ldisc or by user too. The default one is n_tty,
  20. implementing echoes, signal handling, jobs control, special characters
  21. processing, and more. The transformed characters are passed further to
  22. user/device, depending on the source.
  23. In-detail description of the named TTY structures is in separate documents:
  24. .. toctree::
  25. :maxdepth: 2
  26. tty_driver
  27. tty_port
  28. tty_struct
  29. tty_ldisc
  30. tty_buffer
  31. tty_internals
  32. Writing TTY Driver
  33. ==================
  34. Before one starts writing a TTY driver, they must consider
  35. :doc:`Serial <../serial/driver>` and :doc:`USB Serial <../../usb/usb-serial>`
  36. layers first. Drivers for serial devices can often use one of these specific
  37. layers to implement a serial driver. Only special devices should be handled
  38. directly by the TTY Layer. If you are about to write such a driver, read on.
  39. A *typical* sequence a TTY driver performs is as follows:
  40. #. Allocate and register a TTY driver (module init)
  41. #. Create and register TTY devices as they are probed (probe function)
  42. #. Handle TTY operations and events like interrupts (TTY core invokes the
  43. former, the device the latter)
  44. #. Remove devices as they are going away (remove function)
  45. #. Unregister and free the TTY driver (module exit)
  46. Steps regarding driver, i.e. 1., 3., and 5. are described in detail in
  47. :doc:`tty_driver`. For the other two (devices handling), look into
  48. :doc:`tty_port`.
  49. Other Documentation
  50. ===================
  51. Miscellaneous documentation can be further found in these documents:
  52. .. toctree::
  53. :maxdepth: 2
  54. moxa-smartio
  55. n_gsm
  56. n_tty