ehci.h revision 199058
1184610Salfred/* $FreeBSD: head/sys/dev/usb/controller/ehci.h 199058 2009-11-08 20:51:15Z thompsa $ */
2184610Salfred/*-
3184610Salfred * Copyright (c) 2001 The NetBSD Foundation, Inc.
4184610Salfred * All rights reserved.
5184610Salfred *
6184610Salfred * This code is derived from software contributed to The NetBSD Foundation
7184610Salfred * by Lennart Augustsson (lennart@augustsson.net).
8184610Salfred *
9184610Salfred * Redistribution and use in source and binary forms, with or without
10184610Salfred * modification, are permitted provided that the following conditions
11184610Salfred * are met:
12184610Salfred * 1. Redistributions of source code must retain the above copyright
13184610Salfred *    notice, this list of conditions and the following disclaimer.
14184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
15184610Salfred *    notice, this list of conditions and the following disclaimer in the
16184610Salfred *    documentation and/or other materials provided with the distribution.
17184610Salfred * 3. All advertising materials mentioning features or use of this software
18184610Salfred *    must display the following acknowledgement:
19184610Salfred *        This product includes software developed by the NetBSD
20184610Salfred *        Foundation, Inc. and its contributors.
21184610Salfred * 4. Neither the name of The NetBSD Foundation nor the names of its
22184610Salfred *    contributors may be used to endorse or promote products derived
23184610Salfred *    from this software without specific prior written permission.
24184610Salfred *
25184610Salfred * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26184610Salfred * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27184610Salfred * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28184610Salfred * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29184610Salfred * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30184610Salfred * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31184610Salfred * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32184610Salfred * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33184610Salfred * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34184610Salfred * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35184610Salfred * POSSIBILITY OF SUCH DAMAGE.
36184610Salfred */
37184610Salfred
38184610Salfred#ifndef _EHCI_H_
39184610Salfred#define	_EHCI_H_
40184610Salfred
41190174Sthompsa#define	EHCI_MAX_DEVICES MIN(USB_MAX_DEVICES, 128)
42187170Sthompsa
43184610Salfred/*
44184610Salfred * Alignment NOTE: structures must be aligned so that the hardware can index
45184610Salfred * without performing addition.
46184610Salfred */
47184610Salfred#define	EHCI_FRAMELIST_ALIGN          0x1000	/* bytes */
48184610Salfred#define	EHCI_FRAMELIST_COUNT            1024	/* units */
49184610Salfred#define	EHCI_VIRTUAL_FRAMELIST_COUNT     128	/* units */
50184610Salfred
51184610Salfred#if ((8*EHCI_VIRTUAL_FRAMELIST_COUNT) < USB_MAX_HS_ISOC_FRAMES_PER_XFER)
52184610Salfred#error "maximum number of high-speed isochronous frames is higher than supported!"
53184610Salfred#endif
54184610Salfred
55184610Salfred#if (EHCI_VIRTUAL_FRAMELIST_COUNT < USB_MAX_FS_ISOC_FRAMES_PER_XFER)
56184610Salfred#error "maximum number of full-speed isochronous frames is higher than supported!"
57184610Salfred#endif
58184610Salfred
59184610Salfred/* Link types */
60184610Salfred#define	EHCI_LINK_TERMINATE	0x00000001
61184610Salfred#define	EHCI_LINK_TYPE(x)	((x) & 0x00000006)
62184610Salfred#define	EHCI_LINK_ITD		0x0
63184610Salfred#define	EHCI_LINK_QH		0x2
64184610Salfred#define	EHCI_LINK_SITD		0x4
65184610Salfred#define	EHCI_LINK_FSTN		0x6
66184610Salfred#define	EHCI_LINK_ADDR(x)	((x) &~ 0x1f)
67184610Salfred
68184610Salfred/* Structures alignment (bytes) */
69184610Salfred#define	EHCI_ITD_ALIGN	128
70184610Salfred#define	EHCI_SITD_ALIGN	64
71184610Salfred#define	EHCI_QTD_ALIGN	64
72184610Salfred#define	EHCI_QH_ALIGN	128
73184610Salfred#define	EHCI_FSTN_ALIGN	32
74184610Salfred/* Data buffers are divided into one or more pages */
75184610Salfred#define	EHCI_PAGE_SIZE	0x1000
76184610Salfred#if	((USB_PAGE_SIZE < EHCI_PAGE_SIZE) || (EHCI_PAGE_SIZE == 0) ||	\
77184610Salfred	(USB_PAGE_SIZE < EHCI_ITD_ALIGN) || (EHCI_ITD_ALIGN == 0) ||	\
78184610Salfred	(USB_PAGE_SIZE < EHCI_SITD_ALIGN) || (EHCI_SITD_ALIGN == 0) ||	\
79184610Salfred	(USB_PAGE_SIZE < EHCI_QTD_ALIGN) || (EHCI_QTD_ALIGN == 0) ||	\
80184610Salfred	(USB_PAGE_SIZE < EHCI_QH_ALIGN) || (EHCI_QH_ALIGN == 0) ||	\
81184610Salfred	(USB_PAGE_SIZE < EHCI_FSTN_ALIGN) || (EHCI_FSTN_ALIGN == 0))
82184610Salfred#error	"Invalid USB page size!"
83184610Salfred#endif
84184610Salfred
85184610Salfred
86184610Salfred/*
87184610Salfred * Isochronous Transfer Descriptor.  This descriptor is used for high speed
88184610Salfred * transfers only.
89184610Salfred */
90184610Salfredstruct ehci_itd {
91184610Salfred	volatile uint32_t itd_next;
92184610Salfred	volatile uint32_t itd_status[8];
93184610Salfred#define	EHCI_ITD_SET_LEN(x)	((x) << 16)
94184610Salfred#define	EHCI_ITD_GET_LEN(x)	(((x) >> 16) & 0xFFF)
95184610Salfred#define	EHCI_ITD_IOC		(1 << 15)
96184610Salfred#define	EHCI_ITD_SET_PG(x)	((x) << 12)
97184610Salfred#define	EHCI_ITD_GET_PG(x)	(((x) >> 12) & 0x7)
98184610Salfred#define	EHCI_ITD_SET_OFFS(x)	(x)
99184610Salfred#define	EHCI_ITD_GET_OFFS(x)	(((x) >> 0) & 0xFFF)
100184610Salfred#define	EHCI_ITD_ACTIVE		(1 << 31)
101184610Salfred#define	EHCI_ITD_DATABUFERR	(1 << 30)
102184610Salfred#define	EHCI_ITD_BABBLE		(1 << 29)
103184610Salfred#define	EHCI_ITD_XACTERR	(1 << 28)
104184610Salfred	volatile uint32_t itd_bp[7];
105184610Salfred	/* itd_bp[0] */
106184610Salfred#define	EHCI_ITD_SET_ADDR(x)	(x)
107184610Salfred#define	EHCI_ITD_GET_ADDR(x)	(((x) >> 0) & 0x7F)
108184610Salfred#define	EHCI_ITD_SET_ENDPT(x)	((x) << 8)
109184610Salfred#define	EHCI_ITD_GET_ENDPT(x)	(((x) >> 8) & 0xF)
110184610Salfred	/* itd_bp[1] */
111184610Salfred#define	EHCI_ITD_SET_DIR_IN	(1 << 11)
112184610Salfred#define	EHCI_ITD_SET_DIR_OUT	(0 << 11)
113184610Salfred#define	EHCI_ITD_SET_MPL(x)	(x)
114184610Salfred#define	EHCI_ITD_GET_MPL(x)	(((x) >> 0) & 0x7FF)
115184610Salfred	volatile uint32_t itd_bp_hi[7];
116184610Salfred/*
117184610Salfred * Extra information needed:
118184610Salfred */
119184610Salfred	uint32_t itd_self;
120184610Salfred	struct ehci_itd *next;
121184610Salfred	struct ehci_itd *prev;
122184610Salfred	struct ehci_itd *obj_next;
123192984Sthompsa	struct usb_page_cache *page_cache;
124184610Salfred} __aligned(EHCI_ITD_ALIGN);
125184610Salfred
126184610Salfredtypedef struct ehci_itd ehci_itd_t;
127184610Salfred
128184610Salfred/*
129184610Salfred * Split Transaction Isochronous Transfer Descriptor.  This descriptor is used
130184610Salfred * for full speed transfers only.
131184610Salfred */
132184610Salfredstruct ehci_sitd {
133184610Salfred	volatile uint32_t sitd_next;
134184610Salfred	volatile uint32_t sitd_portaddr;
135184610Salfred#define	EHCI_SITD_SET_DIR_OUT	(0 << 31)
136184610Salfred#define	EHCI_SITD_SET_DIR_IN	(1 << 31)
137184610Salfred#define	EHCI_SITD_SET_ADDR(x)	(x)
138184610Salfred#define	EHCI_SITD_GET_ADDR(x)	((x) & 0x7F)
139184610Salfred#define	EHCI_SITD_SET_ENDPT(x)	((x) << 8)
140184610Salfred#define	EHCI_SITD_GET_ENDPT(x)	(((x) >> 8) & 0xF)
141184610Salfred#define	EHCI_SITD_GET_DIR(x)	((x) >> 31)
142184610Salfred#define	EHCI_SITD_SET_PORT(x)	((x) << 24)
143184610Salfred#define	EHCI_SITD_GET_PORT(x)	(((x) >> 24) & 0x7F)
144184610Salfred#define	EHCI_SITD_SET_HUBA(x)	((x) << 16)
145184610Salfred#define	EHCI_SITD_GET_HUBA(x)	(((x) >> 16) & 0x7F)
146184610Salfred	volatile uint32_t sitd_mask;
147184610Salfred#define	EHCI_SITD_SET_SMASK(x)	(x)
148184610Salfred#define	EHCI_SITD_SET_CMASK(x)	((x) << 8)
149184610Salfred	volatile uint32_t sitd_status;
150184610Salfred#define	EHCI_SITD_COMPLETE_SPLIT	(1<<1)
151184610Salfred#define	EHCI_SITD_START_SPLIT		(0<<1)
152184610Salfred#define	EHCI_SITD_MISSED_MICRO_FRAME	(1<<2)
153184610Salfred#define	EHCI_SITD_XACTERR		(1<<3)
154184610Salfred#define	EHCI_SITD_BABBLE		(1<<4)
155184610Salfred#define	EHCI_SITD_DATABUFERR		(1<<5)
156184610Salfred#define	EHCI_SITD_ERROR			(1<<6)
157184610Salfred#define	EHCI_SITD_ACTIVE		(1<<7)
158184610Salfred#define	EHCI_SITD_IOC			(1<<31)
159184610Salfred#define	EHCI_SITD_SET_LEN(len)		((len)<<16)
160184610Salfred#define	EHCI_SITD_GET_LEN(x)		(((x)>>16) & 0x3FF)
161184610Salfred	volatile uint32_t sitd_bp[2];
162184610Salfred	volatile uint32_t sitd_back;
163184610Salfred	volatile uint32_t sitd_bp_hi[2];
164184610Salfred/*
165184610Salfred * Extra information needed:
166184610Salfred */
167184610Salfred	uint32_t sitd_self;
168184610Salfred	struct ehci_sitd *next;
169184610Salfred	struct ehci_sitd *prev;
170184610Salfred	struct ehci_sitd *obj_next;
171192984Sthompsa	struct usb_page_cache *page_cache;
172184610Salfred} __aligned(EHCI_SITD_ALIGN);
173184610Salfred
174184610Salfredtypedef struct ehci_sitd ehci_sitd_t;
175184610Salfred
176184610Salfred/* Queue Element Transfer Descriptor */
177184610Salfredstruct ehci_qtd {
178184610Salfred	volatile uint32_t qtd_next;
179184610Salfred	volatile uint32_t qtd_altnext;
180184610Salfred	volatile uint32_t qtd_status;
181184610Salfred#define	EHCI_QTD_GET_STATUS(x)	(((x) >>  0) & 0xff)
182184610Salfred#define	EHCI_QTD_SET_STATUS(x)  ((x) << 0)
183184610Salfred#define	EHCI_QTD_ACTIVE		0x80
184184610Salfred#define	EHCI_QTD_HALTED		0x40
185184610Salfred#define	EHCI_QTD_BUFERR		0x20
186184610Salfred#define	EHCI_QTD_BABBLE		0x10
187184610Salfred#define	EHCI_QTD_XACTERR	0x08
188184610Salfred#define	EHCI_QTD_MISSEDMICRO	0x04
189184610Salfred#define	EHCI_QTD_SPLITXSTATE	0x02
190184610Salfred#define	EHCI_QTD_PINGSTATE	0x01
191184610Salfred#define	EHCI_QTD_STATERRS	0x74
192184610Salfred#define	EHCI_QTD_GET_PID(x)	(((x) >>  8) & 0x3)
193184610Salfred#define	EHCI_QTD_SET_PID(x)	((x) <<  8)
194184610Salfred#define	EHCI_QTD_PID_OUT	0x0
195184610Salfred#define	EHCI_QTD_PID_IN		0x1
196184610Salfred#define	EHCI_QTD_PID_SETUP	0x2
197184610Salfred#define	EHCI_QTD_GET_CERR(x)	(((x) >> 10) &  0x3)
198184610Salfred#define	EHCI_QTD_SET_CERR(x)	((x) << 10)
199184610Salfred#define	EHCI_QTD_GET_C_PAGE(x)	(((x) >> 12) &  0x7)
200184610Salfred#define	EHCI_QTD_SET_C_PAGE(x)	((x) << 12)
201184610Salfred#define	EHCI_QTD_GET_IOC(x)	(((x) >> 15) &  0x1)
202184610Salfred#define	EHCI_QTD_IOC		0x00008000
203184610Salfred#define	EHCI_QTD_GET_BYTES(x)	(((x) >> 16) &  0x7fff)
204184610Salfred#define	EHCI_QTD_SET_BYTES(x)	((x) << 16)
205184610Salfred#define	EHCI_QTD_GET_TOGGLE(x)	(((x) >> 31) &  0x1)
206184610Salfred#define	EHCI_QTD_SET_TOGGLE(x)	((x) << 31)
207184610Salfred#define	EHCI_QTD_TOGGLE_MASK	0x80000000
208184610Salfred#define	EHCI_QTD_NBUFFERS	5
209184610Salfred#define	EHCI_QTD_PAYLOAD_MAX ((EHCI_QTD_NBUFFERS-1)*EHCI_PAGE_SIZE)
210184610Salfred	volatile uint32_t qtd_buffer[EHCI_QTD_NBUFFERS];
211184610Salfred	volatile uint32_t qtd_buffer_hi[EHCI_QTD_NBUFFERS];
212184610Salfred/*
213184610Salfred * Extra information needed:
214184610Salfred */
215184610Salfred	struct ehci_qtd *alt_next;
216184610Salfred	struct ehci_qtd *obj_next;
217192984Sthompsa	struct usb_page_cache *page_cache;
218184610Salfred	uint32_t qtd_self;
219184610Salfred	uint16_t len;
220184610Salfred} __aligned(EHCI_QTD_ALIGN);
221184610Salfred
222184610Salfredtypedef struct ehci_qtd ehci_qtd_t;
223184610Salfred
224184610Salfred/* Queue Head Sub Structure */
225184610Salfredstruct ehci_qh_sub {
226184610Salfred	volatile uint32_t qtd_next;
227184610Salfred	volatile uint32_t qtd_altnext;
228184610Salfred	volatile uint32_t qtd_status;
229184610Salfred	volatile uint32_t qtd_buffer[EHCI_QTD_NBUFFERS];
230184610Salfred	volatile uint32_t qtd_buffer_hi[EHCI_QTD_NBUFFERS];
231184610Salfred} __aligned(4);
232184610Salfred
233184610Salfred/* Queue Head */
234184610Salfredstruct ehci_qh {
235184610Salfred	volatile uint32_t qh_link;
236184610Salfred	volatile uint32_t qh_endp;
237184610Salfred#define	EHCI_QH_GET_ADDR(x)	(((x) >>  0) & 0x7f)	/* endpoint addr */
238184610Salfred#define	EHCI_QH_SET_ADDR(x)	(x)
239184610Salfred#define	EHCI_QH_ADDRMASK	0x0000007f
240184610Salfred#define	EHCI_QH_GET_INACT(x)	(((x) >>  7) & 0x01)	/* inactivate on next */
241184610Salfred#define	EHCI_QH_INACT		0x00000080
242184610Salfred#define	EHCI_QH_GET_ENDPT(x)	(((x) >>  8) & 0x0f)	/* endpoint no */
243184610Salfred#define	EHCI_QH_SET_ENDPT(x)	((x) <<  8)
244184610Salfred#define	EHCI_QH_GET_EPS(x)	(((x) >> 12) & 0x03)	/* endpoint speed */
245184610Salfred#define	EHCI_QH_SET_EPS(x)	((x) << 12)
246184610Salfred#define	EHCI_QH_SPEED_FULL	0x0
247184610Salfred#define	EHCI_QH_SPEED_LOW	0x1
248184610Salfred#define	EHCI_QH_SPEED_HIGH	0x2
249184610Salfred#define	EHCI_QH_GET_DTC(x)	(((x) >> 14) & 0x01)	/* data toggle control */
250184610Salfred#define	EHCI_QH_DTC		0x00004000
251184610Salfred#define	EHCI_QH_GET_HRECL(x)	(((x) >> 15) & 0x01)	/* head of reclamation */
252184610Salfred#define	EHCI_QH_HRECL		0x00008000
253184610Salfred#define	EHCI_QH_GET_MPL(x)	(((x) >> 16) & 0x7ff)	/* max packet len */
254184610Salfred#define	EHCI_QH_SET_MPL(x)	((x) << 16)
255184610Salfred#define	EHCI_QH_MPLMASK		0x07ff0000
256184610Salfred#define	EHCI_QH_GET_CTL(x)	(((x) >> 27) & 0x01)	/* control endpoint */
257184610Salfred#define	EHCI_QH_CTL		0x08000000
258184610Salfred#define	EHCI_QH_GET_NRL(x)	(((x) >> 28) & 0x0f)	/* NAK reload */
259184610Salfred#define	EHCI_QH_SET_NRL(x)	((x) << 28)
260184610Salfred	volatile uint32_t qh_endphub;
261184610Salfred#define	EHCI_QH_GET_SMASK(x)	(((x) >>  0) & 0xff)	/* intr sched mask */
262184610Salfred#define	EHCI_QH_SET_SMASK(x)	((x) <<  0)
263184610Salfred#define	EHCI_QH_GET_CMASK(x)	(((x) >>  8) & 0xff)	/* split completion mask */
264184610Salfred#define	EHCI_QH_SET_CMASK(x)	((x) <<  8)
265184610Salfred#define	EHCI_QH_GET_HUBA(x)	(((x) >> 16) & 0x7f)	/* hub address */
266184610Salfred#define	EHCI_QH_SET_HUBA(x)	((x) << 16)
267184610Salfred#define	EHCI_QH_GET_PORT(x)	(((x) >> 23) & 0x7f)	/* hub port */
268184610Salfred#define	EHCI_QH_SET_PORT(x)	((x) << 23)
269184610Salfred#define	EHCI_QH_GET_MULT(x)	(((x) >> 30) & 0x03)	/* pipe multiplier */
270184610Salfred#define	EHCI_QH_SET_MULT(x)	((x) << 30)
271184610Salfred	volatile uint32_t qh_curqtd;
272184610Salfred	struct ehci_qh_sub qh_qtd;
273184610Salfred/*
274184610Salfred * Extra information needed:
275184610Salfred */
276184610Salfred	struct ehci_qh *next;
277184610Salfred	struct ehci_qh *prev;
278184610Salfred	struct ehci_qh *obj_next;
279192984Sthompsa	struct usb_page_cache *page_cache;
280184610Salfred	uint32_t qh_self;
281184610Salfred} __aligned(EHCI_QH_ALIGN);
282184610Salfred
283184610Salfredtypedef struct ehci_qh ehci_qh_t;
284184610Salfred
285184610Salfred/* Periodic Frame Span Traversal Node */
286184610Salfredstruct ehci_fstn {
287184610Salfred	volatile uint32_t fstn_link;
288184610Salfred	volatile uint32_t fstn_back;
289184610Salfred} __aligned(EHCI_FSTN_ALIGN);
290184610Salfred
291184610Salfredtypedef struct ehci_fstn ehci_fstn_t;
292184610Salfred
293184610Salfredstruct ehci_hw_softc {
294192984Sthompsa	struct usb_page_cache pframes_pc;
295192984Sthompsa	struct usb_page_cache async_start_pc;
296192984Sthompsa	struct usb_page_cache intr_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT];
297192984Sthompsa	struct usb_page_cache isoc_hs_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT];
298192984Sthompsa	struct usb_page_cache isoc_fs_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT];
299184610Salfred
300192984Sthompsa	struct usb_page pframes_pg;
301192984Sthompsa	struct usb_page async_start_pg;
302192984Sthompsa	struct usb_page intr_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT];
303192984Sthompsa	struct usb_page isoc_hs_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT];
304192984Sthompsa	struct usb_page isoc_fs_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT];
305184610Salfred};
306184610Salfred
307184610Salfredstruct ehci_config_desc {
308192984Sthompsa	struct usb_config_descriptor confd;
309192984Sthompsa	struct usb_interface_descriptor ifcd;
310192984Sthompsa	struct usb_endpoint_descriptor endpd;
311184610Salfred} __packed;
312184610Salfred
313184610Salfredunion ehci_hub_desc {
314192984Sthompsa	struct usb_status stat;
315192984Sthompsa	struct usb_port_status ps;
316192984Sthompsa	struct usb_hub_descriptor hubd;
317184610Salfred	uint8_t	temp[128];
318184610Salfred};
319184610Salfred
320184610Salfredtypedef struct ehci_softc {
321184610Salfred	struct ehci_hw_softc sc_hw;
322192984Sthompsa	struct usb_bus sc_bus;		/* base device */
323192984Sthompsa	struct usb_callout sc_tmo_pcd;
324199058Sthompsa	struct usb_callout sc_tmo_poll;
325184610Salfred	union ehci_hub_desc sc_hub_desc;
326184610Salfred
327192984Sthompsa	struct usb_device *sc_devices[EHCI_MAX_DEVICES];
328184610Salfred	struct resource *sc_io_res;
329184610Salfred	struct resource *sc_irq_res;
330184610Salfred	struct ehci_qh *sc_async_p_last;
331184610Salfred	struct ehci_qh *sc_intr_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT];
332184610Salfred	struct ehci_sitd *sc_isoc_fs_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT];
333184610Salfred	struct ehci_itd *sc_isoc_hs_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT];
334184610Salfred	void   *sc_intr_hdl;
335184610Salfred	bus_size_t sc_io_size;
336184610Salfred	bus_space_tag_t sc_io_tag;
337184610Salfred	bus_space_handle_t sc_io_hdl;
338184610Salfred
339184610Salfred	uint32_t sc_eintrs;
340184610Salfred	uint32_t sc_cmd;		/* shadow of cmd register during
341184610Salfred					 * suspend */
342184610Salfred
343184610Salfred	uint16_t sc_intr_stat[EHCI_VIRTUAL_FRAMELIST_COUNT];
344184610Salfred	uint16_t sc_id_vendor;		/* vendor ID for root hub */
345185087Salfred	uint16_t sc_flags;		/* chip specific flags */
346186730Salfred#define	EHCI_SCFLG_SETMODE	0x0001	/* set bridge mode again after init */
347186730Salfred#define	EHCI_SCFLG_FORCESPEED	0x0002	/* force speed */
348186730Salfred#define	EHCI_SCFLG_NORESTERM	0x0004	/* don't terminate reset sequence */
349186730Salfred#define	EHCI_SCFLG_BIGEDESC	0x0008	/* big-endian byte order descriptors */
350186730Salfred#define	EHCI_SCFLG_BIGEMMIO	0x0010	/* big-endian byte order MMIO */
351186730Salfred#define	EHCI_SCFLG_TT		0x0020	/* transaction translator present */
352199058Sthompsa#define	EHCI_SCFLG_LOSTINTRBUG	0x0040	/* workaround for VIA / ATI chipsets */
353184610Salfred
354184610Salfred	uint8_t	sc_offs;		/* offset to operational registers */
355184610Salfred	uint8_t	sc_doorbell_disable;	/* set on doorbell failure */
356184610Salfred	uint8_t	sc_noport;
357184610Salfred	uint8_t	sc_addr;		/* device address */
358184610Salfred	uint8_t	sc_conf;		/* device configuration */
359184610Salfred	uint8_t	sc_isreset;
360184610Salfred	uint8_t	sc_hub_idata[8];
361184610Salfred
362184610Salfred	char	sc_vendor[16];		/* vendor string for root hub */
363184610Salfred
364184610Salfred} ehci_softc_t;
365184610Salfred
366184610Salfred#define	EREAD1(sc, a)	bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (a))
367184610Salfred#define	EREAD2(sc, a)	bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (a))
368184610Salfred#define	EREAD4(sc, a)	bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (a))
369184610Salfred#define	EWRITE1(sc, a, x)						\
370184610Salfred	    bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x))
371184610Salfred#define	EWRITE2(sc, a, x)						\
372184610Salfred	    bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x))
373184610Salfred#define	EWRITE4(sc, a, x)						\
374184610Salfred	    bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x))
375184610Salfred#define	EOREAD1(sc, a)							\
376184610Salfred	    bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a))
377184610Salfred#define	EOREAD2(sc, a)							\
378184610Salfred	    bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a))
379184610Salfred#define	EOREAD4(sc, a)							\
380184610Salfred	    bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a))
381184610Salfred#define	EOWRITE1(sc, a, x)						\
382184610Salfred	    bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x))
383184610Salfred#define	EOWRITE2(sc, a, x)						\
384184610Salfred	    bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x))
385184610Salfred#define	EOWRITE4(sc, a, x)						\
386184610Salfred	    bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x))
387184610Salfred
388189496Sthompsa#ifdef USB_EHCI_BIG_ENDIAN_DESC
389189496Sthompsa/*
390189496Sthompsa * Handle byte order conversion between host and ``host controller''.
391189496Sthompsa * Typically the latter is little-endian but some controllers require
392189496Sthompsa * big-endian in which case we may need to manually swap.
393189496Sthompsa */
394189496Sthompsastatic __inline uint32_t
395189496Sthompsahtohc32(const struct ehci_softc *sc, const uint32_t v)
396189496Sthompsa{
397189496Sthompsa	return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? htobe32(v) : htole32(v);
398189496Sthompsa}
399189496Sthompsa
400189496Sthompsastatic __inline uint16_t
401189496Sthompsahtohc16(const struct ehci_softc *sc, const uint16_t v)
402189496Sthompsa{
403189496Sthompsa	return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? htobe16(v) : htole16(v);
404189496Sthompsa}
405189496Sthompsa
406189496Sthompsastatic __inline uint32_t
407189496Sthompsahc32toh(const struct ehci_softc *sc, const uint32_t v)
408189496Sthompsa{
409189496Sthompsa	return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? be32toh(v) : le32toh(v);
410189496Sthompsa}
411189496Sthompsa
412189496Sthompsastatic __inline uint16_t
413189496Sthompsahc16toh(const struct ehci_softc *sc, const uint16_t v)
414189496Sthompsa{
415189496Sthompsa	return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? be16toh(v) : le16toh(v);
416189496Sthompsa}
417189496Sthompsa#else
418189496Sthompsa/*
419189496Sthompsa * Normal little-endian only conversion routines.
420189496Sthompsa */
421189496Sthompsastatic __inline uint32_t
422189496Sthompsahtohc32(const struct ehci_softc *sc, const uint32_t v)
423189496Sthompsa{
424189496Sthompsa	return htole32(v);
425189496Sthompsa}
426189496Sthompsa
427189496Sthompsastatic __inline uint16_t
428189496Sthompsahtohc16(const struct ehci_softc *sc, const uint16_t v)
429189496Sthompsa{
430189496Sthompsa	return htole16(v);
431189496Sthompsa}
432189496Sthompsa
433189496Sthompsastatic __inline uint32_t
434189496Sthompsahc32toh(const struct ehci_softc *sc, const uint32_t v)
435189496Sthompsa{
436189496Sthompsa	return le32toh(v);
437189496Sthompsa}
438189496Sthompsa
439189496Sthompsastatic __inline uint16_t
440189496Sthompsahc16toh(const struct ehci_softc *sc, const uint16_t v)
441189496Sthompsa{
442189496Sthompsa	return le16toh(v);
443189496Sthompsa}
444189496Sthompsa#endif
445189496Sthompsa
446193045Sthompsausb_bus_mem_cb_t ehci_iterate_hw_softc;
447184610Salfred
448193045Sthompsausb_error_t ehci_reset(ehci_softc_t *sc);
449193045Sthompsausb_error_t ehci_init(ehci_softc_t *sc);
450184610Salfredvoid	ehci_detach(struct ehci_softc *sc);
451184610Salfredvoid	ehci_suspend(struct ehci_softc *sc);
452184610Salfredvoid	ehci_resume(struct ehci_softc *sc);
453184610Salfredvoid	ehci_shutdown(ehci_softc_t *sc);
454184610Salfredvoid	ehci_interrupt(ehci_softc_t *sc);
455184610Salfred
456184610Salfred#endif					/* _EHCI_H_ */
457