Deleted Added
full compact
uvisor.c (187970) uvisor.c (188413)
1/* $NetBSD: uvisor.c,v 1.9 2001/01/23 14:04:14 augustss Exp $ */
1/* $NetBSD: uvisor.c,v 1.9 2001/01/23 14:04:14 augustss Exp $ */
2/* $FreeBSD: head/sys/dev/usb2/serial/uvisor2.c 187970 2009-02-01 00:51:25Z thompsa $ */
2/* $FreeBSD: head/sys/dev/usb2/serial/uvisor2.c 188413 2009-02-09 22:05:25Z thompsa $ */
3
4/* Also already merged from NetBSD:
5 * $NetBSD: uvisor.c,v 1.12 2001/11/13 06:24:57 lukem Exp $
6 * $NetBSD: uvisor.c,v 1.13 2002/02/11 15:11:49 augustss Exp $
7 * $NetBSD: uvisor.c,v 1.14 2002/02/27 23:00:03 augustss Exp $
8 * $NetBSD: uvisor.c,v 1.15 2002/06/16 15:01:31 augustss Exp $
9 * $NetBSD: uvisor.c,v 1.16 2002/07/11 21:14:36 augustss Exp $
10 * $NetBSD: uvisor.c,v 1.17 2002/08/13 11:38:15 augustss Exp $

--- 135 unchanged lines hidden (view full) ---

146 uByte end_point_info;
147 uWord reserved;
148 } __packed connections[UVISOR_MAX_CONN];
149} __packed;
150
151enum {
152 UVISOR_BULK_DT_WR,
153 UVISOR_BULK_DT_RD,
3
4/* Also already merged from NetBSD:
5 * $NetBSD: uvisor.c,v 1.12 2001/11/13 06:24:57 lukem Exp $
6 * $NetBSD: uvisor.c,v 1.13 2002/02/11 15:11:49 augustss Exp $
7 * $NetBSD: uvisor.c,v 1.14 2002/02/27 23:00:03 augustss Exp $
8 * $NetBSD: uvisor.c,v 1.15 2002/06/16 15:01:31 augustss Exp $
9 * $NetBSD: uvisor.c,v 1.16 2002/07/11 21:14:36 augustss Exp $
10 * $NetBSD: uvisor.c,v 1.17 2002/08/13 11:38:15 augustss Exp $

--- 135 unchanged lines hidden (view full) ---

146 uByte end_point_info;
147 uWord reserved;
148 } __packed connections[UVISOR_MAX_CONN];
149} __packed;
150
151enum {
152 UVISOR_BULK_DT_WR,
153 UVISOR_BULK_DT_RD,
154 UVISOR_BULK_CS_WR,
155 UVISOR_BULK_CS_RD,
156 UVISOR_N_TRANSFER = 4,
154 UVISOR_N_TRANSFER,
157};
158
159struct uvisor_softc {
160 struct usb2_com_super_softc sc_super_ucom;
161 struct usb2_com_softc sc_ucom;
162
163 struct usb2_xfer *sc_xfer[UVISOR_N_TRANSFER];
164 struct usb2_device *sc_udev;
165
166 uint16_t sc_flag;
167#define UVISOR_FLAG_PALM4 0x0001
168#define UVISOR_FLAG_VISOR 0x0002
169#define UVISOR_FLAG_PALM35 0x0004
170#define UVISOR_FLAG_SEND_NOTIFY 0x0008
155};
156
157struct uvisor_softc {
158 struct usb2_com_super_softc sc_super_ucom;
159 struct usb2_com_softc sc_ucom;
160
161 struct usb2_xfer *sc_xfer[UVISOR_N_TRANSFER];
162 struct usb2_device *sc_udev;
163
164 uint16_t sc_flag;
165#define UVISOR_FLAG_PALM4 0x0001
166#define UVISOR_FLAG_VISOR 0x0002
167#define UVISOR_FLAG_PALM35 0x0004
168#define UVISOR_FLAG_SEND_NOTIFY 0x0008
171#define UVISOR_FLAG_WRITE_STALL 0x0010
172#define UVISOR_FLAG_READ_STALL 0x0020
173
174 uint8_t sc_iface_no;
175 uint8_t sc_iface_index;
176};
177
178/* prototypes */
179
180static device_probe_t uvisor_probe;
181static device_attach_t uvisor_attach;
182static device_detach_t uvisor_detach;
183
184static usb2_callback_t uvisor_write_callback;
169
170 uint8_t sc_iface_no;
171 uint8_t sc_iface_index;
172};
173
174/* prototypes */
175
176static device_probe_t uvisor_probe;
177static device_attach_t uvisor_attach;
178static device_detach_t uvisor_detach;
179
180static usb2_callback_t uvisor_write_callback;
185static usb2_callback_t uvisor_write_clear_stall_callback;
186static usb2_callback_t uvisor_read_callback;
181static usb2_callback_t uvisor_read_callback;
187static usb2_callback_t uvisor_read_clear_stall_callback;
188
189static usb2_error_t uvisor_init(struct uvisor_softc *, struct usb2_device *,
190 struct usb2_config *);
191static void uvisor_cfg_open(struct usb2_com_softc *);
192static void uvisor_cfg_close(struct usb2_com_softc *);
193static void uvisor_start_read(struct usb2_com_softc *);
194static void uvisor_stop_read(struct usb2_com_softc *);
195static void uvisor_start_write(struct usb2_com_softc *);

