blob: 6a866322ab7a7bcc51fe0deb9193f9bd1bec3885 [file] [log] [blame]
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +05301/* ehci-msm.c - HSUSB Host Controller Driver Implementation
2 *
Vijayavardhan Vennapusa5f32d7a2012-03-14 16:30:26 +05303 * Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved.
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +05304 *
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
8 *
9 * All source code in this file is licensed under the following license except
10 * where indicated.
11 *
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.
15 *
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.
19 *
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
23 */
24
25#include <linux/platform_device.h>
26#include <linux/clk.h>
27#include <linux/err.h>
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +053028#include <linux/pm_runtime.h>
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053029
30#include <linux/usb/otg.h>
31#include <linux/usb/msm_hsusb_hw.h>
32
33#define MSM_USB_BASE (hcd->regs)
34
35static struct otg_transceiver *otg;
36
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053037static int ehci_msm_reset(struct usb_hcd *hcd)
38{
39 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
40 int retval;
41
42 ehci->caps = USB_CAPLENGTH;
43 ehci->regs = USB_CAPLENGTH +
Jan Anderssonc4301312011-05-03 20:11:57 +020044 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Pavankumar Kondeti18f53462011-02-18 17:30:11 +053045 dbg_hcs_params(ehci, "reset");
46 dbg_hcc_params(ehci, "reset");
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053047
48 /* cache the data to minimize the chip reads*/
49 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
50
51 hcd->has_tt = 1;
52 ehci->sbrn = HCD_USB2;
53
Matthieu CASTET5c8d61b2011-02-15 18:41:54 +010054 retval = ehci_halt(ehci);
55 if (retval)
56 return retval;
57
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053058 /* data structure init */
59 retval = ehci_init(hcd);
60 if (retval)
61 return retval;
62
63 retval = ehci_reset(ehci);
64 if (retval)
65 return retval;
66
67 /* bursts of unspecified length. */
68 writel(0, USB_AHBBURST);
69 /* Use the AHB transactor */
Vijayavardhan Vennapusa5f32d7a2012-03-14 16:30:26 +053070 writel_relaxed(0x08, USB_AHBMODE);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053071 /* Disable streaming mode and select host mode */
72 writel(0x13, USB_USBMODE);
73
74 ehci_port_power(ehci, 1);
75 return 0;
76}
77
78static 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),
82
83 /*
84 * generic hardware linkage
85 */
86 .irq = ehci_irq,
87 .flags = HCD_USB2 | HCD_MEMORY,
88
89 .reset = ehci_msm_reset,
Matthieu CASTET5c8d61b2011-02-15 18:41:54 +010090 .start = ehci_run,
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053091
92 .stop = ehci_stop,
93 .shutdown = ehci_shutdown,
94
95 /*
96 * managing i/o requests and associated device resources
97 */
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,
103
104 /*
105 * scheduling support
106 */
107 .get_frame_number = ehci_get_frame,
108
109 /*
110 * root hub support
111 */
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,
116
117 /*
118 * PM support
119 */
120 .bus_suspend = ehci_bus_suspend,
121 .bus_resume = ehci_bus_resume,
122};
123
124static int ehci_msm_probe(struct platform_device *pdev)
125{
126 struct usb_hcd *hcd;
127 struct resource *res;
128 int ret;
129
130 dev_dbg(&pdev->dev, "ehci_msm proble\n");
131
132 hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
133 if (!hcd) {
134 dev_err(&pdev->dev, "Unable to create HCD\n");
135 return -ENOMEM;
136 }
137
138 hcd->irq = platform_get_irq(pdev, 0);
139 if (hcd->irq < 0) {
140 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
141 ret = hcd->irq;
142 goto put_hcd;
143 }
144
145 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
146 if (!res) {
147 dev_err(&pdev->dev, "Unable to get memory resource\n");
148 ret = -ENODEV;
149 goto put_hcd;
150 }
151
152 hcd->rsrc_start = res->start;
153 hcd->rsrc_len = resource_size(res);
154 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
155 if (!hcd->regs) {
156 dev_err(&pdev->dev, "ioremap failed\n");
157 ret = -ENOMEM;
158 goto put_hcd;
159 }
160
161 /*
162 * OTG driver takes care of PHY initialization, clock management,
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530163 * powering up VBUS, mapping of registers address space and power
164 * management.
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530165 */
166 otg = otg_get_transceiver();
167 if (!otg) {
168 dev_err(&pdev->dev, "unable to find transceiver\n");
169 ret = -ENODEV;
170 goto unmap;
171 }
172
173 ret = otg_set_host(otg, &hcd->self);
174 if (ret < 0) {
175 dev_err(&pdev->dev, "unable to register with transceiver\n");
176 goto put_transceiver;
177 }
178
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530179 hcd_to_ehci(hcd)->transceiver = otg;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530180 device_init_wakeup(&pdev->dev, 1);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530181 pm_runtime_enable(&pdev->dev);
182
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530183 return 0;
184
185put_transceiver:
186 otg_put_transceiver(otg);
187unmap:
188 iounmap(hcd->regs);
189put_hcd:
190 usb_put_hcd(hcd);
191
192 return ret;
193}
194
195static int __devexit ehci_msm_remove(struct platform_device *pdev)
196{
197 struct usb_hcd *hcd = platform_get_drvdata(pdev);
198
199 device_init_wakeup(&pdev->dev, 0);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530200 pm_runtime_disable(&pdev->dev);
201 pm_runtime_set_suspended(&pdev->dev);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530202
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530203 hcd_to_ehci(hcd)->transceiver = NULL;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530204 otg_set_host(otg, NULL);
205 otg_put_transceiver(otg);
206
207 usb_put_hcd(hcd);
208
209 return 0;
210}
211
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530212#ifdef CONFIG_PM_RUNTIME
213static int ehci_msm_runtime_idle(struct device *dev)
214{
215 dev_dbg(dev, "ehci runtime idle\n");
216 return 0;
217}
218
219static int ehci_msm_runtime_suspend(struct device *dev)
220{
221 dev_dbg(dev, "ehci runtime suspend\n");
222 /*
223 * Notify OTG about suspend. It takes care of
224 * putting the hardware in LPM.
225 */
226 return otg_set_suspend(otg, 1);
227}
228
229static int ehci_msm_runtime_resume(struct device *dev)
230{
231 dev_dbg(dev, "ehci runtime resume\n");
232 return otg_set_suspend(otg, 0);
233}
234#endif
235
236#ifdef CONFIG_PM_SLEEP
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530237static int ehci_msm_pm_suspend(struct device *dev)
238{
239 struct usb_hcd *hcd = dev_get_drvdata(dev);
240 bool wakeup = device_may_wakeup(dev);
241
242 dev_dbg(dev, "ehci-msm PM suspend\n");
243
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700244 if (!hcd->rh_registered)
245 return 0;
246
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530247 /*
248 * EHCI helper function has also the same check before manipulating
249 * port wakeup flags. We do check here the same condition before
250 * calling the same helper function to avoid bringing hardware
251 * from Low power mode when there is no need for adjusting port
252 * wakeup flags.
253 */
254 if (hcd->self.root_hub->do_remote_wakeup && !wakeup) {
255 pm_runtime_resume(dev);
256 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
257 wakeup);
258 }
259
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530260 return otg_set_suspend(otg, 1);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530261}
262
263static int ehci_msm_pm_resume(struct device *dev)
264{
265 struct usb_hcd *hcd = dev_get_drvdata(dev);
266
267 dev_dbg(dev, "ehci-msm PM resume\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700268
269 if (!hcd->rh_registered)
270 return 0;
271
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530272 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
273
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530274 return otg_set_suspend(otg, 0);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530275}
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530276#endif
277
278static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530279 SET_SYSTEM_SLEEP_PM_OPS(ehci_msm_pm_suspend, ehci_msm_pm_resume)
280 SET_RUNTIME_PM_OPS(ehci_msm_runtime_suspend, ehci_msm_runtime_resume,
281 ehci_msm_runtime_idle)
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530282};
283
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530284static struct platform_driver ehci_msm_driver = {
285 .probe = ehci_msm_probe,
286 .remove = __devexit_p(ehci_msm_remove),
287 .driver = {
288 .name = "msm_hsusb_host",
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530289 .pm = &ehci_msm_dev_pm_ops,
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530290 },
291};