2 * EHCI-compliant USB host controller driver for NVIDIA Tegra SoCs
4 * Copyright (c) 2010 Google, Inc.
5 * Copyright (c) 2009-2014 NVIDIA CORPORATION. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 #include <linux/err.h>
20 #include <linux/platform_device.h>
21 #include <linux/platform_data/tegra_usb.h>
22 #include <linux/irq.h>
23 #include <linux/usb/otg.h>
24 #include <linux/gpio.h>
26 #include <linux/delay.h>
27 #include <linux/of_gpio.h>
28 #include <linux/pm_runtime.h>
29 #include <linux/tegra-soc.h>
31 #include <linux/usb/tegra_usb_phy.h>
33 #include <mach/pm_domains.h>
34 #include <linux/pm_qos.h>
35 #include <linux/wakelock.h>
37 /* HACK! This needs to come from DT */
38 #include "../../../arch/arm/mach-tegra/iomap.h"
41 #define EHCI_DBG(stuff...) pr_info("ehci-tegra: " stuff)
43 #define EHCI_DBG(stuff...) do {} while (0)
46 static const char driver_name[] = "tegra-ehci";
48 #define TEGRA_USB_DMA_ALIGN 32
50 #define HOSTPC_REG_OFFSET 0x1b4
52 #define HOSTPC1_DEVLC_STS (1 << 28)
53 #define HOSTPC1_DEVLC_NYT_ASUS 1
54 #define TEGRA_STREAM_DISABLE 0x1f8
55 #define TEGRA_STREAM_DISABLE_OFFSET (1 << 4)
57 struct tegra_ehci_hcd {
58 struct ehci_hcd *ehci;
59 struct tegra_usb_phy *phy;
60 struct usb_phy *transceiver;
61 struct mutex sync_lock;
62 struct wake_lock ehci_wake_lock;
65 bool bus_suspended_fail;
66 bool unaligned_dma_buf_supported;
68 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
71 bool cpu_boost_in_work;
72 struct delayed_work boost_cpu_freq_work;
73 struct pm_qos_request boost_cpu_freq_req;
77 struct dma_align_buffer {
79 void *old_xfer_buffer;
83 static struct usb_phy *get_usb_phy(struct tegra_usb_phy *x)
85 return (struct usb_phy *)x;
88 static int tegra_ehci_port_speed(struct ehci_hcd *ehci)
90 u32 hostpc = ehci_readl(ehci, &ehci->regs->hostpc);
91 enum usb_device_speed port_speed;
93 switch ((hostpc >> (ehci->has_hostpc ? 25 : 26)) & 3) {
95 port_speed = USB_SPEED_LOW;
98 port_speed = USB_SPEED_FULL;
101 port_speed = USB_SPEED_HIGH;
104 port_speed = USB_SPEED_UNKNOWN;
109 static void tegra_ehci_notify_event(struct tegra_ehci_hcd *tegra, int event)
111 tegra->transceiver->last_event = event;
112 atomic_notifier_call_chain(&tegra->transceiver->notifier, event,
113 tegra->transceiver->otg->gadget);
116 static void free_align_buffer(struct urb *urb, struct usb_hcd *hcd)
118 struct dma_align_buffer *temp;
119 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
121 if (tegra->unaligned_dma_buf_supported)
124 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
127 temp = container_of(urb->transfer_buffer,
128 struct dma_align_buffer, data);
130 /* In transaction, DMA from Device */
131 if (usb_urb_dir_in(urb))
132 memcpy(temp->old_xfer_buffer, temp->data,
133 urb->transfer_buffer_length);
135 urb->transfer_buffer = temp->old_xfer_buffer;
136 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
137 kfree(temp->kmalloc_ptr);
140 static int alloc_align_buffer(struct urb *urb, gfp_t mem_flags,
143 struct dma_align_buffer *temp, *kmalloc_ptr;
145 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
147 if (tegra->unaligned_dma_buf_supported)
150 if (urb->num_sgs || urb->sg ||
151 urb->transfer_buffer_length == 0 ||
152 !((uintptr_t)urb->transfer_buffer & (TEGRA_USB_DMA_ALIGN - 1)))
155 /* Allocate a buffer with enough padding for alignment */
156 kmalloc_size = urb->transfer_buffer_length +
157 sizeof(struct dma_align_buffer) + TEGRA_USB_DMA_ALIGN - 1;
158 kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
163 /* Position our struct dma_align_buffer such that data is aligned */
164 temp = PTR_ALIGN(kmalloc_ptr + 1, TEGRA_USB_DMA_ALIGN) - 1;
165 temp->kmalloc_ptr = kmalloc_ptr;
166 temp->old_xfer_buffer = urb->transfer_buffer;
167 /* OUT transaction, DMA to Device */
168 if (!usb_urb_dir_in(urb))
169 memcpy(temp->data, urb->transfer_buffer,
170 urb->transfer_buffer_length);
172 urb->transfer_buffer = temp->data;
173 urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
178 static int tegra_ehci_map_urb_for_dma(struct usb_hcd *hcd,
179 struct urb *urb, gfp_t mem_flags)
183 ret = alloc_align_buffer(urb, mem_flags, hcd);
187 ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
190 free_align_buffer(urb, hcd);
195 static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd,
198 usb_hcd_unmap_urb_for_dma(hcd, urb);
199 free_align_buffer(urb, hcd);
202 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
203 static void tegra_ehci_boost_cpu_frequency_work(struct work_struct *work)
205 struct tegra_ehci_hcd *tegra = container_of(work,
206 struct tegra_ehci_hcd, boost_cpu_freq_work.work);
207 if (tegra->cpu_boost_in_work) {
208 tegra->boost_requested = true;
209 if (tegra->boost_enable)
210 pm_qos_update_request(
211 &tegra->boost_cpu_freq_req,
212 (s32)CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ * 1000);
217 static irqreturn_t tegra_ehci_irq(struct usb_hcd *hcd)
219 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
220 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
221 irqreturn_t irq_status;
223 spin_lock(&ehci->lock);
224 irq_status = tegra_usb_phy_irq(tegra->phy);
225 if (irq_status == IRQ_NONE) {
226 spin_unlock(&ehci->lock);
229 if (tegra_usb_phy_pmc_wakeup(tegra->phy)) {
230 ehci_dbg(ehci, "pmc interrupt detected\n");
231 wake_lock_timeout(&tegra->ehci_wake_lock, HZ);
232 usb_hcd_resume_root_hub(hcd);
233 spin_unlock(&ehci->lock);
236 spin_unlock(&ehci->lock);
238 EHCI_DBG("%s() cmd = 0x%x, int_sts = 0x%x, portsc = 0x%x\n", __func__,
239 ehci_readl(ehci, &ehci->regs->command),
240 ehci_readl(ehci, &ehci->regs->status),
241 ehci_readl(ehci, &ehci->regs->port_status[0]));
243 irq_status = ehci_irq(hcd);
245 if (ehci->controller_remote_wakeup) {
246 ehci->controller_remote_wakeup = false;
247 tegra_usb_phy_pre_resume(tegra->phy, true);
248 tegra->port_resuming = 1;
254 static int tegra_ehci_hub_control(
263 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
264 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
266 u32 __iomem *status_reg;
268 if (!tegra_usb_phy_hw_accessible(tegra->phy)) {
270 memset(buf, 0, wLength);
274 /* Do tegra phy specific actions based on the type request */
277 if (tegra->port_resuming) {
279 int delay = ehci->reset_done[wIndex-1] - jiffies;
280 /* Sometimes it seems we get called too soon... In that case, wait.*/
282 ehci_dbg(ehci, "GetPortStatus called too soon, waiting %dms...\n", delay);
283 mdelay(jiffies_to_msecs(delay));
285 status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1];
286 /* Ensure the port PORT_SUSPEND and PORT_RESUME has cleared */
287 if (handshake(ehci, status_reg, (PORT_SUSPEND | PORT_RESUME), 0, 25000)) {
288 EHCI_DBG("%s: timeout waiting for SUSPEND to clear\n", __func__);
290 tegra_usb_phy_post_resume(tegra->phy);
291 tegra->port_resuming = 0;
292 /* If run bit is not set by now enable it */
293 cmd = ehci_readl(ehci, &ehci->regs->command);
294 if (!(cmd & CMD_RUN)) {
296 ehci->command |= CMD_RUN;
297 ehci_writel(ehci, cmd, &ehci->regs->command);
299 /* Now we can safely re-enable irqs */
300 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
303 case ClearPortFeature:
304 if (wValue == USB_PORT_FEAT_SUSPEND) {
305 tegra_usb_phy_pre_resume(tegra->phy, false);
306 tegra->port_resuming = 1;
307 } else if (wValue == USB_PORT_FEAT_ENABLE) {
309 temp = ehci_readl(ehci, &ehci->regs->port_status[0]) & ~PORT_RWC_BITS;
310 ehci_writel(ehci, temp & ~PORT_PE, &ehci->regs->port_status[0]);
315 if (wValue == USB_PORT_FEAT_SUSPEND)
316 tegra_usb_phy_pre_suspend(tegra->phy);
320 /* handle ehci hub control request */
321 retval = ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
323 /* do tegra phy specific actions based on the type request */
327 if (wValue == USB_PORT_FEAT_SUSPEND) {
328 tegra_usb_phy_post_suspend(tegra->phy);
329 } else if (wValue == USB_PORT_FEAT_RESET) {
331 tegra_usb_phy_bus_reset(tegra->phy);
332 } else if (wValue == USB_PORT_FEAT_POWER) {
334 tegra_usb_phy_port_power(tegra->phy);
337 case ClearPortFeature:
338 if (wValue == USB_PORT_FEAT_SUSPEND) {
339 /* tegra USB controller needs 25 ms to resume the port */
340 ehci->reset_done[wIndex-1] = jiffies + msecs_to_jiffies(25);
349 static void tegra_ehci_shutdown(struct usb_hcd *hcd)
351 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
352 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
353 struct platform_device *pdev = to_platform_device(hcd->self.controller);
354 struct tegra_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
355 mutex_lock(&tegra->sync_lock);
356 if (tegra_usb_phy_hw_accessible(tegra->phy)) {
357 ehci_silence_controller(ehci);
360 tegra_usb_enable_vbus(tegra->phy, false);
361 mutex_unlock(&tegra->sync_lock);
364 static int tegra_ehci_setup(struct usb_hcd *hcd)
366 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
367 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
369 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
373 /* EHCI registers start at offset 0x100 */
374 ehci->caps = hcd->regs + 0x100;
376 ehci->has_hostpc = tegra->has_hostpc;
377 ehci->broken_hostpc_phcd = true;
379 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
380 ehci->has_hostpc = 1;
382 val = readl(hcd->regs + HOSTPC_REG_OFFSET);
383 val &= ~HOSTPC1_DEVLC_STS;
384 val &= ~HOSTPC1_DEVLC_NYT_ASUS;
385 writel(val, hcd->regs + HOSTPC_REG_OFFSET);
387 /* switch to host mode */
390 retval = ehci_setup(hcd);
394 ehci->controller_remote_wakeup = false;
395 tegra_usb_phy_reset(tegra->phy);
397 #if !defined(CONFIG_ARCH_TEGRA_2x_SOC)
398 if (tegra_platform_is_fpga()) {
399 val = readl(hcd->regs + TEGRA_STREAM_DISABLE);
400 val |= TEGRA_STREAM_DISABLE_OFFSET;
401 writel(val , hcd->regs + TEGRA_STREAM_DISABLE);
410 static int tegra_ehci_bus_suspend(struct usb_hcd *hcd)
412 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
414 EHCI_DBG("%s() BEGIN\n", __func__);
416 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
417 tegra->boost_requested = false;
418 if (tegra->boost_enable
419 && pm_qos_request_active(&tegra->boost_cpu_freq_req))
420 pm_qos_update_request(&tegra->boost_cpu_freq_req,
421 PM_QOS_DEFAULT_VALUE);
422 tegra->cpu_boost_in_work = false;
425 mutex_lock(&tegra->sync_lock);
426 tegra->bus_suspended_fail = false;
427 err = ehci_bus_suspend(hcd);
429 tegra->bus_suspended_fail = true;
431 usb_phy_set_suspend(get_usb_phy(tegra->phy), 1);
432 mutex_unlock(&tegra->sync_lock);
433 EHCI_DBG("%s() END\n", __func__);
438 static int tegra_ehci_bus_resume(struct usb_hcd *hcd)
440 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
442 EHCI_DBG("%s() BEGIN\n", __func__);
444 mutex_lock(&tegra->sync_lock);
445 usb_phy_set_suspend(get_usb_phy(tegra->phy), 0);
446 err = ehci_bus_resume(hcd);
447 mutex_unlock(&tegra->sync_lock);
449 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
450 tegra->boost_requested = true;
451 if (pm_qos_request_active(&tegra->boost_cpu_freq_req)
452 && tegra->boost_enable
453 && (tegra_ehci_port_speed(tegra->ehci) == USB_SPEED_HIGH))
454 pm_qos_update_request(&tegra->boost_cpu_freq_req,
455 (s32)CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ * 1000);
456 tegra->cpu_boost_in_work = false;
458 EHCI_DBG("%s() END\n", __func__);
463 static const struct hc_driver tegra_ehci_hc_driver = {
464 .description = hcd_name,
465 .product_desc = "Tegra EHCI Host Controller",
466 .hcd_priv_size = sizeof(struct ehci_hcd),
467 .flags = HCD_USB2 | HCD_MEMORY,
469 /* standard ehci functions */
472 .urb_enqueue = ehci_urb_enqueue,
473 .urb_dequeue = ehci_urb_dequeue,
474 .endpoint_disable = ehci_endpoint_disable,
475 .endpoint_reset = ehci_endpoint_reset,
476 .get_frame_number = ehci_get_frame,
477 .hub_status_data = ehci_hub_status_data,
478 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
479 .relinquish_port = ehci_relinquish_port,
480 .port_handed_over = ehci_port_handed_over,
482 /* modified ehci functions for tegra */
483 .reset = tegra_ehci_setup,
484 .irq = tegra_ehci_irq,
485 .shutdown = tegra_ehci_shutdown,
486 .map_urb_for_dma = tegra_ehci_map_urb_for_dma,
487 .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma,
488 .hub_control = tegra_ehci_hub_control,
490 .bus_suspend = tegra_ehci_bus_suspend,
491 .bus_resume = tegra_ehci_bus_resume,
495 static u64 tegra_ehci_dma_mask = DMA_BIT_MASK(32);
497 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
498 static ssize_t show_boost_enable(struct device *dev,
499 struct device_attribute *attr,
502 struct tegra_ehci_hcd *tegra = dev_get_drvdata(dev);
503 return scnprintf(buf, PAGE_SIZE, "%s\n",
504 tegra->boost_enable ? "Y" : "N");
508 static ssize_t store_boost_enable(struct device *dev,
509 struct device_attribute *attr,
510 const char *buf, size_t count)
512 struct tegra_ehci_hcd *tegra = dev_get_drvdata(dev);
514 bool old_boost = tegra->boost_enable;
516 if (strtobool(buf, &new_boost) == 0) {
517 tegra->boost_enable = new_boost;
518 if (!old_boost && new_boost
519 && tegra->boost_requested
520 && pm_qos_request_active(&tegra->boost_cpu_freq_req))
521 pm_qos_update_request(
522 &tegra->boost_cpu_freq_req,
523 (s32)CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ * 1000);
524 else if (old_boost && !new_boost
525 && pm_qos_request_active(&tegra->boost_cpu_freq_req))
526 pm_qos_update_request(&tegra->boost_cpu_freq_req,
527 PM_QOS_DEFAULT_VALUE);
531 static DEVICE_ATTR(boost_enable, 0644,
532 show_boost_enable, store_boost_enable);
535 static int tegra_ehci_probe(struct platform_device *pdev)
537 struct resource *res;
539 struct tegra_ehci_hcd *tegra;
540 struct tegra_usb_platform_data *pdata;
543 int instance = pdev->id;
545 /* Right now device-tree probed devices don't get dma_mask set.
546 * Since shared usb code relies on it, set it here for now.
547 * Once we have dma capability bindings this can go away.
549 if (!pdev->dev.dma_mask)
550 pdev->dev.dma_mask = &tegra_ehci_dma_mask;
552 pdata = dev_get_platdata(&pdev->dev);
554 tegra = devm_kzalloc(&pdev->dev, sizeof(struct tegra_ehci_hcd),
557 dev_err(&pdev->dev, "memory alloc failed\n");
561 mutex_init(&tegra->sync_lock);
563 hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev,
564 dev_name(&pdev->dev));
566 dev_err(&pdev->dev, "unable to create HCD\n");
570 platform_set_drvdata(pdev, tegra);
572 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
573 tegra->boost_requested = false;
574 /* Add boost enable/disable knob */
575 tegra->boost_enable = true;
576 err = device_create_file(hcd->self.controller, &dev_attr_boost_enable);
581 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
583 dev_err(&pdev->dev, "failed to get I/O memory\n");
587 hcd->rsrc_start = res->start;
588 hcd->rsrc_len = resource_size(res);
589 hcd->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
591 dev_err(&pdev->dev, "failed to remap I/O memory\n");
596 /* This is pretty ugly and needs to be fixed when we do only
597 * device-tree probing. Old code relies on the platform_device
598 * numbering that we lack for device-tree-instantiated devices.
601 switch (res->start) {
605 case TEGRA_USB2_BASE:
608 case TEGRA_USB3_BASE:
613 dev_err(&pdev->dev, "unknown usb instance\n");
618 irq = platform_get_irq(pdev, 0);
620 dev_err(&pdev->dev, "failed to get IRQ\n");
626 tegra->unaligned_dma_buf_supported = pdata->unaligned_dma_buf_supported;
627 tegra->has_hostpc = pdata->has_hostpc;
629 tegra->phy = tegra_usb_phy_open(pdev);
630 hcd->phy = get_usb_phy(tegra->phy);
631 if (IS_ERR(tegra->phy)) {
632 dev_err(&pdev->dev, "failed to open USB phy\n");
637 err = tegra_usb_phy_power_on(tegra->phy);
639 dev_err(&pdev->dev, "failed to power on the phy\n");
643 err = usb_phy_init(get_usb_phy(tegra->phy));
645 dev_err(&pdev->dev, "failed to init the phy\n");
649 err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_TRIGGER_HIGH);
651 dev_err(&pdev->dev, "Failed to add USB HCD, error=%d\n", err);
655 tegra->ehci = hcd_to_ehci(hcd);
657 if (pdata->port_otg) {
659 devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
660 if (!IS_ERR_OR_NULL(tegra->transceiver))
661 otg_set_host(tegra->transceiver->otg, &hcd->self);
664 tegra_pd_add_device(&pdev->dev);
665 pm_runtime_enable(&pdev->dev);
667 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
668 INIT_DELAYED_WORK(&tegra->boost_cpu_freq_work,
669 tegra_ehci_boost_cpu_frequency_work);
670 pm_qos_add_request(&tegra->boost_cpu_freq_req, PM_QOS_CPU_FREQ_MIN,
671 PM_QOS_DEFAULT_VALUE);
672 schedule_delayed_work(&tegra->boost_cpu_freq_work, 12000);
673 tegra->cpu_boost_in_work = true;
676 wake_lock_init(&tegra->ehci_wake_lock,
677 WAKE_LOCK_SUSPEND, dev_name(&pdev->dev));
682 usb_phy_shutdown(get_usb_phy(tegra->phy));
684 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
685 device_remove_file(hcd->self.controller, &dev_attr_boost_enable);
695 static int tegra_ehci_resume(struct platform_device *pdev)
698 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
699 struct tegra_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
701 err = disable_irq_wake(tegra->irq);
704 "Couldn't disable USB host mode wakeup, irq=%d, "
705 "error=%d\n", tegra->irq, err);
707 if (pdata->u_data.host.turn_off_vbus_on_lp0) {
708 tegra_usb_enable_vbus(tegra->phy, true);
709 tegra_ehci_notify_event(tegra, USB_EVENT_ID);
711 return tegra_usb_phy_power_on(tegra->phy);
714 static int tegra_ehci_suspend(struct platform_device *pdev, pm_message_t state)
716 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
717 struct tegra_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
720 /* bus suspend could have failed because of remote wakeup resume */
721 if (tegra->bus_suspended_fail)
724 err = tegra_usb_phy_power_off(tegra->phy);
727 if (pdata->u_data.host.turn_off_vbus_on_lp0) {
728 tegra_usb_enable_vbus(tegra->phy, false);
729 tegra_usb_phy_pmc_disable(tegra->phy);
732 err = enable_irq_wake(tegra->irq);
735 "Couldn't enable USB host mode wakeup, irq=%d, "
736 "error=%d\n", tegra->irq, err);
743 static int tegra_ehci_remove(struct platform_device *pdev)
745 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
746 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
747 struct usb_device *rhdev = NULL;
748 struct tegra_usb_platform_data *pdata;
749 unsigned long timeout = 0;
751 wake_lock_destroy(&tegra->ehci_wake_lock);
753 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
754 cancel_delayed_work_sync(&tegra->boost_cpu_freq_work);
755 tegra->cpu_boost_in_work = false;
756 pm_qos_remove_request(&tegra->boost_cpu_freq_req);
758 rhdev = hcd->self.root_hub;
759 pdata = dev_get_platdata(&pdev->dev);
761 if (!IS_ERR_OR_NULL(tegra->transceiver))
762 otg_set_host(tegra->transceiver->otg, NULL);
764 /* Make sure phy is powered ON to access USB register */
765 if(!tegra_usb_phy_hw_accessible(tegra->phy))
766 tegra_usb_phy_power_on(tegra->phy);
768 if (pdata->port_otg) {
769 timeout = jiffies + 5 * HZ;
770 /* wait for devices connected to root hub to disconnect*/
771 while (rhdev && usb_hub_find_child(rhdev, 1)) {
772 /* wait for any control packets
773 sent to root hub to complete */
774 if (time_after(jiffies, timeout))
781 #ifdef CONFIG_TEGRA_EHCI_BOOST_CPU_FREQ
782 device_remove_file(hcd->self.controller, &dev_attr_boost_enable);
786 tegra_usb_phy_power_off(tegra->phy);
787 usb_phy_shutdown(get_usb_phy(tegra->phy));
789 mutex_destroy(&tegra->sync_lock);
790 tegra_pd_remove_device(&pdev->dev);
795 static void tegra_ehci_hcd_shutdown(struct platform_device *pdev)
797 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
798 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
800 if (hcd->driver->shutdown)
801 hcd->driver->shutdown(hcd);
804 static struct of_device_id tegra_ehci_of_match[] = {
805 { .compatible = "nvidia,tegra20-ehci", },
809 static struct platform_driver tegra_ehci_driver = {
810 .probe = tegra_ehci_probe,
811 .remove = tegra_ehci_remove,
812 .shutdown = tegra_ehci_hcd_shutdown,
814 .suspend = tegra_ehci_suspend,
815 .resume = tegra_ehci_resume,
819 .of_match_table = tegra_ehci_of_match,