Commit 8f1c99cd authored by Felipe Balbi's avatar Felipe Balbi

usb: dwc3: gadget: refactor dwc3_gadget_init_endpoints()

This just makes it slightly easier to read. No functional changes.
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent f38e35dd
...@@ -2075,113 +2075,142 @@ static const struct usb_gadget_ops dwc3_gadget_ops = { ...@@ -2075,113 +2075,142 @@ static const struct usb_gadget_ops dwc3_gadget_ops = {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total) static int dwc3_gadget_init_control_endpoint(struct dwc3_ep *dep)
{ {
struct dwc3_ep *dep; struct dwc3 *dwc = dep->dwc;
u8 epnum;
INIT_LIST_HEAD(&dwc->gadget.ep_list); usb_ep_set_maxpacket_limit(&dep->endpoint, 512);
dep->endpoint.maxburst = 1;
dep->endpoint.ops = &dwc3_gadget_ep0_ops;
if (!dep->direction)
dwc->gadget.ep0 = &dep->endpoint;
for (epnum = 0; epnum < total; epnum++) { dep->endpoint.caps.type_control = true;
bool direction = epnum & 1;
u8 num = epnum >> 1;
dep = kzalloc(sizeof(*dep), GFP_KERNEL); return 0;
if (!dep) }
return -ENOMEM;
dep->dwc = dwc; static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep)
dep->number = epnum; {
dep->direction = direction; struct dwc3 *dwc = dep->dwc;
dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); int mdwidth;
dwc->eps[epnum] = dep; int kbytes;
int size;
snprintf(dep->name, sizeof(dep->name), "ep%u%s", num, mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
direction ? "in" : "out"); /* MDWIDTH is represented in bits, we need it in bytes */
mdwidth /= 8;
dep->endpoint.name = dep->name; size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1));
if (dwc3_is_usb31(dwc))
size = DWC31_GTXFIFOSIZ_TXFDEF(size);
else
size = DWC3_GTXFIFOSIZ_TXFDEF(size);
if (!(dep->number > 1)) { /* FIFO Depth is in MDWDITH bytes. Multiply */
dep->endpoint.desc = &dwc3_gadget_ep0_desc; size *= mdwidth;
dep->endpoint.comp_desc = NULL;
}
spin_lock_init(&dep->lock); kbytes = size / 1024;
if (kbytes == 0)
if (num == 0) { kbytes = 1;
usb_ep_set_maxpacket_limit(&dep->endpoint, 512);
dep->endpoint.maxburst = 1;
dep->endpoint.ops = &dwc3_gadget_ep0_ops;
if (!direction)
dwc->gadget.ep0 = &dep->endpoint;
} else if (direction) {
int mdwidth;
int kbytes;
int size;
int ret;
mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
/* MDWIDTH is represented in bits, we need it in bytes */
mdwidth /= 8;
size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num));
if (dwc3_is_usb31(dwc))
size = DWC31_GTXFIFOSIZ_TXFDEF(size);
else
size = DWC3_GTXFIFOSIZ_TXFDEF(size);
/* FIFO Depth is in MDWDITH bytes. Multiply */ /*
size *= mdwidth; * FIFO sizes account an extra MDWIDTH * (kbytes + 1) bytes for
* internal overhead. We don't really know how these are used,
* but documentation say it exists.
*/
size -= mdwidth * (kbytes + 1);
size /= kbytes;
kbytes = size / 1024; usb_ep_set_maxpacket_limit(&dep->endpoint, size);
if (kbytes == 0)
kbytes = 1;
/* dep->endpoint.max_streams = 15;
* FIFO sizes account an extra MDWIDTH * (kbytes + 1) bytes for dep->endpoint.ops = &dwc3_gadget_ep_ops;
* internal overhead. We don't really know how these are used, list_add_tail(&dep->endpoint.ep_list,
* but documentation say it exists. &dwc->gadget.ep_list);
*/ dep->endpoint.caps.type_iso = true;
size -= mdwidth * (kbytes + 1); dep->endpoint.caps.type_bulk = true;
size /= kbytes; dep->endpoint.caps.type_int = true;
usb_ep_set_maxpacket_limit(&dep->endpoint, size); return dwc3_alloc_trb_pool(dep);
}
dep->endpoint.max_streams = 15; static int dwc3_gadget_init_out_endpoint(struct dwc3_ep *dep)
dep->endpoint.ops = &dwc3_gadget_ep_ops; {
list_add_tail(&dep->endpoint.ep_list, struct dwc3 *dwc = dep->dwc;
&dwc->gadget.ep_list);
ret = dwc3_alloc_trb_pool(dep); usb_ep_set_maxpacket_limit(&dep->endpoint, 1024);
if (ret) dep->endpoint.max_streams = 15;
return ret; dep->endpoint.ops = &dwc3_gadget_ep_ops;
} else { list_add_tail(&dep->endpoint.ep_list,
int ret; &dwc->gadget.ep_list);
dep->endpoint.caps.type_iso = true;
dep->endpoint.caps.type_bulk = true;
dep->endpoint.caps.type_int = true;
usb_ep_set_maxpacket_limit(&dep->endpoint, 1024); return dwc3_alloc_trb_pool(dep);
dep->endpoint.max_streams = 15; }
dep->endpoint.ops = &dwc3_gadget_ep_ops;
list_add_tail(&dep->endpoint.ep_list,
&dwc->gadget.ep_list);
ret = dwc3_alloc_trb_pool(dep); static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum)
if (ret) {
return ret; struct dwc3_ep *dep;
} bool direction = epnum & 1;
int ret;
u8 num = epnum >> 1;
if (num == 0) { dep = kzalloc(sizeof(*dep), GFP_KERNEL);
dep->endpoint.caps.type_control = true; if (!dep)
} else { return -ENOMEM;
dep->endpoint.caps.type_iso = true;
dep->endpoint.caps.type_bulk = true; dep->dwc = dwc;
dep->endpoint.caps.type_int = true; dep->number = epnum;
} dep->direction = direction;
dep->regs = dwc->regs + DWC3_DEP_BASE(epnum);
dwc->eps[epnum] = dep;
snprintf(dep->name, sizeof(dep->name), "ep%u%s", num,
direction ? "in" : "out");
dep->endpoint.name = dep->name;
if (!(dep->number > 1)) {
dep->endpoint.desc = &dwc3_gadget_ep0_desc;
dep->endpoint.comp_desc = NULL;
}
spin_lock_init(&dep->lock);
if (num == 0)
ret = dwc3_gadget_init_control_endpoint(dep);
else if (direction)
ret = dwc3_gadget_init_in_endpoint(dep);
else
ret = dwc3_gadget_init_out_endpoint(dep);
if (ret)
return ret;
dep->endpoint.caps.dir_in = direction; dep->endpoint.caps.dir_in = direction;
dep->endpoint.caps.dir_out = !direction; dep->endpoint.caps.dir_out = !direction;
INIT_LIST_HEAD(&dep->pending_list); INIT_LIST_HEAD(&dep->pending_list);
INIT_LIST_HEAD(&dep->started_list); INIT_LIST_HEAD(&dep->started_list);
return 0;
}
static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total)
{
u8 epnum;
INIT_LIST_HEAD(&dwc->gadget.ep_list);
for (epnum = 0; epnum < total; epnum++) {
int ret;
ret = dwc3_gadget_init_endpoint(dwc, epnum);
if (ret)
return ret;
} }
return 0; return 0;
......
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