1#include <sys/cdefs.h> |
2__FBSDID("$FreeBSD: head/sys/dev/usb2/serial/umct2.c 188413 2009-02-09 22:05:25Z thompsa $"); |
3 4/*- 5 * Copyright (c) 2003 Scott Long 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: --- 67 unchanged lines hidden (view full) --- 78 79#define UMCT_INTR_INTERVAL 100 80#define UMCT_IFACE_INDEX 0 81#define UMCT_CONFIG_INDEX 1 82 83enum { 84 UMCT_BULK_DT_WR, 85 UMCT_BULK_DT_RD, |
86 UMCT_INTR_DT_RD, |
87 UMCT_N_TRANSFER, |
88}; 89 90struct umct_softc { 91 struct usb2_com_super_softc sc_super_ucom; 92 struct usb2_com_softc sc_ucom; 93 94 struct usb2_device *sc_udev; 95 struct usb2_xfer *sc_xfer[UMCT_N_TRANSFER]; 96 97 uint32_t sc_unit; 98 99 uint16_t sc_obufsize; 100 101 uint8_t sc_lsr; 102 uint8_t sc_msr; 103 uint8_t sc_lcr; 104 uint8_t sc_mcr; |
105 uint8_t sc_iface_no; |
106 uint8_t sc_name[16]; |
107}; 108 109/* prototypes */ 110 111static device_probe_t umct_probe; 112static device_attach_t umct_attach; 113static device_detach_t umct_detach; 114 |
115static usb2_callback_t umct_intr_callback; 116static usb2_callback_t umct_write_callback; |
117static usb2_callback_t umct_read_callback; |
118 |
119static void umct_cfg_do_request(struct umct_softc *sc, uint8_t request, 120 uint16_t len, uint32_t value); |
121static void umct_cfg_get_status(struct usb2_com_softc *, uint8_t *, 122 uint8_t *); 123static void umct_cfg_set_break(struct usb2_com_softc *, uint8_t); 124static void umct_cfg_set_dtr(struct usb2_com_softc *, uint8_t); 125static void umct_cfg_set_rts(struct usb2_com_softc *, uint8_t); 126static uint8_t umct_calc_baud(uint32_t); 127static int umct_pre_param(struct usb2_com_softc *, struct termios *); 128static void umct_cfg_param(struct usb2_com_softc *, struct termios *); --- 18 unchanged lines hidden (view full) --- 147 .endpoint = UE_ADDR_ANY, 148 .direction = UE_DIR_IN, 149 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 150 .mh.bufsize = 0, /* use wMaxPacketSize */ 151 .mh.callback = &umct_read_callback, 152 .ep_index = 0, /* first interrupt endpoint */ 153 }, 154 |
155 [UMCT_INTR_DT_RD] = { 156 .type = UE_INTERRUPT, 157 .endpoint = UE_ADDR_ANY, 158 .direction = UE_DIR_IN, 159 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 160 .mh.bufsize = 0, /* use wMaxPacketSize */ 161 .mh.callback = &umct_intr_callback, 162 .ep_index = 1, /* second interrupt endpoint */ 163 }, |
164}; 165 166static const struct usb2_com_callback umct_callback = { 167 .usb2_com_cfg_get_status = &umct_cfg_get_status, 168 .usb2_com_cfg_set_dtr = &umct_cfg_set_dtr, 169 .usb2_com_cfg_set_rts = &umct_cfg_set_rts, 170 .usb2_com_cfg_set_break = &umct_cfg_set_break, 171 .usb2_com_cfg_param = &umct_cfg_param, --- 128 unchanged lines hidden (view full) --- 300static void 301umct_cfg_do_request(struct umct_softc *sc, uint8_t request, 302 uint16_t len, uint32_t value) 303{ 304 struct usb2_device_request req; 305 usb2_error_t err; 306 uint8_t temp[4]; 307 |
308 if (len > 4) |
309 len = 4; |
310 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 311 req.bRequest = request; 312 USETW(req.wValue, 0); 313 req.wIndex[0] = sc->sc_iface_no; 314 req.wIndex[1] = 0; 315 USETW(req.wLength, len); 316 USETDW(temp, value); 317 |
318 err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 319 &req, temp, 0, 1000); |
320 if (err) { 321 DPRINTFN(0, "device request failed, err=%s " 322 "(ignored)\n", usb2_errstr(err)); 323 } |
324 return; 325} 326 327static void |
328umct_intr_callback(struct usb2_xfer *xfer) 329{ 330 struct umct_softc *sc = xfer->priv_sc; 331 uint8_t buf[2]; 332 333 switch (USB_GET_STATE(xfer)) { 334 case USB_ST_TRANSFERRED: 335 if (xfer->actlen < 2) { --- 4 unchanged lines hidden (view full) --- 340 341 sc->sc_msr = buf[0]; 342 sc->sc_lsr = buf[1]; 343 344 usb2_com_status_change(&sc->sc_ucom); 345 346 case USB_ST_SETUP: 347tr_setup: |
348 xfer->frlengths[0] = xfer->max_data_length; 349 usb2_start_hardware(xfer); |
350 return; 351 352 default: /* Error */ 353 if (xfer->error != USB_ERR_CANCELLED) { |
354 /* try to clear stall first */ 355 xfer->flags.stall_pipe = 1; 356 goto tr_setup; |
357 } 358 return; |
359 } 360} 361 362static void 363umct_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr) 364{ 365 struct umct_softc *sc = ucom->sc_parent; 366 --- 130 unchanged lines hidden (view full) --- 497} 498 499static void 500umct_stop_read(struct usb2_com_softc *ucom) 501{ 502 struct umct_softc *sc = ucom->sc_parent; 503 504 /* stop interrupt endpoint */ |
505 usb2_transfer_stop(sc->sc_xfer[UMCT_INTR_DT_RD]); 506 507 /* stop read endpoint */ |
508 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_DT_RD]); 509} 510 511static void 512umct_start_write(struct usb2_com_softc *ucom) 513{ 514 struct umct_softc *sc = ucom->sc_parent; 515 516 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_DT_WR]); 517} 518 519static void 520umct_stop_write(struct usb2_com_softc *ucom) 521{ 522 struct umct_softc *sc = ucom->sc_parent; 523 |
524 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_DT_WR]); 525} 526 527static void 528umct_write_callback(struct usb2_xfer *xfer) 529{ 530 struct umct_softc *sc = xfer->priv_sc; 531 uint32_t actlen; 532 533 switch (USB_GET_STATE(xfer)) { 534 case USB_ST_SETUP: 535 case USB_ST_TRANSFERRED: |
536tr_setup: |
537 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0, 538 sc->sc_obufsize, &actlen)) { 539 540 xfer->frlengths[0] = actlen; 541 usb2_start_hardware(xfer); 542 } 543 return; 544 545 default: /* Error */ 546 if (xfer->error != USB_ERR_CANCELLED) { |
547 /* try to clear stall first */ 548 xfer->flags.stall_pipe = 1; 549 goto tr_setup; |
550 } 551 return; |
552 } 553} 554 555static void |
556umct_read_callback(struct usb2_xfer *xfer) 557{ 558 struct umct_softc *sc = xfer->priv_sc; 559 560 switch (USB_GET_STATE(xfer)) { 561 case USB_ST_TRANSFERRED: 562 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 563 0, xfer->actlen); 564 565 case USB_ST_SETUP: |
566tr_setup: 567 xfer->frlengths[0] = xfer->max_data_length; 568 usb2_start_hardware(xfer); |
569 return; 570 571 default: /* Error */ 572 if (xfer->error != USB_ERR_CANCELLED) { |
573 /* try to clear stall first */ 574 xfer->flags.stall_pipe = 1; 575 goto tr_setup; |
576 } 577 return; |
578 } 579} |