USB: EHCI: make ehci-atmel a separate driver
[linux-2.6-block.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
25#include <linux/platform_device.h>
26#include <linux/clk.h>
27#include <linux/err.h>
8bb6a164 28#include <linux/pm_runtime.h>
b0848aea
PK
29
30#include <linux/usb/otg.h>
31#include <linux/usb/msm_hsusb_hw.h>
32
33#define MSM_USB_BASE (hcd->regs)
34
b96d3b08 35static struct usb_phy *phy;
b0848aea 36
b0848aea
PK
37static 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;
b0848aea 43 hcd->has_tt = 1;
b0848aea 44
2cb30bb1 45 retval = ehci_setup(hcd);
b0848aea
PK
46 if (retval)
47 return retval;
48
49 /* bursts of unspecified length. */
50 writel(0, USB_AHBBURST);
51 /* Use the AHB transactor */
52 writel(0, USB_AHBMODE);
53 /* Disable streaming mode and select host mode */
54 writel(0x13, USB_USBMODE);
55
b0848aea
PK
56 return 0;
57}
58
59static struct hc_driver msm_hc_driver = {
60 .description = hcd_name,
61 .product_desc = "Qualcomm On-Chip EHCI Host Controller",
62 .hcd_priv_size = sizeof(struct ehci_hcd),
63
64 /*
65 * generic hardware linkage
66 */
67 .irq = ehci_irq,
68 .flags = HCD_USB2 | HCD_MEMORY,
69
70 .reset = ehci_msm_reset,
5c8d61bf 71 .start = ehci_run,
b0848aea
PK
72
73 .stop = ehci_stop,
74 .shutdown = ehci_shutdown,
75
76 /*
77 * managing i/o requests and associated device resources
78 */
79 .urb_enqueue = ehci_urb_enqueue,
80 .urb_dequeue = ehci_urb_dequeue,
81 .endpoint_disable = ehci_endpoint_disable,
82 .endpoint_reset = ehci_endpoint_reset,
83 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
84
85 /*
86 * scheduling support
87 */
88 .get_frame_number = ehci_get_frame,
89
90 /*
91 * root hub support
92 */
93 .hub_status_data = ehci_hub_status_data,
94 .hub_control = ehci_hub_control,
95 .relinquish_port = ehci_relinquish_port,
96 .port_handed_over = ehci_port_handed_over,
97
98 /*
99 * PM support
100 */
101 .bus_suspend = ehci_bus_suspend,
102 .bus_resume = ehci_bus_resume,
103};
104
105static int ehci_msm_probe(struct platform_device *pdev)
106{
107 struct usb_hcd *hcd;
108 struct resource *res;
109 int ret;
110
111 dev_dbg(&pdev->dev, "ehci_msm proble\n");
112
113 hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
114 if (!hcd) {
115 dev_err(&pdev->dev, "Unable to create HCD\n");
116 return -ENOMEM;
117 }
118
119 hcd->irq = platform_get_irq(pdev, 0);
120 if (hcd->irq < 0) {
121 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
122 ret = hcd->irq;
123 goto put_hcd;
124 }
125
126 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
127 if (!res) {
128 dev_err(&pdev->dev, "Unable to get memory resource\n");
129 ret = -ENODEV;
130 goto put_hcd;
131 }
132
133 hcd->rsrc_start = res->start;
134 hcd->rsrc_len = resource_size(res);
df5eb3ff 135 hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
b0848aea
PK
136 if (!hcd->regs) {
137 dev_err(&pdev->dev, "ioremap failed\n");
138 ret = -ENOMEM;
139 goto put_hcd;
140 }
141
142 /*
143 * OTG driver takes care of PHY initialization, clock management,
8bb6a164
PK
144 * powering up VBUS, mapping of registers address space and power
145 * management.
b0848aea 146 */
df5eb3ff 147 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
e299bd93 148 if (IS_ERR(phy)) {
b0848aea
PK
149 dev_err(&pdev->dev, "unable to find transceiver\n");
150 ret = -ENODEV;
df5eb3ff 151 goto put_hcd;
b0848aea
PK
152 }
153
6e13c650 154 ret = otg_set_host(phy->otg, &hcd->self);
b0848aea
PK
155 if (ret < 0) {
156 dev_err(&pdev->dev, "unable to register with transceiver\n");
df5eb3ff 157 goto put_hcd;
b0848aea
PK
158 }
159
160 device_init_wakeup(&pdev->dev, 1);
8bb6a164
PK
161 /*
162 * OTG device parent of HCD takes care of putting
163 * hardware into low power mode.
164 */
165 pm_runtime_no_callbacks(&pdev->dev);
166 pm_runtime_enable(&pdev->dev);
167
b0848aea
PK
168 return 0;
169
b0848aea
PK
170put_hcd:
171 usb_put_hcd(hcd);
172
173 return ret;
174}
175
fb4e98ab 176static int ehci_msm_remove(struct platform_device *pdev)
b0848aea
PK
177{
178 struct usb_hcd *hcd = platform_get_drvdata(pdev);
179
180 device_init_wakeup(&pdev->dev, 0);
8bb6a164
PK
181 pm_runtime_disable(&pdev->dev);
182 pm_runtime_set_suspended(&pdev->dev);
b0848aea 183
6e13c650 184 otg_set_host(phy->otg, NULL);
b0848aea
PK
185
186 usb_put_hcd(hcd);
187
188 return 0;
189}
190
8bb6a164
PK
191#ifdef CONFIG_PM
192static int ehci_msm_pm_suspend(struct device *dev)
193{
194 struct usb_hcd *hcd = dev_get_drvdata(dev);
c5cf9212 195 bool do_wakeup = device_may_wakeup(dev);
8bb6a164
PK
196
197 dev_dbg(dev, "ehci-msm PM suspend\n");
198
c5cf9212 199 return ehci_suspend(hcd, do_wakeup);
8bb6a164
PK
200}
201
202static int ehci_msm_pm_resume(struct device *dev)
203{
204 struct usb_hcd *hcd = dev_get_drvdata(dev);
205
206 dev_dbg(dev, "ehci-msm PM resume\n");
c5cf9212 207 ehci_resume(hcd, false);
8bb6a164
PK
208
209 return 0;
210}
211#else
212#define ehci_msm_pm_suspend NULL
213#define ehci_msm_pm_resume NULL
214#endif
215
216static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
217 .suspend = ehci_msm_pm_suspend,
218 .resume = ehci_msm_pm_resume,
219};
220
b0848aea
PK
221static struct platform_driver ehci_msm_driver = {
222 .probe = ehci_msm_probe,
7690417d 223 .remove = ehci_msm_remove,
b0848aea
PK
224 .driver = {
225 .name = "msm_hsusb_host",
8bb6a164 226 .pm = &ehci_msm_dev_pm_ops,
b0848aea
PK
227 },
228};