uhid.c (187970) | uhid.c (187994) |
---|---|
1/* $NetBSD: uhid.c,v 1.46 2001/11/13 06:24:55 lukem Exp $ */ 2 3/* Also already merged from NetBSD: 4 * $NetBSD: uhid.c,v 1.54 2002/09/23 05:51:21 simonb Exp $ 5 */ 6 7#include <sys/cdefs.h> | 1/* $NetBSD: uhid.c,v 1.46 2001/11/13 06:24:55 lukem Exp $ */ 2 3/* Also already merged from NetBSD: 4 * $NetBSD: uhid.c,v 1.54 2002/09/23 05:51:21 simonb Exp $ 5 */ 6 7#include <sys/cdefs.h> |
8__FBSDID("$FreeBSD: head/sys/dev/usb2/input/uhid2.c 187970 2009-02-01 00:51:25Z thompsa $"); | 8__FBSDID("$FreeBSD: head/sys/dev/usb2/input/uhid2.c 187994 2009-02-02 00:49:39Z alfred $"); |
9 10/*- 11 * Copyright (c) 1998 The NetBSD Foundation, Inc. 12 * All rights reserved. 13 * 14 * This code is derived from software contributed to The NetBSD Foundation 15 * by Lennart Augustsson (lennart@augustsson.net) at 16 * Carlstedt Research & Technology. --- 65 unchanged lines hidden (view full) --- 82 &uhid_debug, 0, "Debug level"); 83#endif 84 85#define UHID_BSIZE 1024 /* bytes, buffer size */ 86#define UHID_FRAME_NUM 50 /* bytes, frame number */ 87 88enum { 89 UHID_INTR_DT_RD, | 9 10/*- 11 * Copyright (c) 1998 The NetBSD Foundation, Inc. 12 * All rights reserved. 13 * 14 * This code is derived from software contributed to The NetBSD Foundation 15 * by Lennart Augustsson (lennart@augustsson.net) at 16 * Carlstedt Research & Technology. --- 65 unchanged lines hidden (view full) --- 82 &uhid_debug, 0, "Debug level"); 83#endif 84 85#define UHID_BSIZE 1024 /* bytes, buffer size */ 86#define UHID_FRAME_NUM 50 /* bytes, frame number */ 87 88enum { 89 UHID_INTR_DT_RD, |
90 UHID_INTR_CS_RD, | |
91 UHID_CTRL_DT_WR, 92 UHID_CTRL_DT_RD, | 90 UHID_CTRL_DT_WR, 91 UHID_CTRL_DT_RD, |
93 UHID_N_TRANSFER = 4, | 92 UHID_N_TRANSFER, |
94}; 95 96struct uhid_softc { 97 struct usb2_fifo_sc sc_fifo; 98 struct mtx sc_mtx; 99 100 struct usb2_xfer *sc_xfer[UHID_N_TRANSFER]; 101 struct usb2_device *sc_udev; --- 7 unchanged lines hidden (view full) --- 109 110 uint8_t sc_iface_no; 111 uint8_t sc_iface_index; 112 uint8_t sc_iid; 113 uint8_t sc_oid; 114 uint8_t sc_fid; 115 uint8_t sc_flags; 116#define UHID_FLAG_IMMED 0x01 /* set if read should be immediate */ | 93}; 94 95struct uhid_softc { 96 struct usb2_fifo_sc sc_fifo; 97 struct mtx sc_mtx; 98 99 struct usb2_xfer *sc_xfer[UHID_N_TRANSFER]; 100 struct usb2_device *sc_udev; --- 7 unchanged lines hidden (view full) --- 108 109 uint8_t sc_iface_no; 110 uint8_t sc_iface_index; 111 uint8_t sc_iid; 112 uint8_t sc_oid; 113 uint8_t sc_fid; 114 uint8_t sc_flags; 115#define UHID_FLAG_IMMED 0x01 /* set if read should be immediate */ |
117#define UHID_FLAG_INTR_STALL 0x02 /* set if interrupt transfer stalled */ | |
118#define UHID_FLAG_STATIC_DESC 0x04 /* set if report descriptors are 119 * static */ 120}; 121 122static const uint8_t uhid_xb360gp_report_descr[] = {UHID_XB360GP_REPORT_DESCR()}; 123static const uint8_t uhid_graphire_report_descr[] = {UHID_GRAPHIRE_REPORT_DESCR()}; 124static const uint8_t uhid_graphire3_4x5_report_descr[] = {UHID_GRAPHIRE3_4X5_REPORT_DESCR()}; 125 126/* prototypes */ 127 128static device_probe_t uhid_probe; 129static device_attach_t uhid_attach; 130static device_detach_t uhid_detach; 131 132static usb2_callback_t uhid_intr_callback; | 116#define UHID_FLAG_STATIC_DESC 0x04 /* set if report descriptors are 117 * static */ 118}; 119 120static const uint8_t uhid_xb360gp_report_descr[] = {UHID_XB360GP_REPORT_DESCR()}; 121static const uint8_t uhid_graphire_report_descr[] = {UHID_GRAPHIRE_REPORT_DESCR()}; 122static const uint8_t uhid_graphire3_4x5_report_descr[] = {UHID_GRAPHIRE3_4X5_REPORT_DESCR()}; 123 124/* prototypes */ 125 126static device_probe_t uhid_probe; 127static device_attach_t uhid_attach; 128static device_detach_t uhid_detach; 129 130static usb2_callback_t uhid_intr_callback; |
133static usb2_callback_t uhid_intr_clear_stall_callback; | |
134static usb2_callback_t uhid_write_callback; 135static usb2_callback_t uhid_read_callback; 136 137static usb2_fifo_cmd_t uhid_start_read; 138static usb2_fifo_cmd_t uhid_stop_read; 139static usb2_fifo_cmd_t uhid_start_write; 140static usb2_fifo_cmd_t uhid_stop_write; 141static usb2_fifo_open_t uhid_open; --- 27 unchanged lines hidden (view full) --- 169 0, sc->sc_isize, 1); 170 } else { 171 /* ignore it */ 172 DPRINTF("ignored short transfer, " 173 "%d bytes\n", xfer->actlen); 174 } 175 176 case USB_ST_SETUP: | 131static usb2_callback_t uhid_write_callback; 132static usb2_callback_t uhid_read_callback; 133 134static usb2_fifo_cmd_t uhid_start_read; 135static usb2_fifo_cmd_t uhid_stop_read; 136static usb2_fifo_cmd_t uhid_start_write; 137static usb2_fifo_cmd_t uhid_stop_write; 138static usb2_fifo_open_t uhid_open; --- 27 unchanged lines hidden (view full) --- 166 0, sc->sc_isize, 1); 167 } else { 168 /* ignore it */ 169 DPRINTF("ignored short transfer, " 170 "%d bytes\n", xfer->actlen); 171 } 172 173 case USB_ST_SETUP: |
177 if (sc->sc_flags & UHID_FLAG_INTR_STALL) { 178 usb2_transfer_start(sc->sc_xfer[UHID_INTR_CS_RD]); 179 } else { 180 if (usb2_fifo_put_bytes_max( 181 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) { 182 xfer->frlengths[0] = xfer->max_data_length; 183 usb2_start_hardware(xfer); 184 } | 174re_submit: 175 if (usb2_fifo_put_bytes_max( 176 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) { 177 xfer->frlengths[0] = sc->sc_isize; 178 usb2_start_hardware(xfer); |
185 } 186 return; 187 188 default: /* Error */ 189 if (xfer->error != USB_ERR_CANCELLED) { 190 /* try to clear stall first */ | 179 } 180 return; 181 182 default: /* Error */ 183 if (xfer->error != USB_ERR_CANCELLED) { 184 /* try to clear stall first */ |
191 sc->sc_flags |= UHID_FLAG_INTR_STALL; 192 usb2_transfer_start(sc->sc_xfer[UHID_INTR_CS_RD]); | 185 xfer->flags.stall_pipe = 1; 186 goto re_submit; |
193 } 194 return; 195 } 196} 197 198static void | 187 } 188 return; 189 } 190} 191 192static void |
199uhid_intr_clear_stall_callback(struct usb2_xfer *xfer) 200{ 201 struct uhid_softc *sc = xfer->priv_sc; 202 struct usb2_xfer *xfer_other = sc->sc_xfer[UHID_INTR_DT_RD]; 203 204 if (usb2_clear_stall_callback(xfer, xfer_other)) { 205 DPRINTF("stall cleared\n"); 206 sc->sc_flags &= ~UHID_FLAG_INTR_STALL; 207 usb2_transfer_start(xfer_other); 208 } 209} 210 211static void | |
212uhid_fill_set_report(struct usb2_device_request *req, uint8_t iface_no, 213 uint8_t type, uint8_t id, uint16_t size) 214{ 215 req->bmRequestType = UT_WRITE_CLASS_INTERFACE; 216 req->bRequest = UR_SET_REPORT; 217 USETW2(req->wValue, type, id); 218 req->wIndex[0] = iface_no; 219 req->wIndex[1] = 0; --- 112 unchanged lines hidden (view full) --- 332 333static const struct usb2_config uhid_config[UHID_N_TRANSFER] = { 334 335 [UHID_INTR_DT_RD] = { 336 .type = UE_INTERRUPT, 337 .endpoint = UE_ADDR_ANY, 338 .direction = UE_DIR_IN, 339 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, | 193uhid_fill_set_report(struct usb2_device_request *req, uint8_t iface_no, 194 uint8_t type, uint8_t id, uint16_t size) 195{ 196 req->bmRequestType = UT_WRITE_CLASS_INTERFACE; 197 req->bRequest = UR_SET_REPORT; 198 USETW2(req->wValue, type, id); 199 req->wIndex[0] = iface_no; 200 req->wIndex[1] = 0; --- 112 unchanged lines hidden (view full) --- 313 314static const struct usb2_config uhid_config[UHID_N_TRANSFER] = { 315 316 [UHID_INTR_DT_RD] = { 317 .type = UE_INTERRUPT, 318 .endpoint = UE_ADDR_ANY, 319 .direction = UE_DIR_IN, 320 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, |
340 .mh.bufsize = 0, /* use wMaxPacketSize */ | 321 .mh.bufsize = UHID_BSIZE, |
341 .mh.callback = &uhid_intr_callback, 342 }, 343 | 322 .mh.callback = &uhid_intr_callback, 323 }, 324 |
344 [UHID_INTR_CS_RD] = { 345 .type = UE_CONTROL, 346 .endpoint = 0x00, /* Control pipe */ 347 .direction = UE_DIR_ANY, 348 .mh.bufsize = sizeof(struct usb2_device_request), 349 .mh.callback = &uhid_intr_clear_stall_callback, 350 .mh.timeout = 1000, /* 1 second */ 351 .mh.interval = 50, /* 50ms */ 352 }, 353 | |
354 [UHID_CTRL_DT_WR] = { 355 .type = UE_CONTROL, 356 .endpoint = 0x00, /* Control pipe */ 357 .direction = UE_DIR_ANY, 358 .mh.bufsize = sizeof(struct usb2_device_request) + UHID_BSIZE, 359 .mh.callback = &uhid_write_callback, 360 .mh.timeout = 1000, /* 1 second */ 361 }, --- 163 unchanged lines hidden (view full) --- 525 case USB_GET_REPORT_DESC: 526 ugd = addr; 527 if (sc->sc_repdesc_size > ugd->ugd_maxlen) { 528 size = ugd->ugd_maxlen; 529 } else { 530 size = sc->sc_repdesc_size; 531 } 532 ugd->ugd_actlen = size; | 325 [UHID_CTRL_DT_WR] = { 326 .type = UE_CONTROL, 327 .endpoint = 0x00, /* Control pipe */ 328 .direction = UE_DIR_ANY, 329 .mh.bufsize = sizeof(struct usb2_device_request) + UHID_BSIZE, 330 .mh.callback = &uhid_write_callback, 331 .mh.timeout = 1000, /* 1 second */ 332 }, --- 163 unchanged lines hidden (view full) --- 496 case USB_GET_REPORT_DESC: 497 ugd = addr; 498 if (sc->sc_repdesc_size > ugd->ugd_maxlen) { 499 size = ugd->ugd_maxlen; 500 } else { 501 size = sc->sc_repdesc_size; 502 } 503 ugd->ugd_actlen = size; |
504 if (ugd->ugd_data == NULL) 505 break; /* descriptor length only */ |
|
533 error = copyout(sc->sc_repdesc_ptr, ugd->ugd_data, size); 534 break; 535 536 case USB_SET_IMMED: 537 if (!(fflags & FREAD)) { 538 error = EPERM; 539 break; 540 } --- 278 unchanged lines hidden --- | 506 error = copyout(sc->sc_repdesc_ptr, ugd->ugd_data, size); 507 break; 508 509 case USB_SET_IMMED: 510 if (!(fflags & FREAD)) { 511 error = EPERM; 512 break; 513 } --- 278 unchanged lines hidden --- |