Commit be7ed2533d4acb9bc67989c4ffddb5814202ba02
1 parent
b959655f18
Exists in
master
and in
55 other branches
usb: mv_udc: Make use of struct ehci_ctrl
The usb_lowlevel_init() call already fills and passes back struct ehci_ctrl , which readily contains correctly determined address of the port register block address computed from values from controller configuration registers. Leverage this and make use of this value as this makes the code mode universal, but also gets us rid of the CONFIG_USB_REG_BASE configuration option. Moreover, this patch cleans up the usb_gadget_register_driver() call a little by correcting the error handling. Note the usb_lowlevel_init() and mvudc_probe() are now called in reversed order, but this has no impact on the code. 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 2 changed files with 26 additions and 21 deletions Side-by-side Diff
drivers/usb/gadget/mv_udc.c
... | ... | @@ -118,7 +118,7 @@ |
118 | 118 | static void ep_enable(int num, int in) |
119 | 119 | { |
120 | 120 | struct ept_queue_head *head; |
121 | - struct mv_udc *udc = controller.udc; | |
121 | + struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; | |
122 | 122 | unsigned n; |
123 | 123 | head = epts + 2*num + in; |
124 | 124 | |
... | ... | @@ -154,7 +154,7 @@ |
154 | 154 | struct usb_request *req, gfp_t gfp_flags) |
155 | 155 | { |
156 | 156 | struct mv_ep *mv_ep = container_of(ep, struct mv_ep, ep); |
157 | - struct mv_udc *udc = controller.udc; | |
157 | + struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; | |
158 | 158 | struct ept_queue_item *item; |
159 | 159 | struct ept_queue_head *head; |
160 | 160 | unsigned phys; |
... | ... | @@ -220,7 +220,7 @@ |
220 | 220 | static void handle_setup(void) |
221 | 221 | { |
222 | 222 | struct usb_request *req = &controller.ep[0].req; |
223 | - struct mv_udc *udc = controller.udc; | |
223 | + struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; | |
224 | 224 | struct ept_queue_head *head; |
225 | 225 | struct usb_ctrlrequest r; |
226 | 226 | int status = 0; |
... | ... | @@ -293,7 +293,7 @@ |
293 | 293 | { |
294 | 294 | int i, num, in; |
295 | 295 | struct ept_queue_head *head; |
296 | - struct mv_udc *udc = controller.udc; | |
296 | + struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; | |
297 | 297 | writel(readl(&udc->epcomp), &udc->epcomp); |
298 | 298 | writel(readl(&udc->epstat), &udc->epstat); |
299 | 299 | writel(0xffffffff, &udc->epflush); |
... | ... | @@ -315,7 +315,7 @@ |
315 | 315 | |
316 | 316 | void udc_irq(void) |
317 | 317 | { |
318 | - struct mv_udc *udc = controller.udc; | |
318 | + struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; | |
319 | 319 | unsigned n = readl(&udc->usbsts); |
320 | 320 | writel(n, &udc->usbsts); |
321 | 321 | int bit, i, num, in; |
... | ... | @@ -373,7 +373,7 @@ |
373 | 373 | int usb_gadget_handle_interrupts(void) |
374 | 374 | { |
375 | 375 | u32 value; |
376 | - struct mv_udc *udc = controller.udc; | |
376 | + struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; | |
377 | 377 | |
378 | 378 | value = readl(&udc->usbsts); |
379 | 379 | if (value) |
... | ... | @@ -384,7 +384,7 @@ |
384 | 384 | |
385 | 385 | static int mv_pullup(struct usb_gadget *gadget, int is_on) |
386 | 386 | { |
387 | - struct mv_udc *udc = controller.udc; | |
387 | + struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; | |
388 | 388 | if (is_on) { |
389 | 389 | /* RESET */ |
390 | 390 | writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd); |
... | ... | @@ -412,7 +412,7 @@ |
412 | 412 | |
413 | 413 | void udc_disconnect(void) |
414 | 414 | { |
415 | - struct mv_udc *udc = controller.udc; | |
415 | + struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; | |
416 | 416 | /* disable pullup */ |
417 | 417 | stop_activity(); |
418 | 418 | writel(USBCMD_FS2, &udc->usbcmd); |
... | ... | @@ -427,7 +427,6 @@ |
427 | 427 | int i; |
428 | 428 | |
429 | 429 | controller.gadget.ops = &mv_udc_ops; |
430 | - controller.udc = (struct mv_udc *)CONFIG_USB_REG_BASE; | |
431 | 430 | epts = memalign(PAGE_SIZE, QH_MAXNUM * sizeof(struct ept_queue_head)); |
432 | 431 | memset(epts, 0, QH_MAXNUM * sizeof(struct ept_queue_head)); |
433 | 432 | for (i = 0; i < 2 * NUM_ENDPOINTS; i++) { |
... | ... | @@ -469,9 +468,8 @@ |
469 | 468 | |
470 | 469 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) |
471 | 470 | { |
472 | - struct mv_udc *udc = controller.udc; | |
473 | - int retval; | |
474 | - void *ctrl; | |
471 | + struct mv_udc *udc; | |
472 | + int ret; | |
475 | 473 | |
476 | 474 | if (!driver |
477 | 475 | || driver->speed < USB_SPEED_FULL |
478 | 476 | |
... | ... | @@ -481,15 +479,22 @@ |
481 | 479 | return -EINVAL; |
482 | 480 | } |
483 | 481 | |
484 | - if (!mvudc_probe()) { | |
485 | - usb_lowlevel_init(0, &ctrl); | |
482 | + ret = usb_lowlevel_init(0, (void **)&controller.ctrl); | |
483 | + if (ret) | |
484 | + return ret; | |
485 | + | |
486 | + ret = mvudc_probe(); | |
487 | + if (!ret) { | |
488 | + udc = (struct mv_udc *)controller.ctrl->hcor; | |
489 | + | |
486 | 490 | /* select ULPI phy */ |
487 | 491 | writel(PTS(PTS_ENABLE) | PFSC, &udc->portsc); |
488 | 492 | } |
489 | - retval = driver->bind(&controller.gadget); | |
490 | - if (retval) { | |
491 | - DBG("driver->bind() returned %d\n", retval); | |
492 | - return retval; | |
493 | + | |
494 | + ret = driver->bind(&controller.gadget); | |
495 | + if (ret) { | |
496 | + DBG("driver->bind() returned %d\n", ret); | |
497 | + return ret; | |
493 | 498 | } |
494 | 499 | controller.driver = driver; |
495 | 500 |
include/usb/mv_udc.h
... | ... | @@ -14,6 +14,8 @@ |
14 | 14 | #include <linux/usb/ch9.h> |
15 | 15 | #include <linux/usb/gadget.h> |
16 | 16 | |
17 | +#include "../../drivers/usb/host/ehci.h" | |
18 | + | |
17 | 19 | #define NUM_ENDPOINTS 6 |
18 | 20 | |
19 | 21 | /* Endpoint parameters */ |
... | ... | @@ -23,7 +25,6 @@ |
23 | 25 | #define EP0_MAX_PACKET_SIZE 64 |
24 | 26 | |
25 | 27 | struct mv_udc { |
26 | - u32 pad0[80]; | |
27 | 28 | #define MICRO_8FRAME 0x8 |
28 | 29 | #define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16) |
29 | 30 | #define USBCMD_FS2 (1 << 15) |
... | ... | @@ -73,7 +74,7 @@ |
73 | 74 | struct mv_drv { |
74 | 75 | struct usb_gadget gadget; |
75 | 76 | struct usb_gadget_driver *driver; |
76 | - struct mv_udc *udc; | |
77 | + struct ehci_ctrl *ctrl; | |
77 | 78 | struct mv_ep ep[NUM_ENDPOINTS]; |
78 | 79 | }; |
79 | 80 | |
... | ... | @@ -121,6 +122,5 @@ |
121 | 122 | #define INFO_BUFFER_ERROR (1 << 5) |
122 | 123 | #define INFO_TX_ERROR (1 << 3) |
123 | 124 | |
124 | -extern int usb_lowlevel_init(int index, void **controller); | |
125 | 125 | #endif /* __MV_UDC_H__ */ |