162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * CoreChip-sz SR9700 one chip USB 1.1 Ethernet Devices
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Author : Liu Junliang <liujunliang_ljl@163.com>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _SR9700_H
962306a36Sopenharmony_ci#define	_SR9700_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/* sr9700 spec. register table on Linux platform */
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* Network Control Reg */
1462306a36Sopenharmony_ci#define	SR_NCR			0x00
1562306a36Sopenharmony_ci#define		NCR_RST			(1 << 0)
1662306a36Sopenharmony_ci#define		NCR_LBK			(3 << 1)
1762306a36Sopenharmony_ci#define		NCR_FDX			(1 << 3)
1862306a36Sopenharmony_ci#define		NCR_WAKEEN		(1 << 6)
1962306a36Sopenharmony_ci/* Network Status Reg */
2062306a36Sopenharmony_ci#define	SR_NSR			0x01
2162306a36Sopenharmony_ci#define		NSR_RXRDY		(1 << 0)
2262306a36Sopenharmony_ci#define		NSR_RXOV		(1 << 1)
2362306a36Sopenharmony_ci#define		NSR_TX1END		(1 << 2)
2462306a36Sopenharmony_ci#define		NSR_TX2END		(1 << 3)
2562306a36Sopenharmony_ci#define		NSR_TXFULL		(1 << 4)
2662306a36Sopenharmony_ci#define		NSR_WAKEST		(1 << 5)
2762306a36Sopenharmony_ci#define		NSR_LINKST		(1 << 6)
2862306a36Sopenharmony_ci#define		NSR_SPEED		(1 << 7)
2962306a36Sopenharmony_ci/* Tx Control Reg */
3062306a36Sopenharmony_ci#define	SR_TCR			0x02
3162306a36Sopenharmony_ci#define		TCR_CRC_DIS		(1 << 1)
3262306a36Sopenharmony_ci#define		TCR_PAD_DIS		(1 << 2)
3362306a36Sopenharmony_ci#define		TCR_LC_CARE		(1 << 3)
3462306a36Sopenharmony_ci#define		TCR_CRS_CARE	(1 << 4)
3562306a36Sopenharmony_ci#define		TCR_EXCECM		(1 << 5)
3662306a36Sopenharmony_ci#define		TCR_LF_EN		(1 << 6)
3762306a36Sopenharmony_ci/* Tx Status Reg for Packet Index 1 */
3862306a36Sopenharmony_ci#define	SR_TSR1		0x03
3962306a36Sopenharmony_ci#define		TSR1_EC			(1 << 2)
4062306a36Sopenharmony_ci#define		TSR1_COL		(1 << 3)
4162306a36Sopenharmony_ci#define		TSR1_LC			(1 << 4)
4262306a36Sopenharmony_ci#define		TSR1_NC			(1 << 5)
4362306a36Sopenharmony_ci#define		TSR1_LOC		(1 << 6)
4462306a36Sopenharmony_ci#define		TSR1_TLF		(1 << 7)
4562306a36Sopenharmony_ci/* Tx Status Reg for Packet Index 2 */
4662306a36Sopenharmony_ci#define	SR_TSR2		0x04
4762306a36Sopenharmony_ci#define		TSR2_EC			(1 << 2)
4862306a36Sopenharmony_ci#define		TSR2_COL		(1 << 3)
4962306a36Sopenharmony_ci#define		TSR2_LC			(1 << 4)
5062306a36Sopenharmony_ci#define		TSR2_NC			(1 << 5)
5162306a36Sopenharmony_ci#define		TSR2_LOC		(1 << 6)
5262306a36Sopenharmony_ci#define		TSR2_TLF		(1 << 7)
5362306a36Sopenharmony_ci/* Rx Control Reg*/
5462306a36Sopenharmony_ci#define	SR_RCR			0x05
5562306a36Sopenharmony_ci#define		RCR_RXEN		(1 << 0)
5662306a36Sopenharmony_ci#define		RCR_PRMSC		(1 << 1)
5762306a36Sopenharmony_ci#define		RCR_RUNT		(1 << 2)
5862306a36Sopenharmony_ci#define		RCR_ALL			(1 << 3)
5962306a36Sopenharmony_ci#define		RCR_DIS_CRC		(1 << 4)
6062306a36Sopenharmony_ci#define		RCR_DIS_LONG	(1 << 5)
6162306a36Sopenharmony_ci/* Rx Status Reg */
6262306a36Sopenharmony_ci#define	SR_RSR			0x06
6362306a36Sopenharmony_ci#define		RSR_AE			(1 << 2)
6462306a36Sopenharmony_ci#define		RSR_MF			(1 << 6)
6562306a36Sopenharmony_ci#define		RSR_RF			(1 << 7)
6662306a36Sopenharmony_ci/* Rx Overflow Counter Reg */
6762306a36Sopenharmony_ci#define	SR_ROCR		0x07
6862306a36Sopenharmony_ci#define		ROCR_ROC		(0x7F << 0)
6962306a36Sopenharmony_ci#define		ROCR_RXFU		(1 << 7)
7062306a36Sopenharmony_ci/* Back Pressure Threshold Reg */
7162306a36Sopenharmony_ci#define	SR_BPTR		0x08
7262306a36Sopenharmony_ci#define		BPTR_JPT		(0x0F << 0)
7362306a36Sopenharmony_ci#define		BPTR_BPHW		(0x0F << 4)
7462306a36Sopenharmony_ci/* Flow Control Threshold Reg */
7562306a36Sopenharmony_ci#define	SR_FCTR		0x09
7662306a36Sopenharmony_ci#define		FCTR_LWOT		(0x0F << 0)
7762306a36Sopenharmony_ci#define		FCTR_HWOT		(0x0F << 4)
7862306a36Sopenharmony_ci/* rx/tx Flow Control Reg */
7962306a36Sopenharmony_ci#define	SR_FCR			0x0A
8062306a36Sopenharmony_ci#define		FCR_FLCE		(1 << 0)
8162306a36Sopenharmony_ci#define		FCR_BKPA		(1 << 4)
8262306a36Sopenharmony_ci#define		FCR_TXPEN		(1 << 5)
8362306a36Sopenharmony_ci#define		FCR_TXPF		(1 << 6)
8462306a36Sopenharmony_ci#define		FCR_TXP0		(1 << 7)
8562306a36Sopenharmony_ci/* Eeprom & Phy Control Reg */
8662306a36Sopenharmony_ci#define	SR_EPCR		0x0B
8762306a36Sopenharmony_ci#define		EPCR_ERRE		(1 << 0)
8862306a36Sopenharmony_ci#define		EPCR_ERPRW		(1 << 1)
8962306a36Sopenharmony_ci#define		EPCR_ERPRR		(1 << 2)
9062306a36Sopenharmony_ci#define		EPCR_EPOS		(1 << 3)
9162306a36Sopenharmony_ci#define		EPCR_WEP		(1 << 4)
9262306a36Sopenharmony_ci/* Eeprom & Phy Address Reg */
9362306a36Sopenharmony_ci#define	SR_EPAR		0x0C
9462306a36Sopenharmony_ci#define		EPAR_EROA		(0x3F << 0)
9562306a36Sopenharmony_ci#define		EPAR_PHY_ADR_MASK	(0x03 << 6)
9662306a36Sopenharmony_ci#define		EPAR_PHY_ADR		(0x01 << 6)
9762306a36Sopenharmony_ci/* Eeprom &	Phy Data Reg */
9862306a36Sopenharmony_ci#define	SR_EPDR		0x0D	/* 0x0D ~ 0x0E for Data Reg Low & High */
9962306a36Sopenharmony_ci/* Wakeup Control Reg */
10062306a36Sopenharmony_ci#define	SR_WCR			0x0F
10162306a36Sopenharmony_ci#define		WCR_MAGICST		(1 << 0)
10262306a36Sopenharmony_ci#define		WCR_LINKST		(1 << 2)
10362306a36Sopenharmony_ci#define		WCR_MAGICEN		(1 << 3)
10462306a36Sopenharmony_ci#define		WCR_LINKEN		(1 << 5)
10562306a36Sopenharmony_ci/* Physical Address Reg */
10662306a36Sopenharmony_ci#define	SR_PAR			0x10	/* 0x10 ~ 0x15 6 bytes for PAR */
10762306a36Sopenharmony_ci/* Multicast Address Reg */
10862306a36Sopenharmony_ci#define	SR_MAR			0x16	/* 0x16 ~ 0x1D 8 bytes for MAR */
10962306a36Sopenharmony_ci/* 0x1e unused */
11062306a36Sopenharmony_ci/* Phy Reset Reg */
11162306a36Sopenharmony_ci#define	SR_PRR			0x1F
11262306a36Sopenharmony_ci#define		PRR_PHY_RST		(1 << 0)
11362306a36Sopenharmony_ci/* Tx sdram Write Pointer Address Low */
11462306a36Sopenharmony_ci#define	SR_TWPAL		0x20
11562306a36Sopenharmony_ci/* Tx sdram Write Pointer Address High */
11662306a36Sopenharmony_ci#define	SR_TWPAH		0x21
11762306a36Sopenharmony_ci/* Tx sdram Read Pointer Address Low */
11862306a36Sopenharmony_ci#define	SR_TRPAL		0x22
11962306a36Sopenharmony_ci/* Tx sdram Read Pointer Address High */
12062306a36Sopenharmony_ci#define	SR_TRPAH		0x23
12162306a36Sopenharmony_ci/* Rx sdram Write Pointer Address Low */
12262306a36Sopenharmony_ci#define	SR_RWPAL		0x24
12362306a36Sopenharmony_ci/* Rx sdram Write Pointer Address High */
12462306a36Sopenharmony_ci#define	SR_RWPAH		0x25
12562306a36Sopenharmony_ci/* Rx sdram Read Pointer Address Low */
12662306a36Sopenharmony_ci#define	SR_RRPAL		0x26
12762306a36Sopenharmony_ci/* Rx sdram Read Pointer Address High */
12862306a36Sopenharmony_ci#define	SR_RRPAH		0x27
12962306a36Sopenharmony_ci/* Vendor ID register */
13062306a36Sopenharmony_ci#define	SR_VID			0x28	/* 0x28 ~ 0x29 2 bytes for VID */
13162306a36Sopenharmony_ci/* Product ID register */
13262306a36Sopenharmony_ci#define	SR_PID			0x2A	/* 0x2A ~ 0x2B 2 bytes for PID */
13362306a36Sopenharmony_ci/* CHIP Revision register */
13462306a36Sopenharmony_ci#define	SR_CHIPR		0x2C
13562306a36Sopenharmony_ci/* 0x2D --> 0xEF unused */
13662306a36Sopenharmony_ci/* USB Device Address */
13762306a36Sopenharmony_ci#define	SR_USBDA		0xF0
13862306a36Sopenharmony_ci#define		USBDA_USBFA		(0x7F << 0)
13962306a36Sopenharmony_ci/* RX packet Counter Reg */
14062306a36Sopenharmony_ci#define	SR_RXC			0xF1
14162306a36Sopenharmony_ci/* Tx packet Counter & USB Status Reg */
14262306a36Sopenharmony_ci#define	SR_TXC_USBS		0xF2
14362306a36Sopenharmony_ci#define		TXC_USBS_TXC0		(1 << 0)
14462306a36Sopenharmony_ci#define		TXC_USBS_TXC1		(1 << 1)
14562306a36Sopenharmony_ci#define		TXC_USBS_TXC2		(1 << 2)
14662306a36Sopenharmony_ci#define		TXC_USBS_EP1RDY		(1 << 5)
14762306a36Sopenharmony_ci#define		TXC_USBS_SUSFLAG	(1 << 6)
14862306a36Sopenharmony_ci#define		TXC_USBS_RXFAULT	(1 << 7)
14962306a36Sopenharmony_ci/* USB Control register */
15062306a36Sopenharmony_ci#define	SR_USBC			0xF4
15162306a36Sopenharmony_ci#define		USBC_EP3NAK		(1 << 4)
15262306a36Sopenharmony_ci#define		USBC_EP3ACK		(1 << 5)
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci/* Register access commands and flags */
15562306a36Sopenharmony_ci#define	SR_RD_REGS		0x00
15662306a36Sopenharmony_ci#define	SR_WR_REGS		0x01
15762306a36Sopenharmony_ci#define	SR_WR_REG		0x03
15862306a36Sopenharmony_ci#define	SR_REQ_RD_REG	(USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
15962306a36Sopenharmony_ci#define	SR_REQ_WR_REG	(USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci/* parameters */
16262306a36Sopenharmony_ci#define	SR_SHARE_TIMEOUT	1000
16362306a36Sopenharmony_ci#define	SR_EEPROM_LEN		256
16462306a36Sopenharmony_ci#define	SR_MCAST_SIZE		8
16562306a36Sopenharmony_ci#define	SR_MCAST_ADDR_FLAG	0x80
16662306a36Sopenharmony_ci#define	SR_MCAST_MAX		64
16762306a36Sopenharmony_ci#define	SR_TX_OVERHEAD		2	/* 2bytes header */
16862306a36Sopenharmony_ci#define	SR_RX_OVERHEAD		7	/* 3bytes header + 4crc tail */
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci#endif	/* _SR9700_H */
171