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 393b1a696bSJiri Slaby (SUSE) tty_ioctl 40b96cd8b0SJiri Slaby tty_internals 41*cf066f93SJiri Slaby (SUSE) console 42b96cd8b0SJiri Slaby 43b96cd8b0SJiri SlabyWriting TTY Driver 44b96cd8b0SJiri Slaby================== 45b96cd8b0SJiri Slaby 46b96cd8b0SJiri SlabyBefore one starts writing a TTY driver, they must consider 47b96cd8b0SJiri Slaby:doc:`Serial <../serial/driver>` and :doc:`USB Serial <../../usb/usb-serial>` 48b96cd8b0SJiri Slabylayers first. Drivers for serial devices can often use one of these specific 49b96cd8b0SJiri Slabylayers to implement a serial driver. Only special devices should be handled 50b96cd8b0SJiri Slabydirectly by the TTY Layer. If you are about to write such a driver, read on. 51b96cd8b0SJiri Slaby 52b96cd8b0SJiri SlabyA *typical* sequence a TTY driver performs is as follows: 53b96cd8b0SJiri Slaby 54b96cd8b0SJiri Slaby#. Allocate and register a TTY driver (module init) 55b96cd8b0SJiri Slaby#. Create and register TTY devices as they are probed (probe function) 56b96cd8b0SJiri Slaby#. Handle TTY operations and events like interrupts (TTY core invokes the 57b96cd8b0SJiri Slaby former, the device the latter) 58b96cd8b0SJiri Slaby#. Remove devices as they are going away (remove function) 59b96cd8b0SJiri Slaby#. Unregister and free the TTY driver (module exit) 60b96cd8b0SJiri Slaby 61b96cd8b0SJiri SlabySteps regarding driver, i.e. 1., 3., and 5. are described in detail in 62b96cd8b0SJiri Slaby:doc:`tty_driver`. For the other two (devices handling), look into 63b96cd8b0SJiri Slaby:doc:`tty_port`. 641a4a8f6bSJiri Slaby 651a4a8f6bSJiri SlabyOther Documentation 661a4a8f6bSJiri Slaby=================== 671a4a8f6bSJiri Slaby 681a4a8f6bSJiri SlabyMiscellaneous documentation can be further found in these documents: 691a4a8f6bSJiri Slaby 701a4a8f6bSJiri Slaby.. toctree:: 711a4a8f6bSJiri Slaby :maxdepth: 2 721a4a8f6bSJiri Slaby 735b437ae9SJiri Slaby moxa-smartio 74e2659503SJiri Slaby n_gsm 751a4a8f6bSJiri Slaby n_tty 76