xref: /haiku/src/add-ons/kernel/busses/usb/ohci_hardware.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2005, Jan-Rixt Van Hoye
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //------------------------------------------------------------------------------
22 
23 #ifndef OHCI_HARD_H
24 #define OHCI_HARD_H
25 
26 // --------------------------------
27 //	The OHCI registers
28 // --------------------------------
29 
30 // --------------------------------
31 //	Revision register (section 7.1.1)
32 // --------------------------------
33 
34 #define	OHCI_REVISION				0x00	// OHCI revision
35 #define		OHCI_REV_LO(rev)		((rev)&0xf)
36 #define		OHCI_REV_HI(rev)		(((rev)>>4)&0xf)
37 #define		OHCI_REV_LEGACY(rev)	((rev) & 0x100)
38 
39 // --------------------------------
40 //	Control register (section 7.1.2)
41 // --------------------------------
42 
43 #define	OHCI_CONTROL				0x04
44 #define		OHCI_CBSR_MASK			0x00000003 // Control-Bulk Service Ratio
45 #define			OHCI_RATIO_1_1		0x00000000
46 #define			OHCI_RATIO_1_2		0x00000001
47 #define			OHCI_RATIO_1_3		0x00000002
48 #define			OHCI_RATIO_1_4		0x00000003
49 #define		OHCI_PLE				0x00000004 // Periodic List Enable
50 #define		OHCI_IE					0x00000008 // Isochronous Enable
51 #define		OHCI_CLE				0x00000010 // Control List Enable
52 #define		OHCI_BLE				0x00000020 // Bulk List Enable
53 #define		OHCI_HCFS_MASK			0x000000c0 // HostControllerFunctionalState
54 #define		OHCI_HCFS_RESET			0x00000000
55 #define		OHCI_HCFS_RESUME		0x00000040
56 #define		OHCI_HCFS_OPERATIONAL	0x00000080
57 #define		OHCI_HCFS_SUSPEND		0x000000c0
58 #define		OHCI_IR					0x00000100 // Interrupt Routing
59 #define		OHCI_RWC				0x00000200 // Remote Wakeup Connected
60 #define		OHCI_RWE				0x00000400 // Remote Wakeup Enabled
61 
62 // --------------------------------
63 //	Command status register (section 7.1.3)
64 // --------------------------------
65 
66 #define OHCI_COMMAND_STATUS	0x08
67 #define		OHCI_HCR				0x00000001 // Host Controller Reset
68 #define		OHCI_CLF				0x00000002 // Control List Filled
69 #define		OHCI_BLF				0x00000004 // Bulk List Filled
70 #define		OHCI_OCR				0x00000008 // Ownership Change Request
71 #define		OHCI_SOC_MASK			0x00030000 // Scheduling Overrun Count
72 
73 // --------------------------------
74 //	Interupt status register (section 7.1.4)
75 // --------------------------------
76 
77 #define OHCI_INTERRUPT_STATUS	0x0c
78 #define		OHCI_SO					0x00000001 // Scheduling Overrun
79 #define		OHCI_WDH				0x00000002 // Writeback Done Head
80 #define		OHCI_SF					0x00000004 // Start of Frame
81 #define		OHCI_RD					0x00000008 // Resume Detected
82 #define		OHCI_UE					0x00000010 // Unrecoverable Error
83 #define		OHCI_FNO				0x00000020 // Frame Number Overflow
84 #define		OHCI_RHSC				0x00000040 // Root Hub Status Change
85 #define		OHCI_OC					0x40000000 // Ownership Change
86 #define		OHCI_MIE				0x80000000 // Master Interrupt Enable
87 
88 // --------------------------------
89 //	Interupt enable register (section 7.1.5)
90 // --------------------------------
91 
92 #define OHCI_INTERRUPT_ENABLE		0x10
93 
94 // --------------------------------
95 //	Interupt disable register (section 7.1.6)
96 // --------------------------------
97 
98 #define OHCI_INTERRUPT_DISABLE		0x14
99 
100 // -------------------------------------
101 //	Memory Pointer Partition (section 7.2)
102 // -------------------------------------
103 
104 // --------------------------------
105 //	HCCA register (section 7.2.1)
106 // --------------------------------
107 
108 #define OHCI_HCCA					0x18
109 
110 // --------------------------------
111 //	Period current ED  register (section 7.2.2)
112 // --------------------------------
113 
114 #define OHCI_PERIOD_CURRENT_ED		0x1c
115 
116 // --------------------------------
117 //	Control head ED register (section 7.2.3)
118 // --------------------------------
119 
120 #define OHCI_CONTROL_HEAD_ED		0x20
121 
122 // --------------------------------
123 //	Current control ED register (section 7.2.4)
124 // --------------------------------
125 
126 #define OHCI_CONTROL_CURRENT_ED		0x24
127 
128 // --------------------------------
129 //	Bulk head ED register (section 7.2.5)
130 // --------------------------------
131 
132 #define OHCI_BULK_HEAD_ED			0x28
133 
134 // --------------------------------
135 //	Current bulk ED register (section 7.2.6)
136 // --------------------------------
137 
138 #define OHCI_BULK_CURRENT_ED		0x2c
139 
140 // --------------------------------
141 //	Done head register (section 7.2.7)
142 // --------------------------------
143 
144 #define OHCI_DONE_HEAD				0x30
145 
146 // --------------------------------
147 //	Frame Counter partition (section 7.3)
148 // --------------------------------
149 
150 // --------------------------------
151 //	Frame interval register (section 7.3.1)
152 // --------------------------------
153 
154 #define OHCI_FM_INTERVAL			0x34
155 #define		OHCI_GET_IVAL(s)		((s) & 0x3fff)
156 #define		OHCI_GET_FSMPS(s)		(((s) >> 16) & 0x7fff)
157 #define		OHCI_FIT				0x80000000
158 
159 // --------------------------------
160 //	Frame remaining register (section 7.3.2)
161 // --------------------------------
162 
163 #define OHCI_FM_REMAINING			0x38
164 
165 // --------------------------------
166 //	Frame number register	(section 7.3.3)
167 // --------------------------------
168 
169 #define OHCI_FM_NUMBER				0x3c
170 
171 // --------------------------------
172 //	Periodic start register (section 7.3.4)
173 // --------------------------------
174 
175 #define OHCI_PERIODIC_START			0x40
176 
177 // --------------------------------
178 //	LS treshold register (section 7.3.5)
179 // --------------------------------
180 
181 #define OHCI_LS_THRESHOLD			0x44
182 
183 // --------------------------------
184 //	Root Hub Partition (section 7.4)
185 // --------------------------------
186 
187 // --------------------------------
188 //	Root Hub Descriptor A register (section 7.4.1)
189 // --------------------------------
190 
191 #define OHCI_RH_DESCRIPTOR_A		0x48
192 #define		OHCI_GET_NDP(s)			((s) & 0xff)
193 #define		OHCI_PSM				0x0100     // Power Switching Mode
194 #define		OHCI_NPS				0x0200	   // No Power Switching
195 #define		OHCI_DT					0x0400     // Device Type
196 #define		OHCI_OCPM				0x0800     // Overcurrent Protection Mode
197 #define		OHCI_NOCP				0x1000     // No Overcurrent Protection
198 #define		OHCI_GET_POTPGT(s)		((s) >> 24)
199 
200 // --------------------------------
201 //	Root Hub Descriptor B register (section 7.4.2)
202 // --------------------------------
203 
204 #define OHCI_RH_DESCRIPTOR_B		0x4c
205 
206 // --------------------------------
207 //	Root Hub status register (section 7.4.3)
208 // --------------------------------
209 
210 #define OHCI_RH_STATUS				0x50
211 #define		OHCI_LPS				0x00000001 // Local Power Status
212 #define		OHCI_OCI				0x00000002 // OverCurrent Indicator
213 #define		OHCI_DRWE				0x00008000 // Device Remote Wakeup Enable
214 #define		OHCI_LPSC				0x00010000 // Local Power Status Change
215 #define		OHCI_CCIC				0x00020000 // OverCurrent Indicator Change
216 #define		OHCI_CRWE				0x80000000 // Clear Remote Wakeup Enable
217 
218 // --------------------------------
219 //	Root Hub port status (n) register (section 7.4.4)
220 // --------------------------------
221 
222 #define OHCI_RH_PORT_STATUS(n)		(0x50 + (n)*4) // 1 based indexing
223 
224 // --------------------------------
225 //	????
226 // --------------------------------
227 
228 #define OHCI_LES					(OHCI_PLE | OHCI_IE | OHCI_CLE | OHCI_BLE)
229 
230 // --------------------------------
231 //	All interupts
232 // --------------------------------
233 
234 #define OHCI_ALL_INTRS				(OHCI_SO | OHCI_WDH | OHCI_SF | OHCI_RD | OHCI_UE | OHCI_FNO | OHCI_RHSC | OHCI_OC)
235 
236 // --------------------------------
237 //	All normal interupts
238 // --------------------------------
239 
240 #define OHCI_NORMAL_INTRS			(OHCI_SO | OHCI_WDH | OHCI_RD | OHCI_UE | OHCI_RHSC)
241 
242 // --------------------------------
243 //	FSMPS
244 // --------------------------------
245 
246 #define OHCI_FSMPS(i)				(((i-210)*6/7) << 16)
247 
248 // --------------------------------
249 //	Periodic
250 // --------------------------------
251 
252 #define OHCI_PERIODIC(i)			((i)*9/10)
253 
254 // --------------------------------
255 //	OHCI physical address
256 // --------------------------------
257 
258 typedef uint32 ohci_physaddr_t;
259 
260 // --------------------------------
261 //	HCCA structure (section 4.4)
262 // --------------------------------
263 
264 #define OHCI_NO_INTRS				32
265 
266 struct hc_hcca
267 {
268 	addr_t		hcca_interrupt_table[OHCI_NO_INTRS];
269 	uint32		hcca_frame_number;
270 	addr_t		hcca_done_head;
271 	uint8		hcca_reserved_for_hc[116];
272 };
273 
274 #define OHCI_DONE_INTRS				1
275 #define OHCI_HCCA_SIZE				256
276 #define OHCI_HCCA_ALIGN				256
277 #define OHCI_PAGE_SIZE				0x1000
278 #define OHCI_PAGE(x)				((x) &~ 0xfff)
279 #define OHCI_PAGE_OFFSET(x)			((x) & 0xfff)
280 
281 // --------------------------------
282 //	Endpoint descriptor structure (section 4.2)
283 // --------------------------------
284 
285 typedef struct hc_endpoint_descriptor
286 {
287 	uint32		ed_flags;
288 	addr_t		ed_qtailp;		// Queue tail pointer
289 	addr_t		ed_qheadp;		// Queue head pointer
290 	addr_t		ed_nexted;		// Next endpoint in the list
291 };
292 
293 #define OHCI_ED_GET_FA(s)			((s) & 0x7f)
294 #define OHCI_ED_ADDRMASK			0x0000007f
295 #define OHCI_ED_SET_FA(s)			(s)
296 #define OHCI_ED_GET_EN(s)			(((s) >> 7) & 0xf)
297 #define OHCI_ED_SET_EN(s)			((s) << 7)
298 #define OHCI_ED_DIR_MASK			0x00001800
299 #define  	OHCI_ED_DIR_TD			0x00000000
300 #define  	OHCI_ED_DIR_OUT			0x00000800
301 #define  	OHCI_ED_DIR_IN			0x00001000
302 #define OHCI_ED_SPEED				0x00002000
303 #define OHCI_ED_SKIP				0x00004000
304 #define OHCI_ED_FORMAT_GEN			0x00000000
305 #define OHCI_ED_FORMAT_ISO			0x00008000
306 #define OHCI_ED_GET_MAXP(s)			(((s) >> 16) & 0x07ff)
307 #define OHCI_ED_SET_MAXP(s)			((s) << 16)
308 #define OHCI_ED_MAXPMASK			(0x7ff << 16)
309 
310 #define OHCI_HALTED					0x00000001
311 #define OHCI_TOGGLECARRY			0x00000002
312 #define OHCI_HEADMASK				0xfffffffc
313 
314 #define OHCI_ED_ALIGN 16
315 
316 // --------------------------------
317 //	General transfer descriptor structure (section 4.3.1)
318 // --------------------------------
319 
320 typedef struct hc_transfer_descriptor
321 {
322 	uint32		td_flags;
323 	addr_t		td_cbp;			// Current Buffer Pointer
324 	addr_t 		td_nexttd;		// Next Transfer Descriptor
325 	addr_t 		td_be;			// Buffer End
326 } ;
327 
328 #define OHCI_TD_R					0x00040000		// Buffer Rounding
329 #define OHCI_TD_DP_MASK				0x00180000		// Direction / PID
330 #define  	OHCI_TD_SETUP			0x00000000
331 #define  	OHCI_TD_OUT				0x00080000
332 #define  	OHCI_TD_IN				0x00100000
333 #define OHCI_TD_GET_DI(x)			(((x) >> 21) & 7)	// Delay Interrupt
334 #define OHCI_TD_SET_DI(x)			((x) << 21)
335 #define  	OHCI_TD_NOINTR			0x00e00000
336 #define  	OHCI_TD_INTR_MASK		0x00e00000
337 #define OHCI_TD_TOGGLE_CARRY		0x00000000
338 #define OHCI_TD_TOGGLE_0			0x02000000
339 #define OHCI_TD_TOGGLE_1			0x03000000
340 #define OHCI_TD_TOGGLE_MASK			0x03000000
341 #define OHCI_TD_GET_EC(x)			(((x) >> 26) & 3)	// Error Count
342 #define OHCI_TD_GET_CC(x)			((x) >> 28)			// Condition Code
343 #define  	OHCI_TD_NOCC			0xf0000000
344 
345 #define OHCI_TD_ALIGN 16
346 
347 // --------------------------------
348 //	Isonchronous transfer descriptor structure (section 4.3.2)
349 // --------------------------------
350 
351 #define OHCI_ITD_NOFFSET 8
352 typedef struct hc_itransfer_descriptor
353 {
354 	uint32		itd_flags;
355 	addr_t		itd_bp0;						// Buffer Page 0
356 	addr_t		itd_nextitd;					// Next Isochronous Transfer Descriptor
357 	addr_t		itd_be;							// Buffer End
358 	uint16		itd_offset[OHCI_ITD_NOFFSET];	// Buffer offsets
359 
360 };
361 
362 #define OHCI_ITD_GET_SF(x)			((x) & 0x0000ffff)
363 #define OHCI_ITD_SET_SF(x)			((x) & 0xffff)
364 #define OHCI_ITD_GET_DI(x)			(((x) >> 21) & 7)		// Delay Interrupt
365 #define OHCI_ITD_SET_DI(x)			((x) << 21)
366 #define  	OHCI_ITD_NOINTR			0x00e00000
367 #define OHCI_ITD_GET_FC(x)			((((x) >> 24) & 7)+1)	// Frame Count
368 #define OHCI_ITD_SET_FC(x)			(((x)-1) << 24)
369 #define OHCI_ITD_GET_CC(x)			((x) >> 28)				// Condition Code
370 #define  	OHCI_ITD_NOCC			0xf0000000
371 
372 #define itd_pswn itd_offset									// Packet Status Word
373 #define OHCI_ITD_PAGE_SELECT		0x00001000
374 #define OHCI_ITD_MK_OFFS(len)		(0xe000 | ((len) & 0x1fff))
375 #define OHCI_ITD_PSW_LENGTH(x)		((x) & 0xfff)		// Transfer length
376 #define OHCI_ITD_PSW_GET_CC(x)		((x) >> 12)			// Condition Code
377 
378 #define OHCI_ITD_ALIGN 32
379 
380 // --------------------------------
381 //	Completion Codes (section 4.3.3)
382 // --------------------------------
383 
384 #define OHCI_CC_NO_ERROR				0
385 #define OHCI_CC_CRC						1
386 #define OHCI_CC_BIT_STUFFING			2
387 #define OHCI_CC_DATA_TOGGLE_MISMATCH	3
388 #define OHCI_CC_STALL					4
389 #define OHCI_CC_DEVICE_NOT_RESPONDING	5
390 #define OHCI_CC_PID_CHECK_FAILURE		6
391 #define OHCI_CC_UNEXPECTED_PID			7
392 #define OHCI_CC_DATA_OVERRUN			8
393 #define OHCI_CC_DATA_UNDERRUN			9
394 #define OHCI_CC_BUFFER_OVERRUN			12
395 #define OHCI_CC_BUFFER_UNDERRUN			13
396 #define OHCI_CC_NOT_ACCESSED			15
397 
398 // --------------------------------
399 // 	Some delay needed when changing
400 //	certain registers.
401 // --------------------------------
402 
403 #define OHCI_ENABLE_POWER_DELAY			5
404 #define OHCI_READ_DESC_DELAY			5
405 
406 #endif // OHCI_HARD_H
407