diff options
Diffstat (limited to 'drivers/usb/host/ehci-tegra.c')
-rw-r--r-- | drivers/usb/host/ehci-tegra.c | 515 |
1 files changed, 120 insertions, 395 deletions
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index 59d111bf44a9..6ee7ef79b4f8 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c | |||
@@ -17,59 +17,53 @@ | |||
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 | ||
37 | /* PORTSC registers */ | 45 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) |
38 | #define TEGRA_USB_PORTSC1 0x184 | ||
39 | #define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30) | ||
40 | #define TEGRA_USB_PORTSC1_PHCD (1 << 23) | ||
41 | 46 | ||
42 | #define TEGRA_USB_DMA_ALIGN 32 | 47 | #define TEGRA_USB_DMA_ALIGN 32 |
43 | 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 | |||
44 | struct tegra_ehci_hcd { | 58 | struct tegra_ehci_hcd { |
45 | struct ehci_hcd *ehci; | ||
46 | struct tegra_usb_phy *phy; | 59 | struct tegra_usb_phy *phy; |
47 | struct clk *clk; | 60 | struct clk *clk; |
48 | struct usb_phy *transceiver; | 61 | struct usb_phy *transceiver; |
49 | int host_resumed; | ||
50 | int port_resuming; | 62 | int port_resuming; |
51 | bool needs_double_reset; | 63 | bool needs_double_reset; |
52 | enum tegra_usb_phy_port_speed port_speed; | 64 | enum tegra_usb_phy_port_speed port_speed; |
53 | }; | 65 | }; |
54 | 66 | ||
55 | static void tegra_ehci_power_up(struct usb_hcd *hcd) | ||
56 | { | ||
57 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
58 | |||
59 | clk_prepare_enable(tegra->clk); | ||
60 | usb_phy_set_suspend(hcd->phy, 0); | ||
61 | tegra->host_resumed = 1; | ||
62 | } | ||
63 | |||
64 | static void tegra_ehci_power_down(struct usb_hcd *hcd) | ||
65 | { | ||
66 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
67 | |||
68 | tegra->host_resumed = 0; | ||
69 | usb_phy_set_suspend(hcd->phy, 1); | ||
70 | clk_disable_unprepare(tegra->clk); | ||
71 | } | ||
72 | |||
73 | static int tegra_ehci_internal_port_reset( | 67 | static int tegra_ehci_internal_port_reset( |
74 | struct ehci_hcd *ehci, | 68 | struct ehci_hcd *ehci, |
75 | u32 __iomem *portsc_reg | 69 | u32 __iomem *portsc_reg |
@@ -144,8 +138,8 @@ static int tegra_ehci_hub_control( | |||
144 | u16 wLength | 138 | u16 wLength |
145 | ) | 139 | ) |
146 | { | 140 | { |
147 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 141 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
148 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | 142 | struct tegra_ehci_hcd *tegra = (struct tegra_ehci_hcd *)ehci->priv; |
149 | u32 __iomem *status_reg; | 143 | u32 __iomem *status_reg; |
150 | u32 temp; | 144 | u32 temp; |
151 | unsigned long flags; | 145 | unsigned long flags; |
@@ -179,7 +173,7 @@ static int tegra_ehci_hub_control( | |||
179 | * If a transaction is in progress, there may be a delay in | 173 | * If a transaction is in progress, there may be a delay in |
180 | * suspending the port. Poll until the port is suspended. | 174 | * suspending the port. Poll until the port is suspended. |
181 | */ | 175 | */ |
182 | if (handshake(ehci, status_reg, PORT_SUSPEND, | 176 | if (ehci_handshake(ehci, status_reg, PORT_SUSPEND, |
183 | PORT_SUSPEND, 5000)) | 177 | PORT_SUSPEND, 5000)) |
184 | pr_err("%s: timeout waiting for SUSPEND\n", __func__); | 178 | pr_err("%s: timeout waiting for SUSPEND\n", __func__); |
185 | 179 | ||
@@ -227,9 +221,9 @@ static int tegra_ehci_hub_control( | |||
227 | spin_lock_irqsave(&ehci->lock, flags); | 221 | spin_lock_irqsave(&ehci->lock, flags); |
228 | 222 | ||
229 | /* Poll until the controller clears RESUME and SUSPEND */ | 223 | /* Poll until the controller clears RESUME and SUSPEND */ |
230 | if (handshake(ehci, status_reg, PORT_RESUME, 0, 2000)) | 224 | if (ehci_handshake(ehci, status_reg, PORT_RESUME, 0, 2000)) |
231 | pr_err("%s: timeout waiting for RESUME\n", __func__); | 225 | pr_err("%s: timeout waiting for RESUME\n", __func__); |
232 | if (handshake(ehci, status_reg, PORT_SUSPEND, 0, 2000)) | 226 | if (ehci_handshake(ehci, status_reg, PORT_SUSPEND, 0, 2000)) |
233 | pr_err("%s: timeout waiting for SUSPEND\n", __func__); | 227 | pr_err("%s: timeout waiting for SUSPEND\n", __func__); |
234 | 228 | ||
235 | ehci->reset_done[wIndex-1] = 0; | 229 | ehci->reset_done[wIndex-1] = 0; |
@@ -242,58 +236,13 @@ static int tegra_ehci_hub_control( | |||
242 | spin_unlock_irqrestore(&ehci->lock, flags); | 236 | spin_unlock_irqrestore(&ehci->lock, flags); |
243 | 237 | ||
244 | /* Handle the hub control events here */ | 238 | /* Handle the hub control events here */ |
245 | return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); | 239 | return orig_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
240 | |||
246 | done: | 241 | done: |
247 | spin_unlock_irqrestore(&ehci->lock, flags); | 242 | spin_unlock_irqrestore(&ehci->lock, flags); |
248 | return retval; | 243 | return retval; |
249 | } | 244 | } |
250 | 245 | ||
251 | static void tegra_ehci_restart(struct usb_hcd *hcd) | ||
252 | { | ||
253 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
254 | |||
255 | ehci_reset(ehci); | ||
256 | |||
257 | /* setup the frame list and Async q heads */ | ||
258 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); | ||
259 | ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next); | ||
260 | /* setup the command register and set the controller in RUN mode */ | ||
261 | ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); | ||
262 | ehci->command |= CMD_RUN; | ||
263 | ehci_writel(ehci, ehci->command, &ehci->regs->command); | ||
264 | |||
265 | down_write(&ehci_cf_port_reset_rwsem); | ||
266 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); | ||
267 | /* flush posted writes */ | ||
268 | ehci_readl(ehci, &ehci->regs->command); | ||
269 | up_write(&ehci_cf_port_reset_rwsem); | ||
270 | } | ||
271 | |||
272 | static void tegra_ehci_shutdown(struct usb_hcd *hcd) | ||
273 | { | ||
274 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
275 | |||
276 | /* ehci_shutdown touches the USB controller registers, make sure | ||
277 | * controller has clocks to it */ | ||
278 | if (!tegra->host_resumed) | ||
279 | tegra_ehci_power_up(hcd); | ||
280 | |||
281 | ehci_shutdown(hcd); | ||
282 | } | ||
283 | |||
284 | static int tegra_ehci_setup(struct usb_hcd *hcd) | ||
285 | { | ||
286 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
287 | |||
288 | /* EHCI registers start at offset 0x100 */ | ||
289 | ehci->caps = hcd->regs + 0x100; | ||
290 | |||
291 | /* switch to host mode */ | ||
292 | hcd->has_tt = 1; | ||
293 | |||
294 | return ehci_setup(hcd); | ||
295 | } | ||
296 | |||
297 | struct dma_aligned_buffer { | 246 | struct dma_aligned_buffer { |
298 | void *kmalloc_ptr; | 247 | void *kmalloc_ptr; |
299 | void *old_xfer_buffer; | 248 | void *old_xfer_buffer; |
@@ -373,38 +322,6 @@ static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | |||
373 | free_dma_aligned_buffer(urb); | 322 | free_dma_aligned_buffer(urb); |
374 | } | 323 | } |
375 | 324 | ||
376 | static const struct hc_driver tegra_ehci_hc_driver = { | ||
377 | .description = hcd_name, | ||
378 | .product_desc = "Tegra EHCI Host Controller", | ||
379 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
380 | .flags = HCD_USB2 | HCD_MEMORY, | ||
381 | |||
382 | /* standard ehci functions */ | ||
383 | .irq = ehci_irq, | ||
384 | .start = ehci_run, | ||
385 | .stop = ehci_stop, | ||
386 | .urb_enqueue = ehci_urb_enqueue, | ||
387 | .urb_dequeue = ehci_urb_dequeue, | ||
388 | .endpoint_disable = ehci_endpoint_disable, | ||
389 | .endpoint_reset = ehci_endpoint_reset, | ||
390 | .get_frame_number = ehci_get_frame, | ||
391 | .hub_status_data = ehci_hub_status_data, | ||
392 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | ||
393 | .relinquish_port = ehci_relinquish_port, | ||
394 | .port_handed_over = ehci_port_handed_over, | ||
395 | |||
396 | /* modified ehci functions for tegra */ | ||
397 | .reset = tegra_ehci_setup, | ||
398 | .shutdown = tegra_ehci_shutdown, | ||
399 | .map_urb_for_dma = tegra_ehci_map_urb_for_dma, | ||
400 | .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma, | ||
401 | .hub_control = tegra_ehci_hub_control, | ||
402 | #ifdef CONFIG_PM | ||
403 | .bus_suspend = ehci_bus_suspend, | ||
404 | .bus_resume = ehci_bus_resume, | ||
405 | #endif | ||
406 | }; | ||
407 | |||
408 | static int setup_vbus_gpio(struct platform_device *pdev, | 325 | static int setup_vbus_gpio(struct platform_device *pdev, |
409 | struct tegra_ehci_platform_data *pdata) | 326 | struct tegra_ehci_platform_data *pdata) |
410 | { | 327 | { |
@@ -432,220 +349,16 @@ static int setup_vbus_gpio(struct platform_device *pdev, | |||
432 | return err; | 349 | return err; |
433 | } | 350 | } |
434 | 351 | ||
435 | #ifdef CONFIG_PM | ||
436 | |||
437 | static int controller_suspend(struct device *dev) | ||
438 | { | ||
439 | struct tegra_ehci_hcd *tegra = | ||
440 | platform_get_drvdata(to_platform_device(dev)); | ||
441 | struct ehci_hcd *ehci = tegra->ehci; | ||
442 | struct usb_hcd *hcd = ehci_to_hcd(ehci); | ||
443 | struct ehci_regs __iomem *hw = ehci->regs; | ||
444 | unsigned long flags; | ||
445 | |||
446 | if (time_before(jiffies, ehci->next_statechange)) | ||
447 | msleep(10); | ||
448 | |||
449 | ehci_halt(ehci); | ||
450 | |||
451 | spin_lock_irqsave(&ehci->lock, flags); | ||
452 | tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3; | ||
453 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
454 | spin_unlock_irqrestore(&ehci->lock, flags); | ||
455 | |||
456 | tegra_ehci_power_down(hcd); | ||
457 | return 0; | ||
458 | } | ||
459 | |||
460 | static int controller_resume(struct device *dev) | ||
461 | { | ||
462 | struct tegra_ehci_hcd *tegra = | ||
463 | platform_get_drvdata(to_platform_device(dev)); | ||
464 | struct ehci_hcd *ehci = tegra->ehci; | ||
465 | struct usb_hcd *hcd = ehci_to_hcd(ehci); | ||
466 | struct ehci_regs __iomem *hw = ehci->regs; | ||
467 | unsigned long val; | ||
468 | |||
469 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
470 | tegra_ehci_power_up(hcd); | ||
471 | |||
472 | if (tegra->port_speed > TEGRA_USB_PHY_PORT_SPEED_HIGH) { | ||
473 | /* Wait for the phy to detect new devices | ||
474 | * before we restart the controller */ | ||
475 | msleep(10); | ||
476 | goto restart; | ||
477 | } | ||
478 | |||
479 | /* Force the phy to keep data lines in suspend state */ | ||
480 | tegra_ehci_phy_restore_start(hcd->phy, tegra->port_speed); | ||
481 | |||
482 | /* Enable host mode */ | ||
483 | tdi_reset(ehci); | ||
484 | |||
485 | /* Enable Port Power */ | ||
486 | val = readl(&hw->port_status[0]); | ||
487 | val |= PORT_POWER; | ||
488 | writel(val, &hw->port_status[0]); | ||
489 | udelay(10); | ||
490 | |||
491 | /* Check if the phy resume from LP0. When the phy resume from LP0 | ||
492 | * USB register will be reset. */ | ||
493 | if (!readl(&hw->async_next)) { | ||
494 | /* Program the field PTC based on the saved speed mode */ | ||
495 | val = readl(&hw->port_status[0]); | ||
496 | val &= ~PORT_TEST(~0); | ||
497 | if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_HIGH) | ||
498 | val |= PORT_TEST_FORCE; | ||
499 | else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL) | ||
500 | val |= PORT_TEST(6); | ||
501 | else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW) | ||
502 | val |= PORT_TEST(7); | ||
503 | writel(val, &hw->port_status[0]); | ||
504 | udelay(10); | ||
505 | |||
506 | /* Disable test mode by setting PTC field to NORMAL_OP */ | ||
507 | val = readl(&hw->port_status[0]); | ||
508 | val &= ~PORT_TEST(~0); | ||
509 | writel(val, &hw->port_status[0]); | ||
510 | udelay(10); | ||
511 | } | ||
512 | |||
513 | /* Poll until CCS is enabled */ | ||
514 | if (handshake(ehci, &hw->port_status[0], PORT_CONNECT, | ||
515 | PORT_CONNECT, 2000)) { | ||
516 | pr_err("%s: timeout waiting for PORT_CONNECT\n", __func__); | ||
517 | goto restart; | ||
518 | } | ||
519 | |||
520 | /* Poll until PE is enabled */ | ||
521 | if (handshake(ehci, &hw->port_status[0], PORT_PE, | ||
522 | PORT_PE, 2000)) { | ||
523 | pr_err("%s: timeout waiting for USB_PORTSC1_PE\n", __func__); | ||
524 | goto restart; | ||
525 | } | ||
526 | |||
527 | /* Clear the PCI status, to avoid an interrupt taken upon resume */ | ||
528 | val = readl(&hw->status); | ||
529 | val |= STS_PCD; | ||
530 | writel(val, &hw->status); | ||
531 | |||
532 | /* Put controller in suspend mode by writing 1 to SUSP bit of PORTSC */ | ||
533 | val = readl(&hw->port_status[0]); | ||
534 | if ((val & PORT_POWER) && (val & PORT_PE)) { | ||
535 | val |= PORT_SUSPEND; | ||
536 | writel(val, &hw->port_status[0]); | ||
537 | |||
538 | /* Wait until port suspend completes */ | ||
539 | if (handshake(ehci, &hw->port_status[0], PORT_SUSPEND, | ||
540 | PORT_SUSPEND, 1000)) { | ||
541 | pr_err("%s: timeout waiting for PORT_SUSPEND\n", | ||
542 | __func__); | ||
543 | goto restart; | ||
544 | } | ||
545 | } | ||
546 | |||
547 | tegra_ehci_phy_restore_end(hcd->phy); | ||
548 | goto done; | ||
549 | |||
550 | restart: | ||
551 | if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH) | ||
552 | tegra_ehci_phy_restore_end(hcd->phy); | ||
553 | |||
554 | tegra_ehci_restart(hcd); | ||
555 | |||
556 | done: | ||
557 | tegra_usb_phy_preresume(hcd->phy); | ||
558 | tegra->port_resuming = 1; | ||
559 | return 0; | ||
560 | } | ||
561 | |||
562 | static int tegra_ehci_suspend(struct device *dev) | ||
563 | { | ||
564 | struct tegra_ehci_hcd *tegra = | ||
565 | platform_get_drvdata(to_platform_device(dev)); | ||
566 | struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci); | ||
567 | int rc = 0; | ||
568 | |||
569 | /* | ||
570 | * When system sleep is supported and USB controller wakeup is | ||
571 | * implemented: If the controller is runtime-suspended and the | ||
572 | * wakeup setting needs to be changed, call pm_runtime_resume(). | ||
573 | */ | ||
574 | if (HCD_HW_ACCESSIBLE(hcd)) | ||
575 | rc = controller_suspend(dev); | ||
576 | return rc; | ||
577 | } | ||
578 | |||
579 | static int tegra_ehci_resume(struct device *dev) | ||
580 | { | ||
581 | int rc; | ||
582 | |||
583 | rc = controller_resume(dev); | ||
584 | if (rc == 0) { | ||
585 | pm_runtime_disable(dev); | ||
586 | pm_runtime_set_active(dev); | ||
587 | pm_runtime_enable(dev); | ||
588 | } | ||
589 | return rc; | ||
590 | } | ||
591 | |||
592 | static int tegra_ehci_runtime_suspend(struct device *dev) | ||
593 | { | ||
594 | return controller_suspend(dev); | ||
595 | } | ||
596 | |||
597 | static int tegra_ehci_runtime_resume(struct device *dev) | ||
598 | { | ||
599 | return controller_resume(dev); | ||
600 | } | ||
601 | |||
602 | static const struct dev_pm_ops tegra_ehci_pm_ops = { | ||
603 | .suspend = tegra_ehci_suspend, | ||
604 | .resume = tegra_ehci_resume, | ||
605 | .runtime_suspend = tegra_ehci_runtime_suspend, | ||
606 | .runtime_resume = tegra_ehci_runtime_resume, | ||
607 | }; | ||
608 | |||
609 | #endif | ||
610 | |||
611 | /* Bits of PORTSC1, which will get cleared by writing 1 into them */ | ||
612 | #define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) | ||
613 | |||
614 | static void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val) | ||
615 | { | ||
616 | unsigned long val; | ||
617 | struct usb_hcd *hcd = bus_to_hcd(x->otg->host); | ||
618 | void __iomem *base = hcd->regs; | ||
619 | |||
620 | val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS; | ||
621 | val &= ~TEGRA_USB_PORTSC1_PTS(3); | ||
622 | val |= TEGRA_USB_PORTSC1_PTS(pts_val & 3); | ||
623 | writel(val, base + TEGRA_USB_PORTSC1); | ||
624 | } | ||
625 | |||
626 | static void tegra_ehci_set_phcd(struct usb_phy *x, bool enable) | ||
627 | { | ||
628 | unsigned long val; | ||
629 | struct usb_hcd *hcd = bus_to_hcd(x->otg->host); | ||
630 | void __iomem *base = hcd->regs; | ||
631 | |||
632 | val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS; | ||
633 | if (enable) | ||
634 | val |= TEGRA_USB_PORTSC1_PHCD; | ||
635 | else | ||
636 | val &= ~TEGRA_USB_PORTSC1_PHCD; | ||
637 | writel(val, base + TEGRA_USB_PORTSC1); | ||
638 | } | ||
639 | |||
640 | static int tegra_ehci_probe(struct platform_device *pdev) | 352 | static int tegra_ehci_probe(struct platform_device *pdev) |
641 | { | 353 | { |
642 | struct resource *res; | 354 | struct resource *res; |
643 | struct usb_hcd *hcd; | 355 | struct usb_hcd *hcd; |
356 | struct ehci_hcd *ehci; | ||
644 | struct tegra_ehci_hcd *tegra; | 357 | struct tegra_ehci_hcd *tegra; |
645 | struct tegra_ehci_platform_data *pdata; | 358 | struct tegra_ehci_platform_data *pdata; |
646 | int err = 0; | 359 | int err = 0; |
647 | int irq; | 360 | int irq; |
648 | int instance = pdev->id; | 361 | struct device_node *np_phy; |
649 | struct usb_phy *u_phy; | 362 | struct usb_phy *u_phy; |
650 | 363 | ||
651 | pdata = pdev->dev.platform_data; | 364 | pdata = pdev->dev.platform_data; |
@@ -665,35 +378,47 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
665 | 378 | ||
666 | setup_vbus_gpio(pdev, pdata); | 379 | setup_vbus_gpio(pdev, pdata); |
667 | 380 | ||
668 | tegra = devm_kzalloc(&pdev->dev, sizeof(struct tegra_ehci_hcd), | ||
669 | GFP_KERNEL); | ||
670 | if (!tegra) | ||
671 | return -ENOMEM; | ||
672 | |||
673 | hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev, | 381 | hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev, |
674 | dev_name(&pdev->dev)); | 382 | dev_name(&pdev->dev)); |
675 | if (!hcd) { | 383 | if (!hcd) { |
676 | dev_err(&pdev->dev, "Unable to create HCD\n"); | 384 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
677 | return -ENOMEM; | 385 | err = -ENOMEM; |
386 | goto cleanup_vbus_gpio; | ||
678 | } | 387 | } |
388 | platform_set_drvdata(pdev, hcd); | ||
389 | ehci = hcd_to_ehci(hcd); | ||
390 | tegra = (struct tegra_ehci_hcd *)ehci->priv; | ||
679 | 391 | ||
680 | platform_set_drvdata(pdev, tegra); | 392 | hcd->has_tt = 1; |
681 | 393 | ||
682 | tegra->clk = devm_clk_get(&pdev->dev, NULL); | 394 | tegra->clk = devm_clk_get(&pdev->dev, NULL); |
683 | if (IS_ERR(tegra->clk)) { | 395 | if (IS_ERR(tegra->clk)) { |
684 | dev_err(&pdev->dev, "Can't get ehci clock\n"); | 396 | dev_err(&pdev->dev, "Can't get ehci clock\n"); |
685 | err = PTR_ERR(tegra->clk); | 397 | err = PTR_ERR(tegra->clk); |
686 | goto fail_clk; | 398 | goto cleanup_hcd_create; |
687 | } | 399 | } |
688 | 400 | ||
689 | err = clk_prepare_enable(tegra->clk); | 401 | err = clk_prepare_enable(tegra->clk); |
690 | if (err) | 402 | if (err) |
691 | goto fail_clk; | 403 | goto cleanup_clk_get; |
692 | 404 | ||
693 | tegra_periph_reset_assert(tegra->clk); | 405 | tegra_periph_reset_assert(tegra->clk); |
694 | udelay(1); | 406 | udelay(1); |
695 | tegra_periph_reset_deassert(tegra->clk); | 407 | tegra_periph_reset_deassert(tegra->clk); |
696 | 408 | ||
409 | np_phy = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0); | ||
410 | if (!np_phy) { | ||
411 | err = -ENODEV; | ||
412 | goto cleanup_clk_en; | ||
413 | } | ||
414 | |||
415 | u_phy = tegra_usb_get_phy(np_phy); | ||
416 | if (IS_ERR(u_phy)) { | ||
417 | err = PTR_ERR(u_phy); | ||
418 | goto cleanup_clk_en; | ||
419 | } | ||
420 | hcd->phy = u_phy; | ||
421 | |||
697 | tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node, | 422 | tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node, |
698 | "nvidia,needs-double-reset"); | 423 | "nvidia,needs-double-reset"); |
699 | 424 | ||
@@ -701,7 +426,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
701 | if (!res) { | 426 | if (!res) { |
702 | dev_err(&pdev->dev, "Failed to get I/O memory\n"); | 427 | dev_err(&pdev->dev, "Failed to get I/O memory\n"); |
703 | err = -ENXIO; | 428 | err = -ENXIO; |
704 | goto fail_io; | 429 | goto cleanup_clk_en; |
705 | } | 430 | } |
706 | hcd->rsrc_start = res->start; | 431 | hcd->rsrc_start = res->start; |
707 | hcd->rsrc_len = resource_size(res); | 432 | hcd->rsrc_len = resource_size(res); |
@@ -709,68 +434,36 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
709 | if (!hcd->regs) { | 434 | if (!hcd->regs) { |
710 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); | 435 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); |
711 | err = -ENOMEM; | 436 | err = -ENOMEM; |
712 | goto fail_io; | 437 | goto cleanup_clk_en; |
713 | } | ||
714 | |||
715 | /* This is pretty ugly and needs to be fixed when we do only | ||
716 | * device-tree probing. Old code relies on the platform_device | ||
717 | * numbering that we lack for device-tree-instantiated devices. | ||
718 | */ | ||
719 | if (instance < 0) { | ||
720 | switch (res->start) { | ||
721 | case TEGRA_USB_BASE: | ||
722 | instance = 0; | ||
723 | break; | ||
724 | case TEGRA_USB2_BASE: | ||
725 | instance = 1; | ||
726 | break; | ||
727 | case TEGRA_USB3_BASE: | ||
728 | instance = 2; | ||
729 | break; | ||
730 | default: | ||
731 | err = -ENODEV; | ||
732 | dev_err(&pdev->dev, "unknown usb instance\n"); | ||
733 | goto fail_io; | ||
734 | } | ||
735 | } | 438 | } |
439 | ehci->caps = hcd->regs + 0x100; | ||
736 | 440 | ||
737 | tegra->phy = tegra_usb_phy_open(&pdev->dev, instance, hcd->regs, | 441 | err = usb_phy_init(hcd->phy); |
738 | pdata->phy_config, | 442 | if (err) { |
739 | TEGRA_USB_PHY_MODE_HOST, | 443 | dev_err(&pdev->dev, "Failed to initialize phy\n"); |
740 | tegra_ehci_set_pts, | 444 | goto cleanup_clk_en; |
741 | tegra_ehci_set_phcd); | ||
742 | if (IS_ERR(tegra->phy)) { | ||
743 | dev_err(&pdev->dev, "Failed to open USB phy\n"); | ||
744 | err = -ENXIO; | ||
745 | goto fail_io; | ||
746 | } | 445 | } |
747 | 446 | ||
748 | hcd->phy = u_phy = &tegra->phy->u_phy; | ||
749 | usb_phy_init(hcd->phy); | ||
750 | |||
751 | u_phy->otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), | 447 | u_phy->otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), |
752 | GFP_KERNEL); | 448 | GFP_KERNEL); |
753 | if (!u_phy->otg) { | 449 | if (!u_phy->otg) { |
754 | dev_err(&pdev->dev, "Failed to alloc memory for otg\n"); | 450 | dev_err(&pdev->dev, "Failed to alloc memory for otg\n"); |
755 | err = -ENOMEM; | 451 | err = -ENOMEM; |
756 | goto fail_io; | 452 | goto cleanup_phy; |
757 | } | 453 | } |
758 | u_phy->otg->host = hcd_to_bus(hcd); | 454 | u_phy->otg->host = hcd_to_bus(hcd); |
759 | 455 | ||
760 | err = usb_phy_set_suspend(hcd->phy, 0); | 456 | err = usb_phy_set_suspend(hcd->phy, 0); |
761 | if (err) { | 457 | if (err) { |
762 | dev_err(&pdev->dev, "Failed to power on the phy\n"); | 458 | dev_err(&pdev->dev, "Failed to power on the phy\n"); |
763 | goto fail_phy; | 459 | goto cleanup_phy; |
764 | } | 460 | } |
765 | 461 | ||
766 | tegra->host_resumed = 1; | ||
767 | tegra->ehci = hcd_to_ehci(hcd); | ||
768 | |||
769 | irq = platform_get_irq(pdev, 0); | 462 | irq = platform_get_irq(pdev, 0); |
770 | if (!irq) { | 463 | if (!irq) { |
771 | dev_err(&pdev->dev, "Failed to get IRQ\n"); | 464 | dev_err(&pdev->dev, "Failed to get IRQ\n"); |
772 | err = -ENODEV; | 465 | err = -ENODEV; |
773 | goto fail_phy; | 466 | goto cleanup_phy; |
774 | } | 467 | } |
775 | 468 | ||
776 | if (pdata->operating_mode == TEGRA_USB_OTG) { | 469 | if (pdata->operating_mode == TEGRA_USB_OTG) { |
@@ -785,39 +478,32 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
785 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); | 478 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
786 | if (err) { | 479 | if (err) { |
787 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | 480 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
788 | goto fail; | 481 | goto cleanup_transceiver; |
789 | } | 482 | } |
790 | 483 | ||
791 | pm_runtime_set_active(&pdev->dev); | ||
792 | pm_runtime_get_noresume(&pdev->dev); | ||
793 | |||
794 | /* Don't skip the pm_runtime_forbid call if wakeup isn't working */ | ||
795 | /* if (!pdata->power_down_on_bus_suspend) */ | ||
796 | pm_runtime_forbid(&pdev->dev); | ||
797 | pm_runtime_enable(&pdev->dev); | ||
798 | pm_runtime_put_sync(&pdev->dev); | ||
799 | return err; | 484 | return err; |
800 | 485 | ||
801 | fail: | 486 | cleanup_transceiver: |
802 | if (!IS_ERR(tegra->transceiver)) | 487 | if (!IS_ERR(tegra->transceiver)) |
803 | otg_set_host(tegra->transceiver->otg, NULL); | 488 | otg_set_host(tegra->transceiver->otg, NULL); |
804 | fail_phy: | 489 | cleanup_phy: |
805 | usb_phy_shutdown(hcd->phy); | 490 | usb_phy_shutdown(hcd->phy); |
806 | fail_io: | 491 | cleanup_clk_en: |
807 | clk_disable_unprepare(tegra->clk); | 492 | clk_disable_unprepare(tegra->clk); |
808 | fail_clk: | 493 | cleanup_clk_get: |
494 | clk_put(tegra->clk); | ||
495 | cleanup_hcd_create: | ||
809 | usb_put_hcd(hcd); | 496 | usb_put_hcd(hcd); |
497 | cleanup_vbus_gpio: | ||
498 | /* FIXME: Undo setup_vbus_gpio() here */ | ||
810 | return err; | 499 | return err; |
811 | } | 500 | } |
812 | 501 | ||
813 | static int tegra_ehci_remove(struct platform_device *pdev) | 502 | static int tegra_ehci_remove(struct platform_device *pdev) |
814 | { | 503 | { |
815 | struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev); | 504 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
816 | struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci); | 505 | struct tegra_ehci_hcd *tegra = |
817 | 506 | (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv; | |
818 | pm_runtime_get_sync(&pdev->dev); | ||
819 | pm_runtime_disable(&pdev->dev); | ||
820 | pm_runtime_put_noidle(&pdev->dev); | ||
821 | 507 | ||
822 | if (!IS_ERR(tegra->transceiver)) | 508 | if (!IS_ERR(tegra->transceiver)) |
823 | otg_set_host(tegra->transceiver->otg, NULL); | 509 | otg_set_host(tegra->transceiver->otg, NULL); |
@@ -833,8 +519,7 @@ static int tegra_ehci_remove(struct platform_device *pdev) | |||
833 | 519 | ||
834 | static void tegra_ehci_hcd_shutdown(struct platform_device *pdev) | 520 | static void tegra_ehci_hcd_shutdown(struct platform_device *pdev) |
835 | { | 521 | { |
836 | struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev); | 522 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
837 | struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci); | ||
838 | 523 | ||
839 | if (hcd->driver->shutdown) | 524 | if (hcd->driver->shutdown) |
840 | hcd->driver->shutdown(hcd); | 525 | hcd->driver->shutdown(hcd); |
@@ -850,10 +535,50 @@ static struct platform_driver tegra_ehci_driver = { | |||
850 | .remove = tegra_ehci_remove, | 535 | .remove = tegra_ehci_remove, |
851 | .shutdown = tegra_ehci_hcd_shutdown, | 536 | .shutdown = tegra_ehci_hcd_shutdown, |
852 | .driver = { | 537 | .driver = { |
853 | .name = "tegra-ehci", | 538 | .name = DRV_NAME, |
854 | .of_match_table = tegra_ehci_of_match, | 539 | .of_match_table = tegra_ehci_of_match, |
855 | #ifdef CONFIG_PM | ||
856 | .pm = &tegra_ehci_pm_ops, | ||
857 | #endif | ||
858 | } | 540 | } |
859 | }; | 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); | ||