| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * OHCI HCD (Host Controller Driver) for USB. | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 3 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> | 
|  | 5 | * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 6 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * This file is licenced under GPL | 
|  | 8 | */ | 
|  | 9 |  | 
|  | 10 | /*-------------------------------------------------------------------------*/ | 
|  | 11 |  | 
|  | 12 | /* | 
|  | 13 | * OHCI Root Hub ... the nonsharable stuff | 
|  | 14 | */ | 
|  | 15 |  | 
|  | 16 | #define dbg_port(hc,label,num,value) \ | 
|  | 17 | ohci_dbg (hc, \ | 
|  | 18 | "%s roothub.portstatus [%d] " \ | 
|  | 19 | "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \ | 
|  | 20 | label, num, temp, \ | 
|  | 21 | (temp & RH_PS_PRSC) ? " PRSC" : "", \ | 
|  | 22 | (temp & RH_PS_OCIC) ? " OCIC" : "", \ | 
|  | 23 | (temp & RH_PS_PSSC) ? " PSSC" : "", \ | 
|  | 24 | (temp & RH_PS_PESC) ? " PESC" : "", \ | 
|  | 25 | (temp & RH_PS_CSC) ? " CSC" : "", \ | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 26 | \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | (temp & RH_PS_LSDA) ? " LSDA" : "", \ | 
|  | 28 | (temp & RH_PS_PPS) ? " PPS" : "", \ | 
|  | 29 | (temp & RH_PS_PRS) ? " PRS" : "", \ | 
|  | 30 | (temp & RH_PS_POCI) ? " POCI" : "", \ | 
|  | 31 | (temp & RH_PS_PSS) ? " PSS" : "", \ | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 32 | \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | (temp & RH_PS_PES) ? " PES" : "", \ | 
|  | 34 | (temp & RH_PS_CCS) ? " CCS" : "" \ | 
|  | 35 | ); | 
|  | 36 |  | 
|  | 37 | /*-------------------------------------------------------------------------*/ | 
|  | 38 |  | 
| David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 39 | /* hcd->hub_irq_enable() */ | 
|  | 40 | static void ohci_rhsc_enable (struct usb_hcd *hcd) | 
|  | 41 | { | 
|  | 42 | struct ohci_hcd		*ohci = hcd_to_ohci (hcd); | 
|  | 43 |  | 
| Alan Stern | 052ac01 | 2006-10-27 10:33:11 -0400 | [diff] [blame] | 44 | spin_lock_irq(&ohci->lock); | 
|  | 45 | if (!ohci->autostop) | 
|  | 46 | del_timer(&hcd->rh_timer);	/* Prevent next poll */ | 
|  | 47 | ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable); | 
|  | 48 | spin_unlock_irq(&ohci->lock); | 
| David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define OHCI_SCHED_ENABLES \ | 
|  | 52 | (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) | 
|  | 53 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 54 | static void dl_done_list (struct ohci_hcd *); | 
|  | 55 | static void finish_unlinks (struct ohci_hcd *, u16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 |  | 
| Alan Stern | b187844 | 2006-10-24 12:02:31 -0400 | [diff] [blame] | 57 | #ifdef	CONFIG_PM | 
|  | 58 | static int ohci_restart(struct ohci_hcd *ohci); | 
| Alan Stern | b187844 | 2006-10-24 12:02:31 -0400 | [diff] [blame] | 59 |  | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 60 | static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) | 
|  | 61 | __releases(ohci->lock) | 
|  | 62 | __acquires(ohci->lock) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | int			status = 0; | 
| Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 65 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); | 
|  | 67 | switch (ohci->hc_control & OHCI_CTRL_HCFS) { | 
|  | 68 | case OHCI_USB_RESUME: | 
|  | 69 | ohci_dbg (ohci, "resume/suspend?\n"); | 
|  | 70 | ohci->hc_control &= ~OHCI_CTRL_HCFS; | 
|  | 71 | ohci->hc_control |= OHCI_USB_RESET; | 
|  | 72 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); | 
|  | 73 | (void) ohci_readl (ohci, &ohci->regs->control); | 
|  | 74 | /* FALL THROUGH */ | 
|  | 75 | case OHCI_USB_RESET: | 
|  | 76 | status = -EBUSY; | 
|  | 77 | ohci_dbg (ohci, "needs reinit!\n"); | 
|  | 78 | goto done; | 
|  | 79 | case OHCI_USB_SUSPEND: | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 80 | if (!ohci->autostop) { | 
|  | 81 | ohci_dbg (ohci, "already suspended\n"); | 
|  | 82 | goto done; | 
|  | 83 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 85 | ohci_dbg (ohci, "%s root hub\n", | 
|  | 86 | autostop ? "auto-stop" : "suspend"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 |  | 
|  | 88 | /* First stop any processing */ | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 89 | if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | ohci->hc_control &= ~OHCI_SCHED_ENABLES; | 
|  | 91 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); | 
|  | 92 | ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); | 
|  | 93 | ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus); | 
|  | 94 |  | 
|  | 95 | /* sched disables take effect on the next frame, | 
|  | 96 | * then the last WDH could take 6+ msec | 
|  | 97 | */ | 
|  | 98 | ohci_dbg (ohci, "stopping schedules ...\n"); | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 99 | ohci->autostop = 0; | 
|  | 100 | spin_unlock_irq (&ohci->lock); | 
|  | 101 | msleep (8); | 
|  | 102 | spin_lock_irq (&ohci->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 104 | dl_done_list (ohci); | 
|  | 105 | finish_unlinks (ohci, ohci_frame_no(ohci)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 |  | 
|  | 107 | /* maybe resume can wake root hub */ | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 108 | if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev) || | 
|  | 109 | autostop) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | ohci->hc_control |= OHCI_CTRL_RWE; | 
| Alan Stern | 1f7e1a3 | 2006-09-25 15:41:21 -0400 | [diff] [blame] | 111 | else { | 
|  | 112 | ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | ohci->hc_control &= ~OHCI_CTRL_RWE; | 
| Alan Stern | 1f7e1a3 | 2006-09-25 15:41:21 -0400 | [diff] [blame] | 114 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 |  | 
| David Brownell | f197b2c | 2005-09-22 22:42:53 -0700 | [diff] [blame] | 116 | /* Suspend hub ... this is the "global (to this bus) suspend" mode, | 
|  | 117 | * which doesn't imply ports will first be individually suspended. | 
|  | 118 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | ohci->hc_control &= ~OHCI_CTRL_HCFS; | 
|  | 120 | ohci->hc_control |= OHCI_USB_SUSPEND; | 
|  | 121 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); | 
|  | 122 | (void) ohci_readl (ohci, &ohci->regs->control); | 
|  | 123 |  | 
|  | 124 | /* no resumes until devices finish suspending */ | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 125 | if (!autostop) { | 
|  | 126 | ohci->next_statechange = jiffies + msecs_to_jiffies (5); | 
|  | 127 | ohci->autostop = 0; | 
|  | 128 | } | 
| David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 129 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | done: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return status; | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | static inline struct ed *find_head (struct ed *ed) | 
|  | 135 | { | 
|  | 136 | /* for bulk and control lists */ | 
|  | 137 | while (ed->ed_prev) | 
|  | 138 | ed = ed->ed_prev; | 
|  | 139 | return ed; | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 | /* caller has locked the root hub */ | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 143 | static int ohci_rh_resume (struct ohci_hcd *ohci) | 
|  | 144 | __releases(ohci->lock) | 
|  | 145 | __acquires(ohci->lock) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 147 | struct usb_hcd		*hcd = ohci_to_hcd (ohci); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | u32			temp, enables; | 
|  | 149 | int			status = -EINPROGRESS; | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 150 | int			autostopped = ohci->autostop; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 |  | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 152 | ohci->autostop = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); | 
|  | 154 |  | 
|  | 155 | if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { | 
| David Brownell | f197b2c | 2005-09-22 22:42:53 -0700 | [diff] [blame] | 156 | /* this can happen after resuming a swsusp snapshot */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | if (hcd->state == HC_STATE_RESUMING) { | 
|  | 158 | ohci_dbg (ohci, "BIOS/SMM active, control %03x\n", | 
|  | 159 | ohci->hc_control); | 
|  | 160 | status = -EBUSY; | 
|  | 161 | /* this happens when pmcore resumes HC then root */ | 
|  | 162 | } else { | 
|  | 163 | ohci_dbg (ohci, "duplicate resume\n"); | 
|  | 164 | status = 0; | 
|  | 165 | } | 
|  | 166 | } else switch (ohci->hc_control & OHCI_CTRL_HCFS) { | 
|  | 167 | case OHCI_USB_SUSPEND: | 
|  | 168 | ohci->hc_control &= ~(OHCI_CTRL_HCFS|OHCI_SCHED_ENABLES); | 
|  | 169 | ohci->hc_control |= OHCI_USB_RESUME; | 
|  | 170 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); | 
|  | 171 | (void) ohci_readl (ohci, &ohci->regs->control); | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 172 | ohci_dbg (ohci, "%s root hub\n", | 
|  | 173 | autostopped ? "auto-start" : "resume"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | break; | 
|  | 175 | case OHCI_USB_RESUME: | 
|  | 176 | /* HCFS changes sometime after INTR_RD */ | 
| Alan Stern | 1b7be3c | 2006-11-06 12:05:00 -0500 | [diff] [blame] | 177 | ohci_dbg(ohci, "%swakeup root hub\n", | 
| Alan Stern | 583cead | 2006-10-24 12:04:22 -0400 | [diff] [blame] | 178 | autostopped ? "auto-" : ""); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | break; | 
|  | 180 | case OHCI_USB_OPER: | 
| David Brownell | f197b2c | 2005-09-22 22:42:53 -0700 | [diff] [blame] | 181 | /* this can happen after resuming a swsusp snapshot */ | 
|  | 182 | ohci_dbg (ohci, "snapshot resume? reinit\n"); | 
|  | 183 | status = -EBUSY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | break; | 
|  | 185 | default:		/* RESET, we lost power */ | 
| David Brownell | f197b2c | 2005-09-22 22:42:53 -0700 | [diff] [blame] | 186 | ohci_dbg (ohci, "lost power\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | status = -EBUSY; | 
|  | 188 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | if (status == -EBUSY) { | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 190 | if (!autostopped) { | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 191 | spin_unlock_irq (&ohci->lock); | 
|  | 192 | (void) ohci_init (ohci); | 
|  | 193 | status = ohci_restart (ohci); | 
|  | 194 | spin_lock_irq (&ohci->lock); | 
|  | 195 | } | 
|  | 196 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } | 
|  | 198 | if (status != -EINPROGRESS) | 
|  | 199 | return status; | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 200 | if (autostopped) | 
|  | 201 | goto skip_resume; | 
|  | 202 | spin_unlock_irq (&ohci->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | /* Some controllers (lucent erratum) need extra-long delays */ | 
| David Brownell | f197b2c | 2005-09-22 22:42:53 -0700 | [diff] [blame] | 205 | msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 |  | 
|  | 207 | temp = ohci_readl (ohci, &ohci->regs->control); | 
|  | 208 | temp &= OHCI_CTRL_HCFS; | 
|  | 209 | if (temp != OHCI_USB_RESUME) { | 
|  | 210 | ohci_err (ohci, "controller won't resume\n"); | 
| Alan Stern | 565402b | 2006-10-27 10:35:01 -0400 | [diff] [blame] | 211 | spin_lock_irq(&ohci->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | return -EBUSY; | 
|  | 213 | } | 
|  | 214 |  | 
|  | 215 | /* disable old schedule state, reinit from scratch */ | 
|  | 216 | ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); | 
|  | 217 | ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent); | 
|  | 218 | ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); | 
|  | 219 | ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent); | 
|  | 220 | ohci_writel (ohci, 0, &ohci->regs->ed_periodcurrent); | 
|  | 221 | ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); | 
|  | 222 |  | 
|  | 223 | /* Sometimes PCI D3 suspend trashes frame timings ... */ | 
|  | 224 | periodic_reinit (ohci); | 
|  | 225 |  | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 226 | /* the following code is executed with ohci->lock held and | 
|  | 227 | * irqs disabled if and only if autostopped is true | 
|  | 228 | */ | 
|  | 229 |  | 
|  | 230 | skip_resume: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | /* interrupts might have been disabled */ | 
|  | 232 | ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); | 
|  | 233 | if (ohci->ed_rm_list) | 
|  | 234 | ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 |  | 
|  | 236 | /* Then re-enable operations */ | 
|  | 237 | ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control); | 
|  | 238 | (void) ohci_readl (ohci, &ohci->regs->control); | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 239 | if (!autostopped) | 
|  | 240 | msleep (3); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 |  | 
| David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 242 | temp = ohci->hc_control; | 
|  | 243 | temp &= OHCI_CTRL_RWC; | 
|  | 244 | temp |= OHCI_CONTROL_INIT | OHCI_USB_OPER; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | ohci->hc_control = temp; | 
|  | 246 | ohci_writel (ohci, temp, &ohci->regs->control); | 
|  | 247 | (void) ohci_readl (ohci, &ohci->regs->control); | 
|  | 248 |  | 
|  | 249 | /* TRSMRCY */ | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 250 | if (!autostopped) { | 
|  | 251 | msleep (10); | 
|  | 252 | spin_lock_irq (&ohci->lock); | 
|  | 253 | } | 
|  | 254 | /* now ohci->lock is always held and irqs are always disabled */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 |  | 
| David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 256 | /* keep it alive for more than ~5x suspend + resume costs */ | 
|  | 257 | ohci->next_statechange = jiffies + STATECHANGE_DELAY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 |  | 
|  | 259 | /* maybe turn schedules back on */ | 
|  | 260 | enables = 0; | 
|  | 261 | temp = 0; | 
|  | 262 | if (!ohci->ed_rm_list) { | 
|  | 263 | if (ohci->ed_controltail) { | 
|  | 264 | ohci_writel (ohci, | 
|  | 265 | find_head (ohci->ed_controltail)->dma, | 
|  | 266 | &ohci->regs->ed_controlhead); | 
|  | 267 | enables |= OHCI_CTRL_CLE; | 
|  | 268 | temp |= OHCI_CLF; | 
|  | 269 | } | 
|  | 270 | if (ohci->ed_bulktail) { | 
|  | 271 | ohci_writel (ohci, find_head (ohci->ed_bulktail)->dma, | 
|  | 272 | &ohci->regs->ed_bulkhead); | 
|  | 273 | enables |= OHCI_CTRL_BLE; | 
|  | 274 | temp |= OHCI_BLF; | 
|  | 275 | } | 
|  | 276 | } | 
|  | 277 | if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs) | 
|  | 278 | enables |= OHCI_CTRL_PLE|OHCI_CTRL_IE; | 
|  | 279 | if (enables) { | 
|  | 280 | ohci_dbg (ohci, "restarting schedules ... %08x\n", enables); | 
|  | 281 | ohci->hc_control |= enables; | 
|  | 282 | ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); | 
|  | 283 | if (temp) | 
|  | 284 | ohci_writel (ohci, temp, &ohci->regs->cmdstatus); | 
|  | 285 | (void) ohci_readl (ohci, &ohci->regs->control); | 
|  | 286 | } | 
|  | 287 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | return 0; | 
|  | 289 | } | 
|  | 290 |  | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 291 | static int ohci_bus_suspend (struct usb_hcd *hcd) | 
|  | 292 | { | 
|  | 293 | struct ohci_hcd		*ohci = hcd_to_ohci (hcd); | 
|  | 294 | int			rc; | 
|  | 295 |  | 
|  | 296 | spin_lock_irq (&ohci->lock); | 
|  | 297 |  | 
|  | 298 | if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) | 
|  | 299 | rc = -ESHUTDOWN; | 
|  | 300 | else | 
|  | 301 | rc = ohci_rh_suspend (ohci, 0); | 
|  | 302 | spin_unlock_irq (&ohci->lock); | 
|  | 303 | return rc; | 
|  | 304 | } | 
|  | 305 |  | 
|  | 306 | static int ohci_bus_resume (struct usb_hcd *hcd) | 
|  | 307 | { | 
|  | 308 | struct ohci_hcd		*ohci = hcd_to_ohci (hcd); | 
|  | 309 | int			rc; | 
|  | 310 |  | 
|  | 311 | if (time_before (jiffies, ohci->next_statechange)) | 
|  | 312 | msleep(5); | 
|  | 313 |  | 
|  | 314 | spin_lock_irq (&ohci->lock); | 
|  | 315 |  | 
|  | 316 | if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) | 
|  | 317 | rc = -ESHUTDOWN; | 
|  | 318 | else | 
|  | 319 | rc = ohci_rh_resume (ohci); | 
|  | 320 | spin_unlock_irq (&ohci->lock); | 
|  | 321 |  | 
|  | 322 | /* poll until we know a device is connected or we autostop */ | 
|  | 323 | if (rc == 0) | 
|  | 324 | usb_hcd_poll_rh_status(hcd); | 
|  | 325 | return rc; | 
|  | 326 | } | 
|  | 327 |  | 
| Alan Stern | 1f9fc88 | 2006-11-20 11:06:59 -0500 | [diff] [blame] | 328 | /* Carry out polling-, autostop-, and autoresume-related state changes */ | 
|  | 329 | static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, | 
|  | 330 | int any_connected) | 
|  | 331 | { | 
|  | 332 | int	poll_rh = 1; | 
|  | 333 |  | 
|  | 334 | switch (ohci->hc_control & OHCI_CTRL_HCFS) { | 
|  | 335 |  | 
|  | 336 | case OHCI_USB_OPER: | 
|  | 337 | /* keep on polling until we know a device is connected | 
|  | 338 | * and RHSC is enabled */ | 
|  | 339 | if (!ohci->autostop) { | 
|  | 340 | if (any_connected || | 
|  | 341 | !device_may_wakeup(&ohci_to_hcd(ohci) | 
|  | 342 | ->self.root_hub->dev)) { | 
|  | 343 | if (ohci_readl(ohci, &ohci->regs->intrenable) & | 
|  | 344 | OHCI_INTR_RHSC) | 
|  | 345 | poll_rh = 0; | 
|  | 346 | } else { | 
|  | 347 | ohci->autostop = 1; | 
|  | 348 | ohci->next_statechange = jiffies + HZ; | 
|  | 349 | } | 
|  | 350 |  | 
|  | 351 | /* if no devices have been attached for one second, autostop */ | 
|  | 352 | } else { | 
|  | 353 | if (changed || any_connected) { | 
|  | 354 | ohci->autostop = 0; | 
|  | 355 | ohci->next_statechange = jiffies + | 
|  | 356 | STATECHANGE_DELAY; | 
|  | 357 | } else if (time_after_eq(jiffies, | 
|  | 358 | ohci->next_statechange) | 
|  | 359 | && !ohci->ed_rm_list | 
|  | 360 | && !(ohci->hc_control & | 
|  | 361 | OHCI_SCHED_ENABLES)) { | 
|  | 362 | ohci_rh_suspend(ohci, 1); | 
|  | 363 | } | 
|  | 364 | } | 
|  | 365 | break; | 
|  | 366 |  | 
|  | 367 | /* if there is a port change, autostart or ask to be resumed */ | 
|  | 368 | case OHCI_USB_SUSPEND: | 
|  | 369 | case OHCI_USB_RESUME: | 
|  | 370 | if (changed) { | 
|  | 371 | if (ohci->autostop) | 
|  | 372 | ohci_rh_resume(ohci); | 
|  | 373 | else | 
|  | 374 | usb_hcd_resume_root_hub(ohci_to_hcd(ohci)); | 
|  | 375 | } else { | 
|  | 376 | /* everything is idle, no need for polling */ | 
|  | 377 | poll_rh = 0; | 
|  | 378 | } | 
|  | 379 | break; | 
|  | 380 | } | 
|  | 381 | return poll_rh; | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | #else	/* CONFIG_PM */ | 
|  | 385 |  | 
|  | 386 | static inline int ohci_rh_resume(struct ohci_hcd *ohci) | 
|  | 387 | { | 
|  | 388 | return 0; | 
|  | 389 | } | 
|  | 390 |  | 
|  | 391 | /* Carry out polling-related state changes. | 
|  | 392 | * autostop isn't used when CONFIG_PM is turned off. | 
|  | 393 | */ | 
|  | 394 | static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, | 
|  | 395 | int any_connected) | 
|  | 396 | { | 
|  | 397 | int	poll_rh = 1; | 
|  | 398 |  | 
|  | 399 | /* keep on polling until RHSC is enabled */ | 
|  | 400 | if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC) | 
|  | 401 | poll_rh = 0; | 
|  | 402 | return poll_rh; | 
|  | 403 | } | 
|  | 404 |  | 
| David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 405 | #endif	/* CONFIG_PM */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 |  | 
|  | 407 | /*-------------------------------------------------------------------------*/ | 
|  | 408 |  | 
|  | 409 | /* build "status change" packet (one or two bytes) from HC registers */ | 
|  | 410 |  | 
|  | 411 | static int | 
|  | 412 | ohci_hub_status_data (struct usb_hcd *hcd, char *buf) | 
|  | 413 | { | 
|  | 414 | struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
| David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 415 | int		i, changed = 0, length = 1; | 
| Alan Stern | 052ac01 | 2006-10-27 10:33:11 -0400 | [diff] [blame] | 416 | int		any_connected = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | unsigned long	flags; | 
|  | 418 |  | 
|  | 419 | spin_lock_irqsave (&ohci->lock, flags); | 
|  | 420 |  | 
| David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 421 | /* undocumented erratum seen on at least rev D */ | 
|  | 422 | if ((ohci->flags & OHCI_QUIRK_AMD756) | 
|  | 423 | && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) { | 
|  | 424 | ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP); | 
|  | 426 | /* retry later; "should not happen" */ | 
|  | 427 | goto done; | 
|  | 428 | } | 
|  | 429 |  | 
|  | 430 | /* init status */ | 
|  | 431 | if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC)) | 
|  | 432 | buf [0] = changed = 1; | 
|  | 433 | else | 
|  | 434 | buf [0] = 0; | 
| David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 435 | if (ohci->num_ports > 7) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | buf [1] = 0; | 
|  | 437 | length++; | 
|  | 438 | } | 
|  | 439 |  | 
|  | 440 | /* look at each port */ | 
| David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 441 | for (i = 0; i < ohci->num_ports; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | u32	status = roothub_portstatus (ohci, i); | 
|  | 443 |  | 
| Alan Stern | 8d1a243 | 2006-09-26 14:46:16 -0400 | [diff] [blame] | 444 | /* can't autostop if ports are connected */ | 
|  | 445 | any_connected |= (status & RH_PS_CCS); | 
|  | 446 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC | 
|  | 448 | | RH_PS_OCIC | RH_PS_PRSC)) { | 
|  | 449 | changed = 1; | 
|  | 450 | if (i < 7) | 
|  | 451 | buf [0] |= 1 << (i + 1); | 
|  | 452 | else | 
|  | 453 | buf [1] |= 1 << (i - 7); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 |  | 
| Alan Stern | 1f9fc88 | 2006-11-20 11:06:59 -0500 | [diff] [blame] | 457 | hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed, | 
|  | 458 | any_connected); | 
| David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 459 |  | 
|  | 460 | done: | 
|  | 461 | spin_unlock_irqrestore (&ohci->lock, flags); | 
|  | 462 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | return changed ? length : 0; | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | /*-------------------------------------------------------------------------*/ | 
|  | 467 |  | 
|  | 468 | static void | 
|  | 469 | ohci_hub_descriptor ( | 
|  | 470 | struct ohci_hcd			*ohci, | 
|  | 471 | struct usb_hub_descriptor	*desc | 
|  | 472 | ) { | 
|  | 473 | u32		rh = roothub_a (ohci); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | u16		temp; | 
|  | 475 |  | 
|  | 476 | desc->bDescriptorType = 0x29; | 
|  | 477 | desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24; | 
|  | 478 | desc->bHubContrCurrent = 0; | 
|  | 479 |  | 
| David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 480 | desc->bNbrPorts = ohci->num_ports; | 
|  | 481 | temp = 1 + (ohci->num_ports / 8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | desc->bDescLength = 7 + 2 * temp; | 
|  | 483 |  | 
|  | 484 | temp = 0; | 
|  | 485 | if (rh & RH_A_NPS)		/* no power switching? */ | 
|  | 486 | temp |= 0x0002; | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 487 | if (rh & RH_A_PSM)		/* per-port power switching? */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | temp |= 0x0001; | 
|  | 489 | if (rh & RH_A_NOCP)		/* no overcurrent reporting? */ | 
|  | 490 | temp |= 0x0010; | 
|  | 491 | else if (rh & RH_A_OCPM)	/* per-port overcurrent reporting? */ | 
|  | 492 | temp |= 0x0008; | 
|  | 493 | desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); | 
|  | 494 |  | 
|  | 495 | /* two bitmaps:  ports removable, and usb 1.0 legacy PortPwrCtrlMask */ | 
|  | 496 | rh = roothub_b (ohci); | 
| KAMBAROV, ZAUR | b2134bc | 2005-06-24 22:20:35 -0700 | [diff] [blame] | 497 | memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | desc->bitmap [0] = rh & RH_B_DR; | 
| David Brownell | fdd13b3 | 2005-08-31 11:52:57 -0700 | [diff] [blame] | 499 | if (ohci->num_ports > 7) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | desc->bitmap [1] = (rh & RH_B_DR) >> 8; | 
| KAMBAROV, ZAUR | b2134bc | 2005-06-24 22:20:35 -0700 | [diff] [blame] | 501 | desc->bitmap [2] = 0xff; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } else | 
|  | 503 | desc->bitmap [1] = 0xff; | 
|  | 504 | } | 
|  | 505 |  | 
|  | 506 | /*-------------------------------------------------------------------------*/ | 
|  | 507 |  | 
|  | 508 | #ifdef	CONFIG_USB_OTG | 
|  | 509 |  | 
|  | 510 | static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port) | 
|  | 511 | { | 
|  | 512 | struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
|  | 513 | u32			status; | 
|  | 514 |  | 
|  | 515 | if (!port) | 
|  | 516 | return -EINVAL; | 
|  | 517 | port--; | 
|  | 518 |  | 
|  | 519 | /* start port reset before HNP protocol times out */ | 
|  | 520 | status = ohci_readl(ohci, &ohci->regs->roothub.portstatus [port]); | 
|  | 521 | if (!(status & RH_PS_CCS)) | 
|  | 522 | return -ENODEV; | 
|  | 523 |  | 
|  | 524 | /* khubd will finish the reset later */ | 
|  | 525 | ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); | 
|  | 526 | return 0; | 
|  | 527 | } | 
|  | 528 |  | 
|  | 529 | static void start_hnp(struct ohci_hcd *ohci); | 
|  | 530 |  | 
|  | 531 | #else | 
|  | 532 |  | 
|  | 533 | #define	ohci_start_port_reset		NULL | 
|  | 534 |  | 
|  | 535 | #endif | 
|  | 536 |  | 
|  | 537 | /*-------------------------------------------------------------------------*/ | 
|  | 538 |  | 
|  | 539 |  | 
|  | 540 | /* See usb 7.1.7.5:  root hubs must issue at least 50 msec reset signaling, | 
|  | 541 | * not necessarily continuous ... to guard against resume signaling. | 
|  | 542 | * The short timeout is safe for non-root hubs, and is backward-compatible | 
|  | 543 | * with earlier Linux hosts. | 
|  | 544 | */ | 
|  | 545 | #ifdef	CONFIG_USB_SUSPEND | 
|  | 546 | #define	PORT_RESET_MSEC		50 | 
|  | 547 | #else | 
|  | 548 | #define	PORT_RESET_MSEC		10 | 
|  | 549 | #endif | 
|  | 550 |  | 
|  | 551 | /* this timer value might be vendor-specific ... */ | 
|  | 552 | #define	PORT_RESET_HW_MSEC	10 | 
|  | 553 |  | 
|  | 554 | /* wrap-aware logic morphed from <linux/jiffies.h> */ | 
|  | 555 | #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) | 
|  | 556 |  | 
|  | 557 | /* called from some task, normally khubd */ | 
| Takamasa Ohtake | 23d10a9 | 2006-12-06 17:04:15 -0800 | [diff] [blame] | 558 | static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { | 
|  | 560 | __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; | 
|  | 561 | u32	temp; | 
|  | 562 | u16	now = ohci_readl(ohci, &ohci->regs->fmnumber); | 
|  | 563 | u16	reset_done = now + PORT_RESET_MSEC; | 
|  | 564 |  | 
|  | 565 | /* build a "continuous enough" reset signal, with up to | 
|  | 566 | * 3msec gap between pulses.  scheduler HZ==100 must work; | 
|  | 567 | * this might need to be deadline-scheduled. | 
|  | 568 | */ | 
|  | 569 | do { | 
|  | 570 | /* spin until any current reset finishes */ | 
|  | 571 | for (;;) { | 
|  | 572 | temp = ohci_readl (ohci, portstat); | 
| Takamasa Ohtake | 23d10a9 | 2006-12-06 17:04:15 -0800 | [diff] [blame] | 573 | /* handle e.g. CardBus eject */ | 
|  | 574 | if (temp == ~(u32)0) | 
|  | 575 | return -ESHUTDOWN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | if (!(temp & RH_PS_PRS)) | 
|  | 577 | break; | 
|  | 578 | udelay (500); | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 579 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 |  | 
|  | 581 | if (!(temp & RH_PS_CCS)) | 
|  | 582 | break; | 
|  | 583 | if (temp & RH_PS_PRSC) | 
|  | 584 | ohci_writel (ohci, RH_PS_PRSC, portstat); | 
|  | 585 |  | 
|  | 586 | /* start the next reset, sleep till it's probably done */ | 
|  | 587 | ohci_writel (ohci, RH_PS_PRS, portstat); | 
|  | 588 | msleep(PORT_RESET_HW_MSEC); | 
|  | 589 | now = ohci_readl(ohci, &ohci->regs->fmnumber); | 
|  | 590 | } while (tick_before(now, reset_done)); | 
|  | 591 | /* caller synchronizes using PRSC */ | 
| Takamasa Ohtake | 23d10a9 | 2006-12-06 17:04:15 -0800 | [diff] [blame] | 592 |  | 
|  | 593 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | } | 
|  | 595 |  | 
|  | 596 | static int ohci_hub_control ( | 
|  | 597 | struct usb_hcd	*hcd, | 
|  | 598 | u16		typeReq, | 
|  | 599 | u16		wValue, | 
|  | 600 | u16		wIndex, | 
|  | 601 | char		*buf, | 
|  | 602 | u16		wLength | 
|  | 603 | ) { | 
|  | 604 | struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
|  | 605 | int		ports = hcd_to_bus (hcd)->root_hub->maxchild; | 
|  | 606 | u32		temp; | 
|  | 607 | int		retval = 0; | 
|  | 608 |  | 
| Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 609 | if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) | 
|  | 610 | return -ESHUTDOWN; | 
|  | 611 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | switch (typeReq) { | 
|  | 613 | case ClearHubFeature: | 
|  | 614 | switch (wValue) { | 
|  | 615 | case C_HUB_OVER_CURRENT: | 
|  | 616 | ohci_writel (ohci, RH_HS_OCIC, | 
|  | 617 | &ohci->regs->roothub.status); | 
|  | 618 | case C_HUB_LOCAL_POWER: | 
|  | 619 | break; | 
|  | 620 | default: | 
|  | 621 | goto error; | 
|  | 622 | } | 
|  | 623 | break; | 
|  | 624 | case ClearPortFeature: | 
|  | 625 | if (!wIndex || wIndex > ports) | 
|  | 626 | goto error; | 
|  | 627 | wIndex--; | 
|  | 628 |  | 
|  | 629 | switch (wValue) { | 
|  | 630 | case USB_PORT_FEAT_ENABLE: | 
|  | 631 | temp = RH_PS_CCS; | 
|  | 632 | break; | 
|  | 633 | case USB_PORT_FEAT_C_ENABLE: | 
|  | 634 | temp = RH_PS_PESC; | 
|  | 635 | break; | 
|  | 636 | case USB_PORT_FEAT_SUSPEND: | 
|  | 637 | temp = RH_PS_POCI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | break; | 
|  | 639 | case USB_PORT_FEAT_C_SUSPEND: | 
|  | 640 | temp = RH_PS_PSSC; | 
|  | 641 | break; | 
|  | 642 | case USB_PORT_FEAT_POWER: | 
|  | 643 | temp = RH_PS_LSDA; | 
|  | 644 | break; | 
|  | 645 | case USB_PORT_FEAT_C_CONNECTION: | 
|  | 646 | temp = RH_PS_CSC; | 
|  | 647 | break; | 
|  | 648 | case USB_PORT_FEAT_C_OVER_CURRENT: | 
|  | 649 | temp = RH_PS_OCIC; | 
|  | 650 | break; | 
|  | 651 | case USB_PORT_FEAT_C_RESET: | 
|  | 652 | temp = RH_PS_PRSC; | 
|  | 653 | break; | 
|  | 654 | default: | 
|  | 655 | goto error; | 
|  | 656 | } | 
|  | 657 | ohci_writel (ohci, temp, | 
|  | 658 | &ohci->regs->roothub.portstatus [wIndex]); | 
|  | 659 | // ohci_readl (ohci, &ohci->regs->roothub.portstatus [wIndex]); | 
|  | 660 | break; | 
|  | 661 | case GetHubDescriptor: | 
|  | 662 | ohci_hub_descriptor (ohci, (struct usb_hub_descriptor *) buf); | 
|  | 663 | break; | 
|  | 664 | case GetHubStatus: | 
|  | 665 | temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE); | 
| David Miller | 92164c5d | 2006-06-21 22:26:09 -0700 | [diff] [blame] | 666 | put_unaligned(cpu_to_le32 (temp), (__le32 *) buf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | break; | 
|  | 668 | case GetPortStatus: | 
|  | 669 | if (!wIndex || wIndex > ports) | 
|  | 670 | goto error; | 
|  | 671 | wIndex--; | 
|  | 672 | temp = roothub_portstatus (ohci, wIndex); | 
| David Miller | 92164c5d | 2006-06-21 22:26:09 -0700 | [diff] [blame] | 673 | put_unaligned(cpu_to_le32 (temp), (__le32 *) buf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 |  | 
|  | 675 | #ifndef	OHCI_VERBOSE_DEBUG | 
|  | 676 | if (*(u16*)(buf+2))	/* only if wPortChange is interesting */ | 
|  | 677 | #endif | 
|  | 678 | dbg_port (ohci, "GetStatus", wIndex, temp); | 
|  | 679 | break; | 
|  | 680 | case SetHubFeature: | 
|  | 681 | switch (wValue) { | 
|  | 682 | case C_HUB_OVER_CURRENT: | 
|  | 683 | // FIXME:  this can be cleared, yes? | 
|  | 684 | case C_HUB_LOCAL_POWER: | 
|  | 685 | break; | 
|  | 686 | default: | 
|  | 687 | goto error; | 
|  | 688 | } | 
|  | 689 | break; | 
|  | 690 | case SetPortFeature: | 
|  | 691 | if (!wIndex || wIndex > ports) | 
|  | 692 | goto error; | 
|  | 693 | wIndex--; | 
|  | 694 | switch (wValue) { | 
|  | 695 | case USB_PORT_FEAT_SUSPEND: | 
|  | 696 | #ifdef	CONFIG_USB_OTG | 
|  | 697 | if (hcd->self.otg_port == (wIndex + 1) | 
|  | 698 | && hcd->self.b_hnp_enable) | 
|  | 699 | start_hnp(ohci); | 
|  | 700 | else | 
|  | 701 | #endif | 
|  | 702 | ohci_writel (ohci, RH_PS_PSS, | 
|  | 703 | &ohci->regs->roothub.portstatus [wIndex]); | 
|  | 704 | break; | 
|  | 705 | case USB_PORT_FEAT_POWER: | 
|  | 706 | ohci_writel (ohci, RH_PS_PPS, | 
|  | 707 | &ohci->regs->roothub.portstatus [wIndex]); | 
|  | 708 | break; | 
|  | 709 | case USB_PORT_FEAT_RESET: | 
| Takamasa Ohtake | 23d10a9 | 2006-12-06 17:04:15 -0800 | [diff] [blame] | 710 | retval = root_port_reset (ohci, wIndex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | break; | 
|  | 712 | default: | 
|  | 713 | goto error; | 
|  | 714 | } | 
|  | 715 | break; | 
|  | 716 |  | 
|  | 717 | default: | 
|  | 718 | error: | 
|  | 719 | /* "protocol stall" on error */ | 
|  | 720 | retval = -EPIPE; | 
|  | 721 | } | 
|  | 722 | return retval; | 
|  | 723 | } | 
|  | 724 |  |