usb: dwc3: gadget: fix init endpoints and resize tx fifos

The dwc3 initializes all of the endpoints in the following order:
epnum 0: USB EP0-OUT
epnum 1: USB EP0-IN
epnum 2: USB EP1-OUT
epnum 3: USB EP1-IN
...

This initialization logic works well if the number of IN endpoints
is equal to OUT endpoints. However, some SoCs have different number
of endpoints between the EP-IN and EP-OUT (e.g. RK3399/RV1109 7 IN
endpoints and 6 OUT endpoints), it will fail to init all of the
endpoints in this case.

This patch fixes the initialization logic for all of the IN and OUT
endpoints.

In addition, this patch also fixes the fifo depth of the Tx fifo0
when resize all of the tx fifos. And increase the fifos of isoc IN
endponits to hide system high bus latency.

Change-Id: I2928024f39cafaf669fd8e19b945a570c9650ca8
Signed-off-by: William Wu <william.wu@rock-chips.com>
This commit is contained in:
William Wu
2020-04-20 10:11:00 +08:00
committed by Tao Huang
parent e9494f6332
commit c2185009e2

View File

@@ -159,7 +159,7 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state)
*/
static int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
{
int last_fifo_depth = 0;
int last_fifo_depth;
int fifo_size;
int mdwidth;
u8 num, num_in_eps;
@@ -172,6 +172,9 @@ static int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
/* MDWIDTH is represented in bits, we need it in bytes */
mdwidth >>= 3;
fifo_size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0));
last_fifo_depth = DWC3_GTXFIFOSIZ_TXFSTADDR(fifo_size) >> 16;
for (num = 0; num < num_in_eps; num++) {
u8 epnum = (num << 1) | 1;
struct dwc3_ep *dep = dwc->eps[epnum];
@@ -182,9 +185,10 @@ static int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
if (!(dep->flags & DWC3_EP_ENABLED))
continue;
if (usb_endpoint_xfer_bulk(dep->endpoint.desc) ||
usb_endpoint_xfer_isoc(dep->endpoint.desc))
if (usb_endpoint_xfer_bulk(dep->endpoint.desc))
mult = 3;
else if (usb_endpoint_xfer_isoc(dep->endpoint.desc))
mult = 6;
/*
* REVISIT: the following assumes we will always have enough
@@ -2399,12 +2403,25 @@ static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum)
static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total)
{
u8 epnum;
u8 epnum, num;
u8 num_in_eps, num_out_eps;
bool direction;
num_in_eps = DWC3_NUM_IN_EPS(&dwc->hwparams);
num_out_eps = total - num_in_eps;
INIT_LIST_HEAD(&dwc->gadget.ep_list);
for (epnum = 0; epnum < total; epnum++) {
int ret;
direction = epnum & 1;
num = (epnum >> 1) + 1;
if ((!direction && num > num_out_eps) ||
(direction && num > num_in_eps)) {
total++;
continue;
}
ret = dwc3_gadget_init_endpoint(dwc, epnum);
if (ret)