mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-12 19:46:50 +07:00
usb: dwc3: gadget: refactor dwc3_gadget_init_endpoints()
This just makes it slightly easier to read. No functional changes. Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
This commit is contained in:
parent
f38e35dd84
commit
8f1c99cd24
@ -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 *dwc = dep->dwc;
|
||||
|
||||
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;
|
||||
|
||||
dep->endpoint.caps.type_control = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep)
|
||||
{
|
||||
struct dwc3 *dwc = dep->dwc;
|
||||
int mdwidth;
|
||||
int kbytes;
|
||||
int size;
|
||||
|
||||
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(dep->number >> 1));
|
||||
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;
|
||||
|
||||
kbytes = size / 1024;
|
||||
if (kbytes == 0)
|
||||
kbytes = 1;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
usb_ep_set_maxpacket_limit(&dep->endpoint, size);
|
||||
|
||||
dep->endpoint.max_streams = 15;
|
||||
dep->endpoint.ops = &dwc3_gadget_ep_ops;
|
||||
list_add_tail(&dep->endpoint.ep_list,
|
||||
&dwc->gadget.ep_list);
|
||||
dep->endpoint.caps.type_iso = true;
|
||||
dep->endpoint.caps.type_bulk = true;
|
||||
dep->endpoint.caps.type_int = true;
|
||||
|
||||
return dwc3_alloc_trb_pool(dep);
|
||||
}
|
||||
|
||||
static int dwc3_gadget_init_out_endpoint(struct dwc3_ep *dep)
|
||||
{
|
||||
struct dwc3 *dwc = dep->dwc;
|
||||
|
||||
usb_ep_set_maxpacket_limit(&dep->endpoint, 1024);
|
||||
dep->endpoint.max_streams = 15;
|
||||
dep->endpoint.ops = &dwc3_gadget_ep_ops;
|
||||
list_add_tail(&dep->endpoint.ep_list,
|
||||
&dwc->gadget.ep_list);
|
||||
dep->endpoint.caps.type_iso = true;
|
||||
dep->endpoint.caps.type_bulk = true;
|
||||
dep->endpoint.caps.type_int = true;
|
||||
|
||||
return dwc3_alloc_trb_pool(dep);
|
||||
}
|
||||
|
||||
static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum)
|
||||
{
|
||||
struct dwc3_ep *dep;
|
||||
bool direction = epnum & 1;
|
||||
int ret;
|
||||
u8 num = epnum >> 1;
|
||||
|
||||
dep = kzalloc(sizeof(*dep), GFP_KERNEL);
|
||||
if (!dep)
|
||||
return -ENOMEM;
|
||||
|
||||
dep->dwc = dwc;
|
||||
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_out = !direction;
|
||||
|
||||
INIT_LIST_HEAD(&dep->pending_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++) {
|
||||
bool direction = epnum & 1;
|
||||
u8 num = epnum >> 1;
|
||||
int ret;
|
||||
|
||||
dep = kzalloc(sizeof(*dep), GFP_KERNEL);
|
||||
if (!dep)
|
||||
return -ENOMEM;
|
||||
|
||||
dep->dwc = dwc;
|
||||
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) {
|
||||
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;
|
||||
|
||||
kbytes = size / 1024;
|
||||
if (kbytes == 0)
|
||||
kbytes = 1;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
usb_ep_set_maxpacket_limit(&dep->endpoint, size);
|
||||
|
||||
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);
|
||||
if (ret)
|
||||
return ret;
|
||||
} else {
|
||||
int ret;
|
||||
|
||||
usb_ep_set_maxpacket_limit(&dep->endpoint, 1024);
|
||||
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);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
dep->endpoint.caps.type_control = true;
|
||||
} else {
|
||||
dep->endpoint.caps.type_iso = true;
|
||||
dep->endpoint.caps.type_bulk = true;
|
||||
dep->endpoint.caps.type_int = true;
|
||||
}
|
||||
|
||||
dep->endpoint.caps.dir_in = direction;
|
||||
dep->endpoint.caps.dir_out = !direction;
|
||||
|
||||
INIT_LIST_HEAD(&dep->pending_list);
|
||||
INIT_LIST_HEAD(&dep->started_list);
|
||||
ret = dwc3_gadget_init_endpoint(dwc, epnum);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user