--- 13 unchanged lines hidden (view full) ---

209 [UVISOR_BULK_DT_RD] = {
210 .type = UE_BULK,
211 .endpoint = UE_ADDR_ANY,
212 .direction = UE_DIR_IN,
213 .mh.bufsize = UVISOR_BUFSIZE, /* bytes */
214 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
215 .mh.callback = &uvisor_read_callback,
216 },
182
183static usb2_error_t uvisor_init(struct uvisor_softc *, struct usb2_device *,
184 struct usb2_config *);
185static void uvisor_cfg_open(struct usb2_com_softc *);
186static void uvisor_cfg_close(struct usb2_com_softc *);
187static void uvisor_start_read(struct usb2_com_softc *);
188static void uvisor_stop_read(struct usb2_com_softc *);
189static void uvisor_start_write(struct usb2_com_softc *);

--- 13 unchanged lines hidden (view full) ---

203 [UVISOR_BULK_DT_RD] = {
204 .type = UE_BULK,
205 .endpoint = UE_ADDR_ANY,
206 .direction = UE_DIR_IN,
207 .mh.bufsize = UVISOR_BUFSIZE, /* bytes */
208 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
209 .mh.callback = &uvisor_read_callback,
210 },
217
218 [UVISOR_BULK_CS_WR] = {
219 .type = UE_CONTROL,
220 .endpoint = 0x00, /* Control pipe */
221 .direction = UE_DIR_ANY,
222 .mh.bufsize = sizeof(struct usb2_device_request),
223 .mh.callback = &uvisor_write_clear_stall_callback,
224 .mh.timeout = 1000, /* 1 second */
225 .mh.interval = 50, /* 50ms */
226 },
227
228 [UVISOR_BULK_CS_RD] = {
229 .type = UE_CONTROL,
230 .endpoint = 0x00, /* Control pipe */
231 .direction = UE_DIR_ANY,
232 .mh.bufsize = sizeof(struct usb2_device_request),
233 .mh.callback = &uvisor_read_clear_stall_callback,
234 .mh.timeout = 1000, /* 1 second */
235 .mh.interval = 50, /* 50ms */
236 },
237};
238
239static const struct usb2_com_callback uvisor_callback = {
240 .usb2_com_cfg_open = &uvisor_cfg_open,
241 .usb2_com_cfg_close = &uvisor_cfg_close,
242 .usb2_com_start_read = &uvisor_start_read,
243 .usb2_com_stop_read = &uvisor_stop_read,
244 .usb2_com_start_write = &uvisor_start_write,

--- 96 unchanged lines hidden (view full) ---

341 error = usb2_transfer_setup(uaa->device, &sc->sc_iface_index,
342 sc->sc_xfer, uvisor_config_copy, UVISOR_N_TRANSFER,
343 sc, &Giant);
344 if (error) {
345 DPRINTF("could not allocate all pipes\n");
346 goto detach;
347 }
348 /* clear stall at first run */
211};
212
213static const struct usb2_com_callback uvisor_callback = {
214 .usb2_com_cfg_open = &uvisor_cfg_open,
215 .usb2_com_cfg_close = &uvisor_cfg_close,
216 .usb2_com_start_read = &uvisor_start_read,
217 .usb2_com_stop_read = &uvisor_stop_read,
218 .usb2_com_start_write = &uvisor_start_write,

--- 96 unchanged lines hidden (view full) ---

315 error = usb2_transfer_setup(uaa->device, &sc->sc_iface_index,
316 sc->sc_xfer, uvisor_config_copy, UVISOR_N_TRANSFER,
317 sc, &Giant);
318 if (error) {
319 DPRINTF("could not allocate all pipes\n");
320 goto detach;
321 }
322 /* clear stall at first run */
349 sc->sc_flag |= (UVISOR_FLAG_WRITE_STALL |
350 UVISOR_FLAG_READ_STALL);
323 usb2_transfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_WR]);
324 usb2_transfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_RD]);
351
352 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
353 &uvisor_callback, &Giant);
354 if (error) {
355 DPRINTF("usb2_com_attach failed\n");
356 goto detach;
357 }
358 return (0);

