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