This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / usb / host / ohci-lh7a404.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 Sharp LH7A404
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  *
16  * This file is licenced under the GPL.
17  */
18
19 #include <asm/hardware.h>
20 #include <asm/mach-types.h>
21 #include <asm/arch/hardware.h>
22
23
24 extern int usb_disabled(void);
25
26 /*-------------------------------------------------------------------------*/
27
28 static void lh7a404_start_hc(struct platform_device *dev)
29 {
30         printk(KERN_DEBUG __FILE__
31                ": starting LH7A404 OHCI USB Controller\n");
32
33         /*
34          * Now, carefully enable the USB clock, and take
35          * the USB host controller out of reset.
36          */
37         CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */
38         udelay(1000);
39         USBH_CMDSTATUS = OHCI_HCR;
40         
41         printk(KERN_DEBUG __FILE__
42                    ": Clock to USB host has been enabled \n");
43 }
44
45 static void lh7a404_stop_hc(struct platform_device *dev)
46 {
47         printk(KERN_DEBUG __FILE__
48                ": stopping LH7A404 OHCI USB Controller\n");
49
50         CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */
51 }
52
53
54 /*-------------------------------------------------------------------------*/
55
56
57 static irqreturn_t usb_hcd_lh7a404_hcim_irq (int irq, void *__hcd,
58                                              struct pt_regs * r)
59 {
60         struct usb_hcd *hcd = __hcd;
61
62         return usb_hcd_irq(irq, hcd, r);
63 }
64
65 /*-------------------------------------------------------------------------*/
66
67 void usb_hcd_lh7a404_remove (struct usb_hcd *, struct platform_device *);
68
69 /* configure so an HC device and id are always provided */
70 /* always called with process context; sleeping is OK */
71
72
73 /**
74  * usb_hcd_lh7a404_probe - initialize LH7A404-based HCDs
75  * Context: !in_interrupt()
76  *
77  * Allocates basic resources for this USB host controller, and
78  * then invokes the start() method for the HCD associated with it
79  * through the hotplug entry's driver_data.
80  *
81  */
82 int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
83                           struct usb_hcd **hcd_out,
84                           struct platform_device *dev)
85 {
86         int retval;
87         struct usb_hcd *hcd = 0;
88
89         unsigned int *addr = NULL;
90
91         if (!request_mem_region(dev->resource[0].start,
92                                 dev->resource[0].end
93                                 - dev->resource[0].start + 1, hcd_name)) {
94                 pr_debug("request_mem_region failed");
95                 return -EBUSY;
96         }
97         
98         
99         lh7a404_start_hc(dev);
100         
101         addr = ioremap(dev->resource[0].start,
102                        dev->resource[0].end
103                        - dev->resource[0].start + 1);
104         if (!addr) {
105                 pr_debug("ioremap failed");
106                 retval = -ENOMEM;
107                 goto err1;
108         }
109         
110
111         hcd = driver->hcd_alloc ();
112         if (hcd == NULL){
113                 pr_debug ("hcd_alloc failed");
114                 retval = -ENOMEM;
115                 goto err1;
116         }
117
118         if(dev->resource[1].flags != IORESOURCE_IRQ){
119                 pr_debug ("resource[1] is not IORESOURCE_IRQ");
120                 retval = -ENOMEM;
121                 goto err1;
122         }
123
124         hcd->driver = (struct hc_driver *) driver;
125         hcd->description = driver->description;
126         hcd->irq = dev->resource[1].start;
127         hcd->regs = addr;
128         hcd->self.controller = &dev->dev;
129
130         retval = hcd_buffer_create (hcd);
131         if (retval != 0) {
132                 pr_debug ("pool alloc fail");
133                 goto err1;
134         }
135
136         retval = request_irq (hcd->irq, usb_hcd_lh7a404_hcim_irq, SA_INTERRUPT,
137                               hcd->description, hcd);
138         if (retval != 0) {
139                 pr_debug("request_irq failed");
140                 retval = -EBUSY;
141                 goto err2;
142         }
143
144         pr_debug ("%s (LH7A404) at 0x%p, irq %d",
145              hcd->description, hcd->regs, hcd->irq);
146
147         usb_bus_init (&hcd->self);
148         hcd->self.op = &usb_hcd_operations;
149         hcd->self.hcpriv = (void *) hcd;
150         hcd->self.bus_name = "lh7a404";
151         hcd->product_desc = "LH7A404 OHCI";
152
153         INIT_LIST_HEAD (&hcd->dev_list);
154
155         usb_register_bus (&hcd->self);
156
157         if ((retval = driver->start (hcd)) < 0)
158         {
159                 usb_hcd_lh7a404_remove(hcd, dev);
160                 return retval;
161         }
162
163         *hcd_out = hcd;
164         return 0;
165
166  err2:
167         hcd_buffer_destroy (hcd);
168         if (hcd)
169                 driver->hcd_free(hcd);
170  err1:
171         lh7a404_stop_hc(dev);
172         release_mem_region(dev->resource[0].start,
173                                 dev->resource[0].end
174                            - dev->resource[0].start + 1);
175         return retval;
176 }
177
178
179 /* may be called without controller electrically present */
180 /* may be called with controller, bus, and devices active */
181
182 /**
183  * usb_hcd_lh7a404_remove - shutdown processing for LH7A404-based HCDs
184  * @dev: USB Host Controller being removed
185  * Context: !in_interrupt()
186  *
187  * Reverses the effect of usb_hcd_lh7a404_probe(), first invoking
188  * the HCD's stop() method.  It is always called from a thread
189  * context, normally "rmmod", "apmd", or something similar.
190  *
191  */
192 void usb_hcd_lh7a404_remove (struct usb_hcd *hcd, struct platform_device *dev)
193 {
194         void *base;
195
196         pr_debug ("remove: %s, state %x", hcd->self.bus_name, hcd->state);
197
198         if (in_interrupt ())
199                 BUG ();
200
201         hcd->state = USB_STATE_QUIESCING;
202
203         pr_debug ("%s: roothub graceful disconnect", hcd->self.bus_name);
204         usb_disconnect (&hcd->self.root_hub);
205
206         hcd->driver->stop (hcd);
207         hcd->state = USB_STATE_HALT;
208
209         free_irq (hcd->irq, hcd);
210         hcd_buffer_destroy (hcd);
211
212         usb_deregister_bus (&hcd->self);
213
214         base = hcd->regs;
215         hcd->driver->hcd_free (hcd);
216
217         lh7a404_stop_hc(dev);
218         release_mem_region(dev->resource[0].start,
219                            dev->resource[0].end
220                            - dev->resource[0].start + 1);
221 }
222
223 /*-------------------------------------------------------------------------*/
224
225 static int __devinit
226 ohci_lh7a404_start (struct usb_hcd *hcd)
227 {
228         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
229         int             ret;
230
231         ohci_dbg (ohci, "ohci_lh7a404_start, ohci:%p", ohci);
232                         
233         ohci->hcca = dma_alloc_coherent (hcd->self.controller,
234                         sizeof *ohci->hcca, &ohci->hcca_dma, 0);
235         if (!ohci->hcca)
236                 return -ENOMEM;
237
238         ohci_dbg (ohci, "ohci_lh7a404_start, ohci->hcca:%p",
239                         ohci->hcca);
240
241         memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
242
243         if ((ret = ohci_mem_init (ohci)) < 0) {
244                 ohci_stop (hcd);
245                 return ret;
246         }
247         ohci->regs = hcd->regs;
248
249         if (hc_reset (ohci) < 0) {
250                 ohci_stop (hcd);
251                 return -ENODEV;
252         }
253
254         if (hc_start (ohci) < 0) {
255                 err ("can't start %s", ohci->hcd.self.bus_name);
256                 ohci_stop (hcd);
257                 return -EBUSY;
258         }
259         create_debug_files (ohci);
260
261 #ifdef  DEBUG
262         ohci_dump (ohci, 1);
263 #endif /*DEBUG*/
264         return 0;
265 }
266
267 /*-------------------------------------------------------------------------*/
268
269 static const struct hc_driver ohci_lh7a404_hc_driver = {
270         .description =          hcd_name,
271
272         /*
273          * generic hardware linkage
274          */
275         .irq =                  ohci_irq,
276         .flags =                HCD_USB11,
277
278         /*
279          * basic lifecycle operations
280          */
281         .start =                ohci_lh7a404_start,
282 #ifdef  CONFIG_PM
283         /* suspend:             ohci_lh7a404_suspend,  -- tbd */
284         /* resume:              ohci_lh7a404_resume,   -- tbd */
285 #endif /*CONFIG_PM*/
286         .stop =                 ohci_stop,
287
288         /*
289          * memory lifecycle (except per-request)
290          */
291         .hcd_alloc =            ohci_hcd_alloc,
292         .hcd_free =             ohci_hcd_free,
293
294         /*
295          * managing i/o requests and associated device resources
296          */
297         .urb_enqueue =          ohci_urb_enqueue,
298         .urb_dequeue =          ohci_urb_dequeue,
299         .endpoint_disable =     ohci_endpoint_disable,
300
301         /*
302          * scheduling support
303          */
304         .get_frame_number =     ohci_get_frame,
305
306         /*
307          * root hub support
308          */
309         .hub_status_data =      ohci_hub_status_data,
310         .hub_control =          ohci_hub_control,
311 };
312
313 /*-------------------------------------------------------------------------*/
314
315 static int ohci_hcd_lh7a404_drv_probe(struct device *dev)
316 {
317         struct platform_device *pdev = to_platform_device(dev);
318         struct usb_hcd *hcd = NULL;
319         int ret;
320
321         pr_debug ("In ohci_hcd_lh7a404_drv_probe");
322
323         if (usb_disabled())
324                 return -ENODEV;
325
326         ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, &hcd, pdev);
327
328         if (ret == 0)
329                 dev_set_drvdata(dev, hcd);
330
331         return ret;
332 }
333
334 static int ohci_hcd_lh7a404_drv_remove(struct device *dev)
335 {
336         struct platform_device *pdev = to_platform_device(dev);
337         struct usb_hcd *hcd = dev_get_drvdata(dev);
338
339         usb_hcd_lh7a404_remove(hcd, pdev);
340         dev_set_drvdata(dev, NULL);
341         return 0;
342 }
343         /*TBD*/
344 /*static int ohci_hcd_lh7a404_drv_suspend(struct device *dev)
345 {
346         struct platform_device *pdev = to_platform_device(dev);
347         struct usb_hcd *hcd = dev_get_drvdata(dev);
348
349         return 0;
350 }
351 static int ohci_hcd_lh7a404_drv_resume(struct device *dev)
352 {
353         struct platform_device *pdev = to_platform_device(dev);
354         struct usb_hcd *hcd = dev_get_drvdata(dev);
355
356
357         return 0;
358 }
359 */
360
361 static struct device_driver ohci_hcd_lh7a404_driver = {
362         .name           = "lh7a404-ohci",
363         .bus            = &platform_bus_type,
364         .probe          = ohci_hcd_lh7a404_drv_probe,
365         .remove         = ohci_hcd_lh7a404_drv_remove,
366         /*.suspend      = ohci_hcd_lh7a404_drv_suspend, */
367         /*.resume       = ohci_hcd_lh7a404_drv_resume, */
368 };
369
370 static int __init ohci_hcd_lh7a404_init (void)
371 {
372         pr_debug (DRIVER_INFO " (LH7A404)");
373         pr_debug ("block sizes: ed %d td %d\n",
374                 sizeof (struct ed), sizeof (struct td));
375
376         return driver_register(&ohci_hcd_lh7a404_driver);
377 }
378
379 static void __exit ohci_hcd_lh7a404_cleanup (void)
380 {
381         driver_unregister(&ohci_hcd_lh7a404_driver);
382 }
383
384 module_init (ohci_hcd_lh7a404_init);
385 module_exit (ohci_hcd_lh7a404_cleanup);