xref: /freebsd/sys/dev/usb/controller/musb_otg.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
102ac6454SAndrew Thompson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
402ac6454SAndrew Thompson  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
502ac6454SAndrew Thompson  *
602ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
702ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
802ac6454SAndrew Thompson  * are met:
902ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1002ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1102ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1202ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1302ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1402ac6454SAndrew Thompson  *
1502ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1602ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1702ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1802ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1902ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2002ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2102ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2202ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2302ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2402ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2502ac6454SAndrew Thompson  * SUCH DAMAGE.
2602ac6454SAndrew Thompson  */
2702ac6454SAndrew Thompson 
2802ac6454SAndrew Thompson /*
29fde87526SAndrew Thompson  * This header file defines the registers of the Mentor Graphics USB OnTheGo
30fde87526SAndrew Thompson  * Inventra chip.
3102ac6454SAndrew Thompson  */
3202ac6454SAndrew Thompson 
3302ac6454SAndrew Thompson #ifndef _MUSB2_OTG_H_
3402ac6454SAndrew Thompson #define	_MUSB2_OTG_H_
3502ac6454SAndrew Thompson 
36860e12e9SOleksandr Tymoshenko #define	MUSB2_MAX_DEVICES USB_MAX_DEVICES
3702ac6454SAndrew Thompson 
3802ac6454SAndrew Thompson /* Common registers */
3902ac6454SAndrew Thompson 
4002ac6454SAndrew Thompson #define	MUSB2_REG_FADDR 0x0000		/* function address register */
4102ac6454SAndrew Thompson #define	MUSB2_MASK_FADDR 0x7F
4202ac6454SAndrew Thompson 
4302ac6454SAndrew Thompson #define	MUSB2_REG_POWER 0x0001		/* power register */
4402ac6454SAndrew Thompson #define	MUSB2_MASK_SUSPM_ENA 0x01
4502ac6454SAndrew Thompson #define	MUSB2_MASK_SUSPMODE 0x02
4602ac6454SAndrew Thompson #define	MUSB2_MASK_RESUME 0x04
4702ac6454SAndrew Thompson #define	MUSB2_MASK_RESET 0x08
4802ac6454SAndrew Thompson #define	MUSB2_MASK_HSMODE 0x10
4902ac6454SAndrew Thompson #define	MUSB2_MASK_HSENAB 0x20
5002ac6454SAndrew Thompson #define	MUSB2_MASK_SOFTC 0x40
5102ac6454SAndrew Thompson #define	MUSB2_MASK_ISOUPD 0x80
5202ac6454SAndrew Thompson 
5302ac6454SAndrew Thompson /* Endpoint interrupt handling */
5402ac6454SAndrew Thompson 
5502ac6454SAndrew Thompson #define	MUSB2_REG_INTTX 0x0002		/* transmit interrupt register */
5602ac6454SAndrew Thompson #define	MUSB2_REG_INTRX 0x0004		/* receive interrupt register */
5702ac6454SAndrew Thompson #define	MUSB2_REG_INTTXE 0x0006		/* transmit interrupt enable register */
5802ac6454SAndrew Thompson #define	MUSB2_REG_INTRXE 0x0008		/* receive interrupt enable register */
5902ac6454SAndrew Thompson #define	MUSB2_MASK_EPINT(epn) (1 << (epn))	/* epn = [0..15] */
6002ac6454SAndrew Thompson 
6102ac6454SAndrew Thompson /* Common interrupt handling */
6202ac6454SAndrew Thompson 
6302ac6454SAndrew Thompson #define	MUSB2_REG_INTUSB 0x000A		/* USB interrupt register */
6402ac6454SAndrew Thompson #define	MUSB2_MASK_ISUSP 0x01
6502ac6454SAndrew Thompson #define	MUSB2_MASK_IRESUME 0x02
6602ac6454SAndrew Thompson #define	MUSB2_MASK_IRESET 0x04
6702ac6454SAndrew Thompson #define	MUSB2_MASK_IBABBLE 0x04
6802ac6454SAndrew Thompson #define	MUSB2_MASK_ISOF 0x08
6902ac6454SAndrew Thompson #define	MUSB2_MASK_ICONN 0x10
7002ac6454SAndrew Thompson #define	MUSB2_MASK_IDISC 0x20
7102ac6454SAndrew Thompson #define	MUSB2_MASK_ISESSRQ 0x40
7202ac6454SAndrew Thompson #define	MUSB2_MASK_IVBUSERR 0x80
7302ac6454SAndrew Thompson 
7402ac6454SAndrew Thompson #define	MUSB2_REG_INTUSBE 0x000B	/* USB interrupt enable register */
7502ac6454SAndrew Thompson #define	MUSB2_REG_FRAME 0x000C		/* USB frame register */
7602ac6454SAndrew Thompson #define	MUSB2_MASK_FRAME 0x3FF		/* 0..1023 */
7702ac6454SAndrew Thompson 
7802ac6454SAndrew Thompson #define	MUSB2_REG_EPINDEX 0x000E	/* endpoint index register */
7902ac6454SAndrew Thompson #define	MUSB2_MASK_EPINDEX 0x0F
8002ac6454SAndrew Thompson 
8102ac6454SAndrew Thompson #define	MUSB2_REG_TESTMODE 0x000F	/* test mode register */
8202ac6454SAndrew Thompson #define	MUSB2_MASK_TSE0_NAK 0x01
8302ac6454SAndrew Thompson #define	MUSB2_MASK_TJ 0x02
8402ac6454SAndrew Thompson #define	MUSB2_MASK_TK 0x04
8502ac6454SAndrew Thompson #define	MUSB2_MASK_TPACKET 0x08
8602ac6454SAndrew Thompson #define	MUSB2_MASK_TFORCE_HS 0x10
8702ac6454SAndrew Thompson #define	MUSB2_MASK_TFORCE_LS 0x20
8802ac6454SAndrew Thompson #define	MUSB2_MASK_TFIFO_ACC 0x40
8902ac6454SAndrew Thompson #define	MUSB2_MASK_TFORCE_HC 0x80
9002ac6454SAndrew Thompson 
9102ac6454SAndrew Thompson #define	MUSB2_REG_INDEXED_CSR 0x0010	/* EP control status register offset */
9202ac6454SAndrew Thompson 
9302ac6454SAndrew Thompson #define	MUSB2_REG_TXMAXP (0x0000 + MUSB2_REG_INDEXED_CSR)
9402ac6454SAndrew Thompson #define	MUSB2_REG_RXMAXP (0x0004 + MUSB2_REG_INDEXED_CSR)
9502ac6454SAndrew Thompson #define	MUSB2_MASK_PKTSIZE 0x03FF	/* in bytes, should be even */
9602ac6454SAndrew Thompson #define	MUSB2_MASK_PKTMULT 0xFC00	/* HS packet multiplier: 0..2 */
9702ac6454SAndrew Thompson 
9802ac6454SAndrew Thompson #define	MUSB2_REG_TXCSRL (0x0002 + MUSB2_REG_INDEXED_CSR)
9902ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXPKTRDY 0x01
10002ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXFIFONEMPTY 0x02
10102ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXUNDERRUN 0x04	/* Device Mode */
10202ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXERROR 0x04	/* Host Mode */
10302ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXFFLUSH 0x08
10402ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXSENDSTALL 0x10/* Device Mode */
10502ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXSETUPPKT 0x10	/* Host Mode */
10602ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXSENTSTALL 0x20/* Device Mode */
10702ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXSTALLED 0x20	/* Host Mode */
10802ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_TXDT_CLR 0x40
109860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSRL_TXINCOMP 0x80 /* Device mode */
110860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSRL_TXNAKTO 0x80 /* Host mode */
11102ac6454SAndrew Thompson 
11202ac6454SAndrew Thompson /* Device Side Mode */
11302ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_RXPKTRDY 0x01
11402ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_TXPKTRDY 0x02
11502ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_SENTSTALL 0x04
11602ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_DATAEND 0x08
11702ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_SETUPEND 0x10
11802ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_SENDSTALL 0x20
11902ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_RXPKTRDY_CLR 0x40
12002ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_SETUPEND_CLR 0x80
12102ac6454SAndrew Thompson 
12202ac6454SAndrew Thompson /* Host Side Mode */
123860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSR0L_TXFIFONEMPTY 0x02
12402ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_RXSTALL 0x04
12502ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_SETUPPKT 0x08
12602ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_ERROR 0x10
12702ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_REQPKT 0x20
12802ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_STATUSPKT 0x40
12902ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0L_NAKTIMO 0x80
13002ac6454SAndrew Thompson 
13102ac6454SAndrew Thompson #define	MUSB2_REG_TXCSRH (0x0003 + MUSB2_REG_INDEXED_CSR)
13202ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_TXDT_VAL 0x01	/* Host Mode */
133860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSRH_TXDT_WREN 0x02	/* Host Mode */
13402ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_TXDMAREQMODE 0x04
13502ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_TXDT_SWITCH 0x08
13602ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_TXDMAREQENA 0x10
13702ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXMODE 0x00
13802ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_TXMODE 0x20
13902ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_TXISO 0x40	/* Device Mode */
14002ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_TXAUTOSET 0x80
14102ac6454SAndrew Thompson 
14202ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0H_FFLUSH 0x01	/* Device Side flush FIFO */
14302ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0H_DT 0x02	/* Host Side data toggle */
144860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSR0H_DT_WREN 0x04	/* Host Side */
14502ac6454SAndrew Thompson #define	MUSB2_MASK_CSR0H_PING_DIS 0x08	/* Host Side */
14602ac6454SAndrew Thompson 
14702ac6454SAndrew Thompson #define	MUSB2_REG_RXCSRL (0x0006 + MUSB2_REG_INDEXED_CSR)
14802ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_RXPKTRDY 0x01
14902ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_RXFIFOFULL 0x02
150860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSRL_RXOVERRUN 0x04 /* Device Mode */
151860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSRL_RXERROR 0x04 /* Host Mode */
152860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSRL_RXDATAERR 0x08 /* Device Mode */
153860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSRL_RXNAKTO 0x08 /* Host Mode */
15402ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_RXFFLUSH 0x10
15502ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_RXSENDSTALL 0x20/* Device Mode */
15602ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_RXREQPKT 0x20	/* Host Mode */
15702ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_RXSENTSTALL 0x40/* Device Mode */
15802ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_RXSTALL 0x40	/* Host Mode */
15902ac6454SAndrew Thompson #define	MUSB2_MASK_CSRL_RXDT_CLR 0x80
16002ac6454SAndrew Thompson 
16102ac6454SAndrew Thompson #define	MUSB2_REG_RXCSRH (0x0007 + MUSB2_REG_INDEXED_CSR)
16202ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXINCOMP 0x01
16302ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXDT_VAL 0x02	/* Host Mode */
164860e12e9SOleksandr Tymoshenko #define	MUSB2_MASK_CSRH_RXDT_WREN 0x04	/* Host Mode */
16502ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXDMAREQMODE 0x08
16602ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXNYET 0x10
16702ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXDMAREQENA 0x20
16802ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXISO 0x40	/* Device Mode */
16902ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXAUTOREQ 0x40	/* Host Mode */
17002ac6454SAndrew Thompson #define	MUSB2_MASK_CSRH_RXAUTOCLEAR 0x80
17102ac6454SAndrew Thompson 
17202ac6454SAndrew Thompson #define	MUSB2_REG_RXCOUNT (0x0008 + MUSB2_REG_INDEXED_CSR)
17302ac6454SAndrew Thompson #define	MUSB2_MASK_RXCOUNT 0xFFFF
17402ac6454SAndrew Thompson 
17502ac6454SAndrew Thompson #define	MUSB2_REG_TXTI (0x000A + MUSB2_REG_INDEXED_CSR)
17602ac6454SAndrew Thompson #define	MUSB2_REG_RXTI (0x000C + MUSB2_REG_INDEXED_CSR)
17702ac6454SAndrew Thompson 
17802ac6454SAndrew Thompson /* Host Mode */
17902ac6454SAndrew Thompson #define	MUSB2_MASK_TI_SPEED 0xC0
18002ac6454SAndrew Thompson #define	MUSB2_MASK_TI_SPEED_LO 0xC0
18102ac6454SAndrew Thompson #define	MUSB2_MASK_TI_SPEED_FS 0x80
18202ac6454SAndrew Thompson #define	MUSB2_MASK_TI_SPEED_HS 0x40
18302ac6454SAndrew Thompson #define	MUSB2_MASK_TI_PROTO_CTRL 0x00
18402ac6454SAndrew Thompson #define	MUSB2_MASK_TI_PROTO_ISOC 0x10
18502ac6454SAndrew Thompson #define	MUSB2_MASK_TI_PROTO_BULK 0x20
18602ac6454SAndrew Thompson #define	MUSB2_MASK_TI_PROTO_INTR 0x30
18702ac6454SAndrew Thompson #define	MUSB2_MASK_TI_EP_NUM 0x0F
18802ac6454SAndrew Thompson 
18902ac6454SAndrew Thompson #define	MUSB2_REG_TXNAKLIMIT (0x000B /* EPN=0 */ + MUSB2_REG_INDEXED_CSR)
19002ac6454SAndrew Thompson #define	MUSB2_REG_RXNAKLIMIT (0x000D /* EPN=0 */ + MUSB2_REG_INDEXED_CSR)
19102ac6454SAndrew Thompson #define	MUSB2_MASK_NAKLIMIT 0xFF
19202ac6454SAndrew Thompson 
19302ac6454SAndrew Thompson #define	MUSB2_REG_FSIZE (0x000F + MUSB2_REG_INDEXED_CSR)
19402ac6454SAndrew Thompson #define	MUSB2_MASK_RX_FSIZE 0xF0	/* 3..13, 2**n bytes */
19502ac6454SAndrew Thompson #define	MUSB2_MASK_TX_FSIZE 0x0F	/* 3..13, 2**n bytes */
19602ac6454SAndrew Thompson 
19702ac6454SAndrew Thompson #define	MUSB2_REG_EPFIFO(n) (0x0020 + (4*(n)))
19802ac6454SAndrew Thompson 
199add5cc2fSAndrew Thompson #define	MUSB2_REG_CONFDATA (0x000F + MUSB2_REG_INDEXED_CSR)	/* EPN=0 */
20002ac6454SAndrew Thompson #define	MUSB2_MASK_CD_UTMI_DW 0x01
20102ac6454SAndrew Thompson #define	MUSB2_MASK_CD_SOFTCONE 0x02
20202ac6454SAndrew Thompson #define	MUSB2_MASK_CD_DYNFIFOSZ 0x04
20302ac6454SAndrew Thompson #define	MUSB2_MASK_CD_HBTXE 0x08
20402ac6454SAndrew Thompson #define	MUSB2_MASK_CD_HBRXE 0x10
20502ac6454SAndrew Thompson #define	MUSB2_MASK_CD_BIGEND 0x20
20602ac6454SAndrew Thompson #define	MUSB2_MASK_CD_MPTXE 0x40
20702ac6454SAndrew Thompson #define	MUSB2_MASK_CD_MPRXE 0x80
20802ac6454SAndrew Thompson 
20902ac6454SAndrew Thompson /* Various registers */
21002ac6454SAndrew Thompson 
21102ac6454SAndrew Thompson #define	MUSB2_REG_DEVCTL 0x0060
21202ac6454SAndrew Thompson #define	MUSB2_MASK_SESS 0x01
21302ac6454SAndrew Thompson #define	MUSB2_MASK_HOSTREQ 0x02
21402ac6454SAndrew Thompson #define	MUSB2_MASK_HOSTMD 0x04
21502ac6454SAndrew Thompson #define	MUSB2_MASK_VBUS0 0x08
21602ac6454SAndrew Thompson #define	MUSB2_MASK_VBUS1 0x10
21702ac6454SAndrew Thompson #define	MUSB2_MASK_LSDEV 0x20
21802ac6454SAndrew Thompson #define	MUSB2_MASK_FSDEV 0x40
21902ac6454SAndrew Thompson #define	MUSB2_MASK_BDEV 0x80
22002ac6454SAndrew Thompson 
22102ac6454SAndrew Thompson #define	MUSB2_REG_MISC 0x0061
22202ac6454SAndrew Thompson #define	MUSB2_MASK_RXEDMA 0x01
22302ac6454SAndrew Thompson #define	MUSB2_MASK_TXEDMA 0x02
22402ac6454SAndrew Thompson 
22502ac6454SAndrew Thompson #define	MUSB2_REG_TXFIFOSZ 0x0062
22602ac6454SAndrew Thompson #define	MUSB2_REG_RXFIFOSZ 0x0063
22702ac6454SAndrew Thompson #define	MUSB2_MASK_FIFODB 0x10		/* set if double buffering, r/w */
22802ac6454SAndrew Thompson #define	MUSB2_MASK_FIFOSZ 0x0F
22902ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_8 0
23002ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_16 1
23102ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_32 2
23202ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_64 3
23302ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_128 4
23402ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_256 5
23502ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_512 6
23602ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_1024 7
23702ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_2048 8
23802ac6454SAndrew Thompson #define	MUSB2_VAL_FIFOSZ_4096 9
23902ac6454SAndrew Thompson 
24002ac6454SAndrew Thompson #define	MUSB2_REG_TXFIFOADD 0x0064
24102ac6454SAndrew Thompson #define	MUSB2_REG_RXFIFOADD 0x0066
24202ac6454SAndrew Thompson #define	MUSB2_MASK_FIFOADD 0xFFF	/* unit is 8-bytes */
24302ac6454SAndrew Thompson 
24402ac6454SAndrew Thompson #define	MUSB2_REG_VSTATUS 0x0068
24502ac6454SAndrew Thompson #define	MUSB2_REG_VCONTROL 0x0068
24602ac6454SAndrew Thompson #define	MUSB2_REG_HWVERS 0x006C
24702ac6454SAndrew Thompson #define	MUSB2_REG_ULPI_BASE 0x0070
24802ac6454SAndrew Thompson 
24902ac6454SAndrew Thompson #define	MUSB2_REG_EPINFO 0x0078
25002ac6454SAndrew Thompson #define	MUSB2_MASK_NRXEP 0xF0
25102ac6454SAndrew Thompson #define	MUSB2_MASK_NTXEP 0x0F
25202ac6454SAndrew Thompson 
25302ac6454SAndrew Thompson #define	MUSB2_REG_RAMINFO 0x0079
25402ac6454SAndrew Thompson #define	MUSB2_REG_LINKINFO 0x007A
25502ac6454SAndrew Thompson 
25602ac6454SAndrew Thompson #define	MUSB2_REG_VPLEN 0x007B
25702ac6454SAndrew Thompson #define	MUSB2_MASK_VPLEN 0xFF
25802ac6454SAndrew Thompson 
25902ac6454SAndrew Thompson #define	MUSB2_REG_HS_EOF1 0x007C
26002ac6454SAndrew Thompson #define	MUSB2_REG_FS_EOF1 0x007D
26102ac6454SAndrew Thompson #define	MUSB2_REG_LS_EOF1 0x007E
26202ac6454SAndrew Thompson #define	MUSB2_REG_SOFT_RST 0x007F
26302ac6454SAndrew Thompson #define	MUSB2_MASK_SRST 0x01
26402ac6454SAndrew Thompson #define	MUSB2_MASK_SRSTX 0x02
26502ac6454SAndrew Thompson 
26602ac6454SAndrew Thompson #define	MUSB2_REG_RQPKTCOUNT(n) (0x0300 + (4*(n))
26702ac6454SAndrew Thompson #define	MUSB2_REG_RXDBDIS 0x0340
26802ac6454SAndrew Thompson #define	MUSB2_REG_TXDBDIS 0x0342
26902ac6454SAndrew Thompson #define	MUSB2_MASK_DB(n) (1 << (n))	/* disable double buffer, n = [0..15] */
27002ac6454SAndrew Thompson 
27102ac6454SAndrew Thompson #define	MUSB2_REG_CHIRPTO 0x0344
27202ac6454SAndrew Thompson #define	MUSB2_REG_HSRESUM 0x0346
27302ac6454SAndrew Thompson 
27402ac6454SAndrew Thompson /* Host Mode only registers */
27502ac6454SAndrew Thompson 
27602ac6454SAndrew Thompson #define	MUSB2_REG_TXFADDR(n) (0x0080 + (8*(n)))
27702ac6454SAndrew Thompson #define	MUSB2_REG_TXHADDR(n) (0x0082 + (8*(n)))
27802ac6454SAndrew Thompson #define	MUSB2_REG_TXHUBPORT(n) (0x0083 + (8*(n)))
27902ac6454SAndrew Thompson #define	MUSB2_REG_RXFADDR(n) (0x0084 + (8*(n)))
28002ac6454SAndrew Thompson #define	MUSB2_REG_RXHADDR(n) (0x0086 + (8*(n)))
281860e12e9SOleksandr Tymoshenko #define	MUSB2_REG_RXHUBPORT(n) (0x0087 + (8*(n)))
28202ac6454SAndrew Thompson 
28302ac6454SAndrew Thompson #define	MUSB2_EP_MAX 16			/* maximum number of endpoints */
28402ac6454SAndrew Thompson 
285860e12e9SOleksandr Tymoshenko #define	MUSB2_DEVICE_MODE	0
286860e12e9SOleksandr Tymoshenko #define	MUSB2_HOST_MODE		1
287860e12e9SOleksandr Tymoshenko 
28802ac6454SAndrew Thompson #define	MUSB2_READ_2(sc, reg) \
28902ac6454SAndrew Thompson   bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, reg)
29002ac6454SAndrew Thompson 
29102ac6454SAndrew Thompson #define	MUSB2_WRITE_2(sc, reg, data)	\
29202ac6454SAndrew Thompson   bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data)
29302ac6454SAndrew Thompson 
29402ac6454SAndrew Thompson #define	MUSB2_READ_1(sc, reg) \
29502ac6454SAndrew Thompson   bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, reg)
29602ac6454SAndrew Thompson 
29702ac6454SAndrew Thompson #define	MUSB2_WRITE_1(sc, reg, data)	\
29802ac6454SAndrew Thompson   bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, reg, data)
29902ac6454SAndrew Thompson 
30002ac6454SAndrew Thompson struct musbotg_td;
30102ac6454SAndrew Thompson struct musbotg_softc;
30202ac6454SAndrew Thompson 
30302ac6454SAndrew Thompson typedef uint8_t (musbotg_cmd_t)(struct musbotg_td *td);
30402ac6454SAndrew Thompson 
30502ac6454SAndrew Thompson struct musbotg_dma {
30602ac6454SAndrew Thompson 	struct musbotg_softc *sc;
30702ac6454SAndrew Thompson 	uint32_t dma_chan;
30802ac6454SAndrew Thompson 	uint8_t	busy:1;
30902ac6454SAndrew Thompson 	uint8_t	complete:1;
31002ac6454SAndrew Thompson 	uint8_t	error:1;
31102ac6454SAndrew Thompson };
31202ac6454SAndrew Thompson 
31302ac6454SAndrew Thompson struct musbotg_td {
31402ac6454SAndrew Thompson 	struct musbotg_td *obj_next;
31502ac6454SAndrew Thompson 	musbotg_cmd_t *func;
316760bc48eSAndrew Thompson 	struct usb_page_cache *pc;
31702ac6454SAndrew Thompson 	uint32_t offset;
31802ac6454SAndrew Thompson 	uint32_t remainder;
31902ac6454SAndrew Thompson 	uint16_t max_frame_size;	/* packet_size * mult */
3205c767719SHans Petter Selasky 	uint16_t reg_max_packet;
32102ac6454SAndrew Thompson 	uint8_t	ep_no;
322860e12e9SOleksandr Tymoshenko 	uint8_t	transfer_type;
32302ac6454SAndrew Thompson 	uint8_t	error:1;
32402ac6454SAndrew Thompson 	uint8_t	alt_next:1;
32502ac6454SAndrew Thompson 	uint8_t	short_pkt:1;
32602ac6454SAndrew Thompson 	uint8_t	support_multi_buffer:1;
32702ac6454SAndrew Thompson 	uint8_t	did_stall:1;
32802ac6454SAndrew Thompson 	uint8_t	dma_enabled:1;
329860e12e9SOleksandr Tymoshenko 	uint8_t	transaction_started:1;
330860e12e9SOleksandr Tymoshenko 	uint8_t dev_addr;
331860e12e9SOleksandr Tymoshenko 	uint8_t toggle;
332860e12e9SOleksandr Tymoshenko 	int8_t channel;
333860e12e9SOleksandr Tymoshenko 	uint8_t haddr;
334860e12e9SOleksandr Tymoshenko 	uint8_t hport;
33502ac6454SAndrew Thompson };
33602ac6454SAndrew Thompson 
33702ac6454SAndrew Thompson struct musbotg_std_temp {
33802ac6454SAndrew Thompson 	musbotg_cmd_t *func;
339760bc48eSAndrew Thompson 	struct usb_page_cache *pc;
34002ac6454SAndrew Thompson 	struct musbotg_td *td;
34102ac6454SAndrew Thompson 	struct musbotg_td *td_next;
34202ac6454SAndrew Thompson 	uint32_t len;
34302ac6454SAndrew Thompson 	uint32_t offset;
34402ac6454SAndrew Thompson 	uint16_t max_frame_size;
34502ac6454SAndrew Thompson 	uint8_t	short_pkt;
34602ac6454SAndrew Thompson 	/*
34702ac6454SAndrew Thompson          * short_pkt = 0: transfer should be short terminated
34802ac6454SAndrew Thompson          * short_pkt = 1: transfer should not be short terminated
34902ac6454SAndrew Thompson          */
35002ac6454SAndrew Thompson 	uint8_t	setup_alt_next;
351476183dfSAndrew Thompson 	uint8_t did_stall;
352860e12e9SOleksandr Tymoshenko 	uint8_t dev_addr;
353860e12e9SOleksandr Tymoshenko 	int8_t channel;
354860e12e9SOleksandr Tymoshenko 	uint8_t haddr;
355860e12e9SOleksandr Tymoshenko 	uint8_t hport;
356860e12e9SOleksandr Tymoshenko 	uint8_t	transfer_type;
35702ac6454SAndrew Thompson };
35802ac6454SAndrew Thompson 
35902ac6454SAndrew Thompson struct musbotg_config_desc {
360760bc48eSAndrew Thompson 	struct usb_config_descriptor confd;
361760bc48eSAndrew Thompson 	struct usb_interface_descriptor ifcd;
362760bc48eSAndrew Thompson 	struct usb_endpoint_descriptor endpd;
36302ac6454SAndrew Thompson } __packed;
36402ac6454SAndrew Thompson 
36502ac6454SAndrew Thompson union musbotg_hub_temp {
36602ac6454SAndrew Thompson 	uWord	wValue;
367760bc48eSAndrew Thompson 	struct usb_port_status ps;
36802ac6454SAndrew Thompson };
36902ac6454SAndrew Thompson 
37002ac6454SAndrew Thompson struct musbotg_flags {
37102ac6454SAndrew Thompson 	uint8_t	change_connect:1;
37202ac6454SAndrew Thompson 	uint8_t	change_suspend:1;
373860e12e9SOleksandr Tymoshenko 	uint8_t	change_reset:1;
374860e12e9SOleksandr Tymoshenko 	uint8_t	change_over_current:1;
375860e12e9SOleksandr Tymoshenko 	uint8_t	change_enabled:1;
37602ac6454SAndrew Thompson 	uint8_t	status_suspend:1;	/* set if suspended */
37702ac6454SAndrew Thompson 	uint8_t	status_vbus:1;		/* set if present */
37802ac6454SAndrew Thompson 	uint8_t	status_bus_reset:1;	/* set if reset complete */
37902ac6454SAndrew Thompson 	uint8_t	status_high_speed:1;	/* set if High Speed is selected */
38002ac6454SAndrew Thompson 	uint8_t	remote_wakeup:1;
38102ac6454SAndrew Thompson 	uint8_t	self_powered:1;
38202ac6454SAndrew Thompson 	uint8_t	clocks_off:1;
38302ac6454SAndrew Thompson 	uint8_t	port_powered:1;
38402ac6454SAndrew Thompson 	uint8_t	port_enabled:1;
385860e12e9SOleksandr Tymoshenko 	uint8_t	port_over_current:1;
38602ac6454SAndrew Thompson 	uint8_t	d_pulled_up:1;
38702ac6454SAndrew Thompson };
38802ac6454SAndrew Thompson 
389d614c09aSAndrew Turner struct musb_otg_ep_cfg {
390d614c09aSAndrew Turner 	int ep_end;
391d614c09aSAndrew Turner 	int ep_fifosz_shift;
392d614c09aSAndrew Turner 	uint8_t ep_fifosz_reg;
393d614c09aSAndrew Turner };
394d614c09aSAndrew Turner 
39502ac6454SAndrew Thompson struct musbotg_softc {
396760bc48eSAndrew Thompson 	struct usb_bus sc_bus;
39702ac6454SAndrew Thompson 	union musbotg_hub_temp sc_hub_temp;
398408b9d7cSHans Petter Selasky 	struct usb_hw_ep_profile sc_hw_ep_profile[MUSB2_EP_MAX];
39902ac6454SAndrew Thompson 
400760bc48eSAndrew Thompson 	struct usb_device *sc_devices[MUSB2_MAX_DEVICES];
40102ac6454SAndrew Thompson 	struct resource *sc_io_res;
40202ac6454SAndrew Thompson 	struct resource *sc_irq_res;
40302ac6454SAndrew Thompson 	void   *sc_intr_hdl;
40402ac6454SAndrew Thompson 	bus_size_t sc_io_size;
40502ac6454SAndrew Thompson 	bus_space_tag_t sc_io_tag;
40602ac6454SAndrew Thompson 	bus_space_handle_t sc_io_hdl;
40702ac6454SAndrew Thompson 
40802ac6454SAndrew Thompson 	void    (*sc_clocks_on) (void *arg);
40902ac6454SAndrew Thompson 	void    (*sc_clocks_off) (void *arg);
410860e12e9SOleksandr Tymoshenko 	void    (*sc_ep_int_set) (struct musbotg_softc *sc, int ep, int on);
41102ac6454SAndrew Thompson 	void   *sc_clocks_arg;
41202ac6454SAndrew Thompson 
41302ac6454SAndrew Thompson 	uint32_t sc_bounce_buf[(1024 * 3) / 4];	/* bounce buffer */
41402ac6454SAndrew Thompson 
41502ac6454SAndrew Thompson 	uint8_t	sc_ep_max;		/* maximum number of RX and TX
41602ac6454SAndrew Thompson 					 * endpoints supported */
41702ac6454SAndrew Thompson 	uint8_t	sc_rt_addr;		/* root HUB address */
41802ac6454SAndrew Thompson 	uint8_t	sc_dv_addr;		/* device address */
41902ac6454SAndrew Thompson 	uint8_t	sc_conf;		/* root HUB config */
42002ac6454SAndrew Thompson 	uint8_t	sc_ep0_busy;		/* set if ep0 is busy */
42102ac6454SAndrew Thompson 	uint8_t	sc_ep0_cmd;		/* pending commands */
42202ac6454SAndrew Thompson 	uint8_t	sc_conf_data;		/* copy of hardware register */
42302ac6454SAndrew Thompson 
42402ac6454SAndrew Thompson 	uint8_t	sc_hub_idata[1];
425860e12e9SOleksandr Tymoshenko 	uint16_t sc_channel_mask;	/* 16 endpoints */
42602ac6454SAndrew Thompson 
42702ac6454SAndrew Thompson 	struct musbotg_flags sc_flags;
428860e12e9SOleksandr Tymoshenko 	uint8_t	sc_id;
429860e12e9SOleksandr Tymoshenko 	uint8_t	sc_mode;
430860e12e9SOleksandr Tymoshenko 	void *sc_platform_data;
431d614c09aSAndrew Turner 	const struct musb_otg_ep_cfg *sc_ep_cfg;
43202ac6454SAndrew Thompson };
43302ac6454SAndrew Thompson 
43402ac6454SAndrew Thompson /* prototypes */
43502ac6454SAndrew Thompson 
436e0a69b51SAndrew Thompson usb_error_t musbotg_init(struct musbotg_softc *sc);
43702ac6454SAndrew Thompson void	musbotg_uninit(struct musbotg_softc *sc);
438860e12e9SOleksandr Tymoshenko void	musbotg_interrupt(struct musbotg_softc *sc,
439860e12e9SOleksandr Tymoshenko     uint16_t rxstat, uint16_t txstat, uint8_t stat);
44002ac6454SAndrew Thompson void	musbotg_vbus_interrupt(struct musbotg_softc *sc, uint8_t is_on);
441860e12e9SOleksandr Tymoshenko void	musbotg_connect_interrupt(struct musbotg_softc *sc);
44202ac6454SAndrew Thompson 
44302ac6454SAndrew Thompson #endif					/* _MUSB2_OTG_H_ */
444