Linux-2.6.12-rc2
[deliverable/linux.git] / drivers / usb / host / ohci-ppc-soc.c
1 /*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 * (C) Copyright 2003-2005 MontaVista Software Inc.
8 *
9 * Bus Glue for PPC On-Chip OHCI driver
10 * Tested on Freescale MPC5200 and IBM STB04xxx
11 *
12 * Modified by Dale Farnsworth <dale@farnsworth.org> from ohci-sa1111.c
13 *
14 * This file is licenced under the GPL.
15 */
16
17 #include <asm/usb.h>
18
19 /* configure so an HC device and id are always provided */
20 /* always called with process context; sleeping is OK */
21
22 /**
23 * usb_hcd_ppc_soc_probe - initialize On-Chip HCDs
24 * Context: !in_interrupt()
25 *
26 * Allocates basic resources for this USB host controller, and
27 * then invokes the start() method for the HCD associated with it
28 * through the hotplug entry's driver_data.
29 *
30 * Store this function in the HCD's struct pci_driver as probe().
31 */
32 static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
33 struct platform_device *pdev)
34 {
35 int retval;
36 struct usb_hcd *hcd;
37 struct ohci_hcd *ohci;
38 struct resource *res;
39 int irq;
40 struct usb_hcd_platform_data *pd = pdev->dev.platform_data;
41
42 pr_debug("initializing PPC-SOC USB Controller\n");
43
44 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
45 if (!res) {
46 pr_debug(__FILE__ ": no irq\n");
47 return -ENODEV;
48 }
49 irq = res->start;
50
51 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
52 if (!res) {
53 pr_debug(__FILE__ ": no reg addr\n");
54 return -ENODEV;
55 }
56
57 hcd = usb_create_hcd(driver, &pdev->dev, "PPC-SOC USB");
58 if (!hcd)
59 return -ENOMEM;
60 hcd->rsrc_start = res->start;
61 hcd->rsrc_len = res->end - res->start + 1;
62
63 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
64 pr_debug(__FILE__ ": request_mem_region failed\n");
65 retval = -EBUSY;
66 goto err1;
67 }
68
69 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
70 if (!hcd->regs) {
71 pr_debug(__FILE__ ": ioremap failed\n");
72 retval = -ENOMEM;
73 goto err2;
74 }
75
76 if (pd->start && (retval = pd->start(pdev)))
77 goto err3;
78
79 ohci = hcd_to_ohci(hcd);
80 ohci->flags |= OHCI_BIG_ENDIAN;
81 ohci_hcd_init(ohci);
82
83 retval = usb_add_hcd(hcd, irq, SA_INTERRUPT);
84 if (retval == 0)
85 return retval;
86
87 pr_debug("Removing PPC-SOC USB Controller\n");
88 if (pd && pd->stop)
89 pd->stop(pdev);
90 err3:
91 iounmap(hcd->regs);
92 err2:
93 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
94 err1:
95 usb_put_hcd(hcd);
96 return retval;
97 }
98
99
100 /* may be called without controller electrically present */
101 /* may be called with controller, bus, and devices active */
102
103 /**
104 * usb_hcd_ppc_soc_remove - shutdown processing for On-Chip HCDs
105 * @pdev: USB Host Controller being removed
106 * Context: !in_interrupt()
107 *
108 * Reverses the effect of usb_hcd_ppc_soc_probe(), first invoking
109 * the HCD's stop() method. It is always called from a thread
110 * context, normally "rmmod", "apmd", or something similar.
111 *
112 */
113 static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd,
114 struct platform_device *pdev)
115 {
116 struct usb_hcd_platform_data *pd = pdev->dev.platform_data;
117
118 usb_remove_hcd(hcd);
119
120 pr_debug("stopping PPC-SOC USB Controller\n");
121 if (pd && pd->stop)
122 pd->stop(pdev);
123
124 iounmap(hcd->regs);
125 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
126 usb_hcd_put(hcd);
127 }
128
129 static int __devinit
130 ohci_ppc_soc_start(struct usb_hcd *hcd)
131 {
132 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
133 int ret;
134
135 if ((ret = ohci_init(ohci)) < 0)
136 return ret;
137
138 if ((ret = ohci_run(ohci)) < 0) {
139 err("can't start %s", ohci_to_hcd(ohci)->self.bus_name);
140 ohci_stop(hcd);
141 return ret;
142 }
143
144 return 0;
145 }
146
147 static const struct hc_driver ohci_ppc_soc_hc_driver = {
148 .description = hcd_name,
149 .hcd_priv_size = sizeof(struct ohci_hcd),
150
151 /*
152 * generic hardware linkage
153 */
154 .irq = ohci_irq,
155 .flags = HCD_USB11 | HCD_MEMORY,
156
157 /*
158 * basic lifecycle operations
159 */
160 .start = ohci_ppc_soc_start,
161 .stop = ohci_stop,
162
163 /*
164 * managing i/o requests and associated device resources
165 */
166 .urb_enqueue = ohci_urb_enqueue,
167 .urb_dequeue = ohci_urb_dequeue,
168 .endpoint_disable = ohci_endpoint_disable,
169
170 /*
171 * scheduling support
172 */
173 .get_frame_number = ohci_get_frame,
174
175 /*
176 * root hub support
177 */
178 .hub_status_data = ohci_hub_status_data,
179 .hub_control = ohci_hub_control,
180 #ifdef CONFIG_USB_SUSPEND
181 .hub_suspend = ohci_hub_suspend,
182 .hub_resume = ohci_hub_resume,
183 #endif
184 .start_port_reset = ohci_start_port_reset,
185 };
186
187 static int ohci_hcd_ppc_soc_drv_probe(struct device *dev)
188 {
189 struct platform_device *pdev = to_platform_device(dev);
190 int ret;
191
192 if (usb_disabled())
193 return -ENODEV;
194
195 ret = usb_hcd_ppc_soc_probe(&ohci_ppc_soc_hc_driver, pdev);
196 return ret;
197 }
198
199 static int ohci_hcd_ppc_soc_drv_remove(struct device *dev)
200 {
201 struct platform_device *pdev = to_platform_device(dev);
202 struct usb_hcd *hcd = dev_get_drvdata(dev);
203
204 usb_hcd_ppc_soc_remove(hcd, pdev);
205 return 0;
206 }
207
208 static struct device_driver ohci_hcd_ppc_soc_driver = {
209 .name = "ppc-soc-ohci",
210 .bus = &platform_bus_type,
211 .probe = ohci_hcd_ppc_soc_drv_probe,
212 .remove = ohci_hcd_ppc_soc_drv_remove,
213 #if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM)
214 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
215 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
216 #endif
217 };
218
219 static int __init ohci_hcd_ppc_soc_init(void)
220 {
221 pr_debug(DRIVER_INFO " (PPC SOC)\n");
222 pr_debug("block sizes: ed %d td %d\n", sizeof(struct ed),
223 sizeof(struct td));
224
225 return driver_register(&ohci_hcd_ppc_soc_driver);
226 }
227
228 static void __exit ohci_hcd_ppc_soc_cleanup(void)
229 {
230 driver_unregister(&ohci_hcd_ppc_soc_driver);
231 }
232
233 module_init(ohci_hcd_ppc_soc_init);
234 module_exit(ohci_hcd_ppc_soc_cleanup);
This page took 0.043665 seconds and 5 git commands to generate.