uplcom.c revision 1.66 1 1.66 martin /* $NetBSD: uplcom.c,v 1.66 2008/09/16 20:00:17 martin Exp $ */
2 1.1 ichiro /*
3 1.3 ichiro * Copyright (c) 2001 The NetBSD Foundation, Inc.
4 1.1 ichiro * All rights reserved.
5 1.1 ichiro *
6 1.1 ichiro * This code is derived from software contributed to The NetBSD Foundation
7 1.12 ichiro * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
8 1.1 ichiro *
9 1.1 ichiro * Redistribution and use in source and binary forms, with or without
10 1.1 ichiro * modification, are permitted provided that the following conditions
11 1.1 ichiro * are met:
12 1.1 ichiro * 1. Redistributions of source code must retain the above copyright
13 1.1 ichiro * notice, this list of conditions and the following disclaimer.
14 1.1 ichiro * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 ichiro * notice, this list of conditions and the following disclaimer in the
16 1.1 ichiro * documentation and/or other materials provided with the distribution.
17 1.1 ichiro *
18 1.1 ichiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.1 ichiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.1 ichiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.1 ichiro * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.1 ichiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.1 ichiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.1 ichiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.1 ichiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.1 ichiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.1 ichiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.1 ichiro * POSSIBILITY OF SUCH DAMAGE.
29 1.1 ichiro */
30 1.1 ichiro
31 1.1 ichiro /*
32 1.31 wiz * General information: http://www.prolific.com.tw/fr_pl2303.htm
33 1.31 wiz * http://www.hitachi-hitec.com/jyouhou/prolific/2303.pdf
34 1.1 ichiro */
35 1.21 lukem
36 1.21 lukem #include <sys/cdefs.h>
37 1.66 martin __KERNEL_RCSID(0, "$NetBSD: uplcom.c,v 1.66 2008/09/16 20:00:17 martin Exp $");
38 1.1 ichiro
39 1.1 ichiro #include <sys/param.h>
40 1.1 ichiro #include <sys/systm.h>
41 1.1 ichiro #include <sys/kernel.h>
42 1.12 ichiro #include <sys/malloc.h>
43 1.1 ichiro #include <sys/ioctl.h>
44 1.1 ichiro #include <sys/conf.h>
45 1.1 ichiro #include <sys/tty.h>
46 1.1 ichiro #include <sys/file.h>
47 1.1 ichiro #include <sys/select.h>
48 1.1 ichiro #include <sys/proc.h>
49 1.1 ichiro #include <sys/device.h>
50 1.1 ichiro #include <sys/poll.h>
51 1.1 ichiro
52 1.1 ichiro #include <dev/usb/usb.h>
53 1.1 ichiro #include <dev/usb/usbcdc.h>
54 1.1 ichiro
55 1.1 ichiro #include <dev/usb/usbdi.h>
56 1.1 ichiro #include <dev/usb/usbdi_util.h>
57 1.1 ichiro #include <dev/usb/usbdevs.h>
58 1.1 ichiro #include <dev/usb/usb_quirks.h>
59 1.1 ichiro
60 1.1 ichiro #include <dev/usb/ucomvar.h>
61 1.1 ichiro
62 1.1 ichiro #ifdef UPLCOM_DEBUG
63 1.1 ichiro #define DPRINTFN(n, x) if (uplcomdebug > (n)) logprintf x
64 1.12 ichiro int uplcomdebug = 0;
65 1.1 ichiro #else
66 1.1 ichiro #define DPRINTFN(n, x)
67 1.1 ichiro #endif
68 1.1 ichiro #define DPRINTF(x) DPRINTFN(0, x)
69 1.1 ichiro
70 1.1 ichiro #define UPLCOM_CONFIG_INDEX 0
71 1.10 ichiro #define UPLCOM_IFACE_INDEX 0
72 1.10 ichiro #define UPLCOM_SECOND_IFACE_INDEX 1
73 1.1 ichiro
74 1.19 ichiro #define UPLCOM_SET_REQUEST 0x01
75 1.43 augustss #define UPLCOM_SET_CRTSCTS_0 0x41
76 1.43 augustss #define UPLCOM_SET_CRTSCTS_HX 0x61
77 1.12 ichiro #define RSAQ_STATUS_DSR 0x02
78 1.12 ichiro #define RSAQ_STATUS_DCD 0x01
79 1.12 ichiro
80 1.43 augustss enum pl2303_type {
81 1.66 martin UPLCOM_TYPE_0, /* we use this for all non-HX variants */
82 1.43 augustss UPLCOM_TYPE_HX,
83 1.43 augustss };
84 1.43 augustss
85 1.1 ichiro struct uplcom_softc {
86 1.1 ichiro USBBASEDEVICE sc_dev; /* base device */
87 1.1 ichiro usbd_device_handle sc_udev; /* USB device */
88 1.14 ichiro usbd_interface_handle sc_iface; /* interface */
89 1.1 ichiro int sc_iface_number; /* interface number */
90 1.1 ichiro
91 1.20 ichiro usbd_interface_handle sc_intr_iface; /* interrupt interface */
92 1.12 ichiro int sc_intr_number; /* interrupt number */
93 1.12 ichiro usbd_pipe_handle sc_intr_pipe; /* interrupt pipe */
94 1.12 ichiro u_char *sc_intr_buf; /* interrupt buffer */
95 1.12 ichiro int sc_isize;
96 1.12 ichiro
97 1.1 ichiro usb_cdc_line_state_t sc_line_state; /* current line state */
98 1.37 martin int sc_dtr; /* current DTR state */
99 1.37 martin int sc_rts; /* current RTS state */
100 1.1 ichiro
101 1.12 ichiro device_ptr_t sc_subdev; /* ucom device */
102 1.1 ichiro
103 1.13 ichiro u_char sc_dying; /* disconnecting */
104 1.12 ichiro
105 1.12 ichiro u_char sc_lsr; /* Local status register */
106 1.12 ichiro u_char sc_msr; /* uplcom status register */
107 1.43 augustss
108 1.43 augustss enum pl2303_type sc_type; /* PL2303 chip type */
109 1.1 ichiro };
110 1.1 ichiro
111 1.1 ichiro /*
112 1.1 ichiro * These are the maximum number of bytes transferred per frame.
113 1.1 ichiro * The output buffer size cannot be increased due to the size encoding.
114 1.1 ichiro */
115 1.6 augustss #define UPLCOMIBUFSIZE 256
116 1.6 augustss #define UPLCOMOBUFSIZE 256
117 1.1 ichiro
118 1.11 ichiro Static usbd_status uplcom_reset(struct uplcom_softc *);
119 1.1 ichiro Static usbd_status uplcom_set_line_coding(struct uplcom_softc *sc,
120 1.6 augustss usb_cdc_line_state_t *state);
121 1.19 ichiro Static usbd_status uplcom_set_crtscts(struct uplcom_softc *);
122 1.12 ichiro Static void uplcom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
123 1.1 ichiro
124 1.12 ichiro Static void uplcom_set(void *, int, int, int);
125 1.12 ichiro Static void uplcom_dtr(struct uplcom_softc *, int);
126 1.12 ichiro Static void uplcom_rts(struct uplcom_softc *, int);
127 1.12 ichiro Static void uplcom_break(struct uplcom_softc *, int);
128 1.12 ichiro Static void uplcom_set_line_state(struct uplcom_softc *);
129 1.12 ichiro Static void uplcom_get_status(void *, int portno, u_char *lsr, u_char *msr);
130 1.12 ichiro #if TODO
131 1.53 christos Static int uplcom_ioctl(void *, int, u_long, void *, int, usb_proc_ptr );
132 1.12 ichiro #endif
133 1.12 ichiro Static int uplcom_param(void *, int, struct termios *);
134 1.12 ichiro Static int uplcom_open(void *, int);
135 1.12 ichiro Static void uplcom_close(void *, int);
136 1.43 augustss Static usbd_status uplcom_vendor_control_write(usbd_device_handle, u_int16_t, u_int16_t);
137 1.1 ichiro
138 1.1 ichiro struct ucom_methods uplcom_methods = {
139 1.12 ichiro uplcom_get_status,
140 1.1 ichiro uplcom_set,
141 1.1 ichiro uplcom_param,
142 1.12 ichiro NULL, /* uplcom_ioctl, TODO */
143 1.11 ichiro uplcom_open,
144 1.11 ichiro uplcom_close,
145 1.1 ichiro NULL,
146 1.1 ichiro NULL,
147 1.1 ichiro };
148 1.1 ichiro
149 1.66 martin static const struct usb_devno uplcom_devs[] = {
150 1.1 ichiro /* I/O DATA USB-RSAQ2 */
151 1.66 martin { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_RSAQ2 },
152 1.48 martin /* I/O DATA USB-RSAQ3 */
153 1.66 martin { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_RSAQ3 },
154 1.13 ichiro /* I/O DATA USB-RSAQ */
155 1.66 martin { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBRSAQ },
156 1.55 uebayasi /* I/O DATA USB-RSAQ5 */
157 1.66 martin { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBRSAQ5 },
158 1.16 ichiro /* PLANEX USB-RS232 URS-03 */
159 1.66 martin { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC232A },
160 1.66 martin /* various */
161 1.66 martin { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303 },
162 1.58 sborrill /* SMART Technologies USB to serial */
163 1.66 martin { USB_VENDOR_PROLIFIC2, USB_PRODUCT_PROLIFIC2_PL2303 },
164 1.34 augustss /* IOGEAR/ATENTRIPPLITE */
165 1.66 martin { USB_VENDOR_TRIPPLITE, USB_PRODUCT_TRIPPLITE_U209 },
166 1.22 augustss /* ELECOM UC-SGT */
167 1.66 martin { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_UCSGT },
168 1.46 sekiya /* ELECOM UC-SGT0 */
169 1.66 martin { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_UCSGT0 },
170 1.44 pooka /* Panasonic 50" Touch Panel */
171 1.66 martin { USB_VENDOR_PANASONIC, USB_PRODUCT_PANASONIC_TYTP50P6S },
172 1.25 ichiro /* RATOC REX-USB60 */
173 1.66 martin { USB_VENDOR_RATOC, USB_PRODUCT_RATOC_REXUSB60 },
174 1.26 ichiro /* TDK USB-PHS Adapter UHA6400 */
175 1.66 martin { USB_VENDOR_TDK, USB_PRODUCT_TDK_UHA6400 },
176 1.27 ichiro /* TDK USB-PDC Adapter UPA9664 */
177 1.66 martin { USB_VENDOR_TDK, USB_PRODUCT_TDK_UPA9664 },
178 1.30 augustss /* Sony Ericsson USB Cable */
179 1.66 martin { USB_VENDOR_SUSTEEN, USB_PRODUCT_SUSTEEN_DCU10 },
180 1.32 augustss /* SOURCENEXT KeikaiDenwa 8 */
181 1.66 martin { USB_VENDOR_SOURCENEXT, USB_PRODUCT_SOURCENEXT_KEIKAI8 },
182 1.32 augustss /* SOURCENEXT KeikaiDenwa 8 with charger */
183 1.66 martin { USB_VENDOR_SOURCENEXT, USB_PRODUCT_SOURCENEXT_KEIKAI8_CHG },
184 1.32 augustss /* HAL Corporation Crossam2+USB */
185 1.66 martin { USB_VENDOR_HAL, USB_PRODUCT_HAL_IMR001 },
186 1.38 jdolecek /* Sitecom USB to serial cable */
187 1.66 martin { USB_VENDOR_SITECOM, USB_PRODUCT_SITECOM_CN104 },
188 1.41 augustss /* Pharos USB GPS - Microsoft version */
189 1.66 martin { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303X },
190 1.52 msaitoh /* Willcom WS002IN (DD) */
191 1.66 martin { USB_VENDOR_NETINDEX, USB_PRODUCT_NETINDEX_WS002IN },
192 1.1 ichiro };
193 1.23 augustss #define uplcom_lookup(v, p) usb_lookup(uplcom_devs, v, p)
194 1.32 augustss
195 1.65 cube int uplcom_match(device_t, cfdata_t, void *);
196 1.60 dyoung void uplcom_attach(device_t, device_t, void *);
197 1.60 dyoung void uplcom_childdet(device_t, device_t);
198 1.60 dyoung int uplcom_detach(device_t, int);
199 1.60 dyoung int uplcom_activate(device_t, enum devact);
200 1.60 dyoung extern struct cfdriver uplcom_cd;
201 1.65 cube CFATTACH_DECL2_NEW(uplcom, sizeof(struct uplcom_softc), uplcom_match,
202 1.60 dyoung uplcom_attach, uplcom_detach, uplcom_activate, NULL, uplcom_childdet);
203 1.1 ichiro
204 1.1 ichiro USB_MATCH(uplcom)
205 1.1 ichiro {
206 1.1 ichiro USB_MATCH_START(uplcom, uaa);
207 1.1 ichiro
208 1.23 augustss return (uplcom_lookup(uaa->vendor, uaa->product) != NULL ?
209 1.23 augustss UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
210 1.1 ichiro }
211 1.1 ichiro
212 1.1 ichiro USB_ATTACH(uplcom)
213 1.1 ichiro {
214 1.1 ichiro USB_ATTACH_START(uplcom, sc, uaa);
215 1.1 ichiro usbd_device_handle dev = uaa->device;
216 1.66 martin usb_device_descriptor_t *ddesc;
217 1.10 ichiro usb_config_descriptor_t *cdesc;
218 1.1 ichiro usb_interface_descriptor_t *id;
219 1.1 ichiro usb_endpoint_descriptor_t *ed;
220 1.42 augustss char *devinfop;
221 1.65 cube const char *devname = device_xname(self);
222 1.1 ichiro usbd_status err;
223 1.1 ichiro int i;
224 1.1 ichiro struct ucom_attach_args uca;
225 1.1 ichiro
226 1.65 cube sc->sc_dev = self;
227 1.65 cube
228 1.42 augustss devinfop = usbd_devinfo_alloc(dev, 0);
229 1.42 augustss USB_ATTACH_SETUP;
230 1.65 cube aprint_normal_dev(self, "%s\n", devinfop);
231 1.42 augustss usbd_devinfo_free(devinfop);
232 1.10 ichiro
233 1.10 ichiro sc->sc_udev = dev;
234 1.10 ichiro
235 1.1 ichiro DPRINTF(("\n\nuplcom attach: sc=%p\n", sc));
236 1.1 ichiro
237 1.28 augustss /* initialize endpoints */
238 1.13 ichiro uca.bulkin = uca.bulkout = -1;
239 1.13 ichiro sc->sc_intr_number = -1;
240 1.13 ichiro sc->sc_intr_pipe = NULL;
241 1.13 ichiro
242 1.6 augustss /* Move the device into the configured state. */
243 1.1 ichiro err = usbd_set_config_index(dev, UPLCOM_CONFIG_INDEX, 1);
244 1.1 ichiro if (err) {
245 1.65 cube aprint_error("\n%s: failed to set configuration, err=%s\n",
246 1.1 ichiro devname, usbd_errstr(err));
247 1.13 ichiro sc->sc_dying = 1;
248 1.1 ichiro USB_ATTACH_ERROR_RETURN;
249 1.1 ichiro }
250 1.1 ichiro
251 1.48 martin /* determine chip type */
252 1.66 martin ddesc = usbd_get_device_descriptor(dev);
253 1.66 martin if (ddesc->bDeviceClass != UDCLASS_COMM &&
254 1.66 martin ddesc->bMaxPacketSize == 0x40)
255 1.66 martin sc->sc_type = UPLCOM_TYPE_HX;
256 1.59 mlelstv
257 1.66 martin #ifdef UPLCOM_DEBUG
258 1.59 mlelstv /* print the chip type */
259 1.59 mlelstv if (sc->sc_type == UPLCOM_TYPE_HX) {
260 1.59 mlelstv DPRINTF(("uplcom_attach: chiptype HX\n"));
261 1.59 mlelstv } else {
262 1.59 mlelstv DPRINTF(("uplcom_attach: chiptype 0\n"));
263 1.59 mlelstv }
264 1.59 mlelstv #endif
265 1.59 mlelstv
266 1.59 mlelstv /* Move the device into the configured state. */
267 1.59 mlelstv err = usbd_set_config_index(dev, UPLCOM_CONFIG_INDEX, 1);
268 1.59 mlelstv if (err) {
269 1.65 cube aprint_error_dev(self, "failed to set configuration: %s\n",
270 1.65 cube usbd_errstr(err));
271 1.59 mlelstv sc->sc_dying = 1;
272 1.59 mlelstv USB_ATTACH_ERROR_RETURN;
273 1.59 mlelstv }
274 1.43 augustss
275 1.10 ichiro /* get the config descriptor */
276 1.10 ichiro cdesc = usbd_get_config_descriptor(sc->sc_udev);
277 1.10 ichiro
278 1.10 ichiro if (cdesc == NULL) {
279 1.65 cube aprint_error_dev(self,
280 1.65 cube "failed to get configuration descriptor\n");
281 1.13 ichiro sc->sc_dying = 1;
282 1.10 ichiro USB_ATTACH_ERROR_RETURN;
283 1.10 ichiro }
284 1.10 ichiro
285 1.13 ichiro /* get the (first/common) interface */
286 1.28 augustss err = usbd_device2interface_handle(dev, UPLCOM_IFACE_INDEX,
287 1.10 ichiro &sc->sc_iface);
288 1.1 ichiro if (err) {
289 1.65 cube aprint_error("\n%s: failed to get interface, err=%s\n",
290 1.1 ichiro devname, usbd_errstr(err));
291 1.13 ichiro sc->sc_dying = 1;
292 1.1 ichiro USB_ATTACH_ERROR_RETURN;
293 1.1 ichiro }
294 1.13 ichiro
295 1.13 ichiro /* Find the interrupt endpoints */
296 1.13 ichiro
297 1.13 ichiro id = usbd_get_interface_descriptor(sc->sc_iface);
298 1.13 ichiro sc->sc_iface_number = id->bInterfaceNumber;
299 1.13 ichiro
300 1.13 ichiro for (i = 0; i < id->bNumEndpoints; i++) {
301 1.13 ichiro ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
302 1.13 ichiro if (ed == NULL) {
303 1.65 cube aprint_error_dev(self,
304 1.65 cube "no endpoint descriptor for %d\n", i);
305 1.13 ichiro sc->sc_dying = 1;
306 1.13 ichiro USB_ATTACH_ERROR_RETURN;
307 1.13 ichiro }
308 1.13 ichiro
309 1.13 ichiro if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
310 1.13 ichiro UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
311 1.13 ichiro sc->sc_intr_number = ed->bEndpointAddress;
312 1.13 ichiro sc->sc_isize = UGETW(ed->wMaxPacketSize);
313 1.28 augustss }
314 1.13 ichiro }
315 1.13 ichiro
316 1.13 ichiro if (sc->sc_intr_number== -1) {
317 1.65 cube aprint_error_dev(self, "Could not find interrupt in\n");
318 1.13 ichiro sc->sc_dying = 1;
319 1.13 ichiro USB_ATTACH_ERROR_RETURN;
320 1.13 ichiro }
321 1.13 ichiro
322 1.20 ichiro /* keep interface for interrupt */
323 1.20 ichiro sc->sc_intr_iface = sc->sc_iface;
324 1.20 ichiro
325 1.10 ichiro /*
326 1.13 ichiro * USB-RSAQ1 has two interface
327 1.13 ichiro *
328 1.13 ichiro * USB-RSAQ1 | USB-RSAQ2
329 1.13 ichiro * -----------------+-----------------
330 1.14 ichiro * Interface 0 |Interface 0
331 1.14 ichiro * Interrupt(0x81) | Interrupt(0x81)
332 1.13 ichiro * -----------------+ BulkIN(0x02)
333 1.14 ichiro * Interface 1 | BulkOUT(0x83)
334 1.28 augustss * BulkIN(0x02) |
335 1.13 ichiro * BulkOUT(0x83) |
336 1.10 ichiro */
337 1.10 ichiro if (cdesc->bNumInterface == 2) {
338 1.28 augustss err = usbd_device2interface_handle(dev,
339 1.13 ichiro UPLCOM_SECOND_IFACE_INDEX, &sc->sc_iface);
340 1.10 ichiro if (err) {
341 1.65 cube aprint_error("\n%s: failed to get second interface, err=%s\n",
342 1.10 ichiro devname, usbd_errstr(err));
343 1.13 ichiro sc->sc_dying = 1;
344 1.10 ichiro USB_ATTACH_ERROR_RETURN;
345 1.10 ichiro }
346 1.28 augustss }
347 1.1 ichiro
348 1.13 ichiro /* Find the bulk{in,out} endpoints */
349 1.1 ichiro
350 1.12 ichiro id = usbd_get_interface_descriptor(sc->sc_iface);
351 1.1 ichiro sc->sc_iface_number = id->bInterfaceNumber;
352 1.1 ichiro
353 1.1 ichiro for (i = 0; i < id->bNumEndpoints; i++) {
354 1.12 ichiro ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
355 1.1 ichiro if (ed == NULL) {
356 1.65 cube aprint_error_dev(self,
357 1.65 cube "no endpoint descriptor for %d\n", i);
358 1.13 ichiro sc->sc_dying = 1;
359 1.1 ichiro USB_ATTACH_ERROR_RETURN;
360 1.1 ichiro }
361 1.1 ichiro
362 1.1 ichiro if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
363 1.1 ichiro UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
364 1.1 ichiro uca.bulkin = ed->bEndpointAddress;
365 1.1 ichiro } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
366 1.1 ichiro UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
367 1.1 ichiro uca.bulkout = ed->bEndpointAddress;
368 1.1 ichiro }
369 1.1 ichiro }
370 1.1 ichiro
371 1.1 ichiro if (uca.bulkin == -1) {
372 1.65 cube aprint_error_dev(self, "Could not find data bulk in\n");
373 1.13 ichiro sc->sc_dying = 1;
374 1.1 ichiro USB_ATTACH_ERROR_RETURN;
375 1.1 ichiro }
376 1.1 ichiro
377 1.1 ichiro if (uca.bulkout == -1) {
378 1.65 cube aprint_error_dev(self, "Could not find data bulk out\n");
379 1.13 ichiro sc->sc_dying = 1;
380 1.12 ichiro USB_ATTACH_ERROR_RETURN;
381 1.12 ichiro }
382 1.12 ichiro
383 1.37 martin sc->sc_dtr = sc->sc_rts = -1;
384 1.1 ichiro uca.portno = UCOM_UNK_PORTNO;
385 1.1 ichiro /* bulkin, bulkout set above */
386 1.1 ichiro uca.ibufsize = UPLCOMIBUFSIZE;
387 1.1 ichiro uca.obufsize = UPLCOMOBUFSIZE;
388 1.1 ichiro uca.ibufsizepad = UPLCOMIBUFSIZE;
389 1.4 ichiro uca.opkthdrlen = 0;
390 1.1 ichiro uca.device = dev;
391 1.12 ichiro uca.iface = sc->sc_iface;
392 1.1 ichiro uca.methods = &uplcom_methods;
393 1.1 ichiro uca.arg = sc;
394 1.8 augustss uca.info = NULL;
395 1.1 ichiro
396 1.11 ichiro err = uplcom_reset(sc);
397 1.11 ichiro
398 1.1 ichiro if (err) {
399 1.65 cube aprint_error_dev(self, "reset failed, %s\n", usbd_errstr(err));
400 1.13 ichiro sc->sc_dying = 1;
401 1.1 ichiro USB_ATTACH_ERROR_RETURN;
402 1.1 ichiro }
403 1.1 ichiro
404 1.7 augustss usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
405 1.7 augustss USBDEV(sc->sc_dev));
406 1.7 augustss
407 1.12 ichiro DPRINTF(("uplcom: in=0x%x out=0x%x intr=0x%x\n",
408 1.12 ichiro uca.bulkin, uca.bulkout, sc->sc_intr_number ));
409 1.39 drochner sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, &uca,
410 1.39 drochner ucomprint, ucomsubmatch);
411 1.1 ichiro
412 1.1 ichiro USB_ATTACH_SUCCESS_RETURN;
413 1.1 ichiro }
414 1.1 ichiro
415 1.60 dyoung void
416 1.60 dyoung uplcom_childdet(device_t self, device_t child)
417 1.60 dyoung {
418 1.60 dyoung struct uplcom_softc *sc = device_private(self);
419 1.60 dyoung
420 1.60 dyoung KASSERT(sc->sc_subdev == child);
421 1.60 dyoung sc->sc_subdev = NULL;
422 1.60 dyoung }
423 1.60 dyoung
424 1.1 ichiro USB_DETACH(uplcom)
425 1.1 ichiro {
426 1.1 ichiro USB_DETACH_START(uplcom, sc);
427 1.1 ichiro int rv = 0;
428 1.1 ichiro
429 1.1 ichiro DPRINTF(("uplcom_detach: sc=%p flags=%d\n", sc, flags));
430 1.12 ichiro
431 1.12 ichiro if (sc->sc_intr_pipe != NULL) {
432 1.12 ichiro usbd_abort_pipe(sc->sc_intr_pipe);
433 1.12 ichiro usbd_close_pipe(sc->sc_intr_pipe);
434 1.12 ichiro free(sc->sc_intr_buf, M_USBDEV);
435 1.12 ichiro sc->sc_intr_pipe = NULL;
436 1.12 ichiro }
437 1.12 ichiro
438 1.1 ichiro sc->sc_dying = 1;
439 1.60 dyoung if (sc->sc_subdev != NULL)
440 1.1 ichiro rv = config_detach(sc->sc_subdev, flags);
441 1.7 augustss
442 1.7 augustss usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
443 1.7 augustss USBDEV(sc->sc_dev));
444 1.1 ichiro
445 1.1 ichiro return (rv);
446 1.1 ichiro }
447 1.1 ichiro
448 1.1 ichiro int
449 1.60 dyoung uplcom_activate(device_t self, enum devact act)
450 1.1 ichiro {
451 1.60 dyoung struct uplcom_softc *sc = device_private(self);
452 1.1 ichiro int rv = 0;
453 1.1 ichiro
454 1.1 ichiro switch (act) {
455 1.1 ichiro case DVACT_ACTIVATE:
456 1.1 ichiro return (EOPNOTSUPP);
457 1.1 ichiro
458 1.1 ichiro case DVACT_DEACTIVATE:
459 1.1 ichiro if (sc->sc_subdev != NULL)
460 1.1 ichiro rv = config_deactivate(sc->sc_subdev);
461 1.1 ichiro sc->sc_dying = 1;
462 1.1 ichiro break;
463 1.1 ichiro }
464 1.1 ichiro return (rv);
465 1.1 ichiro }
466 1.1 ichiro
467 1.1 ichiro usbd_status
468 1.11 ichiro uplcom_reset(struct uplcom_softc *sc)
469 1.1 ichiro {
470 1.66 martin usb_device_request_t req;
471 1.1 ichiro usbd_status err;
472 1.1 ichiro
473 1.19 ichiro req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
474 1.19 ichiro req.bRequest = UPLCOM_SET_REQUEST;
475 1.19 ichiro USETW(req.wValue, 0);
476 1.1 ichiro USETW(req.wIndex, sc->sc_iface_number);
477 1.28 augustss USETW(req.wLength, 0);
478 1.28 augustss
479 1.28 augustss err = usbd_do_request(sc->sc_udev, &req, 0);
480 1.1 ichiro if (err)
481 1.1 ichiro return (EIO);
482 1.1 ichiro
483 1.1 ichiro return (0);
484 1.1 ichiro }
485 1.1 ichiro
486 1.59 mlelstv struct pl2303x_init {
487 1.59 mlelstv uint8_t req_type;
488 1.59 mlelstv uint8_t request;
489 1.59 mlelstv uint16_t value;
490 1.59 mlelstv uint16_t index;
491 1.59 mlelstv uint16_t length;
492 1.59 mlelstv };
493 1.59 mlelstv
494 1.59 mlelstv static const struct pl2303x_init pl2303x[] = {
495 1.59 mlelstv { UT_READ_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x8484, 0, 0 },
496 1.59 mlelstv { UT_WRITE_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x0404, 0, 0 },
497 1.59 mlelstv { UT_READ_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x8484, 0, 0 },
498 1.59 mlelstv { UT_READ_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x8383, 0, 0 },
499 1.59 mlelstv { UT_READ_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x8484, 0, 0 },
500 1.59 mlelstv { UT_WRITE_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x0404, 1, 0 },
501 1.59 mlelstv { UT_READ_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x8484, 0, 0 },
502 1.59 mlelstv { UT_READ_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x8383, 0, 0 },
503 1.59 mlelstv { UT_WRITE_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0, 1, 0 },
504 1.59 mlelstv { UT_WRITE_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 1, 0, 0 },
505 1.59 mlelstv { UT_WRITE_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 2, 0x44, 0 }
506 1.59 mlelstv };
507 1.59 mlelstv #define N_PL2302X_INIT (sizeof(pl2303x)/sizeof(pl2303x[0]))
508 1.59 mlelstv
509 1.59 mlelstv static usbd_status
510 1.59 mlelstv uplcom_pl2303x_init(struct uplcom_softc *sc)
511 1.59 mlelstv {
512 1.59 mlelstv usb_device_request_t req;
513 1.59 mlelstv usbd_status err;
514 1.59 mlelstv int i;
515 1.59 mlelstv
516 1.59 mlelstv for (i = 0; i < N_PL2302X_INIT; i++) {
517 1.59 mlelstv req.bmRequestType = pl2303x[i].req_type;
518 1.59 mlelstv req.bRequest = pl2303x[i].request;
519 1.59 mlelstv USETW(req.wValue, pl2303x[i].value);
520 1.59 mlelstv USETW(req.wIndex, pl2303x[i].index);
521 1.59 mlelstv USETW(req.wLength, pl2303x[i].length);
522 1.59 mlelstv
523 1.59 mlelstv err = usbd_do_request(sc->sc_udev, &req, 0);
524 1.59 mlelstv if (err) {
525 1.65 cube aprint_error_dev(sc->sc_dev,
526 1.65 cube "uplcom_pl2303x_init failed: %s\n",
527 1.65 cube usbd_errstr(err));
528 1.59 mlelstv return (EIO);
529 1.59 mlelstv }
530 1.59 mlelstv }
531 1.59 mlelstv
532 1.59 mlelstv return (0);
533 1.59 mlelstv }
534 1.59 mlelstv
535 1.1 ichiro void
536 1.1 ichiro uplcom_set_line_state(struct uplcom_softc *sc)
537 1.1 ichiro {
538 1.1 ichiro usb_device_request_t req;
539 1.1 ichiro int ls;
540 1.1 ichiro
541 1.37 martin /* make sure we have initialized state for sc_dtr and sc_rts */
542 1.37 martin if (sc->sc_dtr == -1)
543 1.37 martin sc->sc_dtr = 0;
544 1.37 martin if (sc->sc_rts == -1)
545 1.37 martin sc->sc_rts = 0;
546 1.37 martin
547 1.45 martin ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
548 1.45 martin (sc->sc_rts ? UCDC_LINE_RTS : 0);
549 1.37 martin
550 1.1 ichiro req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
551 1.1 ichiro req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
552 1.1 ichiro USETW(req.wValue, ls);
553 1.1 ichiro USETW(req.wIndex, sc->sc_iface_number);
554 1.1 ichiro USETW(req.wLength, 0);
555 1.1 ichiro
556 1.1 ichiro (void)usbd_do_request(sc->sc_udev, &req, 0);
557 1.1 ichiro }
558 1.1 ichiro
559 1.1 ichiro void
560 1.50 christos uplcom_set(void *addr, int portno, int reg, int onoff)
561 1.1 ichiro {
562 1.1 ichiro struct uplcom_softc *sc = addr;
563 1.1 ichiro
564 1.1 ichiro switch (reg) {
565 1.1 ichiro case UCOM_SET_DTR:
566 1.1 ichiro uplcom_dtr(sc, onoff);
567 1.1 ichiro break;
568 1.1 ichiro case UCOM_SET_RTS:
569 1.1 ichiro uplcom_rts(sc, onoff);
570 1.1 ichiro break;
571 1.1 ichiro case UCOM_SET_BREAK:
572 1.1 ichiro uplcom_break(sc, onoff);
573 1.1 ichiro break;
574 1.1 ichiro default:
575 1.1 ichiro break;
576 1.1 ichiro }
577 1.1 ichiro }
578 1.1 ichiro
579 1.1 ichiro void
580 1.1 ichiro uplcom_dtr(struct uplcom_softc *sc, int onoff)
581 1.1 ichiro {
582 1.1 ichiro
583 1.11 ichiro DPRINTF(("uplcom_dtr: onoff=%d\n", onoff));
584 1.1 ichiro
585 1.37 martin if (sc->sc_dtr != -1 && !sc->sc_dtr == !onoff)
586 1.1 ichiro return;
587 1.37 martin
588 1.37 martin sc->sc_dtr = !!onoff;
589 1.1 ichiro
590 1.1 ichiro uplcom_set_line_state(sc);
591 1.1 ichiro }
592 1.1 ichiro
593 1.1 ichiro void
594 1.1 ichiro uplcom_rts(struct uplcom_softc *sc, int onoff)
595 1.1 ichiro {
596 1.1 ichiro DPRINTF(("uplcom_rts: onoff=%d\n", onoff));
597 1.1 ichiro
598 1.37 martin if (sc->sc_rts != -1 && !sc->sc_rts == !onoff)
599 1.1 ichiro return;
600 1.37 martin
601 1.37 martin sc->sc_rts = !!onoff;
602 1.1 ichiro
603 1.1 ichiro uplcom_set_line_state(sc);
604 1.4 ichiro }
605 1.4 ichiro
606 1.4 ichiro void
607 1.4 ichiro uplcom_break(struct uplcom_softc *sc, int onoff)
608 1.4 ichiro {
609 1.4 ichiro usb_device_request_t req;
610 1.4 ichiro
611 1.4 ichiro DPRINTF(("uplcom_break: onoff=%d\n", onoff));
612 1.4 ichiro
613 1.4 ichiro req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
614 1.4 ichiro req.bRequest = UCDC_SEND_BREAK;
615 1.4 ichiro USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
616 1.4 ichiro USETW(req.wIndex, sc->sc_iface_number);
617 1.4 ichiro USETW(req.wLength, 0);
618 1.4 ichiro
619 1.4 ichiro (void)usbd_do_request(sc->sc_udev, &req, 0);
620 1.1 ichiro }
621 1.1 ichiro
622 1.1 ichiro usbd_status
623 1.19 ichiro uplcom_set_crtscts(struct uplcom_softc *sc)
624 1.19 ichiro {
625 1.19 ichiro usb_device_request_t req;
626 1.19 ichiro usbd_status err;
627 1.19 ichiro
628 1.19 ichiro DPRINTF(("uplcom_set_crtscts: on\n"));
629 1.19 ichiro
630 1.19 ichiro req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
631 1.19 ichiro req.bRequest = UPLCOM_SET_REQUEST;
632 1.19 ichiro USETW(req.wValue, 0);
633 1.43 augustss if (sc->sc_type == UPLCOM_TYPE_HX)
634 1.43 augustss USETW(req.wIndex, UPLCOM_SET_CRTSCTS_HX);
635 1.43 augustss else
636 1.43 augustss USETW(req.wIndex, UPLCOM_SET_CRTSCTS_0);
637 1.19 ichiro USETW(req.wLength, 0);
638 1.19 ichiro
639 1.19 ichiro err = usbd_do_request(sc->sc_udev, &req, 0);
640 1.19 ichiro if (err) {
641 1.19 ichiro DPRINTF(("uplcom_set_crtscts: failed, err=%s\n",
642 1.19 ichiro usbd_errstr(err)));
643 1.19 ichiro return (err);
644 1.19 ichiro }
645 1.19 ichiro
646 1.19 ichiro return (USBD_NORMAL_COMPLETION);
647 1.19 ichiro }
648 1.19 ichiro
649 1.19 ichiro usbd_status
650 1.1 ichiro uplcom_set_line_coding(struct uplcom_softc *sc, usb_cdc_line_state_t *state)
651 1.1 ichiro {
652 1.1 ichiro usb_device_request_t req;
653 1.1 ichiro usbd_status err;
654 1.1 ichiro
655 1.1 ichiro DPRINTF(("uplcom_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
656 1.1 ichiro UGETDW(state->dwDTERate), state->bCharFormat,
657 1.1 ichiro state->bParityType, state->bDataBits));
658 1.1 ichiro
659 1.1 ichiro if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
660 1.1 ichiro DPRINTF(("uplcom_set_line_coding: already set\n"));
661 1.1 ichiro return (USBD_NORMAL_COMPLETION);
662 1.1 ichiro }
663 1.1 ichiro
664 1.1 ichiro req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
665 1.1 ichiro req.bRequest = UCDC_SET_LINE_CODING;
666 1.1 ichiro USETW(req.wValue, 0);
667 1.1 ichiro USETW(req.wIndex, sc->sc_iface_number);
668 1.1 ichiro USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
669 1.1 ichiro
670 1.1 ichiro err = usbd_do_request(sc->sc_udev, &req, state);
671 1.1 ichiro if (err) {
672 1.1 ichiro DPRINTF(("uplcom_set_line_coding: failed, err=%s\n",
673 1.1 ichiro usbd_errstr(err)));
674 1.1 ichiro return (err);
675 1.1 ichiro }
676 1.1 ichiro
677 1.1 ichiro sc->sc_line_state = *state;
678 1.1 ichiro
679 1.1 ichiro return (USBD_NORMAL_COMPLETION);
680 1.1 ichiro }
681 1.1 ichiro
682 1.1 ichiro int
683 1.50 christos uplcom_param(void *addr, int portno, struct termios *t)
684 1.1 ichiro {
685 1.1 ichiro struct uplcom_softc *sc = addr;
686 1.1 ichiro usbd_status err;
687 1.1 ichiro usb_cdc_line_state_t ls;
688 1.1 ichiro
689 1.1 ichiro DPRINTF(("uplcom_param: sc=%p\n", sc));
690 1.1 ichiro
691 1.1 ichiro USETDW(ls.dwDTERate, t->c_ospeed);
692 1.1 ichiro if (ISSET(t->c_cflag, CSTOPB))
693 1.1 ichiro ls.bCharFormat = UCDC_STOP_BIT_2;
694 1.1 ichiro else
695 1.1 ichiro ls.bCharFormat = UCDC_STOP_BIT_1;
696 1.1 ichiro if (ISSET(t->c_cflag, PARENB)) {
697 1.1 ichiro if (ISSET(t->c_cflag, PARODD))
698 1.1 ichiro ls.bParityType = UCDC_PARITY_ODD;
699 1.1 ichiro else
700 1.1 ichiro ls.bParityType = UCDC_PARITY_EVEN;
701 1.1 ichiro } else
702 1.1 ichiro ls.bParityType = UCDC_PARITY_NONE;
703 1.1 ichiro switch (ISSET(t->c_cflag, CSIZE)) {
704 1.1 ichiro case CS5:
705 1.1 ichiro ls.bDataBits = 5;
706 1.1 ichiro break;
707 1.1 ichiro case CS6:
708 1.1 ichiro ls.bDataBits = 6;
709 1.1 ichiro break;
710 1.1 ichiro case CS7:
711 1.1 ichiro ls.bDataBits = 7;
712 1.1 ichiro break;
713 1.1 ichiro case CS8:
714 1.1 ichiro ls.bDataBits = 8;
715 1.1 ichiro break;
716 1.1 ichiro }
717 1.1 ichiro
718 1.1 ichiro err = uplcom_set_line_coding(sc, &ls);
719 1.1 ichiro if (err) {
720 1.1 ichiro DPRINTF(("uplcom_param: err=%s\n", usbd_errstr(err)));
721 1.1 ichiro return (EIO);
722 1.1 ichiro }
723 1.19 ichiro
724 1.19 ichiro if (ISSET(t->c_cflag, CRTSCTS))
725 1.19 ichiro uplcom_set_crtscts(sc);
726 1.19 ichiro
727 1.37 martin if (sc->sc_rts == -1 || sc->sc_dtr == -1)
728 1.37 martin uplcom_set_line_state(sc);
729 1.37 martin
730 1.19 ichiro if (err) {
731 1.19 ichiro DPRINTF(("uplcom_param: err=%s\n", usbd_errstr(err)));
732 1.19 ichiro return (EIO);
733 1.19 ichiro }
734 1.19 ichiro
735 1.1 ichiro return (0);
736 1.11 ichiro }
737 1.11 ichiro
738 1.43 augustss Static usbd_status
739 1.43 augustss uplcom_vendor_control_write(usbd_device_handle dev, u_int16_t value, u_int16_t index)
740 1.43 augustss {
741 1.43 augustss usb_device_request_t req;
742 1.43 augustss usbd_status err;
743 1.43 augustss
744 1.43 augustss req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
745 1.43 augustss req.bRequest = UPLCOM_SET_REQUEST;
746 1.43 augustss USETW(req.wValue, value);
747 1.43 augustss USETW(req.wIndex, index);
748 1.43 augustss USETW(req.wLength, 0);
749 1.43 augustss
750 1.43 augustss err = usbd_do_request(dev, &req, NULL);
751 1.43 augustss
752 1.43 augustss if (err) {
753 1.43 augustss DPRINTF(("uplcom_open: vendor write failed, err=%s (%d)\n",
754 1.43 augustss usbd_errstr(err), err));
755 1.43 augustss }
756 1.43 augustss
757 1.43 augustss return err;
758 1.43 augustss }
759 1.43 augustss
760 1.11 ichiro int
761 1.50 christos uplcom_open(void *addr, int portno)
762 1.11 ichiro {
763 1.11 ichiro struct uplcom_softc *sc = addr;
764 1.43 augustss usbd_status err;
765 1.28 augustss
766 1.11 ichiro if (sc->sc_dying)
767 1.11 ichiro return (EIO);
768 1.11 ichiro
769 1.12 ichiro DPRINTF(("uplcom_open: sc=%p\n", sc));
770 1.11 ichiro
771 1.43 augustss /* Some unknown device frobbing. */
772 1.43 augustss if (sc->sc_type == UPLCOM_TYPE_HX)
773 1.43 augustss uplcom_vendor_control_write(sc->sc_udev, 2, 0x44);
774 1.43 augustss else
775 1.43 augustss uplcom_vendor_control_write(sc->sc_udev, 2, 0x24);
776 1.43 augustss
777 1.12 ichiro if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
778 1.12 ichiro sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
779 1.20 ichiro err = usbd_open_pipe_intr(sc->sc_intr_iface, sc->sc_intr_number,
780 1.12 ichiro USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc,
781 1.12 ichiro sc->sc_intr_buf, sc->sc_isize,
782 1.12 ichiro uplcom_intr, USBD_DEFAULT_INTERVAL);
783 1.12 ichiro if (err) {
784 1.12 ichiro DPRINTF(("%s: cannot open interrupt pipe (addr %d)\n",
785 1.12 ichiro USBDEVNAME(sc->sc_dev), sc->sc_intr_number));
786 1.12 ichiro return (EIO);
787 1.12 ichiro }
788 1.12 ichiro }
789 1.11 ichiro
790 1.59 mlelstv if (sc->sc_type == UPLCOM_TYPE_HX)
791 1.59 mlelstv return (uplcom_pl2303x_init(sc));
792 1.59 mlelstv
793 1.11 ichiro return (0);
794 1.11 ichiro }
795 1.11 ichiro
796 1.11 ichiro void
797 1.50 christos uplcom_close(void *addr, int portno)
798 1.11 ichiro {
799 1.11 ichiro struct uplcom_softc *sc = addr;
800 1.12 ichiro int err;
801 1.12 ichiro
802 1.12 ichiro if (sc->sc_dying)
803 1.12 ichiro return;
804 1.12 ichiro
805 1.12 ichiro DPRINTF(("uplcom_close: close\n"));
806 1.12 ichiro
807 1.12 ichiro if (sc->sc_intr_pipe != NULL) {
808 1.12 ichiro err = usbd_abort_pipe(sc->sc_intr_pipe);
809 1.12 ichiro if (err)
810 1.12 ichiro printf("%s: abort interrupt pipe failed: %s\n",
811 1.12 ichiro USBDEVNAME(sc->sc_dev), usbd_errstr(err));
812 1.12 ichiro err = usbd_close_pipe(sc->sc_intr_pipe);
813 1.12 ichiro if (err)
814 1.12 ichiro printf("%s: close interrupt pipe failed: %s\n",
815 1.12 ichiro USBDEVNAME(sc->sc_dev), usbd_errstr(err));
816 1.12 ichiro free(sc->sc_intr_buf, M_USBDEV);
817 1.12 ichiro sc->sc_intr_pipe = NULL;
818 1.12 ichiro }
819 1.12 ichiro }
820 1.12 ichiro
821 1.12 ichiro void
822 1.50 christos uplcom_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
823 1.49 christos usbd_status status)
824 1.12 ichiro {
825 1.12 ichiro struct uplcom_softc *sc = priv;
826 1.12 ichiro u_char *buf = sc->sc_intr_buf;
827 1.12 ichiro u_char pstatus;
828 1.11 ichiro
829 1.11 ichiro if (sc->sc_dying)
830 1.11 ichiro return;
831 1.11 ichiro
832 1.12 ichiro if (status != USBD_NORMAL_COMPLETION) {
833 1.12 ichiro if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
834 1.12 ichiro return;
835 1.12 ichiro
836 1.12 ichiro DPRINTF(("%s: abnormal status: %s\n", USBDEVNAME(sc->sc_dev),
837 1.12 ichiro usbd_errstr(status)));
838 1.12 ichiro usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
839 1.12 ichiro return;
840 1.12 ichiro }
841 1.12 ichiro
842 1.12 ichiro DPRINTF(("%s: uplcom status = %02x\n", USBDEVNAME(sc->sc_dev), buf[8]));
843 1.12 ichiro
844 1.15 augustss sc->sc_lsr = sc->sc_msr = 0;
845 1.15 augustss pstatus = buf[8];
846 1.15 augustss if (ISSET(pstatus, RSAQ_STATUS_DSR))
847 1.15 augustss sc->sc_msr |= UMSR_DSR;
848 1.15 augustss if (ISSET(pstatus, RSAQ_STATUS_DCD))
849 1.15 augustss sc->sc_msr |= UMSR_DCD;
850 1.65 cube ucom_status_change(device_private(sc->sc_subdev));
851 1.12 ichiro }
852 1.12 ichiro
853 1.12 ichiro void
854 1.50 christos uplcom_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
855 1.12 ichiro {
856 1.12 ichiro struct uplcom_softc *sc = addr;
857 1.12 ichiro
858 1.12 ichiro DPRINTF(("uplcom_get_status:\n"));
859 1.12 ichiro
860 1.12 ichiro if (lsr != NULL)
861 1.12 ichiro *lsr = sc->sc_lsr;
862 1.12 ichiro if (msr != NULL)
863 1.12 ichiro *msr = sc->sc_msr;
864 1.12 ichiro }
865 1.12 ichiro
866 1.12 ichiro #if TODO
867 1.12 ichiro int
868 1.53 christos uplcom_ioctl(void *addr, int portno, u_long cmd, void *data, int flag,
869 1.24 augustss usb_proc_ptr p)
870 1.12 ichiro {
871 1.12 ichiro struct uplcom_softc *sc = addr;
872 1.12 ichiro int error = 0;
873 1.12 ichiro
874 1.12 ichiro if (sc->sc_dying)
875 1.12 ichiro return (EIO);
876 1.12 ichiro
877 1.12 ichiro DPRINTF(("uplcom_ioctl: cmd=0x%08lx\n", cmd));
878 1.12 ichiro
879 1.12 ichiro switch (cmd) {
880 1.12 ichiro case TIOCNOTTY:
881 1.12 ichiro case TIOCMGET:
882 1.12 ichiro case TIOCMSET:
883 1.12 ichiro case USB_GET_CM_OVER_DATA:
884 1.12 ichiro case USB_SET_CM_OVER_DATA:
885 1.12 ichiro break;
886 1.12 ichiro
887 1.12 ichiro default:
888 1.12 ichiro DPRINTF(("uplcom_ioctl: unknown\n"));
889 1.12 ichiro error = ENOTTY;
890 1.12 ichiro break;
891 1.11 ichiro }
892 1.11 ichiro
893 1.12 ichiro return (error);
894 1.1 ichiro }
895 1.12 ichiro #endif
896