diff options
Diffstat (limited to 'drivers/usb/host/ehci-tegra.c')
-rw-r--r-- | drivers/usb/host/ehci-tegra.c | 128 |
1 files changed, 74 insertions, 54 deletions
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index 80634292efee..338c8a56118d 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c | |||
@@ -17,25 +17,44 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/clk.h> | 19 | #include <linux/clk.h> |
20 | #include <linux/clk/tegra.h> | ||
21 | #include <linux/dma-mapping.h> | ||
20 | #include <linux/err.h> | 22 | #include <linux/err.h> |
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/platform_data/tegra_usb.h> | ||
23 | #include <linux/irq.h> | ||
24 | #include <linux/usb/otg.h> | ||
25 | #include <linux/gpio.h> | 23 | #include <linux/gpio.h> |
24 | #include <linux/io.h> | ||
25 | #include <linux/irq.h> | ||
26 | #include <linux/module.h> | ||
26 | #include <linux/of.h> | 27 | #include <linux/of.h> |
27 | #include <linux/of_gpio.h> | 28 | #include <linux/of_gpio.h> |
29 | #include <linux/platform_device.h> | ||
30 | #include <linux/platform_data/tegra_usb.h> | ||
28 | #include <linux/pm_runtime.h> | 31 | #include <linux/pm_runtime.h> |
32 | #include <linux/slab.h> | ||
29 | #include <linux/usb/ehci_def.h> | 33 | #include <linux/usb/ehci_def.h> |
30 | #include <linux/usb/tegra_usb_phy.h> | 34 | #include <linux/usb/tegra_usb_phy.h> |
31 | #include <linux/clk/tegra.h> | 35 | #include <linux/usb.h> |
36 | #include <linux/usb/hcd.h> | ||
37 | #include <linux/usb/otg.h> | ||
38 | |||
39 | #include "ehci.h" | ||
32 | 40 | ||
33 | #define TEGRA_USB_BASE 0xC5000000 | 41 | #define TEGRA_USB_BASE 0xC5000000 |
34 | #define TEGRA_USB2_BASE 0xC5004000 | 42 | #define TEGRA_USB2_BASE 0xC5004000 |
35 | #define TEGRA_USB3_BASE 0xC5008000 | 43 | #define TEGRA_USB3_BASE 0xC5008000 |
36 | 44 | ||
45 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) | ||
46 | |||
37 | #define TEGRA_USB_DMA_ALIGN 32 | 47 | #define TEGRA_USB_DMA_ALIGN 32 |
38 | 48 | ||
49 | #define DRIVER_DESC "Tegra EHCI driver" | ||
50 | #define DRV_NAME "tegra-ehci" | ||
51 | |||
52 | static struct hc_driver __read_mostly tegra_ehci_hc_driver; | ||
53 | |||
54 | static int (*orig_hub_control)(struct usb_hcd *hcd, | ||
55 | u16 typeReq, u16 wValue, u16 wIndex, | ||
56 | char *buf, u16 wLength); | ||
57 | |||
39 | struct tegra_ehci_hcd { | 58 | struct tegra_ehci_hcd { |
40 | struct ehci_hcd *ehci; | 59 | struct ehci_hcd *ehci; |
41 | struct tegra_usb_phy *phy; | 60 | struct tegra_usb_phy *phy; |
@@ -218,25 +237,13 @@ static int tegra_ehci_hub_control( | |||
218 | spin_unlock_irqrestore(&ehci->lock, flags); | 237 | spin_unlock_irqrestore(&ehci->lock, flags); |
219 | 238 | ||
220 | /* Handle the hub control events here */ | 239 | /* Handle the hub control events here */ |
221 | return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); | 240 | return orig_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
241 | |||
222 | done: | 242 | done: |
223 | spin_unlock_irqrestore(&ehci->lock, flags); | 243 | spin_unlock_irqrestore(&ehci->lock, flags); |
224 | return retval; | 244 | return retval; |
225 | } | 245 | } |
226 | 246 | ||
227 | static int tegra_ehci_setup(struct usb_hcd *hcd) | ||
228 | { | ||
229 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
230 | |||
231 | /* EHCI registers start at offset 0x100 */ | ||
232 | ehci->caps = hcd->regs + 0x100; | ||
233 | |||
234 | /* switch to host mode */ | ||
235 | hcd->has_tt = 1; | ||
236 | |||
237 | return ehci_setup(hcd); | ||
238 | } | ||
239 | |||
240 | struct dma_aligned_buffer { | 247 | struct dma_aligned_buffer { |
241 | void *kmalloc_ptr; | 248 | void *kmalloc_ptr; |
242 | void *old_xfer_buffer; | 249 | void *old_xfer_buffer; |
@@ -316,38 +323,6 @@ static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | |||
316 | free_dma_aligned_buffer(urb); | 323 | free_dma_aligned_buffer(urb); |
317 | } | 324 | } |
318 | 325 | ||
319 | static const struct hc_driver tegra_ehci_hc_driver = { | ||
320 | .description = hcd_name, | ||
321 | .product_desc = "Tegra EHCI Host Controller", | ||
322 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
323 | .flags = HCD_USB2 | HCD_MEMORY, | ||
324 | |||
325 | /* standard ehci functions */ | ||
326 | .irq = ehci_irq, | ||
327 | .start = ehci_run, | ||
328 | .stop = ehci_stop, | ||
329 | .urb_enqueue = ehci_urb_enqueue, | ||
330 | .urb_dequeue = ehci_urb_dequeue, | ||
331 | .endpoint_disable = ehci_endpoint_disable, | ||
332 | .endpoint_reset = ehci_endpoint_reset, | ||
333 | .get_frame_number = ehci_get_frame, | ||
334 | .hub_status_data = ehci_hub_status_data, | ||
335 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | ||
336 | .relinquish_port = ehci_relinquish_port, | ||
337 | .port_handed_over = ehci_port_handed_over, | ||
338 | |||
339 | /* modified ehci functions for tegra */ | ||
340 | .reset = tegra_ehci_setup, | ||
341 | .shutdown = ehci_shutdown, | ||
342 | .map_urb_for_dma = tegra_ehci_map_urb_for_dma, | ||
343 | .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma, | ||
344 | .hub_control = tegra_ehci_hub_control, | ||
345 | #ifdef CONFIG_PM | ||
346 | .bus_suspend = ehci_bus_suspend, | ||
347 | .bus_resume = ehci_bus_resume, | ||
348 | #endif | ||
349 | }; | ||
350 | |||
351 | static int setup_vbus_gpio(struct platform_device *pdev, | 326 | static int setup_vbus_gpio(struct platform_device *pdev, |
352 | struct tegra_ehci_platform_data *pdata) | 327 | struct tegra_ehci_platform_data *pdata) |
353 | { | 328 | { |
@@ -444,6 +419,9 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
444 | err = -ENOMEM; | 419 | err = -ENOMEM; |
445 | goto cleanup_clk; | 420 | goto cleanup_clk; |
446 | } | 421 | } |
422 | tegra->ehci = hcd_to_ehci(hcd); | ||
423 | |||
424 | hcd->has_tt = 1; | ||
447 | hcd->phy = u_phy; | 425 | hcd->phy = u_phy; |
448 | 426 | ||
449 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 427 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
@@ -460,6 +438,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
460 | err = -ENOMEM; | 438 | err = -ENOMEM; |
461 | goto cleanup_hcd_create; | 439 | goto cleanup_hcd_create; |
462 | } | 440 | } |
441 | tegra->ehci->caps = hcd->regs + 0x100; | ||
463 | 442 | ||
464 | err = usb_phy_init(hcd->phy); | 443 | err = usb_phy_init(hcd->phy); |
465 | if (err) { | 444 | if (err) { |
@@ -482,8 +461,6 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
482 | goto cleanup_phy; | 461 | goto cleanup_phy; |
483 | } | 462 | } |
484 | 463 | ||
485 | tegra->ehci = hcd_to_ehci(hcd); | ||
486 | |||
487 | irq = platform_get_irq(pdev, 0); | 464 | irq = platform_get_irq(pdev, 0); |
488 | if (!irq) { | 465 | if (!irq) { |
489 | dev_err(&pdev->dev, "Failed to get IRQ\n"); | 466 | dev_err(&pdev->dev, "Failed to get IRQ\n"); |
@@ -558,7 +535,50 @@ static struct platform_driver tegra_ehci_driver = { | |||
558 | .remove = tegra_ehci_remove, | 535 | .remove = tegra_ehci_remove, |
559 | .shutdown = tegra_ehci_hcd_shutdown, | 536 | .shutdown = tegra_ehci_hcd_shutdown, |
560 | .driver = { | 537 | .driver = { |
561 | .name = "tegra-ehci", | 538 | .name = DRV_NAME, |
562 | .of_match_table = tegra_ehci_of_match, | 539 | .of_match_table = tegra_ehci_of_match, |
563 | } | 540 | } |
564 | }; | 541 | }; |
542 | |||
543 | static const struct ehci_driver_overrides tegra_overrides __initconst = { | ||
544 | .extra_priv_size = sizeof(struct tegra_ehci_hcd), | ||
545 | }; | ||
546 | |||
547 | static int __init ehci_tegra_init(void) | ||
548 | { | ||
549 | if (usb_disabled()) | ||
550 | return -ENODEV; | ||
551 | |||
552 | pr_info(DRV_NAME ": " DRIVER_DESC "\n"); | ||
553 | |||
554 | ehci_init_driver(&tegra_ehci_hc_driver, &tegra_overrides); | ||
555 | |||
556 | /* | ||
557 | * The Tegra HW has some unusual quirks, which require Tegra-specific | ||
558 | * workarounds. We override certain hc_driver functions here to | ||
559 | * achieve that. We explicitly do not enhance ehci_driver_overrides to | ||
560 | * allow this more easily, since this is an unusual case, and we don't | ||
561 | * want to encourage others to override these functions by making it | ||
562 | * too easy. | ||
563 | */ | ||
564 | |||
565 | orig_hub_control = tegra_ehci_hc_driver.hub_control; | ||
566 | |||
567 | tegra_ehci_hc_driver.map_urb_for_dma = tegra_ehci_map_urb_for_dma; | ||
568 | tegra_ehci_hc_driver.unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma; | ||
569 | tegra_ehci_hc_driver.hub_control = tegra_ehci_hub_control; | ||
570 | |||
571 | return platform_driver_register(&tegra_ehci_driver); | ||
572 | } | ||
573 | module_init(ehci_tegra_init); | ||
574 | |||
575 | static void __exit ehci_tegra_cleanup(void) | ||
576 | { | ||
577 | platform_driver_unregister(&tegra_ehci_driver); | ||
578 | } | ||
579 | module_exit(ehci_tegra_cleanup); | ||
580 | |||
581 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
582 | MODULE_LICENSE("GPL"); | ||
583 | MODULE_ALIAS("platform:" DRV_NAME); | ||
584 | MODULE_DEVICE_TABLE(of, tegra_ehci_of_match); | ||