vserver 1.9.5.x5
[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         if(dev->resource[1].flags != IORESOURCE_IRQ){
111                 pr_debug ("resource[1] is not IORESOURCE_IRQ");
112                 retval = -ENOMEM;
113                 goto err1;
114         }
115         
116
117         hcd = usb_create_hcd (driver);
118         if (hcd == NULL){
119                 pr_debug ("hcd_alloc failed");
120                 retval = -ENOMEM;
121                 goto err1;
122         }
123         ohci_hcd_init(hcd_to_ohci(hcd));
124
125         hcd->irq = dev->resource[1].start;
126         hcd->regs = addr;
127         hcd->self.controller = &dev->dev;
128
129         retval = hcd_buffer_create (hcd);
130         if (retval != 0) {
131                 pr_debug ("pool alloc fail");
132                 goto err2;
133         }
134
135         retval = request_irq (hcd->irq, usb_hcd_lh7a404_hcim_irq, SA_INTERRUPT,
136                               hcd->driver->description, hcd);
137         if (retval != 0) {
138                 pr_debug("request_irq failed");
139                 retval = -EBUSY;
140                 goto err3;
141         }
142
143         pr_debug ("%s (LH7A404) at 0x%p, irq %d",
144                 hcd->driver->description, hcd->regs, hcd->irq);
145
146         hcd->self.bus_name = "lh7a404";
147         usb_register_bus (&hcd->self);
148
149         if ((retval = driver->start (hcd)) < 0)
150         {
151                 usb_hcd_lh7a404_remove(hcd, dev);
152                 return retval;
153         }
154
155         *hcd_out = hcd;
156         return 0;
157
158  err3:
159         hcd_buffer_destroy (hcd);
160  err2:
161         usb_put_hcd(hcd);
162  err1:
163         lh7a404_stop_hc(dev);
164         release_mem_region(dev->resource[0].start,
165                                 dev->resource[0].end
166                            - dev->resource[0].start + 1);
167         return retval;
168 }
169
170
171 /* may be called without controller electrically present */
172 /* may be called with controller, bus, and devices active */
173
174 /**
175  * usb_hcd_lh7a404_remove - shutdown processing for LH7A404-based HCDs
176  * @dev: USB Host Controller being removed
177  * Context: !in_interrupt()
178  *
179  * Reverses the effect of usb_hcd_lh7a404_probe(), first invoking
180  * the HCD's stop() method.  It is always called from a thread
181  * context, normally "rmmod", "apmd", or something similar.
182  *
183  */
184 void usb_hcd_lh7a404_remove (struct usb_hcd *hcd, struct platform_device *dev)
185 {
186         pr_debug ("remove: %s, state %x", hcd->self.bus_name, hcd->state);
187
188         if (in_interrupt ())
189                 BUG ();
190
191         hcd->state = USB_STATE_QUIESCING;
192
193         pr_debug ("%s: roothub graceful disconnect", hcd->self.bus_name);
194         usb_disconnect (&hcd->self.root_hub);
195
196         hcd->driver->stop (hcd);
197         hcd->state = USB_STATE_HALT;
198
199         free_irq (hcd->irq, hcd);
200         hcd_buffer_destroy (hcd);
201
202         usb_deregister_bus (&hcd->self);
203
204         lh7a404_stop_hc(dev);
205         release_mem_region(dev->resource[0].start,
206                            dev->resource[0].end
207                            - dev->resource[0].start + 1);
208 }
209
210 /*-------------------------------------------------------------------------*/
211
212 static int __devinit
213 ohci_lh7a404_start (struct usb_hcd *hcd)
214 {
215         struct ohci_hcd *ohci = hcd_to_ohci (hcd);
216         int             ret;
217
218         ohci_dbg (ohci, "ohci_lh7a404_start, ohci:%p", ohci);
219         if ((ret = ohci_init(ohci)) < 0)
220                 return ret;
221
222         if ((ret = ohci_run (ohci)) < 0) {
223                 err ("can't start %s", hcd->self.bus_name);
224                 ohci_stop (hcd);
225                 return ret;
226         }
227         return 0;
228 }
229
230 /*-------------------------------------------------------------------------*/
231
232 static const struct hc_driver ohci_lh7a404_hc_driver = {
233         .description =          hcd_name,
234         .product_desc =         "LH7A404 OHCI",
235         .hcd_priv_size =        sizeof(struct ohci_hcd),
236
237         /*
238          * generic hardware linkage
239          */
240         .irq =                  ohci_irq,
241         .flags =                HCD_USB11,
242
243         /*
244          * basic lifecycle operations
245          */
246         .start =                ohci_lh7a404_start,
247 #ifdef  CONFIG_PM
248         /* suspend:             ohci_lh7a404_suspend,  -- tbd */
249         /* resume:              ohci_lh7a404_resume,   -- tbd */
250 #endif /*CONFIG_PM*/
251         .stop =                 ohci_stop,
252
253         /*
254          * managing i/o requests and associated device resources
255          */
256         .urb_enqueue =          ohci_urb_enqueue,
257         .urb_dequeue =          ohci_urb_dequeue,
258         .endpoint_disable =     ohci_endpoint_disable,
259
260         /*
261          * scheduling support
262          */
263         .get_frame_number =     ohci_get_frame,
264
265         /*
266          * root hub support
267          */
268         .hub_status_data =      ohci_hub_status_data,
269         .hub_control =          ohci_hub_control,
270 };
271
272 /*-------------------------------------------------------------------------*/
273
274 static int ohci_hcd_lh7a404_drv_probe(struct device *dev)
275 {
276         struct platform_device *pdev = to_platform_device(dev);
277         struct usb_hcd *hcd = NULL;
278         int ret;
279
280         pr_debug ("In ohci_hcd_lh7a404_drv_probe");
281
282         if (usb_disabled())
283                 return -ENODEV;
284
285         ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, &hcd, pdev);
286
287         if (ret == 0)
288                 dev_set_drvdata(dev, hcd);
289
290         return ret;
291 }
292
293 static int ohci_hcd_lh7a404_drv_remove(struct device *dev)
294 {
295         struct platform_device *pdev = to_platform_device(dev);
296         struct usb_hcd *hcd = dev_get_drvdata(dev);
297
298         usb_hcd_lh7a404_remove(hcd, pdev);
299         dev_set_drvdata(dev, NULL);
300         return 0;
301 }
302         /*TBD*/
303 /*static int ohci_hcd_lh7a404_drv_suspend(struct device *dev)
304 {
305         struct platform_device *pdev = to_platform_device(dev);
306         struct usb_hcd *hcd = dev_get_drvdata(dev);
307
308         return 0;
309 }
310 static int ohci_hcd_lh7a404_drv_resume(struct device *dev)
311 {
312         struct platform_device *pdev = to_platform_device(dev);
313         struct usb_hcd *hcd = dev_get_drvdata(dev);
314
315
316         return 0;
317 }
318 */
319
320 static struct device_driver ohci_hcd_lh7a404_driver = {
321         .name           = "lh7a404-ohci",
322         .bus            = &platform_bus_type,
323         .probe          = ohci_hcd_lh7a404_drv_probe,
324         .remove         = ohci_hcd_lh7a404_drv_remove,
325         /*.suspend      = ohci_hcd_lh7a404_drv_suspend, */
326         /*.resume       = ohci_hcd_lh7a404_drv_resume, */
327 };
328
329 static int __init ohci_hcd_lh7a404_init (void)
330 {
331         pr_debug (DRIVER_INFO " (LH7A404)");
332         pr_debug ("block sizes: ed %d td %d\n",
333                 sizeof (struct ed), sizeof (struct td));
334
335         return driver_register(&ohci_hcd_lh7a404_driver);
336 }
337
338 static void __exit ohci_hcd_lh7a404_cleanup (void)
339 {
340         driver_unregister(&ohci_hcd_lh7a404_driver);
341 }
342
343 module_init (ohci_hcd_lh7a404_init);
344 module_exit (ohci_hcd_lh7a404_cleanup);