diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2007-02-07 16:26:50 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2007-02-07 16:26:50 +0000 |
commit | 21f57bcbf57691e121daafa905a0f81a62ca5d74 (patch) | |
tree | 3a9a1decb15c42b0274c27572e69a3d17bdd40a2 /sys | |
parent | 2142a7bc71470da8e9699ba751db6085e0e84598 (diff) |
Several improvements to the usb client code. Still not working.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/arm/xscale/pxa27x_udc.c | 145 | ||||
-rw-r--r-- | sys/arch/arm/xscale/pxa27x_udcreg.h | 24 | ||||
-rw-r--r-- | sys/dev/usb/if_cdcef.c | 19 | ||||
-rw-r--r-- | sys/dev/usb/usbf.c | 4 | ||||
-rw-r--r-- | sys/dev/usb/usbf_subr.c | 4 |
5 files changed, 156 insertions, 40 deletions
diff --git a/sys/arch/arm/xscale/pxa27x_udc.c b/sys/arch/arm/xscale/pxa27x_udc.c index b8665aada02..f5ee876cd1b 100644 --- a/sys/arch/arm/xscale/pxa27x_udc.c +++ b/sys/arch/arm/xscale/pxa27x_udc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pxa27x_udc.c,v 1.7 2006/11/28 15:42:30 uwe Exp $ */ +/* $OpenBSD: pxa27x_udc.c,v 1.8 2007/02/07 16:26:49 drahn Exp $ */ /* * Copyright (c) 2005 David Gwynne <dlg@openbsd.org> @@ -51,7 +51,7 @@ struct pxaudc_xfer { struct pxaudc_pipe { struct usbf_pipe pipe; - LIST_ENTRY(pxaudc_pipe) list; +// LIST_ENTRY(pxaudc_pipe) list; }; struct pxaudc_softc { @@ -73,6 +73,7 @@ struct pxaudc_softc { u_int32_t sc_isr1; /* XXX deferred interrupts */ u_int32_t sc_otgisr; /* XXX deferred interrupts */ struct pxaudc_pipe *sc_pipe[PXAUDC_NEP]; + int sc_npipe; }; int pxaudc_match(struct device *, void *, void *); @@ -167,7 +168,6 @@ struct usbf_pipe_methods pxaudc_bulk_methods = { #define CSR_CLR_4(sc, reg, val) \ CSR_WRITE_4((sc), (reg), CSR_READ_4((sc), (reg)) & ~(val)) -#define PXAUDC_DEBUG #ifndef PXAUDC_DEBUG #define DPRINTF(l, x) do {} while (0) #else @@ -242,6 +242,7 @@ pxaudc_attach(struct device *parent, struct device *self, void *aux) sc->sc_bus.ep0_maxp = PXAUDC_EP0MAXP; sc->sc_bus.usbrev = USBREV_1_1; sc->sc_bus.dmatag = pxa->pxa_dmat; + sc->sc_npipe = 0; /* ep0 is always there. */ /* Attach logical device and function. */ (void)config_found(self, &sc->sc_bus, NULL); @@ -363,33 +364,82 @@ pxaudc_dump_regs(struct pxaudc_softc *sc) void pxaudc_enable(struct pxaudc_softc *sc) { + int i; + DPRINTF(0,("pxaudc_enable\n")); /* Start the clocks. */ pxa2x0_clkman_config(CKEN_USBDC, 1); +#if 0 /* Configure Port 2 for USB device. */ CSR_WRITE_4(sc, USBDC_UP2OCR, USBDC_UP2OCR_DMPUE | USBDC_UP2OCR_DPPUE | USBDC_UP2OCR_HXOE); +#else + /* Configure Port 2 for USB device. */ + CSR_WRITE_4(sc, USBDC_UP2OCR, USBDC_UP2OCR_DPPUE | USBDC_UP2OCR_HXOE); +#endif + + sc->sc_icr0 = 0; + sc->sc_icr1 = 0; + + for (i = 0; i < PXAUDC_NEP; i++) + CSR_WRITE_4(sc, USBDC_UDCECR(i), 0); /* disable endpoints */ + + for (i = 1; i < sc->sc_npipe; i++) { + if (sc->sc_pipe[i] != NULL) { + struct usbf_endpoint *ep = + sc->sc_pipe[i]->pipe.endpoint; + u_int32_t cr; + int dir = usbf_endpoint_dir(ep); + usb_endpoint_descriptor_t *ed = ep->edesc; + + if (i < 16) + sc->sc_icr0 |= USBDC_UDCICR0_IE(i); + else + sc->sc_icr1 |= USBDC_UDCICR1_IE(i-16); + + printf("configuring pipe/ep %x\n", i); + cr = USBDC_UDCECR_EE; + cr |= USBDC_UDCECR_ENs( + UE_GET_ADDR(ed->bEndpointAddress)); + cr |= USBDC_UDCECR_MPSs(UGETW(ed->wMaxPacketSize)); + cr |= USBDC_UDCECR_ETs(ed->bmAttributes & UE_XFERTYPE); + if (dir == UE_DIR_OUT) + cr |= USBDC_UDCECR_ED; + + /* XXX - until pipe has cn/in/ain */ + cr |= USBDC_UDCECR_AISNs(0) | USBDC_UDCECR_INs(0) | + USBDC_UDCECR_CNs(1); + + CSR_WRITE_4(sc, USBDC_UDCECR(i), cr); + printf("endpoint %c programed to %x\n", '@'+i, cr); + + /* clear old status */ + CSR_WRITE_4(sc, USBDC_UDCCSR(1), + USBDC_UDCCSR_PC | USBDC_UDCCSR_TRN | + USBDC_UDCCSR_SST | USBDC_UDCCSR_FEF); + printf("csr%d %x\n", i, CSR_READ_4(sc, USBDC_UDCCSR(1))); + } + } + /* Enable interrupts for configured endpoints. */ - CSR_SET_4(sc, USBDC_UDCICR0, USBDC_UDCICR0_IE(0) | + CSR_WRITE_4(sc, USBDC_UDCICR0, USBDC_UDCICR0_IE(0) | sc->sc_icr0); - CSR_SET_4(sc, USBDC_UDCICR1, USBDC_UDCICR1_IERS | + printf("icr0 %x\n", CSR_READ_4(sc, USBDC_UDCICR0)); + CSR_WRITE_4(sc, USBDC_UDCICR1, USBDC_UDCICR1_IERS | USBDC_UDCICR1_IECC | sc->sc_icr1); + printf("icr1 %x\n", CSR_READ_4(sc, USBDC_UDCICR1)); - /* XXX */ - CSR_WRITE_4(sc, USBDC_UDCICR0, 0x00000C3F); - CSR_WRITE_4(sc, USBDC_UDCECR(1), 0x0200D103); - CSR_WRITE_4(sc, USBDC_UDCECR(2), 0x02014103); - CSR_WRITE_4(sc, USBDC_UDCECR(3), 0x0201B403); - CSR_WRITE_4(sc, USBDC_UDCECR(4), 0x02022403); - CSR_WRITE_4(sc, USBDC_UDCECR(5), 0x0202F021); + CSR_SET_4(sc, USBDC_UDCCSR0, USBDC_UDCCSR0_ACM); /* Enable the controller. */ CSR_CLR_4(sc, USBDC_UDCCR, USBDC_UDCCR_EMCE); CSR_SET_4(sc, USBDC_UDCCR, USBDC_UDCCR_UDE); + printf("udccr %b\n", CSR_READ_4(sc, USBDC_UDCCR), USBDC_UDCCR_BITS); + /* Enable USB client on port 2. */ pxa2x0_gpio_clear_bit(37); /* USB_P2_8 */ } @@ -556,7 +606,7 @@ pxaudc_intr(void *v) isr1 = CSR_READ_4(sc, USBDC_UDCISR1); otgisr = CSR_READ_4(sc, USBDC_UDCOTGISR); - DPRINTF(1,("pxaudc_intr: isr0=%b, isr1=%b, otgisr=%b\n", + DPRINTF(0,("pxaudc_intr: isr0=%b, isr1=%b, otgisr=%b\n", isr0, USBDC_UDCISR0_BITS, isr1, USBDC_UDCISR1_BITS, otgisr, USBDC_UDCOTGISR_BITS)); @@ -576,6 +626,7 @@ pxaudc_intr(void *v) /* Claim this interrupt. */ return 1; } +u_int32_t csr1, csr2; void pxaudc_intr1(struct pxaudc_softc *sc) @@ -594,6 +645,32 @@ pxaudc_intr1(struct pxaudc_softc *sc) sc->sc_bus.intr_context++; + if (isr0 & USBDC_UDCISR0_IR(1)) { + printf("interrupt pending ep[1]\n"); + } + { + int i; + u_int32_t csr; + csr = CSR_READ_4(sc, USBDC_UDCCSR(1)); + if (csr1 != csr) { + printf("CSR1 %x\n", csr); + csr1 = csr; + } + csr = CSR_READ_4(sc, USBDC_UDCCSR(2)); + if (csr2 != csr) { + printf("CSR1 %x\n", csr); + csr2 = csr; + } + for (i = 1; i < 23; i++) { + int x; + x = CSR_READ_4(sc, USBDC_UDCBCR(i)); + if( x != 0) + printf("data present in ep %d %d\n", i, x); + } + } + if (isr0 & USBDC_UDCISR0_IR(2)) { + printf("interrupt pending ep[2]\n"); + } /* Handle USB RESET condition. */ if (isr1 & USBDC_UDCISR1_IRRS) { sc->sc_ep0state = EP0_SETUP; @@ -606,6 +683,25 @@ pxaudc_intr1(struct pxaudc_softc *sc) if (isr0 & USBDC_UDCISR0_IR(0)) pxaudc_ep0_intr(sc); + if (isr1 & USBDC_UDCISR1_IRCC) { + u_int32_t csr0; + csr0 = CSR_READ_4(sc, USBDC_UDCCSR0); + + printf("config change isr %x %x acn %x ain %x aaisn %x\n", + isr0, isr1, + (csr0 >> 11) & 7, + (csr0 >> 8) & 7, + (csr0 >> 5) & 7); + CSR_SET_4(sc, USBDC_UDCCSR0, USBDC_UDCCR_SMAC); + csr0 = CSR_READ_4(sc, USBDC_UDCCSR0); + + printf("after config change isr %x %x acn %x ain %x aaisn %x\n", + isr0, isr1, + (csr0 >> 11) & 7, + (csr0 >> 8) & 7, + (csr0 >> 5) & 7); + } + ret: sc->sc_bus.intr_context--; } @@ -619,7 +715,7 @@ pxaudc_ep0_intr(struct pxaudc_softc *sc) u_int32_t csr0; csr0 = CSR_READ_4(sc, USBDC_UDCCSR0); - DPRINTF(1,("pxaudc_ep0_intr: csr0=%b\n", csr0, USBDC_UDCCSR0_BITS)); + DPRINTF(0,("pxaudc_ep0_intr: csr0=%b\n", csr0, USBDC_UDCCSR0_BITS)); ppipe = sc->sc_pipe[0]; if (ppipe != NULL) { @@ -659,7 +755,7 @@ pxaudc_open(struct usbf_pipe *pipe) if (usbf_endpoint_index(pipe->endpoint) >= PXAUDC_NEP) return USBF_BAD_ADDRESS; - DPRINTF(1,("pxaudc_open\n")); + DPRINTF(0,("pxaudc_open\n")); s = splhardusb(); switch (usbf_endpoint_type(pipe->endpoint)) { @@ -679,7 +775,9 @@ pxaudc_open(struct usbf_pipe *pipe) return USBF_BAD_ADDRESS; } - sc->sc_pipe[usbf_endpoint_index(pipe->endpoint)] = ppipe; + sc->sc_pipe[sc->sc_npipe] = ppipe; + sc->sc_npipe++; + printf("adding pipe %x\n", usbf_endpoint_index(pipe->endpoint)); splx(s); return USBF_NORMAL_COMPLETION; @@ -765,8 +863,10 @@ pxaudc_ctrl_start(usbf_xfer_handle xfer) else { /* XXX boring message, this case is normally reached if * XXX the xfer for a device request is being queued. */ - DPRINTF(0,("%s: ep0 ctrl-out, xfer=%p, len=%u, " - "actlen=%u\n", DEVNAME(sc), xfer, xfer->length, + DPRINTF(0,("%s: ep[%x] ctrl-out, xfer=%p, len=%u, " + "actlen=%u\n", DEVNAME(sc), + usbf_endpoint_address(xfer->pipe->endpoint), + xfer, xfer->length, xfer->actlen)); } splx(s); @@ -777,10 +877,10 @@ pxaudc_ctrl_start(usbf_xfer_handle xfer) void pxaudc_ctrl_abort(usbf_xfer_handle xfer) { - struct usbf_pipe *pipe = xfer->pipe; - struct pxaudc_softc *sc = (struct pxaudc_softc *)pipe->device->bus; int s; #ifdef PXAUDC_DEBUG + struct usbf_pipe *pipe = xfer->pipe; + struct pxaudc_softc *sc = (struct pxaudc_softc *)pipe->device->bus; int index = usbf_endpoint_index(pipe->endpoint); int dir = usbf_endpoint_dir(pipe->endpoint); int type = usbf_endpoint_type(pipe->endpoint); @@ -861,7 +961,7 @@ pxaudc_bulk_start(usbf_xfer_handle xfer) int iswrite = usbf_endpoint_dir(pipe->endpoint) == UE_DIR_IN; int s; - DPRINTF(1,("%s: ep%d bulk-%s start, xfer=%p, len=%u\n", DEVNAME(sc), + DPRINTF(0,("%s: ep%d bulk-%s start, xfer=%p, len=%u\n", DEVNAME(sc), usbf_endpoint_index(pipe->endpoint), iswrite ? "in" : "out", xfer, xfer->length)); @@ -869,6 +969,9 @@ pxaudc_bulk_start(usbf_xfer_handle xfer) xfer->status = USBF_IN_PROGRESS; if (iswrite) pxaudc_write(sc, xfer); + else { + /* enable interrupt */ + } splx(s); return USBF_IN_PROGRESS; } diff --git a/sys/arch/arm/xscale/pxa27x_udcreg.h b/sys/arch/arm/xscale/pxa27x_udcreg.h index b9e2e4ad76b..8905e62187c 100644 --- a/sys/arch/arm/xscale/pxa27x_udcreg.h +++ b/sys/arch/arm/xscale/pxa27x_udcreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pxa27x_udcreg.h,v 1.2 2006/11/25 18:10:29 uwe Exp $ */ +/* $OpenBSD: pxa27x_udcreg.h,v 1.3 2007/02/07 16:26:49 drahn Exp $ */ /* * Copyright (c) 2005 David Gwynne <dlg@openbsd.org> @@ -43,18 +43,18 @@ #define USBDC_UDCCR_AALTHNP (1<<30) /* A-Dev Alt Host Neg Proto Port Sup */ #define USBDC_UDCCR_OEN (1<<31) /* On-The-Go Enable */ #define USBDC_UDCICR0 0x0004 /* UDC Interrupt Control Register 0 */ -#define USBDC_UDCICR0_IE(n) (3<<(n)) /* Interrupt Enables */ +#define USBDC_UDCICR0_IE(n) (3<<((n)*2)) /* Interrupt Enables */ #define USBDC_UDCICR1 0x0008 /* UDC Interrupt Control Register 1 */ -#define USBDC_UDCICR1_IE(n) (3<<(n)) /* Interrupt Enables */ +#define USBDC_UDCICR1_IE(n) (3<<((n)*2)) /* Interrupt Enables */ #define USBDC_UDCICR1_IERS (1<<27) /* Interrupt Enable Reset */ #define USBDC_UDCICR1_IESU (1<<28) /* Interrupt Enable Suspend */ #define USBDC_UDCICR1_IERU (1<<29) /* Interrupt Enable Resume */ #define USBDC_UDCICR1_IESOF (1<<30) /* Interrupt Enable Start of Frame */ #define USBDC_UDCICR1_IECC (1<<31) /* Interrupt Enable Config Change */ #define USBDC_UDCISR0 0x000c /* UDC Interrupt Status Register 0 */ -#define USBDC_UDCISR0_IR(n) (3<<(n)) /* Interrupt Requests */ +#define USBDC_UDCISR0_IR(n) (3<<((n)*2)) /* Interrupt Requests */ #define USBDC_UDCISR1 0x0010 /* UDC Interrupt Status Register 1 */ -#define USBDC_UDCISR1_IR(n) (3<<(n)) /* Interrupt Requests */ +#define USBDC_UDCISR1_IR(n) (3<<((n)*2)) /* Interrupt Requests */ #define USBDC_UDCISR1_IRRS (1<<27) /* Interrupt Enable Reset */ #define USBDC_UDCISR1_IRSU (1<<28) /* Interrupt Enable Suspend */ #define USBDC_UDCISR1_IRRU (1<<29) /* Interrupt Enable Resume */ @@ -141,14 +141,24 @@ #define USBDC_UDCECR(n) (0x0400+4*(n)) /* UDC Configuration Registers */ #define USBDC_UDCECR_EE (1<<0) /* Endpoint Enable */ #define USBDC_UDCECR_DE (1<<1) /* Double-Buffering Enable */ -#define USBDC_UDCECR_MPE (1023<<2) /* Maximum Packet Size */ -#define USBDC_UDCECR_ED (1<<12) /* USB Endpoint Direction */ +#define USBDC_UDCECR_MPS (1023<<2) /* Maximum Packet Size */ +#define USBDC_UDCECR_ED (1<<12) /* USB Endpoint Direction 0 OUT, 1 IN */ #define USBDC_UDCECR_ET (3<<13) /* USB Enpoint Type */ #define USBDC_UDCECR_EN (15<<15) /* Endpoint Number */ #define USBDC_UDCECR_AISN (7<<19) /* Alternate Interface Number */ #define USBDC_UDCECR_IN (7<<22) /* Interface Number */ #define USBDC_UDCECR_CN (3<<25) /* Configuration Number */ +#define USBDC_UDCECR_MPSs(n) ((n)<<2) /* Maximum Packet Size */ +#define USBDC_UDCECR_ETs(n) ((n)<<13) /* USB Enpoint Type */ +#define USBDC_UDCECR_ET_INT 3 +#define USBDC_UDCECR_ET_BULK 2 +#define USBDC_UDCECR_ET_ISO 1 +#define USBDC_UDCECR_ENs(n) ((n)<<15) /* Endpoint Number */ +#define USBDC_UDCECR_AISNs(n) ((n)<<19) /* Alternate Interface Number */ +#define USBDC_UDCECR_INs(n) ((n)<<22) /* Interface Number */ +#define USBDC_UDCECR_CNs(n) ((n)<<25) /* Configuration Number */ + #define USBDC_UDCCR_BITS \ "\20\001UDE\002UDA\003UDR\004EMCE\005SMAC\021DWRE" \ "\035BHNP\036AHNP\037OEN" diff --git a/sys/dev/usb/if_cdcef.c b/sys/dev/usb/if_cdcef.c index aaa9dc696a3..5491bc057a6 100644 --- a/sys/dev/usb/if_cdcef.c +++ b/sys/dev/usb/if_cdcef.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_cdcef.c,v 1.1 2006/11/25 18:10:29 uwe Exp $ */ +/* $OpenBSD: if_cdcef.c,v 1.2 2007/02/07 16:26:49 drahn Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> @@ -136,10 +136,10 @@ USB_ATTACH(cdcef) USB_ATTACH_ERROR_RETURN; } /* XXX don't use hard-coded values 128 and 16. */ - err = usbf_add_endpoint(sc->sc_iface, UE_DIR_IN, UE_BULK, - 128, 16, &sc->sc_ep_in) || - usbf_add_endpoint(sc->sc_iface, UE_DIR_OUT, UE_BULK, - 128, 16, &sc->sc_ep_out); + err = usbf_add_endpoint(sc->sc_iface, UE_DIR_IN | 1, UE_BULK, + 64, 16, &sc->sc_ep_in) || + usbf_add_endpoint(sc->sc_iface, UE_DIR_OUT | 1, UE_BULK, + 64, 16, &sc->sc_ep_out); if (err) { printf("%s: usbf_add_endpoint failed\n", DEVNAME(sc)); USB_ATTACH_ERROR_RETURN; @@ -189,6 +189,10 @@ USB_ATTACH(cdcef) USB_ATTACH_ERROR_RETURN; } + printf("input pipe %x output pipe %x\n", + usbf_endpoint_address(sc->sc_ep_in), + usbf_endpoint_address(sc->sc_ep_out)); + /* Get ready to receive packets. */ usbf_setup_xfer(sc->sc_xfer_out, sc->sc_pipe_out, (void *)sc, sc->sc_buffer_out, CDCEF_BUFSZ, 0, 0, cdcef_rxeof); @@ -205,6 +209,7 @@ usbf_status cdcef_do_request(usbf_function_handle fun, usb_device_request_t *req, void **data) { + printf("cdcef_do_request\n"); return USBF_STALLED; } @@ -224,7 +229,7 @@ cdcef_txeof(usbf_xfer_handle xfer, usbf_private_handle priv, /* Setup another xfer. */ usbf_setup_xfer(xfer, sc->sc_pipe_in, (void *)sc, - sc->sc_buffer_in, CDCEF_BUFSZ, 0, 0, cdcef_rxeof); + sc->sc_buffer_in, CDCEF_BUFSZ, 0, 0, cdcef_txeof); err = usbf_transfer(xfer); if (err && err != USBF_IN_PROGRESS) { printf("%s: usbf_transfer failed\n", DEVNAME(sc)); @@ -238,7 +243,7 @@ cdcef_rxeof(usbf_xfer_handle xfer, usbf_private_handle priv, { struct cdcef_softc *sc = priv; - printf("cdcef_txeof: xfer=%p, priv=%p, %s\n", xfer, priv, + printf("cdcef_rxeof: xfer=%p, priv=%p, %s\n", xfer, priv, usbf_errstr(err)); /* Setup another xfer. */ diff --git a/sys/dev/usb/usbf.c b/sys/dev/usb/usbf.c index a1715323fbc..a82cb254248 100644 --- a/sys/dev/usb/usbf.c +++ b/sys/dev/usb/usbf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usbf.c,v 1.1 2006/11/25 18:10:29 uwe Exp $ */ +/* $OpenBSD: usbf.c,v 1.2 2007/02/07 16:26:49 drahn Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> @@ -64,7 +64,6 @@ #include <dev/usb/usbf.h> #include <dev/usb/usbfvar.h> -#define USBF_DEBUG #ifndef USBF_DEBUG #define DPRINTF(l, x) do {} while (0) #else @@ -455,6 +454,7 @@ usbf_do_request(usbf_xfer_handle xfer, usbf_private_handle priv, case C(UR_SET_CONFIG, UT_WRITE_DEVICE): /* Change device state from Address to Configured. */ + printf("set config activated\n"); err = usbf_set_config(dev, UGETW(req->wValue) & 0xff); break; diff --git a/sys/dev/usb/usbf_subr.c b/sys/dev/usb/usbf_subr.c index afb9512a66b..ffedaf5ed29 100644 --- a/sys/dev/usb/usbf_subr.c +++ b/sys/dev/usb/usbf_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usbf_subr.c,v 1.1 2006/11/25 18:10:29 uwe Exp $ */ +/* $OpenBSD: usbf_subr.c,v 1.2 2007/02/07 16:26:49 drahn Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> @@ -33,7 +33,6 @@ #include <dev/usb/usbf.h> #include <dev/usb/usbfvar.h> -#define USBF_DEBUG #ifndef USBF_DEBUG #define DPRINTF(l, x) do {} while (0) #else @@ -572,7 +571,6 @@ usbf_end_config(usbf_config_handle uc) ui->idesc = (usb_interface_descriptor_t *)d; SIMPLEQ_FOREACH(ue, &ui->endpoint_head, next) { - ue->edesc->bEndpointAddress |= 1; /* XXX humbug */ err = usbf_add_config_desc(uc, (usb_descriptor_t *)ue->edesc, &d); if (err) |