1*81508fe3Sjsg /* $OpenBSD: uplcom.c,v 1.81 2024/05/23 03:21:09 jsg Exp $ */
2681fdbd8Snate /* $NetBSD: uplcom.c,v 1.29 2002/09/23 05:51:23 simonb Exp $ */
3720abebfSmillert /*
4720abebfSmillert * Copyright (c) 2001 The NetBSD Foundation, Inc.
5720abebfSmillert * All rights reserved.
6720abebfSmillert *
7720abebfSmillert * This code is derived from software contributed to The NetBSD Foundation
8720abebfSmillert * by Ichiro FUKUHARA (ichiro@ichiro.org).
9720abebfSmillert *
10720abebfSmillert * Redistribution and use in source and binary forms, with or without
11720abebfSmillert * modification, are permitted provided that the following conditions
12720abebfSmillert * are met:
13720abebfSmillert * 1. Redistributions of source code must retain the above copyright
14720abebfSmillert * notice, this list of conditions and the following disclaimer.
15720abebfSmillert * 2. Redistributions in binary form must reproduce the above copyright
16720abebfSmillert * notice, this list of conditions and the following disclaimer in the
17720abebfSmillert * documentation and/or other materials provided with the distribution.
18720abebfSmillert *
19720abebfSmillert * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20720abebfSmillert * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21720abebfSmillert * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22720abebfSmillert * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23720abebfSmillert * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24720abebfSmillert * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25720abebfSmillert * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26720abebfSmillert * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27720abebfSmillert * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28720abebfSmillert * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29720abebfSmillert * POSSIBILITY OF SUCH DAMAGE.
30720abebfSmillert */
31720abebfSmillert
32720abebfSmillert /*
33720abebfSmillert * Simple datasheet
342b96f905Sjmc * http://www.prolific.com.tw/PDF/PL-2303%20Market%20Spec.pdf
352b96f905Sjmc * http://www.hitachi-hitec.com/jyouhou/prolific/2303.pdf
36720abebfSmillert * (english)
37720abebfSmillert *
38720abebfSmillert */
39720abebfSmillert
40720abebfSmillert #include <sys/param.h>
41720abebfSmillert #include <sys/systm.h>
42720abebfSmillert #include <sys/malloc.h>
43720abebfSmillert #include <sys/tty.h>
44720abebfSmillert #include <sys/device.h>
45720abebfSmillert
46720abebfSmillert #include <dev/usb/usb.h>
47720abebfSmillert #include <dev/usb/usbcdc.h>
48720abebfSmillert
49720abebfSmillert #include <dev/usb/usbdi.h>
50720abebfSmillert #include <dev/usb/usbdevs.h>
51720abebfSmillert
52720abebfSmillert #include <dev/usb/ucomvar.h>
53720abebfSmillert
54720abebfSmillert #ifdef UPLCOM_DEBUG
55695146ceSjsg #define DPRINTFN(n, x) do { if (uplcomdebug > (n)) printf x; } while (0)
56720abebfSmillert int uplcomdebug = 0;
57720abebfSmillert #else
58720abebfSmillert #define DPRINTFN(n, x)
59720abebfSmillert #endif
60720abebfSmillert #define DPRINTF(x) DPRINTFN(0, x)
61720abebfSmillert
62720abebfSmillert #define UPLCOM_IFACE_INDEX 0
63720abebfSmillert #define UPLCOM_SECOND_IFACE_INDEX 1
64720abebfSmillert
65720abebfSmillert #define UPLCOM_SET_REQUEST 0x01
66eccf7d77Spatrick #define UPLCOM_HXN_SET_REQUEST 0x80
67eccf7d77Spatrick #define UPLCOM_HXN_SET_CRTSCTS_REG 0x0A
68720abebfSmillert #define UPLCOM_SET_CRTSCTS 0x41
693aa560b7Sdlg #define UPLCOM_HX_SET_CRTSCTS 0x61
70eccf7d77Spatrick #define UPLCOM_HXN_SET_CRTSCTS 0xFA
71eccf7d77Spatrick #define UPLCOM_HX_STATUS_REG 0x8080
72f1f7ba03Sdlg #define RSAQ_STATUS_CTS 0x80
73720abebfSmillert #define RSAQ_STATUS_DSR 0x02
74720abebfSmillert #define RSAQ_STATUS_DCD 0x01
75720abebfSmillert
76eccf7d77Spatrick #define UPLCOM_TYPE_01 0
77eccf7d77Spatrick #define UPLCOM_TYPE_HX 1
78eccf7d77Spatrick #define UPLCOM_TYPE_HXN 2
79eccf7d77Spatrick
80720abebfSmillert struct uplcom_softc {
818c5d01eeSmk struct device sc_dev; /* base device */
82ab0b1be7Smglocker struct usbd_device *sc_udev; /* USB device */
83ab0b1be7Smglocker struct usbd_interface *sc_iface; /* interface */
84720abebfSmillert int sc_iface_number; /* interface number */
85720abebfSmillert
86ab0b1be7Smglocker struct usbd_interface *sc_intr_iface; /* interrupt interface */
87720abebfSmillert int sc_intr_number; /* interrupt number */
88ab0b1be7Smglocker struct usbd_pipe *sc_intr_pipe; /* interrupt pipe */
89720abebfSmillert u_char *sc_intr_buf; /* interrupt buffer */
90720abebfSmillert int sc_isize;
91720abebfSmillert
92ab0b1be7Smglocker struct usb_cdc_line_state sc_line_state;/* current line state */
93021bcdb4Sdlg int sc_dtr; /* current DTR state */
94021bcdb4Sdlg int sc_rts; /* current RTS state */
95720abebfSmillert
9673030186Smbalmer struct device *sc_subdev; /* ucom device */
97720abebfSmillert
98720abebfSmillert u_char sc_lsr; /* Local status register */
99720abebfSmillert u_char sc_msr; /* uplcom status register */
100eccf7d77Spatrick int sc_type; /* variant */
101720abebfSmillert };
102720abebfSmillert
103720abebfSmillert /*
104720abebfSmillert * These are the maximum number of bytes transferred per frame.
105720abebfSmillert * The output buffer size cannot be increased due to the size encoding.
106720abebfSmillert */
107720abebfSmillert #define UPLCOMIBUFSIZE 256
108720abebfSmillert #define UPLCOMOBUFSIZE 256
109720abebfSmillert
11078315254Smbalmer usbd_status uplcom_reset(struct uplcom_softc *);
11178315254Smbalmer usbd_status uplcom_set_line_coding(struct uplcom_softc *sc,
112ab0b1be7Smglocker struct usb_cdc_line_state *state);
11378315254Smbalmer usbd_status uplcom_set_crtscts(struct uplcom_softc *);
114ab0b1be7Smglocker void uplcom_intr(struct usbd_xfer *, void *, usbd_status);
115720abebfSmillert
11678315254Smbalmer void uplcom_set(void *, int, int, int);
11778315254Smbalmer void uplcom_dtr(struct uplcom_softc *, int);
11878315254Smbalmer void uplcom_rts(struct uplcom_softc *, int);
11978315254Smbalmer void uplcom_break(struct uplcom_softc *, int);
12078315254Smbalmer void uplcom_set_line_state(struct uplcom_softc *);
12178315254Smbalmer void uplcom_get_status(void *, int portno, u_char *lsr, u_char *msr);
12278315254Smbalmer int uplcom_param(void *, int, struct termios *);
12378315254Smbalmer int uplcom_open(void *, int);
12478315254Smbalmer void uplcom_close(void *, int);
125720abebfSmillert
126c520a48cSnaddy const struct ucom_methods uplcom_methods = {
127720abebfSmillert uplcom_get_status,
128720abebfSmillert uplcom_set,
129720abebfSmillert uplcom_param,
130a1b4eae8Smpi NULL,
131720abebfSmillert uplcom_open,
132720abebfSmillert uplcom_close,
133720abebfSmillert NULL,
134720abebfSmillert NULL,
135720abebfSmillert };
136720abebfSmillert
137b5b99636Snate static const struct usb_devno uplcom_devs[] = {
138c37d3d11Sjsg { USB_VENDOR_ALCATEL, USB_PRODUCT_ALCATEL_OT535 },
139c37d3d11Sjsg { USB_VENDOR_ANCHOR, USB_PRODUCT_ANCHOR_SERIAL },
1402fd643e8Sjsg { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC232A },
141f8fd3cfcSbrad { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U257 },
1422fd643e8Sjsg { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_UCSGT },
1432fd643e8Sjsg { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_UCSGT0 },
1442fd643e8Sjsg { USB_VENDOR_HAL, USB_PRODUCT_HAL_IMR001 },
14567e3c979Smikeb { USB_VENDOR_HP, USB_PRODUCT_HP_LD220 },
1462fd643e8Sjsg { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBRSAQ },
147ecf81798Sjsg { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBRSAQ5 },
148c37d3d11Sjsg { USB_VENDOR_LEADTEK, USB_PRODUCT_LEADTEK_9531 },
1490d1afdc0Sjsg { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_700WX },
150c37d3d11Sjsg { USB_VENDOR_MOBILEACTION, USB_PRODUCT_MOBILEACTION_MA620 },
151c37d3d11Sjsg { USB_VENDOR_NOKIA, USB_PRODUCT_NOKIA_CA42 },
152c37d3d11Sjsg { USB_VENDOR_OTI, USB_PRODUCT_OTI_DKU5 },
153c37d3d11Sjsg { USB_VENDOR_PLX, USB_PRODUCT_PLX_CA42 },
1542fd643e8Sjsg { USB_VENDOR_PANASONIC, USB_PRODUCT_PANASONIC_TYTP50P6S },
1552fd643e8Sjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303 },
1562e8dbc7dSjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303GB },
157eccf7d77Spatrick { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303GC },
1582e8dbc7dSjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303GE },
1592e8dbc7dSjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303GL },
1602e8dbc7dSjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303GS },
1612e8dbc7dSjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303GT },
1622fd643e8Sjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303X },
1632fd643e8Sjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303X2 },
1642fd643e8Sjsg { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_RSAQ2 },
165c377bb0bSderaadt { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303BENQ },
166a8a890abSjsg { USB_VENDOR_PROLIFIC2, USB_PRODUCT_PROLIFIC2_PL2303 },
167c37d3d11Sjsg { USB_VENDOR_RADIOSHACK, USB_PRODUCT_RADIOSHACK_PL2303 },
1682fd643e8Sjsg { USB_VENDOR_RATOC, USB_PRODUCT_RATOC_REXUSB60 },
169c37d3d11Sjsg { USB_VENDOR_SAGEM, USB_PRODUCT_SAGEM_SERIAL },
170c37d3d11Sjsg { USB_VENDOR_SIEMENS3, USB_PRODUCT_SIEMENS3_SX1 },
171c37d3d11Sjsg { USB_VENDOR_SIEMENS3, USB_PRODUCT_SIEMENS3_X65 },
172c37d3d11Sjsg { USB_VENDOR_SIEMENS3, USB_PRODUCT_SIEMENS3_X75 },
1732fd643e8Sjsg { USB_VENDOR_SITECOM, USB_PRODUCT_SITECOM_CN104 },
1742fd643e8Sjsg { USB_VENDOR_SOURCENEXT, USB_PRODUCT_SOURCENEXT_KEIKAI8 },
1752fd643e8Sjsg { USB_VENDOR_SOURCENEXT, USB_PRODUCT_SOURCENEXT_KEIKAI8_CHG },
176c37d3d11Sjsg { USB_VENDOR_SPEEDDRAGON, USB_PRODUCT_SPEEDDRAGON_MS3303H },
1772fd643e8Sjsg { USB_VENDOR_SUSTEEN, USB_PRODUCT_SUSTEEN_DCU11 },
1782fd643e8Sjsg { USB_VENDOR_SYNTECH, USB_PRODUCT_SYNTECH_SERIAL },
1792fd643e8Sjsg { USB_VENDOR_TDK, USB_PRODUCT_TDK_UHA6400 },
1802fd643e8Sjsg { USB_VENDOR_TDK, USB_PRODUCT_TDK_UPA9664 },
18125863b4fSderaadt { USB_VENDOR_TRIPPLITE, USB_PRODUCT_TRIPPLITE_U209 },
182733361f3Sokan { USB_VENDOR_SMART, USB_PRODUCT_SMART_PL2303 },
183733361f3Sokan { USB_VENDOR_YCCABLE, USB_PRODUCT_YCCABLE_PL2303 }
184720abebfSmillert };
185b5b99636Snate #define uplcom_lookup(v, p) usb_lookup(uplcom_devs, v, p)
186720abebfSmillert
1879f5f6d50Smbalmer int uplcom_match(struct device *, void *, void *);
1889f5f6d50Smbalmer void uplcom_attach(struct device *, struct device *, void *);
1899f5f6d50Smbalmer int uplcom_detach(struct device *, int);
1909f5f6d50Smbalmer
1919f5f6d50Smbalmer struct cfdriver uplcom_cd = {
1929f5f6d50Smbalmer NULL, "uplcom", DV_DULL
1939f5f6d50Smbalmer };
1949f5f6d50Smbalmer
1959f5f6d50Smbalmer const struct cfattach uplcom_ca = {
19684f0598eSmpi sizeof(struct uplcom_softc), uplcom_match, uplcom_attach, uplcom_detach
1979f5f6d50Smbalmer };
198720abebfSmillert
199de5d9ff0Sjsg int
uplcom_match(struct device * parent,void * match,void * aux)200de5d9ff0Sjsg uplcom_match(struct device *parent, void *match, void *aux)
201720abebfSmillert {
202de5d9ff0Sjsg struct usb_attach_arg *uaa = aux;
203720abebfSmillert
204c0d38480Smpi if (uaa->iface == NULL)
205720abebfSmillert return (UMATCH_NONE);
206720abebfSmillert
207b5b99636Snate return (uplcom_lookup(uaa->vendor, uaa->product) != NULL ?
208b5b99636Snate UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
209720abebfSmillert }
210720abebfSmillert
211de5d9ff0Sjsg void
uplcom_attach(struct device * parent,struct device * self,void * aux)212de5d9ff0Sjsg uplcom_attach(struct device *parent, struct device *self, void *aux)
213720abebfSmillert {
214de5d9ff0Sjsg struct uplcom_softc *sc = (struct uplcom_softc *)self;
215de5d9ff0Sjsg struct usb_attach_arg *uaa = aux;
216ab0b1be7Smglocker struct usbd_device *dev = uaa->device;
217720abebfSmillert usb_config_descriptor_t *cdesc;
2183aa560b7Sdlg usb_device_descriptor_t *ddesc;
219720abebfSmillert usb_interface_descriptor_t *id;
220720abebfSmillert usb_endpoint_descriptor_t *ed;
2214ab2b9feSmbalmer char *devname = sc->sc_dev.dv_xname;
222eccf7d77Spatrick usb_device_request_t req;
223720abebfSmillert usbd_status err;
224eccf7d77Spatrick uByte val;
225720abebfSmillert int i;
226720abebfSmillert struct ucom_attach_args uca;
227720abebfSmillert
228720abebfSmillert sc->sc_udev = dev;
229720abebfSmillert
230720abebfSmillert DPRINTF(("\n\nuplcom attach: sc=%p\n", sc));
231720abebfSmillert
232720abebfSmillert /* initialize endpoints */
233720abebfSmillert uca.bulkin = uca.bulkout = -1;
234720abebfSmillert sc->sc_intr_number = -1;
235720abebfSmillert sc->sc_intr_pipe = NULL;
236720abebfSmillert
237720abebfSmillert /* get the config descriptor */
238720abebfSmillert cdesc = usbd_get_config_descriptor(sc->sc_udev);
239720abebfSmillert
240720abebfSmillert if (cdesc == NULL) {
241720abebfSmillert printf("%s: failed to get configuration descriptor\n",
2424ab2b9feSmbalmer sc->sc_dev.dv_xname);
243484025c5Spirofti usbd_deactivate(sc->sc_udev);
244de5d9ff0Sjsg return;
245720abebfSmillert }
246720abebfSmillert
2473aa560b7Sdlg /* get the device descriptor */
2483aa560b7Sdlg ddesc = usbd_get_device_descriptor(sc->sc_udev);
2493aa560b7Sdlg if (ddesc == NULL) {
2503aa560b7Sdlg printf("%s: failed to get device descriptor\n",
2514ab2b9feSmbalmer sc->sc_dev.dv_xname);
252484025c5Spirofti usbd_deactivate(sc->sc_udev);
253de5d9ff0Sjsg return;
2543aa560b7Sdlg }
2553aa560b7Sdlg
2563aa560b7Sdlg /*
2573aa560b7Sdlg * The Linux driver suggest this will only be true for the HX
2583aa560b7Sdlg * variants. The datasheets disagree.
2593aa560b7Sdlg */
2604d30b2a2Sderaadt if (ddesc->bDeviceClass == 0x02)
261eccf7d77Spatrick sc->sc_type = UPLCOM_TYPE_01;
2624d30b2a2Sderaadt else if (ddesc->bMaxPacketSize == 0x40)
263eccf7d77Spatrick sc->sc_type = UPLCOM_TYPE_HX;
2644d30b2a2Sderaadt else
265eccf7d77Spatrick sc->sc_type = UPLCOM_TYPE_01;
266eccf7d77Spatrick
267eccf7d77Spatrick if (sc->sc_type == UPLCOM_TYPE_HX) {
268eccf7d77Spatrick req.bmRequestType = UT_READ_VENDOR_DEVICE;
269eccf7d77Spatrick req.bRequest = UPLCOM_SET_REQUEST;
270eccf7d77Spatrick USETW(req.wValue, UPLCOM_HX_STATUS_REG);
271eccf7d77Spatrick USETW(req.wIndex, sc->sc_iface_number);
272eccf7d77Spatrick USETW(req.wLength, 1);
273eccf7d77Spatrick err = usbd_do_request(sc->sc_udev, &req, &val);
274eccf7d77Spatrick if (err)
275eccf7d77Spatrick sc->sc_type = UPLCOM_TYPE_HXN;
276eccf7d77Spatrick }
2773aa560b7Sdlg
278eb421eacSmpi #ifdef UPLCOM_DEBUG
2794d30b2a2Sderaadt /* print the chip type */
280eccf7d77Spatrick if (sc->sc_type == UPLCOM_TYPE_HXN) {
281eccf7d77Spatrick DPRINTF(("uplcom_attach: chiptype 2303XN\n"));
282eccf7d77Spatrick } else if (sc->sc_type == UPLCOM_TYPE_HX) {
2834d30b2a2Sderaadt DPRINTF(("uplcom_attach: chiptype 2303X\n"));
2844d30b2a2Sderaadt } else {
2854d30b2a2Sderaadt DPRINTF(("uplcom_attach: chiptype 2303\n"));
2864d30b2a2Sderaadt }
2874d30b2a2Sderaadt #endif
288720abebfSmillert /* get the (first/common) interface */
289720abebfSmillert err = usbd_device2interface_handle(dev, UPLCOM_IFACE_INDEX,
290720abebfSmillert &sc->sc_iface);
291720abebfSmillert if (err) {
292720abebfSmillert printf("\n%s: failed to get interface, err=%s\n",
293720abebfSmillert devname, usbd_errstr(err));
294484025c5Spirofti usbd_deactivate(sc->sc_udev);
295de5d9ff0Sjsg return;
296720abebfSmillert }
297720abebfSmillert
298720abebfSmillert /* Find the interrupt endpoints */
299720abebfSmillert
300720abebfSmillert id = usbd_get_interface_descriptor(sc->sc_iface);
301720abebfSmillert sc->sc_iface_number = id->bInterfaceNumber;
302720abebfSmillert
303720abebfSmillert for (i = 0; i < id->bNumEndpoints; i++) {
304720abebfSmillert ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
305720abebfSmillert if (ed == NULL) {
306720abebfSmillert printf("%s: no endpoint descriptor for %d\n",
3074ab2b9feSmbalmer sc->sc_dev.dv_xname, i);
308484025c5Spirofti usbd_deactivate(sc->sc_udev);
309de5d9ff0Sjsg return;
310720abebfSmillert }
311720abebfSmillert
312720abebfSmillert if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
313720abebfSmillert UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
314720abebfSmillert sc->sc_intr_number = ed->bEndpointAddress;
315720abebfSmillert sc->sc_isize = UGETW(ed->wMaxPacketSize);
316720abebfSmillert }
317720abebfSmillert }
318720abebfSmillert
319720abebfSmillert if (sc->sc_intr_number== -1) {
320720abebfSmillert printf("%s: Could not find interrupt in\n",
3214ab2b9feSmbalmer sc->sc_dev.dv_xname);
322484025c5Spirofti usbd_deactivate(sc->sc_udev);
323de5d9ff0Sjsg return;
324720abebfSmillert }
325720abebfSmillert
326720abebfSmillert /* keep interface for interrupt */
327720abebfSmillert sc->sc_intr_iface = sc->sc_iface;
328720abebfSmillert
329720abebfSmillert /*
330720abebfSmillert * USB-RSAQ1 has two interface
331720abebfSmillert *
332720abebfSmillert * USB-RSAQ1 | USB-RSAQ2
333720abebfSmillert * -----------------+-----------------
334720abebfSmillert * Interface 0 |Interface 0
335720abebfSmillert * Interrupt(0x81) | Interrupt(0x81)
336720abebfSmillert * -----------------+ BulkIN(0x02)
337720abebfSmillert * Interface 1 | BulkOUT(0x83)
338720abebfSmillert * BulkIN(0x02) |
339720abebfSmillert * BulkOUT(0x83) |
340720abebfSmillert */
341f2476161Smglocker if (cdesc->bNumInterfaces == 2) {
342720abebfSmillert err = usbd_device2interface_handle(dev,
343720abebfSmillert UPLCOM_SECOND_IFACE_INDEX, &sc->sc_iface);
344720abebfSmillert if (err) {
345720abebfSmillert printf("\n%s: failed to get second interface, err=%s\n",
346720abebfSmillert devname, usbd_errstr(err));
347484025c5Spirofti usbd_deactivate(sc->sc_udev);
348de5d9ff0Sjsg return;
349720abebfSmillert }
350720abebfSmillert }
351720abebfSmillert
352720abebfSmillert /* Find the bulk{in,out} endpoints */
353720abebfSmillert
354720abebfSmillert id = usbd_get_interface_descriptor(sc->sc_iface);
355720abebfSmillert sc->sc_iface_number = id->bInterfaceNumber;
356720abebfSmillert
357720abebfSmillert for (i = 0; i < id->bNumEndpoints; i++) {
358720abebfSmillert ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
359720abebfSmillert if (ed == NULL) {
360720abebfSmillert printf("%s: no endpoint descriptor for %d\n",
3614ab2b9feSmbalmer sc->sc_dev.dv_xname, i);
362484025c5Spirofti usbd_deactivate(sc->sc_udev);
363de5d9ff0Sjsg return;
364720abebfSmillert }
365720abebfSmillert
366720abebfSmillert if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
367720abebfSmillert UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
368720abebfSmillert uca.bulkin = ed->bEndpointAddress;
369720abebfSmillert } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
370720abebfSmillert UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
371720abebfSmillert uca.bulkout = ed->bEndpointAddress;
372720abebfSmillert }
373720abebfSmillert }
374720abebfSmillert
375720abebfSmillert if (uca.bulkin == -1) {
376720abebfSmillert printf("%s: Could not find data bulk in\n",
3774ab2b9feSmbalmer sc->sc_dev.dv_xname);
378484025c5Spirofti usbd_deactivate(sc->sc_udev);
379de5d9ff0Sjsg return;
380720abebfSmillert }
381720abebfSmillert
382720abebfSmillert if (uca.bulkout == -1) {
383720abebfSmillert printf("%s: Could not find data bulk out\n",
3844ab2b9feSmbalmer sc->sc_dev.dv_xname);
385484025c5Spirofti usbd_deactivate(sc->sc_udev);
386de5d9ff0Sjsg return;
387720abebfSmillert }
388720abebfSmillert
389720abebfSmillert sc->sc_dtr = sc->sc_rts = -1;
390720abebfSmillert uca.portno = UCOM_UNK_PORTNO;
391720abebfSmillert /* bulkin, bulkout set above */
392720abebfSmillert uca.ibufsize = UPLCOMIBUFSIZE;
393720abebfSmillert uca.obufsize = UPLCOMOBUFSIZE;
394720abebfSmillert uca.ibufsizepad = UPLCOMIBUFSIZE;
395720abebfSmillert uca.opkthdrlen = 0;
396720abebfSmillert uca.device = dev;
397720abebfSmillert uca.iface = sc->sc_iface;
398720abebfSmillert uca.methods = &uplcom_methods;
399720abebfSmillert uca.arg = sc;
400720abebfSmillert uca.info = NULL;
401720abebfSmillert
402eccf7d77Spatrick if (sc->sc_type != UPLCOM_TYPE_HXN) {
403720abebfSmillert err = uplcom_reset(sc);
404720abebfSmillert if (err) {
4054ab2b9feSmbalmer printf("%s: reset failed, %s\n", sc->sc_dev.dv_xname,
406720abebfSmillert usbd_errstr(err));
407484025c5Spirofti usbd_deactivate(sc->sc_udev);
408de5d9ff0Sjsg return;
409720abebfSmillert }
410eccf7d77Spatrick }
411720abebfSmillert
412720abebfSmillert DPRINTF(("uplcom: in=0x%x out=0x%x intr=0x%x\n",
413720abebfSmillert uca.bulkin, uca.bulkout, sc->sc_intr_number ));
414720abebfSmillert sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch);
415720abebfSmillert }
416720abebfSmillert
417de5d9ff0Sjsg int
uplcom_detach(struct device * self,int flags)418de5d9ff0Sjsg uplcom_detach(struct device *self, int flags)
419720abebfSmillert {
420de5d9ff0Sjsg struct uplcom_softc *sc = (struct uplcom_softc *)self;
421720abebfSmillert int rv = 0;
422720abebfSmillert
423720abebfSmillert DPRINTF(("uplcom_detach: sc=%p flags=%d\n", sc, flags));
424720abebfSmillert
425720abebfSmillert if (sc->sc_intr_pipe != NULL) {
426720abebfSmillert usbd_close_pipe(sc->sc_intr_pipe);
427234dfda1Sderaadt free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
428720abebfSmillert sc->sc_intr_pipe = NULL;
429720abebfSmillert }
430720abebfSmillert
431720abebfSmillert if (sc->sc_subdev != NULL) {
432720abebfSmillert rv = config_detach(sc->sc_subdev, flags);
433720abebfSmillert sc->sc_subdev = NULL;
434720abebfSmillert }
435720abebfSmillert
436720abebfSmillert return (rv);
437720abebfSmillert }
438720abebfSmillert
439720abebfSmillert usbd_status
uplcom_reset(struct uplcom_softc * sc)440720abebfSmillert uplcom_reset(struct uplcom_softc *sc)
441720abebfSmillert {
442720abebfSmillert usb_device_request_t req;
443720abebfSmillert usbd_status err;
444720abebfSmillert
445720abebfSmillert req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
446720abebfSmillert req.bRequest = UPLCOM_SET_REQUEST;
447720abebfSmillert USETW(req.wValue, 0);
448720abebfSmillert USETW(req.wIndex, sc->sc_iface_number);
449720abebfSmillert USETW(req.wLength, 0);
450720abebfSmillert
451720abebfSmillert err = usbd_do_request(sc->sc_udev, &req, 0);
452720abebfSmillert if (err)
453720abebfSmillert return (EIO);
454720abebfSmillert
455720abebfSmillert return (0);
456720abebfSmillert }
457720abebfSmillert
458720abebfSmillert void
uplcom_set_line_state(struct uplcom_softc * sc)459720abebfSmillert uplcom_set_line_state(struct uplcom_softc *sc)
460720abebfSmillert {
461720abebfSmillert usb_device_request_t req;
462720abebfSmillert int ls;
463720abebfSmillert
464021bcdb4Sdlg /* Make sure we have initialized state for sc_dtr and sc_rts */
465021bcdb4Sdlg if (sc->sc_dtr == -1)
466021bcdb4Sdlg sc->sc_dtr = 0;
467021bcdb4Sdlg if (sc->sc_rts == -1)
468021bcdb4Sdlg sc->sc_rts = 0;
469021bcdb4Sdlg
470d8ca7f4cSbrad ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
471d8ca7f4cSbrad (sc->sc_rts ? UCDC_LINE_RTS : 0);
472021bcdb4Sdlg
473720abebfSmillert req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
474720abebfSmillert req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
475720abebfSmillert USETW(req.wValue, ls);
476720abebfSmillert USETW(req.wIndex, sc->sc_iface_number);
477720abebfSmillert USETW(req.wLength, 0);
478720abebfSmillert
479720abebfSmillert (void)usbd_do_request(sc->sc_udev, &req, 0);
480720abebfSmillert
481720abebfSmillert }
482720abebfSmillert
483720abebfSmillert void
uplcom_set(void * addr,int portno,int reg,int onoff)484720abebfSmillert uplcom_set(void *addr, int portno, int reg, int onoff)
485720abebfSmillert {
486720abebfSmillert struct uplcom_softc *sc = addr;
487720abebfSmillert
488720abebfSmillert switch (reg) {
489720abebfSmillert case UCOM_SET_DTR:
490720abebfSmillert uplcom_dtr(sc, onoff);
491720abebfSmillert break;
492720abebfSmillert case UCOM_SET_RTS:
493720abebfSmillert uplcom_rts(sc, onoff);
494720abebfSmillert break;
495720abebfSmillert case UCOM_SET_BREAK:
496720abebfSmillert uplcom_break(sc, onoff);
497720abebfSmillert break;
498720abebfSmillert default:
499720abebfSmillert break;
500720abebfSmillert }
501720abebfSmillert }
502720abebfSmillert
503720abebfSmillert void
uplcom_dtr(struct uplcom_softc * sc,int onoff)504720abebfSmillert uplcom_dtr(struct uplcom_softc *sc, int onoff)
505720abebfSmillert {
506720abebfSmillert
507720abebfSmillert DPRINTF(("uplcom_dtr: onoff=%d\n", onoff));
508720abebfSmillert
509021bcdb4Sdlg if (sc->sc_dtr != -1 && !sc->sc_dtr == !onoff)
510720abebfSmillert return;
511021bcdb4Sdlg
512f1586299Sdjm sc->sc_dtr = !!onoff;
513720abebfSmillert
514720abebfSmillert uplcom_set_line_state(sc);
515720abebfSmillert }
516720abebfSmillert
517720abebfSmillert void
uplcom_rts(struct uplcom_softc * sc,int onoff)518720abebfSmillert uplcom_rts(struct uplcom_softc *sc, int onoff)
519720abebfSmillert {
520720abebfSmillert DPRINTF(("uplcom_rts: onoff=%d\n", onoff));
521720abebfSmillert
522f1586299Sdjm if (sc->sc_rts == -1 && !sc->sc_rts == !onoff)
523720abebfSmillert return;
524021bcdb4Sdlg
525f1586299Sdjm sc->sc_rts = !!onoff;
526720abebfSmillert
527720abebfSmillert uplcom_set_line_state(sc);
528720abebfSmillert }
529720abebfSmillert
530720abebfSmillert void
uplcom_break(struct uplcom_softc * sc,int onoff)531720abebfSmillert uplcom_break(struct uplcom_softc *sc, int onoff)
532720abebfSmillert {
533720abebfSmillert usb_device_request_t req;
534720abebfSmillert
535720abebfSmillert DPRINTF(("uplcom_break: onoff=%d\n", onoff));
536720abebfSmillert
537720abebfSmillert req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
538720abebfSmillert req.bRequest = UCDC_SEND_BREAK;
539720abebfSmillert USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF);
540720abebfSmillert USETW(req.wIndex, sc->sc_iface_number);
541720abebfSmillert USETW(req.wLength, 0);
542720abebfSmillert
543720abebfSmillert (void)usbd_do_request(sc->sc_udev, &req, 0);
544720abebfSmillert }
545720abebfSmillert
546720abebfSmillert usbd_status
uplcom_set_crtscts(struct uplcom_softc * sc)547720abebfSmillert uplcom_set_crtscts(struct uplcom_softc *sc)
548720abebfSmillert {
549720abebfSmillert usb_device_request_t req;
550720abebfSmillert usbd_status err;
551720abebfSmillert
552720abebfSmillert DPRINTF(("uplcom_set_crtscts: on\n"));
553720abebfSmillert
554720abebfSmillert req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
555eccf7d77Spatrick if (sc->sc_type == UPLCOM_TYPE_HXN) {
556eccf7d77Spatrick req.bRequest = UPLCOM_HXN_SET_REQUEST;
557eccf7d77Spatrick USETW(req.wValue, UPLCOM_HXN_SET_CRTSCTS_REG);
558eccf7d77Spatrick USETW(req.wIndex, UPLCOM_HXN_SET_CRTSCTS);
559eccf7d77Spatrick } else {
560720abebfSmillert req.bRequest = UPLCOM_SET_REQUEST;
561720abebfSmillert USETW(req.wValue, 0);
562eccf7d77Spatrick USETW(req.wIndex, (sc->sc_type == UPLCOM_TYPE_HX ?
563eccf7d77Spatrick UPLCOM_HX_SET_CRTSCTS : UPLCOM_SET_CRTSCTS));
564eccf7d77Spatrick }
565720abebfSmillert USETW(req.wLength, 0);
566720abebfSmillert
567720abebfSmillert err = usbd_do_request(sc->sc_udev, &req, 0);
568720abebfSmillert if (err) {
569720abebfSmillert DPRINTF(("uplcom_set_crtscts: failed, err=%s\n",
570720abebfSmillert usbd_errstr(err)));
571720abebfSmillert return (err);
572720abebfSmillert }
573720abebfSmillert
574720abebfSmillert return (USBD_NORMAL_COMPLETION);
575720abebfSmillert }
576720abebfSmillert
577720abebfSmillert usbd_status
uplcom_set_line_coding(struct uplcom_softc * sc,struct usb_cdc_line_state * state)578ab0b1be7Smglocker uplcom_set_line_coding(struct uplcom_softc *sc,
579ab0b1be7Smglocker struct usb_cdc_line_state *state)
580720abebfSmillert {
581720abebfSmillert usb_device_request_t req;
582720abebfSmillert usbd_status err;
583720abebfSmillert
584720abebfSmillert DPRINTF(("uplcom_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n",
585720abebfSmillert UGETDW(state->dwDTERate), state->bCharFormat,
586720abebfSmillert state->bParityType, state->bDataBits));
587720abebfSmillert
588720abebfSmillert if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) {
589720abebfSmillert DPRINTF(("uplcom_set_line_coding: already set\n"));
590720abebfSmillert return (USBD_NORMAL_COMPLETION);
591720abebfSmillert }
592720abebfSmillert
593720abebfSmillert req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
594720abebfSmillert req.bRequest = UCDC_SET_LINE_CODING;
595720abebfSmillert USETW(req.wValue, 0);
596720abebfSmillert USETW(req.wIndex, sc->sc_iface_number);
597720abebfSmillert USETW(req.wLength, UCDC_LINE_STATE_LENGTH);
598720abebfSmillert
599720abebfSmillert err = usbd_do_request(sc->sc_udev, &req, state);
600720abebfSmillert if (err) {
601720abebfSmillert DPRINTF(("uplcom_set_line_coding: failed, err=%s\n",
602720abebfSmillert usbd_errstr(err)));
603720abebfSmillert return (err);
604720abebfSmillert }
605720abebfSmillert
606720abebfSmillert sc->sc_line_state = *state;
607720abebfSmillert
608720abebfSmillert return (USBD_NORMAL_COMPLETION);
609720abebfSmillert }
610720abebfSmillert
611720abebfSmillert int
uplcom_param(void * addr,int portno,struct termios * t)612720abebfSmillert uplcom_param(void *addr, int portno, struct termios *t)
613720abebfSmillert {
614720abebfSmillert struct uplcom_softc *sc = addr;
615720abebfSmillert usbd_status err;
616ab0b1be7Smglocker struct usb_cdc_line_state ls;
617720abebfSmillert
618720abebfSmillert DPRINTF(("uplcom_param: sc=%p\n", sc));
619720abebfSmillert
620720abebfSmillert USETDW(ls.dwDTERate, t->c_ospeed);
621720abebfSmillert if (ISSET(t->c_cflag, CSTOPB))
622720abebfSmillert ls.bCharFormat = UCDC_STOP_BIT_2;
623720abebfSmillert else
624720abebfSmillert ls.bCharFormat = UCDC_STOP_BIT_1;
625720abebfSmillert if (ISSET(t->c_cflag, PARENB)) {
626720abebfSmillert if (ISSET(t->c_cflag, PARODD))
627720abebfSmillert ls.bParityType = UCDC_PARITY_ODD;
628720abebfSmillert else
629720abebfSmillert ls.bParityType = UCDC_PARITY_EVEN;
630720abebfSmillert } else
631720abebfSmillert ls.bParityType = UCDC_PARITY_NONE;
632720abebfSmillert switch (ISSET(t->c_cflag, CSIZE)) {
633720abebfSmillert case CS5:
634720abebfSmillert ls.bDataBits = 5;
635720abebfSmillert break;
636720abebfSmillert case CS6:
637720abebfSmillert ls.bDataBits = 6;
638720abebfSmillert break;
639720abebfSmillert case CS7:
640720abebfSmillert ls.bDataBits = 7;
641720abebfSmillert break;
642720abebfSmillert case CS8:
643720abebfSmillert ls.bDataBits = 8;
644720abebfSmillert break;
645720abebfSmillert }
646720abebfSmillert
647720abebfSmillert err = uplcom_set_line_coding(sc, &ls);
648720abebfSmillert if (err) {
649720abebfSmillert DPRINTF(("uplcom_param: err=%s\n", usbd_errstr(err)));
650720abebfSmillert return (EIO);
651720abebfSmillert }
652720abebfSmillert
653720abebfSmillert if (ISSET(t->c_cflag, CRTSCTS))
654720abebfSmillert uplcom_set_crtscts(sc);
655720abebfSmillert
656021bcdb4Sdlg if (sc->sc_rts == -1 || sc->sc_dtr == -1)
657021bcdb4Sdlg uplcom_set_line_state(sc);
658021bcdb4Sdlg
659720abebfSmillert return (0);
660720abebfSmillert }
661720abebfSmillert
662720abebfSmillert int
uplcom_open(void * addr,int portno)663720abebfSmillert uplcom_open(void *addr, int portno)
664720abebfSmillert {
665720abebfSmillert struct uplcom_softc *sc = addr;
6663aa560b7Sdlg usb_device_request_t req;
6673aa560b7Sdlg usbd_status uerr;
668720abebfSmillert int err;
669720abebfSmillert
670484025c5Spirofti if (usbd_is_dying(sc->sc_udev))
671720abebfSmillert return (EIO);
672720abebfSmillert
673720abebfSmillert DPRINTF(("uplcom_open: sc=%p\n", sc));
674720abebfSmillert
675720abebfSmillert if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
676720abebfSmillert sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
677720abebfSmillert err = usbd_open_pipe_intr(sc->sc_intr_iface, sc->sc_intr_number,
678720abebfSmillert USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc,
679720abebfSmillert sc->sc_intr_buf, sc->sc_isize,
680720abebfSmillert uplcom_intr, USBD_DEFAULT_INTERVAL);
681720abebfSmillert if (err) {
682720abebfSmillert DPRINTF(("%s: cannot open interrupt pipe (addr %d)\n",
6834ab2b9feSmbalmer sc->sc_dev.dv_xname, sc->sc_intr_number));
684720abebfSmillert return (EIO);
685720abebfSmillert }
686720abebfSmillert }
687720abebfSmillert
688eccf7d77Spatrick if (sc->sc_type == UPLCOM_TYPE_HX) {
6893aa560b7Sdlg /*
6903aa560b7Sdlg * Undocumented (vendor unresponsive) - possibly changes
6913aa560b7Sdlg * flow control semantics. It is needed for HX variant devices.
6923aa560b7Sdlg */
6933aa560b7Sdlg req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
6943aa560b7Sdlg req.bRequest = UPLCOM_SET_REQUEST;
6953aa560b7Sdlg USETW(req.wValue, 2);
6963aa560b7Sdlg USETW(req.wIndex, 0x44);
6973aa560b7Sdlg USETW(req.wLength, 0);
6983aa560b7Sdlg
6993aa560b7Sdlg uerr = usbd_do_request(sc->sc_udev, &req, 0);
7003aa560b7Sdlg if (uerr)
7013aa560b7Sdlg return (EIO);
7023aa560b7Sdlg
7033aa560b7Sdlg /* Reset upstream data pipes */
7043aa560b7Sdlg req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
7053aa560b7Sdlg req.bRequest = UPLCOM_SET_REQUEST;
7063aa560b7Sdlg USETW(req.wValue, 8);
7073aa560b7Sdlg USETW(req.wIndex, 0);
7083aa560b7Sdlg USETW(req.wLength, 0);
7093aa560b7Sdlg
7103aa560b7Sdlg uerr = usbd_do_request(sc->sc_udev, &req, 0);
7113aa560b7Sdlg if (uerr)
7123aa560b7Sdlg return (EIO);
7133aa560b7Sdlg
7143aa560b7Sdlg req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
7153aa560b7Sdlg req.bRequest = UPLCOM_SET_REQUEST;
7163aa560b7Sdlg USETW(req.wValue, 9);
7173aa560b7Sdlg USETW(req.wIndex, 0);
7183aa560b7Sdlg USETW(req.wLength, 0);
7193aa560b7Sdlg
7203aa560b7Sdlg uerr = usbd_do_request(sc->sc_udev, &req, 0);
7213aa560b7Sdlg if (uerr)
7223aa560b7Sdlg return (EIO);
7233aa560b7Sdlg }
7243aa560b7Sdlg
725eccf7d77Spatrick if (sc->sc_type == UPLCOM_TYPE_HXN) {
726eccf7d77Spatrick /* Reset upstream data pipes */
727eccf7d77Spatrick req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
728eccf7d77Spatrick req.bRequest = UPLCOM_HXN_SET_REQUEST;
729eccf7d77Spatrick USETW(req.wValue, 0x07);
730eccf7d77Spatrick USETW(req.wIndex, 0x03);
731eccf7d77Spatrick USETW(req.wLength, 0);
732eccf7d77Spatrick
733eccf7d77Spatrick uerr = usbd_do_request(sc->sc_udev, &req, 0);
734eccf7d77Spatrick if (uerr)
735eccf7d77Spatrick return (EIO);
736eccf7d77Spatrick }
737eccf7d77Spatrick
738720abebfSmillert return (0);
739720abebfSmillert }
740720abebfSmillert
741720abebfSmillert void
uplcom_close(void * addr,int portno)742720abebfSmillert uplcom_close(void *addr, int portno)
743720abebfSmillert {
744720abebfSmillert struct uplcom_softc *sc = addr;
745720abebfSmillert int err;
746720abebfSmillert
747484025c5Spirofti if (usbd_is_dying(sc->sc_udev))
748720abebfSmillert return;
749720abebfSmillert
750720abebfSmillert DPRINTF(("uplcom_close: close\n"));
751720abebfSmillert
752720abebfSmillert if (sc->sc_intr_pipe != NULL) {
753720abebfSmillert err = usbd_close_pipe(sc->sc_intr_pipe);
754720abebfSmillert if (err)
755720abebfSmillert printf("%s: close interrupt pipe failed: %s\n",
7564ab2b9feSmbalmer sc->sc_dev.dv_xname, usbd_errstr(err));
757234dfda1Sderaadt free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
758720abebfSmillert sc->sc_intr_pipe = NULL;
759720abebfSmillert }
760720abebfSmillert }
761720abebfSmillert
762720abebfSmillert void
uplcom_intr(struct usbd_xfer * xfer,void * priv,usbd_status status)763ab0b1be7Smglocker uplcom_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
764720abebfSmillert {
765720abebfSmillert struct uplcom_softc *sc = priv;
766720abebfSmillert u_char *buf = sc->sc_intr_buf;
767720abebfSmillert u_char pstatus;
768720abebfSmillert
769484025c5Spirofti if (usbd_is_dying(sc->sc_udev))
770720abebfSmillert return;
771720abebfSmillert
772720abebfSmillert if (status != USBD_NORMAL_COMPLETION) {
773720abebfSmillert if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
774720abebfSmillert return;
775720abebfSmillert
7764ab2b9feSmbalmer DPRINTF(("%s: abnormal status: %s\n", sc->sc_dev.dv_xname,
777720abebfSmillert usbd_errstr(status)));
778720abebfSmillert usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
779720abebfSmillert return;
780720abebfSmillert }
781720abebfSmillert
7824ab2b9feSmbalmer DPRINTF(("%s: uplcom status = %02x\n", sc->sc_dev.dv_xname, buf[8]));
783720abebfSmillert
784720abebfSmillert sc->sc_lsr = sc->sc_msr = 0;
785720abebfSmillert pstatus = buf[8];
786f1f7ba03Sdlg if (ISSET(pstatus, RSAQ_STATUS_CTS))
787f1f7ba03Sdlg sc->sc_msr |= UMSR_CTS;
788f1f7ba03Sdlg else
789f1f7ba03Sdlg sc->sc_msr &= ~UMSR_CTS;
790720abebfSmillert if (ISSET(pstatus, RSAQ_STATUS_DSR))
791720abebfSmillert sc->sc_msr |= UMSR_DSR;
792f1f7ba03Sdlg else
793f1f7ba03Sdlg sc->sc_msr &= ~UMSR_DSR;
794720abebfSmillert if (ISSET(pstatus, RSAQ_STATUS_DCD))
795720abebfSmillert sc->sc_msr |= UMSR_DCD;
796f1f7ba03Sdlg else
797f1f7ba03Sdlg sc->sc_msr &= ~UMSR_DCD;
798720abebfSmillert ucom_status_change((struct ucom_softc *) sc->sc_subdev);
799720abebfSmillert }
800720abebfSmillert
801720abebfSmillert void
uplcom_get_status(void * addr,int portno,u_char * lsr,u_char * msr)802720abebfSmillert uplcom_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
803720abebfSmillert {
804720abebfSmillert struct uplcom_softc *sc = addr;
805720abebfSmillert
806720abebfSmillert DPRINTF(("uplcom_get_status:\n"));
807720abebfSmillert
808720abebfSmillert if (lsr != NULL)
809720abebfSmillert *lsr = sc->sc_lsr;
810720abebfSmillert if (msr != NULL)
811720abebfSmillert *msr = sc->sc_msr;
812720abebfSmillert }
813