index.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_ioctl
  32. tty_internals
  33. console
  34. Writing TTY Driver
  35. ==================
  36. Before one starts writing a TTY driver, they must consider
  37. :doc:`Serial <../serial/driver>` and :doc:`USB Serial <../../usb/usb-serial>`
  38. layers first. Drivers for serial devices can often use one of these specific
  39. layers to implement a serial driver. Only special devices should be handled
  40. directly by the TTY Layer. If you are about to write such a driver, read on.
  41. A *typical* sequence a TTY driver performs is as follows:
  42. #. Allocate and register a TTY driver (module init)
  43. #. Create and register TTY devices as they are probed (probe function)
  44. #. Handle TTY operations and events like interrupts (TTY core invokes the
  45. former, the device the latter)
  46. #. Remove devices as they are going away (remove function)
  47. #. Unregister and free the TTY driver (module exit)
  48. Steps regarding driver, i.e. 1., 3., and 5. are described in detail in
  49. :doc:`tty_driver`. For the other two (devices handling), look into
  50. :doc:`tty_port`.
  51. Other Documentation
  52. ===================
  53. Miscellaneous documentation can be further found in these documents:
  54. .. toctree::
  55. :maxdepth: 2
  56. moxa-smartio
  57. n_gsm
  58. n_tty