X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fusb%2Fhost%2Fdwc2.c;h=eee60a2b039a247b8c1282d1c2e92294a2377ae8;hb=82b9143bf8e5b359f094b90a19feb50a87268e8a;hp=e370d29ffc8ea9f91b6fa7df1021fcdf37bcce6b;hpb=805b67e1ea9a733f8fd526989b154648aca8afb6;p=u-boot diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index e370d29ffc..eee60a2b03 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -397,15 +398,18 @@ static void dwc_otg_core_init(struct dwc2_core_regs *regs) * @param hc Information needed to initialize the host channel */ static void dwc_otg_hc_init(struct dwc2_core_regs *regs, uint8_t hc_num, - uint8_t dev_addr, uint8_t ep_num, uint8_t ep_is_in, - uint8_t ep_type, uint16_t max_packet) + struct usb_device *dev, uint8_t dev_addr, uint8_t ep_num, + uint8_t ep_is_in, uint8_t ep_type, uint16_t max_packet) { struct dwc2_hc_regs *hc_regs = ®s->hc_regs[hc_num]; - const uint32_t hcchar = (dev_addr << DWC2_HCCHAR_DEVADDR_OFFSET) | - (ep_num << DWC2_HCCHAR_EPNUM_OFFSET) | - (ep_is_in << DWC2_HCCHAR_EPDIR_OFFSET) | - (ep_type << DWC2_HCCHAR_EPTYPE_OFFSET) | - (max_packet << DWC2_HCCHAR_MPS_OFFSET); + uint32_t hcchar = (dev_addr << DWC2_HCCHAR_DEVADDR_OFFSET) | + (ep_num << DWC2_HCCHAR_EPNUM_OFFSET) | + (ep_is_in << DWC2_HCCHAR_EPDIR_OFFSET) | + (ep_type << DWC2_HCCHAR_EPTYPE_OFFSET) | + (max_packet << DWC2_HCCHAR_MPS_OFFSET); + + if (dev->speed == USB_SPEED_LOW) + hcchar |= DWC2_HCCHAR_LSPDDEV; /* Clear old interrupt conditions for this host channel. */ writel(0x3fff, &hc_regs->hcint); @@ -462,7 +466,11 @@ static int dwc_otg_submit_rh_msg_in_status(struct usb_device *dev, void *buffer, if (hprt0 & DWC2_HPRT0_PRTPWR) port_status |= USB_PORT_STAT_POWER; - port_status |= USB_PORT_STAT_HIGH_SPEED; + if ((hprt0 & DWC2_HPRT0_PRTSPD_MASK) == DWC2_HPRT0_PRTSPD_LOW) + port_status |= USB_PORT_STAT_LOW_SPEED; + else if ((hprt0 & DWC2_HPRT0_PRTSPD_MASK) == + DWC2_HPRT0_PRTSPD_HIGH) + port_status |= USB_PORT_STAT_HIGH_SPEED; if (hprt0 & DWC2_HPRT0_PRTENCHNG) port_change |= USB_PORT_STAT_C_ENABLE; @@ -703,10 +711,9 @@ static int dwc_otg_submit_rh_msg(struct usb_device *dev, unsigned long pipe, return stat; } -int wait_for_chhltd(uint32_t *sub, int *toggle) +int wait_for_chhltd(uint32_t *sub, int *toggle, bool ignore_ack) { - const uint32_t hcint_comp_hlt_ack = DWC2_HCINT_XFERCOMP | - DWC2_HCINT_CHHLTD | DWC2_HCINT_ACK; + uint32_t hcint_comp_hlt_ack = DWC2_HCINT_XFERCOMP | DWC2_HCINT_CHHLTD; struct dwc2_hc_regs *hc_regs = ®s->hc_regs[DWC2_HC_CHANNEL]; int ret; uint32_t hcint, hctsiz; @@ -716,6 +723,12 @@ int wait_for_chhltd(uint32_t *sub, int *toggle) return ret; hcint = readl(&hc_regs->hcint); + if (hcint & (DWC2_HCINT_NAK | DWC2_HCINT_FRMOVRUN)) + return -EAGAIN; + if (ignore_ack) + hcint &= ~DWC2_HCINT_ACK; + else + hcint_comp_hlt_ack |= DWC2_HCINT_ACK; if (hcint != hcint_comp_hlt_ack) { debug("%s: Error (HCINT=%08x)\n", __func__, hcint); return -EINVAL; @@ -739,7 +752,7 @@ static int dwc2_eptype[] = { }; int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in, - void *buffer, int len) + void *buffer, int len, bool ignore_ack) { struct dwc2_hc_regs *hc_regs = ®s->hc_regs[DWC2_HC_CHANNEL]; int devnum = usb_pipedevice(pipe); @@ -747,7 +760,7 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in, int max = usb_maxpacket(dev, pipe); int eptype = dwc2_eptype[usb_pipetype(pipe)]; int done = 0; - int ret; + int ret = 0; uint32_t sub; uint32_t xfer_len; uint32_t num_packets; @@ -758,8 +771,8 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in, do { /* Initialize channel */ - dwc_otg_hc_init(regs, DWC2_HC_CHANNEL, devnum, ep, in, eptype, - max); + dwc_otg_hc_init(regs, DWC2_HC_CHANNEL, dev, devnum, ep, in, + eptype, max); xfer_len = len - done; if (xfer_len > CONFIG_DWC2_MAX_TRANSFER_SIZE) @@ -792,7 +805,8 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in, if (!in) memcpy(aligned_buffer, (char *)buffer + done, len); - writel((uint32_t)aligned_buffer, &hc_regs->hcdma); + writel(phys_to_bus((unsigned long)aligned_buffer), + &hc_regs->hcdma); /* Set host channel enable after all other setup is complete. */ clrsetbits_le32(&hc_regs->hcchar, DWC2_HCCHAR_MULTICNT_MASK | @@ -800,11 +814,9 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in, (1 << DWC2_HCCHAR_MULTICNT_OFFSET) | DWC2_HCCHAR_CHEN); - ret = wait_for_chhltd(&sub, pid); - if (ret) { - stop_transfer = 1; + ret = wait_for_chhltd(&sub, pid, ignore_ack); + if (ret) break; - } if (in) { xfer_len -= sub; @@ -823,7 +835,7 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in, dev->status = 0; dev->act_len = done; - return 0; + return ret; } /* U-Boot USB transmission interface */ @@ -839,7 +851,7 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer, } return chunk_msg(dev, pipe, &bulk_data_toggle[devnum][ep], - usb_pipein(pipe), buffer, len); + usb_pipein(pipe), buffer, len, true); } int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, @@ -857,14 +869,14 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, } pid = DWC2_HC_PID_SETUP; - ret = chunk_msg(dev, pipe, &pid, 0, setup, 8); + ret = chunk_msg(dev, pipe, &pid, 0, setup, 8, true); if (ret) return ret; if (buffer) { pid = DWC2_HC_PID_DATA1; ret = chunk_msg(dev, pipe, &pid, usb_pipein(pipe), buffer, - len); + len, false); if (ret) return ret; act_len = dev->act_len; @@ -879,7 +891,8 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, status_direction = 0; pid = DWC2_HC_PID_DATA1; - ret = chunk_msg(dev, pipe, &pid, status_direction, status_buffer, 0); + ret = chunk_msg(dev, pipe, &pid, status_direction, status_buffer, 0, + false); if (ret) return ret; @@ -891,9 +904,21 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int len, int interval) { - printf("dev = %p pipe = %#lx buf = %p size = %d int = %d\n", - dev, pipe, buffer, len, interval); - return -ENOSYS; + unsigned long timeout; + int ret; + + /* FIXME: what is interval? */ + + timeout = get_timer(0) + USB_TIMEOUT_MS(pipe); + for (;;) { + if (get_timer(0) > timeout) { + printf("Timeout poll on interrupt endpoint\n"); + return -ETIMEDOUT; + } + ret = submit_bulk_msg(dev, pipe, buffer, len); + if (ret != -EAGAIN) + return ret; + } } /* U-Boot USB control interface */ @@ -907,7 +932,8 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller) snpsid = readl(®s->gsnpsid); printf("Core Release: %x.%03x\n", snpsid >> 12 & 0xf, snpsid & 0xfff); - if ((snpsid & DWC2_SNPSID_DEVID_MASK) != DWC2_SNPSID_DEVID_VER_2xx) { + if ((snpsid & DWC2_SNPSID_DEVID_MASK) != DWC2_SNPSID_DEVID_VER_2xx && + (snpsid & DWC2_SNPSID_DEVID_MASK) != DWC2_SNPSID_DEVID_VER_3xx) { printf("SNPSID invalid (not DWC2 OTG device): %08x\n", snpsid); return -ENODEV; }