Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 pxa27x |
| 9 | * |
| 10 | * Written by Christopher Hoover <ch@hpl.hp.com> |
| 11 | * Based on fragments of previous driver by Russell King et al. |
| 12 | * |
| 13 | * Modified for LH7A404 from ohci-sa1111.c |
| 14 | * by Durgesh Pattamatta <pattamattad@sharpsec.com> |
| 15 | * |
| 16 | * Modified for pxa27x from ohci-lh7a404.c |
| 17 | * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004 |
| 18 | * |
| 19 | * This file is licenced under the GPL. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/device.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 23 | #include <linux/signal.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
Linus Torvalds | 4fd5f82 | 2005-10-31 07:32:56 -0800 | [diff] [blame^] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/mach-types.h> |
| 27 | #include <asm/hardware.h> |
| 28 | #include <asm/arch/pxa-regs.h> |
| 29 | |
| 30 | |
| 31 | #define PMM_NPS_MODE 1 |
| 32 | #define PMM_GLOBAL_MODE 2 |
| 33 | #define PMM_PERPORT_MODE 3 |
| 34 | |
| 35 | #define PXA_UHC_MAX_PORTNUM 3 |
| 36 | |
| 37 | #define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 ) |
| 38 | |
| 39 | static int pxa27x_ohci_pmm_state; |
| 40 | |
| 41 | /* |
| 42 | PMM_NPS_MODE -- PMM Non-power switching mode |
| 43 | Ports are powered continuously. |
| 44 | |
| 45 | PMM_GLOBAL_MODE -- PMM global switching mode |
| 46 | All ports are powered at the same time. |
| 47 | |
| 48 | PMM_PERPORT_MODE -- PMM per port switching mode |
| 49 | Ports are powered individually. |
| 50 | */ |
| 51 | static int pxa27x_ohci_select_pmm( int mode ) |
| 52 | { |
| 53 | pxa27x_ohci_pmm_state = mode; |
| 54 | |
| 55 | switch ( mode ) { |
| 56 | case PMM_NPS_MODE: |
| 57 | UHCRHDA |= RH_A_NPS; |
| 58 | break; |
| 59 | case PMM_GLOBAL_MODE: |
| 60 | UHCRHDA &= ~(RH_A_NPS & RH_A_PSM); |
| 61 | break; |
| 62 | case PMM_PERPORT_MODE: |
| 63 | UHCRHDA &= ~(RH_A_NPS); |
| 64 | UHCRHDA |= RH_A_PSM; |
| 65 | |
| 66 | /* Set port power control mask bits, only 3 ports. */ |
| 67 | UHCRHDB |= (0x7<<17); |
| 68 | break; |
| 69 | default: |
| 70 | printk( KERN_ERR |
| 71 | "Invalid mode %d, set to non-power switch mode.\n", |
| 72 | mode ); |
| 73 | |
| 74 | pxa27x_ohci_pmm_state = PMM_NPS_MODE; |
| 75 | UHCRHDA |= RH_A_NPS; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | extern int usb_disabled(void); |
| 82 | |
| 83 | /*-------------------------------------------------------------------------*/ |
| 84 | |
| 85 | static void pxa27x_start_hc(struct platform_device *dev) |
| 86 | { |
| 87 | pxa_set_cken(CKEN10_USBHOST, 1); |
| 88 | |
| 89 | UHCHR |= UHCHR_FHR; |
| 90 | udelay(11); |
| 91 | UHCHR &= ~UHCHR_FHR; |
| 92 | |
| 93 | UHCHR |= UHCHR_FSBIR; |
| 94 | while (UHCHR & UHCHR_FSBIR) |
| 95 | cpu_relax(); |
| 96 | |
| 97 | /* This could be properly abstracted away through the |
| 98 | device data the day more machines are supported and |
| 99 | their differences can be figured out correctly. */ |
| 100 | if (machine_is_mainstone()) { |
| 101 | /* setup Port1 GPIO pin. */ |
| 102 | pxa_gpio_mode( 88 | GPIO_ALT_FN_1_IN); /* USBHPWR1 */ |
| 103 | pxa_gpio_mode( 89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */ |
| 104 | |
| 105 | /* Set the Power Control Polarity Low and Power Sense |
| 106 | Polarity Low to active low. Supply power to USB ports. */ |
| 107 | UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) & |
| 108 | ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE); |
David Brownell | 155faf5 | 2005-08-31 11:54:09 -0700 | [diff] [blame] | 109 | |
| 110 | pxa27x_ohci_pmm_state = PMM_PERPORT_MODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | UHCHR &= ~UHCHR_SSE; |
| 114 | |
| 115 | UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE); |
David Brownell | 155faf5 | 2005-08-31 11:54:09 -0700 | [diff] [blame] | 116 | |
| 117 | /* Clear any OTG Pin Hold */ |
| 118 | if (PSSR & PSSR_OTGPH) |
| 119 | PSSR |= PSSR_OTGPH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static void pxa27x_stop_hc(struct platform_device *dev) |
| 123 | { |
| 124 | UHCHR |= UHCHR_FHR; |
| 125 | udelay(11); |
| 126 | UHCHR &= ~UHCHR_FHR; |
| 127 | |
| 128 | UHCCOMS |= 1; |
| 129 | udelay(10); |
| 130 | |
| 131 | pxa_set_cken(CKEN10_USBHOST, 0); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /*-------------------------------------------------------------------------*/ |
| 136 | |
| 137 | /* configure so an HC device and id are always provided */ |
| 138 | /* always called with process context; sleeping is OK */ |
| 139 | |
| 140 | |
| 141 | /** |
| 142 | * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs |
| 143 | * Context: !in_interrupt() |
| 144 | * |
| 145 | * Allocates basic resources for this USB host controller, and |
| 146 | * then invokes the start() method for the HCD associated with it |
| 147 | * through the hotplug entry's driver_data. |
| 148 | * |
| 149 | */ |
| 150 | int usb_hcd_pxa27x_probe (const struct hc_driver *driver, |
| 151 | struct platform_device *dev) |
| 152 | { |
| 153 | int retval; |
| 154 | struct usb_hcd *hcd; |
| 155 | |
| 156 | if (dev->resource[1].flags != IORESOURCE_IRQ) { |
| 157 | pr_debug ("resource[1] is not IORESOURCE_IRQ"); |
| 158 | return -ENOMEM; |
| 159 | } |
| 160 | |
| 161 | hcd = usb_create_hcd (driver, &dev->dev, "pxa27x"); |
| 162 | if (!hcd) |
| 163 | return -ENOMEM; |
| 164 | hcd->rsrc_start = dev->resource[0].start; |
| 165 | hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; |
| 166 | |
| 167 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 168 | pr_debug("request_mem_region failed"); |
| 169 | retval = -EBUSY; |
| 170 | goto err1; |
| 171 | } |
| 172 | |
| 173 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 174 | if (!hcd->regs) { |
| 175 | pr_debug("ioremap failed"); |
| 176 | retval = -ENOMEM; |
| 177 | goto err2; |
| 178 | } |
| 179 | |
| 180 | pxa27x_start_hc(dev); |
| 181 | |
| 182 | /* Select Power Management Mode */ |
David Brownell | 155faf5 | 2005-08-31 11:54:09 -0700 | [diff] [blame] | 183 | pxa27x_ohci_select_pmm(pxa27x_ohci_pmm_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 186 | |
| 187 | retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT); |
| 188 | if (retval == 0) |
| 189 | return retval; |
| 190 | |
| 191 | pxa27x_stop_hc(dev); |
| 192 | iounmap(hcd->regs); |
| 193 | err2: |
| 194 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 195 | err1: |
| 196 | usb_put_hcd(hcd); |
| 197 | return retval; |
| 198 | } |
| 199 | |
| 200 | |
| 201 | /* may be called without controller electrically present */ |
| 202 | /* may be called with controller, bus, and devices active */ |
| 203 | |
| 204 | /** |
| 205 | * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs |
| 206 | * @dev: USB Host Controller being removed |
| 207 | * Context: !in_interrupt() |
| 208 | * |
| 209 | * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking |
| 210 | * the HCD's stop() method. It is always called from a thread |
| 211 | * context, normally "rmmod", "apmd", or something similar. |
| 212 | * |
| 213 | */ |
| 214 | void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *dev) |
| 215 | { |
| 216 | usb_remove_hcd(hcd); |
| 217 | pxa27x_stop_hc(dev); |
| 218 | iounmap(hcd->regs); |
| 219 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 220 | usb_put_hcd(hcd); |
| 221 | } |
| 222 | |
| 223 | /*-------------------------------------------------------------------------*/ |
| 224 | |
| 225 | static int __devinit |
| 226 | ohci_pxa27x_start (struct usb_hcd *hcd) |
| 227 | { |
| 228 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 229 | int ret; |
| 230 | |
| 231 | ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci); |
| 232 | |
David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 233 | /* The value of NDP in roothub_a is incorrect on this hardware */ |
| 234 | ohci->num_ports = 3; |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | if ((ret = ohci_init(ohci)) < 0) |
| 237 | return ret; |
| 238 | |
| 239 | if ((ret = ohci_run (ohci)) < 0) { |
| 240 | err ("can't start %s", hcd->self.bus_name); |
| 241 | ohci_stop (hcd); |
| 242 | return ret; |
| 243 | } |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /*-------------------------------------------------------------------------*/ |
| 249 | |
| 250 | static const struct hc_driver ohci_pxa27x_hc_driver = { |
| 251 | .description = hcd_name, |
| 252 | .product_desc = "PXA27x OHCI", |
| 253 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 254 | |
| 255 | /* |
| 256 | * generic hardware linkage |
| 257 | */ |
| 258 | .irq = ohci_irq, |
| 259 | .flags = HCD_USB11 | HCD_MEMORY, |
| 260 | |
| 261 | /* |
| 262 | * basic lifecycle operations |
| 263 | */ |
| 264 | .start = ohci_pxa27x_start, |
| 265 | .stop = ohci_stop, |
| 266 | |
| 267 | /* |
| 268 | * managing i/o requests and associated device resources |
| 269 | */ |
| 270 | .urb_enqueue = ohci_urb_enqueue, |
| 271 | .urb_dequeue = ohci_urb_dequeue, |
| 272 | .endpoint_disable = ohci_endpoint_disable, |
| 273 | |
| 274 | /* |
| 275 | * scheduling support |
| 276 | */ |
| 277 | .get_frame_number = ohci_get_frame, |
| 278 | |
| 279 | /* |
| 280 | * root hub support |
| 281 | */ |
| 282 | .hub_status_data = ohci_hub_status_data, |
| 283 | .hub_control = ohci_hub_control, |
David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 284 | #ifdef CONFIG_PM |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 285 | .bus_suspend = ohci_bus_suspend, |
| 286 | .bus_resume = ohci_bus_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | #endif |
David Brownell | 9293677 | 2005-09-22 22:32:11 -0700 | [diff] [blame] | 288 | .start_port_reset = ohci_start_port_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | /*-------------------------------------------------------------------------*/ |
| 292 | |
| 293 | static int ohci_hcd_pxa27x_drv_probe(struct device *dev) |
| 294 | { |
| 295 | struct platform_device *pdev = to_platform_device(dev); |
| 296 | int ret; |
| 297 | |
| 298 | pr_debug ("In ohci_hcd_pxa27x_drv_probe"); |
| 299 | |
| 300 | if (usb_disabled()) |
| 301 | return -ENODEV; |
| 302 | |
| 303 | ret = usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev); |
| 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | static int ohci_hcd_pxa27x_drv_remove(struct device *dev) |
| 308 | { |
| 309 | struct platform_device *pdev = to_platform_device(dev); |
| 310 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 311 | |
| 312 | usb_hcd_pxa27x_remove(hcd, pdev); |
| 313 | return 0; |
| 314 | } |
| 315 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 316 | static int ohci_hcd_pxa27x_drv_suspend(struct device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
| 318 | // struct platform_device *pdev = to_platform_device(dev); |
| 319 | // struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 320 | printk("%s: not implemented yet\n", __FUNCTION__); |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 325 | static int ohci_hcd_pxa27x_drv_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
| 327 | // struct platform_device *pdev = to_platform_device(dev); |
| 328 | // struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 329 | printk("%s: not implemented yet\n", __FUNCTION__); |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | |
| 335 | static struct device_driver ohci_hcd_pxa27x_driver = { |
| 336 | .name = "pxa27x-ohci", |
| 337 | .bus = &platform_bus_type, |
| 338 | .probe = ohci_hcd_pxa27x_drv_probe, |
| 339 | .remove = ohci_hcd_pxa27x_drv_remove, |
| 340 | .suspend = ohci_hcd_pxa27x_drv_suspend, |
| 341 | .resume = ohci_hcd_pxa27x_drv_resume, |
| 342 | }; |
| 343 | |
| 344 | static int __init ohci_hcd_pxa27x_init (void) |
| 345 | { |
| 346 | pr_debug (DRIVER_INFO " (pxa27x)"); |
| 347 | pr_debug ("block sizes: ed %d td %d\n", |
| 348 | sizeof (struct ed), sizeof (struct td)); |
| 349 | |
| 350 | return driver_register(&ohci_hcd_pxa27x_driver); |
| 351 | } |
| 352 | |
| 353 | static void __exit ohci_hcd_pxa27x_cleanup (void) |
| 354 | { |
| 355 | driver_unregister(&ohci_hcd_pxa27x_driver); |
| 356 | } |
| 357 | |
| 358 | module_init (ohci_hcd_pxa27x_init); |
| 359 | module_exit (ohci_hcd_pxa27x_cleanup); |