162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * bcsr.h -- Db1xxx/Pb1xxx Devboard CPLD registers ("BCSR") abstraction.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * All Alchemy development boards (except, of course, the weird PB1000)
662306a36Sopenharmony_ci * have a few registers in a CPLD with standardised layout; they mostly
762306a36Sopenharmony_ci * only differ in base address and bit meanings in the RESETS and BOARD
862306a36Sopenharmony_ci * registers.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * All data taken from the official AMD board documentation sheets.
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifndef _DB1XXX_BCSR_H_
1462306a36Sopenharmony_ci#define _DB1XXX_BCSR_H_
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* BCSR base addresses on various boards. BCSR base 2 refers to the
1862306a36Sopenharmony_ci * physical address of the first HEXLEDS register, which is usually
1962306a36Sopenharmony_ci * a variable offset from the WHOAMI register.
2062306a36Sopenharmony_ci */
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/* DB1000, DB1100, DB1500, PB1100, PB1500 */
2362306a36Sopenharmony_ci#define DB1000_BCSR_PHYS_ADDR	0x0E000000
2462306a36Sopenharmony_ci#define DB1000_BCSR_HEXLED_OFS	0x01000000
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define DB1550_BCSR_PHYS_ADDR	0x0F000000
2762306a36Sopenharmony_ci#define DB1550_BCSR_HEXLED_OFS	0x00400000
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define PB1550_BCSR_PHYS_ADDR	0x0F000000
3062306a36Sopenharmony_ci#define PB1550_BCSR_HEXLED_OFS	0x00800000
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define DB1200_BCSR_PHYS_ADDR	0x19800000
3362306a36Sopenharmony_ci#define DB1200_BCSR_HEXLED_OFS	0x00400000
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define PB1200_BCSR_PHYS_ADDR	0x0D800000
3662306a36Sopenharmony_ci#define PB1200_BCSR_HEXLED_OFS	0x00400000
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define DB1300_BCSR_PHYS_ADDR	0x19800000
3962306a36Sopenharmony_ci#define DB1300_BCSR_HEXLED_OFS	0x00400000
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cienum bcsr_id {
4262306a36Sopenharmony_ci	/* BCSR base 1 */
4362306a36Sopenharmony_ci	BCSR_WHOAMI	= 0,
4462306a36Sopenharmony_ci	BCSR_STATUS,
4562306a36Sopenharmony_ci	BCSR_SWITCHES,
4662306a36Sopenharmony_ci	BCSR_RESETS,
4762306a36Sopenharmony_ci	BCSR_PCMCIA,
4862306a36Sopenharmony_ci	BCSR_BOARD,
4962306a36Sopenharmony_ci	BCSR_LEDS,
5062306a36Sopenharmony_ci	BCSR_SYSTEM,
5162306a36Sopenharmony_ci	/* Au1200/1300 based boards */
5262306a36Sopenharmony_ci	BCSR_INTCLR,
5362306a36Sopenharmony_ci	BCSR_INTSET,
5462306a36Sopenharmony_ci	BCSR_MASKCLR,
5562306a36Sopenharmony_ci	BCSR_MASKSET,
5662306a36Sopenharmony_ci	BCSR_SIGSTAT,
5762306a36Sopenharmony_ci	BCSR_INTSTAT,
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	/* BCSR base 2 */
6062306a36Sopenharmony_ci	BCSR_HEXLEDS,
6162306a36Sopenharmony_ci	BCSR_RSVD1,
6262306a36Sopenharmony_ci	BCSR_HEXCLEAR,
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci	BCSR_CNT,
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/* register offsets, valid for all Db1xxx/Pb1xxx boards */
6862306a36Sopenharmony_ci#define BCSR_REG_WHOAMI		0x00
6962306a36Sopenharmony_ci#define BCSR_REG_STATUS		0x04
7062306a36Sopenharmony_ci#define BCSR_REG_SWITCHES	0x08
7162306a36Sopenharmony_ci#define BCSR_REG_RESETS		0x0c
7262306a36Sopenharmony_ci#define BCSR_REG_PCMCIA		0x10
7362306a36Sopenharmony_ci#define BCSR_REG_BOARD		0x14
7462306a36Sopenharmony_ci#define BCSR_REG_LEDS		0x18
7562306a36Sopenharmony_ci#define BCSR_REG_SYSTEM		0x1c
7662306a36Sopenharmony_ci/* Au1200/Au1300 based boards: CPLD IRQ muxer */
7762306a36Sopenharmony_ci#define BCSR_REG_INTCLR		0x20
7862306a36Sopenharmony_ci#define BCSR_REG_INTSET		0x24
7962306a36Sopenharmony_ci#define BCSR_REG_MASKCLR	0x28
8062306a36Sopenharmony_ci#define BCSR_REG_MASKSET	0x2c
8162306a36Sopenharmony_ci#define BCSR_REG_SIGSTAT	0x30
8262306a36Sopenharmony_ci#define BCSR_REG_INTSTAT	0x34
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci/* hexled control, offset from BCSR base 2 */
8562306a36Sopenharmony_ci#define BCSR_REG_HEXLEDS	0x00
8662306a36Sopenharmony_ci#define BCSR_REG_HEXCLEAR	0x08
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/*
8962306a36Sopenharmony_ci * Register Bits and Pieces.
9062306a36Sopenharmony_ci */
9162306a36Sopenharmony_ci#define BCSR_WHOAMI_DCID(x)		((x) & 0xf)
9262306a36Sopenharmony_ci#define BCSR_WHOAMI_CPLD(x)		(((x) >> 4) & 0xf)
9362306a36Sopenharmony_ci#define BCSR_WHOAMI_BOARD(x)		(((x) >> 8) & 0xf)
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci/* register "WHOAMI" bits 11:8 identify the board */
9662306a36Sopenharmony_cienum bcsr_whoami_boards {
9762306a36Sopenharmony_ci	BCSR_WHOAMI_PB1500 = 1,
9862306a36Sopenharmony_ci	BCSR_WHOAMI_PB1500R2,
9962306a36Sopenharmony_ci	BCSR_WHOAMI_PB1100,
10062306a36Sopenharmony_ci	BCSR_WHOAMI_DB1000,
10162306a36Sopenharmony_ci	BCSR_WHOAMI_DB1100,
10262306a36Sopenharmony_ci	BCSR_WHOAMI_DB1500,
10362306a36Sopenharmony_ci	BCSR_WHOAMI_DB1550,
10462306a36Sopenharmony_ci	BCSR_WHOAMI_PB1550_DDR,
10562306a36Sopenharmony_ci	BCSR_WHOAMI_PB1550 = BCSR_WHOAMI_PB1550_DDR,
10662306a36Sopenharmony_ci	BCSR_WHOAMI_PB1550_SDR,
10762306a36Sopenharmony_ci	BCSR_WHOAMI_PB1200_DDR1,
10862306a36Sopenharmony_ci	BCSR_WHOAMI_PB1200 = BCSR_WHOAMI_PB1200_DDR1,
10962306a36Sopenharmony_ci	BCSR_WHOAMI_PB1200_DDR2,
11062306a36Sopenharmony_ci	BCSR_WHOAMI_DB1200,
11162306a36Sopenharmony_ci	BCSR_WHOAMI_DB1300,
11262306a36Sopenharmony_ci};
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci/* STATUS reg.	Unless otherwise noted, they're valid on all boards.
11562306a36Sopenharmony_ci * PB1200 = DB1200.
11662306a36Sopenharmony_ci */
11762306a36Sopenharmony_ci#define BCSR_STATUS_PC0VS		0x0003
11862306a36Sopenharmony_ci#define BCSR_STATUS_PC1VS		0x000C
11962306a36Sopenharmony_ci#define BCSR_STATUS_PC0FI		0x0010
12062306a36Sopenharmony_ci#define BCSR_STATUS_PC1FI		0x0020
12162306a36Sopenharmony_ci#define BCSR_STATUS_PB1550_SWAPBOOT	0x0040
12262306a36Sopenharmony_ci#define BCSR_STATUS_SRAMWIDTH		0x0080
12362306a36Sopenharmony_ci#define BCSR_STATUS_FLASHBUSY		0x0100
12462306a36Sopenharmony_ci#define BCSR_STATUS_ROMBUSY		0x0400
12562306a36Sopenharmony_ci#define BCSR_STATUS_SD0WP		0x0400	/* DB1200/DB1300:SD1 */
12662306a36Sopenharmony_ci#define BCSR_STATUS_SD1WP		0x0800
12762306a36Sopenharmony_ci#define BCSR_STATUS_USBOTGID		0x0800	/* PB/DB1550 */
12862306a36Sopenharmony_ci#define BCSR_STATUS_DB1000_SWAPBOOT	0x2000
12962306a36Sopenharmony_ci#define BCSR_STATUS_DB1200_SWAPBOOT	0x0040	/* DB1200/1300 */
13062306a36Sopenharmony_ci#define BCSR_STATUS_IDECBLID		0x0200	/* DB1200/1300 */
13162306a36Sopenharmony_ci#define BCSR_STATUS_DB1200_U0RXD	0x1000	/* DB1200 */
13262306a36Sopenharmony_ci#define BCSR_STATUS_DB1200_U1RXD	0x2000	/* DB1200 */
13362306a36Sopenharmony_ci#define BCSR_STATUS_FLASHDEN		0xC000
13462306a36Sopenharmony_ci#define BCSR_STATUS_DB1550_U0RXD	0x1000	/* DB1550 */
13562306a36Sopenharmony_ci#define BCSR_STATUS_DB1550_U3RXD	0x2000	/* DB1550 */
13662306a36Sopenharmony_ci#define BCSR_STATUS_PB1550_U0RXD	0x1000	/* PB1550 */
13762306a36Sopenharmony_ci#define BCSR_STATUS_PB1550_U1RXD	0x2000	/* PB1550 */
13862306a36Sopenharmony_ci#define BCSR_STATUS_PB1550_U3RXD	0x8000	/* PB1550 */
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci#define BCSR_STATUS_CFWP		0x4000	/* DB1300 */
14162306a36Sopenharmony_ci#define BCSR_STATUS_USBOCn		0x2000	/* DB1300 */
14262306a36Sopenharmony_ci#define BCSR_STATUS_OTGOCn		0x1000	/* DB1300 */
14362306a36Sopenharmony_ci#define BCSR_STATUS_DCDMARQ		0x0010	/* DB1300 */
14462306a36Sopenharmony_ci#define BCSR_STATUS_IDEDMARQ		0x0020	/* DB1300 */
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci/* DB/PB1000,1100,1500,1550 */
14762306a36Sopenharmony_ci#define BCSR_RESETS_PHY0		0x0001
14862306a36Sopenharmony_ci#define BCSR_RESETS_PHY1		0x0002
14962306a36Sopenharmony_ci#define BCSR_RESETS_DC			0x0004
15062306a36Sopenharmony_ci#define BCSR_RESETS_FIR_SEL		0x2000
15162306a36Sopenharmony_ci#define BCSR_RESETS_IRDA_MODE_MASK	0xC000
15262306a36Sopenharmony_ci#define BCSR_RESETS_IRDA_MODE_FULL	0x0000
15362306a36Sopenharmony_ci#define BCSR_RESETS_PB1550_WSCFSM	0x2000
15462306a36Sopenharmony_ci#define BCSR_RESETS_IRDA_MODE_OFF	0x4000
15562306a36Sopenharmony_ci#define BCSR_RESETS_IRDA_MODE_2_3	0x8000
15662306a36Sopenharmony_ci#define BCSR_RESETS_IRDA_MODE_1_3	0xC000
15762306a36Sopenharmony_ci#define BCSR_RESETS_DMAREQ		0x8000	/* PB1550 */
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci#define BCSR_BOARD_PCIM66EN		0x0001
16062306a36Sopenharmony_ci#define BCSR_BOARD_SD0PWR		0x0040
16162306a36Sopenharmony_ci#define BCSR_BOARD_SD1PWR		0x0080
16262306a36Sopenharmony_ci#define BCSR_BOARD_PCIM33		0x0100
16362306a36Sopenharmony_ci#define BCSR_BOARD_PCIEXTARB		0x0200
16462306a36Sopenharmony_ci#define BCSR_BOARD_GPIO200RST		0x0400
16562306a36Sopenharmony_ci#define BCSR_BOARD_PCICLKOUT		0x0800
16662306a36Sopenharmony_ci#define BCSR_BOARD_PB1100_SD0PWR	0x0400
16762306a36Sopenharmony_ci#define BCSR_BOARD_PB1100_SD1PWR	0x0800
16862306a36Sopenharmony_ci#define BCSR_BOARD_PCICFG		0x1000
16962306a36Sopenharmony_ci#define BCSR_BOARD_SPISEL		0x2000	/* PB/DB1550 */
17062306a36Sopenharmony_ci#define BCSR_BOARD_SD0WP		0x4000	/* DB1100 */
17162306a36Sopenharmony_ci#define BCSR_BOARD_SD1WP		0x8000	/* DB1100 */
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci/* DB/PB1200/1300 */
17562306a36Sopenharmony_ci#define BCSR_RESETS_ETH			0x0001
17662306a36Sopenharmony_ci#define BCSR_RESETS_CAMERA		0x0002
17762306a36Sopenharmony_ci#define BCSR_RESETS_DC			0x0004
17862306a36Sopenharmony_ci#define BCSR_RESETS_IDE			0x0008
17962306a36Sopenharmony_ci#define BCSR_RESETS_TV			0x0010	/* DB1200/1300 */
18062306a36Sopenharmony_ci/* Not resets but in the same register */
18162306a36Sopenharmony_ci#define BCSR_RESETS_PWMR1MUX		0x0800	/* DB1200 */
18262306a36Sopenharmony_ci#define BCSR_RESETS_PB1200_WSCFSM	0x0800	/* PB1200 */
18362306a36Sopenharmony_ci#define BCSR_RESETS_PSC0MUX		0x1000
18462306a36Sopenharmony_ci#define BCSR_RESETS_PSC1MUX		0x2000
18562306a36Sopenharmony_ci#define BCSR_RESETS_SPISEL		0x4000
18662306a36Sopenharmony_ci#define BCSR_RESETS_SD1MUX		0x8000	/* PB1200 */
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci#define BCSR_RESETS_VDDQSHDN		0x0200	/* DB1300 */
18962306a36Sopenharmony_ci#define BCSR_RESETS_OTPPGM		0x0400	/* DB1300 */
19062306a36Sopenharmony_ci#define BCSR_RESETS_OTPSCLK		0x0800	/* DB1300 */
19162306a36Sopenharmony_ci#define BCSR_RESETS_OTPWRPROT		0x1000	/* DB1300 */
19262306a36Sopenharmony_ci#define BCSR_RESETS_OTPCSB		0x2000	/* DB1300 */
19362306a36Sopenharmony_ci#define BCSR_RESETS_OTGPWR		0x4000	/* DB1300 */
19462306a36Sopenharmony_ci#define BCSR_RESETS_USBHPWR		0x8000	/* DB1300 */
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#define BCSR_BOARD_LCDVEE		0x0001
19762306a36Sopenharmony_ci#define BCSR_BOARD_LCDVDD		0x0002
19862306a36Sopenharmony_ci#define BCSR_BOARD_LCDBL		0x0004
19962306a36Sopenharmony_ci#define BCSR_BOARD_CAMSNAP		0x0010
20062306a36Sopenharmony_ci#define BCSR_BOARD_CAMPWR		0x0020
20162306a36Sopenharmony_ci#define BCSR_BOARD_SD0PWR		0x0040
20262306a36Sopenharmony_ci#define BCSR_BOARD_CAMCS		0x0010	/* DB1300 */
20362306a36Sopenharmony_ci#define BCSR_BOARD_HDMI_DE		0x0040	/* DB1300 */
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP		0x00FF
20662306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP_1		0x0080
20762306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP_2		0x0040
20862306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP_3		0x0020
20962306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP_4		0x0010
21062306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP_5		0x0008
21162306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP_6		0x0004
21262306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP_7		0x0002
21362306a36Sopenharmony_ci#define BCSR_SWITCHES_DIP_8		0x0001
21462306a36Sopenharmony_ci#define BCSR_SWITCHES_ROTARY		0x0F00
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci#define BCSR_PCMCIA_PC0VPP		0x0003
21862306a36Sopenharmony_ci#define BCSR_PCMCIA_PC0VCC		0x000C
21962306a36Sopenharmony_ci#define BCSR_PCMCIA_PC0DRVEN		0x0010
22062306a36Sopenharmony_ci#define BCSR_PCMCIA_PC0RST		0x0080
22162306a36Sopenharmony_ci#define BCSR_PCMCIA_PC1VPP		0x0300
22262306a36Sopenharmony_ci#define BCSR_PCMCIA_PC1VCC		0x0C00
22362306a36Sopenharmony_ci#define BCSR_PCMCIA_PC1DRVEN		0x1000
22462306a36Sopenharmony_ci#define BCSR_PCMCIA_PC1RST		0x8000
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci#define BCSR_LEDS_DECIMALS		0x0003
22862306a36Sopenharmony_ci#define BCSR_LEDS_LED0			0x0100
22962306a36Sopenharmony_ci#define BCSR_LEDS_LED1			0x0200
23062306a36Sopenharmony_ci#define BCSR_LEDS_LED2			0x0400
23162306a36Sopenharmony_ci#define BCSR_LEDS_LED3			0x0800
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci#define BCSR_SYSTEM_RESET		0x8000	/* clear to reset */
23562306a36Sopenharmony_ci#define BCSR_SYSTEM_PWROFF		0x4000	/* set to power off */
23662306a36Sopenharmony_ci#define BCSR_SYSTEM_VDDI		0x001F	/* PB1xxx boards */
23762306a36Sopenharmony_ci#define BCSR_SYSTEM_DEBUGCSMASK		0x003F	/* DB1300 */
23862306a36Sopenharmony_ci#define BCSR_SYSTEM_UDMAMODE		0x0100	/* DB1300 */
23962306a36Sopenharmony_ci#define BCSR_SYSTEM_WAKEONIRQ		0x0200	/* DB1300 */
24062306a36Sopenharmony_ci#define BCSR_SYSTEM_VDDI1300		0x3C00	/* DB1300 */
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci/* initialize BCSR for a board. Provide the PHYSICAL addresses of both
24562306a36Sopenharmony_ci * BCSR spaces.
24662306a36Sopenharmony_ci */
24762306a36Sopenharmony_civoid __init bcsr_init(unsigned long bcsr1_phys, unsigned long bcsr2_phys);
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci/* read a board register */
25062306a36Sopenharmony_ciunsigned short bcsr_read(enum bcsr_id reg);
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci/* write to a board register */
25362306a36Sopenharmony_civoid bcsr_write(enum bcsr_id reg, unsigned short val);
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci/* modify a register. clear bits set in 'clr', set bits set in 'set' */
25662306a36Sopenharmony_civoid bcsr_mod(enum bcsr_id reg, unsigned short clr, unsigned short set);
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci/* install CPLD IRQ demuxer (DB1200/PB1200) */
25962306a36Sopenharmony_civoid __init bcsr_init_irq(int csc_start, int csc_end, int hook_irq);
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci#endif
262