]> git.sur5r.net Git - u-boot/blobdiff - drivers/usb/host/dwc2.c
usb: ehci-marvell: Drop wrl accessor function
[u-boot] / drivers / usb / host / dwc2.c
index e8a7e713c87f46c09ce1e0cea9ae465d3ec5ba18..eee60a2b039a247b8c1282d1c2e92294a2377ae8 100644 (file)
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <usb.h>
 #include <malloc.h>
+#include <phys2bus.h>
 #include <usbroothubdes.h>
 #include <asm/io.h>
 
@@ -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 = &regs->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 = &regs->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;
@@ -724,11 +737,9 @@ int wait_for_chhltd(uint32_t *sub, int *toggle)
        hctsiz = readl(&hc_regs->hctsiz);
        *sub = (hctsiz & DWC2_HCTSIZ_XFERSIZE_MASK) >>
                DWC2_HCTSIZ_XFERSIZE_OFFSET;
-       if (toggle)
-               *toggle = (hctsiz & DWC2_HCTSIZ_PID_MASK) >>
-                       DWC2_HCTSIZ_PID_OFFSET;
+       *toggle = (hctsiz & DWC2_HCTSIZ_PID_MASK) >> DWC2_HCTSIZ_PID_OFFSET;
 
-       debug("%s: sub=%u toggle=%d\n", __func__, *sub, toggle ? *toggle : -1);
+       debug("%s: sub=%u toggle=%d\n", __func__, *sub, *toggle);
 
        return 0;
 }
@@ -741,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 = &regs->hc_regs[DWC2_HC_CHANNEL];
        int devnum = usb_pipedevice(pipe);
@@ -749,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,24 +769,18 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
        debug("%s: msg: pipe %lx pid %d in %d len %d\n", __func__, pipe, *pid,
              in, len);
 
-       if (len > DWC2_DATA_BUF_SIZE) {
-               printf("%s: %d is more then available buffer size (%d)\n",
-                      __func__, len, DWC2_DATA_BUF_SIZE);
-               dev->status = 0;
-               dev->act_len = 0;
-               return -EINVAL;
-       }
-
        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;
-               /* Make sure that xfer_len is a multiple of max packet size. */
                if (xfer_len > CONFIG_DWC2_MAX_TRANSFER_SIZE)
                        xfer_len = CONFIG_DWC2_MAX_TRANSFER_SIZE - max + 1;
+               if (xfer_len > DWC2_DATA_BUF_SIZE)
+                       xfer_len = DWC2_DATA_BUF_SIZE - max + 1;
 
+               /* Make sure that xfer_len is a multiple of max packet size. */
                if (xfer_len > 0) {
                        num_packets = (xfer_len + max - 1) / max;
                        if (num_packets > CONFIG_DWC2_MAX_PACKET_COUNT) {
@@ -797,8 +802,11 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
                       (*pid << DWC2_HCTSIZ_PID_OFFSET),
                       &hc_regs->hctsiz);
 
-               memcpy(aligned_buffer, (char *)buffer + done, len - done);
-               writel((uint32_t)aligned_buffer, &hc_regs->hcdma);
+               if (!in)
+                       memcpy(aligned_buffer, (char *)buffer + done, len);
+
+               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 |
@@ -806,22 +814,20 @@ 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;
-               }
 
-               done += xfer_len;
                if (in) {
-                       done -= sub;
+                       xfer_len -= sub;
+                       memcpy(buffer + done, aligned_buffer, xfer_len);
                        if (sub)
                                stop_transfer = 1;
                }
-       } while ((done < len) && !stop_transfer);
 
-       if (done && in)
-               memcpy(buffer, aligned_buffer, done);
+               done += xfer_len;
+
+       } while ((done < len) && !stop_transfer);
 
        writel(0, &hc_regs->hcintmsk);
        writel(0xFFFFFFFF, &hc_regs->hcint);
@@ -829,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 */
@@ -845,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,
@@ -863,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;
@@ -885,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;
 
@@ -897,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 */
@@ -913,7 +932,8 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
        snpsid = readl(&regs->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;
        }