0001 .. SPDX-License-Identifier: GPL-2.0
0002
0003 ===
0004 TTY
0005 ===
0006
0007 Teletypewriter (TTY) layer takes care of all those serial devices. Including
0008 the virtual ones like pseudoterminal (PTY).
0009
0010 TTY structures
0011 ==============
0012
0013 There are several major TTY structures. Every TTY device in a system has a
0014 corresponding struct tty_port. These devices are maintained by a TTY driver
0015 which is struct tty_driver. This structure describes the driver but also
0016 contains a reference to operations which could be performed on the TTYs. It is
0017 struct tty_operations. Then, upon open, a struct tty_struct is allocated and
0018 lives until the final close. During this time, several callbacks from struct
0019 tty_operations are invoked by the TTY layer.
0020
0021 Every character received by the kernel (both from devices and users) is passed
0022 through a preselected :doc:`tty_ldisc` (in
0023 short ldisc; in C, struct tty_ldisc_ops). Its task is to transform characters
0024 as defined by a particular ldisc or by user too. The default one is n_tty,
0025 implementing echoes, signal handling, jobs control, special characters
0026 processing, and more. The transformed characters are passed further to
0027 user/device, depending on the source.
0028
0029 In-detail description of the named TTY structures is in separate documents:
0030
0031 .. toctree::
0032 :maxdepth: 2
0033
0034 tty_driver
0035 tty_port
0036 tty_struct
0037 tty_ldisc
0038 tty_buffer
0039 tty_internals
0040
0041 Writing TTY Driver
0042 ==================
0043
0044 Before one starts writing a TTY driver, they must consider
0045 :doc:`Serial <../serial/driver>` and :doc:`USB Serial <../../usb/usb-serial>`
0046 layers first. Drivers for serial devices can often use one of these specific
0047 layers to implement a serial driver. Only special devices should be handled
0048 directly by the TTY Layer. If you are about to write such a driver, read on.
0049
0050 A *typical* sequence a TTY driver performs is as follows:
0051
0052 #. Allocate and register a TTY driver (module init)
0053 #. Create and register TTY devices as they are probed (probe function)
0054 #. Handle TTY operations and events like interrupts (TTY core invokes the
0055 former, the device the latter)
0056 #. Remove devices as they are going away (remove function)
0057 #. Unregister and free the TTY driver (module exit)
0058
0059 Steps regarding driver, i.e. 1., 3., and 5. are described in detail in
0060 :doc:`tty_driver`. For the other two (devices handling), look into
0061 :doc:`tty_port`.
0062
0063 Other Documentation
0064 ===================
0065
0066 Miscellaneous documentation can be further found in these documents:
0067
0068 .. toctree::
0069 :maxdepth: 2
0070
0071 moxa-smartio
0072 n_gsm
0073 n_tty