Commit 46b780d4 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Felipe Balbi

usb: dwc3: gadget: increase readability of dwc3_gadget_init_endpoints()

The commit 47d3946e

	usb: dwc3: refactor gadget endpoint count calculation

refactored dwc3_gadget_init_endpoints() and in particular changed in or
out endpoint numbering to be through. It's not always convenient and
makes code a slightly harder to read.

Introduce a new temporary variable to make it easier to understand what
is going on inside the function.

While doing that, rename local variables as follows:
	u8 num	-> u8 total
	int num -> int kbytes

Replace implicit direction check via epnum with explicit use of
direction variable.

While here, replace %d to %u when compounding endpoint name since we are
using unsigned type.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 8e55d303
...@@ -2027,15 +2027,16 @@ static const struct usb_gadget_ops dwc3_gadget_ops = { ...@@ -2027,15 +2027,16 @@ static const struct usb_gadget_ops dwc3_gadget_ops = {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 num) static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total)
{ {
struct dwc3_ep *dep; struct dwc3_ep *dep;
u8 epnum; u8 epnum;
INIT_LIST_HEAD(&dwc->gadget.ep_list); INIT_LIST_HEAD(&dwc->gadget.ep_list);
for (epnum = 0; epnum < num; epnum++) { for (epnum = 0; epnum < total; epnum++) {
bool direction = epnum & 1; bool direction = epnum & 1;
u8 num = epnum >> 1;
dep = kzalloc(sizeof(*dep), GFP_KERNEL); dep = kzalloc(sizeof(*dep), GFP_KERNEL);
if (!dep) if (!dep)
...@@ -2047,7 +2048,7 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 num) ...@@ -2047,7 +2048,7 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 num)
dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); dep->regs = dwc->regs + DWC3_DEP_BASE(epnum);
dwc->eps[epnum] = dep; dwc->eps[epnum] = dep;
snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1, snprintf(dep->name, sizeof(dep->name), "ep%u%s", num,
direction ? "in" : "out"); direction ? "in" : "out");
dep->endpoint.name = dep->name; dep->endpoint.name = dep->name;
...@@ -2059,39 +2060,39 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 num) ...@@ -2059,39 +2060,39 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 num)
spin_lock_init(&dep->lock); spin_lock_init(&dep->lock);
if (epnum == 0 || epnum == 1) { if (num == 0) {
usb_ep_set_maxpacket_limit(&dep->endpoint, 512); usb_ep_set_maxpacket_limit(&dep->endpoint, 512);
dep->endpoint.maxburst = 1; dep->endpoint.maxburst = 1;
dep->endpoint.ops = &dwc3_gadget_ep0_ops; dep->endpoint.ops = &dwc3_gadget_ep0_ops;
if (!epnum) if (!direction)
dwc->gadget.ep0 = &dep->endpoint; dwc->gadget.ep0 = &dep->endpoint;
} else if (direction) { } else if (direction) {
int mdwidth; int mdwidth;
int kbytes;
int size; int size;
int ret; int ret;
int num;
mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0); mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
/* MDWIDTH is represented in bits, we need it in bytes */ /* MDWIDTH is represented in bits, we need it in bytes */
mdwidth /= 8; mdwidth /= 8;
size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(epnum >> 1)); size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num));
size = DWC3_GTXFIFOSIZ_TXFDEF(size); size = DWC3_GTXFIFOSIZ_TXFDEF(size);
/* FIFO Depth is in MDWDITH bytes. Multiply */ /* FIFO Depth is in MDWDITH bytes. Multiply */
size *= mdwidth; size *= mdwidth;
num = size / 1024; kbytes = size / 1024;
if (num == 0) if (kbytes == 0)
num = 1; kbytes = 1;
/* /*
* FIFO sizes account an extra MDWIDTH * (num + 1) bytes for * FIFO sizes account an extra MDWIDTH * (kbytes + 1) bytes for
* internal overhead. We don't really know how these are used, * internal overhead. We don't really know how these are used,
* but documentation say it exists. * but documentation say it exists.
*/ */
size -= mdwidth * (num + 1); size -= mdwidth * (kbytes + 1);
size /= num; size /= kbytes;
usb_ep_set_maxpacket_limit(&dep->endpoint, size); usb_ep_set_maxpacket_limit(&dep->endpoint, size);
...@@ -2117,7 +2118,7 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 num) ...@@ -2117,7 +2118,7 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 num)
return ret; return ret;
} }
if (epnum == 0 || epnum == 1) { if (num == 0) {
dep->endpoint.caps.type_control = true; dep->endpoint.caps.type_control = true;
} else { } else {
dep->endpoint.caps.type_iso = true; dep->endpoint.caps.type_iso = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment