2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
7 * This file is licenced under GPL
10 #define OHCI_SCHED_ENABLES \
11 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
14 static int admhc_restart(struct admhcd
*ahcd
);
16 static int admhc_rh_suspend(struct admhcd
*ahcd
, int autostop
)
17 __releases(ahcd
->lock
)
18 __acquires(ahcd
->lock
)
22 ahcd
->hc_control
= admhc_readl(ahcd
, &ahcd
->regs
->control
);
23 switch (ahcd
->hc_control
& OHCI_CTRL_HCFS
) {
25 admhc_dbg(ahcd
, "resume/suspend?\n");
26 ahcd
->hc_control
&= ~OHCI_CTRL_HCFS
;
27 ahcd
->hc_control
|= OHCI_USB_RESET
;
28 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
29 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
33 admhc_dbg(ahcd
, "needs reinit!\n");
35 case OHCI_USB_SUSPEND
:
36 if (!ahcd
->autostop
) {
37 admhc_dbg(ahcd
, "already suspended\n");
41 admhc_dbg(ahcd
, "%s root hub\n",
42 autostop
? "auto-stop" : "suspend");
44 /* First stop any processing */
45 if (!autostop
&& (ahcd
->hc_control
& OHCI_SCHED_ENABLES
)) {
46 ahcd
->hc_control
&= ~OHCI_SCHED_ENABLES
;
47 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
48 ahcd
->hc_control
= admhc_readl(ahcd
, &ahcd
->regs
->control
);
49 admhc_writel(ahcd
, OHCI_INTR_SF
, &ahcd
->regs
->intrstatus
);
51 /* sched disables take effect on the next frame,
52 * then the last WDH could take 6+ msec
54 admhc_dbg(ahcd
, "stopping schedules ...\n");
56 spin_unlock_irq (&ahcd
->lock
);
58 spin_lock_irq(&ahcd
->lock
);
61 finish_unlinks (ahcd
, admhc_frame_no(ahcd
));
63 /* maybe resume can wake root hub */
64 if (device_may_wakeup(&admhcd_to_hcd(ahcd
)->self
.root_hub
->dev
) ||
66 ahcd
->hc_control
|= OHCI_CTRL_RWE
;
68 admhc_writel(ahcd
, OHCI_INTR_RHSC
, &ahcd
->regs
->intrdisable
);
69 ahcd
->hc_control
&= ~OHCI_CTRL_RWE
;
72 /* Suspend hub ... this is the "global (to this bus) suspend" mode,
73 * which doesn't imply ports will first be individually suspended.
75 ahcd
->hc_control
&= ~OHCI_CTRL_HCFS
;
76 ahcd
->hc_control
|= OHCI_USB_SUSPEND
;
77 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
78 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
80 /* no resumes until devices finish suspending */
82 ahcd
->next_statechange
= jiffies
+ msecs_to_jiffies (5);
90 static inline struct ed
*find_head(struct ed
*ed
)
92 /* for bulk and control lists */
98 /* caller has locked the root hub */
99 static int admhc_rh_resume(struct admhcd
*ahcd
)
100 __releases(ahcd
->lock
)
101 __acquires(ahcd
->lock
)
103 struct usb_hcd
*hcd
= admhcd_to_hcd (ahcd
);
105 int status
= -EINPROGRESS
;
106 int autostopped
= ahcd
->autostop
;
109 ahcd
->hc_control
= admhc_readl(ahcd
, &ahcd
->regs
->control
);
111 if (ahcd
->hc_control
& (OHCI_CTRL_IR
| OHCI_SCHED_ENABLES
)) {
112 /* this can happen after resuming a swsusp snapshot */
113 if (hcd
->state
== HC_STATE_RESUMING
) {
114 admhc_dbg(ahcd
, "BIOS/SMM active, control %03x\n",
117 /* this happens when pmcore resumes HC then root */
119 admhc_dbg(ahcd
, "duplicate resume\n");
122 } else switch (ahcd
->hc_control
& OHCI_CTRL_HCFS
) {
123 case OHCI_USB_SUSPEND
:
124 ahcd
->hc_control
&= ~(OHCI_CTRL_HCFS
|OHCI_SCHED_ENABLES
);
125 ahcd
->hc_control
|= OHCI_USB_RESUME
;
126 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
127 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
128 admhc_dbg(ahcd
, "%s root hub\n",
129 autostopped
? "auto-start" : "resume");
131 case OHCI_USB_RESUME
:
132 /* HCFS changes sometime after INTR_RD */
133 admhc_dbg(ahcd
, "%swakeup root hub\n",
134 autostopped
? "auto-" : "");
137 /* this can happen after resuming a swsusp snapshot */
138 admhc_dbg(ahcd
, "snapshot resume? reinit\n");
141 default: /* RESET, we lost power */
142 admhc_dbg(ahcd
, "lost power\n");
145 if (status
== -EBUSY
) {
147 spin_unlock_irq (&ahcd
->lock
);
148 (void) ahcd_init (ahcd
);
149 status
= admhc_restart (ahcd
);
150 spin_lock_irq(&ahcd
->lock
);
154 if (status
!= -EINPROGRESS
)
158 spin_unlock_irq (&ahcd
->lock
);
160 /* Some controllers (lucent erratum) need extra-long delays */
161 msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1);
163 temp
= admhc_readl(ahcd
, &ahcd
->regs
->control
);
164 temp
&= OHCI_CTRL_HCFS
;
165 if (temp
!= OHCI_USB_RESUME
) {
166 admhc_err (ahcd
, "controller won't resume\n");
167 spin_lock_irq(&ahcd
->lock
);
171 /* disable old schedule state, reinit from scratch */
172 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_controlhead
);
173 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_controlcurrent
);
174 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_bulkhead
);
175 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_bulkcurrent
);
176 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_periodcurrent
);
177 admhc_writel(ahcd
, (u32
) ahcd
->hcca_dma
, &ahcd
->ahcd
->regs
->hcca
);
179 /* Sometimes PCI D3 suspend trashes frame timings ... */
180 periodic_reinit(ahcd
);
182 /* the following code is executed with ahcd->lock held and
183 * irqs disabled if and only if autostopped is true
187 /* interrupts might have been disabled */
188 admhc_writel(ahcd
, OHCI_INTR_INIT
, &ahcd
->regs
->int_enable
);
189 if (ahcd
->ed_rm_list
)
190 admhc_writel(ahcd
, OHCI_INTR_SF
, &ahcd
->regs
->int_enable
);
192 /* Then re-enable operations */
193 admhc_writel(ahcd
, OHCI_USB_OPER
, &ahcd
->regs
->control
);
194 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
198 temp
= ahcd
->hc_control
;
199 temp
&= OHCI_CTRL_RWC
;
200 temp
|= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
201 ahcd
->hc_control
= temp
;
202 admhc_writel(ahcd
, temp
, &ahcd
->regs
->control
);
203 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
208 spin_lock_irq(&ahcd
->lock
);
210 /* now ahcd->lock is always held and irqs are always disabled */
212 /* keep it alive for more than ~5x suspend + resume costs */
213 ahcd
->next_statechange
= jiffies
+ STATECHANGE_DELAY
;
215 /* maybe turn schedules back on */
218 if (!ahcd
->ed_rm_list
) {
219 if (ahcd
->ed_controltail
) {
221 find_head (ahcd
->ed_controltail
)->dma
,
222 &ahcd
->regs
->ed_controlhead
);
223 enables
|= OHCI_CTRL_CLE
;
226 if (ahcd
->ed_bulktail
) {
227 admhc_writel(ahcd
, find_head (ahcd
->ed_bulktail
)->dma
,
228 &ahcd
->regs
->ed_bulkhead
);
229 enables
|= OHCI_CTRL_BLE
;
233 if (hcd
->self
.bandwidth_isoc_reqs
|| hcd
->self
.bandwidth_int_reqs
)
234 enables
|= OHCI_CTRL_PLE
|OHCI_CTRL_IE
;
236 admhc_dbg(ahcd
, "restarting schedules ... %08x\n", enables
);
237 ahcd
->hc_control
|= enables
;
238 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
240 admhc_writel(ahcd
, temp
, &ahcd
->regs
->cmdstatus
);
241 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
247 static int admhc_bus_suspend(struct usb_hcd
*hcd
)
249 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
252 spin_lock_irq(&ahcd
->lock
);
254 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)))
257 rc
= admhc_rh_suspend(ahcd
, 0);
258 spin_unlock_irq(&ahcd
->lock
);
262 static int admhc_bus_resume(struct usb_hcd
*hcd
)
264 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
267 if (time_before(jiffies
, ahcd
->next_statechange
))
270 spin_lock_irq(&ahcd
->lock
);
272 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)))
275 rc
= admhc_rh_resume(ahcd
);
276 spin_unlock_irq(&ahcd
->lock
);
278 /* poll until we know a device is connected or we autostop */
280 usb_hcd_poll_rh_status(hcd
);
284 /* Carry out polling-, autostop-, and autoresume-related state changes */
285 static int admhc_root_hub_state_changes(struct admhcd
*ahcd
, int changed
,
290 switch (ahcd
->hc_control
& OHCI_CTRL_HCFS
) {
293 /* keep on polling until we know a device is connected
294 * and RHSC is enabled */
295 if (!ahcd
->autostop
) {
297 !device_may_wakeup(&admhcd_to_hcd(ahcd
)
298 ->self
.root_hub
->dev
)) {
299 if (admhc_readl(ahcd
, &ahcd
->regs
->int_enable
) &
304 ahcd
->next_statechange
= jiffies
+ HZ
;
307 /* if no devices have been attached for one second, autostop */
309 if (changed
|| any_connected
) {
311 ahcd
->next_statechange
= jiffies
+
313 } else if (time_after_eq(jiffies
,
314 ahcd
->next_statechange
)
316 && !(ahcd
->hc_control
&
317 OHCI_SCHED_ENABLES
)) {
318 ahcd_rh_suspend(ahcd
, 1);
323 /* if there is a port change, autostart or ask to be resumed */
324 case OHCI_USB_SUSPEND
:
325 case OHCI_USB_RESUME
:
328 admhc_rh_resume(ahcd
);
330 usb_hcd_resume_root_hub(admhcd_to_hcd(ahcd
));
332 /* everything is idle, no need for polling */
340 /*-------------------------------------------------------------------------*/
342 /* must not be called from interrupt context */
343 static int admhc_restart(struct admhcd
*ahcd
)
347 struct urb_priv
*priv
;
349 /* mark any devices gone, so they do nothing till khubd disconnects.
350 * recycle any "live" eds/tds (and urbs) right away.
351 * later, khubd disconnect processing will recycle the other state,
352 * (either as disconnect/reconnect, or maybe someday as a reset).
354 spin_lock_irq(&ahcd
->lock
);
356 usb_root_hub_lost_power(admhcd_to_hcd(ahcd
)->self
.root_hub
);
357 if (!list_empty(&ahcd
->pending
))
358 admhc_dbg(ahcd
, "abort schedule...\n");
359 list_for_each_entry(priv
, &ahcd
->pending
, pending
) {
360 struct urb
*urb
= priv
->td
[0]->urb
;
361 struct ed
*ed
= priv
->ed
;
365 ed
->state
= ED_UNLINK
;
366 ed
->hwINFO
|= cpu_to_hc32(ahcd
, ED_DEQUEUE
);
367 ed_deschedule (ahcd
, ed
);
369 ed
->ed_next
= ahcd
->ed_rm_list
;
371 ahcd
->ed_rm_list
= ed
;
376 admhc_dbg(ahcd
, "bogus ed %p state %d\n",
380 spin_lock(&urb
->lock
);
381 urb
->status
= -ESHUTDOWN
;
382 spin_unlock(&urb
->lock
);
384 finish_unlinks(ahcd
, 0);
385 spin_unlock_irq(&ahcd
->lock
);
387 /* paranoia, in case that didn't work: */
389 /* empty the interrupt branches */
390 for (i
= 0; i
< NUM_INTS
; i
++) ahcd
->load
[i
] = 0;
391 for (i
= 0; i
< NUM_INTS
; i
++) ahcd
->hcca
->int_table
[i
] = 0;
393 /* no EDs to remove */
394 ahcd
->ed_rm_list
= NULL
;
396 /* empty control and bulk lists */
397 ahcd
->ed_controltail
= NULL
;
398 ahcd
->ed_bulktail
= NULL
;
400 if ((temp
= admhc_run(ahcd
)) < 0) {
401 admhc_err(ahcd
, "can't restart, %d\n", temp
);
404 /* here we "know" root ports should always stay powered,
405 * and that if we try to turn them back on the root hub
406 * will respond to CSC processing.
410 admhc_writel(ahcd
, RH_PS_PSS
,
411 &ahcd
->regs
->portstatus
[i
]);
412 admhc_dbg(ahcd
, "restart complete\n");
417 #else /* CONFIG_PM */
419 static inline int admhc_rh_resume(struct admhcd
*ahcd
)
424 /* Carry out polling-related state changes.
425 * autostop isn't used when CONFIG_PM is turned off.
427 static int admhc_root_hub_state_changes(struct admhcd
*ahcd
, int changed
,
432 /* keep on polling until RHSC is enabled */
433 if (admhc_readl(ahcd
, &ahcd
->regs
->int_enable
) & ADMHC_INTR_INSM
)
439 #endif /* CONFIG_PM */
This page took 0.072267 seconds and 5 git commands to generate.