ufoma.c (189002) | ufoma.c (189265) |
---|---|
1/* $NetBSD: umodem.c,v 1.45 2002/09/23 05:51:23 simonb Exp $ */ 2 3#include <sys/cdefs.h> | 1/* $NetBSD: umodem.c,v 1.45 2002/09/23 05:51:23 simonb Exp $ */ 2 3#include <sys/cdefs.h> |
4__FBSDID("$FreeBSD: head/sys/dev/usb/serial/ufoma.c 189002 2009-02-24 17:15:29Z ed $"); | 4__FBSDID("$FreeBSD: head/sys/dev/usb/serial/ufoma.c 189265 2009-03-02 02:44:10Z thompsa $"); |
5#define UFOMA_HANDSFREE 6/*- 7 * Copyright (c) 2005, Takanori Watanabe 8 * Copyright (c) 2003, M. Warner Losh <imp@FreeBSD.org>. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions --- 142 unchanged lines hidden (view full) --- 155 UFOMA_BULK_ENDPT_READ, 156 UFOMA_BULK_ENDPT_MAX, 157}; 158 159struct ufoma_softc { 160 struct usb2_com_super_softc sc_super_ucom; 161 struct usb2_com_softc sc_ucom; 162 struct cv sc_cv; | 5#define UFOMA_HANDSFREE 6/*- 7 * Copyright (c) 2005, Takanori Watanabe 8 * Copyright (c) 2003, M. Warner Losh <imp@FreeBSD.org>. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions --- 142 unchanged lines hidden (view full) --- 155 UFOMA_BULK_ENDPT_READ, 156 UFOMA_BULK_ENDPT_MAX, 157}; 158 159struct ufoma_softc { 160 struct usb2_com_super_softc sc_super_ucom; 161 struct usb2_com_softc sc_ucom; 162 struct cv sc_cv; |
163 struct mtx sc_mtx; |
|
163 164 struct usb2_xfer *sc_ctrl_xfer[UFOMA_CTRL_ENDPT_MAX]; 165 struct usb2_xfer *sc_bulk_xfer[UFOMA_BULK_ENDPT_MAX]; 166 uint8_t *sc_modetable; 167 device_t sc_dev; 168 struct usb2_device *sc_udev; 169 170 uint32_t sc_unit; --- 189 unchanged lines hidden (view full) --- 360 usb2_mcpc_acm_descriptor *mad; 361 uint8_t elements; 362 int32_t error; 363 364 sc->sc_udev = uaa->device; 365 sc->sc_dev = dev; 366 sc->sc_unit = device_get_unit(dev); 367 | 164 165 struct usb2_xfer *sc_ctrl_xfer[UFOMA_CTRL_ENDPT_MAX]; 166 struct usb2_xfer *sc_bulk_xfer[UFOMA_BULK_ENDPT_MAX]; 167 uint8_t *sc_modetable; 168 device_t sc_dev; 169 struct usb2_device *sc_udev; 170 171 uint32_t sc_unit; --- 189 unchanged lines hidden (view full) --- 361 usb2_mcpc_acm_descriptor *mad; 362 uint8_t elements; 363 int32_t error; 364 365 sc->sc_udev = uaa->device; 366 sc->sc_dev = dev; 367 sc->sc_unit = device_get_unit(dev); 368 |
369 mtx_init(&sc->sc_mtx, "ufoma", NULL, MTX_DEF); |
|
368 usb2_cv_init(&sc->sc_cv, "CWAIT"); 369 370 device_set_usb2_desc(dev); 371 372 snprintf(sc->sc_name, sizeof(sc->sc_name), 373 "%s", device_get_nameunit(dev)); 374 375 DPRINTF("\n"); 376 377 /* setup control transfers */ 378 379 cd = usb2_get_config_descriptor(uaa->device); 380 id = usb2_get_interface_descriptor(uaa->iface); 381 sc->sc_ctrl_iface_no = id->bInterfaceNumber; 382 sc->sc_ctrl_iface_index = uaa->info.bIfaceIndex; 383 384 error = usb2_transfer_setup(uaa->device, 385 &sc->sc_ctrl_iface_index, sc->sc_ctrl_xfer, | 370 usb2_cv_init(&sc->sc_cv, "CWAIT"); 371 372 device_set_usb2_desc(dev); 373 374 snprintf(sc->sc_name, sizeof(sc->sc_name), 375 "%s", device_get_nameunit(dev)); 376 377 DPRINTF("\n"); 378 379 /* setup control transfers */ 380 381 cd = usb2_get_config_descriptor(uaa->device); 382 id = usb2_get_interface_descriptor(uaa->iface); 383 sc->sc_ctrl_iface_no = id->bInterfaceNumber; 384 sc->sc_ctrl_iface_index = uaa->info.bIfaceIndex; 385 386 error = usb2_transfer_setup(uaa->device, 387 &sc->sc_ctrl_iface_index, sc->sc_ctrl_xfer, |
386 ufoma_ctrl_config, UFOMA_CTRL_ENDPT_MAX, sc, &Giant); | 388 ufoma_ctrl_config, UFOMA_CTRL_ENDPT_MAX, sc, &sc->sc_mtx); |
387 388 if (error) { 389 device_printf(dev, "allocating control USB " 390 "transfers failed!\n"); 391 goto detach; 392 } 393 mad = ufoma_get_intconf(cd, id, UDESC_VS_INTERFACE, UDESCSUB_MCPC_ACM); 394 if (mad == NULL) { --- 24 unchanged lines hidden (view full) --- 419 } 420 sc->sc_modetable[0] = (elements + 1); 421 bcopy(mad->bMode, &sc->sc_modetable[1], elements); 422 423 sc->sc_currentmode = UMCPC_ACM_MODE_UNLINKED; 424 sc->sc_modetoactivate = mad->bMode[0]; 425 426 /* clear stall at first run, if any */ | 389 390 if (error) { 391 device_printf(dev, "allocating control USB " 392 "transfers failed!\n"); 393 goto detach; 394 } 395 mad = ufoma_get_intconf(cd, id, UDESC_VS_INTERFACE, UDESCSUB_MCPC_ACM); 396 if (mad == NULL) { --- 24 unchanged lines hidden (view full) --- 421 } 422 sc->sc_modetable[0] = (elements + 1); 423 bcopy(mad->bMode, &sc->sc_modetable[1], elements); 424 425 sc->sc_currentmode = UMCPC_ACM_MODE_UNLINKED; 426 sc->sc_modetoactivate = mad->bMode[0]; 427 428 /* clear stall at first run, if any */ |
429 mtx_lock(&sc->sc_mtx); |
|
427 usb2_transfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_WRITE]); 428 usb2_transfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_READ]); | 430 usb2_transfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_WRITE]); 431 usb2_transfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_READ]); |
432 mtx_unlock(&sc->sc_mtx); |
|
429 430 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, | 433 434 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, |
431 &ufoma_callback, &Giant); | 435 &ufoma_callback, &sc->sc_mtx); |
432 if (error) { 433 DPRINTF("usb2_com_attach failed\n"); 434 goto detach; 435 } 436 /*Sysctls*/ 437 sctx = device_get_sysctl_ctx(dev); 438 soid = device_get_sysctl_tree(dev); 439 --- 20 unchanged lines hidden (view full) --- 460} 461 462static int 463ufoma_detach(device_t dev) 464{ 465 struct ufoma_softc *sc = device_get_softc(dev); 466 467 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1); | 436 if (error) { 437 DPRINTF("usb2_com_attach failed\n"); 438 goto detach; 439 } 440 /*Sysctls*/ 441 sctx = device_get_sysctl_ctx(dev); 442 soid = device_get_sysctl_tree(dev); 443 --- 20 unchanged lines hidden (view full) --- 464} 465 466static int 467ufoma_detach(device_t dev) 468{ 469 struct ufoma_softc *sc = device_get_softc(dev); 470 471 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1); |
468 | |
469 usb2_transfer_unsetup(sc->sc_ctrl_xfer, UFOMA_CTRL_ENDPT_MAX); | 472 usb2_transfer_unsetup(sc->sc_ctrl_xfer, UFOMA_CTRL_ENDPT_MAX); |
470 | |
471 usb2_transfer_unsetup(sc->sc_bulk_xfer, UFOMA_BULK_ENDPT_MAX); 472 473 if (sc->sc_modetable) { 474 free(sc->sc_modetable, M_USBDEV); 475 } | 473 usb2_transfer_unsetup(sc->sc_bulk_xfer, UFOMA_BULK_ENDPT_MAX); 474 475 if (sc->sc_modetable) { 476 free(sc->sc_modetable, M_USBDEV); 477 } |
478 mtx_destroy(&sc->sc_mtx); |
|
476 usb2_cv_destroy(&sc->sc_cv); 477 478 return (0); 479} 480 481static void * 482ufoma_get_intconf(struct usb2_config_descriptor *cd, struct usb2_interface_descriptor *id, 483 uint8_t type, uint8_t subtype) --- 23 unchanged lines hidden (view full) --- 507 req.bRequest = UMCPC_SET_LINK; 508 USETW(req.wValue, UMCPC_CM_MOBILE_ACM); 509 USETW(req.wIndex, sc->sc_ctrl_iface_no); 510 USETW(req.wLength, sc->sc_modetable[0]); 511 512 usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 513 &req, sc->sc_modetable, 0, 1000); 514 | 479 usb2_cv_destroy(&sc->sc_cv); 480 481 return (0); 482} 483 484static void * 485ufoma_get_intconf(struct usb2_config_descriptor *cd, struct usb2_interface_descriptor *id, 486 uint8_t type, uint8_t subtype) --- 23 unchanged lines hidden (view full) --- 510 req.bRequest = UMCPC_SET_LINK; 511 USETW(req.wValue, UMCPC_CM_MOBILE_ACM); 512 USETW(req.wIndex, sc->sc_ctrl_iface_no); 513 USETW(req.wLength, sc->sc_modetable[0]); 514 515 usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 516 &req, sc->sc_modetable, 0, 1000); 517 |
515 error = usb2_cv_timedwait(&sc->sc_cv, &Giant, hz); | 518 error = usb2_cv_timedwait(&sc->sc_cv, &sc->sc_mtx, hz); |
516 517 if (error) { 518 DPRINTF("NO response\n"); 519 } 520} 521 522static void 523ufoma_cfg_activate_state(struct ufoma_softc *sc, uint16_t state) --- 5 unchanged lines hidden (view full) --- 529 req.bRequest = UMCPC_ACTIVATE_MODE; 530 USETW(req.wValue, state); 531 USETW(req.wIndex, sc->sc_ctrl_iface_no); 532 USETW(req.wLength, 0); 533 534 usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 535 &req, NULL, 0, 1000); 536 | 519 520 if (error) { 521 DPRINTF("NO response\n"); 522 } 523} 524 525static void 526ufoma_cfg_activate_state(struct ufoma_softc *sc, uint16_t state) --- 5 unchanged lines hidden (view full) --- 532 req.bRequest = UMCPC_ACTIVATE_MODE; 533 USETW(req.wValue, state); 534 USETW(req.wIndex, sc->sc_ctrl_iface_no); 535 USETW(req.wLength, 0); 536 537 usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 538 &req, NULL, 0, 1000); 539 |
537 error = usb2_cv_timedwait(&sc->sc_cv, &Giant, | 540 error = usb2_cv_timedwait(&sc->sc_cv, &sc->sc_mtx, |
538 (UFOMA_MAX_TIMEOUT * hz)); 539 if (error) { 540 DPRINTF("No response\n"); 541 } 542} 543 544static void 545ufoma_ctrl_read_callback(struct usb2_xfer *xfer) --- 484 unchanged lines hidden (view full) --- 1030 } else { 1031 device_printf(dev, "no data interface!\n"); 1032 return (EINVAL); 1033 } 1034 } 1035 1036 error = usb2_transfer_setup(uaa->device, 1037 &sc->sc_data_iface_index, sc->sc_bulk_xfer, | 541 (UFOMA_MAX_TIMEOUT * hz)); 542 if (error) { 543 DPRINTF("No response\n"); 544 } 545} 546 547static void 548ufoma_ctrl_read_callback(struct usb2_xfer *xfer) --- 484 unchanged lines hidden (view full) --- 1033 } else { 1034 device_printf(dev, "no data interface!\n"); 1035 return (EINVAL); 1036 } 1037 } 1038 1039 error = usb2_transfer_setup(uaa->device, 1040 &sc->sc_data_iface_index, sc->sc_bulk_xfer, |
1038 ufoma_bulk_config, UFOMA_BULK_ENDPT_MAX, sc, &Giant); | 1041 ufoma_bulk_config, UFOMA_BULK_ENDPT_MAX, sc, &sc->sc_mtx); |
1039 1040 if (error) { 1041 device_printf(dev, "allocating BULK USB " 1042 "transfers failed!\n"); 1043 return (EINVAL); 1044 } 1045 return (0); 1046} --- 166 unchanged lines hidden --- | 1042 1043 if (error) { 1044 device_printf(dev, "allocating BULK USB " 1045 "transfers failed!\n"); 1046 return (EINVAL); 1047 } 1048 return (0); 1049} --- 166 unchanged lines hidden --- |