162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __MACH_SDK7786_FPGA_H
362306a36Sopenharmony_ci#define __MACH_SDK7786_FPGA_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/io.h>
662306a36Sopenharmony_ci#include <linux/types.h>
762306a36Sopenharmony_ci#include <linux/bitops.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#define SRSTR		0x000
1062306a36Sopenharmony_ci#define  SRSTR_MAGIC	0x1971	/* Fixed magical read value */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#define INTASR		0x010
1362306a36Sopenharmony_ci#define INTAMR		0x020
1462306a36Sopenharmony_ci#define MODSWR		0x030
1562306a36Sopenharmony_ci#define INTTESTR	0x040
1662306a36Sopenharmony_ci#define SYSSR		0x050
1762306a36Sopenharmony_ci#define NRGPR		0x060
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define NMISR		0x070
2062306a36Sopenharmony_ci#define  NMISR_MAN_NMI	BIT(0)
2162306a36Sopenharmony_ci#define  NMISR_AUX_NMI	BIT(1)
2262306a36Sopenharmony_ci#define  NMISR_MASK	(NMISR_MAN_NMI | NMISR_AUX_NMI)
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define NMIMR		0x080
2562306a36Sopenharmony_ci#define  NMIMR_MAN_NMIM	BIT(0)	/* Manual NMI mask */
2662306a36Sopenharmony_ci#define  NMIMR_AUX_NMIM	BIT(1)	/* Auxiliary NMI mask */
2762306a36Sopenharmony_ci#define  NMIMR_MASK	(NMIMR_MAN_NMIM | NMIMR_AUX_NMIM)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define INTBSR		0x090
3062306a36Sopenharmony_ci#define INTBMR		0x0a0
3162306a36Sopenharmony_ci#define USRLEDR		0x0b0
3262306a36Sopenharmony_ci#define MAPSWR		0x0c0
3362306a36Sopenharmony_ci#define FPGAVR		0x0d0
3462306a36Sopenharmony_ci#define FPGADR		0x0e0
3562306a36Sopenharmony_ci#define PCBRR		0x0f0
3662306a36Sopenharmony_ci#define RSR		0x100
3762306a36Sopenharmony_ci#define EXTASR		0x110
3862306a36Sopenharmony_ci#define SPCAR		0x120
3962306a36Sopenharmony_ci#define INTMSR		0x130
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define PCIECR		0x140
4262306a36Sopenharmony_ci#define  PCIECR_PCIEMUX1	BIT(15)
4362306a36Sopenharmony_ci#define  PCIECR_PCIEMUX0	BIT(14)
4462306a36Sopenharmony_ci#define  PCIECR_PRST4		BIT(12) /* slot 4 card present */
4562306a36Sopenharmony_ci#define  PCIECR_PRST3		BIT(11) /* slot 3 card present */
4662306a36Sopenharmony_ci#define  PCIECR_PRST2		BIT(10) /* slot 2 card present */
4762306a36Sopenharmony_ci#define  PCIECR_PRST1		BIT(9)  /* slot 1 card present */
4862306a36Sopenharmony_ci#define  PCIECR_CLKEN		BIT(4)	/* oscillator enable */
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#define FAER		0x150
5162306a36Sopenharmony_ci#define USRGPIR		0x160
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/* 0x170 reserved */
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#define LCLASR			0x180
5662306a36Sopenharmony_ci#define  LCLASR_FRAMEN		BIT(15)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define  LCLASR_FPGA_SEL_SHIFT	12
5962306a36Sopenharmony_ci#define  LCLASR_NAND_SEL_SHIFT	8
6062306a36Sopenharmony_ci#define  LCLASR_NORB_SEL_SHIFT	4
6162306a36Sopenharmony_ci#define  LCLASR_NORA_SEL_SHIFT	0
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define  LCLASR_AREA_MASK	0x7
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define  LCLASR_FPGA_SEL_MASK	(LCLASR_AREA_MASK << LCLASR_FPGA_SEL_SHIFT)
6662306a36Sopenharmony_ci#define  LCLASR_NAND_SEL_MASK	(LCLASR_AREA_MASK << LCLASR_NAND_SEL_SHIFT)
6762306a36Sopenharmony_ci#define  LCLASR_NORB_SEL_MASK	(LCLASR_AREA_MASK << LCLASR_NORB_SEL_SHIFT)
6862306a36Sopenharmony_ci#define  LCLASR_NORA_SEL_MASK	(LCLASR_AREA_MASK << LCLASR_NORA_SEL_SHIFT)
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#define SBCR		0x190
7162306a36Sopenharmony_ci#define  SCBR_I2CMEN	BIT(0)	/* FPGA I2C master enable */
7262306a36Sopenharmony_ci#define  SCBR_I2CCEN	BIT(1)	/* CPU I2C master enable */
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define PWRCR		0x1a0
7562306a36Sopenharmony_ci#define  PWRCR_SCISEL0	BIT(0)
7662306a36Sopenharmony_ci#define  PWRCR_SCISEL1	BIT(1)
7762306a36Sopenharmony_ci#define  PWRCR_SCIEN	BIT(2)	/* Serial port enable */
7862306a36Sopenharmony_ci#define  PWRCR_PDWNACK	BIT(5)	/* Power down acknowledge */
7962306a36Sopenharmony_ci#define  PWRCR_PDWNREQ	BIT(7)	/* Power down request */
8062306a36Sopenharmony_ci#define  PWRCR_INT2	BIT(11)	/* INT2 connection to power manager */
8162306a36Sopenharmony_ci#define  PWRCR_BUPINIT	BIT(13)	/* DDR backup initialize */
8262306a36Sopenharmony_ci#define  PWRCR_BKPRST	BIT(15) /* Backup power reset */
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#define SPCBR		0x1b0
8562306a36Sopenharmony_ci#define SPICR		0x1c0
8662306a36Sopenharmony_ci#define SPIDR		0x1d0
8762306a36Sopenharmony_ci#define I2CCR		0x1e0
8862306a36Sopenharmony_ci#define I2CDR		0x1f0
8962306a36Sopenharmony_ci#define FPGACR		0x200
9062306a36Sopenharmony_ci#define IASELR1		0x210
9162306a36Sopenharmony_ci#define IASELR2		0x220
9262306a36Sopenharmony_ci#define IASELR3		0x230
9362306a36Sopenharmony_ci#define IASELR4		0x240
9462306a36Sopenharmony_ci#define IASELR5		0x250
9562306a36Sopenharmony_ci#define IASELR6		0x260
9662306a36Sopenharmony_ci#define IASELR7		0x270
9762306a36Sopenharmony_ci#define IASELR8		0x280
9862306a36Sopenharmony_ci#define IASELR9		0x290
9962306a36Sopenharmony_ci#define IASELR10	0x2a0
10062306a36Sopenharmony_ci#define IASELR11	0x2b0
10162306a36Sopenharmony_ci#define IASELR12	0x2c0
10262306a36Sopenharmony_ci#define IASELR13	0x2d0
10362306a36Sopenharmony_ci#define IASELR14	0x2e0
10462306a36Sopenharmony_ci#define IASELR15	0x2f0
10562306a36Sopenharmony_ci/* 0x300 reserved */
10662306a36Sopenharmony_ci#define IBSELR1		0x310
10762306a36Sopenharmony_ci#define IBSELR2		0x320
10862306a36Sopenharmony_ci#define IBSELR3		0x330
10962306a36Sopenharmony_ci#define IBSELR4		0x340
11062306a36Sopenharmony_ci#define IBSELR5		0x350
11162306a36Sopenharmony_ci#define IBSELR6		0x360
11262306a36Sopenharmony_ci#define IBSELR7		0x370
11362306a36Sopenharmony_ci#define IBSELR8		0x380
11462306a36Sopenharmony_ci#define IBSELR9		0x390
11562306a36Sopenharmony_ci#define IBSELR10	0x3a0
11662306a36Sopenharmony_ci#define IBSELR11	0x3b0
11762306a36Sopenharmony_ci#define IBSELR12	0x3c0
11862306a36Sopenharmony_ci#define IBSELR13	0x3d0
11962306a36Sopenharmony_ci#define IBSELR14	0x3e0
12062306a36Sopenharmony_ci#define IBSELR15	0x3f0
12162306a36Sopenharmony_ci#define USRACR		0x400
12262306a36Sopenharmony_ci#define BEEPR		0x410
12362306a36Sopenharmony_ci#define USRLCDR		0x420
12462306a36Sopenharmony_ci#define SMBCR		0x430
12562306a36Sopenharmony_ci#define SMBDR		0x440
12662306a36Sopenharmony_ci#define USBCR		0x450
12762306a36Sopenharmony_ci#define AMSR		0x460
12862306a36Sopenharmony_ci#define ACCR		0x470
12962306a36Sopenharmony_ci#define SDIFCR		0x480
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci/* arch/sh/boards/mach-sdk7786/fpga.c */
13262306a36Sopenharmony_ciextern void __iomem *sdk7786_fpga_base;
13362306a36Sopenharmony_ciextern void sdk7786_fpga_init(void);
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/* arch/sh/boards/mach-sdk7786/nmi.c */
13662306a36Sopenharmony_ciextern void sdk7786_nmi_init(void);
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci#define SDK7786_FPGA_REGADDR(reg)	(sdk7786_fpga_base + (reg))
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci/*
14162306a36Sopenharmony_ci * A convenience wrapper from register offset to internal I2C address,
14262306a36Sopenharmony_ci * when the FPGA is in I2C slave mode.
14362306a36Sopenharmony_ci */
14462306a36Sopenharmony_ci#define SDK7786_FPGA_I2CADDR(reg)	((reg) >> 3)
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_cistatic inline u16 fpga_read_reg(unsigned int reg)
14762306a36Sopenharmony_ci{
14862306a36Sopenharmony_ci	return ioread16(sdk7786_fpga_base + reg);
14962306a36Sopenharmony_ci}
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_cistatic inline void fpga_write_reg(u16 val, unsigned int reg)
15262306a36Sopenharmony_ci{
15362306a36Sopenharmony_ci	iowrite16(val, sdk7786_fpga_base + reg);
15462306a36Sopenharmony_ci}
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci#endif /* __MACH_SDK7786_FPGA_H */
157