usb: remove use of __devexit
[linux-2.6-block.git] / drivers / usb / host / ohci-omap3.c
CommitLineData
88ed0c97
AG
1/*
2 * ohci-omap3.c - driver for OHCI on OMAP3 and later processors
3 *
4 * Bus Glue for OMAP3 USBHOST 3 port OHCI controller
5 * This controller is also used in later OMAPs and AM35x chips
6 *
7 * Copyright (C) 2007-2010 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 * Author: Anand Gadiyar <gadiyar@ti.com>
19403165 10 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
88ed0c97
AG
11 *
12 * Based on ehci-omap.c and some other ohci glue layers
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
19403165 28 * TODO (last updated Feb 27, 2011):
88ed0c97 29 * - add kernel-doc
88ed0c97
AG
30 */
31
32#include <linux/platform_device.h>
88ed0c97 33#include <plat/usb.h>
6c984b06 34#include <linux/pm_runtime.h>
88ed0c97 35
88ed0c97
AG
36/*-------------------------------------------------------------------------*/
37
88ed0c97
AG
38static int ohci_omap3_init(struct usb_hcd *hcd)
39{
40 dev_dbg(hcd->self.controller, "starting OHCI controller\n");
41
42 return ohci_init(hcd_to_ohci(hcd));
43}
44
88ed0c97
AG
45/*-------------------------------------------------------------------------*/
46
47static int ohci_omap3_start(struct usb_hcd *hcd)
48{
49 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
50 int ret;
51
52 /*
53 * RemoteWakeupConnected has to be set explicitly before
54 * calling ohci_run. The reset value of RWC is 0.
55 */
56 ohci->hc_control = OHCI_CTRL_RWC;
57 writel(OHCI_CTRL_RWC, &ohci->regs->control);
58
59 ret = ohci_run(ohci);
60
61 if (ret < 0) {
62 dev_err(hcd->self.controller, "can't start\n");
63 ohci_stop(hcd);
64 }
65
66 return ret;
67}
68
69/*-------------------------------------------------------------------------*/
70
88ed0c97
AG
71static const struct hc_driver ohci_omap3_hc_driver = {
72 .description = hcd_name,
73 .product_desc = "OMAP3 OHCI Host Controller",
74 .hcd_priv_size = sizeof(struct ohci_hcd),
75
76 /*
77 * generic hardware linkage
78 */
79 .irq = ohci_irq,
80 .flags = HCD_USB11 | HCD_MEMORY,
81
82 /*
83 * basic lifecycle operations
84 */
85 .reset = ohci_omap3_init,
86 .start = ohci_omap3_start,
87 .stop = ohci_stop,
88 .shutdown = ohci_shutdown,
89
90 /*
91 * managing i/o requests and associated device resources
92 */
93 .urb_enqueue = ohci_urb_enqueue,
94 .urb_dequeue = ohci_urb_dequeue,
95 .endpoint_disable = ohci_endpoint_disable,
96
97 /*
98 * scheduling support
99 */
100 .get_frame_number = ohci_get_frame,
101
102 /*
103 * root hub support
104 */
105 .hub_status_data = ohci_hub_status_data,
106 .hub_control = ohci_hub_control,
107#ifdef CONFIG_PM
108 .bus_suspend = ohci_bus_suspend,
109 .bus_resume = ohci_bus_resume,
110#endif
111 .start_port_reset = ohci_start_port_reset,
112};
113
114/*-------------------------------------------------------------------------*/
115
116/*
117 * configure so an HC device and id are always provided
118 * always called with process context; sleeping is OK
119 */
120
121/**
122 * ohci_hcd_omap3_probe - initialize OMAP-based HCDs
123 *
124 * Allocates basic resources for this USB host controller, and
125 * then invokes the start() method for the HCD associated with it
126 * through the hotplug entry's driver_data.
127 */
41ac7b3a 128static int ohci_hcd_omap3_probe(struct platform_device *pdev)
88ed0c97 129{
19403165
KM
130 struct device *dev = &pdev->dev;
131 struct usb_hcd *hcd = NULL;
132 void __iomem *regs = NULL;
133 struct resource *res;
134 int ret = -ENODEV;
135 int irq;
88ed0c97
AG
136
137 if (usb_disabled())
6c984b06 138 return -ENODEV;
88ed0c97 139
19403165
KM
140 if (!dev->parent) {
141 dev_err(dev, "Missing parent device\n");
142 return -ENODEV;
88ed0c97
AG
143 }
144
19403165
KM
145 irq = platform_get_irq_byname(pdev, "ohci-irq");
146 if (irq < 0) {
147 dev_err(dev, "OHCI irq failed\n");
148 return -ENODEV;
149 }
88ed0c97 150
19403165
KM
151 res = platform_get_resource_byname(pdev,
152 IORESOURCE_MEM, "ohci");
d80cba6c 153 if (!res) {
19403165
KM
154 dev_err(dev, "UHH OHCI get resource failed\n");
155 return -ENOMEM;
88ed0c97
AG
156 }
157
19403165
KM
158 regs = ioremap(res->start, resource_size(res));
159 if (!regs) {
160 dev_err(dev, "UHH OHCI ioremap failed\n");
161 return -ENOMEM;
88ed0c97
AG
162 }
163
88ed0c97 164
19403165
KM
165 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
166 dev_name(dev));
167 if (!hcd) {
168 dev_err(dev, "usb_create_hcd failed\n");
169 goto err_io;
170 }
88ed0c97
AG
171
172 hcd->rsrc_start = res->start;
173 hcd->rsrc_len = resource_size(res);
19403165 174 hcd->regs = regs;
88ed0c97 175
6c984b06
KM
176 pm_runtime_enable(dev);
177 pm_runtime_get_sync(dev);
88ed0c97 178
19403165 179 ohci_hcd_init(hcd_to_ohci(hcd));
88ed0c97 180
b5dd18d8 181 ret = usb_add_hcd(hcd, irq, 0);
88ed0c97 182 if (ret) {
19403165 183 dev_dbg(dev, "failed to add hcd with err %d\n", ret);
88ed0c97
AG
184 goto err_add_hcd;
185 }
186
187 return 0;
188
189err_add_hcd:
6c984b06 190 pm_runtime_put_sync(dev);
88ed0c97
AG
191 usb_put_hcd(hcd);
192
19403165
KM
193err_io:
194 iounmap(regs);
195
88ed0c97
AG
196 return ret;
197}
198
199/*
200 * may be called without controller electrically present
201 * may be called with controller, bus, and devices active
202 */
203
204/**
205 * ohci_hcd_omap3_remove - shutdown processing for OHCI HCDs
206 * @pdev: USB Host Controller being removed
207 *
208 * Reverses the effect of ohci_hcd_omap3_probe(), first invoking
209 * the HCD's stop() method. It is always called from a thread
210 * context, normally "rmmod", "apmd", or something similar.
211 */
fb4e98ab 212static int ohci_hcd_omap3_remove(struct platform_device *pdev)
88ed0c97 213{
19403165
KM
214 struct device *dev = &pdev->dev;
215 struct usb_hcd *hcd = dev_get_drvdata(dev);
88ed0c97 216
88ed0c97 217 iounmap(hcd->regs);
19403165 218 usb_remove_hcd(hcd);
6c984b06
KM
219 pm_runtime_put_sync(dev);
220 pm_runtime_disable(dev);
88ed0c97 221 usb_put_hcd(hcd);
88ed0c97
AG
222 return 0;
223}
224
225static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
226{
19403165 227 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
88ed0c97
AG
228
229 if (hcd->driver->shutdown)
230 hcd->driver->shutdown(hcd);
231}
232
233static struct platform_driver ohci_hcd_omap3_driver = {
234 .probe = ohci_hcd_omap3_probe,
7690417d 235 .remove = ohci_hcd_omap3_remove,
88ed0c97
AG
236 .shutdown = ohci_hcd_omap3_shutdown,
237 .driver = {
238 .name = "ohci-omap3",
239 },
240};
241
242MODULE_ALIAS("platform:ohci-omap3");
243MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");