16 #define dbg_port(hc,label,num,value) \
18 "%s roothub.portstatus [%d] " \
19 "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
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" : "", \
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" : "", \
33 (temp & RH_PS_PES) ? " PES" : "", \
34 (temp & RH_PS_CCS) ? " CCS" : "" \
39 #define OHCI_SCHED_ENABLES \
40 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
42 static void dl_done_list (
struct ohci_hcd *);
43 static void finish_unlinks (
struct ohci_hcd *,
u16);
46 static int ohci_rh_suspend (
struct ohci_hcd *
ohci,
int autostop)
66 if (!
ohci->autostop) {
72 autostop ?
"auto-stop" :
"suspend");
86 spin_unlock_irq (&
ohci->lock);
88 spin_lock_irq (&
ohci->lock);
91 finish_unlinks (
ohci, ohci_frame_no(
ohci));
94 if (ohci_to_hcd(
ohci)->
self.root_hub->do_remote_wakeup || autostop) {
98 &
ohci->regs->intrdisable);
121 static inline struct ed *find_head (
struct ed *
ed)
134 struct usb_hcd *hcd = ohci_to_hcd (
ohci);
137 int autostopped =
ohci->autostop;
160 autostopped ?
"auto-start" :
"resume");
165 autostopped ?
"auto-" :
"");
176 if (status == -
EBUSY) {
178 spin_unlock_irq (&
ohci->lock);
180 status = ohci_restart (
ohci);
182 usb_root_hub_lost_power(hcd->self.root_hub);
184 spin_lock_irq (&
ohci->lock);
192 spin_unlock_irq (&
ohci->lock);
201 spin_lock_irq(&
ohci->lock);
214 periodic_reinit (
ohci);
223 if (
ohci->ed_rm_list)
232 temp =
ohci->hc_control;
242 spin_lock_irq (&
ohci->lock);
252 if (!
ohci->ed_rm_list) {
253 if (
ohci->ed_controltail) {
255 find_head (
ohci->ed_controltail)->dma,
256 &
ohci->regs->ed_controlhead);
260 if (
ohci->ed_bulktail) {
262 &
ohci->regs->ed_bulkhead);
267 if (hcd->self.bandwidth_isoc_reqs || hcd->self.bandwidth_int_reqs)
270 ohci_dbg (
ohci,
"restarting schedules ... %08x\n", enables);
271 ohci->hc_control |= enables;
282 static int ohci_bus_suspend (
struct usb_hcd *hcd)
287 spin_lock_irq (&ohci->
lock);
289 if (
unlikely(!HCD_HW_ACCESSIBLE(hcd)))
292 rc = ohci_rh_suspend (ohci, 0);
293 spin_unlock_irq (&ohci->
lock);
297 static int ohci_bus_resume (
struct usb_hcd *hcd)
299 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
305 spin_lock_irq (&ohci->
lock);
307 if (
unlikely(!HCD_HW_ACCESSIBLE(hcd)))
310 rc = ohci_rh_resume (ohci);
311 spin_unlock_irq (&ohci->
lock);
320 static void __maybe_unused ohci_finish_controller_resume(
struct usb_hcd *hcd)
322 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
324 bool need_reinit =
false;
340 spin_lock_irq(&ohci->
lock);
341 ohci_rh_resume(ohci);
342 ohci_rh_suspend(ohci, 0);
343 spin_unlock_irq(&ohci->
lock);
349 for (port = 0; port < ohci->
num_ports; port++)
351 &ohci->
regs->roothub.portstatus[port]);
358 usb_hcd_resume_root_hub(hcd);
362 static int ohci_root_hub_state_changes(
struct ohci_hcd *ohci,
int changed,
363 int any_connected,
int rhsc_status)
378 if (!rhsc_enable && !rhsc_status && !changed) {
388 !device_may_wakeup(&ohci_to_hcd(ohci)
389 ->
self.root_hub->dev)) {
399 if (changed || any_connected) {
408 ohci_rh_suspend(ohci, 1);
420 ohci_rh_resume(ohci);
422 usb_hcd_resume_root_hub(ohci_to_hcd(ohci));
426 !ohci_to_hcd(ohci)->
self.root_hub->
434 if (!rhsc_enable && !rhsc_status) {
437 &ohci->
regs->intrenable);
450 static inline int ohci_rh_resume(
struct ohci_hcd *ohci)
458 static int ohci_root_hub_state_changes(
struct ohci_hcd *ohci,
int changed,
459 int any_connected,
int rhsc_status)
469 if (changed || rhsc_status)
484 ohci_hub_status_data (
struct usb_hcd *hcd,
char *
buf)
486 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
487 int i, changed = 0,
length = 1;
488 int any_connected = 0;
493 if (!HCD_HW_ACCESSIBLE(hcd))
499 ohci_warn (ohci,
"bogus NDP, rereads as NDP=%d\n",
507 buf [0] = changed = 1;
522 u32 status = roothub_portstatus (ohci, i);
531 buf [0] |= 1 << (i + 1);
533 buf [1] |= 1 << (i - 7);
537 if (ohci_root_hub_state_changes(ohci, changed,
538 any_connected, rhsc_status))
539 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
541 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
545 spin_unlock_irqrestore (&ohci->
lock, flags);
547 return changed ?
length : 0;
553 ohci_hub_descriptor (
557 u32 rh = roothub_a (ohci);
580 rh = roothub_b (ohci);
593 #ifdef CONFIG_USB_OTG
597 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
605 status =
ohci_readl(ohci, &ohci->
regs->roothub.portstatus [port]);
616 #define ohci_start_port_reset NULL
628 #ifdef CONFIG_USB_SUSPEND
629 #define PORT_RESET_MSEC 50
631 #define PORT_RESET_MSEC 10
635 #define PORT_RESET_HW_MSEC 10
638 #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
641 static inline int root_port_reset (
struct ohci_hcd *ohci,
unsigned port)
658 while (--limit_2 >= 0) {
674 "port[%d] reset timeout, stat %08x\n",
688 }
while (
tick_before(now, reset_done) && --limit_1 >= 0);
697 static int ohci_hub_control (
705 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
710 if (
unlikely(!HCD_HW_ACCESSIBLE(hcd)))
714 case ClearHubFeature:
718 &ohci->
regs->roothub.status);
725 case ClearPortFeature:
726 if (!wIndex || wIndex > ports)
759 &ohci->
regs->roothub.portstatus [wIndex]);
762 case GetHubDescriptor:
770 if (!wIndex || wIndex > ports)
773 temp = roothub_portstatus (ohci, wIndex);
776 #ifndef OHCI_VERBOSE_DEBUG
779 dbg_port (ohci,
"GetStatus", wIndex, temp);
792 if (!wIndex || wIndex > ports)
797 #ifdef CONFIG_USB_OTG
798 if (hcd->self.otg_port == (wIndex + 1)
799 && hcd->self.b_hnp_enable)
804 &ohci->
regs->roothub.portstatus [wIndex]);
808 &ohci->
regs->roothub.portstatus [wIndex]);
811 retval = root_port_reset (ohci, wIndex);