]> CyberLeo.Net >> Repos - FreeBSD/releng/8.0.git/blob - sys/dev/usb/serial/usb_serial.h
Adjust to reflect 8.0-RELEASE.
[FreeBSD/releng/8.0.git] / sys / dev / usb / serial / usb_serial.h
1 /*      $NetBSD: ucomvar.h,v 1.9 2001/01/23 21:56:17 augustss Exp $     */
2 /*      $FreeBSD$       */
3
4 /*-
5  * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 /*-
31  * Copyright (c) 1999 The NetBSD Foundation, Inc.
32  * All rights reserved.
33  *
34  * This code is derived from software contributed to The NetBSD Foundation
35  * by Lennart Augustsson (lennart@augustsson.net) at
36  * Carlstedt Research & Technology.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. All advertising materials mentioning features or use of this software
47  *    must display the following acknowledgement:
48  *        This product includes software developed by the NetBSD
49  *        Foundation, Inc. and its contributors.
50  * 4. Neither the name of The NetBSD Foundation nor the names of its
51  *    contributors may be used to endorse or promote products derived
52  *    from this software without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
55  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
58  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64  * POSSIBILITY OF SUCH DAMAGE.
65  */
66
67 #ifndef _USB_SERIAL_H_
68 #define _USB_SERIAL_H_
69
70 #include <sys/tty.h>
71 #include <sys/serial.h>
72 #include <sys/fcntl.h>
73 #include <sys/termios.h>
74
75 /* Module interface related macros */
76 #define UCOM_MODVER     1
77
78 #define UCOM_MINVER     1
79 #define UCOM_PREFVER    UCOM_MODVER
80 #define UCOM_MAXVER     1
81
82 struct usb_device;
83 struct ucom_softc;
84 struct usb_device_request;
85 struct thread;
86
87 /*
88  * NOTE: There is no guarantee that "ucom_cfg_close()" will
89  * be called after "ucom_cfg_open()" if the device is detached
90  * while it is open!
91  */
92 struct ucom_callback {
93         void    (*ucom_cfg_get_status) (struct ucom_softc *, uint8_t *plsr, uint8_t *pmsr);
94         void    (*ucom_cfg_set_dtr) (struct ucom_softc *, uint8_t);
95         void    (*ucom_cfg_set_rts) (struct ucom_softc *, uint8_t);
96         void    (*ucom_cfg_set_break) (struct ucom_softc *, uint8_t);
97         void    (*ucom_cfg_param) (struct ucom_softc *, struct termios *);
98         void    (*ucom_cfg_open) (struct ucom_softc *);
99         void    (*ucom_cfg_close) (struct ucom_softc *);
100         int     (*ucom_pre_open) (struct ucom_softc *);
101         int     (*ucom_pre_param) (struct ucom_softc *, struct termios *);
102         int     (*ucom_ioctl) (struct ucom_softc *, uint32_t, caddr_t, int, struct thread *);
103         void    (*ucom_start_read) (struct ucom_softc *);
104         void    (*ucom_stop_read) (struct ucom_softc *);
105         void    (*ucom_start_write) (struct ucom_softc *);
106         void    (*ucom_stop_write) (struct ucom_softc *);
107         void    (*ucom_tty_name) (struct ucom_softc *, char *pbuf, uint16_t buflen, uint16_t local_subunit);
108 };
109
110 /* Line status register */
111 #define ULSR_RCV_FIFO   0x80
112 #define ULSR_TSRE       0x40            /* Transmitter empty: byte sent */
113 #define ULSR_TXRDY      0x20            /* Transmitter buffer empty */
114 #define ULSR_BI         0x10            /* Break detected */
115 #define ULSR_FE         0x08            /* Framing error: bad stop bit */
116 #define ULSR_PE         0x04            /* Parity error */
117 #define ULSR_OE         0x02            /* Overrun, lost incoming byte */
118 #define ULSR_RXRDY      0x01            /* Byte ready in Receive Buffer */
119 #define ULSR_RCV_MASK   0x1f            /* Mask for incoming data or error */
120
121 struct ucom_cfg_task {
122         struct usb_proc_msg hdr;
123         struct ucom_softc *sc;
124 };
125
126 struct ucom_param_task {
127         struct usb_proc_msg hdr;
128         struct ucom_softc *sc;
129         struct termios termios_copy;
130 };
131
132 struct ucom_super_softc {
133         struct usb_process sc_tq;
134 };
135
136 struct ucom_softc {
137         /*
138          * NOTE: To avoid loosing level change information we use two
139          * tasks instead of one for all commands.
140          *
141          * Level changes are transitions like:
142          *
143          * ON->OFF
144          * OFF->ON
145          * OPEN->CLOSE
146          * CLOSE->OPEN
147          */
148         struct ucom_cfg_task    sc_start_task[2];
149         struct ucom_cfg_task    sc_open_task[2];
150         struct ucom_cfg_task    sc_close_task[2];
151         struct ucom_cfg_task    sc_line_state_task[2];
152         struct ucom_cfg_task    sc_status_task[2];
153         struct ucom_param_task  sc_param_task[2];
154         struct cv sc_cv;
155         /* Used to set "UCOM_FLAG_GP_DATA" flag: */
156         struct usb_proc_msg     *sc_last_start_xfer;
157         const struct ucom_callback *sc_callback;
158         struct ucom_super_softc *sc_super;
159         struct tty *sc_tty;
160         struct mtx *sc_mtx;
161         void   *sc_parent;
162         uint32_t sc_unit;
163         uint32_t sc_local_unit;
164         uint16_t sc_portno;
165         uint8_t sc_flag;
166 #define UCOM_FLAG_RTS_IFLOW     0x01    /* use RTS input flow control */
167 #define UCOM_FLAG_GONE          0x02    /* the device is gone */
168 #define UCOM_FLAG_ATTACHED      0x04    /* set if attached */
169 #define UCOM_FLAG_GP_DATA       0x08    /* set if get and put data is possible */
170 #define UCOM_FLAG_LL_READY      0x20    /* set if low layer is ready */
171 #define UCOM_FLAG_HL_READY      0x40    /* set if high layer is ready */
172         uint8_t sc_lsr;
173         uint8_t sc_msr;
174         uint8_t sc_mcr;
175         uint8_t sc_ttyfreed;            /* set when TTY has been freed */
176         /* programmed line state bits */
177         uint8_t sc_pls_set;             /* set bits */
178         uint8_t sc_pls_clr;             /* cleared bits */
179         uint8_t sc_pls_curr;            /* last state */
180 #define UCOM_LS_DTR     0x01
181 #define UCOM_LS_RTS     0x02
182 #define UCOM_LS_BREAK   0x04
183 };
184
185 #define ucom_cfg_do_request(udev,com,req,ptr,flags,timo) \
186     usbd_do_request_proc(udev,&(com)->sc_super->sc_tq,req,ptr,flags,NULL,timo)
187
188 int     ucom_attach(struct ucom_super_softc *,
189             struct ucom_softc *, uint32_t, void *,
190             const struct ucom_callback *callback, struct mtx *);
191 void    ucom_detach(struct ucom_super_softc *,
192             struct ucom_softc *, uint32_t);
193 void    ucom_status_change(struct ucom_softc *);
194 uint8_t ucom_get_data(struct ucom_softc *, struct usb_page_cache *,
195             uint32_t, uint32_t, uint32_t *);
196 void    ucom_put_data(struct ucom_softc *, struct usb_page_cache *,
197             uint32_t, uint32_t);
198 uint8_t ucom_cfg_is_gone(struct ucom_softc *);
199 #endif                                  /* _USB_SERIAL_H_ */