113#define USLCOM_FLOW_RTS_ON 0x00000040 /* RTS static active */ 114#define USLCOM_FLOW_RTS_HS 0x00000080 /* RTS handshake */ 115 116/* USLCOM_VENDOR_SPECIFIC values */ 117#define USLCOM_WRITE_LATCH 0x37E1 118#define USLCOM_READ_LATCH 0x00C2 119 120enum { 121 USLCOM_BULK_DT_WR, 122 USLCOM_BULK_DT_RD, 123 USLCOM_CTRL_DT_RD, 124 USLCOM_N_TRANSFER, 125}; 126 127struct uslcom_softc { 128 struct ucom_super_softc sc_super_ucom; 129 struct ucom_softc sc_ucom; 130 struct usb_callout sc_watchdog; 131 132 struct usb_xfer *sc_xfer[USLCOM_N_TRANSFER]; 133 struct usb_device *sc_udev; 134 struct mtx sc_mtx; 135 136 uint8_t sc_msr; 137 uint8_t sc_lsr; 138 uint8_t sc_iface_no; 139}; 140 141static device_probe_t uslcom_probe; 142static device_attach_t uslcom_attach; 143static device_detach_t uslcom_detach; 144static device_free_softc_t uslcom_free_softc; 145 146static usb_callback_t uslcom_write_callback; 147static usb_callback_t uslcom_read_callback; 148static usb_callback_t uslcom_control_callback; 149 150static void uslcom_free(struct ucom_softc *); 151static void uslcom_open(struct ucom_softc *); 152static void uslcom_close(struct ucom_softc *); 153static void uslcom_set_dtr(struct ucom_softc *, uint8_t); 154static void uslcom_set_rts(struct ucom_softc *, uint8_t); 155static void uslcom_set_break(struct ucom_softc *, uint8_t); 156static int uslcom_ioctl(struct ucom_softc *, uint32_t, caddr_t, int, 157 struct thread *); 158static int uslcom_pre_param(struct ucom_softc *, struct termios *); 159static void uslcom_param(struct ucom_softc *, struct termios *); 160static void uslcom_get_status(struct ucom_softc *, uint8_t *, uint8_t *); 161static void uslcom_start_read(struct ucom_softc *); 162static void uslcom_stop_read(struct ucom_softc *); 163static void uslcom_start_write(struct ucom_softc *); 164static void uslcom_stop_write(struct ucom_softc *); 165static void uslcom_poll(struct ucom_softc *ucom); 166 167static const struct usb_config uslcom_config[USLCOM_N_TRANSFER] = { 168 169 [USLCOM_BULK_DT_WR] = { 170 .type = UE_BULK, 171 .endpoint = UE_ADDR_ANY, 172 .direction = UE_DIR_OUT, 173 .bufsize = USLCOM_BULK_BUF_SIZE, 174 .flags = {.pipe_bof = 1,}, 175 .callback = &uslcom_write_callback, 176 }, 177 178 [USLCOM_BULK_DT_RD] = { 179 .type = UE_BULK, 180 .endpoint = UE_ADDR_ANY, 181 .direction = UE_DIR_IN, 182 .bufsize = USLCOM_BULK_BUF_SIZE, 183 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 184 .callback = &uslcom_read_callback, 185 }, 186 [USLCOM_CTRL_DT_RD] = { 187 .type = UE_CONTROL, 188 .endpoint = 0x00, 189 .direction = UE_DIR_ANY, 190 .bufsize = sizeof(struct usb_device_request) + 8, 191 .flags = {.pipe_bof = 1,}, 192 .callback = &uslcom_control_callback, 193 .timeout = 1000, /* 1 second timeout */ 194 }, 195}; 196 197static struct ucom_callback uslcom_callback = { 198 .ucom_cfg_open = &uslcom_open, 199 .ucom_cfg_close = &uslcom_close, 200 .ucom_cfg_get_status = &uslcom_get_status, 201 .ucom_cfg_set_dtr = &uslcom_set_dtr, 202 .ucom_cfg_set_rts = &uslcom_set_rts, 203 .ucom_cfg_set_break = &uslcom_set_break, 204 .ucom_ioctl = &uslcom_ioctl, 205 .ucom_cfg_param = &uslcom_param, 206 .ucom_pre_param = &uslcom_pre_param, 207 .ucom_start_read = &uslcom_start_read, 208 .ucom_stop_read = &uslcom_stop_read, 209 .ucom_start_write = &uslcom_start_write, 210 .ucom_stop_write = &uslcom_stop_write, 211 .ucom_poll = &uslcom_poll, 212 .ucom_free = &uslcom_free, 213}; 214 215static const STRUCT_USB_HOST_ID uslcom_devs[] = { 216#define USLCOM_DEV(v,p) { USB_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p) } 217 USLCOM_DEV(BALTECH, CARDREADER), 218 USLCOM_DEV(CLIPSAL, 5000CT2), 219 USLCOM_DEV(CLIPSAL, 5500PACA), 220 USLCOM_DEV(CLIPSAL, 5500PCU), 221 USLCOM_DEV(CLIPSAL, 560884), 222 USLCOM_DEV(CLIPSAL, 5800PC), 223 USLCOM_DEV(CLIPSAL, C5000CT2), 224 USLCOM_DEV(CLIPSAL, L51xx), 225 USLCOM_DEV(DATAAPEX, MULTICOM), 226 USLCOM_DEV(DELL, DW700), 227 USLCOM_DEV(DIGIANSWER, ZIGBEE802154), 228 USLCOM_DEV(DYNASTREAM, ANTDEVBOARD), 229 USLCOM_DEV(DYNASTREAM, ANTDEVBOARD2), 230 USLCOM_DEV(DYNASTREAM, ANT2USB), 231 USLCOM_DEV(ELV, USBI2C), 232 USLCOM_DEV(FESTO, CMSP), 233 USLCOM_DEV(FESTO, CPX_USB), 234 USLCOM_DEV(FOXCONN, PIRELLI_DP_L10), 235 USLCOM_DEV(FOXCONN, TCOM_TC_300), 236 USLCOM_DEV(GEMALTO, PROXPU), 237 USLCOM_DEV(JABLOTRON, PC60B), 238 USLCOM_DEV(KAMSTRUP, OPTICALEYE), 239 USLCOM_DEV(KAMSTRUP, MBUS_250D), 240 USLCOM_DEV(LINKINSTRUMENTS, MSO19), 241 USLCOM_DEV(LINKINSTRUMENTS, MSO28), 242 USLCOM_DEV(LINKINSTRUMENTS, MSO28_2), 243 USLCOM_DEV(MEI, CASHFLOW_SC), 244 USLCOM_DEV(MEI, S2000), 245 USLCOM_DEV(OWEN, AC4), 246 USLCOM_DEV(PHILIPS, ACE1001), 247 USLCOM_DEV(PLX, CA42), 248 USLCOM_DEV(RENESAS, RX610), 249 USLCOM_DEV(SILABS, AC_SERV_CAN), 250 USLCOM_DEV(SILABS, AC_SERV_CIS), 251 USLCOM_DEV(SILABS, AC_SERV_IBUS), 252 USLCOM_DEV(SILABS, AC_SERV_OBD), 253 USLCOM_DEV(SILABS, AEROCOMM), 254 USLCOM_DEV(SILABS, AMBER_AMB2560), 255 USLCOM_DEV(SILABS, ARGUSISP), 256 USLCOM_DEV(SILABS, ARKHAM_DS101_A), 257 USLCOM_DEV(SILABS, ARKHAM_DS101_M), 258 USLCOM_DEV(SILABS, ARYGON_MIFARE), 259 USLCOM_DEV(SILABS, AVIT_USB_TTL), 260 USLCOM_DEV(SILABS, B_G_H3000), 261 USLCOM_DEV(SILABS, BALLUFF_RFID), 262 USLCOM_DEV(SILABS, BEI_VCP), 263 USLCOM_DEV(SILABS, BSM7DUSB), 264 USLCOM_DEV(SILABS, BURNSIDE), 265 USLCOM_DEV(SILABS, C2_EDGE_MODEM), 266 USLCOM_DEV(SILABS, CP2102), 267 USLCOM_DEV(SILABS, CP210X_2), 268 USLCOM_DEV(SILABS, CP210X_3), 269 USLCOM_DEV(SILABS, CP210X_4), 270 USLCOM_DEV(SILABS, CRUMB128), 271 USLCOM_DEV(SILABS, CYGNAL), 272 USLCOM_DEV(SILABS, CYGNAL_DEBUG), 273 USLCOM_DEV(SILABS, CYGNAL_GPS), 274 USLCOM_DEV(SILABS, DEGREE), 275 USLCOM_DEV(SILABS, DEKTEK_DTAPLUS), 276 USLCOM_DEV(SILABS, EMS_C1007), 277 USLCOM_DEV(SILABS, HAMLINKUSB), 278 USLCOM_DEV(SILABS, HELICOM), 279 USLCOM_DEV(SILABS, IMS_USB_RS422), 280 USLCOM_DEV(SILABS, INFINITY_MIC), 281 USLCOM_DEV(SILABS, INSYS_MODEM), 282 USLCOM_DEV(SILABS, IRZ_SG10), 283 USLCOM_DEV(SILABS, KYOCERA_GPS), 284 USLCOM_DEV(SILABS, LIPOWSKY_HARP), 285 USLCOM_DEV(SILABS, LIPOWSKY_JTAG), 286 USLCOM_DEV(SILABS, LIPOWSKY_LIN), 287 USLCOM_DEV(SILABS, MC35PU), 288 USLCOM_DEV(SILABS, MJS_TOSLINK), 289 USLCOM_DEV(SILABS, MSD_DASHHAWK), 290 USLCOM_DEV(SILABS, MULTIPLEX_RC), 291 USLCOM_DEV(SILABS, OPTRIS_MSPRO), 292 USLCOM_DEV(SILABS, POLOLU), 293 USLCOM_DEV(SILABS, PROCYON_AVS), 294 USLCOM_DEV(SILABS, SB_PARAMOUNT_ME), 295 USLCOM_DEV(SILABS, SUUNTO), 296 USLCOM_DEV(SILABS, TAMSMASTER), 297 USLCOM_DEV(SILABS, TELEGESIS_ETRX2), 298 USLCOM_DEV(SILABS, TRACIENT), 299 USLCOM_DEV(SILABS, TRAQMATE), 300 USLCOM_DEV(SILABS, USBCOUNT50), 301 USLCOM_DEV(SILABS, USBPULSE100), 302 USLCOM_DEV(SILABS, USBSCOPE50), 303 USLCOM_DEV(SILABS, USBWAVE12), 304 USLCOM_DEV(SILABS, VSTABI), 305 USLCOM_DEV(SILABS, WAVIT), 306 USLCOM_DEV(SILABS, WMRBATT), 307 USLCOM_DEV(SILABS, WMRRIGBLASTER), 308 USLCOM_DEV(SILABS, WMRRIGTALK), 309 USLCOM_DEV(SILABS, ZEPHYR_BIO), 310 USLCOM_DEV(SILABS2, DCU11CLONE), 311 USLCOM_DEV(SILABS3, GPRS_MODEM), 312 USLCOM_DEV(SILABS4, 100EU_MODEM), 313 USLCOM_DEV(SYNTECH, CYPHERLAB100), 314 USLCOM_DEV(USI, MC60), 315 USLCOM_DEV(VAISALA, CABLE), 316 USLCOM_DEV(WAGO, SERVICECABLE), 317 USLCOM_DEV(WAVESENSE, JAZZ), 318 USLCOM_DEV(WIENERPLEINBAUS, PL512), 319 USLCOM_DEV(WIENERPLEINBAUS, RCM), 320 USLCOM_DEV(WIENERPLEINBAUS, MPOD), 321 USLCOM_DEV(WIENERPLEINBAUS, CML), 322#undef USLCOM_DEV 323}; 324 325static device_method_t uslcom_methods[] = { 326 DEVMETHOD(device_probe, uslcom_probe), 327 DEVMETHOD(device_attach, uslcom_attach), 328 DEVMETHOD(device_detach, uslcom_detach), 329 DEVMETHOD(device_free_softc, uslcom_free_softc), 330 DEVMETHOD_END 331}; 332 333static devclass_t uslcom_devclass; 334 335static driver_t uslcom_driver = { 336 .name = "uslcom", 337 .methods = uslcom_methods, 338 .size = sizeof(struct uslcom_softc), 339}; 340 341DRIVER_MODULE(uslcom, uhub, uslcom_driver, uslcom_devclass, NULL, 0); 342MODULE_DEPEND(uslcom, ucom, 1, 1, 1); 343MODULE_DEPEND(uslcom, usb, 1, 1, 1); 344MODULE_VERSION(uslcom, 1); 345 346static void 347uslcom_watchdog(void *arg) 348{ 349 struct uslcom_softc *sc = arg; 350 351 mtx_assert(&sc->sc_mtx, MA_OWNED); 352 353 usbd_transfer_start(sc->sc_xfer[USLCOM_CTRL_DT_RD]); 354 355 usb_callout_reset(&sc->sc_watchdog, 356 hz / 4, &uslcom_watchdog, sc); 357} 358 359static int 360uslcom_probe(device_t dev) 361{ 362 struct usb_attach_arg *uaa = device_get_ivars(dev); 363 364 DPRINTFN(11, "\n"); 365 366 if (uaa->usb_mode != USB_MODE_HOST) { 367 return (ENXIO); 368 } 369 if (uaa->info.bConfigIndex != USLCOM_CONFIG_INDEX) { 370 return (ENXIO); 371 } 372 return (usbd_lookup_id_by_uaa(uslcom_devs, sizeof(uslcom_devs), uaa)); 373} 374 375static int 376uslcom_attach(device_t dev) 377{ 378 struct usb_attach_arg *uaa = device_get_ivars(dev); 379 struct uslcom_softc *sc = device_get_softc(dev); 380 int error; 381 382 DPRINTFN(11, "\n"); 383 384 device_set_usb_desc(dev); 385 mtx_init(&sc->sc_mtx, "uslcom", NULL, MTX_DEF); 386 ucom_ref(&sc->sc_super_ucom); 387 usb_callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0); 388 389 sc->sc_udev = uaa->device; 390 /* use the interface number from the USB interface descriptor */ 391 sc->sc_iface_no = uaa->info.bIfaceNum; 392 393 error = usbd_transfer_setup(uaa->device, 394 &uaa->info.bIfaceIndex, sc->sc_xfer, uslcom_config, 395 USLCOM_N_TRANSFER, sc, &sc->sc_mtx); 396 if (error) { 397 DPRINTF("one or more missing USB endpoints, " 398 "error=%s\n", usbd_errstr(error)); 399 goto detach; 400 } 401 /* clear stall at first run */ 402 mtx_lock(&sc->sc_mtx); 403 usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_WR]); 404 usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_RD]); 405 mtx_unlock(&sc->sc_mtx); 406 407 error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 408 &uslcom_callback, &sc->sc_mtx); 409 if (error) { 410 goto detach; 411 } 412 ucom_set_pnpinfo_usb(&sc->sc_super_ucom, dev); 413 414 return (0); 415 416detach: 417 uslcom_detach(dev); 418 return (ENXIO); 419} 420 421static int 422uslcom_detach(device_t dev) 423{ 424 struct uslcom_softc *sc = device_get_softc(dev); 425 426 DPRINTF("sc=%p\n", sc); 427 428 ucom_detach(&sc->sc_super_ucom, &sc->sc_ucom); 429 usbd_transfer_unsetup(sc->sc_xfer, USLCOM_N_TRANSFER); 430 431 usb_callout_drain(&sc->sc_watchdog); 432 433 return (0); 434} 435 436UCOM_UNLOAD_DRAIN(uslcom); 437 438static void 439uslcom_free_softc(device_t dev, void *arg) 440{ 441 struct uslcom_softc *sc = arg; 442 443 if (ucom_unref(&sc->sc_super_ucom)) { 444 if (mtx_initialized(&sc->sc_mtx)) 445 mtx_destroy(&sc->sc_mtx); 446 device_free_softc(dev, sc); 447 } 448} 449 450static void 451uslcom_free(struct ucom_softc *ucom) 452{ 453 uslcom_free_softc(NULL, ucom->sc_parent); 454} 455 456static void 457uslcom_open(struct ucom_softc *ucom) 458{ 459 struct uslcom_softc *sc = ucom->sc_parent; 460 struct usb_device_request req; 461 462 req.bmRequestType = USLCOM_WRITE;
| 118#define USLCOM_FLOW_RTS_ON 0x00000040 /* RTS static active */ 119#define USLCOM_FLOW_RTS_HS 0x00000080 /* RTS handshake */ 120 121/* USLCOM_VENDOR_SPECIFIC values */ 122#define USLCOM_WRITE_LATCH 0x37E1 123#define USLCOM_READ_LATCH 0x00C2 124 125enum { 126 USLCOM_BULK_DT_WR, 127 USLCOM_BULK_DT_RD, 128 USLCOM_CTRL_DT_RD, 129 USLCOM_N_TRANSFER, 130}; 131 132struct uslcom_softc { 133 struct ucom_super_softc sc_super_ucom; 134 struct ucom_softc sc_ucom; 135 struct usb_callout sc_watchdog; 136 137 struct usb_xfer *sc_xfer[USLCOM_N_TRANSFER]; 138 struct usb_device *sc_udev; 139 struct mtx sc_mtx; 140 141 uint8_t sc_msr; 142 uint8_t sc_lsr; 143 uint8_t sc_iface_no; 144}; 145 146static device_probe_t uslcom_probe; 147static device_attach_t uslcom_attach; 148static device_detach_t uslcom_detach; 149static device_free_softc_t uslcom_free_softc; 150 151static usb_callback_t uslcom_write_callback; 152static usb_callback_t uslcom_read_callback; 153static usb_callback_t uslcom_control_callback; 154 155static void uslcom_free(struct ucom_softc *); 156static void uslcom_open(struct ucom_softc *); 157static void uslcom_close(struct ucom_softc *); 158static void uslcom_set_dtr(struct ucom_softc *, uint8_t); 159static void uslcom_set_rts(struct ucom_softc *, uint8_t); 160static void uslcom_set_break(struct ucom_softc *, uint8_t); 161static int uslcom_ioctl(struct ucom_softc *, uint32_t, caddr_t, int, 162 struct thread *); 163static int uslcom_pre_param(struct ucom_softc *, struct termios *); 164static void uslcom_param(struct ucom_softc *, struct termios *); 165static void uslcom_get_status(struct ucom_softc *, uint8_t *, uint8_t *); 166static void uslcom_start_read(struct ucom_softc *); 167static void uslcom_stop_read(struct ucom_softc *); 168static void uslcom_start_write(struct ucom_softc *); 169static void uslcom_stop_write(struct ucom_softc *); 170static void uslcom_poll(struct ucom_softc *ucom); 171 172static const struct usb_config uslcom_config[USLCOM_N_TRANSFER] = { 173 174 [USLCOM_BULK_DT_WR] = { 175 .type = UE_BULK, 176 .endpoint = UE_ADDR_ANY, 177 .direction = UE_DIR_OUT, 178 .bufsize = USLCOM_BULK_BUF_SIZE, 179 .flags = {.pipe_bof = 1,}, 180 .callback = &uslcom_write_callback, 181 }, 182 183 [USLCOM_BULK_DT_RD] = { 184 .type = UE_BULK, 185 .endpoint = UE_ADDR_ANY, 186 .direction = UE_DIR_IN, 187 .bufsize = USLCOM_BULK_BUF_SIZE, 188 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 189 .callback = &uslcom_read_callback, 190 }, 191 [USLCOM_CTRL_DT_RD] = { 192 .type = UE_CONTROL, 193 .endpoint = 0x00, 194 .direction = UE_DIR_ANY, 195 .bufsize = sizeof(struct usb_device_request) + 8, 196 .flags = {.pipe_bof = 1,}, 197 .callback = &uslcom_control_callback, 198 .timeout = 1000, /* 1 second timeout */ 199 }, 200}; 201 202static struct ucom_callback uslcom_callback = { 203 .ucom_cfg_open = &uslcom_open, 204 .ucom_cfg_close = &uslcom_close, 205 .ucom_cfg_get_status = &uslcom_get_status, 206 .ucom_cfg_set_dtr = &uslcom_set_dtr, 207 .ucom_cfg_set_rts = &uslcom_set_rts, 208 .ucom_cfg_set_break = &uslcom_set_break, 209 .ucom_ioctl = &uslcom_ioctl, 210 .ucom_cfg_param = &uslcom_param, 211 .ucom_pre_param = &uslcom_pre_param, 212 .ucom_start_read = &uslcom_start_read, 213 .ucom_stop_read = &uslcom_stop_read, 214 .ucom_start_write = &uslcom_start_write, 215 .ucom_stop_write = &uslcom_stop_write, 216 .ucom_poll = &uslcom_poll, 217 .ucom_free = &uslcom_free, 218}; 219 220static const STRUCT_USB_HOST_ID uslcom_devs[] = { 221#define USLCOM_DEV(v,p) { USB_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p) } 222 USLCOM_DEV(BALTECH, CARDREADER), 223 USLCOM_DEV(CLIPSAL, 5000CT2), 224 USLCOM_DEV(CLIPSAL, 5500PACA), 225 USLCOM_DEV(CLIPSAL, 5500PCU), 226 USLCOM_DEV(CLIPSAL, 560884), 227 USLCOM_DEV(CLIPSAL, 5800PC), 228 USLCOM_DEV(CLIPSAL, C5000CT2), 229 USLCOM_DEV(CLIPSAL, L51xx), 230 USLCOM_DEV(DATAAPEX, MULTICOM), 231 USLCOM_DEV(DELL, DW700), 232 USLCOM_DEV(DIGIANSWER, ZIGBEE802154), 233 USLCOM_DEV(DYNASTREAM, ANTDEVBOARD), 234 USLCOM_DEV(DYNASTREAM, ANTDEVBOARD2), 235 USLCOM_DEV(DYNASTREAM, ANT2USB), 236 USLCOM_DEV(ELV, USBI2C), 237 USLCOM_DEV(FESTO, CMSP), 238 USLCOM_DEV(FESTO, CPX_USB), 239 USLCOM_DEV(FOXCONN, PIRELLI_DP_L10), 240 USLCOM_DEV(FOXCONN, TCOM_TC_300), 241 USLCOM_DEV(GEMALTO, PROXPU), 242 USLCOM_DEV(JABLOTRON, PC60B), 243 USLCOM_DEV(KAMSTRUP, OPTICALEYE), 244 USLCOM_DEV(KAMSTRUP, MBUS_250D), 245 USLCOM_DEV(LINKINSTRUMENTS, MSO19), 246 USLCOM_DEV(LINKINSTRUMENTS, MSO28), 247 USLCOM_DEV(LINKINSTRUMENTS, MSO28_2), 248 USLCOM_DEV(MEI, CASHFLOW_SC), 249 USLCOM_DEV(MEI, S2000), 250 USLCOM_DEV(OWEN, AC4), 251 USLCOM_DEV(PHILIPS, ACE1001), 252 USLCOM_DEV(PLX, CA42), 253 USLCOM_DEV(RENESAS, RX610), 254 USLCOM_DEV(SILABS, AC_SERV_CAN), 255 USLCOM_DEV(SILABS, AC_SERV_CIS), 256 USLCOM_DEV(SILABS, AC_SERV_IBUS), 257 USLCOM_DEV(SILABS, AC_SERV_OBD), 258 USLCOM_DEV(SILABS, AEROCOMM), 259 USLCOM_DEV(SILABS, AMBER_AMB2560), 260 USLCOM_DEV(SILABS, ARGUSISP), 261 USLCOM_DEV(SILABS, ARKHAM_DS101_A), 262 USLCOM_DEV(SILABS, ARKHAM_DS101_M), 263 USLCOM_DEV(SILABS, ARYGON_MIFARE), 264 USLCOM_DEV(SILABS, AVIT_USB_TTL), 265 USLCOM_DEV(SILABS, B_G_H3000), 266 USLCOM_DEV(SILABS, BALLUFF_RFID), 267 USLCOM_DEV(SILABS, BEI_VCP), 268 USLCOM_DEV(SILABS, BSM7DUSB), 269 USLCOM_DEV(SILABS, BURNSIDE), 270 USLCOM_DEV(SILABS, C2_EDGE_MODEM), 271 USLCOM_DEV(SILABS, CP2102), 272 USLCOM_DEV(SILABS, CP210X_2), 273 USLCOM_DEV(SILABS, CP210X_3), 274 USLCOM_DEV(SILABS, CP210X_4), 275 USLCOM_DEV(SILABS, CRUMB128), 276 USLCOM_DEV(SILABS, CYGNAL), 277 USLCOM_DEV(SILABS, CYGNAL_DEBUG), 278 USLCOM_DEV(SILABS, CYGNAL_GPS), 279 USLCOM_DEV(SILABS, DEGREE), 280 USLCOM_DEV(SILABS, DEKTEK_DTAPLUS), 281 USLCOM_DEV(SILABS, EMS_C1007), 282 USLCOM_DEV(SILABS, HAMLINKUSB), 283 USLCOM_DEV(SILABS, HELICOM), 284 USLCOM_DEV(SILABS, IMS_USB_RS422), 285 USLCOM_DEV(SILABS, INFINITY_MIC), 286 USLCOM_DEV(SILABS, INSYS_MODEM), 287 USLCOM_DEV(SILABS, IRZ_SG10), 288 USLCOM_DEV(SILABS, KYOCERA_GPS), 289 USLCOM_DEV(SILABS, LIPOWSKY_HARP), 290 USLCOM_DEV(SILABS, LIPOWSKY_JTAG), 291 USLCOM_DEV(SILABS, LIPOWSKY_LIN), 292 USLCOM_DEV(SILABS, MC35PU), 293 USLCOM_DEV(SILABS, MJS_TOSLINK), 294 USLCOM_DEV(SILABS, MSD_DASHHAWK), 295 USLCOM_DEV(SILABS, MULTIPLEX_RC), 296 USLCOM_DEV(SILABS, OPTRIS_MSPRO), 297 USLCOM_DEV(SILABS, POLOLU), 298 USLCOM_DEV(SILABS, PROCYON_AVS), 299 USLCOM_DEV(SILABS, SB_PARAMOUNT_ME), 300 USLCOM_DEV(SILABS, SUUNTO), 301 USLCOM_DEV(SILABS, TAMSMASTER), 302 USLCOM_DEV(SILABS, TELEGESIS_ETRX2), 303 USLCOM_DEV(SILABS, TRACIENT), 304 USLCOM_DEV(SILABS, TRAQMATE), 305 USLCOM_DEV(SILABS, USBCOUNT50), 306 USLCOM_DEV(SILABS, USBPULSE100), 307 USLCOM_DEV(SILABS, USBSCOPE50), 308 USLCOM_DEV(SILABS, USBWAVE12), 309 USLCOM_DEV(SILABS, VSTABI), 310 USLCOM_DEV(SILABS, WAVIT), 311 USLCOM_DEV(SILABS, WMRBATT), 312 USLCOM_DEV(SILABS, WMRRIGBLASTER), 313 USLCOM_DEV(SILABS, WMRRIGTALK), 314 USLCOM_DEV(SILABS, ZEPHYR_BIO), 315 USLCOM_DEV(SILABS2, DCU11CLONE), 316 USLCOM_DEV(SILABS3, GPRS_MODEM), 317 USLCOM_DEV(SILABS4, 100EU_MODEM), 318 USLCOM_DEV(SYNTECH, CYPHERLAB100), 319 USLCOM_DEV(USI, MC60), 320 USLCOM_DEV(VAISALA, CABLE), 321 USLCOM_DEV(WAGO, SERVICECABLE), 322 USLCOM_DEV(WAVESENSE, JAZZ), 323 USLCOM_DEV(WIENERPLEINBAUS, PL512), 324 USLCOM_DEV(WIENERPLEINBAUS, RCM), 325 USLCOM_DEV(WIENERPLEINBAUS, MPOD), 326 USLCOM_DEV(WIENERPLEINBAUS, CML), 327#undef USLCOM_DEV 328}; 329 330static device_method_t uslcom_methods[] = { 331 DEVMETHOD(device_probe, uslcom_probe), 332 DEVMETHOD(device_attach, uslcom_attach), 333 DEVMETHOD(device_detach, uslcom_detach), 334 DEVMETHOD(device_free_softc, uslcom_free_softc), 335 DEVMETHOD_END 336}; 337 338static devclass_t uslcom_devclass; 339 340static driver_t uslcom_driver = { 341 .name = "uslcom", 342 .methods = uslcom_methods, 343 .size = sizeof(struct uslcom_softc), 344}; 345 346DRIVER_MODULE(uslcom, uhub, uslcom_driver, uslcom_devclass, NULL, 0); 347MODULE_DEPEND(uslcom, ucom, 1, 1, 1); 348MODULE_DEPEND(uslcom, usb, 1, 1, 1); 349MODULE_VERSION(uslcom, 1); 350 351static void 352uslcom_watchdog(void *arg) 353{ 354 struct uslcom_softc *sc = arg; 355 356 mtx_assert(&sc->sc_mtx, MA_OWNED); 357 358 usbd_transfer_start(sc->sc_xfer[USLCOM_CTRL_DT_RD]); 359 360 usb_callout_reset(&sc->sc_watchdog, 361 hz / 4, &uslcom_watchdog, sc); 362} 363 364static int 365uslcom_probe(device_t dev) 366{ 367 struct usb_attach_arg *uaa = device_get_ivars(dev); 368 369 DPRINTFN(11, "\n"); 370 371 if (uaa->usb_mode != USB_MODE_HOST) { 372 return (ENXIO); 373 } 374 if (uaa->info.bConfigIndex != USLCOM_CONFIG_INDEX) { 375 return (ENXIO); 376 } 377 return (usbd_lookup_id_by_uaa(uslcom_devs, sizeof(uslcom_devs), uaa)); 378} 379 380static int 381uslcom_attach(device_t dev) 382{ 383 struct usb_attach_arg *uaa = device_get_ivars(dev); 384 struct uslcom_softc *sc = device_get_softc(dev); 385 int error; 386 387 DPRINTFN(11, "\n"); 388 389 device_set_usb_desc(dev); 390 mtx_init(&sc->sc_mtx, "uslcom", NULL, MTX_DEF); 391 ucom_ref(&sc->sc_super_ucom); 392 usb_callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0); 393 394 sc->sc_udev = uaa->device; 395 /* use the interface number from the USB interface descriptor */ 396 sc->sc_iface_no = uaa->info.bIfaceNum; 397 398 error = usbd_transfer_setup(uaa->device, 399 &uaa->info.bIfaceIndex, sc->sc_xfer, uslcom_config, 400 USLCOM_N_TRANSFER, sc, &sc->sc_mtx); 401 if (error) { 402 DPRINTF("one or more missing USB endpoints, " 403 "error=%s\n", usbd_errstr(error)); 404 goto detach; 405 } 406 /* clear stall at first run */ 407 mtx_lock(&sc->sc_mtx); 408 usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_WR]); 409 usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_RD]); 410 mtx_unlock(&sc->sc_mtx); 411 412 error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 413 &uslcom_callback, &sc->sc_mtx); 414 if (error) { 415 goto detach; 416 } 417 ucom_set_pnpinfo_usb(&sc->sc_super_ucom, dev); 418 419 return (0); 420 421detach: 422 uslcom_detach(dev); 423 return (ENXIO); 424} 425 426static int 427uslcom_detach(device_t dev) 428{ 429 struct uslcom_softc *sc = device_get_softc(dev); 430 431 DPRINTF("sc=%p\n", sc); 432 433 ucom_detach(&sc->sc_super_ucom, &sc->sc_ucom); 434 usbd_transfer_unsetup(sc->sc_xfer, USLCOM_N_TRANSFER); 435 436 usb_callout_drain(&sc->sc_watchdog); 437 438 return (0); 439} 440 441UCOM_UNLOAD_DRAIN(uslcom); 442 443static void 444uslcom_free_softc(device_t dev, void *arg) 445{ 446 struct uslcom_softc *sc = arg; 447 448 if (ucom_unref(&sc->sc_super_ucom)) { 449 if (mtx_initialized(&sc->sc_mtx)) 450 mtx_destroy(&sc->sc_mtx); 451 device_free_softc(dev, sc); 452 } 453} 454 455static void 456uslcom_free(struct ucom_softc *ucom) 457{ 458 uslcom_free_softc(NULL, ucom->sc_parent); 459} 460 461static void 462uslcom_open(struct ucom_softc *ucom) 463{ 464 struct uslcom_softc *sc = ucom->sc_parent; 465 struct usb_device_request req; 466 467 req.bmRequestType = USLCOM_WRITE;
|