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 /*-------------------------------------------------------------------------*/
13 * OHCI Root Hub ... the nonsharable stuff
16 #define dbg_port(hc,label,num,value) \
19 "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
21 (temp & ADMHC_PS_PRSC) ? " PRSC" : "", \
22 (temp & ADMHC_PS_OCIC) ? " OCIC" : "", \
23 (temp & ADMHC_PS_PSSC) ? " PSSC" : "", \
24 (temp & ADMHC_PS_PESC) ? " PESC" : "", \
25 (temp & ADMHC_PS_CSC) ? " CSC" : "", \
27 (temp & ADMHC_PS_LSDA) ? " LSDA" : "", \
28 (temp & ADMHC_PS_PPS) ? " PPS" : "", \
29 (temp & ADMHC_PS_PRS) ? " PRS" : "", \
30 (temp & ADMHC_PS_POCI) ? " POCI" : "", \
31 (temp & ADMHC_PS_PSS) ? " PSS" : "", \
33 (temp & ADMHC_PS_PES) ? " PES" : "", \
34 (temp & ADMHC_PS_CCS) ? " CCS" : "" \
37 #define dbg_port_write(hc,label,num,value) \
40 "= 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
42 (temp & ADMHC_PS_PRSC) ? " PRSC" : "", \
43 (temp & ADMHC_PS_OCIC) ? " OCIC" : "", \
44 (temp & ADMHC_PS_PSSC) ? " PSSC" : "", \
45 (temp & ADMHC_PS_PESC) ? " PESC" : "", \
46 (temp & ADMHC_PS_CSC) ? " CSC" : "", \
48 (temp & ADMHC_PS_CPP) ? " CPP" : "", \
49 (temp & ADMHC_PS_SPP) ? " SPP" : "", \
50 (temp & ADMHC_PS_SPR) ? " SPR" : "", \
51 (temp & ADMHC_PS_CPS) ? " CPS" : "", \
52 (temp & ADMHC_PS_SPS) ? " SPS" : "", \
54 (temp & ADMHC_PS_SPE) ? " SPE" : "", \
55 (temp & ADMHC_PS_CPE) ? " CPE" : "" \
58 /*-------------------------------------------------------------------------*/
60 /* hcd->hub_irq_enable() */
61 static void admhc_hub_irq_enable(struct usb_hcd
*hcd
)
63 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
65 spin_lock_irq(&ahcd
->lock
);
67 del_timer(&hcd
->rh_timer
); /* Prevent next poll */
68 admhc_intr_enable(ahcd
, ADMHC_INTR_INSM
);
69 spin_unlock_irq(&ahcd
->lock
);
72 /*-------------------------------------------------------------------------*/
74 /* build "status change" packet (one or two bytes) from HC registers */
77 admhc_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
79 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
80 int i
, changed
= 0, length
= 1;
81 int any_connected
= 0;
85 spin_lock_irqsave(&ahcd
->lock
, flags
);
86 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
))
90 status
= admhc_get_rhdesc(ahcd
);
91 if (status
& (ADMHC_RH_LPSC
| ADMHC_RH_OCIC
))
92 buf
[0] = changed
= 1;
95 if (ahcd
->num_ports
> 7) {
100 /* look at each port */
101 for (i
= 0; i
< ahcd
->num_ports
; i
++) {
102 status
= admhc_get_portstatus(ahcd
, i
);
104 /* can't autostop if ports are connected */
105 any_connected
|= (status
& ADMHC_PS_CCS
);
107 if (status
& (ADMHC_PS_CSC
| ADMHC_PS_PESC
| ADMHC_PS_PSSC
108 | ADMHC_PS_OCIC
| ADMHC_PS_PRSC
)) {
111 buf
[0] |= 1 << (i
+ 1);
113 buf
[1] |= 1 << (i
- 7);
117 hcd
->poll_rh
= admhc_root_hub_state_changes(ahcd
, changed
,
121 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
123 return changed
? length
: 0;
126 /*-------------------------------------------------------------------------*/
128 static void admhc_hub_descriptor(struct admhcd
*ahcd
,
129 struct usb_hub_descriptor
*desc
)
131 u32 rh
= admhc_get_rhdesc(ahcd
);
134 desc
->bDescriptorType
= USB_DT_HUB
; /* Hub-descriptor */
135 desc
->bPwrOn2PwrGood
= ADMHC_POTPGT
/2; /* use default value */
136 desc
->bHubContrCurrent
= 0x00; /* 0mA */
138 desc
->bNbrPorts
= ahcd
->num_ports
;
139 temp
= 1 + (ahcd
->num_ports
/ 8);
140 desc
->bDescLength
= USB_DT_HUB_NONVAR_SIZE
+ 2 * temp
;
144 if (rh
& ADMHC_RH_NPS
) /* no power switching? */
146 if (rh
& ADMHC_RH_PSM
) /* per-port power switching? */
148 if (rh
& ADMHC_RH_NOCP
) /* no overcurrent reporting? */
150 else if (rh
& ADMHC_RH_OCPM
) /* per-port overcurrent reporting? */
152 desc
->wHubCharacteristics
= (__force __u16
)cpu_to_hc16(ahcd
, temp
);
154 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
155 desc
->bitmap
[0] = 0;
156 desc
->bitmap
[0] = ~0;
159 /*-------------------------------------------------------------------------*/
161 #ifdef CONFIG_USB_OTG
163 static int admhc_start_port_reset(struct usb_hcd
*hcd
, unsigned port
)
165 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
172 /* start port reset before HNP protocol times out */
173 status
= admhc_readl(ahcd
, &ahcd
->regs
->portstatus
[port
]);
174 if (!(status
& ADMHC_PS_CCS
))
177 /* khubd will finish the reset later */
178 admhc_writel(ahcd
, ADMHC_PS_PRS
, &ahcd
->regs
->portstatus
[port
]);
182 static void start_hnp(struct admhcd
*ahcd
);
186 #define admhc_start_port_reset NULL
190 /*-------------------------------------------------------------------------*/
193 /* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling,
194 * not necessarily continuous ... to guard against resume signaling.
195 * The short timeout is safe for non-root hubs, and is backward-compatible
196 * with earlier Linux hosts.
198 #ifdef CONFIG_USB_SUSPEND
199 #define PORT_RESET_MSEC 50
201 #define PORT_RESET_MSEC 10
204 /* this timer value might be vendor-specific ... */
205 #define PORT_RESET_HW_MSEC 10
207 /* wrap-aware logic morphed from <linux/jiffies.h> */
208 #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
210 /* called from some task, normally khubd */
211 static inline int root_port_reset(struct admhcd
*ahcd
, unsigned port
)
214 /* FIXME: revert to this when frame numbers are updated */
215 __hc32 __iomem
*portstat
= &ahcd
->regs
->portstatus
[port
];
217 u16 now
= admhc_readl(ahcd
, &ahcd
->regs
->fmnumber
);
218 u16 reset_done
= now
+ PORT_RESET_MSEC
;
220 /* build a "continuous enough" reset signal, with up to
221 * 3msec gap between pulses. scheduler HZ==100 must work;
222 * this might need to be deadline-scheduled.
225 /* spin until any current reset finishes */
227 temp
= admhc_readl(ahcd
, portstat
);
228 /* handle e.g. CardBus eject */
231 if (!(temp
& ADMHC_PS_PRS
))
236 if (!(temp
& ADMHC_PS_CCS
))
238 if (temp
& ADMHC_PS_PRSC
)
239 admhc_writel(ahcd
, ADMHC_PS_PRSC
, portstat
);
241 /* start the next reset, sleep till it's probably done */
242 admhc_writel(ahcd
, ADMHC_PS_PRS
, portstat
);
243 msleep(PORT_RESET_HW_MSEC
);
244 now
= admhc_readl(ahcd
, &ahcd
->regs
->fmnumber
);
245 } while (tick_before(now
, reset_done
));
246 /* caller synchronizes using PRSC */
248 __hc32 __iomem
*portstat
= &ahcd
->regs
->portstatus
[port
];
250 unsigned long reset_done
= jiffies
+ msecs_to_jiffies(PORT_RESET_MSEC
);
252 /* build a "continuous enough" reset signal, with up to
253 * 3msec gap between pulses. scheduler HZ==100 must work;
254 * this might need to be deadline-scheduled.
257 /* spin until any current reset finishes */
259 temp
= admhc_readl(ahcd
, portstat
);
260 /* handle e.g. CardBus eject */
263 if (!(temp
& ADMHC_PS_PRS
))
268 if (!(temp
& ADMHC_PS_CCS
))
271 if (temp
& ADMHC_PS_PRSC
)
272 admhc_writel(ahcd
, ADMHC_PS_PRSC
, portstat
);
274 /* start the next reset, sleep till it's probably done */
275 admhc_writel(ahcd
, ADMHC_PS_PRS
, portstat
);
276 msleep(PORT_RESET_HW_MSEC
);
277 } while (time_before(jiffies
, reset_done
));
279 admhc_writel(ahcd
, ADMHC_PS_SPE
| ADMHC_PS_CSC
, portstat
);
285 static int admhc_hub_control (
293 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
294 int ports
= hcd_to_bus (hcd
)->root_hub
->maxchild
;
298 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
)))
302 case ClearHubFeature
:
304 case C_HUB_OVER_CURRENT
:
306 admhc_writel(ahcd
, ADMHC_RH_OCIC
,
307 &ahcd
->regs
->roothub
.status
);
309 case C_HUB_LOCAL_POWER
:
315 case ClearPortFeature
:
316 if (!wIndex
|| wIndex
> ports
)
321 case USB_PORT_FEAT_ENABLE
:
324 case USB_PORT_FEAT_SUSPEND
:
327 case USB_PORT_FEAT_POWER
:
330 case USB_PORT_FEAT_C_CONNECTION
:
333 case USB_PORT_FEAT_C_ENABLE
:
334 temp
= ADMHC_PS_PESC
;
336 case USB_PORT_FEAT_C_SUSPEND
:
337 temp
= ADMHC_PS_PSSC
;
339 case USB_PORT_FEAT_C_OVER_CURRENT
:
340 temp
= ADMHC_PS_OCIC
;
342 case USB_PORT_FEAT_C_RESET
:
343 temp
= ADMHC_PS_PRSC
;
348 admhc_writel(ahcd
, temp
, &ahcd
->regs
->portstatus
[wIndex
]);
350 case GetHubDescriptor
:
351 admhc_hub_descriptor(ahcd
, (struct usb_hub_descriptor
*) buf
);
354 temp
= admhc_get_rhdesc(ahcd
);
355 temp
&= ~(ADMHC_RH_CRWE
| ADMHC_RH_DRWE
);
356 put_unaligned(cpu_to_le32 (temp
), (__le32
*) buf
);
359 if (!wIndex
|| wIndex
> ports
)
362 temp
= admhc_get_portstatus(ahcd
, wIndex
);
363 put_unaligned(cpu_to_le32 (temp
), (__le32
*) buf
);
365 dbg_port(ahcd
, "GetPortStatus", wIndex
, temp
);
369 case C_HUB_OVER_CURRENT
:
370 // FIXME: this can be cleared, yes?
371 case C_HUB_LOCAL_POWER
:
378 if (!wIndex
|| wIndex
> ports
)
383 case USB_PORT_FEAT_ENABLE
:
384 admhc_writel(ahcd
, ADMHC_PS_SPE
,
385 &ahcd
->regs
->portstatus
[wIndex
]);
387 case USB_PORT_FEAT_SUSPEND
:
388 #ifdef CONFIG_USB_OTG
389 if (hcd
->self
.otg_port
== (wIndex
+ 1)
390 && hcd
->self
.b_hnp_enable
)
394 admhc_writel(ahcd
, ADMHC_PS_SPS
,
395 &ahcd
->regs
->portstatus
[wIndex
]);
397 case USB_PORT_FEAT_POWER
:
398 admhc_writel(ahcd
, ADMHC_PS_SPP
,
399 &ahcd
->regs
->portstatus
[wIndex
]);
401 case USB_PORT_FEAT_RESET
:
402 ret
= root_port_reset(ahcd
, wIndex
);
411 /* "protocol stall" on error */