initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / usb / host / ohci-sa1111.c
blobc3cd76aba1635519b6879a23caa279450fff505d
1 /*
2 * OHCI HCD (Host Controller Driver) for USB.
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 * SA1111 Bus Glue
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Rusell King et al.
13 * This file is licenced under the GPL.
16 #include <asm/hardware.h>
17 #include <asm/mach-types.h>
18 #include <asm/arch/assabet.h>
19 #include <asm/arch/badge4.h>
20 #include <asm/hardware/sa1111.h>
22 #ifndef CONFIG_SA1111
23 #error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined."
24 #endif
26 extern int usb_disabled(void);
28 /*-------------------------------------------------------------------------*/
30 static void sa1111_start_hc(struct sa1111_dev *dev)
32 unsigned int usb_rst = 0;
34 printk(KERN_DEBUG __FILE__
35 ": starting SA-1111 OHCI USB Controller\n");
37 #ifdef CONFIG_SA1100_BADGE4
38 if (machine_is_badge4()) {
39 badge4_set_5V(BADGE4_5V_USB, 1);
41 #endif
43 if (machine_is_xp860() ||
44 machine_has_neponset() ||
45 machine_is_pfs168() ||
46 machine_is_badge4())
47 usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
50 * Configure the power sense and control lines. Place the USB
51 * host controller in reset.
53 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
54 dev->mapbase + SA1111_USB_RESET);
57 * Now, carefully enable the USB clock, and take
58 * the USB host controller out of reset.
60 sa1111_enable_device(dev);
61 udelay(11);
62 sa1111_writel(usb_rst, dev->mapbase + SA1111_USB_RESET);
65 static void sa1111_stop_hc(struct sa1111_dev *dev)
67 unsigned int usb_rst;
68 printk(KERN_DEBUG __FILE__
69 ": stopping SA-1111 OHCI USB Controller\n");
72 * Put the USB host controller into reset.
74 usb_rst = sa1111_readl(dev->mapbase + SA1111_USB_RESET);
75 sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
76 dev->mapbase + SA1111_USB_RESET);
79 * Stop the USB clock.
81 sa1111_disable_device(dev);
83 #ifdef CONFIG_SA1100_BADGE4
84 if (machine_is_badge4()) {
85 /* Disable power to the USB bus */
86 badge4_set_5V(BADGE4_5V_USB, 0);
88 #endif
92 /*-------------------------------------------------------------------------*/
94 #if 0
95 static void dump_hci_status(struct usb_hcd *hcd, const char *label)
97 unsigned long status = sa1111_readl(hcd->regs + SA1111_USB_STATUS);
99 dbg ("%s USB_STATUS = { %s%s%s%s%s}", label,
100 ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
101 ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
102 ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
103 ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
104 ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
106 #endif
108 static irqreturn_t usb_hcd_sa1111_hcim_irq (int irq, void *__hcd, struct pt_regs * r)
110 struct usb_hcd *hcd = __hcd;
111 // unsigned long status = sa1111_readl(hcd->regs + SA1111_USB_STATUS);
113 //dump_hci_status(hcd, "irq");
115 #if 0
116 /* may work better this way -- need to investigate further */
117 if (status & USB_STATUS_NIRQHCIM) {
118 //dbg ("not normal HC interrupt; ignoring");
119 return;
121 #endif
123 usb_hcd_irq(irq, hcd, r);
126 * SA1111 seems to re-assert its interrupt immediately
127 * after processing an interrupt. Always return IRQ_HANDLED.
129 return IRQ_HANDLED;
132 /*-------------------------------------------------------------------------*/
134 void usb_hcd_sa1111_remove (struct usb_hcd *, struct sa1111_dev *);
136 /* configure so an HC device and id are always provided */
137 /* always called with process context; sleeping is OK */
141 * usb_hcd_sa1111_probe - initialize SA-1111-based HCDs
142 * Context: !in_interrupt()
144 * Allocates basic resources for this USB host controller, and
145 * then invokes the start() method for the HCD associated with it
146 * through the hotplug entry's driver_data.
148 * Store this function in the HCD's struct pci_driver as probe().
150 int usb_hcd_sa1111_probe (const struct hc_driver *driver,
151 struct usb_hcd **hcd_out,
152 struct sa1111_dev *dev)
154 int retval;
155 struct usb_hcd *hcd = 0;
157 if (!request_mem_region(dev->res.start,
158 dev->res.end - dev->res.start + 1, hcd_name)) {
159 dbg("request_mem_region failed");
160 return -EBUSY;
163 sa1111_start_hc(dev);
165 hcd = driver->hcd_alloc ();
166 if (hcd == NULL){
167 dbg ("hcd_alloc failed");
168 retval = -ENOMEM;
169 goto err1;
172 hcd->driver = (struct hc_driver *) driver;
173 hcd->description = driver->description;
174 hcd->irq = dev->irq[1];
175 hcd->regs = dev->mapbase;
176 hcd->self.controller = &dev->dev;
178 retval = hcd_buffer_create (hcd);
179 if (retval != 0) {
180 dbg ("pool alloc fail");
181 goto err1;
184 retval = request_irq (hcd->irq, usb_hcd_sa1111_hcim_irq, SA_INTERRUPT,
185 hcd->description, hcd);
186 if (retval != 0) {
187 dbg("request_irq failed");
188 retval = -EBUSY;
189 goto err2;
192 info ("%s (SA-1111) at 0x%p, irq %d\n",
193 hcd->description, hcd->regs, hcd->irq);
195 usb_bus_init (&hcd->self);
196 hcd->self.op = &usb_hcd_operations;
197 hcd->self.hcpriv = (void *) hcd;
198 hcd->self.bus_name = "sa1111";
199 hcd->product_desc = "SA-1111 OHCI";
201 INIT_LIST_HEAD (&hcd->dev_list);
203 usb_register_bus (&hcd->self);
205 if ((retval = driver->start (hcd)) < 0)
207 usb_hcd_sa1111_remove(hcd, dev);
208 return retval;
211 *hcd_out = hcd;
212 return 0;
214 err2:
215 hcd_buffer_destroy (hcd);
216 if (hcd)
217 driver->hcd_free(hcd);
218 err1:
219 sa1111_stop_hc(dev);
220 release_mem_region(dev->res.start, dev->res.end - dev->res.start + 1);
221 return retval;
225 /* may be called without controller electrically present */
226 /* may be called with controller, bus, and devices active */
229 * usb_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
230 * @dev: USB Host Controller being removed
231 * Context: !in_interrupt()
233 * Reverses the effect of usb_hcd_sa1111_probe(), first invoking
234 * the HCD's stop() method. It is always called from a thread
235 * context, normally "rmmod", "apmd", or something similar.
238 void usb_hcd_sa1111_remove (struct usb_hcd *hcd, struct sa1111_dev *dev)
240 void *base;
242 info ("remove: %s, state %x", hcd->self.bus_name, hcd->state);
244 if (in_interrupt ())
245 BUG ();
247 hcd->state = USB_STATE_QUIESCING;
249 dbg ("%s: roothub graceful disconnect", hcd->self.bus_name);
250 usb_disconnect (&hcd->self.root_hub);
252 hcd->driver->stop (hcd);
253 hcd->state = USB_STATE_HALT;
255 free_irq (hcd->irq, hcd);
256 hcd_buffer_destroy (hcd);
258 usb_deregister_bus (&hcd->self);
260 base = hcd->regs;
261 hcd->driver->hcd_free (hcd);
263 sa1111_stop_hc(dev);
264 release_mem_region(dev->res.start, dev->res.end - dev->res.start + 1);
267 /*-------------------------------------------------------------------------*/
269 static int __devinit
270 ohci_sa1111_start (struct usb_hcd *hcd)
272 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
273 int ret;
275 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
276 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
277 if (!ohci->hcca)
278 return -ENOMEM;
280 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
281 if ((ret = ohci_mem_init (ohci)) < 0) {
282 ohci_stop (hcd);
283 return ret;
285 ohci->regs = hcd->regs;
287 if (hc_reset (ohci) < 0) {
288 ohci_stop (hcd);
289 return -ENODEV;
292 if (hc_start (ohci) < 0) {
293 err ("can't start %s", ohci->hcd.self.bus_name);
294 ohci_stop (hcd);
295 return -EBUSY;
297 create_debug_files (ohci);
299 #ifdef DEBUG
300 ohci_dump (ohci, 1);
301 #endif
302 return 0;
305 /*-------------------------------------------------------------------------*/
307 static const struct hc_driver ohci_sa1111_hc_driver = {
308 .description = hcd_name,
311 * generic hardware linkage
313 .irq = ohci_irq,
314 .flags = HCD_USB11,
317 * basic lifecycle operations
319 .start = ohci_sa1111_start,
320 #ifdef CONFIG_PM
321 /* suspend: ohci_sa1111_suspend, -- tbd */
322 /* resume: ohci_sa1111_resume, -- tbd */
323 #endif
324 .stop = ohci_stop,
327 * memory lifecycle (except per-request)
329 .hcd_alloc = ohci_hcd_alloc,
330 .hcd_free = ohci_hcd_free,
333 * managing i/o requests and associated device resources
335 .urb_enqueue = ohci_urb_enqueue,
336 .urb_dequeue = ohci_urb_dequeue,
337 .endpoint_disable = ohci_endpoint_disable,
340 * scheduling support
342 .get_frame_number = ohci_get_frame,
345 * root hub support
347 .hub_status_data = ohci_hub_status_data,
348 .hub_control = ohci_hub_control,
349 #ifdef CONFIG_USB_SUSPEND
350 .hub_suspend = ohci_hub_suspend,
351 .hub_resume = ohci_hub_resume,
352 #endif
355 /*-------------------------------------------------------------------------*/
357 static int ohci_hcd_sa1111_drv_probe(struct sa1111_dev *dev)
359 struct usb_hcd *hcd = NULL;
360 int ret;
362 if (usb_disabled())
363 return -ENODEV;
365 ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, &hcd, dev);
367 if (ret == 0)
368 sa1111_set_drvdata(dev, hcd);
370 return ret;
373 static int ohci_hcd_sa1111_drv_remove(struct sa1111_dev *dev)
375 struct usb_hcd *hcd = sa1111_get_drvdata(dev);
377 usb_hcd_sa1111_remove(hcd, dev);
379 sa1111_set_drvdata(dev, NULL);
381 return 0;
384 static struct sa1111_driver ohci_hcd_sa1111_driver = {
385 .drv = {
386 .name = "sa1111-ohci",
388 .devid = SA1111_DEVID_USB,
389 .probe = ohci_hcd_sa1111_drv_probe,
390 .remove = ohci_hcd_sa1111_drv_remove,
393 static int __init ohci_hcd_sa1111_init (void)
395 dbg (DRIVER_INFO " (SA-1111)");
396 dbg ("block sizes: ed %d td %d",
397 sizeof (struct ed), sizeof (struct td));
399 return sa1111_driver_register(&ohci_hcd_sa1111_driver);
402 static void __exit ohci_hcd_sa1111_cleanup (void)
404 sa1111_driver_unregister(&ohci_hcd_sa1111_driver);
407 module_init (ohci_hcd_sa1111_init);
408 module_exit (ohci_hcd_sa1111_cleanup);