18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __MACH_SDK7786_FPGA_H
38c2ecf20Sopenharmony_ci#define __MACH_SDK7786_FPGA_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/io.h>
68c2ecf20Sopenharmony_ci#include <linux/types.h>
78c2ecf20Sopenharmony_ci#include <linux/bitops.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define SRSTR		0x000
108c2ecf20Sopenharmony_ci#define  SRSTR_MAGIC	0x1971	/* Fixed magical read value */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define INTASR		0x010
138c2ecf20Sopenharmony_ci#define INTAMR		0x020
148c2ecf20Sopenharmony_ci#define MODSWR		0x030
158c2ecf20Sopenharmony_ci#define INTTESTR	0x040
168c2ecf20Sopenharmony_ci#define SYSSR		0x050
178c2ecf20Sopenharmony_ci#define NRGPR		0x060
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define NMISR		0x070
208c2ecf20Sopenharmony_ci#define  NMISR_MAN_NMI	BIT(0)
218c2ecf20Sopenharmony_ci#define  NMISR_AUX_NMI	BIT(1)
228c2ecf20Sopenharmony_ci#define  NMISR_MASK	(NMISR_MAN_NMI | NMISR_AUX_NMI)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define NMIMR		0x080
258c2ecf20Sopenharmony_ci#define  NMIMR_MAN_NMIM	BIT(0)	/* Manual NMI mask */
268c2ecf20Sopenharmony_ci#define  NMIMR_AUX_NMIM	BIT(1)	/* Auxiliary NMI mask */
278c2ecf20Sopenharmony_ci#define  NMIMR_MASK	(NMIMR_MAN_NMIM | NMIMR_AUX_NMIM)
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define INTBSR		0x090
308c2ecf20Sopenharmony_ci#define INTBMR		0x0a0
318c2ecf20Sopenharmony_ci#define USRLEDR		0x0b0
328c2ecf20Sopenharmony_ci#define MAPSWR		0x0c0
338c2ecf20Sopenharmony_ci#define FPGAVR		0x0d0
348c2ecf20Sopenharmony_ci#define FPGADR		0x0e0
358c2ecf20Sopenharmony_ci#define PCBRR		0x0f0
368c2ecf20Sopenharmony_ci#define RSR		0x100
378c2ecf20Sopenharmony_ci#define EXTASR		0x110
388c2ecf20Sopenharmony_ci#define SPCAR		0x120
398c2ecf20Sopenharmony_ci#define INTMSR		0x130
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define PCIECR		0x140
428c2ecf20Sopenharmony_ci#define  PCIECR_PCIEMUX1	BIT(15)
438c2ecf20Sopenharmony_ci#define  PCIECR_PCIEMUX0	BIT(14)
448c2ecf20Sopenharmony_ci#define  PCIECR_PRST4		BIT(12) /* slot 4 card present */
458c2ecf20Sopenharmony_ci#define  PCIECR_PRST3		BIT(11) /* slot 3 card present */
468c2ecf20Sopenharmony_ci#define  PCIECR_PRST2		BIT(10) /* slot 2 card present */
478c2ecf20Sopenharmony_ci#define  PCIECR_PRST1		BIT(9)  /* slot 1 card present */
488c2ecf20Sopenharmony_ci#define  PCIECR_CLKEN		BIT(4)	/* oscillator enable */
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define FAER		0x150
518c2ecf20Sopenharmony_ci#define USRGPIR		0x160
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/* 0x170 reserved */
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define LCLASR			0x180
568c2ecf20Sopenharmony_ci#define  LCLASR_FRAMEN		BIT(15)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define  LCLASR_FPGA_SEL_SHIFT	12
598c2ecf20Sopenharmony_ci#define  LCLASR_NAND_SEL_SHIFT	8
608c2ecf20Sopenharmony_ci#define  LCLASR_NORB_SEL_SHIFT	4
618c2ecf20Sopenharmony_ci#define  LCLASR_NORA_SEL_SHIFT	0
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define  LCLASR_AREA_MASK	0x7
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define  LCLASR_FPGA_SEL_MASK	(LCLASR_AREA_MASK << LCLASR_FPGA_SEL_SHIFT)
668c2ecf20Sopenharmony_ci#define  LCLASR_NAND_SEL_MASK	(LCLASR_AREA_MASK << LCLASR_NAND_SEL_SHIFT)
678c2ecf20Sopenharmony_ci#define  LCLASR_NORB_SEL_MASK	(LCLASR_AREA_MASK << LCLASR_NORB_SEL_SHIFT)
688c2ecf20Sopenharmony_ci#define  LCLASR_NORA_SEL_MASK	(LCLASR_AREA_MASK << LCLASR_NORA_SEL_SHIFT)
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define SBCR		0x190
718c2ecf20Sopenharmony_ci#define  SCBR_I2CMEN	BIT(0)	/* FPGA I2C master enable */
728c2ecf20Sopenharmony_ci#define  SCBR_I2CCEN	BIT(1)	/* CPU I2C master enable */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define PWRCR		0x1a0
758c2ecf20Sopenharmony_ci#define  PWRCR_SCISEL0	BIT(0)
768c2ecf20Sopenharmony_ci#define  PWRCR_SCISEL1	BIT(1)
778c2ecf20Sopenharmony_ci#define  PWRCR_SCIEN	BIT(2)	/* Serial port enable */
788c2ecf20Sopenharmony_ci#define  PWRCR_PDWNACK	BIT(5)	/* Power down acknowledge */
798c2ecf20Sopenharmony_ci#define  PWRCR_PDWNREQ	BIT(7)	/* Power down request */
808c2ecf20Sopenharmony_ci#define  PWRCR_INT2	BIT(11)	/* INT2 connection to power manager */
818c2ecf20Sopenharmony_ci#define  PWRCR_BUPINIT	BIT(13)	/* DDR backup initialize */
828c2ecf20Sopenharmony_ci#define  PWRCR_BKPRST	BIT(15) /* Backup power reset */
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define SPCBR		0x1b0
858c2ecf20Sopenharmony_ci#define SPICR		0x1c0
868c2ecf20Sopenharmony_ci#define SPIDR		0x1d0
878c2ecf20Sopenharmony_ci#define I2CCR		0x1e0
888c2ecf20Sopenharmony_ci#define I2CDR		0x1f0
898c2ecf20Sopenharmony_ci#define FPGACR		0x200
908c2ecf20Sopenharmony_ci#define IASELR1		0x210
918c2ecf20Sopenharmony_ci#define IASELR2		0x220
928c2ecf20Sopenharmony_ci#define IASELR3		0x230
938c2ecf20Sopenharmony_ci#define IASELR4		0x240
948c2ecf20Sopenharmony_ci#define IASELR5		0x250
958c2ecf20Sopenharmony_ci#define IASELR6		0x260
968c2ecf20Sopenharmony_ci#define IASELR7		0x270
978c2ecf20Sopenharmony_ci#define IASELR8		0x280
988c2ecf20Sopenharmony_ci#define IASELR9		0x290
998c2ecf20Sopenharmony_ci#define IASELR10	0x2a0
1008c2ecf20Sopenharmony_ci#define IASELR11	0x2b0
1018c2ecf20Sopenharmony_ci#define IASELR12	0x2c0
1028c2ecf20Sopenharmony_ci#define IASELR13	0x2d0
1038c2ecf20Sopenharmony_ci#define IASELR14	0x2e0
1048c2ecf20Sopenharmony_ci#define IASELR15	0x2f0
1058c2ecf20Sopenharmony_ci/* 0x300 reserved */
1068c2ecf20Sopenharmony_ci#define IBSELR1		0x310
1078c2ecf20Sopenharmony_ci#define IBSELR2		0x320
1088c2ecf20Sopenharmony_ci#define IBSELR3		0x330
1098c2ecf20Sopenharmony_ci#define IBSELR4		0x340
1108c2ecf20Sopenharmony_ci#define IBSELR5		0x350
1118c2ecf20Sopenharmony_ci#define IBSELR6		0x360
1128c2ecf20Sopenharmony_ci#define IBSELR7		0x370
1138c2ecf20Sopenharmony_ci#define IBSELR8		0x380
1148c2ecf20Sopenharmony_ci#define IBSELR9		0x390
1158c2ecf20Sopenharmony_ci#define IBSELR10	0x3a0
1168c2ecf20Sopenharmony_ci#define IBSELR11	0x3b0
1178c2ecf20Sopenharmony_ci#define IBSELR12	0x3c0
1188c2ecf20Sopenharmony_ci#define IBSELR13	0x3d0
1198c2ecf20Sopenharmony_ci#define IBSELR14	0x3e0
1208c2ecf20Sopenharmony_ci#define IBSELR15	0x3f0
1218c2ecf20Sopenharmony_ci#define USRACR		0x400
1228c2ecf20Sopenharmony_ci#define BEEPR		0x410
1238c2ecf20Sopenharmony_ci#define USRLCDR		0x420
1248c2ecf20Sopenharmony_ci#define SMBCR		0x430
1258c2ecf20Sopenharmony_ci#define SMBDR		0x440
1268c2ecf20Sopenharmony_ci#define USBCR		0x450
1278c2ecf20Sopenharmony_ci#define AMSR		0x460
1288c2ecf20Sopenharmony_ci#define ACCR		0x470
1298c2ecf20Sopenharmony_ci#define SDIFCR		0x480
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* arch/sh/boards/mach-sdk7786/fpga.c */
1328c2ecf20Sopenharmony_ciextern void __iomem *sdk7786_fpga_base;
1338c2ecf20Sopenharmony_ciextern void sdk7786_fpga_init(void);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/* arch/sh/boards/mach-sdk7786/nmi.c */
1368c2ecf20Sopenharmony_ciextern void sdk7786_nmi_init(void);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#define SDK7786_FPGA_REGADDR(reg)	(sdk7786_fpga_base + (reg))
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci/*
1418c2ecf20Sopenharmony_ci * A convenience wrapper from register offset to internal I2C address,
1428c2ecf20Sopenharmony_ci * when the FPGA is in I2C slave mode.
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_ci#define SDK7786_FPGA_I2CADDR(reg)	((reg) >> 3)
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cistatic inline u16 fpga_read_reg(unsigned int reg)
1478c2ecf20Sopenharmony_ci{
1488c2ecf20Sopenharmony_ci	return ioread16(sdk7786_fpga_base + reg);
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cistatic inline void fpga_write_reg(u16 val, unsigned int reg)
1528c2ecf20Sopenharmony_ci{
1538c2ecf20Sopenharmony_ci	iowrite16(val, sdk7786_fpga_base + reg);
1548c2ecf20Sopenharmony_ci}
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#endif /* __MACH_SDK7786_FPGA_H */
157