2019-04-22 09:27:22 -04:00
|
|
|
====================
|
|
|
|
Low Level Serial API
|
|
|
|
====================
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
This document is meant as a brief overview of some aspects of the new serial
|
|
|
|
driver. It is not complete, any questions you have should be directed to
|
|
|
|
<rmk@arm.linux.org.uk>
|
|
|
|
|
2018-09-13 02:23:38 -04:00
|
|
|
The reference implementation is contained within amba-pl011.c.
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Low Level Serial Hardware Driver
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
The low level serial hardware driver is responsible for supplying port
|
|
|
|
information (defined by uart_port) and a set of control methods (defined
|
|
|
|
by uart_ops) to the core serial driver. The low level driver is also
|
|
|
|
responsible for handling interrupts for the port, and providing any
|
|
|
|
console support.
|
|
|
|
|
|
|
|
|
|
|
|
Console Support
|
|
|
|
---------------
|
|
|
|
|
2023-01-29 18:10:46 -05:00
|
|
|
The serial core provides a few helper functions. This includes identifying
|
2022-07-28 02:10:55 -04:00
|
|
|
the correct port structure (via uart_get_console()) and decoding command line
|
|
|
|
arguments (uart_parse_options()).
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2022-07-28 02:10:55 -04:00
|
|
|
There is also a helper function (uart_console_write()) which performs a
|
2016-04-14 05:08:08 -04:00
|
|
|
character by character write, translating newlines to CRLF sequences.
|
|
|
|
Driver writers are recommended to use this function rather than implementing
|
|
|
|
their own version.
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
Locking
|
|
|
|
-------
|
|
|
|
|
|
|
|
It is the responsibility of the low level hardware driver to perform the
|
|
|
|
necessary locking using port->lock. There are some exceptions (which
|
2022-07-28 02:10:54 -04:00
|
|
|
are described in the struct uart_ops listing below.)
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2016-03-14 11:16:10 -04:00
|
|
|
There are two locks. A per-port spinlock, and an overall semaphore.
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
From the core driver perspective, the port->lock locks the following
|
2019-04-22 09:27:22 -04:00
|
|
|
data::
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
port->mctrl
|
|
|
|
port->icount
|
2016-05-11 07:56:05 -04:00
|
|
|
port->state->xmit.head (circ_buf->head)
|
|
|
|
port->state->xmit.tail (circ_buf->tail)
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
The low level driver is free to use this lock to provide any additional
|
|
|
|
locking.
|
|
|
|
|
|
|
|
The port_sem semaphore is used to protect against ports being added/
|
2014-10-16 16:54:20 -04:00
|
|
|
removed or reconfigured at inappropriate times. Since v2.6.27, this
|
|
|
|
semaphore has been the 'mutex' member of the tty_port struct, and
|
2016-05-11 07:56:04 -04:00
|
|
|
commonly referred to as the port mutex.
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
uart_ops
|
|
|
|
--------
|
|
|
|
|
2022-07-28 02:10:51 -04:00
|
|
|
.. kernel-doc:: include/linux/serial_core.h
|
|
|
|
:identifiers: uart_ops
|
2012-12-26 23:43:42 -05:00
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
Other functions
|
|
|
|
---------------
|
|
|
|
|
2022-07-28 02:10:52 -04:00
|
|
|
.. kernel-doc:: drivers/tty/serial/serial_core.c
|
|
|
|
:identifiers: uart_update_timeout uart_get_baud_rate uart_get_divisor
|
|
|
|
uart_match_port uart_write_wakeup uart_register_driver
|
|
|
|
uart_unregister_driver uart_suspend_port uart_resume_port
|
2022-07-28 02:10:55 -04:00
|
|
|
uart_add_one_port uart_remove_one_port uart_console_write
|
|
|
|
uart_parse_earlycon uart_parse_options uart_set_options
|
|
|
|
uart_get_lsr_info uart_handle_dcd_change uart_handle_cts_change
|
2022-07-28 02:10:56 -04:00
|
|
|
uart_try_toggle_sysrq uart_get_console
|
2005-10-31 06:53:19 -05:00
|
|
|
|
2022-10-04 06:49:25 -04:00
|
|
|
.. kernel-doc:: include/linux/serial_core.h
|
|
|
|
:identifiers: uart_port_tx_limited uart_port_tx
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
Other notes
|
|
|
|
-----------
|
|
|
|
|
|
|
|
It is intended some day to drop the 'unused' entries from uart_port, and
|
|
|
|
allow low level drivers to register their own individual uart_port's with
|
|
|
|
the core. This will allow drivers to use uart_port as a pointer to a
|
|
|
|
structure containing both the uart_port entry with their own extensions,
|
2019-04-22 09:27:22 -04:00
|
|
|
thus::
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
struct my_port {
|
|
|
|
struct uart_port port;
|
|
|
|
int my_stuff;
|
|
|
|
};
|
2014-05-13 14:20:43 -04:00
|
|
|
|
|
|
|
Modem control lines via GPIO
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
Some helpers are provided in order to set/get modem control lines via GPIO.
|
|
|
|
|
2022-07-28 02:10:53 -04:00
|
|
|
.. kernel-doc:: drivers/tty/serial/serial_mctrl_gpio.c
|
|
|
|
:identifiers: mctrl_gpio_init mctrl_gpio_free mctrl_gpio_to_gpiod
|
|
|
|
mctrl_gpio_set mctrl_gpio_get mctrl_gpio_enable_ms
|
|
|
|
mctrl_gpio_disable_ms
|