1 /* $OpenBSD: uplcom.c,v 1.2 2001/10/31 04:24:44 nate Exp $ */ 2 /* $NetBSD: uplcom.c,v 1.20 2001/07/31 12:33:11 ichiro Exp $ */ 3 /* 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Ichiro FUKUHARA (ichiro@ichiro.org). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Simple datasheet 41 * http://www.prolific.com.tw/download/DataSheet/pl2303_ds11.PDF 42 * http://www.nisseisg.co.jp/jyouhou/_cp/@gif/2303.pdf 43 * (english) 44 * 45 */ 46 47 #include <sys/param.h> 48 #include <sys/systm.h> 49 #include <sys/kernel.h> 50 #include <sys/malloc.h> 51 #include <sys/ioctl.h> 52 #include <sys/conf.h> 53 #include <sys/tty.h> 54 #include <sys/file.h> 55 #include <sys/select.h> 56 #include <sys/proc.h> 57 #include <sys/vnode.h> 58 #include <sys/device.h> 59 #include <sys/poll.h> 60 61 #include <dev/usb/usb.h> 62 #include <dev/usb/usbcdc.h> 63 64 #include <dev/usb/usbdi.h> 65 #include <dev/usb/usbdi_util.h> 66 #include <dev/usb/usbdevs.h> 67 #include <dev/usb/usb_quirks.h> 68 69 #include <dev/usb/usbdevs.h> 70 #include <dev/usb/ucomvar.h> 71 72 #ifdef UPLCOM_DEBUG 73 #define DPRINTFN(n, x) if (uplcomdebug > (n)) logprintf x 74 int uplcomdebug = 0; 75 #else 76 #define DPRINTFN(n, x) 77 #endif 78 #define DPRINTF(x) DPRINTFN(0, x) 79 80 #define UPLCOM_CONFIG_INDEX 0 81 #define UPLCOM_IFACE_INDEX 0 82 #define UPLCOM_SECOND_IFACE_INDEX 1 83 84 #define UPLCOM_SET_REQUEST 0x01 85 #define UPLCOM_SET_CRTSCTS 0x41 86 #define RSAQ_STATUS_DSR 0x02 87 #define RSAQ_STATUS_DCD 0x01 88 89 struct uplcom_softc { 90 USBBASEDEVICE sc_dev; /* base device */ 91 usbd_device_handle sc_udev; /* USB device */ 92 usbd_interface_handle sc_iface; /* interface */ 93 int sc_iface_number; /* interface number */ 94 95 usbd_interface_handle sc_intr_iface; /* interrupt interface */ 96 int sc_intr_number; /* interrupt number */ 97 usbd_pipe_handle sc_intr_pipe; /* interrupt pipe */ 98 u_char *sc_intr_buf; /* interrupt buffer */ 99 int sc_isize; 100 101 usb_cdc_line_state_t sc_line_state; /* current line state */ 102 u_char sc_dtr; /* current DTR state */ 103 u_char sc_rts; /* current RTS state */ 104 u_char sc_status; 105 106 device_ptr_t sc_subdev; /* ucom device */ 107 108 u_char sc_dying; /* disconnecting */ 109 110 u_char sc_lsr; /* Local status register */ 111 u_char sc_msr; /* uplcom status register */ 112 }; 113 114 /* 115 * These are the maximum number of bytes transferred per frame. 116 * The output buffer size cannot be increased due to the size encoding. 117 */ 118 #define UPLCOMIBUFSIZE 256 119 #define UPLCOMOBUFSIZE 256 120 121 Static usbd_status uplcom_reset(struct uplcom_softc *); 122 Static usbd_status uplcom_set_line_coding(struct uplcom_softc *sc, 123 usb_cdc_line_state_t *state); 124 Static usbd_status uplcom_set_crtscts(struct uplcom_softc *); 125 Static void uplcom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status); 126 127 Static void uplcom_set(void *, int, int, int); 128 Static void uplcom_dtr(struct uplcom_softc *, int); 129 Static void uplcom_rts(struct uplcom_softc *, int); 130 Static void uplcom_break(struct uplcom_softc *, int); 131 Static void uplcom_set_line_state(struct uplcom_softc *); 132 Static void uplcom_get_status(void *, int portno, u_char *lsr, u_char *msr); 133 #if TODO 134 Static int uplcom_ioctl(void *, int, u_long, caddr_t, int, struct proc *); 135 #endif 136 Static int uplcom_param(void *, int, struct termios *); 137 Static int uplcom_open(void *, int); 138 Static void uplcom_close(void *, int); 139 140 struct ucom_methods uplcom_methods = { 141 uplcom_get_status, 142 uplcom_set, 143 uplcom_param, 144 NULL, /* uplcom_ioctl, TODO */ 145 uplcom_open, 146 uplcom_close, 147 NULL, 148 NULL, 149 }; 150 151 static const struct uplcom_product { 152 uint16_t vendor; 153 uint16_t product; 154 } uplcom_products [] = { 155 /* I/O DATA USB-RSAQ2 */ 156 { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_RSAQ2 }, 157 /* I/O DATA USB-RSAQ */ 158 { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBRSAQ }, 159 /* PLANEX USB-RS232 URS-03 */ 160 { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC232A }, 161 /* IOGEAR/ATEN UC-232A */ 162 { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2303 }, 163 { 0, 0 } 164 }; 165 166 USB_DECLARE_DRIVER(uplcom); 167 168 USB_MATCH(uplcom) 169 { 170 USB_MATCH_START(uplcom, uaa); 171 int i; 172 173 if (uaa->iface != NULL) 174 return (UMATCH_NONE); 175 176 for (i = 0; uplcom_products[i].vendor != 0; i++) { 177 if (uplcom_products[i].vendor == uaa->vendor && 178 uplcom_products[i].product == uaa->product) { 179 return (UMATCH_VENDOR_PRODUCT); 180 } 181 } 182 return (UMATCH_NONE); 183 } 184 185 USB_ATTACH(uplcom) 186 { 187 USB_ATTACH_START(uplcom, sc, uaa); 188 usbd_device_handle dev = uaa->device; 189 usb_config_descriptor_t *cdesc; 190 usb_interface_descriptor_t *id; 191 usb_endpoint_descriptor_t *ed; 192 193 char devinfo[1024]; 194 char *devname = USBDEVNAME(sc->sc_dev); 195 usbd_status err; 196 int i; 197 struct ucom_attach_args uca; 198 199 usbd_devinfo(dev, 0, devinfo); 200 USB_ATTACH_SETUP; 201 printf("%s: %s\n", devname, devinfo); 202 203 sc->sc_udev = dev; 204 205 DPRINTF(("\n\nuplcom attach: sc=%p\n", sc)); 206 207 /* initialize endpoints */ 208 uca.bulkin = uca.bulkout = -1; 209 sc->sc_intr_number = -1; 210 sc->sc_intr_pipe = NULL; 211 212 /* Move the device into the configured state. */ 213 err = usbd_set_config_index(dev, UPLCOM_CONFIG_INDEX, 1); 214 if (err) { 215 printf("\n%s: failed to set configuration, err=%s\n", 216 devname, usbd_errstr(err)); 217 sc->sc_dying = 1; 218 USB_ATTACH_ERROR_RETURN; 219 } 220 221 /* get the config descriptor */ 222 cdesc = usbd_get_config_descriptor(sc->sc_udev); 223 224 if (cdesc == NULL) { 225 printf("%s: failed to get configuration descriptor\n", 226 USBDEVNAME(sc->sc_dev)); 227 sc->sc_dying = 1; 228 USB_ATTACH_ERROR_RETURN; 229 } 230 231 /* get the (first/common) interface */ 232 err = usbd_device2interface_handle(dev, UPLCOM_IFACE_INDEX, 233 &sc->sc_iface); 234 if (err) { 235 printf("\n%s: failed to get interface, err=%s\n", 236 devname, usbd_errstr(err)); 237 sc->sc_dying = 1; 238 USB_ATTACH_ERROR_RETURN; 239 } 240 241 /* Find the interrupt endpoints */ 242 243 id = usbd_get_interface_descriptor(sc->sc_iface); 244 sc->sc_iface_number = id->bInterfaceNumber; 245 246 for (i = 0; i < id->bNumEndpoints; i++) { 247 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i); 248 if (ed == NULL) { 249 printf("%s: no endpoint descriptor for %d\n", 250 USBDEVNAME(sc->sc_dev), i); 251 sc->sc_dying = 1; 252 USB_ATTACH_ERROR_RETURN; 253 } 254 255 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 256 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { 257 sc->sc_intr_number = ed->bEndpointAddress; 258 sc->sc_isize = UGETW(ed->wMaxPacketSize); 259 } 260 } 261 262 if (sc->sc_intr_number== -1) { 263 printf("%s: Could not find interrupt in\n", 264 USBDEVNAME(sc->sc_dev)); 265 sc->sc_dying = 1; 266 USB_ATTACH_ERROR_RETURN; 267 } 268 269 /* keep interface for interrupt */ 270 sc->sc_intr_iface = sc->sc_iface; 271 272 /* 273 * USB-RSAQ1 has two interface 274 * 275 * USB-RSAQ1 | USB-RSAQ2 276 * -----------------+----------------- 277 * Interface 0 |Interface 0 278 * Interrupt(0x81) | Interrupt(0x81) 279 * -----------------+ BulkIN(0x02) 280 * Interface 1 | BulkOUT(0x83) 281 * BulkIN(0x02) | 282 * BulkOUT(0x83) | 283 */ 284 if (cdesc->bNumInterface == 2) { 285 err = usbd_device2interface_handle(dev, 286 UPLCOM_SECOND_IFACE_INDEX, &sc->sc_iface); 287 if (err) { 288 printf("\n%s: failed to get second interface, err=%s\n", 289 devname, usbd_errstr(err)); 290 sc->sc_dying = 1; 291 USB_ATTACH_ERROR_RETURN; 292 } 293 } 294 295 /* Find the bulk{in,out} endpoints */ 296 297 id = usbd_get_interface_descriptor(sc->sc_iface); 298 sc->sc_iface_number = id->bInterfaceNumber; 299 300 for (i = 0; i < id->bNumEndpoints; i++) { 301 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i); 302 if (ed == NULL) { 303 printf("%s: no endpoint descriptor for %d\n", 304 USBDEVNAME(sc->sc_dev), i); 305 sc->sc_dying = 1; 306 USB_ATTACH_ERROR_RETURN; 307 } 308 309 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 310 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 311 uca.bulkin = ed->bEndpointAddress; 312 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && 313 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 314 uca.bulkout = ed->bEndpointAddress; 315 } 316 } 317 318 if (uca.bulkin == -1) { 319 printf("%s: Could not find data bulk in\n", 320 USBDEVNAME(sc->sc_dev)); 321 sc->sc_dying = 1; 322 USB_ATTACH_ERROR_RETURN; 323 } 324 325 if (uca.bulkout == -1) { 326 printf("%s: Could not find data bulk out\n", 327 USBDEVNAME(sc->sc_dev)); 328 sc->sc_dying = 1; 329 USB_ATTACH_ERROR_RETURN; 330 } 331 332 sc->sc_dtr = sc->sc_rts = -1; 333 uca.portno = UCOM_UNK_PORTNO; 334 /* bulkin, bulkout set above */ 335 uca.ibufsize = UPLCOMIBUFSIZE; 336 uca.obufsize = UPLCOMOBUFSIZE; 337 uca.ibufsizepad = UPLCOMIBUFSIZE; 338 uca.opkthdrlen = 0; 339 uca.device = dev; 340 uca.iface = sc->sc_iface; 341 uca.methods = &uplcom_methods; 342 uca.arg = sc; 343 uca.info = NULL; 344 345 err = uplcom_reset(sc); 346 347 if (err) { 348 printf("%s: reset failed, %s\n", USBDEVNAME(sc->sc_dev), 349 usbd_errstr(err)); 350 sc->sc_dying = 1; 351 USB_ATTACH_ERROR_RETURN; 352 } 353 354 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, 355 USBDEV(sc->sc_dev)); 356 357 DPRINTF(("uplcom: in=0x%x out=0x%x intr=0x%x\n", 358 uca.bulkin, uca.bulkout, sc->sc_intr_number )); 359 sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch); 360 361 USB_ATTACH_SUCCESS_RETURN; 362 } 363 364 USB_DETACH(uplcom) 365 { 366 USB_DETACH_START(uplcom, sc); 367 int rv = 0; 368 369 DPRINTF(("uplcom_detach: sc=%p flags=%d\n", sc, flags)); 370 371 if (sc->sc_intr_pipe != NULL) { 372 usbd_abort_pipe(sc->sc_intr_pipe); 373 usbd_close_pipe(sc->sc_intr_pipe); 374 free(sc->sc_intr_buf, M_USBDEV); 375 sc->sc_intr_pipe = NULL; 376 } 377 378 sc->sc_dying = 1; 379 if (sc->sc_subdev != NULL) { 380 rv = config_detach(sc->sc_subdev, flags); 381 sc->sc_subdev = NULL; 382 } 383 384 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, 385 USBDEV(sc->sc_dev)); 386 387 return (rv); 388 } 389 390 int 391 uplcom_activate(device_ptr_t self, enum devact act) 392 { 393 struct uplcom_softc *sc = (struct uplcom_softc *)self; 394 int rv = 0; 395 396 switch (act) { 397 case DVACT_ACTIVATE: 398 return (EOPNOTSUPP); 399 break; 400 401 case DVACT_DEACTIVATE: 402 if (sc->sc_subdev != NULL) 403 rv = config_deactivate(sc->sc_subdev); 404 sc->sc_dying = 1; 405 break; 406 } 407 return (rv); 408 } 409 410 usbd_status 411 uplcom_reset(struct uplcom_softc *sc) 412 { 413 usb_device_request_t req; 414 usbd_status err; 415 416 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 417 req.bRequest = UPLCOM_SET_REQUEST; 418 USETW(req.wValue, 0); 419 USETW(req.wIndex, sc->sc_iface_number); 420 USETW(req.wLength, 0); 421 422 err = usbd_do_request(sc->sc_udev, &req, 0); 423 if (err) 424 return (EIO); 425 426 return (0); 427 } 428 429 void 430 uplcom_set_line_state(struct uplcom_softc *sc) 431 { 432 usb_device_request_t req; 433 int ls; 434 435 ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) | 436 (sc->sc_rts ? UCDC_LINE_RTS : 0); 437 req.bmRequestType = UT_WRITE_CLASS_INTERFACE; 438 req.bRequest = UCDC_SET_CONTROL_LINE_STATE; 439 USETW(req.wValue, ls); 440 USETW(req.wIndex, sc->sc_iface_number); 441 USETW(req.wLength, 0); 442 443 (void)usbd_do_request(sc->sc_udev, &req, 0); 444 445 } 446 447 void 448 uplcom_set(void *addr, int portno, int reg, int onoff) 449 { 450 struct uplcom_softc *sc = addr; 451 452 switch (reg) { 453 case UCOM_SET_DTR: 454 uplcom_dtr(sc, onoff); 455 break; 456 case UCOM_SET_RTS: 457 uplcom_rts(sc, onoff); 458 break; 459 case UCOM_SET_BREAK: 460 uplcom_break(sc, onoff); 461 break; 462 default: 463 break; 464 } 465 } 466 467 void 468 uplcom_dtr(struct uplcom_softc *sc, int onoff) 469 { 470 471 DPRINTF(("uplcom_dtr: onoff=%d\n", onoff)); 472 473 if (sc->sc_dtr == onoff) 474 return; 475 sc->sc_dtr = onoff; 476 477 uplcom_set_line_state(sc); 478 } 479 480 void 481 uplcom_rts(struct uplcom_softc *sc, int onoff) 482 { 483 DPRINTF(("uplcom_rts: onoff=%d\n", onoff)); 484 485 if (sc->sc_rts == onoff) 486 return; 487 sc->sc_rts = onoff; 488 489 uplcom_set_line_state(sc); 490 } 491 492 void 493 uplcom_break(struct uplcom_softc *sc, int onoff) 494 { 495 usb_device_request_t req; 496 497 DPRINTF(("uplcom_break: onoff=%d\n", onoff)); 498 499 req.bmRequestType = UT_WRITE_CLASS_INTERFACE; 500 req.bRequest = UCDC_SEND_BREAK; 501 USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF); 502 USETW(req.wIndex, sc->sc_iface_number); 503 USETW(req.wLength, 0); 504 505 (void)usbd_do_request(sc->sc_udev, &req, 0); 506 } 507 508 usbd_status 509 uplcom_set_crtscts(struct uplcom_softc *sc) 510 { 511 usb_device_request_t req; 512 usbd_status err; 513 514 DPRINTF(("uplcom_set_crtscts: on\n")); 515 516 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 517 req.bRequest = UPLCOM_SET_REQUEST; 518 USETW(req.wValue, 0); 519 USETW(req.wIndex, UPLCOM_SET_CRTSCTS); 520 USETW(req.wLength, 0); 521 522 err = usbd_do_request(sc->sc_udev, &req, 0); 523 if (err) { 524 DPRINTF(("uplcom_set_crtscts: failed, err=%s\n", 525 usbd_errstr(err))); 526 return (err); 527 } 528 529 return (USBD_NORMAL_COMPLETION); 530 } 531 532 usbd_status 533 uplcom_set_line_coding(struct uplcom_softc *sc, usb_cdc_line_state_t *state) 534 { 535 usb_device_request_t req; 536 usbd_status err; 537 538 DPRINTF(("uplcom_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n", 539 UGETDW(state->dwDTERate), state->bCharFormat, 540 state->bParityType, state->bDataBits)); 541 542 if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) { 543 DPRINTF(("uplcom_set_line_coding: already set\n")); 544 return (USBD_NORMAL_COMPLETION); 545 } 546 547 req.bmRequestType = UT_WRITE_CLASS_INTERFACE; 548 req.bRequest = UCDC_SET_LINE_CODING; 549 USETW(req.wValue, 0); 550 USETW(req.wIndex, sc->sc_iface_number); 551 USETW(req.wLength, UCDC_LINE_STATE_LENGTH); 552 553 err = usbd_do_request(sc->sc_udev, &req, state); 554 if (err) { 555 DPRINTF(("uplcom_set_line_coding: failed, err=%s\n", 556 usbd_errstr(err))); 557 return (err); 558 } 559 560 sc->sc_line_state = *state; 561 562 return (USBD_NORMAL_COMPLETION); 563 } 564 565 int 566 uplcom_param(void *addr, int portno, struct termios *t) 567 { 568 struct uplcom_softc *sc = addr; 569 usbd_status err; 570 usb_cdc_line_state_t ls; 571 572 DPRINTF(("uplcom_param: sc=%p\n", sc)); 573 574 USETDW(ls.dwDTERate, t->c_ospeed); 575 if (ISSET(t->c_cflag, CSTOPB)) 576 ls.bCharFormat = UCDC_STOP_BIT_2; 577 else 578 ls.bCharFormat = UCDC_STOP_BIT_1; 579 if (ISSET(t->c_cflag, PARENB)) { 580 if (ISSET(t->c_cflag, PARODD)) 581 ls.bParityType = UCDC_PARITY_ODD; 582 else 583 ls.bParityType = UCDC_PARITY_EVEN; 584 } else 585 ls.bParityType = UCDC_PARITY_NONE; 586 switch (ISSET(t->c_cflag, CSIZE)) { 587 case CS5: 588 ls.bDataBits = 5; 589 break; 590 case CS6: 591 ls.bDataBits = 6; 592 break; 593 case CS7: 594 ls.bDataBits = 7; 595 break; 596 case CS8: 597 ls.bDataBits = 8; 598 break; 599 } 600 601 err = uplcom_set_line_coding(sc, &ls); 602 if (err) { 603 DPRINTF(("uplcom_param: err=%s\n", usbd_errstr(err))); 604 return (EIO); 605 } 606 607 if (ISSET(t->c_cflag, CRTSCTS)) 608 uplcom_set_crtscts(sc); 609 610 if (err) { 611 DPRINTF(("uplcom_param: err=%s\n", usbd_errstr(err))); 612 return (EIO); 613 } 614 615 return (0); 616 } 617 618 int 619 uplcom_open(void *addr, int portno) 620 { 621 struct uplcom_softc *sc = addr; 622 int err; 623 624 if (sc->sc_dying) 625 return (EIO); 626 627 DPRINTF(("uplcom_open: sc=%p\n", sc)); 628 629 if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) { 630 sc->sc_status = 0; /* clear status bit */ 631 sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK); 632 err = usbd_open_pipe_intr(sc->sc_intr_iface, sc->sc_intr_number, 633 USBD_SHORT_XFER_OK, &sc->sc_intr_pipe, sc, 634 sc->sc_intr_buf, sc->sc_isize, 635 uplcom_intr, USBD_DEFAULT_INTERVAL); 636 if (err) { 637 DPRINTF(("%s: cannot open interrupt pipe (addr %d)\n", 638 USBDEVNAME(sc->sc_dev), sc->sc_intr_number)); 639 return (EIO); 640 } 641 } 642 643 return (0); 644 } 645 646 void 647 uplcom_close(void *addr, int portno) 648 { 649 struct uplcom_softc *sc = addr; 650 int err; 651 652 if (sc->sc_dying) 653 return; 654 655 DPRINTF(("uplcom_close: close\n")); 656 657 if (sc->sc_intr_pipe != NULL) { 658 err = usbd_abort_pipe(sc->sc_intr_pipe); 659 if (err) 660 printf("%s: abort interrupt pipe failed: %s\n", 661 USBDEVNAME(sc->sc_dev), usbd_errstr(err)); 662 err = usbd_close_pipe(sc->sc_intr_pipe); 663 if (err) 664 printf("%s: close interrupt pipe failed: %s\n", 665 USBDEVNAME(sc->sc_dev), usbd_errstr(err)); 666 free(sc->sc_intr_buf, M_USBDEV); 667 sc->sc_intr_pipe = NULL; 668 } 669 } 670 671 void 672 uplcom_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) 673 { 674 struct uplcom_softc *sc = priv; 675 u_char *buf = sc->sc_intr_buf; 676 u_char pstatus; 677 678 if (sc->sc_dying) 679 return; 680 681 if (status != USBD_NORMAL_COMPLETION) { 682 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) 683 return; 684 685 DPRINTF(("%s: abnormal status: %s\n", USBDEVNAME(sc->sc_dev), 686 usbd_errstr(status))); 687 usbd_clear_endpoint_stall_async(sc->sc_intr_pipe); 688 return; 689 } 690 691 DPRINTF(("%s: uplcom status = %02x\n", USBDEVNAME(sc->sc_dev), buf[8])); 692 693 sc->sc_lsr = sc->sc_msr = 0; 694 pstatus = buf[8]; 695 if (ISSET(pstatus, RSAQ_STATUS_DSR)) 696 sc->sc_msr |= UMSR_DSR; 697 if (ISSET(pstatus, RSAQ_STATUS_DCD)) 698 sc->sc_msr |= UMSR_DCD; 699 ucom_status_change((struct ucom_softc *) sc->sc_subdev); 700 } 701 702 void 703 uplcom_get_status(void *addr, int portno, u_char *lsr, u_char *msr) 704 { 705 struct uplcom_softc *sc = addr; 706 707 DPRINTF(("uplcom_get_status:\n")); 708 709 if (lsr != NULL) 710 *lsr = sc->sc_lsr; 711 if (msr != NULL) 712 *msr = sc->sc_msr; 713 } 714 715 #if TODO 716 int 717 uplcom_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag, 718 struct proc *p) 719 { 720 struct uplcom_softc *sc = addr; 721 int error = 0; 722 723 if (sc->sc_dying) 724 return (EIO); 725 726 DPRINTF(("uplcom_ioctl: cmd=0x%08lx\n", cmd)); 727 728 switch (cmd) { 729 case TIOCNOTTY: 730 case TIOCMGET: 731 case TIOCMSET: 732 case USB_GET_CM_OVER_DATA: 733 case USB_SET_CM_OVER_DATA: 734 break; 735 736 default: 737 DPRINTF(("uplcom_ioctl: unknown\n")); 738 error = ENOTTY; 739 break; 740 } 741 742 return (error); 743 } 744 #endif 745