--- 178 unchanged lines hidden (view full) ---

537 usb2_error_t err;
538
539 req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
540 req.bRequest = UVISOR_CLOSE_NOTIFICATION;
541 USETW(req.wValue, 0);
542 USETW(req.wIndex, 0);
543 USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
544
325
326 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
327 &uvisor_callback, &Giant);
328 if (error) {
329 DPRINTF("usb2_com_attach failed\n");
330 goto detach;
331 }
332 return (0);

--- 178 unchanged lines hidden (view full) ---

511 usb2_error_t err;
512
513 req.bmRequestType = UT_READ_VENDOR_ENDPOINT; /* XXX read? */
514 req.bRequest = UVISOR_CLOSE_NOTIFICATION;
515 USETW(req.wValue, 0);
516 USETW(req.wIndex, 0);
517 USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE);
518
545 err = usb2_do_request_flags
546 (sc->sc_udev, &Giant, &req, &buffer, 0, NULL, 1000);
547
519 err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
520 &req, buffer, 0, 1000);
548 if (err) {
549 DPRINTFN(0, "close notification failed, error=%s\n",
550 usb2_errstr(err));
551 }
552}
553
554static void
555uvisor_start_read(struct usb2_com_softc *ucom)
556{
557 struct uvisor_softc *sc = ucom->sc_parent;
558
559 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_DT_RD]);
560}
561
562static void
563uvisor_stop_read(struct usb2_com_softc *ucom)
564{
565 struct uvisor_softc *sc = ucom->sc_parent;
566
521 if (err) {
522 DPRINTFN(0, "close notification failed, error=%s\n",
523 usb2_errstr(err));
524 }
525}
526
527static void
528uvisor_start_read(struct usb2_com_softc *ucom)
529{
530 struct uvisor_softc *sc = ucom->sc_parent;
531
532 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_DT_RD]);
533}
534
535static void
536uvisor_stop_read(struct usb2_com_softc *ucom)
537{
538 struct uvisor_softc *sc = ucom->sc_parent;
539
567 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_CS_RD]);
568 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_DT_RD]);
569}
570
571static void
572uvisor_start_write(struct usb2_com_softc *ucom)
573{
574 struct uvisor_softc *sc = ucom->sc_parent;
575
576 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_DT_WR]);
577}
578
579static void
580uvisor_stop_write(struct usb2_com_softc *ucom)
581{
582 struct uvisor_softc *sc = ucom->sc_parent;
583
540 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_DT_RD]);
541}
542
543static void
544uvisor_start_write(struct usb2_com_softc *ucom)
545{
546 struct uvisor_softc *sc = ucom->sc_parent;
547
548 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_DT_WR]);
549}
550
551static void
552uvisor_stop_write(struct usb2_com_softc *ucom)
553{
554 struct uvisor_softc *sc = ucom->sc_parent;
555
584 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_CS_WR]);
585 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_DT_WR]);
586}
587
588static void
589uvisor_write_callback(struct usb2_xfer *xfer)
590{
591 struct uvisor_softc *sc = xfer->priv_sc;
592 uint32_t actlen;
593
594 switch (USB_GET_STATE(xfer)) {
595 case USB_ST_SETUP:
596 case USB_ST_TRANSFERRED:
556 usb2_transfer_stop(sc->sc_xfer[UVISOR_BULK_DT_WR]);
557}
558
559static void
560uvisor_write_callback(struct usb2_xfer *xfer)
561{
562 struct uvisor_softc *sc = xfer->priv_sc;
563 uint32_t actlen;
564
565 switch (USB_GET_STATE(xfer)) {
566 case USB_ST_SETUP:
567 case USB_ST_TRANSFERRED:
597 if (sc->sc_flag & UVISOR_FLAG_WRITE_STALL) {
598 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_CS_WR]);
599 return;
600 }
568tr_setup:
601 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
602 UVISOR_BUFSIZE, &actlen)) {
603
604 xfer->frlengths[0] = actlen;
605 usb2_start_hardware(xfer);
606 }
607 return;
608
609 default: /* Error */
610 if (xfer->error != USB_ERR_CANCELLED) {
569 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
570 UVISOR_BUFSIZE, &actlen)) {
571
572 xfer->frlengths[0] = actlen;
573 usb2_start_hardware(xfer);
574 }
575 return;
576
577 default: /* Error */
578 if (xfer->error != USB_ERR_CANCELLED) {
611 sc->sc_flag |= UVISOR_FLAG_WRITE_STALL;
612 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_CS_WR]);
579 /* try to clear stall first */
580 xfer->flags.stall_pipe = 1;
581 goto tr_setup;
613 }
614 return;
582 }
583 return;
615
616 }
617}
618
619static void
584 }
585}
586
587static void
620uvisor_write_clear_stall_callback(struct usb2_xfer *xfer)
621{
622 struct uvisor_softc *sc = xfer->priv_sc;
623 struct usb2_xfer *xfer_other = sc->sc_xfer[UVISOR_BULK_DT_WR];
624
625 if (usb2_clear_stall_callback(xfer, xfer_other)) {
626 DPRINTF("stall cleared\n");
627 sc->sc_flag &= ~UVISOR_FLAG_WRITE_STALL;
628 usb2_transfer_start(xfer_other);
629 }
630}
631
632static void
633uvisor_read_callback(struct usb2_xfer *xfer)
634{
635 struct uvisor_softc *sc = xfer->priv_sc;
636
637 switch (USB_GET_STATE(xfer)) {
638 case USB_ST_TRANSFERRED:
639 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
640
641 case USB_ST_SETUP:
588uvisor_read_callback(struct usb2_xfer *xfer)
589{
590 struct uvisor_softc *sc = xfer->priv_sc;
591
592 switch (USB_GET_STATE(xfer)) {
593 case USB_ST_TRANSFERRED:
594 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
595
596 case USB_ST_SETUP:
642 if (sc->sc_flag & UVISOR_FLAG_READ_STALL) {
643 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_CS_RD]);
644 } else {
645 xfer->frlengths[0] = xfer->max_data_length;
646 usb2_start_hardware(xfer);
647 }
597tr_setup:
598 xfer->frlengths[0] = xfer->max_data_length;
599 usb2_start_hardware(xfer);
648 return;
649
650 default: /* Error */
651 if (xfer->error != USB_ERR_CANCELLED) {
600 return;
601
602 default: /* Error */
603 if (xfer->error != USB_ERR_CANCELLED) {
652 sc->sc_flag |= UVISOR_FLAG_READ_STALL;
653 usb2_transfer_start(sc->sc_xfer[UVISOR_BULK_CS_RD]);
604 /* try to clear stall first */
605 xfer->flags.stall_pipe = 1;
606 goto tr_setup;
654 }
655 return;
607 }
608 return;
656
657 }
658}
609 }
610}
659
660static void
661uvisor_read_clear_stall_callback(struct usb2_xfer *xfer)
662{
663 struct uvisor_softc *sc = xfer->priv_sc;
664 struct usb2_xfer *xfer_other = sc->sc_xfer[UVISOR_BULK_DT_RD];
665
666 if (usb2_clear_stall_callback(xfer, xfer_other)) {
667 DPRINTF("stall cleared\n");
668 sc->sc_flag &= ~UVISOR_FLAG_READ_STALL;
669 usb2_transfer_start(xfer_other);
670 }
671}