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
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
16 * Modified for pxa27x from ohci-lh7a404.c
17 * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
19 * This file is licenced under the GPL.
22 #include <linux/device.h>
23 #include <asm/mach-types.h>
24 #include <asm/hardware.h>
25 #include <asm/arch/pxa-regs.h>
28 #define PMM_NPS_MODE 1
29 #define PMM_GLOBAL_MODE 2
30 #define PMM_PERPORT_MODE 3
32 #define PXA_UHC_MAX_PORTNUM 3
34 #define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 )
36 static int pxa27x_ohci_pmm_state;
39 PMM_NPS_MODE -- PMM Non-power switching mode
40 Ports are powered continuously.
42 PMM_GLOBAL_MODE -- PMM global switching mode
43 All ports are powered at the same time.
45 PMM_PERPORT_MODE -- PMM per port switching mode
46 Ports are powered individually.
48 static int pxa27x_ohci_select_pmm( int mode )
50 pxa27x_ohci_pmm_state = mode;
57 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
59 case PMM_PERPORT_MODE:
60 UHCRHDA &= ~(RH_A_NPS);
63 /* Set port power control mask bits, only 3 ports. */
68 "Invalid mode %d, set to non-power switch mode.\n",
71 pxa27x_ohci_pmm_state = PMM_NPS_MODE;
79 If you select PMM_PERPORT_MODE, you should set the port power
81 static int pxa27x_ohci_set_port_power( int port )
83 if ( (pxa27x_ohci_pmm_state==PMM_PERPORT_MODE)
84 && (port>0) && (port<PXA_UHC_MAX_PORTNUM) ) {
85 UHCRHPS(port) |= 0x100;
92 If you select PMM_PERPORT_MODE, you should set the port power
94 static int pxa27x_ohci_clear_port_power( int port )
96 if ( (pxa27x_ohci_pmm_state==PMM_PERPORT_MODE)
97 && (port>0) && (port<PXA_UHC_MAX_PORTNUM) ) {
98 UHCRHPS(port) |= 0x200;
105 extern int usb_disabled(void);
107 /*-------------------------------------------------------------------------*/
109 static void pxa27x_start_hc(struct platform_device *dev)
111 pxa_set_cken(CKEN10_USBHOST, 1);
117 UHCHR |= UHCHR_FSBIR;
118 while (UHCHR & UHCHR_FSBIR)
121 /* This could be properly abstracted away through the
122 device data the day more machines are supported and
123 their differences can be figured out correctly. */
124 if (machine_is_mainstone()) {
125 /* setup Port1 GPIO pin. */
126 pxa_gpio_mode( 88 | GPIO_ALT_FN_1_IN); /* USBHPWR1 */
127 pxa_gpio_mode( 89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */
129 /* Set the Power Control Polarity Low and Power Sense
130 Polarity Low to active low. Supply power to USB ports. */
131 UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
132 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
137 UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
140 static void pxa27x_stop_hc(struct platform_device *dev)
149 pxa_set_cken(CKEN10_USBHOST, 0);
153 /*-------------------------------------------------------------------------*/
155 void usb_hcd_pxa27x_remove (struct usb_hcd *, struct platform_device *);
157 /* configure so an HC device and id are always provided */
158 /* always called with process context; sleeping is OK */
162 * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
163 * Context: !in_interrupt()
165 * Allocates basic resources for this USB host controller, and
166 * then invokes the start() method for the HCD associated with it
167 * through the hotplug entry's driver_data.
170 int usb_hcd_pxa27x_probe (const struct hc_driver *driver,
171 struct usb_hcd **hcd_out,
172 struct platform_device *dev)
175 struct usb_hcd *hcd = 0;
177 unsigned int *addr = NULL;
179 if (!request_mem_region(dev->resource[0].start,
181 - dev->resource[0].start + 1, hcd_name)) {
182 pr_debug("request_mem_region failed");
186 pxa27x_start_hc(dev);
188 /* Select Power Management Mode */
189 pxa27x_ohci_select_pmm( PMM_PERPORT_MODE );
191 /* If choosing PMM_PERPORT_MODE, we should set the port power before we use it. */
192 if (pxa27x_ohci_set_port_power(1) < 0)
193 printk(KERN_ERR "Setting port 1 power failed.\n");
195 if (pxa27x_ohci_clear_port_power(2) < 0)
196 printk(KERN_ERR "Setting port 2 power failed.\n");
198 if (pxa27x_ohci_clear_port_power(3) < 0)
199 printk(KERN_ERR "Setting port 3 power failed.\n");
201 addr = ioremap(dev->resource[0].start,
202 dev->resource[0].end - dev->resource[0].start + 1);
204 pr_debug("ioremap failed");
209 hcd = driver->hcd_alloc ();
211 pr_debug ("hcd_alloc failed");
216 if(dev->resource[1].flags != IORESOURCE_IRQ){
217 pr_debug ("resource[1] is not IORESOURCE_IRQ");
222 hcd->driver = (struct hc_driver *) driver;
223 hcd->description = driver->description;
224 hcd->irq = dev->resource[1].start;
226 hcd->self.controller = &dev->dev;
228 retval = hcd_buffer_create (hcd);
230 pr_debug ("pool alloc fail");
234 retval = request_irq (hcd->irq, usb_hcd_irq, SA_INTERRUPT,
235 hcd->description, hcd);
237 pr_debug("request_irq(%d) failed with retval %d\n",hcd->irq,retval);
242 pr_debug ("%s (pxa27x) at 0x%p, irq %d",
243 hcd->description, hcd->regs, hcd->irq);
245 usb_bus_init (&hcd->self);
246 hcd->self.op = &usb_hcd_operations;
247 hcd->self.release = &usb_hcd_release;
248 hcd->self.hcpriv = (void *) hcd;
249 hcd->self.bus_name = "pxa27x";
250 hcd->product_desc = "PXA27x OHCI";
252 INIT_LIST_HEAD (&hcd->dev_list);
254 usb_register_bus (&hcd->self);
256 if ((retval = driver->start (hcd)) < 0) {
257 usb_hcd_pxa27x_remove(hcd, dev);
265 hcd_buffer_destroy (hcd);
269 release_mem_region(dev->resource[0].start,
271 - dev->resource[0].start + 1);
276 /* may be called without controller electrically present */
277 /* may be called with controller, bus, and devices active */
280 * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
281 * @dev: USB Host Controller being removed
282 * Context: !in_interrupt()
284 * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
285 * the HCD's stop() method. It is always called from a thread
286 * context, normally "rmmod", "apmd", or something similar.
289 void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *dev)
291 pr_debug ("remove: %s, state %x", hcd->self.bus_name, hcd->state);
296 hcd->state = USB_STATE_QUIESCING;
298 pr_debug ("%s: roothub graceful disconnect", hcd->self.bus_name);
299 usb_disconnect (&hcd->self.root_hub);
301 hcd->driver->stop (hcd);
302 hcd->state = USB_STATE_HALT;
304 free_irq (hcd->irq, hcd);
305 hcd_buffer_destroy (hcd);
307 usb_deregister_bus (&hcd->self);
310 release_mem_region(dev->resource[0].start,
311 dev->resource[0].end - dev->resource[0].start + 1);
314 /*-------------------------------------------------------------------------*/
317 ohci_pxa27x_start (struct usb_hcd *hcd)
319 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
322 ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
324 if ((ret = ohci_init(ohci)) < 0)
327 if ((ret = ohci_run (ohci)) < 0) {
328 err ("can't start %s", ohci->hcd.self.bus_name);
336 /*-------------------------------------------------------------------------*/
338 static const struct hc_driver ohci_pxa27x_hc_driver = {
339 .description = hcd_name,
342 * generic hardware linkage
348 * basic lifecycle operations
350 .start = ohci_pxa27x_start,
354 * memory lifecycle (except per-request)
356 .hcd_alloc = ohci_hcd_alloc,
359 * managing i/o requests and associated device resources
361 .urb_enqueue = ohci_urb_enqueue,
362 .urb_dequeue = ohci_urb_dequeue,
363 .endpoint_disable = ohci_endpoint_disable,
368 .get_frame_number = ohci_get_frame,
373 .hub_status_data = ohci_hub_status_data,
374 .hub_control = ohci_hub_control,
375 #ifdef CONFIG_USB_SUSPEND
376 .hub_suspend = ohci_hub_suspend,
377 .hub_resume = ohci_hub_resume,
381 /*-------------------------------------------------------------------------*/
383 static int ohci_hcd_pxa27x_drv_probe(struct device *dev)
385 struct platform_device *pdev = to_platform_device(dev);
386 struct usb_hcd *hcd = NULL;
389 pr_debug ("In ohci_hcd_pxa27x_drv_probe");
394 ret = usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, &hcd, pdev);
397 dev_set_drvdata(dev, hcd);
402 static int ohci_hcd_pxa27x_drv_remove(struct device *dev)
404 struct platform_device *pdev = to_platform_device(dev);
405 struct usb_hcd *hcd = dev_get_drvdata(dev);
407 usb_hcd_pxa27x_remove(hcd, pdev);
408 dev_set_drvdata(dev, NULL);
412 static int ohci_hcd_pxa27x_drv_suspend(struct device *dev, u32 state, u32 level)
414 // struct platform_device *pdev = to_platform_device(dev);
415 // struct usb_hcd *hcd = dev_get_drvdata(dev);
416 printk("%s: not implemented yet\n", __FUNCTION__);
421 static int ohci_hcd_pxa27x_drv_resume(struct device *dev, u32 state)
423 // struct platform_device *pdev = to_platform_device(dev);
424 // struct usb_hcd *hcd = dev_get_drvdata(dev);
425 printk("%s: not implemented yet\n", __FUNCTION__);
431 static struct device_driver ohci_hcd_pxa27x_driver = {
432 .name = "pxa27x-ohci",
433 .bus = &platform_bus_type,
434 .probe = ohci_hcd_pxa27x_drv_probe,
435 .remove = ohci_hcd_pxa27x_drv_remove,
436 .suspend = ohci_hcd_pxa27x_drv_suspend,
437 .resume = ohci_hcd_pxa27x_drv_resume,
440 static int __init ohci_hcd_pxa27x_init (void)
442 pr_debug (DRIVER_INFO " (pxa27x)");
443 pr_debug ("block sizes: ed %d td %d\n",
444 sizeof (struct ed), sizeof (struct td));
446 return driver_register(&ohci_hcd_pxa27x_driver);
449 static void __exit ohci_hcd_pxa27x_cleanup (void)
451 driver_unregister(&ohci_hcd_pxa27x_driver);
454 module_init (ohci_hcd_pxa27x_init);
455 module_exit (ohci_hcd_pxa27x_cleanup);