xref: /linux/Documentation/driver-api/tty/index.rst (revision 5b437ae9fcbb22fe6de3c715534515209207a092)
1b96cd8b0SJiri Slaby.. SPDX-License-Identifier: GPL-2.0
2b96cd8b0SJiri Slaby
3b96cd8b0SJiri Slaby===
4b96cd8b0SJiri SlabyTTY
5b96cd8b0SJiri Slaby===
6b96cd8b0SJiri Slaby
7b96cd8b0SJiri SlabyTeletypewriter (TTY) layer takes care of all those serial devices. Including
8b96cd8b0SJiri Slabythe virtual ones like pseudoterminal (PTY).
9b96cd8b0SJiri Slaby
10b96cd8b0SJiri SlabyTTY structures
11b96cd8b0SJiri Slaby==============
12b96cd8b0SJiri Slaby
13b96cd8b0SJiri SlabyThere are several major TTY structures. Every TTY device in a system has a
14b96cd8b0SJiri Slabycorresponding struct tty_port. These devices are maintained by a TTY driver
15b96cd8b0SJiri Slabywhich is struct tty_driver. This structure describes the driver but also
16b96cd8b0SJiri Slabycontains a reference to operations which could be performed on the TTYs. It is
17b96cd8b0SJiri Slabystruct tty_operations. Then, upon open, a struct tty_struct is allocated and
18b96cd8b0SJiri Slabylives until the final close. During this time, several callbacks from struct
19b96cd8b0SJiri Slabytty_operations are invoked by the TTY layer.
20b96cd8b0SJiri Slaby
21b96cd8b0SJiri SlabyEvery character received by the kernel (both from devices and users) is passed
22b96cd8b0SJiri Slabythrough a preselected :doc:`tty_ldisc` (in
23b96cd8b0SJiri Slabyshort ldisc; in C, struct tty_ldisc_ops). Its task is to transform characters
24b96cd8b0SJiri Slabyas defined by a particular ldisc or by user too. The default one is n_tty,
25b96cd8b0SJiri Slabyimplementing echoes, signal handling, jobs control, special characters
26b96cd8b0SJiri Slabyprocessing, and more. The transformed characters are passed further to
27b96cd8b0SJiri Slabyuser/device, depending on the source.
28b96cd8b0SJiri Slaby
29b96cd8b0SJiri SlabyIn-detail description of the named TTY structures is in separate documents:
30b96cd8b0SJiri Slaby
31b96cd8b0SJiri Slaby.. toctree::
32b96cd8b0SJiri Slaby   :maxdepth: 2
33b96cd8b0SJiri Slaby
34b96cd8b0SJiri Slaby   tty_driver
35b96cd8b0SJiri Slaby   tty_port
36b96cd8b0SJiri Slaby   tty_struct
37b96cd8b0SJiri Slaby   tty_ldisc
38b96cd8b0SJiri Slaby   tty_buffer
39b96cd8b0SJiri Slaby   tty_internals
40b96cd8b0SJiri Slaby
41b96cd8b0SJiri SlabyWriting TTY Driver
42b96cd8b0SJiri Slaby==================
43b96cd8b0SJiri Slaby
44b96cd8b0SJiri SlabyBefore one starts writing a TTY driver, they must consider
45b96cd8b0SJiri Slaby:doc:`Serial <../serial/driver>` and :doc:`USB Serial <../../usb/usb-serial>`
46b96cd8b0SJiri Slabylayers first. Drivers for serial devices can often use one of these specific
47b96cd8b0SJiri Slabylayers to implement a serial driver. Only special devices should be handled
48b96cd8b0SJiri Slabydirectly by the TTY Layer. If you are about to write such a driver, read on.
49b96cd8b0SJiri Slaby
50b96cd8b0SJiri SlabyA *typical* sequence a TTY driver performs is as follows:
51b96cd8b0SJiri Slaby
52b96cd8b0SJiri Slaby#. Allocate and register a TTY driver (module init)
53b96cd8b0SJiri Slaby#. Create and register TTY devices as they are probed (probe function)
54b96cd8b0SJiri Slaby#. Handle TTY operations and events like interrupts (TTY core invokes the
55b96cd8b0SJiri Slaby   former, the device the latter)
56b96cd8b0SJiri Slaby#. Remove devices as they are going away (remove function)
57b96cd8b0SJiri Slaby#. Unregister and free the TTY driver (module exit)
58b96cd8b0SJiri Slaby
59b96cd8b0SJiri SlabySteps regarding driver, i.e. 1., 3., and 5. are described in detail in
60b96cd8b0SJiri Slaby:doc:`tty_driver`. For the other two (devices handling), look into
61b96cd8b0SJiri Slaby:doc:`tty_port`.
621a4a8f6bSJiri Slaby
631a4a8f6bSJiri SlabyOther Documentation
641a4a8f6bSJiri Slaby===================
651a4a8f6bSJiri Slaby
661a4a8f6bSJiri SlabyMiscellaneous documentation can be further found in these documents:
671a4a8f6bSJiri Slaby
681a4a8f6bSJiri Slaby.. toctree::
691a4a8f6bSJiri Slaby   :maxdepth: 2
701a4a8f6bSJiri Slaby
71*5b437ae9SJiri Slaby   moxa-smartio
72e2659503SJiri Slaby   n_gsm
731a4a8f6bSJiri Slaby   n_tty
74