usb: renesas_usbhs: shrink spin lock area
[pandora-kernel.git] / drivers / usb / host / ehci-msm.c
1 /* ehci-msm.c - HSUSB Host Controller Driver Implementation
2  *
3  * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
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>
28 #include <linux/pm_runtime.h>
29
30 #include <linux/usb/otg.h>
31 #include <linux/usb/msm_hsusb_hw.h>
32
33 #define MSM_USB_BASE (hcd->regs)
34
35 static struct otg_transceiver *otg;
36
37 static 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 +
44                 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
45         dbg_hcs_params(ehci, "reset");
46         dbg_hcc_params(ehci, "reset");
47
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
54         retval = ehci_halt(ehci);
55         if (retval)
56                 return retval;
57
58         /* 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 */
70         writel(0, USB_AHBMODE);
71         /* Disable streaming mode and select host mode */
72         writel(0x13, USB_USBMODE);
73
74         ehci_port_power(ehci, 1);
75         return 0;
76 }
77
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),
82
83         /*
84          * generic hardware linkage
85          */
86         .irq                    = ehci_irq,
87         .flags                  = HCD_USB2 | HCD_MEMORY,
88
89         .reset                  = ehci_msm_reset,
90         .start                  = ehci_run,
91
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
124 static 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,
163          * powering up VBUS, mapping of registers address space and power
164          * management.
165          */
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
179         device_init_wakeup(&pdev->dev, 1);
180         /*
181          * OTG device parent of HCD takes care of putting
182          * hardware into low power mode.
183          */
184         pm_runtime_no_callbacks(&pdev->dev);
185         pm_runtime_enable(&pdev->dev);
186
187         return 0;
188
189 put_transceiver:
190         otg_put_transceiver(otg);
191 unmap:
192         iounmap(hcd->regs);
193 put_hcd:
194         usb_put_hcd(hcd);
195
196         return ret;
197 }
198
199 static int __devexit ehci_msm_remove(struct platform_device *pdev)
200 {
201         struct usb_hcd *hcd = platform_get_drvdata(pdev);
202
203         device_init_wakeup(&pdev->dev, 0);
204         pm_runtime_disable(&pdev->dev);
205         pm_runtime_set_suspended(&pdev->dev);
206
207         otg_set_host(otg, NULL);
208         otg_put_transceiver(otg);
209
210         usb_put_hcd(hcd);
211
212         return 0;
213 }
214
215 #ifdef CONFIG_PM
216 static int ehci_msm_pm_suspend(struct device *dev)
217 {
218         struct usb_hcd *hcd = dev_get_drvdata(dev);
219         bool wakeup = device_may_wakeup(dev);
220
221         dev_dbg(dev, "ehci-msm PM suspend\n");
222
223         /*
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
228          * wakeup flags.
229          */
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),
233                                 wakeup);
234         }
235
236         return 0;
237 }
238
239 static int ehci_msm_pm_resume(struct device *dev)
240 {
241         struct usb_hcd *hcd = dev_get_drvdata(dev);
242
243         dev_dbg(dev, "ehci-msm PM resume\n");
244         ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
245
246         return 0;
247 }
248 #else
249 #define ehci_msm_pm_suspend     NULL
250 #define ehci_msm_pm_resume      NULL
251 #endif
252
253 static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
254         .suspend         = ehci_msm_pm_suspend,
255         .resume          = ehci_msm_pm_resume,
256 };
257
258 static struct platform_driver ehci_msm_driver = {
259         .probe  = ehci_msm_probe,
260         .remove = __devexit_p(ehci_msm_remove),
261         .driver = {
262                    .name = "msm_hsusb_host",
263                    .pm = &ehci_msm_dev_pm_ops,
264         },
265 };