Commit b5cd45bfad3a25db25b40cfda9e7db80e5ee65f7
1 parent
5804b8859a
Exists in
master
and in
54 other branches
usb: mv_udc: Implement better QH accessor
The code for retrieving QH for particular endpoint is hard to understand, moreover it's duplicated all over the driver. Move the code into single nice and documented function. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Fabio Estevam <fabio.estevam@freescale.com> Cc: Lei Wen <leiwen@marvell.com> Cc: Otavio Salvador <otavio@ossystems.com.br> Cc: Stefano Babic <sbabic@denx.de>
Showing 1 changed file with 18 additions and 5 deletions Side-by-side Diff
drivers/usb/gadget/mv_udc.c
... | ... | @@ -110,6 +110,19 @@ |
110 | 110 | }, |
111 | 111 | }; |
112 | 112 | |
113 | +/** | |
114 | + * mv_get_qh() - return queue head for endpoint | |
115 | + * @ep_num: Endpoint number | |
116 | + * @dir_in: Direction of the endpoint (IN = 1, OUT = 0) | |
117 | + * | |
118 | + * This function returns the QH associated with particular endpoint | |
119 | + * and it's direction. | |
120 | + */ | |
121 | +static struct ept_queue_head *mv_get_qh(int ep_num, int dir_in) | |
122 | +{ | |
123 | + return &controller.epts[(ep_num * 2) + dir_in]; | |
124 | +} | |
125 | + | |
113 | 126 | static struct usb_request * |
114 | 127 | mv_ep_alloc_request(struct usb_ep *ep, unsigned int gfp_flags) |
115 | 128 | { |
... | ... | @@ -127,7 +140,7 @@ |
127 | 140 | struct ept_queue_head *head; |
128 | 141 | struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; |
129 | 142 | unsigned n; |
130 | - head = controller.epts + 2*num + in; | |
143 | + head = mv_get_qh(num, in); | |
131 | 144 | |
132 | 145 | n = readl(&udc->epctrl[num]); |
133 | 146 | if (in) |
... | ... | @@ -169,7 +182,7 @@ |
169 | 182 | num = mv_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; |
170 | 183 | in = (mv_ep->desc->bEndpointAddress & USB_DIR_IN) != 0; |
171 | 184 | item = controller.items[2 * num + in]; |
172 | - head = controller.epts + 2 * num + in; | |
185 | + head = mv_get_qh(num, in); | |
173 | 186 | phys = (unsigned)req->buf; |
174 | 187 | len = req->length; |
175 | 188 | |
... | ... | @@ -233,7 +246,7 @@ |
233 | 246 | int status = 0; |
234 | 247 | int num, in, _num, _in, i; |
235 | 248 | char *buf; |
236 | - head = controller.epts + 2 * 0 + 0; | |
249 | + head = mv_get_qh(0, 0); /* EP0 OUT */ | |
237 | 250 | |
238 | 251 | flush_cache((unsigned long)head, sizeof(struct ept_queue_head)); |
239 | 252 | memcpy(&r, head->setup_data, sizeof(struct usb_ctrlrequest)); |
... | ... | @@ -314,7 +327,7 @@ |
314 | 327 | & USB_ENDPOINT_NUMBER_MASK; |
315 | 328 | in = (controller.ep[i].desc->bEndpointAddress |
316 | 329 | & USB_DIR_IN) != 0; |
317 | - head = controller.epts + (num * 2) + (in); | |
330 | + head = mv_get_qh(num, in); | |
318 | 331 | head->info = INFO_ACTIVE; |
319 | 332 | } |
320 | 333 | } |
... | ... | @@ -397,7 +410,7 @@ |
397 | 410 | writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd); |
398 | 411 | udelay(200); |
399 | 412 | |
400 | - writel((unsigned) controller.epts, &udc->epinitaddr); | |
413 | + writel((unsigned)controller.epts, &udc->epinitaddr); | |
401 | 414 | |
402 | 415 | /* select DEVICE mode */ |
403 | 416 | writel(USBMODE_DEVICE, &udc->usbmode); |