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