xref: /freebsd/sys/dev/usb/controller/ohci.h (revision ab42e8b2df8c3fab030422628f7d8d4c41c29a2f)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
302ac6454SAndrew Thompson  * Copyright (c) 1998 The NetBSD Foundation, Inc.
402ac6454SAndrew Thompson  * All rights reserved.
502ac6454SAndrew Thompson  *
602ac6454SAndrew Thompson  * This code is derived from software contributed to The NetBSD Foundation
702ac6454SAndrew Thompson  * by Lennart Augustsson (lennart@augustsson.net) at
802ac6454SAndrew Thompson  * Carlstedt Research & Technology.
902ac6454SAndrew Thompson  *
1002ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
1102ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1202ac6454SAndrew Thompson  * are met:
1302ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1402ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1502ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1602ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1702ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1802ac6454SAndrew Thompson  * 3. All advertising materials mentioning features or use of this software
1902ac6454SAndrew Thompson  *    must display the following acknowledgement:
2002ac6454SAndrew Thompson  *        This product includes software developed by the NetBSD
2102ac6454SAndrew Thompson  *        Foundation, Inc. and its contributors.
2202ac6454SAndrew Thompson  * 4. Neither the name of The NetBSD Foundation nor the names of its
2302ac6454SAndrew Thompson  *    contributors may be used to endorse or promote products derived
2402ac6454SAndrew Thompson  *    from this software without specific prior written permission.
2502ac6454SAndrew Thompson  *
2602ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2702ac6454SAndrew Thompson  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2802ac6454SAndrew Thompson  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2902ac6454SAndrew Thompson  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3002ac6454SAndrew Thompson  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3102ac6454SAndrew Thompson  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3202ac6454SAndrew Thompson  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3302ac6454SAndrew Thompson  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3402ac6454SAndrew Thompson  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3502ac6454SAndrew Thompson  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3602ac6454SAndrew Thompson  * POSSIBILITY OF SUCH DAMAGE.
3702ac6454SAndrew Thompson  */
3802ac6454SAndrew Thompson 
3902ac6454SAndrew Thompson #ifndef _OHCI_H_
4002ac6454SAndrew Thompson #define	_OHCI_H_
4102ac6454SAndrew Thompson 
42ab42e8b2SAndrew Thompson #define	OHCI_MAX_DEVICES MIN(USB_MAX_DEVICES, 128)
4302ac6454SAndrew Thompson 
4402ac6454SAndrew Thompson /* PCI config registers */
4502ac6454SAndrew Thompson #define	PCI_CBMEM		0x10	/* configuration base memory */
4602ac6454SAndrew Thompson #define	PCI_INTERFACE_OHCI	0x10
4702ac6454SAndrew Thompson 
4802ac6454SAndrew Thompson /* OHCI registers */
4902ac6454SAndrew Thompson #define	OHCI_REVISION		0x00	/* OHCI revision */
5002ac6454SAndrew Thompson #define	OHCI_REV_LO(rev)	((rev) & 0xf)
5102ac6454SAndrew Thompson #define	OHCI_REV_HI(rev)	(((rev)>>4) & 0xf)
5202ac6454SAndrew Thompson #define	OHCI_REV_LEGACY(rev)	((rev) & 0x100)
5302ac6454SAndrew Thompson #define	OHCI_CONTROL		0x04
5402ac6454SAndrew Thompson #define	OHCI_CBSR_MASK		0x00000003	/* Control/Bulk Service Ratio */
5502ac6454SAndrew Thompson #define	OHCI_RATIO_1_1		0x00000000
5602ac6454SAndrew Thompson #define	OHCI_RATIO_1_2		0x00000001
5702ac6454SAndrew Thompson #define	OHCI_RATIO_1_3		0x00000002
5802ac6454SAndrew Thompson #define	OHCI_RATIO_1_4		0x00000003
5902ac6454SAndrew Thompson #define	OHCI_PLE		0x00000004	/* Periodic List Enable */
6002ac6454SAndrew Thompson #define	OHCI_IE			0x00000008	/* Isochronous Enable */
6102ac6454SAndrew Thompson #define	OHCI_CLE		0x00000010	/* Control List Enable */
6202ac6454SAndrew Thompson #define	OHCI_BLE		0x00000020	/* Bulk List Enable */
6302ac6454SAndrew Thompson #define	OHCI_HCFS_MASK		0x000000c0	/* HostControllerFunctionalStat
6402ac6454SAndrew Thompson 						 * e */
6502ac6454SAndrew Thompson #define	OHCI_HCFS_RESET		0x00000000
6602ac6454SAndrew Thompson #define	OHCI_HCFS_RESUME	0x00000040
6702ac6454SAndrew Thompson #define	OHCI_HCFS_OPERATIONAL	0x00000080
6802ac6454SAndrew Thompson #define	OHCI_HCFS_SUSPEND	0x000000c0
6902ac6454SAndrew Thompson #define	OHCI_IR			0x00000100	/* Interrupt Routing */
7002ac6454SAndrew Thompson #define	OHCI_RWC		0x00000200	/* Remote Wakeup Connected */
7102ac6454SAndrew Thompson #define	OHCI_RWE		0x00000400	/* Remote Wakeup Enabled */
7202ac6454SAndrew Thompson #define	OHCI_COMMAND_STATUS	0x08
7302ac6454SAndrew Thompson #define	OHCI_HCR		0x00000001	/* Host Controller Reset */
7402ac6454SAndrew Thompson #define	OHCI_CLF		0x00000002	/* Control List Filled */
7502ac6454SAndrew Thompson #define	OHCI_BLF		0x00000004	/* Bulk List Filled */
7602ac6454SAndrew Thompson #define	OHCI_OCR		0x00000008	/* Ownership Change Request */
7702ac6454SAndrew Thompson #define	OHCI_SOC_MASK		0x00030000	/* Scheduling Overrun Count */
7802ac6454SAndrew Thompson #define	OHCI_INTERRUPT_STATUS	0x0c
7902ac6454SAndrew Thompson #define	OHCI_SO			0x00000001	/* Scheduling Overrun */
8002ac6454SAndrew Thompson #define	OHCI_WDH		0x00000002	/* Writeback Done Head */
8102ac6454SAndrew Thompson #define	OHCI_SF			0x00000004	/* Start of Frame */
8202ac6454SAndrew Thompson #define	OHCI_RD			0x00000008	/* Resume Detected */
8302ac6454SAndrew Thompson #define	OHCI_UE			0x00000010	/* Unrecoverable Error */
8402ac6454SAndrew Thompson #define	OHCI_FNO		0x00000020	/* Frame Number Overflow */
8502ac6454SAndrew Thompson #define	OHCI_RHSC		0x00000040	/* Root Hub Status Change */
8602ac6454SAndrew Thompson #define	OHCI_OC			0x40000000	/* Ownership Change */
8702ac6454SAndrew Thompson #define	OHCI_MIE		0x80000000	/* Master Interrupt Enable */
8802ac6454SAndrew Thompson #define	OHCI_INTERRUPT_ENABLE	0x10
8902ac6454SAndrew Thompson #define	OHCI_INTERRUPT_DISABLE	0x14
9002ac6454SAndrew Thompson #define	OHCI_HCCA		0x18
9102ac6454SAndrew Thompson #define	OHCI_PERIOD_CURRENT_ED	0x1c
9202ac6454SAndrew Thompson #define	OHCI_CONTROL_HEAD_ED	0x20
9302ac6454SAndrew Thompson #define	OHCI_CONTROL_CURRENT_ED	0x24
9402ac6454SAndrew Thompson #define	OHCI_BULK_HEAD_ED	0x28
9502ac6454SAndrew Thompson #define	OHCI_BULK_CURRENT_ED	0x2c
9602ac6454SAndrew Thompson #define	OHCI_DONE_HEAD		0x30
9702ac6454SAndrew Thompson #define	OHCI_FM_INTERVAL	0x34
9802ac6454SAndrew Thompson #define	OHCI_GET_IVAL(s)	((s) & 0x3fff)
9902ac6454SAndrew Thompson #define	OHCI_GET_FSMPS(s)	(((s) >> 16) & 0x7fff)
10002ac6454SAndrew Thompson #define	OHCI_FIT		0x80000000
10102ac6454SAndrew Thompson #define	OHCI_FM_REMAINING	0x38
10202ac6454SAndrew Thompson #define	OHCI_FM_NUMBER		0x3c
10302ac6454SAndrew Thompson #define	OHCI_PERIODIC_START	0x40
10402ac6454SAndrew Thompson #define	OHCI_LS_THRESHOLD	0x44
10502ac6454SAndrew Thompson #define	OHCI_RH_DESCRIPTOR_A	0x48
10602ac6454SAndrew Thompson #define	OHCI_GET_NDP(s)		((s) & 0xff)
10702ac6454SAndrew Thompson #define	OHCI_PSM		0x0100	/* Power Switching Mode */
10802ac6454SAndrew Thompson #define	OHCI_NPS		0x0200	/* No Power Switching */
10902ac6454SAndrew Thompson #define	OHCI_DT			0x0400	/* Device Type */
11002ac6454SAndrew Thompson #define	OHCI_OCPM		0x0800	/* Overcurrent Protection Mode */
11102ac6454SAndrew Thompson #define	OHCI_NOCP		0x1000	/* No Overcurrent Protection */
11202ac6454SAndrew Thompson #define	OHCI_GET_POTPGT(s)	((s) >> 24)
11302ac6454SAndrew Thompson #define	OHCI_RH_DESCRIPTOR_B	0x4c
11402ac6454SAndrew Thompson #define	OHCI_RH_STATUS		0x50
11502ac6454SAndrew Thompson #define	OHCI_LPS		0x00000001	/* Local Power Status */
11602ac6454SAndrew Thompson #define	OHCI_OCI		0x00000002	/* OverCurrent Indicator */
11702ac6454SAndrew Thompson #define	OHCI_DRWE		0x00008000	/* Device Remote Wakeup Enable */
11802ac6454SAndrew Thompson #define	OHCI_LPSC		0x00010000	/* Local Power Status Change */
11902ac6454SAndrew Thompson #define	OHCI_CCIC		0x00020000	/* OverCurrent Indicator
12002ac6454SAndrew Thompson 						 * Change */
12102ac6454SAndrew Thompson #define	OHCI_CRWE		0x80000000	/* Clear Remote Wakeup Enable */
12202ac6454SAndrew Thompson #define	OHCI_RH_PORT_STATUS(n)	(0x50 + ((n)*4))	/* 1 based indexing */
12302ac6454SAndrew Thompson 
12402ac6454SAndrew Thompson #define	OHCI_LES		(OHCI_PLE | OHCI_IE | OHCI_CLE | OHCI_BLE)
12502ac6454SAndrew Thompson #define	OHCI_ALL_INTRS		(OHCI_SO | OHCI_WDH | OHCI_SF |		\
12602ac6454SAndrew Thompson 				OHCI_RD | OHCI_UE | OHCI_FNO |		\
12702ac6454SAndrew Thompson 				OHCI_RHSC | OHCI_OC)
12802ac6454SAndrew Thompson #define	OHCI_NORMAL_INTRS	(OHCI_WDH | OHCI_RD | OHCI_UE | OHCI_RHSC)
12902ac6454SAndrew Thompson 
13002ac6454SAndrew Thompson #define	OHCI_FSMPS(i)		(((i-210)*6/7) << 16)
13102ac6454SAndrew Thompson #define	OHCI_PERIODIC(i)	((i)*9/10)
13202ac6454SAndrew Thompson 
13302ac6454SAndrew Thompson #define	OHCI_NO_INTRS		32
13402ac6454SAndrew Thompson #define	OHCI_HCCA_SIZE		256
13502ac6454SAndrew Thompson 
13602ac6454SAndrew Thompson /* Structures alignment (bytes) */
13702ac6454SAndrew Thompson #define	OHCI_HCCA_ALIGN		256
13802ac6454SAndrew Thompson #define	OHCI_ED_ALIGN		16
13902ac6454SAndrew Thompson #define	OHCI_TD_ALIGN		16
14002ac6454SAndrew Thompson #define	OHCI_ITD_ALIGN		32
14102ac6454SAndrew Thompson 
14202ac6454SAndrew Thompson #define	OHCI_PAGE_SIZE		0x1000
14302ac6454SAndrew Thompson #define	OHCI_PAGE(x)		((x) &~ 0xfff)
14402ac6454SAndrew Thompson #define	OHCI_PAGE_OFFSET(x)	((x) & 0xfff)
14502ac6454SAndrew Thompson #define	OHCI_PAGE_MASK(x)	((x) & 0xfff)
14602ac6454SAndrew Thompson 
14702ac6454SAndrew Thompson #if	((USB_PAGE_SIZE < OHCI_ED_ALIGN) || (OHCI_ED_ALIGN == 0) ||	\
14802ac6454SAndrew Thompson 	(USB_PAGE_SIZE < OHCI_TD_ALIGN) || (OHCI_TD_ALIGN == 0) ||	\
14902ac6454SAndrew Thompson 	(USB_PAGE_SIZE < OHCI_ITD_ALIGN) || (OHCI_ITD_ALIGN == 0) ||	\
15002ac6454SAndrew Thompson 	(USB_PAGE_SIZE < OHCI_PAGE_SIZE) || (OHCI_PAGE_SIZE == 0))
15102ac6454SAndrew Thompson #error	"Invalid USB page size!"
15202ac6454SAndrew Thompson #endif
15302ac6454SAndrew Thompson 
15402ac6454SAndrew Thompson #define	OHCI_VIRTUAL_FRAMELIST_COUNT 128/* dummy */
15502ac6454SAndrew Thompson 
15602ac6454SAndrew Thompson #if (OHCI_VIRTUAL_FRAMELIST_COUNT < USB_MAX_FS_ISOC_FRAMES_PER_XFER)
15702ac6454SAndrew Thompson #error "maximum number of full-speed isochronous frames is higher than supported!"
15802ac6454SAndrew Thompson #endif
15902ac6454SAndrew Thompson 
16002ac6454SAndrew Thompson struct ohci_hcca {
16102ac6454SAndrew Thompson 	volatile uint32_t hcca_interrupt_table[OHCI_NO_INTRS];
16202ac6454SAndrew Thompson 	volatile uint32_t hcca_frame_number;
16302ac6454SAndrew Thompson 	volatile uint32_t hcca_done_head;
16402ac6454SAndrew Thompson #define	OHCI_DONE_INTRS		1
16502ac6454SAndrew Thompson } __aligned(OHCI_HCCA_ALIGN);
16602ac6454SAndrew Thompson 
16702ac6454SAndrew Thompson typedef struct ohci_hcca ohci_hcca_t;
16802ac6454SAndrew Thompson 
16902ac6454SAndrew Thompson struct ohci_ed {
17002ac6454SAndrew Thompson 	volatile uint32_t ed_flags;
17102ac6454SAndrew Thompson #define	OHCI_ED_GET_FA(s)	((s) & 0x7f)
17202ac6454SAndrew Thompson #define	OHCI_ED_ADDRMASK	0x0000007f
17302ac6454SAndrew Thompson #define	OHCI_ED_SET_FA(s)	(s)
17402ac6454SAndrew Thompson #define	OHCI_ED_GET_EN(s)	(((s) >> 7) & 0xf)
17502ac6454SAndrew Thompson #define	OHCI_ED_SET_EN(s)	((s) << 7)
17602ac6454SAndrew Thompson #define	OHCI_ED_DIR_MASK	0x00001800
17702ac6454SAndrew Thompson #define	OHCI_ED_DIR_TD		0x00000000
17802ac6454SAndrew Thompson #define	OHCI_ED_DIR_OUT		0x00000800
17902ac6454SAndrew Thompson #define	OHCI_ED_DIR_IN		0x00001000
18002ac6454SAndrew Thompson #define	OHCI_ED_SPEED		0x00002000
18102ac6454SAndrew Thompson #define	OHCI_ED_SKIP		0x00004000
18202ac6454SAndrew Thompson #define	OHCI_ED_FORMAT_GEN	0x00000000
18302ac6454SAndrew Thompson #define	OHCI_ED_FORMAT_ISO	0x00008000
18402ac6454SAndrew Thompson #define	OHCI_ED_GET_MAXP(s)	(((s) >> 16) & 0x07ff)
18502ac6454SAndrew Thompson #define	OHCI_ED_SET_MAXP(s)	((s) << 16)
18602ac6454SAndrew Thompson #define	OHCI_ED_MAXPMASK	(0x7ff << 16)
18702ac6454SAndrew Thompson 	volatile uint32_t ed_tailp;
18802ac6454SAndrew Thompson 	volatile uint32_t ed_headp;
18902ac6454SAndrew Thompson #define	OHCI_HALTED		0x00000001
19002ac6454SAndrew Thompson #define	OHCI_TOGGLECARRY	0x00000002
19102ac6454SAndrew Thompson #define	OHCI_HEADMASK		0xfffffffc
19202ac6454SAndrew Thompson 	volatile uint32_t ed_next;
19302ac6454SAndrew Thompson /*
19402ac6454SAndrew Thompson  * Extra information needed:
19502ac6454SAndrew Thompson  */
19602ac6454SAndrew Thompson 	struct ohci_ed *next;
19702ac6454SAndrew Thompson 	struct ohci_ed *prev;
19802ac6454SAndrew Thompson 	struct ohci_ed *obj_next;
19902ac6454SAndrew Thompson 	struct usb2_page_cache *page_cache;
20002ac6454SAndrew Thompson 	uint32_t ed_self;
20102ac6454SAndrew Thompson } __aligned(OHCI_ED_ALIGN);
20202ac6454SAndrew Thompson 
20302ac6454SAndrew Thompson typedef struct ohci_ed ohci_ed_t;
20402ac6454SAndrew Thompson 
20502ac6454SAndrew Thompson struct ohci_td {
20602ac6454SAndrew Thompson 	volatile uint32_t td_flags;
20702ac6454SAndrew Thompson #define	OHCI_TD_R		0x00040000	/* Buffer Rounding  */
20802ac6454SAndrew Thompson #define	OHCI_TD_DP_MASK		0x00180000	/* Direction / PID */
20902ac6454SAndrew Thompson #define	OHCI_TD_SETUP		0x00000000
21002ac6454SAndrew Thompson #define	OHCI_TD_OUT		0x00080000
21102ac6454SAndrew Thompson #define	OHCI_TD_IN		0x00100000
21202ac6454SAndrew Thompson #define	OHCI_TD_GET_DI(x)	(((x) >> 21) & 7)	/* Delay Interrupt */
21302ac6454SAndrew Thompson #define	OHCI_TD_SET_DI(x)	((x) << 21)
21402ac6454SAndrew Thompson #define	OHCI_TD_NOINTR		0x00e00000
21502ac6454SAndrew Thompson #define	OHCI_TD_INTR_MASK	0x00e00000
21602ac6454SAndrew Thompson #define	OHCI_TD_TOGGLE_CARRY	0x00000000
21702ac6454SAndrew Thompson #define	OHCI_TD_TOGGLE_0	0x02000000
21802ac6454SAndrew Thompson #define	OHCI_TD_TOGGLE_1	0x03000000
21902ac6454SAndrew Thompson #define	OHCI_TD_TOGGLE_MASK	0x03000000
22002ac6454SAndrew Thompson #define	OHCI_TD_GET_EC(x)	(((x) >> 26) & 3)	/* Error Count */
22102ac6454SAndrew Thompson #define	OHCI_TD_GET_CC(x)	((x) >> 28)	/* Condition Code */
22202ac6454SAndrew Thompson #define	OHCI_TD_SET_CC(x)	((x) << 28)
22302ac6454SAndrew Thompson #define	OHCI_TD_NOCC		0xf0000000
22402ac6454SAndrew Thompson 	volatile uint32_t td_cbp;	/* Current Buffer Pointer */
22502ac6454SAndrew Thompson 	volatile uint32_t td_next;	/* Next TD */
22602ac6454SAndrew Thompson #define	OHCI_TD_NEXT_END	0
22702ac6454SAndrew Thompson 	volatile uint32_t td_be;	/* Buffer End */
22802ac6454SAndrew Thompson /*
22902ac6454SAndrew Thompson  * Extra information needed:
23002ac6454SAndrew Thompson  */
23102ac6454SAndrew Thompson 	struct ohci_td *obj_next;
23202ac6454SAndrew Thompson 	struct ohci_td *alt_next;
23302ac6454SAndrew Thompson 	struct usb2_page_cache *page_cache;
23402ac6454SAndrew Thompson 	uint32_t td_self;
23502ac6454SAndrew Thompson 	uint16_t len;
23602ac6454SAndrew Thompson } __aligned(OHCI_TD_ALIGN);
23702ac6454SAndrew Thompson 
23802ac6454SAndrew Thompson typedef struct ohci_td ohci_td_t;
23902ac6454SAndrew Thompson 
24002ac6454SAndrew Thompson struct ohci_itd {
24102ac6454SAndrew Thompson 	volatile uint32_t itd_flags;
24202ac6454SAndrew Thompson #define	OHCI_ITD_GET_SF(x)	((x) & 0x0000ffff)
24302ac6454SAndrew Thompson #define	OHCI_ITD_SET_SF(x)	((x) & 0xffff)
24402ac6454SAndrew Thompson #define	OHCI_ITD_GET_DI(x)	(((x) >> 21) & 7)	/* Delay Interrupt */
24502ac6454SAndrew Thompson #define	OHCI_ITD_SET_DI(x)	((x) << 21)
24602ac6454SAndrew Thompson #define	OHCI_ITD_NOINTR		0x00e00000
24702ac6454SAndrew Thompson #define	OHCI_ITD_GET_FC(x)	((((x) >> 24) & 7)+1)	/* Frame Count */
24802ac6454SAndrew Thompson #define	OHCI_ITD_SET_FC(x)	(((x)-1) << 24)
24902ac6454SAndrew Thompson #define	OHCI_ITD_GET_CC(x)	((x) >> 28)	/* Condition Code */
25002ac6454SAndrew Thompson #define	OHCI_ITD_NOCC		0xf0000000
25102ac6454SAndrew Thompson #define	OHCI_ITD_NOFFSET	8
25202ac6454SAndrew Thompson 	volatile uint32_t itd_bp0;	/* Buffer Page 0 */
25302ac6454SAndrew Thompson 	volatile uint32_t itd_next;	/* Next ITD */
25402ac6454SAndrew Thompson 	volatile uint32_t itd_be;	/* Buffer End */
25502ac6454SAndrew Thompson 	volatile uint16_t itd_offset[OHCI_ITD_NOFFSET];	/* Buffer offsets and
25602ac6454SAndrew Thompson 							 * Status */
25702ac6454SAndrew Thompson #define	OHCI_ITD_PAGE_SELECT	0x00001000
25802ac6454SAndrew Thompson #define	OHCI_ITD_MK_OFFS(len)	(0xe000 | ((len) & 0x1fff))
25902ac6454SAndrew Thompson #define	OHCI_ITD_PSW_LENGTH(x)	((x) & 0xfff)	/* Transfer length */
26002ac6454SAndrew Thompson #define	OHCI_ITD_PSW_GET_CC(x)	((x) >> 12)	/* Condition Code */
26102ac6454SAndrew Thompson /*
26202ac6454SAndrew Thompson  * Extra information needed:
26302ac6454SAndrew Thompson  */
26402ac6454SAndrew Thompson 	struct ohci_itd *obj_next;
26502ac6454SAndrew Thompson 	struct usb2_page_cache *page_cache;
26602ac6454SAndrew Thompson 	uint32_t itd_self;
26702ac6454SAndrew Thompson 	uint8_t	frames;
26802ac6454SAndrew Thompson } __aligned(OHCI_ITD_ALIGN);
26902ac6454SAndrew Thompson 
27002ac6454SAndrew Thompson typedef struct ohci_itd ohci_itd_t;
27102ac6454SAndrew Thompson 
27202ac6454SAndrew Thompson #define	OHCI_CC_NO_ERROR		0
27302ac6454SAndrew Thompson #define	OHCI_CC_CRC			1
27402ac6454SAndrew Thompson #define	OHCI_CC_BIT_STUFFING		2
27502ac6454SAndrew Thompson #define	OHCI_CC_DATA_TOGGLE_MISMATCH	3
27602ac6454SAndrew Thompson #define	OHCI_CC_STALL			4
27702ac6454SAndrew Thompson #define	OHCI_CC_DEVICE_NOT_RESPONDING	5
27802ac6454SAndrew Thompson #define	OHCI_CC_PID_CHECK_FAILURE	6
27902ac6454SAndrew Thompson #define	OHCI_CC_UNEXPECTED_PID		7
28002ac6454SAndrew Thompson #define	OHCI_CC_DATA_OVERRUN		8
28102ac6454SAndrew Thompson #define	OHCI_CC_DATA_UNDERRUN		9
28202ac6454SAndrew Thompson #define	OHCI_CC_BUFFER_OVERRUN		12
28302ac6454SAndrew Thompson #define	OHCI_CC_BUFFER_UNDERRUN		13
28402ac6454SAndrew Thompson #define	OHCI_CC_NOT_ACCESSED		15
28502ac6454SAndrew Thompson 
28602ac6454SAndrew Thompson /* Some delay needed when changing certain registers. */
28702ac6454SAndrew Thompson #define	OHCI_ENABLE_POWER_DELAY		5
28802ac6454SAndrew Thompson #define	OHCI_READ_DESC_DELAY		5
28902ac6454SAndrew Thompson 
29002ac6454SAndrew Thompson #define	OHCI_NO_EDS			(2*OHCI_NO_INTRS)
29102ac6454SAndrew Thompson 
29202ac6454SAndrew Thompson struct ohci_hw_softc {
29302ac6454SAndrew Thompson 	struct usb2_page_cache hcca_pc;
29402ac6454SAndrew Thompson 	struct usb2_page_cache ctrl_start_pc;
29502ac6454SAndrew Thompson 	struct usb2_page_cache bulk_start_pc;
29602ac6454SAndrew Thompson 	struct usb2_page_cache isoc_start_pc;
29702ac6454SAndrew Thompson 	struct usb2_page_cache intr_start_pc[OHCI_NO_EDS];
29802ac6454SAndrew Thompson 
29902ac6454SAndrew Thompson 	struct usb2_page hcca_pg;
30002ac6454SAndrew Thompson 	struct usb2_page ctrl_start_pg;
30102ac6454SAndrew Thompson 	struct usb2_page bulk_start_pg;
30202ac6454SAndrew Thompson 	struct usb2_page isoc_start_pg;
30302ac6454SAndrew Thompson 	struct usb2_page intr_start_pg[OHCI_NO_EDS];
30402ac6454SAndrew Thompson };
30502ac6454SAndrew Thompson 
30602ac6454SAndrew Thompson struct ohci_config_desc {
30702ac6454SAndrew Thompson 	struct usb2_config_descriptor confd;
30802ac6454SAndrew Thompson 	struct usb2_interface_descriptor ifcd;
30902ac6454SAndrew Thompson 	struct usb2_endpoint_descriptor endpd;
31002ac6454SAndrew Thompson } __packed;
31102ac6454SAndrew Thompson 
31202ac6454SAndrew Thompson union ohci_hub_desc {
31302ac6454SAndrew Thompson 	struct usb2_status stat;
31402ac6454SAndrew Thompson 	struct usb2_port_status ps;
31502ac6454SAndrew Thompson 	struct usb2_device_descriptor devd;
31602ac6454SAndrew Thompson 	struct usb2_hub_descriptor hubd;
31702ac6454SAndrew Thompson 	uint8_t	temp[128];
31802ac6454SAndrew Thompson };
31902ac6454SAndrew Thompson 
32002ac6454SAndrew Thompson typedef struct ohci_softc {
32102ac6454SAndrew Thompson 	struct ohci_hw_softc sc_hw;
32202ac6454SAndrew Thompson 	struct usb2_bus sc_bus;		/* base device */
32302ac6454SAndrew Thompson 	struct usb2_callout sc_tmo_rhsc;
32402ac6454SAndrew Thompson 	union ohci_hub_desc sc_hub_desc;
32502ac6454SAndrew Thompson 	struct usb2_sw_transfer sc_root_ctrl;
32602ac6454SAndrew Thompson 	struct usb2_sw_transfer sc_root_intr;
32702ac6454SAndrew Thompson 
32802ac6454SAndrew Thompson 	struct usb2_device *sc_devices[OHCI_MAX_DEVICES];
32902ac6454SAndrew Thompson 	struct resource *sc_io_res;
33002ac6454SAndrew Thompson 	struct resource *sc_irq_res;
33102ac6454SAndrew Thompson 	struct ohci_hcca *sc_hcca_p;
33202ac6454SAndrew Thompson 	struct ohci_ed *sc_ctrl_p_last;
33302ac6454SAndrew Thompson 	struct ohci_ed *sc_bulk_p_last;
33402ac6454SAndrew Thompson 	struct ohci_ed *sc_isoc_p_last;
33502ac6454SAndrew Thompson 	struct ohci_ed *sc_intr_p_last[OHCI_NO_EDS];
33602ac6454SAndrew Thompson 	void   *sc_intr_hdl;
33702ac6454SAndrew Thompson 	device_t sc_dev;
33802ac6454SAndrew Thompson 	bus_size_t sc_io_size;
33902ac6454SAndrew Thompson 	bus_space_tag_t sc_io_tag;
34002ac6454SAndrew Thompson 	bus_space_handle_t sc_io_hdl;
34102ac6454SAndrew Thompson 
34202ac6454SAndrew Thompson 	uint32_t sc_eintrs;		/* enabled interrupts */
34302ac6454SAndrew Thompson 	uint32_t sc_control;		/* Preserved during suspend/standby */
34402ac6454SAndrew Thompson 	uint32_t sc_intre;
34502ac6454SAndrew Thompson 
34602ac6454SAndrew Thompson 	uint16_t sc_intr_stat[OHCI_NO_EDS];
34702ac6454SAndrew Thompson 	uint16_t sc_id_vendor;
34802ac6454SAndrew Thompson 
34902ac6454SAndrew Thompson 	uint8_t	sc_noport;
35002ac6454SAndrew Thompson 	uint8_t	sc_addr;		/* device address */
35102ac6454SAndrew Thompson 	uint8_t	sc_conf;		/* device configuration */
35202ac6454SAndrew Thompson 	uint8_t	sc_hub_idata[32];
35302ac6454SAndrew Thompson 
35402ac6454SAndrew Thompson 	char	sc_vendor[16];
35502ac6454SAndrew Thompson 
35602ac6454SAndrew Thompson } ohci_softc_t;
35702ac6454SAndrew Thompson 
35802ac6454SAndrew Thompson usb2_bus_mem_cb_t ohci_iterate_hw_softc;
35902ac6454SAndrew Thompson 
36002ac6454SAndrew Thompson usb2_error_t ohci_init(ohci_softc_t *sc);
36102ac6454SAndrew Thompson void	ohci_detach(struct ohci_softc *sc);
36202ac6454SAndrew Thompson void	ohci_suspend(ohci_softc_t *sc);
36302ac6454SAndrew Thompson void	ohci_resume(ohci_softc_t *sc);
36402ac6454SAndrew Thompson void	ohci_interrupt(ohci_softc_t *sc);
36502ac6454SAndrew Thompson 
36602ac6454SAndrew Thompson #endif					/* _OHCI_H_ */
367