1 /* ehci-msm.c - HSUSB Host Controller Driver Implementation
3 * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
5 * Partly derived from ehci-fsl.c and ehci-hcd.c
6 * Copyright (c) 2000-2004 by David Brownell
7 * Copyright (c) 2005 MontaVista Software
9 * All source code in this file is licensed under the following license except
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, you can find it at http://www.fsf.org
25 #include <linux/platform_device.h>
26 #include <linux/clk.h>
27 #include <linux/err.h>
28 #include <linux/pm_runtime.h>
30 #include <linux/usb/otg.h>
31 #include <linux/usb/msm_hsusb_hw.h>
33 #define MSM_USB_BASE (hcd->regs)
35 static struct otg_transceiver
*otg
;
37 static int ehci_msm_reset(struct usb_hcd
*hcd
)
39 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
42 ehci
->caps
= USB_CAPLENGTH
;
43 ehci
->regs
= USB_CAPLENGTH
+
44 HC_LENGTH(ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
45 dbg_hcs_params(ehci
, "reset");
46 dbg_hcc_params(ehci
, "reset");
48 /* cache the data to minimize the chip reads*/
49 ehci
->hcs_params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
52 ehci
->sbrn
= HCD_USB2
;
54 retval
= ehci_halt(ehci
);
58 /* data structure init */
59 retval
= ehci_init(hcd
);
63 retval
= ehci_reset(ehci
);
67 /* bursts of unspecified length. */
68 writel(0, USB_AHBBURST
);
69 /* Use the AHB transactor */
70 writel(0, USB_AHBMODE
);
71 /* Disable streaming mode and select host mode */
72 writel(0x13, USB_USBMODE
);
74 ehci_port_power(ehci
, 1);
78 static struct hc_driver msm_hc_driver
= {
79 .description
= hcd_name
,
80 .product_desc
= "Qualcomm On-Chip EHCI Host Controller",
81 .hcd_priv_size
= sizeof(struct ehci_hcd
),
84 * generic hardware linkage
87 .flags
= HCD_USB2
| HCD_MEMORY
,
89 .reset
= ehci_msm_reset
,
93 .shutdown
= ehci_shutdown
,
96 * managing i/o requests and associated device resources
98 .urb_enqueue
= ehci_urb_enqueue
,
99 .urb_dequeue
= ehci_urb_dequeue
,
100 .endpoint_disable
= ehci_endpoint_disable
,
101 .endpoint_reset
= ehci_endpoint_reset
,
102 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
107 .get_frame_number
= ehci_get_frame
,
112 .hub_status_data
= ehci_hub_status_data
,
113 .hub_control
= ehci_hub_control
,
114 .relinquish_port
= ehci_relinquish_port
,
115 .port_handed_over
= ehci_port_handed_over
,
120 .bus_suspend
= ehci_bus_suspend
,
121 .bus_resume
= ehci_bus_resume
,
124 static int ehci_msm_probe(struct platform_device
*pdev
)
127 struct resource
*res
;
130 dev_dbg(&pdev
->dev
, "ehci_msm proble\n");
132 hcd
= usb_create_hcd(&msm_hc_driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
134 dev_err(&pdev
->dev
, "Unable to create HCD\n");
138 hcd
->irq
= platform_get_irq(pdev
, 0);
140 dev_err(&pdev
->dev
, "Unable to get IRQ resource\n");
145 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
147 dev_err(&pdev
->dev
, "Unable to get memory resource\n");
152 hcd
->rsrc_start
= res
->start
;
153 hcd
->rsrc_len
= resource_size(res
);
154 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
156 dev_err(&pdev
->dev
, "ioremap failed\n");
162 * OTG driver takes care of PHY initialization, clock management,
163 * powering up VBUS, mapping of registers address space and power
166 otg
= otg_get_transceiver();
168 dev_err(&pdev
->dev
, "unable to find transceiver\n");
173 ret
= otg_set_host(otg
, &hcd
->self
);
175 dev_err(&pdev
->dev
, "unable to register with transceiver\n");
176 goto put_transceiver
;
179 device_init_wakeup(&pdev
->dev
, 1);
181 * OTG device parent of HCD takes care of putting
182 * hardware into low power mode.
184 pm_runtime_no_callbacks(&pdev
->dev
);
185 pm_runtime_enable(&pdev
->dev
);
190 otg_put_transceiver(otg
);
199 static int __devexit
ehci_msm_remove(struct platform_device
*pdev
)
201 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
203 device_init_wakeup(&pdev
->dev
, 0);
204 pm_runtime_disable(&pdev
->dev
);
205 pm_runtime_set_suspended(&pdev
->dev
);
207 otg_set_host(otg
, NULL
);
208 otg_put_transceiver(otg
);
216 static int ehci_msm_pm_suspend(struct device
*dev
)
218 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
219 bool wakeup
= device_may_wakeup(dev
);
221 dev_dbg(dev
, "ehci-msm PM suspend\n");
224 * EHCI helper function has also the same check before manipulating
225 * port wakeup flags. We do check here the same condition before
226 * calling the same helper function to avoid bringing hardware
227 * from Low power mode when there is no need for adjusting port
230 if (hcd
->self
.root_hub
->do_remote_wakeup
&& !wakeup
) {
231 pm_runtime_resume(dev
);
232 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd
),
239 static int ehci_msm_pm_resume(struct device
*dev
)
241 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
243 dev_dbg(dev
, "ehci-msm PM resume\n");
244 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd
));
249 #define ehci_msm_pm_suspend NULL
250 #define ehci_msm_pm_resume NULL
253 static const struct dev_pm_ops ehci_msm_dev_pm_ops
= {
254 .suspend
= ehci_msm_pm_suspend
,
255 .resume
= ehci_msm_pm_resume
,
258 static struct platform_driver ehci_msm_driver
= {
259 .probe
= ehci_msm_probe
,
260 .remove
= __devexit_p(ehci_msm_remove
),
262 .name
= "msm_hsusb_host",
263 .pm
= &ehci_msm_dev_pm_ops
,