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> |
eric miao | a8bcf41 | 2007-12-12 08:53:25 +0800 | [diff] [blame] | 25 | #include <linux/clk.h> |
Linus Torvalds | 4fd5f82 | 2005-10-31 07:32:56 -0800 | [diff] [blame] | 26 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/hardware.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/pxa2xx-regs.h> /* FIXME: for PSSR */ |
| 29 | #include <mach/ohci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Eric Miao | 596050b | 2008-09-27 16:12:32 +0800 | [diff] [blame] | 31 | /* |
| 32 | * UHC: USB Host Controller (OHCI-like) register definitions |
| 33 | */ |
| 34 | #define UHC_BASE_PHYS (0x4C000000) |
| 35 | #define UHCREV __REG(0x4C000000) /* UHC HCI Spec Revision */ |
| 36 | #define UHCHCON __REG(0x4C000004) /* UHC Host Control Register */ |
| 37 | #define UHCCOMS __REG(0x4C000008) /* UHC Command Status Register */ |
| 38 | #define UHCINTS __REG(0x4C00000C) /* UHC Interrupt Status Register */ |
| 39 | #define UHCINTE __REG(0x4C000010) /* UHC Interrupt Enable */ |
| 40 | #define UHCINTD __REG(0x4C000014) /* UHC Interrupt Disable */ |
| 41 | #define UHCHCCA __REG(0x4C000018) /* UHC Host Controller Comm. Area */ |
| 42 | #define UHCPCED __REG(0x4C00001C) /* UHC Period Current Endpt Descr */ |
| 43 | #define UHCCHED __REG(0x4C000020) /* UHC Control Head Endpt Descr */ |
| 44 | #define UHCCCED __REG(0x4C000024) /* UHC Control Current Endpt Descr */ |
| 45 | #define UHCBHED __REG(0x4C000028) /* UHC Bulk Head Endpt Descr */ |
| 46 | #define UHCBCED __REG(0x4C00002C) /* UHC Bulk Current Endpt Descr */ |
| 47 | #define UHCDHEAD __REG(0x4C000030) /* UHC Done Head */ |
| 48 | #define UHCFMI __REG(0x4C000034) /* UHC Frame Interval */ |
| 49 | #define UHCFMR __REG(0x4C000038) /* UHC Frame Remaining */ |
| 50 | #define UHCFMN __REG(0x4C00003C) /* UHC Frame Number */ |
| 51 | #define UHCPERS __REG(0x4C000040) /* UHC Periodic Start */ |
| 52 | #define UHCLS __REG(0x4C000044) /* UHC Low Speed Threshold */ |
| 53 | |
| 54 | #define UHCRHDA __REG(0x4C000048) /* UHC Root Hub Descriptor A */ |
| 55 | #define UHCRHDA_NOCP (1 << 12) /* No over current protection */ |
| 56 | #define UHCRHDA_OCPM (1 << 11) /* Over Current Protection Mode */ |
| 57 | #define UHCRHDA_POTPGT(x) \ |
| 58 | (((x) & 0xff) << 24) /* Power On To Power Good Time */ |
| 59 | |
| 60 | #define UHCRHDB __REG(0x4C00004C) /* UHC Root Hub Descriptor B */ |
| 61 | #define UHCRHS __REG(0x4C000050) /* UHC Root Hub Status */ |
| 62 | #define UHCRHPS1 __REG(0x4C000054) /* UHC Root Hub Port 1 Status */ |
| 63 | #define UHCRHPS2 __REG(0x4C000058) /* UHC Root Hub Port 2 Status */ |
| 64 | #define UHCRHPS3 __REG(0x4C00005C) /* UHC Root Hub Port 3 Status */ |
| 65 | |
| 66 | #define UHCSTAT __REG(0x4C000060) /* UHC Status Register */ |
| 67 | #define UHCSTAT_UPS3 (1 << 16) /* USB Power Sense Port3 */ |
| 68 | #define UHCSTAT_SBMAI (1 << 15) /* System Bus Master Abort Interrupt*/ |
| 69 | #define UHCSTAT_SBTAI (1 << 14) /* System Bus Target Abort Interrupt*/ |
| 70 | #define UHCSTAT_UPRI (1 << 13) /* USB Port Resume Interrupt */ |
| 71 | #define UHCSTAT_UPS2 (1 << 12) /* USB Power Sense Port 2 */ |
| 72 | #define UHCSTAT_UPS1 (1 << 11) /* USB Power Sense Port 1 */ |
| 73 | #define UHCSTAT_HTA (1 << 10) /* HCI Target Abort */ |
| 74 | #define UHCSTAT_HBA (1 << 8) /* HCI Buffer Active */ |
| 75 | #define UHCSTAT_RWUE (1 << 7) /* HCI Remote Wake Up Event */ |
| 76 | |
| 77 | #define UHCHR __REG(0x4C000064) /* UHC Reset Register */ |
| 78 | #define UHCHR_SSEP3 (1 << 11) /* Sleep Standby Enable for Port3 */ |
| 79 | #define UHCHR_SSEP2 (1 << 10) /* Sleep Standby Enable for Port2 */ |
| 80 | #define UHCHR_SSEP1 (1 << 9) /* Sleep Standby Enable for Port1 */ |
| 81 | #define UHCHR_PCPL (1 << 7) /* Power control polarity low */ |
| 82 | #define UHCHR_PSPL (1 << 6) /* Power sense polarity low */ |
| 83 | #define UHCHR_SSE (1 << 5) /* Sleep Standby Enable */ |
| 84 | #define UHCHR_UIT (1 << 4) /* USB Interrupt Test */ |
| 85 | #define UHCHR_SSDC (1 << 3) /* Simulation Scale Down Clock */ |
| 86 | #define UHCHR_CGR (1 << 2) /* Clock Generation Reset */ |
| 87 | #define UHCHR_FHR (1 << 1) /* Force Host Controller Reset */ |
| 88 | #define UHCHR_FSBIR (1 << 0) /* Force System Bus Iface Reset */ |
| 89 | |
| 90 | #define UHCHIE __REG(0x4C000068) /* UHC Interrupt Enable Register*/ |
| 91 | #define UHCHIE_UPS3IE (1 << 14) /* Power Sense Port3 IntEn */ |
| 92 | #define UHCHIE_UPRIE (1 << 13) /* Port Resume IntEn */ |
| 93 | #define UHCHIE_UPS2IE (1 << 12) /* Power Sense Port2 IntEn */ |
| 94 | #define UHCHIE_UPS1IE (1 << 11) /* Power Sense Port1 IntEn */ |
| 95 | #define UHCHIE_TAIE (1 << 10) /* HCI Interface Transfer Abort |
| 96 | Interrupt Enable*/ |
| 97 | #define UHCHIE_HBAIE (1 << 8) /* HCI Buffer Active IntEn */ |
| 98 | #define UHCHIE_RWIE (1 << 7) /* Remote Wake-up IntEn */ |
| 99 | |
| 100 | #define UHCHIT __REG(0x4C00006C) /* UHC Interrupt Test register */ |
| 101 | |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | #define PXA_UHC_MAX_PORTNUM 3 |
| 104 | |
| 105 | #define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 ) |
| 106 | |
eric miao | a8bcf41 | 2007-12-12 08:53:25 +0800 | [diff] [blame] | 107 | static struct clk *usb_clk; |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | /* |
| 110 | PMM_NPS_MODE -- PMM Non-power switching mode |
| 111 | Ports are powered continuously. |
| 112 | |
| 113 | PMM_GLOBAL_MODE -- PMM global switching mode |
| 114 | All ports are powered at the same time. |
| 115 | |
| 116 | PMM_PERPORT_MODE -- PMM per port switching mode |
| 117 | Ports are powered individually. |
| 118 | */ |
| 119 | static int pxa27x_ohci_select_pmm( int mode ) |
| 120 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | switch ( mode ) { |
| 122 | case PMM_NPS_MODE: |
| 123 | UHCRHDA |= RH_A_NPS; |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 124 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | case PMM_GLOBAL_MODE: |
| 126 | UHCRHDA &= ~(RH_A_NPS & RH_A_PSM); |
| 127 | break; |
| 128 | case PMM_PERPORT_MODE: |
| 129 | UHCRHDA &= ~(RH_A_NPS); |
| 130 | UHCRHDA |= RH_A_PSM; |
| 131 | |
| 132 | /* Set port power control mask bits, only 3 ports. */ |
| 133 | UHCRHDB |= (0x7<<17); |
| 134 | break; |
| 135 | default: |
| 136 | printk( KERN_ERR |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 137 | "Invalid mode %d, set to non-power switch mode.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | mode ); |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | UHCRHDA |= RH_A_NPS; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | extern int usb_disabled(void); |
| 147 | |
| 148 | /*-------------------------------------------------------------------------*/ |
| 149 | |
Eric Miao | 097b533 | 2008-09-27 15:49:57 +0800 | [diff] [blame] | 150 | static inline void pxa27x_setup_hc(struct pxaohci_platform_data *inf) |
| 151 | { |
| 152 | uint32_t uhchr = UHCHR; |
| 153 | uint32_t uhcrhda = UHCRHDA; |
| 154 | |
| 155 | if (inf->flags & ENABLE_PORT1) |
| 156 | uhchr &= ~UHCHR_SSEP1; |
| 157 | |
| 158 | if (inf->flags & ENABLE_PORT2) |
| 159 | uhchr &= ~UHCHR_SSEP2; |
| 160 | |
| 161 | if (inf->flags & ENABLE_PORT3) |
| 162 | uhchr &= ~UHCHR_SSEP3; |
| 163 | |
| 164 | if (inf->flags & POWER_CONTROL_LOW) |
| 165 | uhchr |= UHCHR_PCPL; |
| 166 | |
| 167 | if (inf->flags & POWER_SENSE_LOW) |
| 168 | uhchr |= UHCHR_PSPL; |
| 169 | |
| 170 | if (inf->flags & NO_OC_PROTECTION) |
| 171 | uhcrhda |= UHCRHDA_NOCP; |
| 172 | |
| 173 | if (inf->flags & OC_MODE_PERPORT) |
| 174 | uhcrhda |= UHCRHDA_OCPM; |
| 175 | |
| 176 | if (inf->power_on_delay) { |
| 177 | uhcrhda &= ~UHCRHDA_POTPGT(0xff); |
| 178 | uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2); |
| 179 | } |
| 180 | |
| 181 | UHCHR = uhchr; |
| 182 | UHCRHDA = uhcrhda; |
| 183 | } |
| 184 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 185 | static int pxa27x_start_hc(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 187 | int retval = 0; |
| 188 | struct pxaohci_platform_data *inf; |
| 189 | |
| 190 | inf = dev->platform_data; |
| 191 | |
eric miao | a8bcf41 | 2007-12-12 08:53:25 +0800 | [diff] [blame] | 192 | clk_enable(usb_clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | UHCHR |= UHCHR_FHR; |
| 195 | udelay(11); |
| 196 | UHCHR &= ~UHCHR_FHR; |
| 197 | |
| 198 | UHCHR |= UHCHR_FSBIR; |
| 199 | while (UHCHR & UHCHR_FSBIR) |
| 200 | cpu_relax(); |
| 201 | |
Eric Miao | 097b533 | 2008-09-27 15:49:57 +0800 | [diff] [blame] | 202 | pxa27x_setup_hc(inf); |
| 203 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 204 | if (inf->init) |
| 205 | retval = inf->init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 207 | if (retval < 0) |
| 208 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | UHCHR &= ~UHCHR_SSE; |
| 211 | |
| 212 | UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE); |
David Brownell | 155faf5 | 2005-08-31 11:54:09 -0700 | [diff] [blame] | 213 | |
| 214 | /* Clear any OTG Pin Hold */ |
Philipp Zabel | d438ae5 | 2008-06-06 18:40:47 +0100 | [diff] [blame] | 215 | if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH)) |
David Brownell | 155faf5 | 2005-08-31 11:54:09 -0700 | [diff] [blame] | 216 | PSSR |= PSSR_OTGPH; |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 217 | |
| 218 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 221 | static void pxa27x_stop_hc(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 223 | struct pxaohci_platform_data *inf; |
| 224 | |
| 225 | inf = dev->platform_data; |
| 226 | |
| 227 | if (inf->exit) |
| 228 | inf->exit(dev); |
| 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | UHCHR |= UHCHR_FHR; |
| 231 | udelay(11); |
| 232 | UHCHR &= ~UHCHR_FHR; |
| 233 | |
| 234 | UHCCOMS |= 1; |
| 235 | udelay(10); |
| 236 | |
eric miao | a8bcf41 | 2007-12-12 08:53:25 +0800 | [diff] [blame] | 237 | clk_disable(usb_clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | |
| 241 | /*-------------------------------------------------------------------------*/ |
| 242 | |
| 243 | /* configure so an HC device and id are always provided */ |
| 244 | /* always called with process context; sleeping is OK */ |
| 245 | |
| 246 | |
| 247 | /** |
| 248 | * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs |
| 249 | * Context: !in_interrupt() |
| 250 | * |
| 251 | * Allocates basic resources for this USB host controller, and |
| 252 | * then invokes the start() method for the HCD associated with it |
| 253 | * through the hotplug entry's driver_data. |
| 254 | * |
| 255 | */ |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 256 | int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
Eric Miao | 84bab73 | 2008-10-03 22:37:21 +0800 | [diff] [blame^] | 258 | int retval, irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | struct usb_hcd *hcd; |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 260 | struct pxaohci_platform_data *inf; |
Eric Miao | 84bab73 | 2008-10-03 22:37:21 +0800 | [diff] [blame^] | 261 | struct resource *r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 263 | inf = pdev->dev.platform_data; |
| 264 | |
| 265 | if (!inf) |
| 266 | return -ENODEV; |
| 267 | |
Eric Miao | 84bab73 | 2008-10-03 22:37:21 +0800 | [diff] [blame^] | 268 | irq = platform_get_irq(pdev, 0); |
| 269 | if (irq < 0) { |
| 270 | pr_err("no resource of IORESOURCE_IRQ"); |
| 271 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
eric miao | a8bcf41 | 2007-12-12 08:53:25 +0800 | [diff] [blame] | 274 | usb_clk = clk_get(&pdev->dev, "USBCLK"); |
| 275 | if (IS_ERR(usb_clk)) |
| 276 | return PTR_ERR(usb_clk); |
| 277 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 278 | hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (!hcd) |
| 280 | return -ENOMEM; |
Eric Miao | 84bab73 | 2008-10-03 22:37:21 +0800 | [diff] [blame^] | 281 | |
| 282 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 283 | if (!r) { |
| 284 | pr_err("no resource of IORESOURCE_MEM"); |
| 285 | retval = -ENXIO; |
| 286 | goto err1; |
| 287 | } |
| 288 | |
| 289 | hcd->rsrc_start = r->start; |
| 290 | hcd->rsrc_len = resource_size(r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 293 | pr_debug("request_mem_region failed"); |
| 294 | retval = -EBUSY; |
| 295 | goto err1; |
| 296 | } |
| 297 | |
| 298 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 299 | if (!hcd->regs) { |
| 300 | pr_debug("ioremap failed"); |
| 301 | retval = -ENOMEM; |
| 302 | goto err2; |
| 303 | } |
| 304 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 305 | if ((retval = pxa27x_start_hc(&pdev->dev)) < 0) { |
| 306 | pr_debug("pxa27x_start_hc failed"); |
| 307 | goto err3; |
| 308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | /* Select Power Management Mode */ |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 311 | pxa27x_ohci_select_pmm(inf->port_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Richard Purdie | 0c27c5d | 2006-06-08 22:44:07 +0100 | [diff] [blame] | 313 | if (inf->power_budget) |
| 314 | hcd->power_budget = inf->power_budget; |
| 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 317 | |
Eric Miao | 84bab73 | 2008-10-03 22:37:21 +0800 | [diff] [blame^] | 318 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | if (retval == 0) |
| 320 | return retval; |
| 321 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 322 | pxa27x_stop_hc(&pdev->dev); |
| 323 | err3: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | iounmap(hcd->regs); |
| 325 | err2: |
| 326 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 327 | err1: |
| 328 | usb_put_hcd(hcd); |
eric miao | a8bcf41 | 2007-12-12 08:53:25 +0800 | [diff] [blame] | 329 | clk_put(usb_clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return retval; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /* may be called without controller electrically present */ |
| 335 | /* may be called with controller, bus, and devices active */ |
| 336 | |
| 337 | /** |
| 338 | * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs |
| 339 | * @dev: USB Host Controller being removed |
| 340 | * Context: !in_interrupt() |
| 341 | * |
| 342 | * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking |
| 343 | * the HCD's stop() method. It is always called from a thread |
| 344 | * context, normally "rmmod", "apmd", or something similar. |
| 345 | * |
| 346 | */ |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 347 | void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
| 349 | usb_remove_hcd(hcd); |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 350 | pxa27x_stop_hc(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | iounmap(hcd->regs); |
| 352 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 353 | usb_put_hcd(hcd); |
eric miao | a8bcf41 | 2007-12-12 08:53:25 +0800 | [diff] [blame] | 354 | clk_put(usb_clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /*-------------------------------------------------------------------------*/ |
| 358 | |
| 359 | static int __devinit |
| 360 | ohci_pxa27x_start (struct usb_hcd *hcd) |
| 361 | { |
| 362 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
| 363 | int ret; |
| 364 | |
| 365 | ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci); |
| 366 | |
David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 367 | /* The value of NDP in roothub_a is incorrect on this hardware */ |
| 368 | ohci->num_ports = 3; |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | if ((ret = ohci_init(ohci)) < 0) |
| 371 | return ret; |
| 372 | |
| 373 | if ((ret = ohci_run (ohci)) < 0) { |
| 374 | err ("can't start %s", hcd->self.bus_name); |
| 375 | ohci_stop (hcd); |
| 376 | return ret; |
| 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | /*-------------------------------------------------------------------------*/ |
| 383 | |
| 384 | static const struct hc_driver ohci_pxa27x_hc_driver = { |
| 385 | .description = hcd_name, |
| 386 | .product_desc = "PXA27x OHCI", |
| 387 | .hcd_priv_size = sizeof(struct ohci_hcd), |
| 388 | |
| 389 | /* |
| 390 | * generic hardware linkage |
| 391 | */ |
| 392 | .irq = ohci_irq, |
| 393 | .flags = HCD_USB11 | HCD_MEMORY, |
| 394 | |
| 395 | /* |
| 396 | * basic lifecycle operations |
| 397 | */ |
| 398 | .start = ohci_pxa27x_start, |
| 399 | .stop = ohci_stop, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 400 | .shutdown = ohci_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | /* |
| 403 | * managing i/o requests and associated device resources |
| 404 | */ |
| 405 | .urb_enqueue = ohci_urb_enqueue, |
| 406 | .urb_dequeue = ohci_urb_dequeue, |
| 407 | .endpoint_disable = ohci_endpoint_disable, |
| 408 | |
| 409 | /* |
| 410 | * scheduling support |
| 411 | */ |
| 412 | .get_frame_number = ohci_get_frame, |
| 413 | |
| 414 | /* |
| 415 | * root hub support |
| 416 | */ |
| 417 | .hub_status_data = ohci_hub_status_data, |
| 418 | .hub_control = ohci_hub_control, |
David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 419 | #ifdef CONFIG_PM |
Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 420 | .bus_suspend = ohci_bus_suspend, |
| 421 | .bus_resume = ohci_bus_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | #endif |
David Brownell | 9293677 | 2005-09-22 22:32:11 -0700 | [diff] [blame] | 423 | .start_port_reset = ohci_start_port_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | }; |
| 425 | |
| 426 | /*-------------------------------------------------------------------------*/ |
| 427 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 428 | static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | pr_debug ("In ohci_hcd_pxa27x_drv_probe"); |
| 431 | |
| 432 | if (usb_disabled()) |
| 433 | return -ENODEV; |
| 434 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 435 | return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 438 | static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 440 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | usb_hcd_pxa27x_remove(hcd, pdev); |
Richard Purdie | a5e36d2 | 2005-11-28 22:15:46 +0000 | [diff] [blame] | 443 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | |
Richard Purdie | 2e1dcc1 | 2005-11-12 14:22:14 +0000 | [diff] [blame] | 447 | #ifdef CONFIG_PM |
| 448 | static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Richard Purdie | a5e36d2 | 2005-11-28 22:15:46 +0000 | [diff] [blame] | 450 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 451 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Richard Purdie | 2e1dcc1 | 2005-11-12 14:22:14 +0000 | [diff] [blame] | 452 | |
| 453 | if (time_before(jiffies, ohci->next_statechange)) |
| 454 | msleep(5); |
| 455 | ohci->next_statechange = jiffies; |
| 456 | |
| 457 | pxa27x_stop_hc(&pdev->dev); |
Richard Purdie | a5e36d2 | 2005-11-28 22:15:46 +0000 | [diff] [blame] | 458 | hcd->state = HC_STATE_SUSPENDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
Richard Purdie | 2e1dcc1 | 2005-11-12 14:22:14 +0000 | [diff] [blame] | 463 | static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
Richard Purdie | a5e36d2 | 2005-11-28 22:15:46 +0000 | [diff] [blame] | 465 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 466 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Richard Purdie | 2e1dcc1 | 2005-11-12 14:22:14 +0000 | [diff] [blame] | 467 | int status; |
| 468 | |
| 469 | if (time_before(jiffies, ohci->next_statechange)) |
| 470 | msleep(5); |
| 471 | ohci->next_statechange = jiffies; |
| 472 | |
| 473 | if ((status = pxa27x_start_hc(&pdev->dev)) < 0) |
| 474 | return status; |
| 475 | |
Alan Stern | 43bbb7e | 2008-04-03 18:03:17 -0400 | [diff] [blame] | 476 | ohci_finish_controller_resume(hcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | return 0; |
| 478 | } |
Richard Purdie | 2e1dcc1 | 2005-11-12 14:22:14 +0000 | [diff] [blame] | 479 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 481 | /* work with hotplug and coldplug */ |
| 482 | MODULE_ALIAS("platform:pxa27x-ohci"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 484 | static struct platform_driver ohci_hcd_pxa27x_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | .probe = ohci_hcd_pxa27x_drv_probe, |
| 486 | .remove = ohci_hcd_pxa27x_drv_remove, |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 487 | .shutdown = usb_hcd_platform_shutdown, |
Richard Purdie | 2e1dcc1 | 2005-11-12 14:22:14 +0000 | [diff] [blame] | 488 | #ifdef CONFIG_PM |
David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 489 | .suspend = ohci_hcd_pxa27x_drv_suspend, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 490 | .resume = ohci_hcd_pxa27x_drv_resume, |
Richard Purdie | 2e1dcc1 | 2005-11-12 14:22:14 +0000 | [diff] [blame] | 491 | #endif |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 492 | .driver = { |
| 493 | .name = "pxa27x-ohci", |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 494 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 495 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | }; |
| 497 | |