ubsa_common.c revision 1.2.14.2 1 1.2.14.2 matt /* $NetBSD: ubsa_common.c,v 1.2.14.2 2008/03/23 02:04:53 matt Exp $ */
2 1.2.14.2 matt /*-
3 1.2.14.2 matt * Copyright (c) 2002, Alexander Kabaev <kan.FreeBSD.org>.
4 1.2.14.2 matt * All rights reserved.
5 1.2.14.2 matt *
6 1.2.14.2 matt * Redistribution and use in source and binary forms, with or without
7 1.2.14.2 matt * modification, are permitted provided that the following conditions
8 1.2.14.2 matt * are met:
9 1.2.14.2 matt * 1. Redistributions of source code must retain the above copyright
10 1.2.14.2 matt * notice, this list of conditions and the following disclaimer.
11 1.2.14.2 matt * 2. Redistributions in binary form must reproduce the above copyright
12 1.2.14.2 matt * notice, this list of conditions and the following disclaimer in the
13 1.2.14.2 matt * documentation and/or other materials provided with the distribution.
14 1.2.14.2 matt *
15 1.2.14.2 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.2.14.2 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.2.14.2 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.2.14.2 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.2.14.2 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.2.14.2 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.2.14.2 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.2.14.2 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.2.14.2 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.2.14.2 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.2.14.2 matt * SUCH DAMAGE.
26 1.2.14.2 matt */
27 1.2.14.2 matt /*
28 1.2.14.2 matt * Copyright (c) 2001 The NetBSD Foundation, Inc.
29 1.2.14.2 matt * All rights reserved.
30 1.2.14.2 matt *
31 1.2.14.2 matt * This code is derived from software contributed to The NetBSD Foundation
32 1.2.14.2 matt * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
33 1.2.14.2 matt *
34 1.2.14.2 matt * Redistribution and use in source and binary forms, with or without
35 1.2.14.2 matt * modification, are permitted provided that the following conditions
36 1.2.14.2 matt * are met:
37 1.2.14.2 matt * 1. Redistributions of source code must retain the above copyright
38 1.2.14.2 matt * notice, this list of conditions and the following disclaimer.
39 1.2.14.2 matt * 2. Redistributions in binary form must reproduce the above copyright
40 1.2.14.2 matt * notice, this list of conditions and the following disclaimer in the
41 1.2.14.2 matt * documentation and/or other materials provided with the distribution.
42 1.2.14.2 matt * 3. All advertising materials mentioning features or use of this software
43 1.2.14.2 matt * must display the following acknowledgement:
44 1.2.14.2 matt * This product includes software developed by the NetBSD
45 1.2.14.2 matt * Foundation, Inc. and its contributors.
46 1.2.14.2 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
47 1.2.14.2 matt * contributors may be used to endorse or promote products derived
48 1.2.14.2 matt * from this software without specific prior written permission.
49 1.2.14.2 matt *
50 1.2.14.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
51 1.2.14.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
52 1.2.14.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 1.2.14.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
54 1.2.14.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
55 1.2.14.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
56 1.2.14.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57 1.2.14.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58 1.2.14.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59 1.2.14.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60 1.2.14.2 matt * POSSIBILITY OF SUCH DAMAGE.
61 1.2.14.2 matt */
62 1.2.14.2 matt
63 1.2.14.2 matt #include <sys/cdefs.h>
64 1.2.14.2 matt __KERNEL_RCSID(0, "$NetBSD: ubsa_common.c,v 1.2.14.2 2008/03/23 02:04:53 matt Exp $");
65 1.2.14.2 matt
66 1.2.14.2 matt #include <sys/param.h>
67 1.2.14.2 matt #include <sys/systm.h>
68 1.2.14.2 matt #include <sys/kernel.h>
69 1.2.14.2 matt #include <sys/malloc.h>
70 1.2.14.2 matt #ifdef __FreeBSD__
71 1.2.14.2 matt #include <sys/bus.h>
72 1.2.14.2 matt #endif
73 1.2.14.2 matt #include <sys/ioccom.h>
74 1.2.14.2 matt #include <sys/fcntl.h>
75 1.2.14.2 matt #include <sys/conf.h>
76 1.2.14.2 matt #include <sys/tty.h>
77 1.2.14.2 matt #include <sys/file.h>
78 1.2.14.2 matt #if __FreeBSD_version >= 500014
79 1.2.14.2 matt #include <sys/selinfo.h>
80 1.2.14.2 matt #else
81 1.2.14.2 matt #include <sys/select.h>
82 1.2.14.2 matt #endif
83 1.2.14.2 matt #include <sys/proc.h>
84 1.2.14.2 matt #include <sys/device.h>
85 1.2.14.2 matt #include <sys/poll.h>
86 1.2.14.2 matt #include <sys/sysctl.h>
87 1.2.14.2 matt #include <sys/bus.h>
88 1.2.14.2 matt
89 1.2.14.2 matt #include <dev/usb/usb.h>
90 1.2.14.2 matt #include <dev/usb/usbdi.h>
91 1.2.14.2 matt #include <dev/usb/usbdi_util.h>
92 1.2.14.2 matt #include <dev/usb/usbdivar.h>
93 1.2.14.2 matt
94 1.2.14.2 matt #include <dev/usb/usbcdc.h>
95 1.2.14.2 matt #include <dev/usb/usbdevs.h>
96 1.2.14.2 matt #include <dev/usb/usb_quirks.h>
97 1.2.14.2 matt #include <dev/usb/ucomvar.h>
98 1.2.14.2 matt #include <dev/usb/ubsavar.h>
99 1.2.14.2 matt
100 1.2.14.2 matt #ifdef UBSA_DEBUG
101 1.2.14.2 matt extern int ubsadebug;
102 1.2.14.2 matt #define DPRINTFN(n, x) do { \
103 1.2.14.2 matt if (ubsadebug > (n)) \
104 1.2.14.2 matt logprintf x; \
105 1.2.14.2 matt } while (0)
106 1.2.14.2 matt #else
107 1.2.14.2 matt #define DPRINTFN(n, x)
108 1.2.14.2 matt #endif
109 1.2.14.2 matt #define DPRINTF(x) DPRINTFN(0, x)
110 1.2.14.2 matt
111 1.2.14.2 matt int
112 1.2.14.2 matt ubsa_request(struct ubsa_softc *sc, int portno, u_int8_t request, u_int16_t value)
113 1.2.14.2 matt {
114 1.2.14.2 matt usb_device_request_t req;
115 1.2.14.2 matt usbd_status err;
116 1.2.14.2 matt
117 1.2.14.2 matt if (sc->sc_quadumts)
118 1.2.14.2 matt req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
119 1.2.14.2 matt else
120 1.2.14.2 matt req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
121 1.2.14.2 matt
122 1.2.14.2 matt if (portno > UBSA_MAXCONN) {
123 1.2.14.2 matt printf("%s: ubsa_request: invalid port(%d)#\n",
124 1.2.14.2 matt USBDEVNAME(sc->sc_dev), portno);
125 1.2.14.2 matt return USBD_INVAL;
126 1.2.14.2 matt }
127 1.2.14.2 matt
128 1.2.14.2 matt req.bRequest = request;
129 1.2.14.2 matt USETW(req.wValue, value);
130 1.2.14.2 matt USETW(req.wIndex, sc->sc_iface_number[portno]);
131 1.2.14.2 matt USETW(req.wLength, 0);
132 1.2.14.2 matt
133 1.2.14.2 matt err = usbd_do_request(sc->sc_udev, &req, 0);
134 1.2.14.2 matt if (err)
135 1.2.14.2 matt printf("%s: ubsa_request: %s\n",
136 1.2.14.2 matt USBDEVNAME(sc->sc_dev), usbd_errstr(err));
137 1.2.14.2 matt return (err);
138 1.2.14.2 matt }
139 1.2.14.2 matt
140 1.2.14.2 matt void
141 1.2.14.2 matt ubsa_dtr(struct ubsa_softc *sc, int portno, int onoff)
142 1.2.14.2 matt {
143 1.2.14.2 matt
144 1.2.14.2 matt DPRINTF(("ubsa_dtr: onoff = %d\n", onoff));
145 1.2.14.2 matt
146 1.2.14.2 matt if (sc->sc_dtr == onoff)
147 1.2.14.2 matt return;
148 1.2.14.2 matt sc->sc_dtr = onoff;
149 1.2.14.2 matt
150 1.2.14.2 matt ubsa_request(sc, portno, UBSA_SET_DTR, onoff ? 1 : 0);
151 1.2.14.2 matt }
152 1.2.14.2 matt
153 1.2.14.2 matt void
154 1.2.14.2 matt ubsa_rts(struct ubsa_softc *sc, int portno, int onoff)
155 1.2.14.2 matt {
156 1.2.14.2 matt
157 1.2.14.2 matt DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
158 1.2.14.2 matt
159 1.2.14.2 matt if (sc->sc_rts == onoff)
160 1.2.14.2 matt return;
161 1.2.14.2 matt sc->sc_rts = onoff;
162 1.2.14.2 matt
163 1.2.14.2 matt ubsa_request(sc, portno, UBSA_SET_RTS, onoff ? 1 : 0);
164 1.2.14.2 matt }
165 1.2.14.2 matt
166 1.2.14.2 matt void
167 1.2.14.2 matt ubsa_quadumts_dtr(struct ubsa_softc *sc, int portno, int onoff)
168 1.2.14.2 matt {
169 1.2.14.2 matt
170 1.2.14.2 matt DPRINTF(("ubsa_dtr: onoff = %d\n", onoff));
171 1.2.14.2 matt
172 1.2.14.2 matt if (sc->sc_dtr == onoff)
173 1.2.14.2 matt return;
174 1.2.14.2 matt sc->sc_dtr = onoff;
175 1.2.14.2 matt
176 1.2.14.2 matt ubsa_request(sc, portno, UBSA_QUADUMTS_SET_PIN,
177 1.2.14.2 matt (sc->sc_rts ? 2 : 0)+(sc->sc_dtr ? 1 : 0));
178 1.2.14.2 matt }
179 1.2.14.2 matt
180 1.2.14.2 matt void
181 1.2.14.2 matt ubsa_quadumts_rts(struct ubsa_softc *sc, int portno, int onoff)
182 1.2.14.2 matt {
183 1.2.14.2 matt
184 1.2.14.2 matt DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
185 1.2.14.2 matt
186 1.2.14.2 matt if (sc->sc_rts == onoff)
187 1.2.14.2 matt return;
188 1.2.14.2 matt sc->sc_rts = onoff;
189 1.2.14.2 matt
190 1.2.14.2 matt ubsa_request(sc, portno, UBSA_QUADUMTS_SET_PIN,
191 1.2.14.2 matt (sc->sc_rts ? 2 : 0)+(sc->sc_dtr ? 1 : 0));
192 1.2.14.2 matt }
193 1.2.14.2 matt
194 1.2.14.2 matt void
195 1.2.14.2 matt ubsa_break(struct ubsa_softc *sc, int portno, int onoff)
196 1.2.14.2 matt {
197 1.2.14.2 matt DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
198 1.2.14.2 matt
199 1.2.14.2 matt ubsa_request(sc, portno, UBSA_SET_BREAK, onoff ? 1 : 0);
200 1.2.14.2 matt }
201 1.2.14.2 matt
202 1.2.14.2 matt void
203 1.2.14.2 matt ubsa_set(void *addr, int portno, int reg, int onoff)
204 1.2.14.2 matt {
205 1.2.14.2 matt struct ubsa_softc *sc;
206 1.2.14.2 matt
207 1.2.14.2 matt sc = addr;
208 1.2.14.2 matt switch (reg) {
209 1.2.14.2 matt case UCOM_SET_DTR:
210 1.2.14.2 matt if (sc->sc_quadumts)
211 1.2.14.2 matt ubsa_quadumts_dtr(sc, portno, onoff);
212 1.2.14.2 matt else
213 1.2.14.2 matt ubsa_dtr(sc, portno, onoff);
214 1.2.14.2 matt break;
215 1.2.14.2 matt case UCOM_SET_RTS:
216 1.2.14.2 matt if (sc->sc_quadumts)
217 1.2.14.2 matt ubsa_quadumts_rts(sc, portno, onoff);
218 1.2.14.2 matt else
219 1.2.14.2 matt ubsa_rts(sc, portno, onoff);
220 1.2.14.2 matt break;
221 1.2.14.2 matt case UCOM_SET_BREAK:
222 1.2.14.2 matt if (!sc->sc_quadumts)
223 1.2.14.2 matt ubsa_break(sc, portno, onoff);
224 1.2.14.2 matt break;
225 1.2.14.2 matt default:
226 1.2.14.2 matt break;
227 1.2.14.2 matt }
228 1.2.14.2 matt }
229 1.2.14.2 matt
230 1.2.14.2 matt void
231 1.2.14.2 matt ubsa_baudrate(struct ubsa_softc *sc, int portno, speed_t speed)
232 1.2.14.2 matt {
233 1.2.14.2 matt u_int16_t value = 0;
234 1.2.14.2 matt
235 1.2.14.2 matt DPRINTF(("ubsa_baudrate: speed = %d\n", speed));
236 1.2.14.2 matt
237 1.2.14.2 matt switch(speed) {
238 1.2.14.2 matt case B0:
239 1.2.14.2 matt break;
240 1.2.14.2 matt case B300:
241 1.2.14.2 matt case B600:
242 1.2.14.2 matt case B1200:
243 1.2.14.2 matt case B2400:
244 1.2.14.2 matt case B4800:
245 1.2.14.2 matt case B9600:
246 1.2.14.2 matt case B19200:
247 1.2.14.2 matt case B38400:
248 1.2.14.2 matt case B57600:
249 1.2.14.2 matt case B115200:
250 1.2.14.2 matt case B230400:
251 1.2.14.2 matt value = B230400 / speed;
252 1.2.14.2 matt break;
253 1.2.14.2 matt default:
254 1.2.14.2 matt printf("%s: ubsa_param: unsupported baudrate, "
255 1.2.14.2 matt "forcing default of 9600\n",
256 1.2.14.2 matt USBDEVNAME(sc->sc_dev));
257 1.2.14.2 matt value = B230400 / B9600;
258 1.2.14.2 matt break;
259 1.2.14.2 matt };
260 1.2.14.2 matt
261 1.2.14.2 matt if (speed == B0) {
262 1.2.14.2 matt ubsa_flow(sc, portno, 0, 0);
263 1.2.14.2 matt ubsa_dtr(sc, portno, 0);
264 1.2.14.2 matt ubsa_rts(sc, portno, 0);
265 1.2.14.2 matt } else
266 1.2.14.2 matt ubsa_request(sc, portno, UBSA_SET_BAUDRATE, value);
267 1.2.14.2 matt }
268 1.2.14.2 matt
269 1.2.14.2 matt void
270 1.2.14.2 matt ubsa_parity(struct ubsa_softc *sc, int portno, tcflag_t cflag)
271 1.2.14.2 matt {
272 1.2.14.2 matt int value;
273 1.2.14.2 matt
274 1.2.14.2 matt DPRINTF(("ubsa_parity: cflag = 0x%x\n", cflag));
275 1.2.14.2 matt
276 1.2.14.2 matt if (cflag & PARENB)
277 1.2.14.2 matt value = (cflag & PARODD) ? UBSA_PARITY_ODD : UBSA_PARITY_EVEN;
278 1.2.14.2 matt else
279 1.2.14.2 matt value = UBSA_PARITY_NONE;
280 1.2.14.2 matt
281 1.2.14.2 matt ubsa_request(sc, portno, UBSA_SET_PARITY, value);
282 1.2.14.2 matt }
283 1.2.14.2 matt
284 1.2.14.2 matt void
285 1.2.14.2 matt ubsa_databits(struct ubsa_softc *sc, int portno, tcflag_t cflag)
286 1.2.14.2 matt {
287 1.2.14.2 matt int value;
288 1.2.14.2 matt
289 1.2.14.2 matt DPRINTF(("ubsa_databits: cflag = 0x%x\n", cflag));
290 1.2.14.2 matt
291 1.2.14.2 matt switch (cflag & CSIZE) {
292 1.2.14.2 matt case CS5: value = 0; break;
293 1.2.14.2 matt case CS6: value = 1; break;
294 1.2.14.2 matt case CS7: value = 2; break;
295 1.2.14.2 matt case CS8: value = 3; break;
296 1.2.14.2 matt default:
297 1.2.14.2 matt printf("%s: ubsa_param: unsupported databits requested, "
298 1.2.14.2 matt "forcing default of 8\n",
299 1.2.14.2 matt USBDEVNAME(sc->sc_dev));
300 1.2.14.2 matt value = 3;
301 1.2.14.2 matt }
302 1.2.14.2 matt
303 1.2.14.2 matt ubsa_request(sc, portno, UBSA_SET_DATA_BITS, value);
304 1.2.14.2 matt }
305 1.2.14.2 matt
306 1.2.14.2 matt void
307 1.2.14.2 matt ubsa_stopbits(struct ubsa_softc *sc, int portno, tcflag_t cflag)
308 1.2.14.2 matt {
309 1.2.14.2 matt int value;
310 1.2.14.2 matt
311 1.2.14.2 matt DPRINTF(("ubsa_stopbits: cflag = 0x%x\n", cflag));
312 1.2.14.2 matt
313 1.2.14.2 matt value = (cflag & CSTOPB) ? 1 : 0;
314 1.2.14.2 matt
315 1.2.14.2 matt ubsa_request(sc, portno, UBSA_SET_STOP_BITS, value);
316 1.2.14.2 matt }
317 1.2.14.2 matt
318 1.2.14.2 matt void
319 1.2.14.2 matt ubsa_flow(struct ubsa_softc *sc, int portno, tcflag_t cflag, tcflag_t iflag)
320 1.2.14.2 matt {
321 1.2.14.2 matt int value;
322 1.2.14.2 matt
323 1.2.14.2 matt DPRINTF(("ubsa_flow: cflag = 0x%x, iflag = 0x%x\n", cflag, iflag));
324 1.2.14.2 matt
325 1.2.14.2 matt value = 0;
326 1.2.14.2 matt if (cflag & CRTSCTS)
327 1.2.14.2 matt value |= UBSA_FLOW_OCTS | UBSA_FLOW_IRTS;
328 1.2.14.2 matt if (iflag & (IXON|IXOFF))
329 1.2.14.2 matt value |= UBSA_FLOW_OXON | UBSA_FLOW_IXON;
330 1.2.14.2 matt
331 1.2.14.2 matt ubsa_request(sc, portno, UBSA_SET_FLOW_CTRL, value);
332 1.2.14.2 matt }
333 1.2.14.2 matt
334 1.2.14.2 matt int
335 1.2.14.2 matt ubsa_param(void *addr, int portno, struct termios *ti)
336 1.2.14.2 matt {
337 1.2.14.2 matt struct ubsa_softc *sc = addr;
338 1.2.14.2 matt
339 1.2.14.2 matt DPRINTF(("ubsa_param: sc = %p\n", sc));
340 1.2.14.2 matt
341 1.2.14.2 matt if (!sc->sc_quadumts) {
342 1.2.14.2 matt ubsa_baudrate(sc, portno, ti->c_ospeed);
343 1.2.14.2 matt ubsa_parity(sc, portno, ti->c_cflag);
344 1.2.14.2 matt ubsa_databits(sc, portno, ti->c_cflag);
345 1.2.14.2 matt ubsa_stopbits(sc, portno, ti->c_cflag);
346 1.2.14.2 matt ubsa_flow(sc, portno, ti->c_cflag, ti->c_iflag);
347 1.2.14.2 matt }
348 1.2.14.2 matt
349 1.2.14.2 matt return (0);
350 1.2.14.2 matt }
351 1.2.14.2 matt
352 1.2.14.2 matt int
353 1.2.14.2 matt ubsa_open(void *addr, int portno)
354 1.2.14.2 matt {
355 1.2.14.2 matt struct ubsa_softc *sc = addr;
356 1.2.14.2 matt int err;
357 1.2.14.2 matt
358 1.2.14.2 matt if (sc->sc_dying)
359 1.2.14.2 matt return (ENXIO);
360 1.2.14.2 matt
361 1.2.14.2 matt if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
362 1.2.14.2 matt sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
363 1.2.14.2 matt /* XXX only iface# = 0 has intr line */
364 1.2.14.2 matt /* XXX E220 specific? need to check */
365 1.2.14.2 matt err = usbd_open_pipe_intr(sc->sc_iface[0],
366 1.2.14.2 matt sc->sc_intr_number,
367 1.2.14.2 matt USBD_SHORT_XFER_OK,
368 1.2.14.2 matt &sc->sc_intr_pipe,
369 1.2.14.2 matt sc,
370 1.2.14.2 matt sc->sc_intr_buf,
371 1.2.14.2 matt sc->sc_isize,
372 1.2.14.2 matt ubsa_intr,
373 1.2.14.2 matt UBSA_INTR_INTERVAL);
374 1.2.14.2 matt if (err) {
375 1.2.14.2 matt printf("%s: cannot open interrupt pipe (addr %d)\n",
376 1.2.14.2 matt USBDEVNAME(sc->sc_dev),
377 1.2.14.2 matt sc->sc_intr_number);
378 1.2.14.2 matt return (EIO);
379 1.2.14.2 matt }
380 1.2.14.2 matt }
381 1.2.14.2 matt
382 1.2.14.2 matt return (0);
383 1.2.14.2 matt }
384 1.2.14.2 matt
385 1.2.14.2 matt void
386 1.2.14.2 matt ubsa_close(void *addr, int portno)
387 1.2.14.2 matt {
388 1.2.14.2 matt struct ubsa_softc *sc = addr;
389 1.2.14.2 matt int err;
390 1.2.14.2 matt
391 1.2.14.2 matt if (sc->sc_dying)
392 1.2.14.2 matt return;
393 1.2.14.2 matt
394 1.2.14.2 matt DPRINTF(("ubsa_close: close\n"));
395 1.2.14.2 matt
396 1.2.14.2 matt if (sc->sc_intr_pipe != NULL) {
397 1.2.14.2 matt err = usbd_abort_pipe(sc->sc_intr_pipe);
398 1.2.14.2 matt if (err)
399 1.2.14.2 matt printf("%s: abort interrupt pipe failed: %s\n",
400 1.2.14.2 matt USBDEVNAME(sc->sc_dev),
401 1.2.14.2 matt usbd_errstr(err));
402 1.2.14.2 matt err = usbd_close_pipe(sc->sc_intr_pipe);
403 1.2.14.2 matt if (err)
404 1.2.14.2 matt printf("%s: close interrupt pipe failed: %s\n",
405 1.2.14.2 matt USBDEVNAME(sc->sc_dev),
406 1.2.14.2 matt usbd_errstr(err));
407 1.2.14.2 matt free(sc->sc_intr_buf, M_USBDEV);
408 1.2.14.2 matt sc->sc_intr_pipe = NULL;
409 1.2.14.2 matt }
410 1.2.14.2 matt }
411 1.2.14.2 matt
412 1.2.14.2 matt void
413 1.2.14.2 matt ubsa_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
414 1.2.14.2 matt usbd_status status)
415 1.2.14.2 matt {
416 1.2.14.2 matt struct ubsa_softc *sc = priv;
417 1.2.14.2 matt u_char *buf;
418 1.2.14.2 matt int i;
419 1.2.14.2 matt
420 1.2.14.2 matt buf = sc->sc_intr_buf;
421 1.2.14.2 matt if (sc->sc_dying)
422 1.2.14.2 matt return;
423 1.2.14.2 matt
424 1.2.14.2 matt if (status != USBD_NORMAL_COMPLETION) {
425 1.2.14.2 matt if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
426 1.2.14.2 matt return;
427 1.2.14.2 matt
428 1.2.14.2 matt DPRINTF(("%s: ubsa_intr: abnormal status: %s\n",
429 1.2.14.2 matt USBDEVNAME(sc->sc_dev), usbd_errstr(status)));
430 1.2.14.2 matt usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
431 1.2.14.2 matt return;
432 1.2.14.2 matt }
433 1.2.14.2 matt
434 1.2.14.2 matt /* incidentally, Belkin adapter status bits match UART 16550 bits */
435 1.2.14.2 matt sc->sc_lsr = buf[2];
436 1.2.14.2 matt sc->sc_msr = buf[3];
437 1.2.14.2 matt
438 1.2.14.2 matt DPRINTF(("%s: ubsa lsr = 0x%02x, msr = 0x%02x\n",
439 1.2.14.2 matt USBDEVNAME(sc->sc_dev), sc->sc_lsr, sc->sc_msr));
440 1.2.14.2 matt
441 1.2.14.2 matt for (i = 0; i < sc->sc_numif; i++) {
442 1.2.14.2 matt ucom_status_change((struct ucom_softc *)sc->sc_subdevs[i]);
443 1.2.14.2 matt }
444 1.2.14.2 matt }
445 1.2.14.2 matt
446 1.2.14.2 matt void
447 1.2.14.2 matt ubsa_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
448 1.2.14.2 matt {
449 1.2.14.2 matt struct ubsa_softc *sc = addr;
450 1.2.14.2 matt
451 1.2.14.2 matt DPRINTF(("ubsa_get_status\n"));
452 1.2.14.2 matt
453 1.2.14.2 matt if (lsr != NULL)
454 1.2.14.2 matt *lsr = sc->sc_lsr;
455 1.2.14.2 matt if (msr != NULL)
456 1.2.14.2 matt *msr = sc->sc_msr;
457 1.2.14.2 matt }
458 1.2.14.2 matt
459