18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Parts of this file are based on Ralink's 2.6.21 BSP
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
78c2ecf20Sopenharmony_ci * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
88c2ecf20Sopenharmony_ci * Copyright (C) 2013 John Crispin <john@phrozen.org>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef _MT7620_REGS_H_
128c2ecf20Sopenharmony_ci#define _MT7620_REGS_H_
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define MT7620_SYSC_BASE		0x10000000
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define SYSC_REG_CHIP_NAME0		0x00
178c2ecf20Sopenharmony_ci#define SYSC_REG_CHIP_NAME1		0x04
188c2ecf20Sopenharmony_ci#define SYSC_REG_EFUSE_CFG		0x08
198c2ecf20Sopenharmony_ci#define SYSC_REG_CHIP_REV		0x0c
208c2ecf20Sopenharmony_ci#define SYSC_REG_SYSTEM_CONFIG0		0x10
218c2ecf20Sopenharmony_ci#define SYSC_REG_SYSTEM_CONFIG1		0x14
228c2ecf20Sopenharmony_ci#define SYSC_REG_CLKCFG0		0x2c
238c2ecf20Sopenharmony_ci#define SYSC_REG_CPU_SYS_CLKCFG		0x3c
248c2ecf20Sopenharmony_ci#define SYSC_REG_CPLL_CONFIG0		0x54
258c2ecf20Sopenharmony_ci#define SYSC_REG_CPLL_CONFIG1		0x58
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define MT7620_CHIP_NAME0		0x3637544d
288c2ecf20Sopenharmony_ci#define MT7620_CHIP_NAME1		0x20203032
298c2ecf20Sopenharmony_ci#define MT7628_CHIP_NAME1		0x20203832
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define SYSCFG0_XTAL_FREQ_SEL		BIT(6)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define CHIP_REV_PKG_MASK		0x1
348c2ecf20Sopenharmony_ci#define CHIP_REV_PKG_SHIFT		16
358c2ecf20Sopenharmony_ci#define CHIP_REV_VER_MASK		0xf
368c2ecf20Sopenharmony_ci#define CHIP_REV_VER_SHIFT		8
378c2ecf20Sopenharmony_ci#define CHIP_REV_ECO_MASK		0xf
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define CLKCFG0_PERI_CLK_SEL		BIT(4)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_SHIFT	16
428c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_MASK	0xf
438c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_1	0	/* 1:1   (Reserved) */
448c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_1_5	1	/* 1:1.5 (Reserved) */
458c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_2	2	/* 1:2   */
468c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_2_5	3       /* 1:2.5 (Reserved) */
478c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_3	4	/* 1:3   */
488c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_3_5	5	/* 1:3.5 (Reserved) */
498c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_4	6	/* 1:4   */
508c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_5	7	/* 1:5   */
518c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_OCP_RATIO_10	8	/* 1:10  */
528c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_CPU_FDIV_SHIFT	8
538c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_CPU_FDIV_MASK	0x1f
548c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_CPU_FFRAC_SHIFT	0
558c2ecf20Sopenharmony_ci#define CPU_SYS_CLKCFG_CPU_FFRAC_MASK	0x1f
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define CPLL_CFG0_SW_CFG		BIT(31)
588c2ecf20Sopenharmony_ci#define CPLL_CFG0_PLL_MULT_RATIO_SHIFT	16
598c2ecf20Sopenharmony_ci#define CPLL_CFG0_PLL_MULT_RATIO_MASK   0x7
608c2ecf20Sopenharmony_ci#define CPLL_CFG0_LC_CURFCK		BIT(15)
618c2ecf20Sopenharmony_ci#define CPLL_CFG0_BYPASS_REF_CLK	BIT(14)
628c2ecf20Sopenharmony_ci#define CPLL_CFG0_PLL_DIV_RATIO_SHIFT	10
638c2ecf20Sopenharmony_ci#define CPLL_CFG0_PLL_DIV_RATIO_MASK	0x3
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define CPLL_CFG1_CPU_AUX1		BIT(25)
668c2ecf20Sopenharmony_ci#define CPLL_CFG1_CPU_AUX0		BIT(24)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_MASK		0x3
698c2ecf20Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_SHIFT		4
708c2ecf20Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_SDRAM		0
718c2ecf20Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_DDR1		1
728c2ecf20Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_DDR2		2
738c2ecf20Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_UNKNOWN	3
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_DDR2_MT7628	0
768c2ecf20Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_DDR1_MT7628	1
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define MT7620_DRAM_BASE		0x0
798c2ecf20Sopenharmony_ci#define MT7620_SDRAM_SIZE_MIN		2
808c2ecf20Sopenharmony_ci#define MT7620_SDRAM_SIZE_MAX		64
818c2ecf20Sopenharmony_ci#define MT7620_DDR1_SIZE_MIN		32
828c2ecf20Sopenharmony_ci#define MT7620_DDR1_SIZE_MAX		128
838c2ecf20Sopenharmony_ci#define MT7620_DDR2_SIZE_MIN		32
848c2ecf20Sopenharmony_ci#define MT7620_DDR2_SIZE_MAX		256
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_UART0_SHIFT	2
878c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_UART0_MASK	0x7
888c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_UART0(x)	((x) << MT7620_GPIO_MODE_UART0_SHIFT)
898c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_UARTF		0x0
908c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PCM_UARTF	0x1
918c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PCM_I2S	0x2
928c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_I2S_UARTF	0x3
938c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PCM_GPIO	0x4
948c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_GPIO_UARTF	0x5
958c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_GPIO_I2S	0x6
968c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_GPIO		0x7
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_NAND		0
998c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_SD		1
1008c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_ND_SD_GPIO	2
1018c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_ND_SD_MASK	0x3
1028c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_ND_SD_SHIFT	18
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PCIE_RST	0
1058c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PCIE_REF	1
1068c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PCIE_GPIO	2
1078c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PCIE_MASK	0x3
1088c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PCIE_SHIFT	16
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_WDT_RST	0
1118c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_WDT_REF	1
1128c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_WDT_GPIO	2
1138c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_WDT_MASK	0x3
1148c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_WDT_SHIFT	21
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_MDIO		0
1178c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_MDIO_REFCLK	1
1188c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_MDIO_GPIO	2
1198c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_MDIO_MASK	0x3
1208c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_MDIO_SHIFT	7
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_I2C		0
1238c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_UART1		5
1248c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_RGMII1		9
1258c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_RGMII2		10
1268c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_SPI		11
1278c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_SPI_REF_CLK	12
1288c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_WLED		13
1298c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_JTAG		15
1308c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_EPHY		15
1318c2ecf20Sopenharmony_ci#define MT7620_GPIO_MODE_PA		20
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic inline int mt7620_get_eco(void)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	return rt_sysc_r32(SYSC_REG_CHIP_REV) & CHIP_REV_ECO_MASK;
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#endif
139