]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
usb: dwc2: gadget: Add DDMA chain pointers to dwc2_hsotg_ep structure
authorVahram Aharonyan <vahrama@synopsys.com>
Thu, 10 Nov 2016 03:28:03 +0000 (19:28 -0800)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Fri, 18 Nov 2016 11:54:20 +0000 (13:54 +0200)
Add DMA descriptor members to the dwc2_hsotg_ep structure.

Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/dwc2/core.h
drivers/usb/dwc2/gadget.c

index 26d4c1716adf151f0af3c1ace461f9e8213c864f..4094d3dee25aa1100cf46363d7b451050d0cd2b6 100644 (file)
@@ -172,6 +172,9 @@ struct dwc2_hsotg_req;
  * @periodic: Set if this is a periodic ep, such as Interrupt
  * @isochronous: Set if this is a isochronous ep
  * @send_zlp: Set if we need to send a zero-length packet.
+ * @desc_list_dma: The DMA address of descriptor chain currently in use.
+ * @desc_list: Pointer to descriptor DMA chain head currently in use.
+ * @desc_count: Count of entries within the DMA descriptor chain of EP.
  * @total_data: The total number of data bytes done.
  * @fifo_size: The size of the FIFO (for periodic IN endpoints)
  * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
@@ -219,6 +222,10 @@ struct dwc2_hsotg_ep {
 #define TARGET_FRAME_INITIAL   0xFFFFFFFF
        bool                    frame_overrun;
 
+       dma_addr_t              desc_list_dma;
+       struct dwc2_dma_desc    *desc_list;
+       u8                      desc_count;
+
        char                    name[10];
 };
 
index 4c1098f84431c324f4bfc249cc50b427aa188c7e..3264375231f48c99739736af67052ae60a36b5d3 100644 (file)
@@ -3077,6 +3077,18 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
        dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n",
                __func__, epctrl, epctrl_reg);
 
+       /* Allocate DMA descriptor chain for non-ctrl endpoints */
+       if (using_desc_dma(hsotg)) {
+               hs_ep->desc_list = dma_alloc_coherent(hsotg->dev,
+                       MAX_DMA_DESC_NUM_GENERIC *
+                       sizeof(struct dwc2_dma_desc),
+                       &hs_ep->desc_list_dma, GFP_KERNEL);
+               if (!hs_ep->desc_list) {
+                       ret = -ENOMEM;
+                       goto error2;
+               }
+       }
+
        spin_lock_irqsave(&hsotg->lock, flags);
 
        epctrl &= ~(DXEPCTL_EPTYPE_MASK | DXEPCTL_MPS_MASK);
@@ -3160,7 +3172,7 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
                        dev_err(hsotg->dev,
                                "%s: No suitable fifo found\n", __func__);
                        ret = -ENOMEM;
-                       goto error;
+                       goto error1;
                }
                hsotg->fifo_map |= 1 << fifo_index;
                epctrl |= DXEPCTL_TXFNUM(fifo_index);
@@ -3182,8 +3194,17 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
        /* enable the endpoint interrupt */
        dwc2_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
 
-error:
+error1:
        spin_unlock_irqrestore(&hsotg->lock, flags);
+
+error2:
+       if (ret && using_desc_dma(hsotg) && hs_ep->desc_list) {
+               dma_free_coherent(hsotg->dev, MAX_DMA_DESC_NUM_GENERIC *
+                       sizeof(struct dwc2_dma_desc),
+                       hs_ep->desc_list, hs_ep->desc_list_dma);
+               hs_ep->desc_list = NULL;
+       }
+
        return ret;
 }
 
@@ -3208,6 +3229,14 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep)
                return -EINVAL;
        }
 
+       /* Remove DMA memory allocated for non-control Endpoints */
+       if (using_desc_dma(hsotg)) {
+               dma_free_coherent(hsotg->dev, MAX_DMA_DESC_NUM_GENERIC *
+                                 sizeof(struct dwc2_dma_desc),
+                                 hs_ep->desc_list, hs_ep->desc_list_dma);
+               hs_ep->desc_list = NULL;
+       }
+
        epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
 
        spin_lock_irqsave(&hsotg->lock, flags);