diff mbox

[v2] dwc2: gadget: Fix ISOC IN DDMA PID bitfield value calculation

Message ID bf808c7575f5b07fa778768f8f2cd85b4af698e9.1527673915.git.hminas@synopsys.com (mailing list archive)
State New, archived
Headers show

Commit Message

Minas Harutyunyan May 30, 2018, 9:52 a.m. UTC
PID bitfield in descriptor should be set based on particular request
length, not based on EP's mc value. PID value can't be set to 0 even
request length is 0.

If request length is 0 then SP bit should be set along PID.

Signed-off-by: Minas Harutyunyan <hminas@synopsys.com>
---
 drivers/usb/dwc2/gadget.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index f0d9ccf1d665..20b04c00e626 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -812,6 +812,8 @@  static int dwc2_gadget_fill_isoc_desc(struct dwc2_hsotg_ep *hs_ep,
 	u32 index;
 	u32 maxsize = 0;
 	u32 mask = 0;
+	u32 sp = 0;
+	u8 pid = 0;
 
 	maxsize = dwc2_gadget_get_desc_params(hs_ep, &mask);
 
@@ -840,10 +842,15 @@  static int dwc2_gadget_fill_isoc_desc(struct dwc2_hsotg_ep *hs_ep,
 			 ((len << DEV_DMA_NBYTES_SHIFT) & mask));
 
 	if (hs_ep->dir_in) {
-		desc->status |= ((hs_ep->mc << DEV_DMA_ISOC_PID_SHIFT) &
-				 DEV_DMA_ISOC_PID_MASK) |
-				((len % hs_ep->ep.maxpacket) ?
-				 DEV_DMA_SHORT : 0) |
+		if (len) {
+			pid = DIV_ROUND_UP(len, hs_ep->ep.maxpacket);
+			sp = (len % hs_ep->ep.maxpacket) ? DEV_DMA_SHORT : 0;
+		} else {
+			pid = 1;
+			sp = DEV_DMA_SHORT;
+		}
+		desc->status |= ((pid << DEV_DMA_ISOC_PID_SHIFT) &
+				 DEV_DMA_ISOC_PID_MASK) | sp |
 				((hs_ep->target_frame <<
 				  DEV_DMA_ISOC_FRNUM_SHIFT) &
 				 DEV_DMA_ISOC_FRNUM_MASK);