blob: 66363eb96bed4300fd6ca940bd25abe9f4b4c9e0 [file] [log] [blame]
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +05301/* ehci-msm.c - HSUSB Host Controller Driver Implementation
2 *
Duy Truonge833aca2013-02-12 13:35:08 -08003 * Copyright (c) 2008-2012, The Linux Foundation. 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
Heikki Krogerusb96d3b02012-02-13 13:24:18 +020035static struct usb_phy *phy;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053036
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;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053043 hcd->has_tt = 1;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053044
Matthieu CASTET2cb30bb2011-07-02 20:59:46 +020045 retval = ehci_setup(hcd);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053046 if (retval)
47 return retval;
48
49 /* bursts of unspecified length. */
50 writel(0, USB_AHBBURST);
51 /* Use the AHB transactor */
Vijayavardhan Vennapusa5f32d7a2012-03-14 16:30:26 +053052 writel_relaxed(0x08, USB_AHBMODE);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053053 /* Disable streaming mode and select host mode */
54 writel(0x13, USB_USBMODE);
55
56 ehci_port_power(ehci, 1);
57 return 0;
58}
59
60static struct hc_driver msm_hc_driver = {
61 .description = hcd_name,
62 .product_desc = "Qualcomm On-Chip EHCI Host Controller",
63 .hcd_priv_size = sizeof(struct ehci_hcd),
64
65 /*
66 * generic hardware linkage
67 */
68 .irq = ehci_irq,
69 .flags = HCD_USB2 | HCD_MEMORY,
70
71 .reset = ehci_msm_reset,
Matthieu CASTET5c8d61b2011-02-15 18:41:54 +010072 .start = ehci_run,
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +053073
74 .stop = ehci_stop,
75 .shutdown = ehci_shutdown,
76
77 /*
78 * managing i/o requests and associated device resources
79 */
80 .urb_enqueue = ehci_urb_enqueue,
81 .urb_dequeue = ehci_urb_dequeue,
82 .endpoint_disable = ehci_endpoint_disable,
83 .endpoint_reset = ehci_endpoint_reset,
84 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
85
86 /*
87 * scheduling support
88 */
89 .get_frame_number = ehci_get_frame,
90
91 /*
92 * root hub support
93 */
94 .hub_status_data = ehci_hub_status_data,
95 .hub_control = ehci_hub_control,
96 .relinquish_port = ehci_relinquish_port,
97 .port_handed_over = ehci_port_handed_over,
98
99 /*
100 * PM support
101 */
102 .bus_suspend = ehci_bus_suspend,
103 .bus_resume = ehci_bus_resume,
104};
105
106static int ehci_msm_probe(struct platform_device *pdev)
107{
108 struct usb_hcd *hcd;
109 struct resource *res;
110 int ret;
111
112 dev_dbg(&pdev->dev, "ehci_msm proble\n");
113
114 hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
115 if (!hcd) {
116 dev_err(&pdev->dev, "Unable to create HCD\n");
117 return -ENOMEM;
118 }
119
120 hcd->irq = platform_get_irq(pdev, 0);
121 if (hcd->irq < 0) {
122 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
123 ret = hcd->irq;
124 goto put_hcd;
125 }
126
127 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
128 if (!res) {
129 dev_err(&pdev->dev, "Unable to get memory resource\n");
130 ret = -ENODEV;
131 goto put_hcd;
132 }
133
134 hcd->rsrc_start = res->start;
135 hcd->rsrc_len = resource_size(res);
136 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
137 if (!hcd->regs) {
138 dev_err(&pdev->dev, "ioremap failed\n");
139 ret = -ENOMEM;
140 goto put_hcd;
141 }
142
143 /*
144 * OTG driver takes care of PHY initialization, clock management,
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530145 * powering up VBUS, mapping of registers address space and power
146 * management.
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530147 */
Heikki Krogerusb96d3b02012-02-13 13:24:18 +0200148 phy = usb_get_transceiver();
149 if (!phy) {
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530150 dev_err(&pdev->dev, "unable to find transceiver\n");
151 ret = -ENODEV;
152 goto unmap;
153 }
154
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200155 ret = otg_set_host(phy->otg, &hcd->self);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530156 if (ret < 0) {
157 dev_err(&pdev->dev, "unable to register with transceiver\n");
158 goto put_transceiver;
159 }
160
Steve Mucklef132c6c2012-06-06 18:30:57 -0700161 hcd_to_ehci(hcd)->transceiver = phy;
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530162 device_init_wakeup(&pdev->dev, 1);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530163 pm_runtime_enable(&pdev->dev);
164
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530165 return 0;
166
167put_transceiver:
Heikki Krogerusb96d3b02012-02-13 13:24:18 +0200168 usb_put_transceiver(phy);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530169unmap:
170 iounmap(hcd->regs);
171put_hcd:
172 usb_put_hcd(hcd);
173
174 return ret;
175}
176
177static int __devexit ehci_msm_remove(struct platform_device *pdev)
178{
179 struct usb_hcd *hcd = platform_get_drvdata(pdev);
180
181 device_init_wakeup(&pdev->dev, 0);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530182 pm_runtime_disable(&pdev->dev);
183 pm_runtime_set_suspended(&pdev->dev);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530184
Vijayavardhan Vennapusaa3152032012-03-05 16:29:30 +0530185 hcd_to_ehci(hcd)->transceiver = NULL;
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200186 otg_set_host(phy->otg, NULL);
Heikki Krogerusb96d3b02012-02-13 13:24:18 +0200187 usb_put_transceiver(phy);
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530188
189 usb_put_hcd(hcd);
190
191 return 0;
192}
193
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530194#ifdef CONFIG_PM_RUNTIME
195static int ehci_msm_runtime_idle(struct device *dev)
196{
197 dev_dbg(dev, "ehci runtime idle\n");
198 return 0;
199}
200
201static int ehci_msm_runtime_suspend(struct device *dev)
202{
203 dev_dbg(dev, "ehci runtime suspend\n");
204 /*
205 * Notify OTG about suspend. It takes care of
206 * putting the hardware in LPM.
207 */
Steve Mucklef132c6c2012-06-06 18:30:57 -0700208 return usb_phy_set_suspend(phy, 1);
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530209}
210
211static int ehci_msm_runtime_resume(struct device *dev)
212{
213 dev_dbg(dev, "ehci runtime resume\n");
Steve Mucklef132c6c2012-06-06 18:30:57 -0700214 return usb_phy_set_suspend(phy, 0);
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530215}
216#endif
217
218#ifdef CONFIG_PM_SLEEP
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530219static int ehci_msm_pm_suspend(struct device *dev)
220{
221 struct usb_hcd *hcd = dev_get_drvdata(dev);
222 bool wakeup = device_may_wakeup(dev);
223
224 dev_dbg(dev, "ehci-msm PM suspend\n");
225
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700226 if (!hcd->rh_registered)
227 return 0;
228
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530229 /*
230 * EHCI helper function has also the same check before manipulating
231 * port wakeup flags. We do check here the same condition before
232 * calling the same helper function to avoid bringing hardware
233 * from Low power mode when there is no need for adjusting port
234 * wakeup flags.
235 */
236 if (hcd->self.root_hub->do_remote_wakeup && !wakeup) {
237 pm_runtime_resume(dev);
238 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
239 wakeup);
240 }
241
Steve Mucklef132c6c2012-06-06 18:30:57 -0700242 return usb_phy_set_suspend(phy, 1);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530243}
244
245static int ehci_msm_pm_resume(struct device *dev)
246{
247 struct usb_hcd *hcd = dev_get_drvdata(dev);
248
249 dev_dbg(dev, "ehci-msm PM resume\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250
251 if (!hcd->rh_registered)
252 return 0;
253
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530254 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
255
Steve Mucklef132c6c2012-06-06 18:30:57 -0700256 return usb_phy_set_suspend(phy, 0);
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530257}
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530258#endif
259
260static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
Pavankumar Kondeti8be99cf2011-08-04 10:48:08 +0530261 SET_SYSTEM_SLEEP_PM_OPS(ehci_msm_pm_suspend, ehci_msm_pm_resume)
262 SET_RUNTIME_PM_OPS(ehci_msm_runtime_suspend, ehci_msm_runtime_resume,
263 ehci_msm_runtime_idle)
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530264};
265
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530266static struct platform_driver ehci_msm_driver = {
267 .probe = ehci_msm_probe,
268 .remove = __devexit_p(ehci_msm_remove),
269 .driver = {
270 .name = "msm_hsusb_host",
Pavankumar Kondeti8bb6a162010-12-07 17:53:57 +0530271 .pm = &ehci_msm_dev_pm_ops,
Pavankumar Kondetib0848ae2010-12-07 17:53:56 +0530272 },
273};