dwc3: gadget: Use TXFIFO register based on used dwc3 version
TXFIFO register's bit(15) is reserved on usb31 version. Hence this
change starts using dwc3 version based TXFIFO size related macro
to update TXFIFO register while resizing TXFIFO of USB endpoint.
Change-Id: I1b9fb9d109f1ad8e1fd4bc23c75341bdec912c10
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 079a318..5f576b1 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -633,6 +633,7 @@
int ret, num;
u32 reg;
struct dwc3_ep *dep;
+ int size;
cfg = le16_to_cpu(ctrl->wValue);
@@ -649,15 +650,26 @@
if (dwc->needs_fifo_resize && dwc->tx_fifo_size) {
/* Read ep0IN related TXFIFO size */
dep = dwc->eps[1];
- dwc->last_fifo_depth = dep->fifo_depth =
- (dwc3_readl(dwc->regs,
- DWC3_GTXFIFOSIZ(0)) & 0xFFFF);
+ size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0));
+ if (dwc3_is_usb31(dwc))
+ dep->fifo_depth = DWC31_GTXFIFOSIZ_TXFDEF(size);
+ else
+ dep->fifo_depth = DWC3_GTXFIFOSIZ_TXFDEF(size);
+
+ dwc->last_fifo_depth = dep->fifo_depth;
/* Clear existing TXFIFO for all IN eps except ep0 */
for (num = 3; num < min_t(int, dwc->num_eps,
DWC3_ENDPOINTS_NUM); num += 2) {
dep = dwc->eps[num];
+ size = 0;
+ /* Don't change TXFRAMNUM on usb31 version */
+ if (dwc3_is_usb31(dwc))
+ size = dwc3_readl(dwc->regs,
+ DWC3_GTXFIFOSIZ(num >> 1)) &
+ DWC31_GTXFIFOSIZ_TXFRAMNUM;
+
dwc3_writel(dwc->regs,
- DWC3_GTXFIFOSIZ(num >> 1), 0);
+ DWC3_GTXFIFOSIZ(num >> 1), size);
dep->fifo_depth = 0;
dev_dbg(dwc->dev, "%s(): %s fifo_depth:%x\n",
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 754dddb..5d9fbcf 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -199,7 +199,7 @@
int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc, struct dwc3_ep *dep)
{
int fifo_size, mdwidth, max_packet = 1024;
- int tmp, mult = 1;
+ int tmp, mult = 1, size;
if (!dwc->needs_fifo_resize || !dwc->tx_fifo_size)
return 0;
@@ -231,9 +231,18 @@
tmp = ((max_packet + mdwidth) * mult) + mdwidth;
fifo_size = DIV_ROUND_UP(tmp, mdwidth);
dep->fifo_depth = fifo_size;
- fifo_size |= (dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)) & 0xffff0000)
- + (dwc->last_fifo_depth << 16);
- dwc->last_fifo_depth += (fifo_size & 0xffff);
+
+ size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0));
+ if (dwc3_is_usb31(dwc))
+ size = DWC31_GTXFIFOSIZ_TXFDEF(size);
+ else
+ size = DWC3_GTXFIFOSIZ_TXFDEF(size);
+
+ fifo_size |= (size + (dwc->last_fifo_depth << 16));
+ if (dwc3_is_usb31(dwc))
+ dwc->last_fifo_depth += DWC31_GTXFIFOSIZ_TXFDEF(fifo_size);
+ else
+ dwc->last_fifo_depth += DWC3_GTXFIFOSIZ_TXFDEF(fifo_size);
dev_dbg(dwc->dev, "%s ep_num:%d last_fifo_depth:%04x fifo_depth:%d\n",
dep->endpoint.name, dep->endpoint.ep_num, dwc->last_fifo_depth,
@@ -246,7 +255,11 @@
dev_err(dwc->dev, "Fifosize(%d) > RAM size(%d) %s depth:%d\n",
(dwc->last_fifo_depth * mdwidth), dwc->tx_fifo_size,
dep->endpoint.name, fifo_size);
- dwc->last_fifo_depth -= (fifo_size & 0xffff);
+ if (dwc3_is_usb31(dwc))
+ fifo_size = DWC31_GTXFIFOSIZ_TXFDEF(fifo_size);
+ else
+ fifo_size = DWC3_GTXFIFOSIZ_TXFDEF(fifo_size);
+ dwc->last_fifo_depth -= fifo_size;
dep->fifo_depth = 0;
WARN_ON(1);
return -ENOMEM;