1f9f848faSopenharmony_ci/*-
2f9f848faSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause
3f9f848faSopenharmony_ci *
4f9f848faSopenharmony_ci * Copyright (c) 2001 The NetBSD Foundation, Inc.
5f9f848faSopenharmony_ci * All rights reserved.
6f9f848faSopenharmony_ci *
7f9f848faSopenharmony_ci * This code is derived from software contributed to The NetBSD Foundation
8f9f848faSopenharmony_ci * by Lennart Augustsson (lennart@augustsson.net).
9f9f848faSopenharmony_ci *
10f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without
11f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions
12f9f848faSopenharmony_ci * are met:
13f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright
14f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer.
15f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
16f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
17f9f848faSopenharmony_ci *    documentation and/or other materials provided with the distribution.
18f9f848faSopenharmony_ci *
19f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20f9f848faSopenharmony_ci * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21f9f848faSopenharmony_ci * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22f9f848faSopenharmony_ci * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23f9f848faSopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24f9f848faSopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25f9f848faSopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26f9f848faSopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27f9f848faSopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28f9f848faSopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29f9f848faSopenharmony_ci * POSSIBILITY OF SUCH DAMAGE.
30f9f848faSopenharmony_ci */
31f9f848faSopenharmony_ci
32f9f848faSopenharmony_ci#ifndef _EHCIREG_H_
33f9f848faSopenharmony_ci#define	_EHCIREG_H_
34f9f848faSopenharmony_ci
35f9f848faSopenharmony_ci/* PCI config registers  */
36f9f848faSopenharmony_ci#define	PCI_CBMEM		0x10	/* configuration base MEM */
37f9f848faSopenharmony_ci#define	PCI_INTERFACE_EHCI	0x20
38f9f848faSopenharmony_ci#define	PCI_USBREV		0x60	/* RO USB protocol revision */
39f9f848faSopenharmony_ci#define	PCI_USB_REV_MASK	0xff
40f9f848faSopenharmony_ci#define	PCI_USB_REV_PRE_1_0	0x00
41f9f848faSopenharmony_ci#define	PCI_USB_REV_1_0		0x10
42f9f848faSopenharmony_ci#define	PCI_USB_REV_1_1		0x11
43f9f848faSopenharmony_ci#define	PCI_USB_REV_2_0		0x20
44f9f848faSopenharmony_ci#define	PCI_EHCI_FLADJ		0x61	/* RW Frame len adj, SOF=59488+6*fladj */
45f9f848faSopenharmony_ci#define	PCI_EHCI_PORTWAKECAP	0x62	/* RW Port wake caps (opt)  */
46f9f848faSopenharmony_ci
47f9f848faSopenharmony_ci/* EHCI Extended Capabilities */
48f9f848faSopenharmony_ci#define	EHCI_EC_LEGSUP		0x01
49f9f848faSopenharmony_ci#define	EHCI_EECP_NEXT(x)	(((x) >> 8) & 0xff)
50f9f848faSopenharmony_ci#define	EHCI_EECP_ID(x)		((x) & 0xff)
51f9f848faSopenharmony_ci
52f9f848faSopenharmony_ci/* Legacy support extended capability */
53f9f848faSopenharmony_ci#define	EHCI_LEGSUP_BIOS_SEM		0x02
54f9f848faSopenharmony_ci#define	EHCI_LEGSUP_OS_SEM		0x03
55f9f848faSopenharmony_ci#define	EHCI_LEGSUP_USBLEGCTLSTS	0x04
56f9f848faSopenharmony_ci
57f9f848faSopenharmony_ci/* EHCI capability registers */
58f9f848faSopenharmony_ci#define	EHCI_CAPLEN_HCIVERSION	0x00	/* RO Capability register length
59f9f848faSopenharmony_ci					 * (least-significant byte) and
60f9f848faSopenharmony_ci					 * interface version number (two
61f9f848faSopenharmony_ci					 * most significant)
62f9f848faSopenharmony_ci					 */
63f9f848faSopenharmony_ci#define EHCI_CAPLENGTH(x)	((x) & 0xff)
64f9f848faSopenharmony_ci#define EHCI_HCIVERSION(x)	(((x) >> 16) & 0xffff)
65f9f848faSopenharmony_ci#define	EHCI_HCSPARAMS		0x04	/* RO Structural parameters */
66f9f848faSopenharmony_ci#define	EHCI_HCS_DEBUGPORT(x)	(((x) >> 20) & 0xf)
67f9f848faSopenharmony_ci#define	EHCI_HCS_P_INDICATOR(x) ((x) & 0x10000)
68f9f848faSopenharmony_ci#define	EHCI_HCS_N_CC(x)	(((x) >> 12) & 0xf)	/* # of companion ctlrs */
69f9f848faSopenharmony_ci#define	EHCI_HCS_N_PCC(x)	(((x) >> 8) & 0xf)	/* # of ports per comp. */
70f9f848faSopenharmony_ci#define	EHCI_HCS_PPC(x)		((x) & 0x10)	/* port power control */
71f9f848faSopenharmony_ci#define	EHCI_HCS_N_PORTS(x)	((x) & 0xf)	/* # of ports */
72f9f848faSopenharmony_ci#define	EHCI_HCCPARAMS		0x08	/* RO Capability parameters */
73f9f848faSopenharmony_ci#define	EHCI_HCC_EECP(x)	(((x) >> 8) & 0xff)	/* extended ports caps */
74f9f848faSopenharmony_ci#define	EHCI_HCC_IST(x)		(((x) >> 4) & 0xf)	/* isoc sched threshold */
75f9f848faSopenharmony_ci#define	EHCI_HCC_ASPC(x)	((x) & 0x4)	/* async sched park cap */
76f9f848faSopenharmony_ci#define	EHCI_HCC_PFLF(x)	((x) & 0x2)	/* prog frame list flag */
77f9f848faSopenharmony_ci#define	EHCI_HCC_64BIT(x)	((x) & 0x1)	/* 64 bit address cap */
78f9f848faSopenharmony_ci#define	EHCI_HCSP_PORTROUTE	0x0c	/* RO Companion port route description */
79f9f848faSopenharmony_ci
80f9f848faSopenharmony_ci/* EHCI operational registers.  Offset given by EHCI_CAPLENGTH register */
81f9f848faSopenharmony_ci#define	EHCI_USBCMD		0x00	/* RO, RW, WO Command register */
82f9f848faSopenharmony_ci#define	EHCI_CMD_ITC_M		0x00ff0000	/* RW interrupt threshold ctrl */
83f9f848faSopenharmony_ci#define	EHCI_CMD_ITC_1		0x00010000
84f9f848faSopenharmony_ci#define	EHCI_CMD_ITC_2		0x00020000
85f9f848faSopenharmony_ci#define	EHCI_CMD_ITC_4		0x00040000
86f9f848faSopenharmony_ci#define	EHCI_CMD_ITC_8		0x00080000
87f9f848faSopenharmony_ci#define	EHCI_CMD_ITC_16		0x00100000
88f9f848faSopenharmony_ci#define	EHCI_CMD_ITC_32		0x00200000
89f9f848faSopenharmony_ci#define	EHCI_CMD_ITC_64		0x00400000
90f9f848faSopenharmony_ci#define	EHCI_CMD_ASPME		0x00000800	/* RW/RO async park enable */
91f9f848faSopenharmony_ci#define	EHCI_CMD_ASPMC		0x00000300	/* RW/RO async park count */
92f9f848faSopenharmony_ci#define	EHCI_CMD_LHCR		0x00000080	/* RW light host ctrl reset */
93f9f848faSopenharmony_ci#define	EHCI_CMD_IAAD		0x00000040	/* RW intr on async adv door
94f9f848faSopenharmony_ci						 * bell */
95f9f848faSopenharmony_ci#define	EHCI_CMD_ASE		0x00000020	/* RW async sched enable */
96f9f848faSopenharmony_ci#define	EHCI_CMD_PSE		0x00000010	/* RW periodic sched enable */
97f9f848faSopenharmony_ci#define	EHCI_CMD_FLS_M		0x0000000c	/* RW/RO frame list size */
98f9f848faSopenharmony_ci#define	EHCI_CMD_FLS(x)		(((x) >> 2) & 3)	/* RW/RO frame list size */
99f9f848faSopenharmony_ci#define	EHCI_CMD_HCRESET	0x00000002	/* RW reset */
100f9f848faSopenharmony_ci#define	EHCI_CMD_RS		0x00000001	/* RW run/stop */
101f9f848faSopenharmony_ci#define	EHCI_USBSTS		0x04	/* RO, RW, RWC Status register */
102f9f848faSopenharmony_ci#define	EHCI_STS_ASS		0x00008000	/* RO async sched status */
103f9f848faSopenharmony_ci#define	EHCI_STS_PSS		0x00004000	/* RO periodic sched status */
104f9f848faSopenharmony_ci#define	EHCI_STS_REC		0x00002000	/* RO reclamation */
105f9f848faSopenharmony_ci#define	EHCI_STS_HCH		0x00001000	/* RO host controller halted */
106f9f848faSopenharmony_ci#define	EHCI_STS_IAA		0x00000020	/* RWC interrupt on async adv */
107f9f848faSopenharmony_ci#define	EHCI_STS_HSE		0x00000010	/* RWC host system error */
108f9f848faSopenharmony_ci#define	EHCI_STS_FLR		0x00000008	/* RWC frame list rollover */
109f9f848faSopenharmony_ci#define	EHCI_STS_PCD		0x00000004	/* RWC port change detect */
110f9f848faSopenharmony_ci#define	EHCI_STS_ERRINT		0x00000002	/* RWC error interrupt */
111f9f848faSopenharmony_ci#define	EHCI_STS_INT		0x00000001	/* RWC interrupt */
112f9f848faSopenharmony_ci#define	EHCI_STS_INTRS(x)	((x) & 0x3f)
113f9f848faSopenharmony_ci
114f9f848faSopenharmony_ci/*
115f9f848faSopenharmony_ci * NOTE: the doorbell interrupt is enabled, but the doorbell is never
116f9f848faSopenharmony_ci * used! SiS chipsets require this.
117f9f848faSopenharmony_ci */
118f9f848faSopenharmony_ci#define	EHCI_NORMAL_INTRS	(EHCI_STS_IAA | EHCI_STS_HSE |	\
119f9f848faSopenharmony_ci				EHCI_STS_PCD | EHCI_STS_ERRINT | EHCI_STS_INT)
120f9f848faSopenharmony_ci
121f9f848faSopenharmony_ci#define	EHCI_USBINTR		0x08	/* RW Interrupt register */
122f9f848faSopenharmony_ci#define	EHCI_INTR_IAAE		0x00000020	/* interrupt on async advance
123f9f848faSopenharmony_ci						 * ena */
124f9f848faSopenharmony_ci#define	EHCI_INTR_HSEE		0x00000010	/* host system error ena */
125f9f848faSopenharmony_ci#define	EHCI_INTR_FLRE		0x00000008	/* frame list rollover ena */
126f9f848faSopenharmony_ci#define	EHCI_INTR_PCIE		0x00000004	/* port change ena */
127f9f848faSopenharmony_ci#define	EHCI_INTR_UEIE		0x00000002	/* USB error intr ena */
128f9f848faSopenharmony_ci#define	EHCI_INTR_UIE		0x00000001	/* USB intr ena */
129f9f848faSopenharmony_ci
130f9f848faSopenharmony_ci#define	EHCI_FRINDEX		0x0c	/* RW Frame Index register */
131f9f848faSopenharmony_ci
132f9f848faSopenharmony_ci#define	EHCI_CTRLDSSEGMENT	0x10	/* RW Control Data Structure Segment */
133f9f848faSopenharmony_ci
134f9f848faSopenharmony_ci#define	EHCI_PERIODICLISTBASE	0x14	/* RW Periodic List Base */
135f9f848faSopenharmony_ci#define	EHCI_ASYNCLISTADDR	0x18	/* RW Async List Base */
136f9f848faSopenharmony_ci
137f9f848faSopenharmony_ci#define	EHCI_CONFIGFLAG		0x40	/* RW Configure Flag register */
138f9f848faSopenharmony_ci#define	EHCI_CONF_CF		0x00000001	/* RW configure flag */
139f9f848faSopenharmony_ci
140f9f848faSopenharmony_ci#define	EHCI_PORTSC(n)		(0x40+(4*(n)))	/* RO, RW, RWC Port Status reg */
141f9f848faSopenharmony_ci#define	EHCI_PS_WKOC_E		0x00400000	/* RW wake on over current ena */
142f9f848faSopenharmony_ci#define	EHCI_PS_WKDSCNNT_E	0x00200000	/* RW wake on disconnect ena */
143f9f848faSopenharmony_ci#define	EHCI_PS_WKCNNT_E	0x00100000	/* RW wake on connect ena */
144f9f848faSopenharmony_ci#define	EHCI_PS_PTC		0x000f0000	/* RW port test control */
145f9f848faSopenharmony_ci#define	EHCI_PS_PIC		0x0000c000	/* RW port indicator control */
146f9f848faSopenharmony_ci#define	EHCI_PS_PO		0x00002000	/* RW port owner */
147f9f848faSopenharmony_ci#define	EHCI_PS_PP		0x00001000	/* RW,RO port power */
148f9f848faSopenharmony_ci#define	EHCI_PS_LS		0x00000c00	/* RO line status */
149f9f848faSopenharmony_ci#define	EHCI_PS_IS_LOWSPEED(x)	(((x) & EHCI_PS_LS) == 0x00000400)
150f9f848faSopenharmony_ci#define	EHCI_PS_PR		0x00000100	/* RW port reset */
151f9f848faSopenharmony_ci#define	EHCI_PS_SUSP		0x00000080	/* RW suspend */
152f9f848faSopenharmony_ci#define	EHCI_PS_FPR		0x00000040	/* RW force port resume */
153f9f848faSopenharmony_ci#define	EHCI_PS_OCC		0x00000020	/* RWC over current change */
154f9f848faSopenharmony_ci#define	EHCI_PS_OCA		0x00000010	/* RO over current active */
155f9f848faSopenharmony_ci#define	EHCI_PS_PEC		0x00000008	/* RWC port enable change */
156f9f848faSopenharmony_ci#define	EHCI_PS_PE		0x00000004	/* RW port enable */
157f9f848faSopenharmony_ci#define	EHCI_PS_CSC		0x00000002	/* RWC connect status change */
158f9f848faSopenharmony_ci#define	EHCI_PS_CS		0x00000001	/* RO connect status */
159f9f848faSopenharmony_ci#define	EHCI_PS_CLEAR		(EHCI_PS_OCC | EHCI_PS_PEC | EHCI_PS_CSC)
160f9f848faSopenharmony_ci
161f9f848faSopenharmony_ci#define	EHCI_PORT_RESET_COMPLETE	2	/* ms */
162f9f848faSopenharmony_ci
163f9f848faSopenharmony_ci/*
164f9f848faSopenharmony_ci * Registers not covered by EHCI specification
165f9f848faSopenharmony_ci *
166f9f848faSopenharmony_ci *
167f9f848faSopenharmony_ci * EHCI_USBMODE register offset is different for cores with LPM support,
168f9f848faSopenharmony_ci * bits are equal
169f9f848faSopenharmony_ci */
170f9f848faSopenharmony_ci#define	EHCI_USBMODE_NOLPM	0x68	/* RW USB Device mode reg (no LPM) */
171f9f848faSopenharmony_ci#define	EHCI_USBMODE_LPM	0xC8	/* RW USB Device mode reg (LPM) */
172f9f848faSopenharmony_ci#define	EHCI_UM_CM		0x00000003	/* R/WO Controller Mode */
173f9f848faSopenharmony_ci#define	EHCI_UM_CM_IDLE		0x0	/* Idle */
174f9f848faSopenharmony_ci#define	EHCI_UM_CM_HOST		0x3	/* Host Controller */
175f9f848faSopenharmony_ci#define	EHCI_UM_ES		0x00000004	/* R/WO Endian Select */
176f9f848faSopenharmony_ci#define	EHCI_UM_ES_LE		0x0	/* Little-endian byte alignment */
177f9f848faSopenharmony_ci#define	EHCI_UM_ES_BE		0x4	/* Big-endian byte alignment */
178f9f848faSopenharmony_ci#define	EHCI_UM_SDIS		0x00000010	/* R/WO Stream Disable Mode */
179f9f848faSopenharmony_ci
180f9f848faSopenharmony_ci/*
181f9f848faSopenharmony_ci * Actual port speed bits depends on EHCI_HOSTC(n) registers presence,
182f9f848faSopenharmony_ci * speed encoding is equal
183f9f848faSopenharmony_ci */
184f9f848faSopenharmony_ci#define	EHCI_HOSTC(n)		(0x80+(4*(n)))	/* RO, RW Host mode control reg */
185f9f848faSopenharmony_ci#define	EHCI_HOSTC_PSPD_SHIFT	25
186f9f848faSopenharmony_ci#define	EHCI_HOSTC_PSPD_MASK	0x3
187f9f848faSopenharmony_ci
188f9f848faSopenharmony_ci#define	EHCI_PORTSC_PSPD_SHIFT	26
189f9f848faSopenharmony_ci#define	EHCI_PORTSC_PSPD_MASK	0x3
190f9f848faSopenharmony_ci
191f9f848faSopenharmony_ci#define	EHCI_PORT_SPEED_FULL	0
192f9f848faSopenharmony_ci#define	EHCI_PORT_SPEED_LOW	1
193f9f848faSopenharmony_ci#define	EHCI_PORT_SPEED_HIGH	2
194f9f848faSopenharmony_ci#endif	/* _EHCIREG_H_ */
195