summaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3/gadget.c
diff options
context:
space:
mode:
authorFelipe Balbi <felipe.balbi@linux.intel.com>2016-04-05 12:09:51 +0200
committerFelipe Balbi <felipe.balbi@linux.intel.com>2016-04-19 10:11:46 +0200
commitef966b9d33533b0bf01fb8c4d586ac3b20a3bdb5 (patch)
tree75da78b3e3cf384b6aa872cb0b006826ed4d9d02 /drivers/usb/dwc3/gadget.c
parentusb: dwc3: get rid of DWC3_TRB_MASK (diff)
downloadlinux-ef966b9d33533b0bf01fb8c4d586ac3b20a3bdb5.tar.xz
linux-ef966b9d33533b0bf01fb8c4d586ac3b20a3bdb5.zip
usb: dwc3: gadget: add trb enqueue/dequeue helpers
Add three little helpers which will aid in making the code slightly easier to read. One helper increments enqueue pointer, another increments dequeue pointer and the last one tests if we're dealing with the last TRB. Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Diffstat (limited to 'drivers/usb/dwc3/gadget.c')
-rw-r--r--drivers/usb/dwc3/gadget.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0e7cc20c2fd0..98d8a4549103 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -145,6 +145,21 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state)
return -ETIMEDOUT;
}
+static void dwc3_ep_inc_enq(struct dwc3_ep *dep)
+{
+ dep->trb_enqueue++;
+}
+
+static void dwc3_ep_inc_deq(struct dwc3_ep *dep)
+{
+ dep->trb_dequeue++;
+}
+
+static int dwc3_ep_is_last_trb(unsigned int index)
+{
+ return (index % DWC3_TRB_NUM) == (DWC3_TRB_NUM - 1);
+}
+
void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
int status)
{
@@ -154,16 +169,15 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
if (req->started) {
i = 0;
do {
- dep->trb_dequeue++;
+ dwc3_ep_inc_deq(dep);
/*
* Skip LINK TRB. We can't use req->trb and check for
* DWC3_TRBCTL_LINK_TRB because it points the TRB we
* just completed (not the LINK TRB).
*/
- if (((dep->trb_dequeue % DWC3_TRB_NUM) ==
- DWC3_TRB_NUM - 1) &&
+ if (dwc3_ep_is_last_trb(dep->trb_dequeue) &&
usb_endpoint_xfer_isoc(dep->endpoint.desc))
- dep->trb_dequeue++;
+ dwc3_ep_inc_deq(dep);
} while(++i < req->request.num_mapped_sgs);
req->started = false;
}
@@ -750,11 +764,11 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
req->first_trb_index = dep->trb_enqueue % DWC3_TRB_NUM;
}
- dep->trb_enqueue++;
+ dwc3_ep_inc_enq(dep);
/* Skip the LINK-TRB on ISOC */
- if (((dep->trb_enqueue % DWC3_TRB_NUM) == DWC3_TRB_NUM - 1) &&
+ if (dwc3_ep_is_last_trb(dep->trb_enqueue) &&
usb_endpoint_xfer_isoc(dep->endpoint.desc))
- dep->trb_enqueue++;
+ dwc3_ep_inc_enq(dep);
trb->size = DWC3_TRB_SIZE_LENGTH(length);
trb->bpl = lower_32_bits(dma);