5 *----------------------------------------------------------------------------
6 * Includes for OHCI USB Controller
7 *----------------------------------------------------------------------------
8 * By Chris Hodges <chrisly@platon42.de>
11 #include <exec/types.h>
14 /* PCI Class: PCI_CLASS_SERIAL_USB */
18 - Framelist contains all the same entries pointing to ISO-TD
19 - ISO-TD: is inactive by default. Links to Control-QH
20 - Control-QH: - Head links to Int-Queue
21 - Element: Links to dummy-TD if empty (inactive)
22 - Element: otherwise links to QH for control transfer
23 - Int-Queue : - Head links to Bulk-Queue
29 * --------------------- OHCI registers ------------------------
30 * Warning: These are BYTE offsets!
33 /* operational registers */
34 #define OHCI_REVISION 0x000 /* Host Controller Revision (r) */
35 #define OHCI_CONTROL 0x004 /* Control register (r/w) */
36 #define OHCI_CMDSTATUS 0x008 /* Command and Status */
37 #define OHCI_INTSTATUS 0x00c /* Interrupt Status (r/wc) */
38 #define OHCI_INTEN 0x010 /* Interrupt Enable (r/ws) */
39 #define OHCI_INTDIS 0x014 /* Interrupt Disable (r/wc) */
40 #define OHCI_HCCA 0x018 /* Pointer to HCCA */
41 #define OHCI_PERIODIC_ED 0x01c /* Current periodic ED */
42 #define OHCI_CTRL_HEAD_ED 0x020 /* Control Head ED */
43 #define OHCI_CTRL_ED 0x024 /* Current control ED */
44 #define OHCI_BULK_HEAD_ED 0x028 /* Bulk Head ED */
45 #define OHCI_BULK_ED 0x02c /* Current bulk ED */
46 #define OHCI_DONEHEAD 0x030 /* Done head pointer */
47 #define OHCI_FRAMEINTERVAL 0x034 /* Frame interval */
48 #define OHCI_FRAMEREMAINING 0x038 /* Frame remaining time */
49 #define OHCI_FRAMECOUNT 0x03c /* Frame number */
50 #define OHCI_PERIODICSTART 0x040 /* Periodic start (usually 10% of 12000 == 0x3e67) */
51 #define OHCI_LSTHRESHOLD 0x044 /* Lowspeed threshold (usually 0x0628) */
52 #define OHCI_HUBDESCA 0x048 /* Root Hub Descriptor A */
53 #define OHCI_HUBDESCB 0x04c /* Root Hub Descriptor B */
54 #define OHCI_HUBSTATUS 0x050 /* Root Hub Status */
55 #define OHCI_PORTSTATUS 0x054 /* Port Status */
57 /* OHCI_CONTROL defines */
58 #define OCLS_CBSR 0 /* Control Bulk Service Ratio */
59 #define OCLB_PERIODICENABLE 2 /* Periodic Enable */
60 #define OCLB_ISOENABLE 3 /* Isochronous Enable */
61 #define OCLB_CTRLENABLE 4 /* Control List enable */
62 #define OCLB_BULKENABLE 5 /* Bulk List enable */
63 #define OCLS_USBSTATE 6 /* Host controller functional state */
64 #define OCLB_SMIINT 8 /* SMI Interrupt routing */
65 #define OCLB_REMOTEWAKEUP 10 /* Remote wakeup enabled */
67 #define OCLF_PERIODICENABLE (1UL<<OCLB_PERIODICENABLE)
68 #define OCLF_ISOENABLE (1UL<<OCLB_ISOENABLE)
69 #define OCLF_CTRLENABLE (1UL<<OCLB_CTRLENABLE)
70 #define OCLF_BULKENABLE (1UL<<OCLB_BULKENABLE)
71 #define OCLF_SMIINT (1UL<<OCLB_SMIINT)
72 #define OCLF_REMOTEWAKEUP (1UL<<OCLB_REMOTEWAKEUP)
74 #define OCLM_CBSR (((1UL<<2)-1)<<OCLS_CBSR)
75 #define OCLM_USBSTATE (((1UL<<2)-1)<<OCLS_USBSTATE)
76 #define OCLF_USBRESET (0UL<<OCLS_USBSTATE)
77 #define OCLF_USBRESUME (1UL<<OCLS_USBSTATE)
78 #define OCLF_USBOPER (2UL<<OCLS_USBSTATE)
79 #define OCLF_USBSUSPEND (3UL<<OCLS_USBSTATE)
81 /* OHCI_CMDSTATUS defines */
82 #define OCSB_HCRESET 0 /* Host controller reset */
83 #define OCSB_CTRLENABLE 1 /* Enable Control List processing */
84 #define OCSB_BULKENABLE 2 /* Enable Bulk List processing */
86 #define OCSF_HCRESET (1UL<<OCSB_HCRESET)
87 #define OCSF_CTRLENABLE (1UL<<OCSB_CTRLENABLE)
88 #define OCSF_BULKENABLE (1UL<<OCSB_BULKENABLE)
90 /* OHCI_INTSTATUS, OHCI_INTEN and OHCI_INTDIS defines */
91 #define OISB_SCHEDOVERRUN 0 /* Schedule overrun */
92 #define OISB_DONEHEAD 1 /* Writeback done head */
93 #define OISB_SOF 2 /* Start of Frame */
94 #define OISB_RESUMEDTX 3 /* Resume detected */
95 #define OISB_HOSTERROR 4 /* Unrecoverable error */
96 #define OISB_FRAMECOUNTOVER 5 /* Frame counter overrun (15 bit) */
97 #define OISB_HUBCHANGE 6 /* Root Hub status change */
98 #define OISB_MASTERENABLE 31 /* Master Interrupt enable (INTEN only) */
100 #define OISF_SCHEDOVERRUN (1UL<<OISB_SCHEDOVERRUN)
101 #define OISF_DONEHEAD (1UL<<OISB_DONEHEAD)
102 #define OISF_SOF (1UL<<OISB_SOF)
103 #define OISF_RESUMEDTX (1UL<<OISB_RESUMEDTX)
104 #define OISF_HOSTERROR (1UL<<OISB_HOSTERROR)
105 #define OISF_FRAMECOUNTOVER (1UL<<OISB_FRAMECOUNTOVER)
106 #define OISF_HUBCHANGE (1UL<<OISB_HUBCHANGE)
107 #define OISF_MASTERENABLE (1UL<<OISB_MASTERENABLE)
109 #define OISF_ALL_INTS (OISF_SCHEDOVERRUN|OISF_DONEHEAD|OISF_SOF|OISF_RESUMEDTX|OISF_HOSTERROR|OISF_FRAMECOUNTOVER|OISF_HUBCHANGE|OISF_MASTERENABLE)
111 /* OHCI_INTERVAL defines */
112 #define OIVS_INTERVAL 0 /* Interval, usually 11999 == 0x2edf */
113 #define OIVS_BITSPERFRAME 16 /* Size of the frames in bits, usually ((12000 - 210) * 6) / 7 == 10105 */
114 #define OIVB_TOGGLE 31 /* Toggle on change of interval */
116 #define OIVM_INTERVAL (((1UL<<14)-1)<<OIVS_INTERVAL)
117 #define OIVM_BITSPERFRAME (((1UL<<15)-1)<<OIVS_BITSPERFRAME)
118 #define OIVF_TOGGLE (1UL<<OIVB_TOGGLE)
120 #define OHCI_DEF_BITSPERFRAME 10105
122 /* OHCI_HUBDESCA defines */
123 #define OHAS_NUMPORTS 0 /* Number of downstream ports */
124 #define OHAB_INDIVIDUALPS 8 /* Power switching per port */
125 #define OHAB_NOPOWERSWITCH 9 /* Ports always powered */
126 #define OHAB_INDIVIDUALOC 11 /* Overcurrent Detection per port */
127 #define OHAB_NOOVERCURRENT 12 /* No over-current detection */
128 #define OHAS_POWERGOOD 24 /* Power-good delay */
130 #define OHAM_NUMPORTS (((1UL<<8)-1)<<OHAS_NUMPORTS)
131 #define OHAF_INDIVIDUALPS (1UL<<OHAB_INDIVIDUALPS)
132 #define OHAF_NOPOWERSWITCH (1UL<<OHAB_NOPOWERSWITCH)
133 #define OHAF_INDIVIDUALOC (1UL<<OHAB_INDIVIDUALOC)
134 #define OHAF_NOOVERCURRENT (1UL<<OHAB_NOOVERCURRENT)
135 #define OHAM_POWERGOOD (((1UL<<8)-1)<<OHAS_POWERGOOD)
137 /* OHCI_HUBDESCB defines */
138 #define OHBS_DEVREMOVABLE 0 /* Bitmask of removable devices at roothub (port 1 == bit 1) */
139 #define OHBS_PORTPOWERCTRL 16 /* Bitmask of global power controlled ports */
141 #define OHBM_DEVREMOVABLE (((1UL<<16)-1)<<OHBS_DEVREMOVABLE)
142 #define OHBM_PORTPOWERCTRL (((1UL<<16)-1)<<OHBS_PORTPOWERCTRL)
144 /* OHCI_HUBSTATUS defines */
145 #define OHSB_UNPOWERHUB 0 /* Clear global Hub power */
146 #define OHSB_OVERCURRENT 1 /* Global over-current reported */
147 #define OHSB_POWERHUB 16 /* Set global Hub power */
148 #define OHSB_OVERCURRENTCHG 17 /* Reports change in over-current situation */
150 #define OHSF_UNPOWERHUB (1UL<<OHSB_UNPOWERHUB)
151 #define OHSF_OVERCURRENT (1UL<<OHSB_OVERCURRENT)
152 #define OHSF_POWERHUB (1UL<<OHSB_POWERHUB)
153 #define OHSF_OVERCURRENTCHG (1UL<<OHSB_OVERCURRENTCHG)
155 /* OHCI_PORTSTATUS defines */
156 #define OHPB_PORTCONNECTED 0 /* Port Connection status (r) */
157 #define OHPB_PORTDISABLE 0 /* Clear Port enable (w) */
158 #define OHPB_PORTENABLE 1 /* Port Enabled (r), Enable Port (w) */
159 #define OHPB_PORTSUSPEND 2 /* Port Suspended (r), Suspend Port (w) */
160 #define OHPB_OVERCURRENT 3 /* Port Overcurrent detected (r) */
161 #define OHPB_RESUME 3 /* Resume from suspend (w) */
162 #define OHPB_PORTRESET 4 /* Port in reset (r), Reset port (w) */
163 #define OHPB_PORTPOWER 8 /* Power powered (r), Power port (w) */
164 #define OHPB_LOWSPEED 9 /* Low speed device connected (r) */
165 #define OHPB_PORTUNPOWER 9 /* Clear Port power (w) */
166 #define OHPB_CONNECTCHANGE 16 /* Port Connection change */
167 #define OHPB_ENABLECHANGE 17 /* Port Enable/Disable change */
168 #define OHPB_RESUMEDTX 18 /* Resume detected */
169 #define OHPB_OVERCURRENTCHG 19 /* Over-current change */
170 #define OHPB_RESETCHANGE 20 /* Reset complete */
172 #define OHPF_PORTCONNECTED (1UL<<OHPB_PORTCONNECTED)
173 #define OHPF_PORTDISABLE (1UL<<OHPB_PORTDISABLE)
174 #define OHPF_PORTENABLE (1UL<<OHPB_PORTENABLE)
175 #define OHPF_PORTSUSPEND (1UL<<OHPB_PORTSUSPEND)
176 #define OHPF_OVERCURRENT (1UL<<OHPB_OVERCURRENT)
177 #define OHPF_RESUME (1UL<<OHPB_RESUME)
178 #define OHPF_PORTRESET (1UL<<OHPB_PORTRESET)
179 #define OHPF_PORTPOWER (1UL<<OHPB_PORTPOWER)
180 #define OHPF_LOWSPEED (1UL<<OHPB_LOWSPEED)
181 #define OHPF_PORTUNPOWER (1UL<<OHPB_PORTUNPOWER)
182 #define OHPF_CONNECTCHANGE (1UL<<OHPB_CONNECTCHANGE)
183 #define OHPF_ENABLECHANGE (1UL<<OHPB_ENABLECHANGE)
184 #define OHPF_RESUMEDTX (1UL<<OHPB_RESUMEDTX)
185 #define OHPF_OVERCURRENTCHG (1UL<<OHPB_OVERCURRENTCHG)
186 #define OHPF_RESETCHANGE (1UL<<OHPB_RESETCHANGE)
188 /* data structures */
192 #define OHCI_HCCA_SIZE 256 /* size of HCCA section */
193 #define OHCI_HCCA_ALIGNMENT 0x0ff /* alignment of HCCA section */
197 ULONG oha_IntEDs
[32]; /* LE PHYSICAL pointer to Interrupt EDs */
198 UWORD oha_FrameCount
; /* LE Framecounter */
199 UWORD oha_FrmCntChg
; /* Set 0 when framecounter was updated */
200 ULONG oha_DoneHead
; /* LE PHYSICAL pointer to Head of ED finished + unmasked Int */
204 #define OHCI_PAGE_SIZE 4096
206 #define OHCI_TDQH_ALIGNMENT 0x001f
208 #define OHCI_ED_POOLSIZE 128
209 #define OHCI_TD_POOLSIZE 512
211 #define OHCI_TD_BULK_LIMIT (128<<10) // limit for one batch of BULK data TDs
216 struct OhciED
*oed_Succ
;
217 struct OhciED
*oed_Pred
;
218 ULONG oed_Self
; /* LE PHYSICAL pointer to self */
219 struct IOUsbHWReq
*oed_IOReq
; /* IO Request this belongs to */
221 struct OhciTD
*oed_FirstTD
; /* First TD */
222 ULONG oed_Continue
; /* Flag for fragmented bulk transfer */
226 /* HC data, aligned to 16 bytes */
227 ULONG oed_EPCaps
; /* LE MaxPacketSize and other stuff */
228 ULONG oed_TailPtr
; /* LE PHYSICAL TD Queue Tail Pointer */
229 ULONG oed_HeadPtr
; /* LE PHYSICAL TD Queue Head Pointer */
230 ULONG oed_NextED
; /* LE PHYSICAL Next Endpoint Descriptor */
235 struct OhciTD
*otd_Succ
;
236 ULONG otd_Length
; /* Length of transfer */
237 //struct OhciTD *otd_Pred;
238 ULONG otd_Self
; /* LE PHYSICAL pointer to self */
239 struct OhciED
*otd_ED
; /* Pointer to parent ED this TD belongs to */
241 /* HC data, aligned to 16 bytes */
242 ULONG otd_Ctrl
; /* LE Ctrl stuff */
243 ULONG otd_BufferPtr
; /* LE PHYSICAL Current Buffer Pointer */
244 ULONG otd_NextTD
; /* LE PHYSICAL Next TD */
245 ULONG otd_BufferEnd
; /* LE PHYSICAL End of buffer */
248 /* pointer defines */
250 #define OHCI_PTRMASK 0xfffffff0 /* frame list pointer mask */
252 /* ED EPCaps defines */
254 #define OECB_LOWSPEED 13 /* Lowspeed */
255 #define OECB_SKIP 14 /* Skip ED */
256 #define OECB_ISO 15 /* Isochronous endpoint */
258 #define OECS_DEVADDR 0 /* Device Address */
259 #define OECS_ENDPOINT 7 /* Endpoint number */
260 #define OECS_DIRECTION 11 /* Direction */
261 #define OECS_MAXPKTLEN 16 /* MaxPacketLength */
263 #define OECF_LOWSPEED (1UL<<OECB_LOWSPEED)
264 #define OECF_SKIP (1UL<<OECB_SKIP)
265 #define OECF_ISO (1UL<<OECB_ISO)
267 #define OECM_DEVADDR (((1UL<<7)-1)<<OECS_DEVADDR)
268 #define OECM_ENDPOINT (((1UL<<4)-1)<<OECS_ENDPOINT)
269 #define OECM_MAXPKTLEN (((1UL<<11)-1)<<OECS_MAXPKTLEN)
271 #define OECM_DIRECTION (((1UL<<2)-1)<<OECS_DIRECTION)
272 #define OECF_DIRECTION_TD (0UL<<OECS_DIRECTION)
273 #define OECF_DIRECTION_OUT (1UL<<OECS_DIRECTION)
274 #define OECF_DIRECTION_IN (2UL<<OECS_DIRECTION)
276 /* ED HeadPtr defines */
278 #define OEHB_HALTED 0 /* TD Queue is halted */
279 #define OEHB_DATA1 1 /* Data 1 Toggle bit */
281 #define OEHF_HALTED (1UL<<OEHB_HALTED)
282 #define OEHF_DATA1 (1UL<<OEHB_DATA1)
284 /* TD Ctrl defines */
286 #define OTCB_ALLOWSHORTPKT 18 /* Allow short packets */
287 #define OTCB_DATA1 24 /* Data 1 toggle bit */
288 #define OTCB_TOGGLEFROMTD 25 /* Data toggle comes from TD */
290 #define OTCS_PIDCODE 19 /* PID code */
291 #define OTCS_DELAYINT 21 /* Delay interrupt by given amount of frames */
292 #define OTCS_ERRORCOUNT 26 /* Number of errors occurred so far */
293 #define OTCS_COMPLETIONCODE 28 /* Error codes */
295 #define OTCF_ALLOWSHORTPKT (1UL<<OTCB_ALLOWSHORTPKT)
296 #define OTCF_DATA0 (0UL<<OTCB_DATA1)
297 #define OTCF_DATA1 (1UL<<OTCB_DATA1)
298 #define OTCF_TOGGLEFROMTD (1UL<<OTCB_TOGGLEFROMTD)
300 #define OTCM_PIDCODE (((1UL<<2)-1)<<OTCS_PIDCODE)
301 #define OTCF_PIDCODE_SETUP (0UL<<OTCS_PIDCODE)
302 #define OTCF_PIDCODE_OUT (1UL<<OTCS_PIDCODE)
303 #define OTCF_PIDCODE_IN (2UL<<OTCS_PIDCODE)
305 #define OTCM_DELAYINT (((1UL<<3)-1)<<OTCS_DELAYINT)
306 #define OTCF_NOINT (7UL<<OTCS_DELAYINT)
308 #define OTCM_ERRORCOUNT (((1UL<<2)-1)<<OTCS_ERRORCOUNT)
309 #define OTCM_COMPLETIONCODE (((1UL<<4)-1)<<OTCS_COMPLETIONCODE)
310 #define OTCF_CC_NOERROR (0UL<<OTCS_COMPLETIONCODE)
311 #define OTCF_CC_CRCERROR (1UL<<OTCS_COMPLETIONCODE)
312 #define OTCF_CC_BABBLE (2UL<<OTCS_COMPLETIONCODE)
313 #define OTCF_CC_WRONGTOGGLE (3UL<<OTCS_COMPLETIONCODE)
314 #define OTCF_CC_STALL (4UL<<OTCS_COMPLETIONCODE)
315 #define OTCF_CC_TIMEOUT (5UL<<OTCS_COMPLETIONCODE)
316 #define OTCF_CC_PIDCORRUPT (6UL<<OTCS_COMPLETIONCODE)
317 #define OTCF_CC_WRONGPID (7UL<<OTCS_COMPLETIONCODE)
318 #define OTCF_CC_OVERFLOW (8UL<<OTCS_COMPLETIONCODE)
319 #define OTCF_CC_SHORTPKT (9UL<<OTCS_COMPLETIONCODE)
320 #define OTCF_CC_OVERRUN (12UL<<OTCS_COMPLETIONCODE)
321 #define OTCF_CC_UNDERRUN (13UL<<OTCS_COMPLETIONCODE)
322 #define OTCF_CC_INVALID (15UL<<OTCS_COMPLETIONCODE)
324 #endif /* OHCICHIP_H */