TTY

Teletypewriter (TTY) layer takes care of all those serial devices. Includingthe virtual ones like pseudoterminal (PTY).

TTY structures

There are several major TTY structures. Every TTY device in a system has acorrespondingstructtty_port. These devices are maintained by a TTY driverwhich isstructtty_driver. This structure describes the driver but alsocontains a reference to operations which could be performed on the TTYs. It isstructtty_operations. Then, upon open, astructtty_struct is allocated andlives until the final close. During this time, several callbacks fromstructtty_operations are invoked by the TTY layer.

Every character received by the kernel (both from devices and users) is passedthrough a preselectedTTY Line Discipline (inshort ldisc; in C,structtty_ldisc_ops). Its task is to transform charactersas defined by a particular ldisc or by user too. The default one is n_tty,implementing echoes, signal handling, jobs control, special charactersprocessing, and more. The transformed characters are passed further touser/device, depending on the source.

In-detail description of the named TTY structures is in separate documents:

Writing TTY Driver

Before one starts writing a TTY driver, they must considerSerial andUSB Seriallayers first. Drivers for serial devices can often use one of these specificlayers to implement a serial driver. Only special devices should be handleddirectly by the TTY Layer. If you are about to write such a driver, read on.

Atypical sequence a TTY driver performs is as follows:

  1. Allocate and register a TTY driver (module init)

  2. Create and register TTY devices as they are probed (probe function)

  3. Handle TTY operations and events like interrupts (TTY core invokes theformer, the device the latter)

  4. Remove devices as they are going away (remove function)

  5. Unregister and free the TTY driver (module exit)

Steps regarding driver, i.e. 1., 3., and 5. are described in detail inTTY Driver and TTY Operations. For the other two (devices handling), look intoTTY Port.

Other Documentation

Miscellaneous documentation can be further found in these documents: