xref: /freebsd/share/man/man4/uart.4 (revision 2008043f386721d58158e37e0d7e50df8095942d)
1.\"
2.\" Copyright (c) 2003 Marcel Moolenaar
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\"
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.Dd July 11, 2020
27.Dt UART 4
28.Os
29.Sh NAME
30.Nm uart
31.Nd driver for Universal Asynchronous Receiver/Transmitter (UART) devices
32.Sh SYNOPSIS
33.Cd "device uart"
34.Pp
35.Cd "device puc"
36.Cd "device uart"
37.Pp
38.Cd "device scc"
39.Cd "device uart"
40.Pp
41In
42.Pa /boot/device.hints :
43.Cd hint.uart.0.disabled="1"
44.Cd hint.uart.0.baud="38400"
45.Cd hint.uart.0.port="0x3f8"
46.Cd hint.uart.0.flags="0x10"
47.Pp
48With
49.Ar flags
50encoded as:
51.Bl -tag -compact -width 0x000000
52.It 0x00010
53device is potential system console
54.It 0x00080
55use this port for remote kernel debugging
56.It 0x00100
57set RX FIFO trigger level to ``low'' (NS8250 only)
58.It 0x00200
59set RX FIFO trigger level to ``medium low'' (NS8250 only)
60.It 0x00400
61set RX FIFO trigger level to ``medium high'' (default, NS8250 only)
62.It 0x00800
63set RX FIFO trigger level to ``high'' (NS8250 only)
64.El
65.\"
66.Sh DESCRIPTION
67The
68.Nm
69device driver provides support for various classes of UARTs implementing the
70EIA RS-232C (CCITT V.24) serial communications interface.
71Each such interface is controlled by a separate and independent instance of
72the
73.Nm
74driver.
75The primary support for devices that contain multiple serial interfaces or
76that contain other functionality besides one or more serial interfaces is
77provided by the
78.Xr puc 4 ,
79or
80.Xr scc 4
81device drivers.
82However, the serial interfaces of those devices that are managed by the
83.Xr puc 4 ,
84or
85.Xr scc 4
86driver are each independently controlled by the
87.Nm
88driver.
89As such, the
90.Xr puc 4 ,
91or
92.Xr scc 4
93driver provides umbrella functionality for the
94.Nm
95driver and hides the complexities that are inherent when elementary components
96are packaged together.
97.Pp
98The
99.Nm
100driver has a modular design to allow it to be used on differing hardware and
101for various purposes.
102In the following sections the components are discussed in detail.
103Options are described in the section that covers the component to which each
104option applies.
105.\"
106.Ss CORE COMPONENT
107At the heart of the
108.Nm
109driver is the core component.
110It contains the bus attachments and the low-level interrupt handler.
111.\"
112.Ss HARDWARE DRIVERS
113The core component and the kernel interfaces talk to the hardware through the
114hardware interface.
115This interface serves as an abstraction of the hardware and allows varying
116UARTs to be used for serial communications.
117.\"
118.Ss SYSTEM DEVICES
119System devices are UARTs that have a special purpose by way of hardware
120design or software setup.
121For example, Sun UltraSparc machines use UARTs as their keyboard interface.
122Such an UART cannot be used for general purpose communications.
123Likewise, when the kernel is configured for a serial console, the
124corresponding UART will in turn be a system device so that the kernel can
125output boot messages early on in the boot process.
126.\"
127.Ss KERNEL INTERFACES
128The last but not least of the components is the kernel interface.
129This component ultimately determines how the UART is made visible to the
130kernel in particular and to users in general.
131The default kernel interface is the TTY interface.
132This allows the UART to be used for terminals, modems and serial line IP
133applications.
134System devices, with the notable exception of serial consoles, generally
135have specialized kernel interfaces.
136.\"
137.Sh HARDWARE
138The
139.Nm
140driver supports the following classes of UARTs:
141.Pp
142.Bl -bullet -compact
143.It
144NS8250: standard hardware based on the 8250, 16450, 16550, 16650, 16750 or
145the 16950 UARTs.
146.It
147SCC: serial communications controllers supported by the
148.Xr scc 4
149device driver.
150.El
151.\"
152.Sh Pulse Per Second (PPS) Timing Interface
153The
154.Nm
155driver can capture PPS timing information as defined in RFC 2783.
156The API, accessed via
157.Xr ioctl 2 ,
158is available on the tty device.
159To use the PPS capture feature with
160.Xr ntpd 8 ,
161symlink the tty callout device
162.Va /dev/cuau?
163to
164.Va /dev/pps0.
165.Pp
166The
167.Va hw.uart.pps_mode
168tunable configures the PPS capture mode for all uart devices;
169it can be set in
170.Xr loader.conf 5 .
171The
172.Va dev.uart.0.pps_mode
173sysctl configures the PPS capture mode for a specific uart device;
174it can be set in
175.Xr loader.conf 5
176or
177.Xr sysctl.conf 5 .
178.Pp
179The following capture modes are available:
180.Bl -tag -compact -offset "mmmm" -width "mmmm"
181.It 0x00
182Capture disabled.
183.It 0x01
184Capture pulses on the CTS line.
185.It 0x02
186Capture pulses on the DCD line.
187.El
188.Pp
189The following values may be ORed with the capture mode to configure
190capture processing options:
191.Bl -tag -compact -offset "mmmm" -width "mmmm"
192.It 0x10
193Invert the pulse (RS-232 logic low = ASSERT, high = CLEAR).
194.It 0x20
195Attempt to capture narrow pulses.
196.El
197.Pp
198Add the narrow pulse option when the incoming PPS pulse width is small
199enough to prevent reliable capture in normal mode.
200In narrow mode the driver uses the hardware's ability to latch a line
201state change; not all hardware has this capability.
202The hardware latch provides a reliable indication that a pulse occurred,
203but prevents distinguishing between the CLEAR and ASSERT edges of the pulse.
204For each detected pulse, the driver synthesizes both an ASSERT and a CLEAR
205event, using the same timestamp for each.
206To prevent spurious events when the hardware is intermittently able to
207see both edges of a pulse, the driver will not generate a new pair of
208events within a half second of the prior pair.
209Both normal and narrow pulse modes work with
210.Xr ntpd 8 .
211.Pp
212Add the invert option when the connection to the uart device uses TTL
213level signals, or when the PPS source emits inverted pulses.
214RFC 2783 defines an ASSERT event as a higher-voltage line level, and a CLEAR
215event as a lower-voltage line level, in the context of the RS-232 protocol.
216The modem control signals on a TTL-level connection are typically
217inverted from the RS-232 levels.
218For example, carrier presence is indicated by a high signal on an RS-232
219DCD line, and by a low signal on a TTL DCD line.
220This is due to the use of inverting line driver buffers to convert between
221TTL and RS-232 line levels in most hardware designs.
222Generally speaking, a connection to a DB-9 style connector is an RS-232
223level signal at up to 12 volts.
224A connection to header pins or an edge-connector on an embedded board
225is typically a TTL signal at 3.3 or 5 volts.
226.Sh Special Devices
227The
228.Nm
229driver also supports an initial-state and a lock-state control
230device for each of the callin and the callout "data" devices.
231The termios settings of a data device are copied
232from those of the corresponding initial-state device
233on first opens and are not inherited from previous opens.
234Use
235.Xr stty 1
236in the normal way on the initial-state devices to program
237initial termios states suitable for your setup.
238.Pp
239The lock termios state acts as flags to disable changing
240the termios state.
241E.g., to lock a flag variable such as CRTSCTS, use
242.Em stty crtscts
243on the lock-state device.
244Speeds and special characters
245may be locked by setting the corresponding value in the lock-state
246device to any nonzero value.
247E.g., to lock a speed to 115200, use
248.Dq Li stty 115200
249on the initial-state device and
250.Dq Li stty 1
251on the lock-state device.
252.Pp
253Correct programs talking to correctly wired external devices
254work with almost arbitrary initial states and almost no locking,
255but other setups may benefit from changing some of the default
256initial state and locking the state.
257In particular, the initial states for non (POSIX) standard flags
258should be set to suit the devices attached and may need to be
259locked to prevent buggy programs from changing them.
260E.g., CRTSCTS should be locked on for devices that support
261RTS/CTS handshaking at all times and off for devices that do not
262support it at all.
263CLOCAL should be locked on for devices that do not support carrier.
264HUPCL may be locked off if you do not
265want to hang up for some reason.
266In general, very bad things happen
267if something is locked to the wrong state, and things should not
268be locked for devices that support more than one setting.
269The CLOCAL flag on callin ports should be locked off for logins
270to avoid certain security holes, but this needs to be done by
271getty if the callin port is used for anything else.
272.Sh FILES
273.Bl -tag -width "/dev/ttyu?.init" -compact
274.It Pa /dev/ttyu?
275for callin ports
276.It Pa /dev/ttyu?.init
277.It Pa /dev/ttyu?.lock
278corresponding callin initial-state and lock-state devices
279.Pp
280.It Pa /dev/cuau?
281for callout ports
282.It Pa /dev/cuau?.init
283.It Pa /dev/cuau?.lock
284corresponding callout initial-state and lock-state devices
285.El
286.Sh SEE ALSO
287.Xr cu 1 ,
288.Xr puc 4 ,
289.Xr scc 4 ,
290.Xr ttys 5
291.\"
292.Sh HISTORY
293The
294.Nm
295device driver first appeared in
296.Fx 5.2 .
297.Sh AUTHORS
298The
299.Nm
300device driver and this manual page were written by
301.An Marcel Moolenaar Aq Mt marcel@xcllnt.net .
302