162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci=== 462306a36Sopenharmony_ciTTY 562306a36Sopenharmony_ci=== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciTeletypewriter (TTY) layer takes care of all those serial devices. Including 862306a36Sopenharmony_cithe virtual ones like pseudoterminal (PTY). 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciTTY structures 1162306a36Sopenharmony_ci============== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciThere are several major TTY structures. Every TTY device in a system has a 1462306a36Sopenharmony_cicorresponding struct tty_port. These devices are maintained by a TTY driver 1562306a36Sopenharmony_ciwhich is struct tty_driver. This structure describes the driver but also 1662306a36Sopenharmony_cicontains a reference to operations which could be performed on the TTYs. It is 1762306a36Sopenharmony_cistruct tty_operations. Then, upon open, a struct tty_struct is allocated and 1862306a36Sopenharmony_cilives until the final close. During this time, several callbacks from struct 1962306a36Sopenharmony_citty_operations are invoked by the TTY layer. 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ciEvery character received by the kernel (both from devices and users) is passed 2262306a36Sopenharmony_cithrough a preselected :doc:`tty_ldisc` (in 2362306a36Sopenharmony_cishort ldisc; in C, struct tty_ldisc_ops). Its task is to transform characters 2462306a36Sopenharmony_cias defined by a particular ldisc or by user too. The default one is n_tty, 2562306a36Sopenharmony_ciimplementing echoes, signal handling, jobs control, special characters 2662306a36Sopenharmony_ciprocessing, and more. The transformed characters are passed further to 2762306a36Sopenharmony_ciuser/device, depending on the source. 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciIn-detail description of the named TTY structures is in separate documents: 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci.. toctree:: 3262306a36Sopenharmony_ci :maxdepth: 2 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci tty_driver 3562306a36Sopenharmony_ci tty_port 3662306a36Sopenharmony_ci tty_struct 3762306a36Sopenharmony_ci tty_ldisc 3862306a36Sopenharmony_ci tty_buffer 3962306a36Sopenharmony_ci tty_internals 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciWriting TTY Driver 4262306a36Sopenharmony_ci================== 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciBefore one starts writing a TTY driver, they must consider 4562306a36Sopenharmony_ci:doc:`Serial <../serial/driver>` and :doc:`USB Serial <../../usb/usb-serial>` 4662306a36Sopenharmony_cilayers first. Drivers for serial devices can often use one of these specific 4762306a36Sopenharmony_cilayers to implement a serial driver. Only special devices should be handled 4862306a36Sopenharmony_cidirectly by the TTY Layer. If you are about to write such a driver, read on. 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ciA *typical* sequence a TTY driver performs is as follows: 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#. Allocate and register a TTY driver (module init) 5362306a36Sopenharmony_ci#. Create and register TTY devices as they are probed (probe function) 5462306a36Sopenharmony_ci#. Handle TTY operations and events like interrupts (TTY core invokes the 5562306a36Sopenharmony_ci former, the device the latter) 5662306a36Sopenharmony_ci#. Remove devices as they are going away (remove function) 5762306a36Sopenharmony_ci#. Unregister and free the TTY driver (module exit) 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ciSteps regarding driver, i.e. 1., 3., and 5. are described in detail in 6062306a36Sopenharmony_ci:doc:`tty_driver`. For the other two (devices handling), look into 6162306a36Sopenharmony_ci:doc:`tty_port`. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ciOther Documentation 6462306a36Sopenharmony_ci=================== 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciMiscellaneous documentation can be further found in these documents: 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci.. toctree:: 6962306a36Sopenharmony_ci :maxdepth: 2 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci moxa-smartio 7262306a36Sopenharmony_ci n_gsm 7362306a36Sopenharmony_ci n_tty 74