Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / dev / usbmisc / ucom / ucomvar.h
1 /*      $NetBSD: ucomvar.h,v 1.9 2001/01/23 21:56:17 augustss Exp $     */
2 /*      $FreeBSD: src/sys/dev/usb/ucomvar.h,v 1.2.2.1 2002/08/08 18:45:04 joe Exp $     */
3 /*      $DragonFly: src/sys/dev/usbmisc/ucom/ucomvar.h,v 1.2 2003/06/17 04:28:32 dillon Exp $   */
4
5 /*-
6  * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
7  * All rights reserved.
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  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30
31 /*
32  * Copyright (c) 1999 The NetBSD Foundation, Inc.
33  * All rights reserved.
34  *
35  * This code is derived from software contributed to The NetBSD Foundation
36  * by Lennart Augustsson (lennart@augustsson.net) at
37  * Carlstedt Research & Technology.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the distribution.
47  * 3. All advertising materials mentioning features or use of this software
48  *    must display the following acknowledgement:
49  *        This product includes software developed by the NetBSD
50  *        Foundation, Inc. and its contributors.
51  * 4. Neither the name of The NetBSD Foundation nor the names of its
52  *    contributors may be used to endorse or promote products derived
53  *    from this software without specific prior written permission.
54  *
55  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
56  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
59  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65  * POSSIBILITY OF SUCH DAMAGE.
66  */
67
68 /* Module interface related macros */
69 #define UCOM_MODVER     1
70
71 #define UCOM_MINVER     1
72 #define UCOM_PREFVER    UCOM_MODVER
73 #define UCOM_MAXVER     1
74
75 /* Macros to clear/set/test flags. */
76 #define SET(t, f)       (t) |= (f)
77 #define CLR(t, f)       (t) &= ~((unsigned)(f))
78 #define ISSET(t, f)     ((t) & (f))
79
80 #define UCOM_CALLOUT_MASK       0x80
81
82 #define UCOMUNIT_MASK           0x3ff7f
83 #define UCOMDIALOUT_MASK        0x80000
84 #define UCOMCALLUNIT_MASK       0x40000
85
86 #define UCOMUNIT(x)             (minor(x) & UCOMUNIT_MASK)
87 #define UCOMDIALOUT(x)          (minor(x) & UCOMDIALOUT_MASK)
88 #define UCOMCALLUNIT(x)         (minor(x) & UCOMCALLUNIT_MASK)
89
90 #define UCOM_UNK_PORTNO         -1      /* XXX */
91
92 struct ucom_softc;
93
94 struct ucom_callback {
95         void (*ucom_get_status)(void *, int, u_char *, u_char *);
96         void (*ucom_set)(void *, int, int, int);
97 #define UCOM_SET_DTR 1
98 #define UCOM_SET_RTS 2
99 #define UCOM_SET_BREAK 3
100         int (*ucom_param)(void *, int, struct termios *);
101         int (*ucom_ioctl)(void *, int, u_long, caddr_t, int, usb_proc_ptr);
102         int (*ucom_open)(void *, int);
103         void (*ucom_close)(void *, int);
104         void (*ucom_read)(void *, int, u_char **, u_int32_t *);
105         void (*ucom_write)(void *, int, u_char *, u_char *, u_int32_t *);
106 };
107
108 /* modem control register */
109 #define UMCR_RTS        0x02    /* Request To Send */
110 #define UMCR_DTR        0x01    /* Data Terminal Ready */
111
112 /* line status register */
113 #define ULSR_RCV_FIFO   0x80
114 #define ULSR_TSRE       0x40    /* Transmitter empty: byte sent */
115 #define ULSR_TXRDY      0x20    /* Transmitter buffer empty */
116 #define ULSR_BI         0x10    /* Break detected */
117 #define ULSR_FE         0x08    /* Framing error: bad stop bit */
118 #define ULSR_PE         0x04    /* Parity error */
119 #define ULSR_OE         0x02    /* Overrun, lost incoming byte */
120 #define ULSR_RXRDY      0x01    /* Byte ready in Receive Buffer */
121 #define ULSR_RCV_MASK   0x1f    /* Mask for incoming data or error */
122
123 /* modem status register */
124 /* All deltas are from the last read of the MSR. */
125 #define UMSR_DCD        0x80    /* Current Data Carrier Detect */
126 #define UMSR_RI         0x40    /* Current Ring Indicator */
127 #define UMSR_DSR        0x20    /* Current Data Set Ready */
128 #define UMSR_CTS        0x10    /* Current Clear to Send */
129 #define UMSR_DDCD       0x08    /* DCD has changed state */
130 #define UMSR_TERI       0x04    /* RI has toggled low to high */
131 #define UMSR_DDSR       0x02    /* DSR has changed state */
132 #define UMSR_DCTS       0x01    /* CTS has changed state */
133
134 /* ucom state declarations */
135 #define UCS_RXSTOP      0x0001  /* Rx stopped */
136 #define UCS_RTS_IFLOW   0x0008  /* use RTS input flow control */
137
138 struct ucom_softc {
139         USBBASEDEVICE           sc_dev;         /* base device */
140         usbd_device_handle      sc_udev;        /* USB device */
141         usbd_interface_handle   sc_iface;       /* data interface */
142
143         int                     sc_bulkin_no;   /* bulk in endpoint address */
144         usbd_pipe_handle        sc_bulkin_pipe; /* bulk in pipe */
145         usbd_xfer_handle        sc_ixfer;       /* read request */
146         u_char                  *sc_ibuf;       /* read buffer */
147         u_int                   sc_ibufsize;    /* read buffer size */
148         u_int                   sc_ibufsizepad; /* read buffer size padded */
149
150         int                     sc_bulkout_no;  /* bulk out endpoint address */
151         usbd_pipe_handle        sc_bulkout_pipe;/* bulk out pipe */
152         usbd_xfer_handle        sc_oxfer;       /* write request */
153         u_char                  *sc_obuf;       /* write buffer */
154         u_int                   sc_obufsize;    /* write buffer size */
155         u_int                   sc_opkthdrlen;  /* header length of
156                                                    output packet */
157
158         struct ucom_callback    *sc_callback;
159         void                    *sc_parent;
160         int                     sc_portno;
161
162         struct tty              *sc_tty;        /* our tty */
163
164         int                     sc_state;
165
166         int                     sc_poll;
167         u_char                  hotchar;
168
169         u_char                  sc_lsr;
170         u_char                  sc_msr;
171         u_char                  sc_mcr;
172
173         u_char                  sc_opening;     /* lock during open */
174         int                     sc_refcnt;
175         u_char                  sc_dying;       /* disconnecting */
176
177         dev_t                   dev;            /* special device node */
178 };
179
180 extern devclass_t ucom_devclass;
181
182 int ucom_attach(struct ucom_softc *);
183 int ucom_detach(struct ucom_softc *);
184 void ucom_status_change(struct ucom_softc *);