xhci: rework cycle bit checking for new dequeue pointers
[deliverable/linux.git] / drivers / usb / host / ehci-msm.c
CommitLineData
b0848aea
PK
1/* ehci-msm.c - HSUSB Host Controller Driver Implementation
2 *
18f53461 3 * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
b0848aea
PK
4 *
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
b0848aea
PK
25#include <linux/clk.h>
26#include <linux/err.h>
8c68e84f
MG
27#include <linux/io.h>
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/platform_device.h>
8bb6a164 31#include <linux/pm_runtime.h>
b0848aea
PK
32#include <linux/usb/otg.h>
33#include <linux/usb/msm_hsusb_hw.h>
8c68e84f
MG
34#include <linux/usb.h>
35#include <linux/usb/hcd.h>
36
37#include "ehci.h"
b0848aea
PK
38
39#define MSM_USB_BASE (hcd->regs)
40
8c68e84f
MG
41#define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller"
42
43static const char hcd_name[] = "ehci-msm";
44static struct hc_driver __read_mostly msm_hc_driver;
b0848aea 45
b0848aea
PK
46static int ehci_msm_reset(struct usb_hcd *hcd)
47{
48 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
49 int retval;
50
51 ehci->caps = USB_CAPLENGTH;
b0848aea 52 hcd->has_tt = 1;
b0848aea 53
2cb30bb1 54 retval = ehci_setup(hcd);
b0848aea
PK
55 if (retval)
56 return retval;
57
58 /* bursts of unspecified length. */
59 writel(0, USB_AHBBURST);
60 /* Use the AHB transactor */
61 writel(0, USB_AHBMODE);
62 /* Disable streaming mode and select host mode */
63 writel(0x13, USB_USBMODE);
64
b0848aea
PK
65 return 0;
66}
67
b0848aea
PK
68static int ehci_msm_probe(struct platform_device *pdev)
69{
70 struct usb_hcd *hcd;
71 struct resource *res;
e4f0da05 72 struct usb_phy *phy;
b0848aea
PK
73 int ret;
74
75 dev_dbg(&pdev->dev, "ehci_msm proble\n");
76
77 hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
78 if (!hcd) {
79 dev_err(&pdev->dev, "Unable to create HCD\n");
80 return -ENOMEM;
81 }
82
83 hcd->irq = platform_get_irq(pdev, 0);
84 if (hcd->irq < 0) {
85 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
86 ret = hcd->irq;
87 goto put_hcd;
88 }
89
90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
91 if (!res) {
92 dev_err(&pdev->dev, "Unable to get memory resource\n");
93 ret = -ENODEV;
94 goto put_hcd;
95 }
96
97 hcd->rsrc_start = res->start;
98 hcd->rsrc_len = resource_size(res);
70843f62
VG
99 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
100 if (IS_ERR(hcd->regs)) {
101 ret = PTR_ERR(hcd->regs);
b0848aea
PK
102 goto put_hcd;
103 }
104
105 /*
106 * OTG driver takes care of PHY initialization, clock management,
8bb6a164
PK
107 * powering up VBUS, mapping of registers address space and power
108 * management.
b0848aea 109 */
0fc924bd
II
110 if (pdev->dev.of_node)
111 phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
112 else
113 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
114
e299bd93 115 if (IS_ERR(phy)) {
b0848aea 116 dev_err(&pdev->dev, "unable to find transceiver\n");
0fc924bd 117 ret = -EPROBE_DEFER;
df5eb3ff 118 goto put_hcd;
b0848aea
PK
119 }
120
6e13c650 121 ret = otg_set_host(phy->otg, &hcd->self);
b0848aea
PK
122 if (ret < 0) {
123 dev_err(&pdev->dev, "unable to register with transceiver\n");
df5eb3ff 124 goto put_hcd;
b0848aea
PK
125 }
126
e4f0da05 127 hcd->phy = phy;
b0848aea 128 device_init_wakeup(&pdev->dev, 1);
8bb6a164
PK
129 /*
130 * OTG device parent of HCD takes care of putting
131 * hardware into low power mode.
132 */
133 pm_runtime_no_callbacks(&pdev->dev);
134 pm_runtime_enable(&pdev->dev);
135
8c68e84f
MG
136 /* FIXME: need to call usb_add_hcd() here? */
137
b0848aea
PK
138 return 0;
139
b0848aea
PK
140put_hcd:
141 usb_put_hcd(hcd);
142
143 return ret;
144}
145
fb4e98ab 146static int ehci_msm_remove(struct platform_device *pdev)
b0848aea
PK
147{
148 struct usb_hcd *hcd = platform_get_drvdata(pdev);
149
150 device_init_wakeup(&pdev->dev, 0);
8bb6a164
PK
151 pm_runtime_disable(&pdev->dev);
152 pm_runtime_set_suspended(&pdev->dev);
b0848aea 153
e4f0da05 154 otg_set_host(hcd->phy->otg, NULL);
b0848aea 155
8c68e84f
MG
156 /* FIXME: need to call usb_remove_hcd() here? */
157
b0848aea
PK
158 usb_put_hcd(hcd);
159
160 return 0;
161}
162
8bb6a164
PK
163#ifdef CONFIG_PM
164static int ehci_msm_pm_suspend(struct device *dev)
165{
166 struct usb_hcd *hcd = dev_get_drvdata(dev);
c5cf9212 167 bool do_wakeup = device_may_wakeup(dev);
8bb6a164
PK
168
169 dev_dbg(dev, "ehci-msm PM suspend\n");
170
c5cf9212 171 return ehci_suspend(hcd, do_wakeup);
8bb6a164
PK
172}
173
174static int ehci_msm_pm_resume(struct device *dev)
175{
176 struct usb_hcd *hcd = dev_get_drvdata(dev);
177
178 dev_dbg(dev, "ehci-msm PM resume\n");
c5cf9212 179 ehci_resume(hcd, false);
8bb6a164
PK
180
181 return 0;
182}
183#else
184#define ehci_msm_pm_suspend NULL
185#define ehci_msm_pm_resume NULL
186#endif
187
188static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
189 .suspend = ehci_msm_pm_suspend,
190 .resume = ehci_msm_pm_resume,
191};
192
3587fb3b 193static const struct of_device_id msm_ehci_dt_match[] = {
0fc924bd
II
194 { .compatible = "qcom,ehci-host", },
195 {}
196};
197MODULE_DEVICE_TABLE(of, msm_ehci_dt_match);
198
b0848aea
PK
199static struct platform_driver ehci_msm_driver = {
200 .probe = ehci_msm_probe,
7690417d 201 .remove = ehci_msm_remove,
b0848aea
PK
202 .driver = {
203 .name = "msm_hsusb_host",
8bb6a164 204 .pm = &ehci_msm_dev_pm_ops,
0fc924bd 205 .of_match_table = msm_ehci_dt_match,
b0848aea
PK
206 },
207};
8c68e84f
MG
208
209static const struct ehci_driver_overrides msm_overrides __initdata = {
210 .reset = ehci_msm_reset,
211};
212
213static int __init ehci_msm_init(void)
214{
215 if (usb_disabled())
216 return -ENODEV;
217
218 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
219 ehci_init_driver(&msm_hc_driver, &msm_overrides);
220 return platform_driver_register(&ehci_msm_driver);
221}
222module_init(ehci_msm_init);
223
224static void __exit ehci_msm_cleanup(void)
225{
226 platform_driver_unregister(&ehci_msm_driver);
227}
228module_exit(ehci_msm_cleanup);
229
230MODULE_DESCRIPTION(DRIVER_DESC);
231MODULE_ALIAS("platform:msm-ehci");
232MODULE_LICENSE("GPL");
This page took 0.350088 seconds and 5 git commands to generate.