162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * PLX NET2272 high/full speed USB device controller
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2005-2006 PLX Technology, Inc.
662306a36Sopenharmony_ci * Copyright (C) 2006-2011 Analog Devices, Inc.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef __NET2272_H__
1062306a36Sopenharmony_ci#define __NET2272_H__
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci/* Main Registers */
1362306a36Sopenharmony_ci#define REGADDRPTR			0x00
1462306a36Sopenharmony_ci#define REGDATA				0x01
1562306a36Sopenharmony_ci#define IRQSTAT0			0x02
1662306a36Sopenharmony_ci#define 	ENDPOINT_0_INTERRUPT			0
1762306a36Sopenharmony_ci#define 	ENDPOINT_A_INTERRUPT			1
1862306a36Sopenharmony_ci#define 	ENDPOINT_B_INTERRUPT			2
1962306a36Sopenharmony_ci#define 	ENDPOINT_C_INTERRUPT			3
2062306a36Sopenharmony_ci#define 	VIRTUALIZED_ENDPOINT_INTERRUPT		4
2162306a36Sopenharmony_ci#define 	SETUP_PACKET_INTERRUPT			5
2262306a36Sopenharmony_ci#define 	DMA_DONE_INTERRUPT			6
2362306a36Sopenharmony_ci#define 	SOF_INTERRUPT				7
2462306a36Sopenharmony_ci#define IRQSTAT1			0x03
2562306a36Sopenharmony_ci#define 	CONTROL_STATUS_INTERRUPT		1
2662306a36Sopenharmony_ci#define 	VBUS_INTERRUPT				2
2762306a36Sopenharmony_ci#define 	SUSPEND_REQUEST_INTERRUPT		3
2862306a36Sopenharmony_ci#define 	SUSPEND_REQUEST_CHANGE_INTERRUPT	4
2962306a36Sopenharmony_ci#define 	RESUME_INTERRUPT			5
3062306a36Sopenharmony_ci#define 	ROOT_PORT_RESET_INTERRUPT		6
3162306a36Sopenharmony_ci#define 	RESET_STATUS				7
3262306a36Sopenharmony_ci#define PAGESEL				0x04
3362306a36Sopenharmony_ci#define DMAREQ				0x1c
3462306a36Sopenharmony_ci#define 	DMA_ENDPOINT_SELECT			0
3562306a36Sopenharmony_ci#define 	DREQ_POLARITY				1
3662306a36Sopenharmony_ci#define 	DACK_POLARITY				2
3762306a36Sopenharmony_ci#define 	EOT_POLARITY				3
3862306a36Sopenharmony_ci#define 	DMA_CONTROL_DACK			4
3962306a36Sopenharmony_ci#define 	DMA_REQUEST_ENABLE			5
4062306a36Sopenharmony_ci#define 	DMA_REQUEST				6
4162306a36Sopenharmony_ci#define 	DMA_BUFFER_VALID			7
4262306a36Sopenharmony_ci#define SCRATCH				0x1d
4362306a36Sopenharmony_ci#define IRQENB0				0x20
4462306a36Sopenharmony_ci#define 	ENDPOINT_0_INTERRUPT_ENABLE		0
4562306a36Sopenharmony_ci#define 	ENDPOINT_A_INTERRUPT_ENABLE		1
4662306a36Sopenharmony_ci#define 	ENDPOINT_B_INTERRUPT_ENABLE		2
4762306a36Sopenharmony_ci#define 	ENDPOINT_C_INTERRUPT_ENABLE		3
4862306a36Sopenharmony_ci#define 	VIRTUALIZED_ENDPOINT_INTERRUPT_ENABLE	4
4962306a36Sopenharmony_ci#define 	SETUP_PACKET_INTERRUPT_ENABLE		5
5062306a36Sopenharmony_ci#define 	DMA_DONE_INTERRUPT_ENABLE		6
5162306a36Sopenharmony_ci#define 	SOF_INTERRUPT_ENABLE			7
5262306a36Sopenharmony_ci#define IRQENB1				0x21
5362306a36Sopenharmony_ci#define 	VBUS_INTERRUPT_ENABLE			2
5462306a36Sopenharmony_ci#define 	SUSPEND_REQUEST_INTERRUPT_ENABLE	3
5562306a36Sopenharmony_ci#define 	SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE	4
5662306a36Sopenharmony_ci#define 	RESUME_INTERRUPT_ENABLE			5
5762306a36Sopenharmony_ci#define 	ROOT_PORT_RESET_INTERRUPT_ENABLE	6
5862306a36Sopenharmony_ci#define LOCCTL				0x22
5962306a36Sopenharmony_ci#define 	DATA_WIDTH				0
6062306a36Sopenharmony_ci#define 	LOCAL_CLOCK_OUTPUT			1
6162306a36Sopenharmony_ci#define 		LOCAL_CLOCK_OUTPUT_OFF			0
6262306a36Sopenharmony_ci#define 		LOCAL_CLOCK_OUTPUT_3_75MHZ		1
6362306a36Sopenharmony_ci#define 		LOCAL_CLOCK_OUTPUT_7_5MHZ		2
6462306a36Sopenharmony_ci#define 		LOCAL_CLOCK_OUTPUT_15MHZ		3
6562306a36Sopenharmony_ci#define 		LOCAL_CLOCK_OUTPUT_30MHZ		4
6662306a36Sopenharmony_ci#define 		LOCAL_CLOCK_OUTPUT_60MHZ		5
6762306a36Sopenharmony_ci#define 	DMA_SPLIT_BUS_MODE			4
6862306a36Sopenharmony_ci#define 	BYTE_SWAP				5
6962306a36Sopenharmony_ci#define 	BUFFER_CONFIGURATION			6
7062306a36Sopenharmony_ci#define 		BUFFER_CONFIGURATION_EPA512_EPB512	0
7162306a36Sopenharmony_ci#define 		BUFFER_CONFIGURATION_EPA1024_EPB512	1
7262306a36Sopenharmony_ci#define 		BUFFER_CONFIGURATION_EPA1024_EPB1024	2
7362306a36Sopenharmony_ci#define 		BUFFER_CONFIGURATION_EPA1024DB		3
7462306a36Sopenharmony_ci#define CHIPREV_LEGACY			0x23
7562306a36Sopenharmony_ci#define 		NET2270_LEGACY_REV			0x40
7662306a36Sopenharmony_ci#define LOCCTL1				0x24
7762306a36Sopenharmony_ci#define 	DMA_MODE				0
7862306a36Sopenharmony_ci#define 		SLOW_DREQ				0
7962306a36Sopenharmony_ci#define 		FAST_DREQ				1
8062306a36Sopenharmony_ci#define 		BURST_MODE				2
8162306a36Sopenharmony_ci#define 	DMA_DACK_ENABLE				2
8262306a36Sopenharmony_ci#define CHIPREV_2272			0x25
8362306a36Sopenharmony_ci#define 		CHIPREV_NET2272_R1			0x10
8462306a36Sopenharmony_ci#define 		CHIPREV_NET2272_R1A			0x11
8562306a36Sopenharmony_ci/* USB Registers */
8662306a36Sopenharmony_ci#define USBCTL0				0x18
8762306a36Sopenharmony_ci#define 	IO_WAKEUP_ENABLE			1
8862306a36Sopenharmony_ci#define 	USB_DETECT_ENABLE			3
8962306a36Sopenharmony_ci#define 	USB_ROOT_PORT_WAKEUP_ENABLE		5
9062306a36Sopenharmony_ci#define USBCTL1				0x19
9162306a36Sopenharmony_ci#define 	VBUS_PIN				0
9262306a36Sopenharmony_ci#define 		USB_FULL_SPEED				1
9362306a36Sopenharmony_ci#define 		USB_HIGH_SPEED				2
9462306a36Sopenharmony_ci#define 	GENERATE_RESUME				3
9562306a36Sopenharmony_ci#define 	VIRTUAL_ENDPOINT_ENABLE			4
9662306a36Sopenharmony_ci#define FRAME0				0x1a
9762306a36Sopenharmony_ci#define FRAME1				0x1b
9862306a36Sopenharmony_ci#define OURADDR				0x30
9962306a36Sopenharmony_ci#define 	FORCE_IMMEDIATE				7
10062306a36Sopenharmony_ci#define USBDIAG				0x31
10162306a36Sopenharmony_ci#define 	FORCE_TRANSMIT_CRC_ERROR		0
10262306a36Sopenharmony_ci#define 	PREVENT_TRANSMIT_BIT_STUFF		1
10362306a36Sopenharmony_ci#define 	FORCE_RECEIVE_ERROR			2
10462306a36Sopenharmony_ci#define 	FAST_TIMES				4
10562306a36Sopenharmony_ci#define USBTEST				0x32
10662306a36Sopenharmony_ci#define 	TEST_MODE_SELECT			0
10762306a36Sopenharmony_ci#define 		NORMAL_OPERATION			0
10862306a36Sopenharmony_ci#define XCVRDIAG			0x33
10962306a36Sopenharmony_ci#define 	FORCE_FULL_SPEED			2
11062306a36Sopenharmony_ci#define 	FORCE_HIGH_SPEED			3
11162306a36Sopenharmony_ci#define 	OPMODE					4
11262306a36Sopenharmony_ci#define 		NORMAL_OPERATION			0
11362306a36Sopenharmony_ci#define 		NON_DRIVING				1
11462306a36Sopenharmony_ci#define 		DISABLE_BITSTUFF_AND_NRZI_ENCODE	2
11562306a36Sopenharmony_ci#define 	LINESTATE				6
11662306a36Sopenharmony_ci#define 		SE0_STATE				0
11762306a36Sopenharmony_ci#define 		J_STATE					1
11862306a36Sopenharmony_ci#define 		K_STATE					2
11962306a36Sopenharmony_ci#define 		SE1_STATE				3
12062306a36Sopenharmony_ci#define VIRTOUT0			0x34
12162306a36Sopenharmony_ci#define VIRTOUT1			0x35
12262306a36Sopenharmony_ci#define VIRTIN0				0x36
12362306a36Sopenharmony_ci#define VIRTIN1				0x37
12462306a36Sopenharmony_ci#define SETUP0				0x40
12562306a36Sopenharmony_ci#define SETUP1				0x41
12662306a36Sopenharmony_ci#define SETUP2				0x42
12762306a36Sopenharmony_ci#define SETUP3				0x43
12862306a36Sopenharmony_ci#define SETUP4				0x44
12962306a36Sopenharmony_ci#define SETUP5				0x45
13062306a36Sopenharmony_ci#define SETUP6				0x46
13162306a36Sopenharmony_ci#define SETUP7				0x47
13262306a36Sopenharmony_ci/* Endpoint Registers (Paged via PAGESEL) */
13362306a36Sopenharmony_ci#define EP_DATA				0x05
13462306a36Sopenharmony_ci#define EP_STAT0			0x06
13562306a36Sopenharmony_ci#define 	DATA_IN_TOKEN_INTERRUPT			0
13662306a36Sopenharmony_ci#define 	DATA_OUT_TOKEN_INTERRUPT		1
13762306a36Sopenharmony_ci#define 	DATA_PACKET_TRANSMITTED_INTERRUPT	2
13862306a36Sopenharmony_ci#define 	DATA_PACKET_RECEIVED_INTERRUPT		3
13962306a36Sopenharmony_ci#define 	SHORT_PACKET_TRANSFERRED_INTERRUPT	4
14062306a36Sopenharmony_ci#define 	NAK_OUT_PACKETS				5
14162306a36Sopenharmony_ci#define 	BUFFER_EMPTY				6
14262306a36Sopenharmony_ci#define 	BUFFER_FULL				7
14362306a36Sopenharmony_ci#define EP_STAT1			0x07
14462306a36Sopenharmony_ci#define 	TIMEOUT					0
14562306a36Sopenharmony_ci#define 	USB_OUT_ACK_SENT			1
14662306a36Sopenharmony_ci#define 	USB_OUT_NAK_SENT			2
14762306a36Sopenharmony_ci#define 	USB_IN_ACK_RCVD				3
14862306a36Sopenharmony_ci#define 	USB_IN_NAK_SENT				4
14962306a36Sopenharmony_ci#define 	USB_STALL_SENT				5
15062306a36Sopenharmony_ci#define 	LOCAL_OUT_ZLP				6
15162306a36Sopenharmony_ci#define 	BUFFER_FLUSH				7
15262306a36Sopenharmony_ci#define EP_TRANSFER0			0x08
15362306a36Sopenharmony_ci#define EP_TRANSFER1			0x09
15462306a36Sopenharmony_ci#define EP_TRANSFER2			0x0a
15562306a36Sopenharmony_ci#define EP_IRQENB			0x0b
15662306a36Sopenharmony_ci#define 	DATA_IN_TOKEN_INTERRUPT_ENABLE		0
15762306a36Sopenharmony_ci#define 	DATA_OUT_TOKEN_INTERRUPT_ENABLE		1
15862306a36Sopenharmony_ci#define 	DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE	2
15962306a36Sopenharmony_ci#define 	DATA_PACKET_RECEIVED_INTERRUPT_ENABLE	3
16062306a36Sopenharmony_ci#define 	SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE	4
16162306a36Sopenharmony_ci#define EP_AVAIL0			0x0c
16262306a36Sopenharmony_ci#define EP_AVAIL1			0x0d
16362306a36Sopenharmony_ci#define EP_RSPCLR			0x0e
16462306a36Sopenharmony_ci#define EP_RSPSET			0x0f
16562306a36Sopenharmony_ci#define 	ENDPOINT_HALT				0
16662306a36Sopenharmony_ci#define 	ENDPOINT_TOGGLE				1
16762306a36Sopenharmony_ci#define 	NAK_OUT_PACKETS_MODE			2
16862306a36Sopenharmony_ci#define 	CONTROL_STATUS_PHASE_HANDSHAKE		3
16962306a36Sopenharmony_ci#define 	INTERRUPT_MODE				4
17062306a36Sopenharmony_ci#define 	AUTOVALIDATE				5
17162306a36Sopenharmony_ci#define 	HIDE_STATUS_PHASE			6
17262306a36Sopenharmony_ci#define 	ALT_NAK_OUT_PACKETS			7
17362306a36Sopenharmony_ci#define EP_MAXPKT0			0x28
17462306a36Sopenharmony_ci#define EP_MAXPKT1			0x29
17562306a36Sopenharmony_ci#define 	ADDITIONAL_TRANSACTION_OPPORTUNITIES	3
17662306a36Sopenharmony_ci#define 		NONE_ADDITIONAL_TRANSACTION		0
17762306a36Sopenharmony_ci#define 		ONE_ADDITIONAL_TRANSACTION		1
17862306a36Sopenharmony_ci#define 		TWO_ADDITIONAL_TRANSACTION		2
17962306a36Sopenharmony_ci#define EP_CFG				0x2a
18062306a36Sopenharmony_ci#define 	ENDPOINT_NUMBER				0
18162306a36Sopenharmony_ci#define 	ENDPOINT_DIRECTION			4
18262306a36Sopenharmony_ci#define 	ENDPOINT_TYPE				5
18362306a36Sopenharmony_ci#define 	ENDPOINT_ENABLE				7
18462306a36Sopenharmony_ci#define EP_HBW				0x2b
18562306a36Sopenharmony_ci#define 	HIGH_BANDWIDTH_OUT_TRANSACTION_PID	0
18662306a36Sopenharmony_ci#define 		DATA0_PID				0
18762306a36Sopenharmony_ci#define 		DATA1_PID				1
18862306a36Sopenharmony_ci#define 		DATA2_PID				2
18962306a36Sopenharmony_ci#define 		MDATA_PID				3
19062306a36Sopenharmony_ci#define EP_BUFF_STATES			0x2c
19162306a36Sopenharmony_ci#define 	BUFFER_A_STATE				0
19262306a36Sopenharmony_ci#define 	BUFFER_B_STATE				2
19362306a36Sopenharmony_ci#define 		BUFF_FREE				0
19462306a36Sopenharmony_ci#define 		BUFF_VALID				1
19562306a36Sopenharmony_ci#define 		BUFF_LCL				2
19662306a36Sopenharmony_ci#define 		BUFF_USB				3
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci/*---------------------------------------------------------------------------*/
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci#define PCI_DEVICE_ID_RDK1	0x9054
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci/* PCI-RDK EPLD Registers */
20362306a36Sopenharmony_ci#define RDK_EPLD_IO_REGISTER1		0x00000000
20462306a36Sopenharmony_ci#define 	RDK_EPLD_USB_RESET				0
20562306a36Sopenharmony_ci#define 	RDK_EPLD_USB_POWERDOWN				1
20662306a36Sopenharmony_ci#define 	RDK_EPLD_USB_WAKEUP				2
20762306a36Sopenharmony_ci#define 	RDK_EPLD_USB_EOT				3
20862306a36Sopenharmony_ci#define 	RDK_EPLD_DPPULL					4
20962306a36Sopenharmony_ci#define RDK_EPLD_IO_REGISTER2		0x00000004
21062306a36Sopenharmony_ci#define 	RDK_EPLD_BUSWIDTH				0
21162306a36Sopenharmony_ci#define 	RDK_EPLD_USER					2
21262306a36Sopenharmony_ci#define 	RDK_EPLD_RESET_INTERRUPT_ENABLE			3
21362306a36Sopenharmony_ci#define 	RDK_EPLD_DMA_TIMEOUT_ENABLE			4
21462306a36Sopenharmony_ci#define RDK_EPLD_STATUS_REGISTER	0x00000008
21562306a36Sopenharmony_ci#define 	RDK_EPLD_USB_LRESET				0
21662306a36Sopenharmony_ci#define RDK_EPLD_REVISION_REGISTER	0x0000000c
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci/* PCI-RDK PLX 9054 Registers */
21962306a36Sopenharmony_ci#define INTCSR				0x68
22062306a36Sopenharmony_ci#define 	PCI_INTERRUPT_ENABLE				8
22162306a36Sopenharmony_ci#define 	LOCAL_INTERRUPT_INPUT_ENABLE			11
22262306a36Sopenharmony_ci#define 	LOCAL_INPUT_INTERRUPT_ACTIVE			15
22362306a36Sopenharmony_ci#define 	LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE		18
22462306a36Sopenharmony_ci#define 	LOCAL_DMA_CHANNEL_1_INTERRUPT_ENABLE		19
22562306a36Sopenharmony_ci#define 	DMA_CHANNEL_0_INTERRUPT_ACTIVE			21
22662306a36Sopenharmony_ci#define 	DMA_CHANNEL_1_INTERRUPT_ACTIVE			22
22762306a36Sopenharmony_ci#define CNTRL				0x6C
22862306a36Sopenharmony_ci#define 	RELOAD_CONFIGURATION_REGISTERS			29
22962306a36Sopenharmony_ci#define 	PCI_ADAPTER_SOFTWARE_RESET			30
23062306a36Sopenharmony_ci#define DMAMODE0			0x80
23162306a36Sopenharmony_ci#define 	LOCAL_BUS_WIDTH					0
23262306a36Sopenharmony_ci#define 	INTERNAL_WAIT_STATES				2
23362306a36Sopenharmony_ci#define 	TA_READY_INPUT_ENABLE				6
23462306a36Sopenharmony_ci#define 	LOCAL_BURST_ENABLE				8
23562306a36Sopenharmony_ci#define 	SCATTER_GATHER_MODE				9
23662306a36Sopenharmony_ci#define 	DONE_INTERRUPT_ENABLE				10
23762306a36Sopenharmony_ci#define 	LOCAL_ADDRESSING_MODE				11
23862306a36Sopenharmony_ci#define 	DEMAND_MODE					12
23962306a36Sopenharmony_ci#define 	DMA_EOT_ENABLE					14
24062306a36Sopenharmony_ci#define 	FAST_SLOW_TERMINATE_MODE_SELECT			15
24162306a36Sopenharmony_ci#define 	DMA_CHANNEL_INTERRUPT_SELECT			17
24262306a36Sopenharmony_ci#define DMAPADR0			0x84
24362306a36Sopenharmony_ci#define DMALADR0			0x88
24462306a36Sopenharmony_ci#define DMASIZ0				0x8c
24562306a36Sopenharmony_ci#define DMADPR0				0x90
24662306a36Sopenharmony_ci#define 	DESCRIPTOR_LOCATION				0
24762306a36Sopenharmony_ci#define 	END_OF_CHAIN					1
24862306a36Sopenharmony_ci#define 	INTERRUPT_AFTER_TERMINAL_COUNT			2
24962306a36Sopenharmony_ci#define 	DIRECTION_OF_TRANSFER				3
25062306a36Sopenharmony_ci#define DMACSR0				0xa8
25162306a36Sopenharmony_ci#define 	CHANNEL_ENABLE					0
25262306a36Sopenharmony_ci#define 	CHANNEL_START					1
25362306a36Sopenharmony_ci#define 	CHANNEL_ABORT					2
25462306a36Sopenharmony_ci#define 	CHANNEL_CLEAR_INTERRUPT				3
25562306a36Sopenharmony_ci#define 	CHANNEL_DONE					4
25662306a36Sopenharmony_ci#define DMATHR				0xb0
25762306a36Sopenharmony_ci#define LBRD1				0xf8
25862306a36Sopenharmony_ci#define 	MEMORY_SPACE_LOCAL_BUS_WIDTH			0
25962306a36Sopenharmony_ci#define 	W8_BIT						0
26062306a36Sopenharmony_ci#define 	W16_BIT						1
26162306a36Sopenharmony_ci
26262306a36Sopenharmony_ci/* Special OR'ing of INTCSR bits */
26362306a36Sopenharmony_ci#define LOCAL_INTERRUPT_TEST \
26462306a36Sopenharmony_ci	((1 << LOCAL_INPUT_INTERRUPT_ACTIVE) | \
26562306a36Sopenharmony_ci	 (1 << LOCAL_INTERRUPT_INPUT_ENABLE))
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci#define DMA_CHANNEL_0_TEST \
26862306a36Sopenharmony_ci	((1 << DMA_CHANNEL_0_INTERRUPT_ACTIVE) | \
26962306a36Sopenharmony_ci	 (1 << LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE))
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci#define DMA_CHANNEL_1_TEST \
27262306a36Sopenharmony_ci	((1 << DMA_CHANNEL_1_INTERRUPT_ACTIVE) | \
27362306a36Sopenharmony_ci	 (1 << LOCAL_DMA_CHANNEL_1_INTERRUPT_ENABLE))
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci/* EPLD Registers */
27662306a36Sopenharmony_ci#define RDK_EPLD_IO_REGISTER1			0x00000000
27762306a36Sopenharmony_ci#define 	RDK_EPLD_USB_RESET			0
27862306a36Sopenharmony_ci#define 	RDK_EPLD_USB_POWERDOWN			1
27962306a36Sopenharmony_ci#define 	RDK_EPLD_USB_WAKEUP			2
28062306a36Sopenharmony_ci#define 	RDK_EPLD_USB_EOT			3
28162306a36Sopenharmony_ci#define 	RDK_EPLD_DPPULL				4
28262306a36Sopenharmony_ci#define RDK_EPLD_IO_REGISTER2			0x00000004
28362306a36Sopenharmony_ci#define 	RDK_EPLD_BUSWIDTH			0
28462306a36Sopenharmony_ci#define 	RDK_EPLD_USER				2
28562306a36Sopenharmony_ci#define 	RDK_EPLD_RESET_INTERRUPT_ENABLE		3
28662306a36Sopenharmony_ci#define 	RDK_EPLD_DMA_TIMEOUT_ENABLE		4
28762306a36Sopenharmony_ci#define RDK_EPLD_STATUS_REGISTER		0x00000008
28862306a36Sopenharmony_ci#define RDK_EPLD_USB_LRESET				0
28962306a36Sopenharmony_ci#define RDK_EPLD_REVISION_REGISTER		0x0000000c
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci#define EPLD_IO_CONTROL_REGISTER		0x400
29262306a36Sopenharmony_ci#define 	NET2272_RESET				0
29362306a36Sopenharmony_ci#define 	BUSWIDTH				1
29462306a36Sopenharmony_ci#define 	MPX_MODE				3
29562306a36Sopenharmony_ci#define 	USER					4
29662306a36Sopenharmony_ci#define 	DMA_TIMEOUT_ENABLE			5
29762306a36Sopenharmony_ci#define 	DMA_CTL_DACK				6
29862306a36Sopenharmony_ci#define 	EPLD_DMA_ENABLE				7
29962306a36Sopenharmony_ci#define EPLD_DMA_CONTROL_REGISTER		0x800
30062306a36Sopenharmony_ci#define 	SPLIT_DMA_MODE				0
30162306a36Sopenharmony_ci#define 	SPLIT_DMA_DIRECTION			1
30262306a36Sopenharmony_ci#define 	SPLIT_DMA_ENABLE			2
30362306a36Sopenharmony_ci#define 	SPLIT_DMA_INTERRUPT_ENABLE		3
30462306a36Sopenharmony_ci#define 	SPLIT_DMA_INTERRUPT			4
30562306a36Sopenharmony_ci#define 	EPLD_DMA_MODE				5
30662306a36Sopenharmony_ci#define 	EPLD_DMA_CONTROLLER_ENABLE		7
30762306a36Sopenharmony_ci#define SPLIT_DMA_ADDRESS_LOW			0xc00
30862306a36Sopenharmony_ci#define SPLIT_DMA_ADDRESS_HIGH			0x1000
30962306a36Sopenharmony_ci#define SPLIT_DMA_BYTE_COUNT_LOW		0x1400
31062306a36Sopenharmony_ci#define SPLIT_DMA_BYTE_COUNT_HIGH		0x1800
31162306a36Sopenharmony_ci#define EPLD_REVISION_REGISTER			0x1c00
31262306a36Sopenharmony_ci#define SPLIT_DMA_RAM				0x4000
31362306a36Sopenharmony_ci#define DMA_RAM_SIZE				0x1000
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci/*---------------------------------------------------------------------------*/
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci#define PCI_DEVICE_ID_RDK2	0x3272
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci/* PCI-RDK version 2 registers */
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci/* Main Control Registers */
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ci#define RDK2_IRQENB			0x00
32462306a36Sopenharmony_ci#define RDK2_IRQSTAT			0x04
32562306a36Sopenharmony_ci#define 	PB7				23
32662306a36Sopenharmony_ci#define 	PB6				22
32762306a36Sopenharmony_ci#define 	PB5				21
32862306a36Sopenharmony_ci#define 	PB4				20
32962306a36Sopenharmony_ci#define 	PB3				19
33062306a36Sopenharmony_ci#define 	PB2				18
33162306a36Sopenharmony_ci#define 	PB1				17
33262306a36Sopenharmony_ci#define 	PB0				16
33362306a36Sopenharmony_ci#define 	GP3				23
33462306a36Sopenharmony_ci#define 	GP2				23
33562306a36Sopenharmony_ci#define 	GP1				23
33662306a36Sopenharmony_ci#define 	GP0				23
33762306a36Sopenharmony_ci#define 	DMA_RETRY_ABORT			6
33862306a36Sopenharmony_ci#define 	DMA_PAUSE_DONE			5
33962306a36Sopenharmony_ci#define 	DMA_ABORT_DONE			4
34062306a36Sopenharmony_ci#define 	DMA_OUT_FIFO_TRANSFER_DONE	3
34162306a36Sopenharmony_ci#define 	DMA_LOCAL_DONE			2
34262306a36Sopenharmony_ci#define 	DMA_PCI_DONE			1
34362306a36Sopenharmony_ci#define 	NET2272_PCI_IRQ			0
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci#define RDK2_LOCCTLRDK			0x08
34662306a36Sopenharmony_ci#define 	CHIP_RESET			3
34762306a36Sopenharmony_ci#define 	SPLIT_DMA			2
34862306a36Sopenharmony_ci#define 	MULTIPLEX_MODE			1
34962306a36Sopenharmony_ci#define 	BUS_WIDTH			0
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci#define RDK2_GPIOCTL			0x10
35262306a36Sopenharmony_ci#define 	GP3_OUT_ENABLE					7
35362306a36Sopenharmony_ci#define 	GP2_OUT_ENABLE					6
35462306a36Sopenharmony_ci#define 	GP1_OUT_ENABLE					5
35562306a36Sopenharmony_ci#define 	GP0_OUT_ENABLE					4
35662306a36Sopenharmony_ci#define 	GP3_DATA					3
35762306a36Sopenharmony_ci#define 	GP2_DATA					2
35862306a36Sopenharmony_ci#define 	GP1_DATA					1
35962306a36Sopenharmony_ci#define 	GP0_DATA					0
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ci#define RDK2_LEDSW			0x14
36262306a36Sopenharmony_ci#define 	LED3				27
36362306a36Sopenharmony_ci#define 	LED2				26
36462306a36Sopenharmony_ci#define 	LED1				25
36562306a36Sopenharmony_ci#define 	LED0				24
36662306a36Sopenharmony_ci#define 	PBUTTON				16
36762306a36Sopenharmony_ci#define 	DIPSW				0
36862306a36Sopenharmony_ci
36962306a36Sopenharmony_ci#define RDK2_DIAG			0x18
37062306a36Sopenharmony_ci#define 	RDK2_FAST_TIMES				2
37162306a36Sopenharmony_ci#define 	FORCE_PCI_SERR				1
37262306a36Sopenharmony_ci#define 	FORCE_PCI_INT				0
37362306a36Sopenharmony_ci#define RDK2_FPGAREV			0x1C
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci/* Dma Control registers */
37662306a36Sopenharmony_ci#define RDK2_DMACTL			0x80
37762306a36Sopenharmony_ci#define 	ADDR_HOLD				24
37862306a36Sopenharmony_ci#define 	RETRY_COUNT				16	/* 23:16 */
37962306a36Sopenharmony_ci#define 	FIFO_THRESHOLD				11	/* 15:11 */
38062306a36Sopenharmony_ci#define 	MEM_WRITE_INVALIDATE			10
38162306a36Sopenharmony_ci#define 	READ_MULTIPLE				9
38262306a36Sopenharmony_ci#define 	READ_LINE				8
38362306a36Sopenharmony_ci#define 	RDK2_DMA_MODE				6	/* 7:6 */
38462306a36Sopenharmony_ci#define 	CONTROL_DACK				5
38562306a36Sopenharmony_ci#define 	EOT_ENABLE				4
38662306a36Sopenharmony_ci#define 	EOT_POLARITY				3
38762306a36Sopenharmony_ci#define 	DACK_POLARITY				2
38862306a36Sopenharmony_ci#define 	DREQ_POLARITY				1
38962306a36Sopenharmony_ci#define 	DMA_ENABLE				0
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci#define RDK2_DMASTAT			0x84
39262306a36Sopenharmony_ci#define 	GATHER_COUNT				12	/* 14:12 */
39362306a36Sopenharmony_ci#define 	FIFO_COUNT				6	/* 11:6 */
39462306a36Sopenharmony_ci#define 	FIFO_FLUSH				5
39562306a36Sopenharmony_ci#define 	FIFO_TRANSFER				4
39662306a36Sopenharmony_ci#define 	PAUSE_DONE				3
39762306a36Sopenharmony_ci#define 	ABORT_DONE				2
39862306a36Sopenharmony_ci#define 	DMA_ABORT				1
39962306a36Sopenharmony_ci#define 	DMA_START				0
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_ci#define RDK2_DMAPCICOUNT		0x88
40262306a36Sopenharmony_ci#define 	DMA_DIRECTION				31
40362306a36Sopenharmony_ci#define 	DMA_PCI_BYTE_COUNT			0	/* 0:23 */
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_ci#define RDK2_DMALOCCOUNT		0x8C	/* 0:23 dma local byte count */
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_ci#define RDK2_DMAADDR			0x90	/* 2:31 PCI bus starting address */
40862306a36Sopenharmony_ci
40962306a36Sopenharmony_ci/*---------------------------------------------------------------------------*/
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_ci#define REG_INDEXED_THRESHOLD	(1 << 5)
41262306a36Sopenharmony_ci
41362306a36Sopenharmony_ci/* DRIVER DATA STRUCTURES and UTILITIES */
41462306a36Sopenharmony_cistruct net2272_ep {
41562306a36Sopenharmony_ci	struct usb_ep ep;
41662306a36Sopenharmony_ci	struct net2272 *dev;
41762306a36Sopenharmony_ci	unsigned long irqs;
41862306a36Sopenharmony_ci
41962306a36Sopenharmony_ci	/* analogous to a host-side qh */
42062306a36Sopenharmony_ci	struct list_head queue;
42162306a36Sopenharmony_ci	const struct usb_endpoint_descriptor *desc;
42262306a36Sopenharmony_ci	unsigned num:8,
42362306a36Sopenharmony_ci	         fifo_size:12,
42462306a36Sopenharmony_ci	         stopped:1,
42562306a36Sopenharmony_ci	         wedged:1,
42662306a36Sopenharmony_ci	         is_in:1,
42762306a36Sopenharmony_ci	         is_iso:1,
42862306a36Sopenharmony_ci	         dma:1,
42962306a36Sopenharmony_ci	         not_empty:1;
43062306a36Sopenharmony_ci};
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_cistruct net2272 {
43362306a36Sopenharmony_ci	/* each device provides one gadget, several endpoints */
43462306a36Sopenharmony_ci	struct usb_gadget gadget;
43562306a36Sopenharmony_ci	struct device *dev;
43662306a36Sopenharmony_ci	unsigned short dev_id;
43762306a36Sopenharmony_ci
43862306a36Sopenharmony_ci	spinlock_t lock;
43962306a36Sopenharmony_ci	struct net2272_ep ep[4];
44062306a36Sopenharmony_ci	struct usb_gadget_driver *driver;
44162306a36Sopenharmony_ci	unsigned protocol_stall:1,
44262306a36Sopenharmony_ci	         softconnect:1,
44362306a36Sopenharmony_ci	         wakeup:1,
44462306a36Sopenharmony_ci		 added:1,
44562306a36Sopenharmony_ci		 async_callbacks:1,
44662306a36Sopenharmony_ci	         dma_eot_polarity:1,
44762306a36Sopenharmony_ci	         dma_dack_polarity:1,
44862306a36Sopenharmony_ci	         dma_dreq_polarity:1,
44962306a36Sopenharmony_ci	         dma_busy:1;
45062306a36Sopenharmony_ci	u16 chiprev;
45162306a36Sopenharmony_ci	u8 pagesel;
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci	unsigned int irq;
45462306a36Sopenharmony_ci	unsigned short fifo_mode;
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ci	unsigned int base_shift;
45762306a36Sopenharmony_ci	u16 __iomem *base_addr;
45862306a36Sopenharmony_ci	union {
45962306a36Sopenharmony_ci#ifdef CONFIG_USB_PCI
46062306a36Sopenharmony_ci		struct {
46162306a36Sopenharmony_ci			void __iomem *plx9054_base_addr;
46262306a36Sopenharmony_ci			void __iomem *epld_base_addr;
46362306a36Sopenharmony_ci		} rdk1;
46462306a36Sopenharmony_ci		struct {
46562306a36Sopenharmony_ci			/* Bar0, Bar1 is base_addr both mem-mapped */
46662306a36Sopenharmony_ci			void __iomem *fpga_base_addr;
46762306a36Sopenharmony_ci		} rdk2;
46862306a36Sopenharmony_ci#endif
46962306a36Sopenharmony_ci	};
47062306a36Sopenharmony_ci};
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_cistatic void __iomem *
47362306a36Sopenharmony_cinet2272_reg_addr(struct net2272 *dev, unsigned int reg)
47462306a36Sopenharmony_ci{
47562306a36Sopenharmony_ci	return dev->base_addr + (reg << dev->base_shift);
47662306a36Sopenharmony_ci}
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_cistatic void
47962306a36Sopenharmony_cinet2272_write(struct net2272 *dev, unsigned int reg, u8 value)
48062306a36Sopenharmony_ci{
48162306a36Sopenharmony_ci	if (reg >= REG_INDEXED_THRESHOLD) {
48262306a36Sopenharmony_ci		/*
48362306a36Sopenharmony_ci		 * Indexed register; use REGADDRPTR/REGDATA
48462306a36Sopenharmony_ci		 *  - Save and restore REGADDRPTR. This prevents REGADDRPTR from
48562306a36Sopenharmony_ci		 *    changes between other code sections, but it is time consuming.
48662306a36Sopenharmony_ci		 *  - Performance tips: either do not save and restore REGADDRPTR (if it
48762306a36Sopenharmony_ci		 *    is safe) or do save/restore operations only in critical sections.
48862306a36Sopenharmony_ci		u8 tmp = readb(dev->base_addr + REGADDRPTR);
48962306a36Sopenharmony_ci		 */
49062306a36Sopenharmony_ci		writeb((u8)reg, net2272_reg_addr(dev, REGADDRPTR));
49162306a36Sopenharmony_ci		writeb(value, net2272_reg_addr(dev, REGDATA));
49262306a36Sopenharmony_ci		/* writeb(tmp, net2272_reg_addr(dev, REGADDRPTR)); */
49362306a36Sopenharmony_ci	} else
49462306a36Sopenharmony_ci		writeb(value, net2272_reg_addr(dev, reg));
49562306a36Sopenharmony_ci}
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_cistatic u8
49862306a36Sopenharmony_cinet2272_read(struct net2272 *dev, unsigned int reg)
49962306a36Sopenharmony_ci{
50062306a36Sopenharmony_ci	u8 ret;
50162306a36Sopenharmony_ci
50262306a36Sopenharmony_ci	if (reg >= REG_INDEXED_THRESHOLD) {
50362306a36Sopenharmony_ci		/*
50462306a36Sopenharmony_ci		 * Indexed register; use REGADDRPTR/REGDATA
50562306a36Sopenharmony_ci		 *  - Save and restore REGADDRPTR. This prevents REGADDRPTR from
50662306a36Sopenharmony_ci		 *    changes between other code sections, but it is time consuming.
50762306a36Sopenharmony_ci		 *  - Performance tips: either do not save and restore REGADDRPTR (if it
50862306a36Sopenharmony_ci		 *    is safe) or do save/restore operations only in critical sections.
50962306a36Sopenharmony_ci		u8 tmp = readb(dev->base_addr + REGADDRPTR);
51062306a36Sopenharmony_ci		 */
51162306a36Sopenharmony_ci		writeb((u8)reg, net2272_reg_addr(dev, REGADDRPTR));
51262306a36Sopenharmony_ci		ret = readb(net2272_reg_addr(dev, REGDATA));
51362306a36Sopenharmony_ci		/* writeb(tmp, net2272_reg_addr(dev, REGADDRPTR)); */
51462306a36Sopenharmony_ci	} else
51562306a36Sopenharmony_ci		ret = readb(net2272_reg_addr(dev, reg));
51662306a36Sopenharmony_ci
51762306a36Sopenharmony_ci	return ret;
51862306a36Sopenharmony_ci}
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_cistatic void
52162306a36Sopenharmony_cinet2272_ep_write(struct net2272_ep *ep, unsigned int reg, u8 value)
52262306a36Sopenharmony_ci{
52362306a36Sopenharmony_ci	struct net2272 *dev = ep->dev;
52462306a36Sopenharmony_ci
52562306a36Sopenharmony_ci	if (dev->pagesel != ep->num) {
52662306a36Sopenharmony_ci		net2272_write(dev, PAGESEL, ep->num);
52762306a36Sopenharmony_ci		dev->pagesel = ep->num;
52862306a36Sopenharmony_ci	}
52962306a36Sopenharmony_ci	net2272_write(dev, reg, value);
53062306a36Sopenharmony_ci}
53162306a36Sopenharmony_ci
53262306a36Sopenharmony_cistatic u8
53362306a36Sopenharmony_cinet2272_ep_read(struct net2272_ep *ep, unsigned int reg)
53462306a36Sopenharmony_ci{
53562306a36Sopenharmony_ci	struct net2272 *dev = ep->dev;
53662306a36Sopenharmony_ci
53762306a36Sopenharmony_ci	if (dev->pagesel != ep->num) {
53862306a36Sopenharmony_ci		net2272_write(dev, PAGESEL, ep->num);
53962306a36Sopenharmony_ci		dev->pagesel = ep->num;
54062306a36Sopenharmony_ci	}
54162306a36Sopenharmony_ci	return net2272_read(dev, reg);
54262306a36Sopenharmony_ci}
54362306a36Sopenharmony_ci
54462306a36Sopenharmony_cistatic void allow_status(struct net2272_ep *ep)
54562306a36Sopenharmony_ci{
54662306a36Sopenharmony_ci	/* ep0 only */
54762306a36Sopenharmony_ci	net2272_ep_write(ep, EP_RSPCLR,
54862306a36Sopenharmony_ci		(1 << CONTROL_STATUS_PHASE_HANDSHAKE) |
54962306a36Sopenharmony_ci		(1 << ALT_NAK_OUT_PACKETS) |
55062306a36Sopenharmony_ci		(1 << NAK_OUT_PACKETS_MODE));
55162306a36Sopenharmony_ci	ep->stopped = 1;
55262306a36Sopenharmony_ci}
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_cistatic void set_halt(struct net2272_ep *ep)
55562306a36Sopenharmony_ci{
55662306a36Sopenharmony_ci	/* ep0 and bulk/intr endpoints */
55762306a36Sopenharmony_ci	net2272_ep_write(ep, EP_RSPCLR, 1 << CONTROL_STATUS_PHASE_HANDSHAKE);
55862306a36Sopenharmony_ci	net2272_ep_write(ep, EP_RSPSET, 1 << ENDPOINT_HALT);
55962306a36Sopenharmony_ci}
56062306a36Sopenharmony_ci
56162306a36Sopenharmony_cistatic void clear_halt(struct net2272_ep *ep)
56262306a36Sopenharmony_ci{
56362306a36Sopenharmony_ci	/* ep0 and bulk/intr endpoints */
56462306a36Sopenharmony_ci	net2272_ep_write(ep, EP_RSPCLR,
56562306a36Sopenharmony_ci		(1 << ENDPOINT_HALT) | (1 << ENDPOINT_TOGGLE));
56662306a36Sopenharmony_ci}
56762306a36Sopenharmony_ci
56862306a36Sopenharmony_ci/* count (<= 4) bytes in the next fifo write will be valid */
56962306a36Sopenharmony_cistatic void set_fifo_bytecount(struct net2272_ep *ep, unsigned count)
57062306a36Sopenharmony_ci{
57162306a36Sopenharmony_ci	/* net2272_ep_write will truncate to u8 for us */
57262306a36Sopenharmony_ci	net2272_ep_write(ep, EP_TRANSFER2, count >> 16);
57362306a36Sopenharmony_ci	net2272_ep_write(ep, EP_TRANSFER1, count >> 8);
57462306a36Sopenharmony_ci	net2272_ep_write(ep, EP_TRANSFER0, count);
57562306a36Sopenharmony_ci}
57662306a36Sopenharmony_ci
57762306a36Sopenharmony_cistruct net2272_request {
57862306a36Sopenharmony_ci	struct usb_request req;
57962306a36Sopenharmony_ci	struct list_head queue;
58062306a36Sopenharmony_ci	unsigned mapped:1,
58162306a36Sopenharmony_ci	         valid:1;
58262306a36Sopenharmony_ci};
58362306a36Sopenharmony_ci
58462306a36Sopenharmony_ci#endif
585