xref: /netbsd/sys/dev/usb/uslsa.c (revision 6550d01e)
1 /* $NetBSD: uslsa.c,v 1.12 2010/11/03 22:34:24 dyoung Exp $ */
2 
3 /* from ugensa.c */
4 
5 /*
6  * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Roland C. Dowdeswell <elric@netbsd.org>.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 2007, 2009 Jonathan A. Kollasch.
36  * All rights reserved.
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  *
47  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57  *
58  */
59 
60 /*
61  * Craig Shelley's Linux driver was used for documentation.
62  */
63 
64 #include <sys/cdefs.h>
65 __KERNEL_RCSID(0, "$NetBSD: uslsa.c,v 1.12 2010/11/03 22:34:24 dyoung Exp $");
66 
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/kernel.h>
70 #include <sys/device.h>
71 #include <sys/conf.h>
72 #include <sys/tty.h>
73 
74 #include <dev/usb/usb.h>
75 
76 #include <dev/usb/usbdi.h>
77 #include <dev/usb/usbdi_util.h>
78 #include <dev/usb/usbdevs.h>
79 
80 #include <dev/usb/ucomvar.h>
81 
82 #ifdef DEBUG
83 #define USLSA_DEBUG
84 #endif
85 
86 #ifdef USLSA_DEBUG
87 #define DPRINTF(x)	if (uslsadebug) printf x
88 #define DPRINTFN(n,x)	if (uslsadebug>(n)) printf x
89 int uslsadebug = 0;
90 #else
91 #define DPRINTF(x)
92 #define DPRINTFN(n,x)
93 #endif
94 
95 #define USLSA_REQ_SET_STATE	0x00
96 
97 #define USLSA_REQ_SET_BPS	0x01
98 #define USLSA_REQ_GET_BPS	0x02
99 
100 #define USLSA_REQ_SET_DPS	0x03
101 #define USLSA_REQ_GET_DPS	0x04
102 
103 #define USLSA_REQ_SET_BREAK	0x05
104 #define USLSA_REQ_GET_BREAK	0x06
105 
106 #define USLSA_REQ_SET_FLOW	0x07
107 #define USLSA_REQ_GET_FLOW	0x08
108 
109 #define USLSA_REQ_SET_MODEM	0x13
110 #define USLSA_REQ_GET_MODEM	0x14
111 
112 #define USLSA_REQ_SET_MISC	0x19
113 #define USLSA_REQ_GET_MISC	0x20
114 
115 #define USLSA_STATE_DISABLE	0x0000
116 #define USLSA_STATE_ENABLE	0x0001
117 
118 #define USLSA_BPS(b)	(3686400/b)
119 
120 #define USLSA_DPS_DATA_MASK		0x0f00
121 #define	USLSA_DPS_DATA_FIVE		0x0500
122 #define	USLSA_DPS_DATA_SIX		0x0600
123 #define	USLSA_DPS_DATA_SEVEN		0x0700
124 #define	USLSA_DPS_DATA_EIGHT		0x0800
125 #define	USLSA_DPS_DATA_NINE		0x0900
126 
127 #define USLSA_DPS_PARITY_MASK		0x00f0
128 #define USLSA_DPS_PARITY_SPACE		0x0040
129 #define USLSA_DPS_PARITY_MARK		0x0030
130 #define USLSA_DPS_PARITY_EVEN		0x0020
131 #define USLSA_DPS_PARITY_ODD		0x0010
132 #define USLSA_DPS_PARITY_NONE		0x0000
133 
134 #define USLSA_DPS_STOP_MASK		0x000f
135 #define USLSA_DPS_STOP_TWO		0x0002
136 #define USLSA_DPS_STOP_ONE_FIVE		0x0001
137 #define USLSA_DPS_STOP_ONE		0x0000
138 
139 #define USLSA_BREAK_DISABLE	0x0001
140 #define USLSA_BREAK_ENABLE	0x0000
141 
142 #define USLSA_FLOW_SET_RTS	0x0200
143 #define USLSA_FLOW_SET_DTR	0x0100
144 #define USLSA_FLOW_MSR_MASK	0x00f0
145 #define USLSA_FLOW_MSR_DCD	0x0080
146 #define USLSA_FLOW_MSR_RI	0x0040
147 #define USLSA_FLOW_MSR_DSR	0x0020
148 #define USLSA_FLOW_MSR_CTS	0x0010
149 #define USLSA_FLOW_RTS		0x0002
150 #define USLSA_FLOW_DTR		0x0001
151 
152 struct uslsa_softc {
153 	device_t		sc_dev;		/* base device */
154 	usbd_device_handle	sc_udev;	/* device */
155 	usbd_interface_handle	sc_iface;	/* interface */
156 
157 	device_t		sc_subdev;	/* ucom device */
158 
159 	u_char			sc_dying;	/* disconnecting */
160 
161 	u_char			sc_lsr;		/* local status register */
162 	u_char			sc_msr;		/* uslsa status register */
163 };
164 
165 static void uslsa_get_status(void *sc, int, u_char *, u_char *);
166 static void uslsa_set(void *, int, int, int);
167 static int uslsa_param(void *, int, struct termios *);
168 static int uslsa_open(void *, int);
169 static void uslsa_close(void *, int);
170 
171 static int uslsa_request_set(struct uslsa_softc *, uint8_t, uint16_t);
172 static void uslsa_set_flow(struct uslsa_softc *, tcflag_t, tcflag_t);
173 
174 struct ucom_methods uslsa_methods = {
175 	uslsa_get_status,
176 	uslsa_set,
177 	uslsa_param,
178 	NULL,
179 	uslsa_open,
180 	uslsa_close,
181 	NULL,
182 	NULL,
183 };
184 
185 #define USLSA_CONFIG_INDEX	0
186 #define USLSA_IFACE_INDEX	0
187 #define USLSA_BUFSIZE		256
188 
189 static const struct usb_devno uslsa_devs[] = {
190         { USB_VENDOR_BALTECH,           USB_PRODUCT_BALTECH_CARDREADER },
191         { USB_VENDOR_DYNASTREAM,        USB_PRODUCT_DYNASTREAM_ANTDEVBOARD },
192         { USB_VENDOR_JABLOTRON,         USB_PRODUCT_JABLOTRON_PC60B },
193         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_ARGUSISP },
194         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_CRUMB128 },
195         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_DEGREECONT },
196         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_DESKTOPMOBILE },
197         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_IPLINK1220 },
198         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_LIPOWSKY_HARP },
199         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_LIPOWSKY_JTAG },
200         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_LIPOWSKY_LIN },
201         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_POLOLU },
202         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_CP210X_1 },
203         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_CP210X_2 },
204         { USB_VENDOR_SILABS,            USB_PRODUCT_SILABS_SUNNTO },
205         { USB_VENDOR_SILABS2,           USB_PRODUCT_SILABS2_DCU11CLONE },
206         { USB_VENDOR_USI,               USB_PRODUCT_USI_MC60 }
207 };
208 #define uslsa_lookup(v, p) usb_lookup(uslsa_devs, v, p)
209 
210 int uslsa_match(device_t, cfdata_t, void *);
211 void uslsa_attach(device_t, device_t, void *);
212 void uslsa_childdet(device_t, device_t);
213 int uslsa_detach(device_t, int);
214 int uslsa_activate(device_t, enum devact);
215 extern struct cfdriver uslsa_cd;
216 CFATTACH_DECL2_NEW(uslsa, sizeof(struct uslsa_softc), uslsa_match,
217     uslsa_attach, uslsa_detach, uslsa_activate, NULL, uslsa_childdet);
218 
219 int
220 uslsa_match(device_t parent, cfdata_t match, void *aux)
221 {
222 	struct usb_attach_arg *uaa = aux;
223 
224 	return (uslsa_lookup(uaa->vendor, uaa->product) != NULL ?
225 	        UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
226 }
227 
228 void
229 uslsa_attach(device_t parent, device_t self, void *aux)
230 {
231 	struct uslsa_softc *sc = device_private(self);
232 	struct usb_attach_arg *uaa = aux;
233 	usbd_device_handle dev = uaa->device;
234 	usbd_interface_handle iface;
235 	usb_interface_descriptor_t *id;
236 	usb_endpoint_descriptor_t *ed;
237 	char *devinfop;
238 	usbd_status err;
239 	struct ucom_attach_args uca;
240 	int i;
241 
242 	sc->sc_dev = self;
243 
244 	DPRINTFN(10, ("\nuslsa_attach: sc=%p\n", sc));
245 
246 	aprint_naive("\n");
247 	aprint_normal("\n");
248 
249 	devinfop = usbd_devinfo_alloc(dev, 0);
250 	aprint_normal_dev(self, "%s\n", devinfop);
251 	usbd_devinfo_free(devinfop);
252 
253 	/* Move the device into the configured state. */
254 	err = usbd_set_config_index(dev, USLSA_CONFIG_INDEX, 1);
255 	if (err) {
256 		aprint_error_dev(self, "failed to set configuration, err=%s\n",
257 		   usbd_errstr(err));
258 		goto bad;
259 	}
260 
261 	err = usbd_device2interface_handle(dev, USLSA_IFACE_INDEX, &iface);
262 	if (err) {
263 		aprint_error_dev(self, "failed to get interface, err=%s\n",
264 		   usbd_errstr(err));
265 		goto bad;
266 	}
267 
268 	id = usbd_get_interface_descriptor(iface);
269 
270 	sc->sc_udev = dev;
271 	sc->sc_iface = iface;
272 
273 	uca.info = "Silicon Labs CP210x";
274 	uca.portno = UCOM_UNK_PORTNO;
275 	uca.ibufsize = USLSA_BUFSIZE;
276 	uca.obufsize = USLSA_BUFSIZE;
277 	uca.ibufsizepad = USLSA_BUFSIZE;
278 	uca.opkthdrlen = 0;
279 	uca.device = dev;
280 	uca.iface = iface;
281 	uca.methods = &uslsa_methods;
282 	uca.arg = sc;
283 
284 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
285 	                   sc->sc_dev);
286 
287 	uca.bulkin = uca.bulkout = -1;
288 	for (i = 0; i < id->bNumEndpoints; i++) {
289 		int addr, dir, attr;
290 
291 		ed = usbd_interface2endpoint_descriptor(iface, i);
292 		if (ed == NULL) {
293 			aprint_error_dev(self,
294 			    "could not read endpoint descriptor: %s\n",
295 			    usbd_errstr(err));
296 			goto bad;
297 		}
298 		addr = ed->bEndpointAddress;
299 		dir = UE_GET_DIR(ed->bEndpointAddress);
300 		attr = ed->bmAttributes & UE_XFERTYPE;
301 		if (dir == UE_DIR_IN && attr == UE_BULK)
302 			uca.bulkin = addr;
303 		else if (dir == UE_DIR_OUT && attr == UE_BULK)
304 			uca.bulkout = addr;
305 		else
306 			aprint_error_dev(self, "unexpected endpoint\n");
307 	}
308 	if (uca.bulkin == -1) {
309 		aprint_error_dev(self, "Could not find data bulk in\n");
310 		goto bad;
311 	}
312 	if (uca.bulkout == -1) {
313 		aprint_error_dev(self, "Could not find data bulk out\n");
314 		goto bad;
315 	}
316 
317 	DPRINTF(("uslsa: in=0x%x out=0x%x\n", uca.bulkin, uca.bulkout));
318 	sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, &uca,
319 	                                    ucomprint, ucomsubmatch);
320 
321 	return;
322 
323 bad:
324 	DPRINTF(("uslsa_attach: ATTACH ERROR\n"));
325 	sc->sc_dying = 1;
326 	return;
327 }
328 
329 int
330 uslsa_activate(device_t self, enum devact act)
331 {
332 	struct uslsa_softc *sc = device_private(self);
333 
334 	switch (act) {
335 	case DVACT_DEACTIVATE:
336 		sc->sc_dying = 1;
337 		return 0;
338 	default:
339 		return EOPNOTSUPP;
340 	}
341 }
342 
343 void
344 uslsa_childdet(device_t self, device_t child)
345 {
346 	struct uslsa_softc *sc = device_private(self);
347 
348 	KASSERT(sc->sc_subdev == child);
349 	sc->sc_subdev = NULL;
350 }
351 
352 int
353 uslsa_detach(device_t self, int flags)
354 {
355 	struct uslsa_softc *sc = device_private(self);
356 	int rv = 0;
357 
358 	DPRINTF(("uslsa_detach: sc=%p flags=%d\n", sc, flags));
359 
360 	sc->sc_dying = 1;
361 
362 	if (sc->sc_subdev != NULL)
363 		rv = config_detach(sc->sc_subdev, flags);
364 
365 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
366 	                   sc->sc_dev);
367 
368 	return (rv);
369 }
370 
371 static void
372 uslsa_get_status(void *vsc, int portno, u_char *lsr, u_char *msr)
373 {
374 	struct uslsa_softc *sc;
375 	usb_device_request_t req;
376 	usbd_status err;
377 	int actlen;
378 	uint16_t flowreg;
379 
380 	sc = vsc;
381 
382 	DPRINTF(("uslsa_get_status:\n"));
383 
384 	req.bmRequestType = UT_READ_VENDOR_INTERFACE;
385 	req.bRequest = USLSA_REQ_GET_FLOW;
386 	USETW(req.wValue, 0);
387 	USETW(req.wIndex, 0);
388 	USETW(req.wLength, sizeof(flowreg));
389 
390 	err = usbd_do_request_flags(sc->sc_udev, &req, &flowreg,
391 	    USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
392 	if (err)
393 		printf("%s: uslsa_get_status: %s\n",
394 		    device_xname(sc->sc_dev), usbd_errstr(err));
395 
396 	DPRINTF(("uslsa_get_status: flowreg=0x%x\n", flowreg));
397 
398 	sc->sc_msr = (u_char)(USLSA_FLOW_MSR_MASK & flowreg);
399 
400 	if (lsr != NULL)
401 		*lsr = sc->sc_lsr;
402 	if (msr != NULL)
403 		*msr = sc->sc_msr;
404 }
405 
406 static void
407 uslsa_set(void *vsc, int portno, int reg, int onoff)
408 {
409 	struct uslsa_softc *sc;
410 
411 	sc = vsc;
412 
413 	DPRINTF(("uslsa_set: sc=%p, port=%d reg=%d onoff=%d\n", sc, portno,
414 	         reg, onoff));
415 
416 	switch (reg) {
417 	case UCOM_SET_DTR:
418 		if (uslsa_request_set(sc, USLSA_REQ_SET_FLOW,
419 			(onoff ? (USLSA_FLOW_DTR | USLSA_FLOW_SET_DTR) :
420 			    USLSA_FLOW_SET_DTR)))
421 			printf("%s: uslsa_set_dtr failed\n",
422 			       device_xname(sc->sc_dev));
423 		break;
424 	case UCOM_SET_RTS:
425 		if (uslsa_request_set(sc, USLSA_REQ_SET_FLOW,
426 			(onoff ? (USLSA_FLOW_RTS | USLSA_FLOW_SET_RTS) :
427 			    USLSA_FLOW_SET_RTS)))
428 			printf("%s: uslsa_set_rts failed\n",
429 			       device_xname(sc->sc_dev));
430 		break;
431 	case UCOM_SET_BREAK:
432 		if (uslsa_request_set(sc, USLSA_REQ_SET_BREAK,
433 			(onoff ? USLSA_BREAK_ENABLE :
434 			    USLSA_BREAK_DISABLE)))
435 			printf("%s: uslsa_set_break failed\n",
436 			       device_xname(sc->sc_dev));
437 		break;
438 	default:
439 		break;
440 	}
441 }
442 
443 static int
444 uslsa_param(void *vsc, int portno, struct termios * t)
445 {
446 	struct uslsa_softc *sc;
447 	uint16_t data;
448 
449 	sc = vsc;
450 
451 	DPRINTF(("uslsa_param: sc=%p\n", sc));
452 
453 	switch (t->c_ospeed) {
454 	case B600:
455 	case B1200:
456 	case B2400:
457 	case B4800:
458 	case B9600:
459 	case B19200:
460 	case B38400:
461 	case B57600:
462 	case B115200:
463 	case B230400:
464 	case B460800:
465 	case B921600:
466 		data = USLSA_BPS(t->c_ospeed);
467 		break;
468 	default:
469 		printf("%s: uslsa_param: unsupported data rate, "
470 		       "forcing default of 115200bps\n",
471 		       device_xname(sc->sc_dev));
472 		data = USLSA_BPS(B115200);
473 	};
474 
475 	if (uslsa_request_set(sc, USLSA_REQ_SET_BPS, data))
476 		printf("%s: uslsa_param: setting data rate failed\n",
477 		       device_xname(sc->sc_dev));
478 
479 	data = 0;
480 
481 	if (ISSET(t->c_cflag, CSTOPB))
482 		data |= USLSA_DPS_STOP_TWO;
483 	else
484 		data |= USLSA_DPS_STOP_ONE;
485 
486 	if (ISSET(t->c_cflag, PARENB)) {
487 		if (ISSET(t->c_cflag, PARODD))
488 			data |= USLSA_DPS_PARITY_ODD;
489 		else
490 			data |= USLSA_DPS_PARITY_EVEN;
491 	} else
492 		data |= USLSA_DPS_PARITY_NONE;
493 
494 	switch (ISSET(t->c_cflag, CSIZE)) {
495 	case CS5:
496 		data |= USLSA_DPS_DATA_FIVE;
497 		break;
498 	case CS6:
499 		data |= USLSA_DPS_DATA_SIX;
500 		break;
501 	case CS7:
502 		data |= USLSA_DPS_DATA_SEVEN;
503 		break;
504 	case CS8:
505 		data |= USLSA_DPS_DATA_EIGHT;
506 		break;
507 	}
508 
509 	DPRINTF(("uslsa_param: setting DPS register to 0x%x\n", data));
510 	if (uslsa_request_set(sc, USLSA_REQ_SET_DPS, data))
511 		printf("%s: setting DPS register failed: invalid argument\n",
512 		       device_xname(sc->sc_dev));
513 
514 	uslsa_set_flow(sc, t->c_cflag, t->c_iflag);
515 
516 	return 0;
517 }
518 
519 
520 static int
521 uslsa_open(void *vsc, int portno)
522 {
523 	struct uslsa_softc *sc;
524 
525 	sc = vsc;
526 
527 	DPRINTF(("uslsa_open: sc=%p\n", sc));
528 
529 	if (sc->sc_dying)
530 		return (EIO);
531 
532 	if (uslsa_request_set(sc, USLSA_REQ_SET_STATE, USLSA_STATE_ENABLE))
533 		return (EIO);
534 
535 	return 0;
536 }
537 
538 void
539 uslsa_close(void *vsc, int portno)
540 {
541 	struct uslsa_softc *sc;
542 
543 	sc = vsc;
544 
545 	if (sc->sc_dying)
546 		return;
547 
548 	DPRINTF(("uslsa_close: sc=%p\n", sc));
549 
550 	if (uslsa_request_set(sc, USLSA_REQ_SET_STATE,
551 	    USLSA_STATE_DISABLE))
552 		printf("%s: disable-on-close failed\n",
553 		       device_xname(sc->sc_dev));
554 }
555 
556 /*
557  * uslsa_request_set(), wrapper for doing sets with usbd_do_request()
558  */
559 static int
560 uslsa_request_set(struct uslsa_softc * sc, uint8_t request, uint16_t value)
561 {
562 	usb_device_request_t req;
563 	usbd_status err;
564 
565 	req.bmRequestType = UT_WRITE_VENDOR_INTERFACE;
566 	req.bRequest = request;
567 	USETW(req.wValue, value);
568 	USETW(req.wIndex, 0);
569 	USETW(req.wLength, 0);
570 
571 	err = usbd_do_request(sc->sc_udev, &req, 0);
572 	if (err)
573 		printf("%s: uslsa_request: %s\n",
574 		       device_xname(sc->sc_dev), usbd_errstr(err));
575 	return err;
576 }
577 
578 /*
579  * uslsa_set_flow() does some magic to set up hardware flow control
580  */
581 static void
582 uslsa_set_flow(struct uslsa_softc *sc, tcflag_t cflag, tcflag_t iflag)
583 {
584 	uint8_t mysterydata[16];
585 	usb_device_request_t req;
586 	usbd_status err;
587 
588 	DPRINTF(("uslsa_set_flow: cflag = 0x%x, iflag = 0x%x\n",
589 	         cflag, iflag));
590 
591 	req.bmRequestType = UT_READ_VENDOR_INTERFACE;
592 	req.bRequest = USLSA_REQ_GET_MODEM;
593 	USETW(req.wValue, 0);
594 	USETW(req.wIndex, 0);
595 	USETW(req.wLength, 16);
596 
597 	err = usbd_do_request(sc->sc_udev, &req, mysterydata);
598 	if (err)
599 		printf("%s: uslsa_set_flow: %s\n",
600 		       device_xname(sc->sc_dev), usbd_errstr(err));
601 
602 	if (ISSET(cflag, CRTSCTS)) {
603 		mysterydata[0] &= ~0x7b;
604 		mysterydata[0] |= 0x09;
605 		mysterydata[4] = 0x80;
606 	} else {
607 		mysterydata[0] &= ~0x7b;
608 		mysterydata[0] |= 0x01;
609 		mysterydata[4] = 0x40;
610 	}
611 
612 	req.bmRequestType = UT_WRITE_VENDOR_INTERFACE;
613 	req.bRequest = USLSA_REQ_SET_MODEM;
614 	USETW(req.wValue, 0);
615 	USETW(req.wIndex, 0);
616 	USETW(req.wLength, 16);
617 
618 	err = usbd_do_request(sc->sc_udev, &req, mysterydata);
619 	if (err)
620 		printf("%s: uslsa_set_flow: %s\n",
621 		       device_xname(sc->sc_dev), usbd_errstr(err));
622 }
623