2 * ADM5120 HCD (Host Controller Driver) for USB
4 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
6 * This file was derived from fragments of the OHCI driver.
7 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
8 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
10 * This file is licenced under the GPL.
13 #define OHCI_SCHED_ENABLES \
14 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
17 static int admhc_restart(struct admhcd
*ahcd
);
19 static int admhc_rh_suspend(struct admhcd
*ahcd
, int autostop
)
20 __releases(ahcd
->lock
)
21 __acquires(ahcd
->lock
)
25 ahcd
->hc_control
= admhc_readl(ahcd
, &ahcd
->regs
->control
);
26 switch (ahcd
->hc_control
& OHCI_CTRL_HCFS
) {
28 admhc_dbg(ahcd
, "resume/suspend?\n");
29 ahcd
->hc_control
&= ~OHCI_CTRL_HCFS
;
30 ahcd
->hc_control
|= OHCI_USB_RESET
;
31 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
32 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
36 admhc_dbg(ahcd
, "needs reinit!\n");
38 case OHCI_USB_SUSPEND
:
39 if (!ahcd
->autostop
) {
40 admhc_dbg(ahcd
, "already suspended\n");
44 admhc_dbg(ahcd
, "%s root hub\n",
45 autostop
? "auto-stop" : "suspend");
47 /* First stop any processing */
48 if (!autostop
&& (ahcd
->hc_control
& OHCI_SCHED_ENABLES
)) {
49 ahcd
->hc_control
&= ~OHCI_SCHED_ENABLES
;
50 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
51 ahcd
->hc_control
= admhc_readl(ahcd
, &ahcd
->regs
->control
);
52 admhc_writel(ahcd
, OHCI_INTR_SF
, &ahcd
->regs
->intrstatus
);
54 /* sched disables take effect on the next frame,
55 * then the last WDH could take 6+ msec
57 admhc_dbg(ahcd
, "stopping schedules ...\n");
59 spin_unlock_irq (&ahcd
->lock
);
61 spin_lock_irq(&ahcd
->lock
);
64 finish_unlinks (ahcd
, admhc_frame_no(ahcd
));
66 /* maybe resume can wake root hub */
67 if (device_may_wakeup(&admhcd_to_hcd(ahcd
)->self
.root_hub
->dev
) ||
69 ahcd
->hc_control
|= OHCI_CTRL_RWE
;
71 admhc_writel(ahcd
, OHCI_INTR_RHSC
, &ahcd
->regs
->intrdisable
);
72 ahcd
->hc_control
&= ~OHCI_CTRL_RWE
;
75 /* Suspend hub ... this is the "global (to this bus) suspend" mode,
76 * which doesn't imply ports will first be individually suspended.
78 ahcd
->hc_control
&= ~OHCI_CTRL_HCFS
;
79 ahcd
->hc_control
|= OHCI_USB_SUSPEND
;
80 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
81 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
83 /* no resumes until devices finish suspending */
85 ahcd
->next_statechange
= jiffies
+ msecs_to_jiffies (5);
93 static inline struct ed
*find_head(struct ed
*ed
)
95 /* for bulk and control lists */
101 /* caller has locked the root hub */
102 static int admhc_rh_resume(struct admhcd
*ahcd
)
103 __releases(ahcd
->lock
)
104 __acquires(ahcd
->lock
)
106 struct usb_hcd
*hcd
= admhcd_to_hcd (ahcd
);
108 int status
= -EINPROGRESS
;
109 int autostopped
= ahcd
->autostop
;
112 ahcd
->hc_control
= admhc_readl(ahcd
, &ahcd
->regs
->control
);
114 if (ahcd
->hc_control
& (OHCI_CTRL_IR
| OHCI_SCHED_ENABLES
)) {
115 /* this can happen after resuming a swsusp snapshot */
116 if (hcd
->state
== HC_STATE_RESUMING
) {
117 admhc_dbg(ahcd
, "BIOS/SMM active, control %03x\n",
120 /* this happens when pmcore resumes HC then root */
122 admhc_dbg(ahcd
, "duplicate resume\n");
125 } else switch (ahcd
->hc_control
& OHCI_CTRL_HCFS
) {
126 case OHCI_USB_SUSPEND
:
127 ahcd
->hc_control
&= ~(OHCI_CTRL_HCFS
|OHCI_SCHED_ENABLES
);
128 ahcd
->hc_control
|= OHCI_USB_RESUME
;
129 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
130 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
131 admhc_dbg(ahcd
, "%s root hub\n",
132 autostopped
? "auto-start" : "resume");
134 case OHCI_USB_RESUME
:
135 /* HCFS changes sometime after INTR_RD */
136 admhc_dbg(ahcd
, "%swakeup root hub\n",
137 autostopped
? "auto-" : "");
140 /* this can happen after resuming a swsusp snapshot */
141 admhc_dbg(ahcd
, "snapshot resume? reinit\n");
144 default: /* RESET, we lost power */
145 admhc_dbg(ahcd
, "lost power\n");
148 if (status
== -EBUSY
) {
150 spin_unlock_irq (&ahcd
->lock
);
151 (void) ahcd_init (ahcd
);
152 status
= admhc_restart (ahcd
);
153 spin_lock_irq(&ahcd
->lock
);
157 if (status
!= -EINPROGRESS
)
161 spin_unlock_irq (&ahcd
->lock
);
163 /* Some controllers (lucent erratum) need extra-long delays */
164 msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1);
166 temp
= admhc_readl(ahcd
, &ahcd
->regs
->control
);
167 temp
&= OHCI_CTRL_HCFS
;
168 if (temp
!= OHCI_USB_RESUME
) {
169 admhc_err (ahcd
, "controller won't resume\n");
170 spin_lock_irq(&ahcd
->lock
);
174 /* disable old schedule state, reinit from scratch */
175 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_controlhead
);
176 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_controlcurrent
);
177 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_bulkhead
);
178 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_bulkcurrent
);
179 admhc_writel(ahcd
, 0, &ahcd
->regs
->ed_periodcurrent
);
180 admhc_writel(ahcd
, (u32
) ahcd
->hcca_dma
, &ahcd
->ahcd
->regs
->hcca
);
182 /* Sometimes PCI D3 suspend trashes frame timings ... */
183 periodic_reinit(ahcd
);
185 /* the following code is executed with ahcd->lock held and
186 * irqs disabled if and only if autostopped is true
190 /* interrupts might have been disabled */
191 admhc_writel(ahcd
, OHCI_INTR_INIT
, &ahcd
->regs
->int_enable
);
192 if (ahcd
->ed_rm_list
)
193 admhc_writel(ahcd
, OHCI_INTR_SF
, &ahcd
->regs
->int_enable
);
195 /* Then re-enable operations */
196 admhc_writel(ahcd
, OHCI_USB_OPER
, &ahcd
->regs
->control
);
197 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
201 temp
= ahcd
->hc_control
;
202 temp
&= OHCI_CTRL_RWC
;
203 temp
|= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
204 ahcd
->hc_control
= temp
;
205 admhc_writel(ahcd
, temp
, &ahcd
->regs
->control
);
206 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
211 spin_lock_irq(&ahcd
->lock
);
213 /* now ahcd->lock is always held and irqs are always disabled */
215 /* keep it alive for more than ~5x suspend + resume costs */
216 ahcd
->next_statechange
= jiffies
+ STATECHANGE_DELAY
;
218 /* maybe turn schedules back on */
221 if (!ahcd
->ed_rm_list
) {
222 if (ahcd
->ed_controltail
) {
224 find_head (ahcd
->ed_controltail
)->dma
,
225 &ahcd
->regs
->ed_controlhead
);
226 enables
|= OHCI_CTRL_CLE
;
229 if (ahcd
->ed_bulktail
) {
230 admhc_writel(ahcd
, find_head (ahcd
->ed_bulktail
)->dma
,
231 &ahcd
->regs
->ed_bulkhead
);
232 enables
|= OHCI_CTRL_BLE
;
236 if (hcd
->self
.bandwidth_isoc_reqs
|| hcd
->self
.bandwidth_int_reqs
)
237 enables
|= OHCI_CTRL_PLE
|OHCI_CTRL_IE
;
239 admhc_dbg(ahcd
, "restarting schedules ... %08x\n", enables
);
240 ahcd
->hc_control
|= enables
;
241 admhc_writel(ahcd
, ahcd
->hc_control
, &ahcd
->ahcd
->regs
->control
);
243 admhc_writel(ahcd
, temp
, &ahcd
->regs
->cmdstatus
);
244 (void) admhc_readl(ahcd
, &ahcd
->regs
->control
);
250 static int admhc_bus_suspend(struct usb_hcd
*hcd
)
252 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
255 spin_lock_irq(&ahcd
->lock
);
257 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)))
260 rc
= admhc_rh_suspend(ahcd
, 0);
261 spin_unlock_irq(&ahcd
->lock
);
265 static int admhc_bus_resume(struct usb_hcd
*hcd
)
267 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
270 if (time_before(jiffies
, ahcd
->next_statechange
))
273 spin_lock_irq(&ahcd
->lock
);
275 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)))
278 rc
= admhc_rh_resume(ahcd
);
279 spin_unlock_irq(&ahcd
->lock
);
281 /* poll until we know a device is connected or we autostop */
283 usb_hcd_poll_rh_status(hcd
);
287 /* Carry out polling-, autostop-, and autoresume-related state changes */
288 static int admhc_root_hub_state_changes(struct admhcd
*ahcd
, int changed
,
293 switch (ahcd
->hc_control
& OHCI_CTRL_HCFS
) {
296 /* keep on polling until we know a device is connected
297 * and RHSC is enabled */
298 if (!ahcd
->autostop
) {
300 !device_may_wakeup(&admhcd_to_hcd(ahcd
)
301 ->self
.root_hub
->dev
)) {
302 if (admhc_readl(ahcd
, &ahcd
->regs
->int_enable
) &
307 ahcd
->next_statechange
= jiffies
+ HZ
;
310 /* if no devices have been attached for one second, autostop */
312 if (changed
|| any_connected
) {
314 ahcd
->next_statechange
= jiffies
+
316 } else if (time_after_eq(jiffies
,
317 ahcd
->next_statechange
)
319 && !(ahcd
->hc_control
&
320 OHCI_SCHED_ENABLES
)) {
321 ahcd_rh_suspend(ahcd
, 1);
326 /* if there is a port change, autostart or ask to be resumed */
327 case OHCI_USB_SUSPEND
:
328 case OHCI_USB_RESUME
:
331 admhc_rh_resume(ahcd
);
333 usb_hcd_resume_root_hub(admhcd_to_hcd(ahcd
));
335 /* everything is idle, no need for polling */
343 /*-------------------------------------------------------------------------*/
345 /* must not be called from interrupt context */
346 static int admhc_restart(struct admhcd
*ahcd
)
350 struct urb_priv
*priv
;
352 /* mark any devices gone, so they do nothing till khubd disconnects.
353 * recycle any "live" eds/tds (and urbs) right away.
354 * later, khubd disconnect processing will recycle the other state,
355 * (either as disconnect/reconnect, or maybe someday as a reset).
357 spin_lock_irq(&ahcd
->lock
);
359 usb_root_hub_lost_power(admhcd_to_hcd(ahcd
)->self
.root_hub
);
360 if (!list_empty(&ahcd
->pending
))
361 admhc_dbg(ahcd
, "abort schedule...\n");
362 list_for_each_entry(priv
, &ahcd
->pending
, pending
) {
363 struct urb
*urb
= priv
->td
[0]->urb
;
364 struct ed
*ed
= priv
->ed
;
368 ed
->state
= ED_UNLINK
;
369 ed
->hwINFO
|= cpu_to_hc32(ahcd
, ED_DEQUEUE
);
370 ed_deschedule (ahcd
, ed
);
372 ed
->ed_next
= ahcd
->ed_rm_list
;
374 ahcd
->ed_rm_list
= ed
;
379 admhc_dbg(ahcd
, "bogus ed %p state %d\n",
383 spin_lock(&urb
->lock
);
384 urb
->status
= -ESHUTDOWN
;
385 spin_unlock(&urb
->lock
);
387 finish_unlinks(ahcd
, 0);
388 spin_unlock_irq(&ahcd
->lock
);
390 /* paranoia, in case that didn't work: */
392 /* empty the interrupt branches */
393 for (i
= 0; i
< NUM_INTS
; i
++) ahcd
->load
[i
] = 0;
394 for (i
= 0; i
< NUM_INTS
; i
++) ahcd
->hcca
->int_table
[i
] = 0;
396 /* no EDs to remove */
397 ahcd
->ed_rm_list
= NULL
;
399 /* empty control and bulk lists */
400 ahcd
->ed_controltail
= NULL
;
401 ahcd
->ed_bulktail
= NULL
;
403 if ((temp
= admhc_run(ahcd
)) < 0) {
404 admhc_err(ahcd
, "can't restart, %d\n", temp
);
407 /* here we "know" root ports should always stay powered,
408 * and that if we try to turn them back on the root hub
409 * will respond to CSC processing.
413 admhc_writel(ahcd
, RH_PS_PSS
,
414 &ahcd
->regs
->portstatus
[i
]);
415 admhc_dbg(ahcd
, "restart complete\n");
420 #else /* CONFIG_PM */
422 static inline int admhc_rh_resume(struct admhcd
*ahcd
)
427 /* Carry out polling-related state changes.
428 * autostop isn't used when CONFIG_PM is turned off.
430 static int admhc_root_hub_state_changes(struct admhcd
*ahcd
, int changed
,
435 /* keep on polling until RHSC is enabled */
436 if (admhc_readl(ahcd
, &ahcd
->regs
->int_enable
) & ADMHC_INTR_INSM
)
442 #endif /* CONFIG_PM */
This page took 0.062425 seconds and 5 git commands to generate.