33 #define TEGRA_USB_DMA_ALIGN 32
46 static void tegra_ehci_power_up(
struct usb_hcd *hcd)
50 clk_prepare_enable(tegra->
emc_clk);
51 clk_prepare_enable(tegra->
clk);
52 usb_phy_set_suspend(&tegra->
phy->u_phy, 0);
56 static void tegra_ehci_power_down(
struct usb_hcd *hcd)
61 usb_phy_set_suspend(&tegra->
phy->u_phy, 1);
62 clk_disable_unprepare(tegra->
clk);
63 clk_disable_unprepare(tegra->
emc_clk);
66 static int tegra_ehci_internal_port_reset(
78 saved_usbintr = ehci_readl(ehci, &ehci->
regs->intr_enable);
80 ehci_writel(ehci, 0, &ehci->
regs->intr_enable);
81 spin_unlock_irqrestore(&ehci->
lock, flags);
87 for (i = 0; i < 2; i++) {
88 temp = ehci_readl(ehci, portsc_reg);
90 ehci_writel(ehci, temp, portsc_reg);
93 ehci_writel(ehci, temp, portsc_reg);
104 temp = ehci_readl(ehci, portsc_reg);
105 }
while (!(temp &
PORT_PE) && tries--);
117 ehci_writel(ehci, PORT_CSC, portsc_reg);
123 temp = ehci_readl(ehci, &ehci->
regs->status);
124 ehci_writel(ehci, temp, &ehci->
regs->status);
127 ehci_writel(ehci, saved_usbintr, &ehci->
regs->intr_enable);
131 static int tegra_ehci_hub_control(
140 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
147 status_reg = &ehci->
regs->port_status[(wIndex & 0xff) - 1];
151 if (typeReq == GetPortStatus) {
152 temp = ehci_readl(ehci, status_reg);
161 temp = ehci_readl(ehci, status_reg);
162 if ((temp & PORT_PE) == 0 || (temp &
PORT_RESET) != 0) {
177 pr_err(
"%s: timeout waiting for SUSPEND\n", __func__);
184 if (tegra->
phy->instance == 0 &&
186 spin_unlock_irqrestore(&ehci->
lock, flags);
187 return tegra_ehci_internal_port_reset(ehci, status_reg);
197 else if (typeReq == ClearPortFeature &&
199 temp = ehci_readl(ehci, status_reg);
200 if ((temp & PORT_RESET) || !(temp & PORT_PE)) {
218 spin_unlock_irqrestore(&ehci->
lock, flags);
224 pr_err(
"%s: timeout waiting for RESUME\n", __func__);
225 if (
handshake(ehci, status_reg, PORT_SUSPEND, 0, 2000))
226 pr_err(
"%s: timeout waiting for SUSPEND\n", __func__);
235 spin_unlock_irqrestore(&ehci->
lock, flags);
238 return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
240 spin_unlock_irqrestore(&ehci->
lock, flags);
244 static void tegra_ehci_restart(
struct usb_hcd *hcd)
246 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
252 ehci_writel(ehci, (
u32)ehci->
async->qh_dma, &ehci->
regs->async_next);
256 ehci_writel(ehci, ehci->
command, &ehci->
regs->command);
259 ehci_writel(ehci,
FLAG_CF, &ehci->
regs->configured_flag);
261 ehci_readl(ehci, &ehci->
regs->command);
262 up_write(&ehci_cf_port_reset_rwsem);
265 static void tegra_ehci_shutdown(
struct usb_hcd *hcd)
272 tegra_ehci_power_up(hcd);
277 static int tegra_ehci_setup(
struct usb_hcd *hcd)
279 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
283 ehci->
caps = hcd->regs + 0x100;
288 retval = ehci_setup(hcd);
292 ehci_port_power(ehci, 1);
302 static void free_dma_aligned_buffer(
struct urb *
urb)
306 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
312 if (usb_urb_dir_in(urb))
314 urb->transfer_buffer_length);
318 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
321 static int alloc_dma_aligned_buffer(
struct urb *
urb,
gfp_t mem_flags)
326 if (urb->num_sgs || urb->sg ||
327 urb->transfer_buffer_length == 0 ||
332 kmalloc_size = urb->transfer_buffer_length +
335 kmalloc_ptr =
kmalloc(kmalloc_size, mem_flags);
343 if (usb_urb_dir_out(urb))
345 urb->transfer_buffer_length);
346 urb->transfer_buffer = temp->
data;
348 urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
353 static int tegra_ehci_map_urb_for_dma(
struct usb_hcd *hcd,
struct urb *urb,
358 ret = alloc_dma_aligned_buffer(urb, mem_flags);
364 free_dma_aligned_buffer(urb);
369 static void tegra_ehci_unmap_urb_for_dma(
struct usb_hcd *hcd,
struct urb *urb)
372 free_dma_aligned_buffer(urb);
375 static const struct hc_driver tegra_ehci_hc_driver = {
376 .description = hcd_name,
377 .product_desc =
"Tegra EHCI Host Controller",
378 .hcd_priv_size =
sizeof(
struct ehci_hcd),
379 .flags = HCD_USB2 | HCD_MEMORY,
385 .urb_enqueue = ehci_urb_enqueue,
386 .urb_dequeue = ehci_urb_dequeue,
387 .endpoint_disable = ehci_endpoint_disable,
388 .endpoint_reset = ehci_endpoint_reset,
389 .get_frame_number = ehci_get_frame,
390 .hub_status_data = ehci_hub_status_data,
391 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
392 .relinquish_port = ehci_relinquish_port,
393 .port_handed_over = ehci_port_handed_over,
396 .reset = tegra_ehci_setup,
397 .shutdown = tegra_ehci_shutdown,
398 .map_urb_for_dma = tegra_ehci_map_urb_for_dma,
399 .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma,
400 .hub_control = tegra_ehci_hub_control,
414 if (!gpio_is_valid(gpio))
415 gpio = of_get_named_gpio(pdev->
dev.of_node,
416 "nvidia,vbus-gpio", 0);
417 if (!gpio_is_valid(gpio))
422 dev_err(&pdev->
dev,
"can't request vbus gpio %d", gpio);
436 static int controller_suspend(
struct device *
dev)
441 struct usb_hcd *hcd = ehci_to_hcd(ehci);
452 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
453 spin_unlock_irqrestore(&ehci->
lock, flags);
455 tegra_ehci_power_down(hcd);
459 static int controller_resume(
struct device *dev)
464 struct usb_hcd *hcd = ehci_to_hcd(ehci);
468 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
469 tegra_ehci_power_up(hcd);
515 pr_err(
"%s: timeout waiting for PORT_CONNECT\n", __func__);
522 pr_err(
"%s: timeout waiting for USB_PORTSC1_PE\n", __func__);
539 PORT_SUSPEND, 1000)) {
540 pr_err(
"%s: timeout waiting for PORT_SUSPEND\n",
553 tegra_ehci_restart(hcd);
561 static int tegra_ehci_suspend(
struct device *dev)
565 struct usb_hcd *hcd = ehci_to_hcd(tegra->
ehci);
573 if (HCD_HW_ACCESSIBLE(hcd))
574 rc = controller_suspend(dev);
578 static int tegra_ehci_resume(
struct device *dev)
582 rc = controller_resume(dev);
584 pm_runtime_disable(dev);
585 pm_runtime_set_active(dev);
591 static int tegra_ehci_runtime_suspend(
struct device *dev)
593 return controller_suspend(dev);
596 static int tegra_ehci_runtime_resume(
struct device *dev)
598 return controller_resume(dev);
601 static const struct dev_pm_ops tegra_ehci_pm_ops = {
603 .resume = tegra_ehci_resume,
604 .runtime_suspend = tegra_ehci_runtime_suspend,
605 .runtime_resume = tegra_ehci_runtime_resume,
620 int instance = pdev->
id;
622 pdata = pdev->
dev.platform_data;
624 dev_err(&pdev->
dev,
"Platform data missing\n");
632 if (!pdev->
dev.dma_mask)
633 pdev->
dev.dma_mask = &tegra_ehci_dma_mask;
635 setup_vbus_gpio(pdev, pdata);
643 dev_name(&pdev->
dev));
645 dev_err(&pdev->
dev,
"Unable to create HCD\n");
649 platform_set_drvdata(pdev, tegra);
652 if (IS_ERR(tegra->
clk)) {
653 dev_err(&pdev->
dev,
"Can't get ehci clock\n");
654 err = PTR_ERR(tegra->
clk);
658 err = clk_prepare_enable(tegra->
clk);
669 clk_prepare_enable(tegra->
emc_clk);
674 dev_err(&pdev->
dev,
"Failed to get I/O memory\n");
678 hcd->rsrc_start = res->
start;
679 hcd->rsrc_len = resource_size(res);
682 dev_err(&pdev->
dev,
"Failed to remap I/O memory\n");
692 switch (res->
start) {
704 dev_err(&pdev->
dev,
"unknown usb instance\n");
712 if (IS_ERR(tegra->
phy)) {
713 dev_err(&pdev->
dev,
"Failed to open USB phy\n");
718 usb_phy_init(&tegra->
phy->u_phy);
720 err = usb_phy_set_suspend(&tegra->
phy->u_phy, 0);
722 dev_err(&pdev->
dev,
"Failed to power on the phy\n");
727 tegra->
ehci = hcd_to_ehci(hcd);
736 #ifdef CONFIG_USB_OTG_UTILS
747 dev_err(&pdev->
dev,
"Failed to add USB HCD\n");
751 pm_runtime_set_active(&pdev->
dev);
752 pm_runtime_get_noresume(&pdev->
dev);
758 pm_runtime_put_sync(&pdev->
dev);
762 #ifdef CONFIG_USB_OTG_UTILS
766 usb_phy_shutdown(&tegra->
phy->u_phy);
768 clk_disable_unprepare(tegra->
emc_clk);
770 clk_disable_unprepare(tegra->
clk);
779 struct usb_hcd *hcd = ehci_to_hcd(tegra->
ehci);
784 pm_runtime_get_sync(&pdev->
dev);
785 pm_runtime_disable(&pdev->
dev);
786 pm_runtime_put_noidle(&pdev->
dev);
788 #ifdef CONFIG_USB_OTG_UTILS
796 usb_phy_shutdown(&tegra->
phy->u_phy);
798 clk_disable_unprepare(tegra->
clk);
800 clk_disable_unprepare(tegra->
emc_clk);
808 struct usb_hcd *hcd = ehci_to_hcd(tegra->
ehci);
810 if (hcd->driver->shutdown)
811 hcd->driver->shutdown(hcd);
815 { .compatible =
"nvidia,tegra20-ehci", },
820 .probe = tegra_ehci_probe,
821 .remove = tegra_ehci_remove,
822 .shutdown = tegra_ehci_hcd_shutdown,
824 .name =
"tegra-ehci",
825 .of_match_table = tegra_ehci_of_match,
827 .pm = &tegra_ehci_pm_ops,