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
8 * Bus Glue for Sharp LH7A404
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Rusell King et al.
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
16 * This file is licenced under the GPL.
19 #include <asm/hardware.h>
20 #include <asm/mach-types.h>
21 #include <asm/arch/hardware.h>
24 extern int usb_disabled(void);
26 /*-------------------------------------------------------------------------*/
28 static void lh7a404_start_hc(struct platform_device *dev)
30 printk(KERN_DEBUG __FILE__
31 ": starting LH7A404 OHCI USB Controller\n");
34 * Now, carefully enable the USB clock, and take
35 * the USB host controller out of reset.
37 CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */
39 USBH_CMDSTATUS = OHCI_HCR;
41 printk(KERN_DEBUG __FILE__
42 ": Clock to USB host has been enabled \n");
45 static void lh7a404_stop_hc(struct platform_device *dev)
47 printk(KERN_DEBUG __FILE__
48 ": stopping LH7A404 OHCI USB Controller\n");
50 CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */
54 /*-------------------------------------------------------------------------*/
57 static irqreturn_t usb_hcd_lh7a404_hcim_irq (int irq, void *__hcd,
60 struct usb_hcd *hcd = __hcd;
62 return usb_hcd_irq(irq, hcd, r);
65 /*-------------------------------------------------------------------------*/
67 void usb_hcd_lh7a404_remove (struct usb_hcd *, struct platform_device *);
69 /* configure so an HC device and id are always provided */
70 /* always called with process context; sleeping is OK */
74 * usb_hcd_lh7a404_probe - initialize LH7A404-based HCDs
75 * Context: !in_interrupt()
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.
82 int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
83 struct usb_hcd **hcd_out,
84 struct platform_device *dev)
87 struct usb_hcd *hcd = 0;
89 unsigned int *addr = NULL;
91 if (!request_mem_region(dev->resource[0].start,
93 - dev->resource[0].start + 1, hcd_name)) {
94 pr_debug("request_mem_region failed");
99 lh7a404_start_hc(dev);
101 addr = ioremap(dev->resource[0].start,
103 - dev->resource[0].start + 1);
105 pr_debug("ioremap failed");
111 hcd = driver->hcd_alloc ();
113 pr_debug ("hcd_alloc failed");
118 if(dev->resource[1].flags != IORESOURCE_IRQ){
119 pr_debug ("resource[1] is not IORESOURCE_IRQ");
124 hcd->driver = (struct hc_driver *) driver;
125 hcd->description = driver->description;
126 hcd->irq = dev->resource[1].start;
128 hcd->self.controller = &dev->dev;
130 retval = hcd_buffer_create (hcd);
132 pr_debug ("pool alloc fail");
136 retval = request_irq (hcd->irq, usb_hcd_lh7a404_hcim_irq, SA_INTERRUPT,
137 hcd->description, hcd);
139 pr_debug("request_irq failed");
144 pr_debug ("%s (LH7A404) at 0x%p, irq %d",
145 hcd->description, hcd->regs, hcd->irq);
147 usb_bus_init (&hcd->self);
148 hcd->self.op = &usb_hcd_operations;
149 hcd->self.release = &usb_hcd_release;
150 hcd->self.hcpriv = (void *) hcd;
151 hcd->self.bus_name = "lh7a404";
152 hcd->product_desc = "LH7A404 OHCI";
154 INIT_LIST_HEAD (&hcd->dev_list);
156 usb_register_bus (&hcd->self);
158 if ((retval = driver->start (hcd)) < 0)
160 usb_hcd_lh7a404_remove(hcd, dev);
168 hcd_buffer_destroy (hcd);
171 lh7a404_stop_hc(dev);
172 release_mem_region(dev->resource[0].start,
174 - dev->resource[0].start + 1);
179 /* may be called without controller electrically present */
180 /* may be called with controller, bus, and devices active */
183 * usb_hcd_lh7a404_remove - shutdown processing for LH7A404-based HCDs
184 * @dev: USB Host Controller being removed
185 * Context: !in_interrupt()
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.
192 void usb_hcd_lh7a404_remove (struct usb_hcd *hcd, struct platform_device *dev)
194 pr_debug ("remove: %s, state %x", hcd->self.bus_name, hcd->state);
199 hcd->state = USB_STATE_QUIESCING;
201 pr_debug ("%s: roothub graceful disconnect", hcd->self.bus_name);
202 usb_disconnect (&hcd->self.root_hub);
204 hcd->driver->stop (hcd);
205 hcd->state = USB_STATE_HALT;
207 free_irq (hcd->irq, hcd);
208 hcd_buffer_destroy (hcd);
210 usb_deregister_bus (&hcd->self);
212 lh7a404_stop_hc(dev);
213 release_mem_region(dev->resource[0].start,
215 - dev->resource[0].start + 1);
218 /*-------------------------------------------------------------------------*/
221 ohci_lh7a404_start (struct usb_hcd *hcd)
223 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
226 ohci_dbg (ohci, "ohci_lh7a404_start, ohci:%p", ohci);
227 if ((ret = ohci_init(ohci)) < 0)
230 if ((ret = ohci_run (ohci)) < 0) {
231 err ("can't start %s", ohci->hcd.self.bus_name);
238 /*-------------------------------------------------------------------------*/
240 static const struct hc_driver ohci_lh7a404_hc_driver = {
241 .description = hcd_name,
244 * generic hardware linkage
250 * basic lifecycle operations
252 .start = ohci_lh7a404_start,
254 /* suspend: ohci_lh7a404_suspend, -- tbd */
255 /* resume: ohci_lh7a404_resume, -- tbd */
260 * memory lifecycle (except per-request)
262 .hcd_alloc = ohci_hcd_alloc,
265 * managing i/o requests and associated device resources
267 .urb_enqueue = ohci_urb_enqueue,
268 .urb_dequeue = ohci_urb_dequeue,
269 .endpoint_disable = ohci_endpoint_disable,
274 .get_frame_number = ohci_get_frame,
279 .hub_status_data = ohci_hub_status_data,
280 .hub_control = ohci_hub_control,
283 /*-------------------------------------------------------------------------*/
285 static int ohci_hcd_lh7a404_drv_probe(struct device *dev)
287 struct platform_device *pdev = to_platform_device(dev);
288 struct usb_hcd *hcd = NULL;
291 pr_debug ("In ohci_hcd_lh7a404_drv_probe");
296 ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, &hcd, pdev);
299 dev_set_drvdata(dev, hcd);
304 static int ohci_hcd_lh7a404_drv_remove(struct device *dev)
306 struct platform_device *pdev = to_platform_device(dev);
307 struct usb_hcd *hcd = dev_get_drvdata(dev);
309 usb_hcd_lh7a404_remove(hcd, pdev);
310 dev_set_drvdata(dev, NULL);
314 /*static int ohci_hcd_lh7a404_drv_suspend(struct device *dev)
316 struct platform_device *pdev = to_platform_device(dev);
317 struct usb_hcd *hcd = dev_get_drvdata(dev);
321 static int ohci_hcd_lh7a404_drv_resume(struct device *dev)
323 struct platform_device *pdev = to_platform_device(dev);
324 struct usb_hcd *hcd = dev_get_drvdata(dev);
331 static struct device_driver ohci_hcd_lh7a404_driver = {
332 .name = "lh7a404-ohci",
333 .bus = &platform_bus_type,
334 .probe = ohci_hcd_lh7a404_drv_probe,
335 .remove = ohci_hcd_lh7a404_drv_remove,
336 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
337 /*.resume = ohci_hcd_lh7a404_drv_resume, */
340 static int __init ohci_hcd_lh7a404_init (void)
342 pr_debug (DRIVER_INFO " (LH7A404)");
343 pr_debug ("block sizes: ed %d td %d\n",
344 sizeof (struct ed), sizeof (struct td));
346 return driver_register(&ohci_hcd_lh7a404_driver);
349 static void __exit ohci_hcd_lh7a404_cleanup (void)
351 driver_unregister(&ohci_hcd_lh7a404_driver);
354 module_init (ohci_hcd_lh7a404_init);
355 module_exit (ohci_hcd_lh7a404_cleanup);