xref: /netbsd/share/man/man9/ucom.9 (revision bf9ec67e)
1.\"	$NetBSD: ucom.9,v 1.8 2002/02/07 03:15:10 ross Exp $
2.\"
3.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Lennart Augustsson.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd April 15, 2000
38.Dt UCOM 9
39.Os
40.Sh NAME
41.Nm ucom
42.Nd interface for USB tty like devices
43.Sh DESCRIPTION
44The
45.Nm
46driver is a (relatively) easy way to make a USB device look like
47a
48.Xr tty 4 .
49It basically takes two bulk pipes, input and output, and makes
50a tty out of them.
51This is useful for a number of device types, e.g., serial ports
52(see
53.Xr uftdi 4 ) ,
54modems (see
55.Xr umodem 4 ) ,
56and devices that traditionally look like a tty (see
57.Xr uvisor 4 ) .
58.Pp
59Communication between the real driver and the
60.Nm
61driver is via the attachment arguments (when attached) and
62via the
63.Va ucom_methods
64struct
65.Sh ATTACHMENT
66.Bd -literal
67struct ucom_attach_args {
68	int portno;
69	int bulkin;
70	int bulkout;
71	u_int ibufsize;
72	u_int ibufsizepad;
73	u_int obufsize;
74	u_int obufsizepad;
75	usbd_device_handle device;
76	usbd_interface_handle iface;
77	struct ucom_methods *methods;
78	void *arg;
79};
80.Ed
81.Pp
82.Bl -tag -width indent
83.It Dv int portno
84identifies the port if the devices should have more than one
85.Nm
86attached.  Use the value
87.Dv UCOM_UNK_PORTNO
88if there is only one port.
89.It Dv int bulkin
90the number of the bulk input pipe.
91.It Dv int bulkout
92the number of the bulk output pipe.
93.It Dv u_int ibufsize
94the size of the read requests on the bulk in pipe.
95.It Dv u_int ibufsizepad
96the size of the input buffer.  This is usually the same
97as .Dv ibufsize.
98.It Dv u_int obufsize
99the size of the write requests on the bulk out pipe.
100.It Dv u_int ibufsizepad
101the size of the output buffer.  This is usually the same
102as .Dv obufsize.
103.It Dv usbd_device_handle device
104a handle to the device.
105.It usbd_interface_handle iface
106a handle to the interface that should be used.
107.It struct ucom_methods *methods
108a pointer to the methods that the
109.Nm
110driver should use for further communication with the driver.
111.It void *arg
112the value that should be passed as first argument to each method.
113.El
114.Sh METHODS
115The
116.Dv ucom_methods
117struct contains a number of function pointers used by the
118.Nm
119driver at various stages.  If the device is not interested
120in being called at a particular point it should just use a
121.Dv NULL
122pointer and the
123.Nm
124driver will use a sensible default.
125.Bd -literal
126struct ucom_methods {
127	void (*ucom_get_status)(void *sc, int portno,
128				u_char *lsr, u_char *msr);
129	void (*ucom_set)(void *sc, int portno, int reg, int onoff);
130#define UCOM_SET_DTR 1
131#define UCOM_SET_RTS 2
132#define UCOM_SET_BREAK 3
133	int (*ucom_param)(void *sc, int portno, struct termios *);
134	int (*ucom_ioctl)(void *sc, int portno, u_long cmd,
135			  caddr_t data, int flag, struct proc *p);
136	int (*ucom_open)(void *sc, int portno);
137	void (*ucom_close)(void *sc, int portno);
138	void (*ucom_read)(void *sc, int portno, u_char **ptr,
139			  u_int32_t *count);
140	void (*ucom_write)(void *sc, int portno, u_char *to,
141			   u_char *from, u_int32_t *count);
142};
143.Ed
144.Pp
145.Bl -tag -width indent
146.It Fn "void (*ucom_get_status)" "void *sc, int portno, u_char *lsr, u_char *msr"
147get the status of port
148.Fa portno .
149The status consists of the line status,
150.Fa lsr ,
151and the modem status
152.Fa msr .
153The contents of these two bytes is exactly as for a 16550 UART.
154.It Fn "void (*ucom_set)" "void *sc, int portno, int reg, int onoff"
155Set (or unset) a particular feature of a port.
156.It Fn "int (*ucom_param)" "void *sc, int portno, struct termios *t"
157Set the speed, number of data bit, stop bits, and parity of a port
158according to the
159.Xr termios 4
160struct.
161.It Fn "int (*ucom_ioctl)" "void *sc, int portno, u_long cmd, caddr_t data, int flag, struct proc *p"
162implements any non-standard
163.Xr ioctl 2
164that a device needs.
165.It Fn "int (*ucom_open)" "void *sc, int portno"
166called just before the
167.Nm
168driver opens the bulk pipes for the port.
169.It Fn "void (*ucom_close)" "void *sc, int portno"
170called just after the
171.Nm
172driver closes the bulk pipes for the port.
173.It Fn "void (*ucom_read)" "void *sc, int portno, u_char **ptr, u_int32_t *count"
174if the data delivered on the bulk pipe is not just the raw input characters
175this routine needs to adjust
176.Fa ptr
177and
178.Fa count
179so that they tell where to find the given number of raw characters.
180.It Fn "void (*ucom_write)" "void *sc, int portno, u_char *dst, u_char *src, u_int32_t *count"
181if the data written to the bulk pipe is not just the raw characters then
182this routine needs to copy
183.Fa count
184raw characters from
185.Fa src
186into the buffer at
187.Fa dst
188and do the appropriate padding.  The
189.Fa count
190should be updated to the new size.
191The buffer at
192.Fa src
193is at most
194.Va ibufsize
195bytes and the buffer
196at
197.Fa dst
198is
199.Va ibufsizepad
200bytes.
201.El
202.Pp
203Apart from these methods there is a function
204.Bl -tag -width 5n -offset 5n
205.It Fn "void ucom_status_change" "struct ucom_softc *"
206.El
207.Pp
208which should be called by the driver whenever it notices a status change.
209.Sh SEE ALSO
210.Xr tty 4 ,
211.Xr uftdi 4 ,
212.Xr umodem 4 ,
213.Xr usb 4 ,
214.Xr uvisor 4
215.Sh HISTORY
216This
217.Nm
218interface first appeared in
219.Nx 1.5 .
220