Introduction to Linux Device Drivers Class 3: Serial Drivers using Linux Aug 6, 2014 Khem Raj
Introduction Serial port is commonly used communication channel Implemented using UART On PCs UART is part of SuperIO chipset Kernel Drivers for serial devices are generic
Introduction Serial subsystem is use when Terminal session over serial console Using modem or dialup Touch controllers, IR devices, bluetooth USB-2-serial converters
Serial Subsystem Architecture Low level drivers to interact with UART Tty driver layer above driver Data exchange core layer talks to tty driver Shapes behavior of serial subsystem
Serial Drivers Serial over USB Char drivers USB driver talks in a layers setup Tty driver interacts with USB drivers and insulated the serial data exchange (data discipline) Char drivers But do not expose syscall APIs like regular char drivers Services tty layer
UART Driver 3 main Data structures uart_driver – Per UART uart_port – Per port owned by UART uart_ops – Common tty file operations Each UART driver must support Used by tty layer Defines methods to access hardware
UART Driver Register with serial subsystem uart_register_driver(struct uart_driver *); Register every port on device uart_add_one_port(struct uart_driver * , struct uart_port *) serial8250_register_port(struct uart_port *) Internally calls uart_add_one_port
USB UART Platform Driver Implemented at platform Driver Platform drivers used for platform devices Autonomous, appear on port-based devices, host-bridges, controllers on SOCs Directly accessible from CPU bus Has a name, driver bindings, resources list
USB UART Platform Driver Standard Driver Model Device discovery handled outside driver Provides probe() and remove() functions Support Power management and notifications on shutdown
USB UART Platform Driver Registers with USB core Uses uart_register_driver() New tty entries /proc/tty/drivers/ Registers Platform devices Uses platform_device_register_simple() Platform Driver entry points ( functions ) Registers probe(), remove(), suspend(), resume() functions
tty Drivers Registration tty_struct tty_flip_buffer tty_driver Contains information about opening tty tty_flip_buffer Data collection Serial drivers use it. tty_driver Tty driver API used by upper layers Uses tty_register_driver() and tty_register_device () for devices
Line Discipline Registered with tty_register_ldisc() Removed with tty_unregister_ldisc() TTY side APIs Used to call into tty driver Driver access Calls tty driver functions e.g. write(), read() .. Via function pointers Driver Side Interfaces Talks between line discipline and driver receive_buf, write_wakeup, dcd_change
Line Discipline Callers from tty layer as well as driver should take locks If More info in Documentation/serial/tty.txt
Thanks Questions?