ubsavar.h revision 1.1 1 /* $NetBSD: ubsavar.h,v 1.1 2008/01/21 11:36:47 ichiro Exp $ */
2 /*-
3 * Copyright (c) 2002, Alexander Kabaev <kan.FreeBSD.org>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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 AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27 /*
28 * Copyright (c) 2001 The NetBSD Foundation, Inc.
29 * All rights reserved.
30 *
31 * This code is derived from software contributed to The NetBSD Foundation
32 * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the NetBSD
45 * Foundation, Inc. and its contributors.
46 * 4. Neither the name of The NetBSD Foundation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
51 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
52 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
54 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
55 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
56 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60 * POSSIBILITY OF SUCH DAMAGE.
61 */
62
63 #define UBSA_MODVER 1 /* module version */
64
65 #define UBSA_DEFAULT_CONFIG_INDEX 1
66 #define UBSA_IFACE_INDEX_OFFSET 0
67
68 #define UBSA_INTR_INTERVAL 100 /* ms */
69
70 #define UBSA_SET_BAUDRATE 0x00
71 #define UBSA_SET_STOP_BITS 0x01
72 #define UBSA_SET_DATA_BITS 0x02
73 #define UBSA_SET_PARITY 0x03
74 #define UBSA_SET_DTR 0x0A
75 #define UBSA_SET_RTS 0x0B
76 #define UBSA_SET_BREAK 0x0C
77 #define UBSA_SET_FLOW_CTRL 0x10
78
79 #define UBSA_QUADUMTS_SET_PIN 0x22
80
81 #define UBSA_PARITY_NONE 0x00
82 #define UBSA_PARITY_EVEN 0x01
83 #define UBSA_PARITY_ODD 0x02
84 #define UBSA_PARITY_MARK 0x03
85 #define UBSA_PARITY_SPACE 0x04
86
87 #define UBSA_FLOW_NONE 0x0000
88 #define UBSA_FLOW_OCTS 0x0001
89 #define UBSA_FLOW_ODSR 0x0002
90 #define UBSA_FLOW_IDSR 0x0004
91 #define UBSA_FLOW_IDTR 0x0008
92 #define UBSA_FLOW_IRTS 0x0010
93 #define UBSA_FLOW_ORTS 0x0020
94 #define UBSA_FLOW_UNKNOWN 0x0040
95 #define UBSA_FLOW_OXON 0x0080
96 #define UBSA_FLOW_IXON 0x0100
97
98 /* line status register */
99 #define UBSA_LSR_TSRE 0x40 /* Transmitter empty: byte sent */
100 #define UBSA_LSR_TXRDY 0x20 /* Transmitter buffer empty */
101 #define UBSA_LSR_BI 0x10 /* Break detected */
102 #define UBSA_LSR_FE 0x08 /* Framing error: bad stop bit */
103 #define UBSA_LSR_PE 0x04 /* Parity error */
104 #define UBSA_LSR_OE 0x02 /* Overrun, lost incoming byte */
105 #define UBSA_LSR_RXRDY 0x01 /* Byte ready in Receive Buffer */
106 #define UBSA_LSR_RCV_MASK 0x1f /* Mask for incoming data or error */
107
108 /* modem status register */
109 /* All deltas are from the last read of the MSR. */
110 #define UBSA_MSR_DCD 0x80 /* Current Data Carrier Detect */
111 #define UBSA_MSR_RI 0x40 /* Current Ring Indicator */
112 #define UBSA_MSR_DSR 0x20 /* Current Data Set Ready */
113 #define UBSA_MSR_CTS 0x10 /* Current Clear to Send */
114 #define UBSA_MSR_DDCD 0x08 /* DCD has changed state */
115 #define UBSA_MSR_TERI 0x04 /* RI has toggled low to high */
116 #define UBSA_MSR_DDSR 0x02 /* DSR has changed state */
117 #define UBSA_MSR_DCTS 0x01 /* CTS has changed state */
118
119 #define UBSA_MAXCONN 3
120
121 struct ubsa_softc {
122 USBBASEDEVICE sc_dev; /* base device */
123 usbd_device_handle sc_udev; /* USB device */
124 usbd_interface_handle sc_iface[UBSA_MAXCONN]; /* interface */
125
126 int sc_iface_number[UBSA_MAXCONN]; /* interface number */
127 int sc_config_index; /* USB CONFIG_INDEX */
128
129 int sc_intr_number; /* interrupt number */
130 usbd_pipe_handle sc_intr_pipe; /* interrupt pipe */
131 u_char *sc_intr_buf; /* interrupt buffer */
132 int sc_isize;
133
134 u_char sc_dtr; /* current DTR state */
135 u_char sc_rts; /* current RTS state */
136
137 u_char sc_lsr; /* Local status register */
138 u_char sc_msr; /* ubsa status register */
139
140 device_ptr_t sc_subdevs[UBSA_MAXCONN]; /* ucom device */
141 int sc_numif; /* number of interfaces */
142
143 u_char sc_dying; /* disconnecting */
144 u_char sc_quadumts;
145 };
146
147
148 Static void ubsa_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
149
150 Static void ubsa_get_status(void *, int, u_char *, u_char *);
151 Static void ubsa_set(void *, int, int, int);
152 Static int ubsa_param(void *, int, struct termios *);
153 Static int ubsa_open(void *, int);
154 Static void ubsa_close(void *, int);
155
156 Static void ubsa_break(struct ubsa_softc *sc, int, int onoff);
157 Static int ubsa_request(struct ubsa_softc *, int, u_int8_t, u_int16_t);
158 Static void ubsa_dtr(struct ubsa_softc *, int, int);
159 Static void ubsa_quadumts_dtr(struct ubsa_softc *, int, int);
160 Static void ubsa_rts(struct ubsa_softc *, int, int);
161 Static void ubsa_quadumts_rts(struct ubsa_softc *, int, int);
162 Static void ubsa_baudrate(struct ubsa_softc *, int, speed_t);
163 Static void ubsa_parity(struct ubsa_softc *, int, tcflag_t);
164 Static void ubsa_databits(struct ubsa_softc *, int, tcflag_t);
165 Static void ubsa_stopbits(struct ubsa_softc *, int, tcflag_t);
166 Static void ubsa_flow(struct ubsa_softc *, int, tcflag_t, tcflag_t);
167
168