This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / usb / host / ohci-au1xxx.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  *
8  * Bus Glue for AMD Alchemy Au1xxx
9  *
10  * Written by Christopher Hoover <ch@hpl.hp.com>
11  * Based on fragments of previous driver by Rusell King et al.
12  *
13  * Modified for LH7A404 from ohci-sa1111.c
14  *  by Durgesh Pattamatta <pattamattad@sharpsec.com>
15  * Modified for AMD Alchemy Au1xxx
16  *  by Matt Porter <mporter@kernel.crashing.org>
17  *
18  * This file is licenced under the GPL.
19  */
20
21 #include <asm/mach-au1x00/au1000.h>
22
23 #define USBH_ENABLE_BE (1<<0)
24 #define USBH_ENABLE_C  (1<<1)
25 #define USBH_ENABLE_E  (1<<2)
26 #define USBH_ENABLE_CE (1<<3)
27 #define USBH_ENABLE_RD (1<<4)
28
29 #ifdef __LITTLE_ENDIAN
30 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
31 #elif __BIG_ENDIAN
32 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE)
33 #else
34 #error not byte order defined
35 #endif
36
37 extern int usb_disabled(void);
38
39 /*-------------------------------------------------------------------------*/
40
41 static void au1xxx_start_hc(struct platform_device *dev)
42 {
43         printk(KERN_DEBUG __FILE__
44                 ": starting Au1xxx OHCI USB Controller\n");
45
46         /* enable host controller */
47         au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
48         udelay(1000);
49         au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
50         udelay(1000);
51
52         /* wait for reset complete (read register twice; see au1500 errata) */
53         while (au_readl(USB_HOST_CONFIG),
54                 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
55                 udelay(1000);
56
57         printk(KERN_DEBUG __FILE__
58         ": Clock to USB host has been enabled \n");
59 }
60
61 static void au1xxx_stop_hc(struct platform_device *dev)
62 {
63         printk(KERN_DEBUG __FILE__
64                ": stopping Au1xxx OHCI USB Controller\n");
65
66         /* Disable clock */
67         au_writel(readl((void *)USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
68 }
69
70
71 /*-------------------------------------------------------------------------*/
72
73
74 static irqreturn_t usb_hcd_au1xxx_hcim_irq (int irq, void *__hcd,
75                                              struct pt_regs * r)
76 {
77         struct usb_hcd *hcd = __hcd;
78
79         return usb_hcd_irq(irq, hcd, r);
80 }
81
82 /*-------------------------------------------------------------------------*/
83
84 void usb_hcd_au1xxx_remove (struct usb_hcd *, struct platform_device *);
85
86 /* configure so an HC device and id are always provided */
87 /* always called with process context; sleeping is OK */
88
89
90 /**
91  * usb_hcd_au1xxx_probe - initialize Au1xxx-based HCDs
92  * Context: !in_interrupt()
93  *
94  * Allocates basic resources for this USB host controller, and
95  * then invokes the start() method for the HCD associated with it
96  * through the hotplug entry's driver_data.
97  *
98  */
99 int usb_hcd_au1xxx_probe (const struct hc_driver *driver,
100                           struct usb_hcd **hcd_out,
101                           struct platform_device *dev)
102 {
103         int retval;
104         struct usb_hcd *hcd = 0;
105
106         unsigned int *addr = NULL;
107
108         if (!request_mem_region(dev->resource[0].start,
109                                 dev->resource[0].end
110                                 - dev->resource[0].start + 1, hcd_name)) {
111                 pr_debug("request_mem_region failed");
112                 return -EBUSY;
113         }
114
115         au1xxx_start_hc(dev);
116
117         addr = ioremap(dev->resource[0].start,
118                        dev->resource[0].end
119                        - dev->resource[0].start + 1);
120         if (!addr) {
121                 pr_debug("ioremap failed");
122                 retval = -ENOMEM;
123                 goto err1;
124         }
125
126         if(dev->resource[1].flags != IORESOURCE_IRQ) {
127                 pr_debug ("resource[1] is not IORESOURCE_IRQ");
128                 retval = -ENOMEM;
129                 goto err1;
130         }
131
132         hcd = usb_create_hcd(driver);
133         if (hcd == NULL) {
134                 pr_debug ("usb_create_hcd failed");
135                 retval = -ENOMEM;
136                 goto err1;
137         }
138         ohci_hcd_init(hcd_to_ohci(hcd));
139
140         hcd->irq = dev->resource[1].start;
141         hcd->regs = addr;
142         hcd->self.controller = &dev->dev;
143
144         retval = hcd_buffer_create (hcd);
145         if (retval != 0) {
146                 pr_debug ("pool alloc fail");
147                 goto err2;
148         }
149
150         retval = request_irq (hcd->irq, usb_hcd_au1xxx_hcim_irq, SA_INTERRUPT,
151                               hcd->driver->description, hcd);
152         if (retval != 0) {
153                 pr_debug("request_irq failed");
154                 retval = -EBUSY;
155                 goto err3;
156         }
157
158         pr_debug ("%s (Au1xxx) at 0x%p, irq %d",
159              hcd->driver->description, hcd->regs, hcd->irq);
160
161         hcd->self.bus_name = "au1xxx";
162
163         usb_register_bus (&hcd->self);
164
165         if ((retval = driver->start (hcd)) < 0)
166         {
167                 usb_hcd_au1xxx_remove(hcd, dev);
168                 printk("bad driver->start\n");
169                 return retval;
170         }
171
172         *hcd_out = hcd;
173         return 0;
174
175  err3:
176         hcd_buffer_destroy (hcd);
177  err2:
178         usb_put_hcd(hcd);
179  err1:
180         au1xxx_stop_hc(dev);
181         release_mem_region(dev->resource[0].start,
182                                 dev->resource[0].end
183                            - dev->resource[0].start + 1);
184         return retval;
185 }
186
187
188 /* may be called without controller electrically present */
189 /* may be called with controller, bus, and devices active */
190
191 /**
192  * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
193  * @dev: USB Host Controller being removed
194  * Context: !in_interrupt()
195  *
196  * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
197  * the HCD's stop() method.  It is always called from a thread
198  * context, normally "rmmod", "apmd", or something similar.
199  *
200  */
201 void usb_hcd_au1xxx_remove (struct usb_hcd *hcd, struct platform_device *dev)
202 {
203         pr_debug ("remove: %s, state %x", hcd->self.bus_name, hcd->state);
204
205         if (in_interrupt ())
206                 BUG ();
207
208         hcd->state = USB_STATE_QUIESCING;
209
210         pr_debug ("%s: roothub graceful disconnect", hcd->self.bus_name);
211         usb_disconnect (&hcd->self.root_hub);
212
213         hcd->driver->stop (hcd);
214         hcd->state = USB_STATE_HALT;
215
216         free_irq (hcd->irq, hcd);
217         hcd_buffer_destroy (hcd);
218
219         usb_deregister_bus (&hcd->self);
220
221         au1xxx_stop_hc(dev);
222         release_mem_region(dev->resource[0].start,
223                            dev->resource[0].end
224                            - dev->resource[0].start + 1);
225 }
226
227 /*-------------------------------------------------------------------------*/
228
229 static int __devinit
230 ohci_au1xxx_start (struct usb_hcd *hcd)
231 {
232         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
233         int             ret;
234
235         ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci);
236
237         if ((ret = ohci_init (ohci)) < 0)
238                 return ret;
239
240         if ((ret = ohci_run (ohci)) < 0) {
241                 err ("can't start %s", hcd->self.bus_name);
242                 ohci_stop (hcd);
243                 return ret;
244         }
245
246         return 0;
247 }
248
249 /*-------------------------------------------------------------------------*/
250
251 static const struct hc_driver ohci_au1xxx_hc_driver = {
252         .description =          hcd_name,
253         .product_desc =         "Au1xxx OHCI",
254         .hcd_priv_size =        sizeof(struct ohci_hcd),
255
256         /*
257          * generic hardware linkage
258          */
259         .irq =                  ohci_irq,
260         .flags =                HCD_USB11,
261
262         /*
263          * basic lifecycle operations
264          */
265         .start =                ohci_au1xxx_start,
266 #ifdef  CONFIG_PM
267         /* suspend:             ohci_au1xxx_suspend,  -- tbd */
268         /* resume:              ohci_au1xxx_resume,   -- tbd */
269 #endif /*CONFIG_PM*/
270         .stop =                 ohci_stop,
271
272         /*
273          * managing i/o requests and associated device resources
274          */
275         .urb_enqueue =          ohci_urb_enqueue,
276         .urb_dequeue =          ohci_urb_dequeue,
277         .endpoint_disable =     ohci_endpoint_disable,
278
279         /*
280          * scheduling support
281          */
282         .get_frame_number =     ohci_get_frame,
283
284         /*
285          * root hub support
286          */
287         .hub_status_data =      ohci_hub_status_data,
288         .hub_control =          ohci_hub_control,
289 };
290
291 /*-------------------------------------------------------------------------*/
292
293 static int ohci_hcd_au1xxx_drv_probe(struct device *dev)
294 {
295         struct platform_device *pdev = to_platform_device(dev);
296         struct usb_hcd *hcd = NULL;
297         int ret;
298
299         pr_debug ("In ohci_hcd_au1xxx_drv_probe");
300
301         if (usb_disabled())
302                 return -ENODEV;
303
304         ret = usb_hcd_au1xxx_probe(&ohci_au1xxx_hc_driver, &hcd, pdev);
305
306         if (ret == 0)
307                 dev_set_drvdata(dev, hcd);
308
309         return ret;
310 }
311
312 static int ohci_hcd_au1xxx_drv_remove(struct device *dev)
313 {
314         struct platform_device *pdev = to_platform_device(dev);
315         struct usb_hcd *hcd = dev_get_drvdata(dev);
316
317         usb_hcd_au1xxx_remove(hcd, pdev);
318         dev_set_drvdata(dev, NULL);
319         return 0;
320 }
321         /*TBD*/
322 /*static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
323 {
324         struct platform_device *pdev = to_platform_device(dev);
325         struct usb_hcd *hcd = dev_get_drvdata(dev);
326
327         return 0;
328 }
329 static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
330 {
331         struct platform_device *pdev = to_platform_device(dev);
332         struct usb_hcd *hcd = dev_get_drvdata(dev);
333
334         return 0;
335 }
336 */
337
338 static struct device_driver ohci_hcd_au1xxx_driver = {
339         .name           = "au1xxx-ohci",
340         .bus            = &platform_bus_type,
341         .probe          = ohci_hcd_au1xxx_drv_probe,
342         .remove         = ohci_hcd_au1xxx_drv_remove,
343         /*.suspend      = ohci_hcd_au1xxx_drv_suspend, */
344         /*.resume       = ohci_hcd_au1xxx_drv_resume, */
345 };
346
347 static int __init ohci_hcd_au1xxx_init (void)
348 {
349         pr_debug (DRIVER_INFO " (Au1xxx)");
350         pr_debug ("block sizes: ed %d td %d\n",
351                 sizeof (struct ed), sizeof (struct td));
352
353         return driver_register(&ohci_hcd_au1xxx_driver);
354 }
355
356 static void __exit ohci_hcd_au1xxx_cleanup (void)
357 {
358         driver_unregister(&ohci_hcd_au1xxx_driver);
359 }
360
361 module_init (ohci_hcd_au1xxx_init);
362 module_exit (ohci_hcd_au1xxx_cleanup);