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 _RT305X_REGS_H_
128c2ecf20Sopenharmony_ci#define _RT305X_REGS_H_
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciextern enum ralink_soc_type ralink_soc;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistatic inline int soc_is_rt3050(void)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	return ralink_soc == RT305X_SOC_RT3050;
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic inline int soc_is_rt3052(void)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	return ralink_soc == RT305X_SOC_RT3052;
248c2ecf20Sopenharmony_ci}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic inline int soc_is_rt305x(void)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	return soc_is_rt3050() || soc_is_rt3052();
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic inline int soc_is_rt3350(void)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	return ralink_soc == RT305X_SOC_RT3350;
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic inline int soc_is_rt3352(void)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	return ralink_soc == RT305X_SOC_RT3352;
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic inline int soc_is_rt5350(void)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	return ralink_soc == RT305X_SOC_RT5350;
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define RT305X_SYSC_BASE		0x10000000
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define SYSC_REG_CHIP_NAME0		0x00
498c2ecf20Sopenharmony_ci#define SYSC_REG_CHIP_NAME1		0x04
508c2ecf20Sopenharmony_ci#define SYSC_REG_CHIP_ID		0x0c
518c2ecf20Sopenharmony_ci#define SYSC_REG_SYSTEM_CONFIG		0x10
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define RT3052_CHIP_NAME0		0x30335452
548c2ecf20Sopenharmony_ci#define RT3052_CHIP_NAME1		0x20203235
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define RT3350_CHIP_NAME0		0x33335452
578c2ecf20Sopenharmony_ci#define RT3350_CHIP_NAME1		0x20203035
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define RT3352_CHIP_NAME0		0x33335452
608c2ecf20Sopenharmony_ci#define RT3352_CHIP_NAME1		0x20203235
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define RT5350_CHIP_NAME0		0x33355452
638c2ecf20Sopenharmony_ci#define RT5350_CHIP_NAME1		0x20203035
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define CHIP_ID_ID_MASK			0xff
668c2ecf20Sopenharmony_ci#define CHIP_ID_ID_SHIFT		8
678c2ecf20Sopenharmony_ci#define CHIP_ID_REV_MASK		0xff
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define RT305X_SYSCFG_CPUCLK_SHIFT		18
708c2ecf20Sopenharmony_ci#define RT305X_SYSCFG_CPUCLK_MASK		0x1
718c2ecf20Sopenharmony_ci#define RT305X_SYSCFG_CPUCLK_LOW		0x0
728c2ecf20Sopenharmony_ci#define RT305X_SYSCFG_CPUCLK_HIGH		0x1
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define RT305X_SYSCFG_SRAM_CS0_MODE_SHIFT	2
758c2ecf20Sopenharmony_ci#define RT305X_SYSCFG_CPUCLK_MASK		0x1
768c2ecf20Sopenharmony_ci#define RT305X_SYSCFG_SRAM_CS0_MODE_WDT		0x1
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define RT3352_SYSCFG0_CPUCLK_SHIFT	8
798c2ecf20Sopenharmony_ci#define RT3352_SYSCFG0_CPUCLK_MASK	0x1
808c2ecf20Sopenharmony_ci#define RT3352_SYSCFG0_CPUCLK_LOW	0x0
818c2ecf20Sopenharmony_ci#define RT3352_SYSCFG0_CPUCLK_HIGH	0x1
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_CPUCLK_SHIFT	8
848c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_CPUCLK_MASK	0x3
858c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_CPUCLK_360	0x0
868c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_CPUCLK_320	0x2
878c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_CPUCLK_300	0x3
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_DRAM_SIZE_SHIFT  12
908c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_DRAM_SIZE_MASK   7
918c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_DRAM_SIZE_2M     0
928c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_DRAM_SIZE_8M     1
938c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_DRAM_SIZE_16M    2
948c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_DRAM_SIZE_32M    3
958c2ecf20Sopenharmony_ci#define RT5350_SYSCFG0_DRAM_SIZE_64M    4
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* multi function gpio pins */
988c2ecf20Sopenharmony_ci#define RT305X_GPIO_I2C_SD		1
998c2ecf20Sopenharmony_ci#define RT305X_GPIO_I2C_SCLK		2
1008c2ecf20Sopenharmony_ci#define RT305X_GPIO_SPI_EN		3
1018c2ecf20Sopenharmony_ci#define RT305X_GPIO_SPI_CLK		4
1028c2ecf20Sopenharmony_ci/* GPIO 7-14 is shared between UART0, PCM  and I2S interfaces */
1038c2ecf20Sopenharmony_ci#define RT305X_GPIO_7			7
1048c2ecf20Sopenharmony_ci#define RT305X_GPIO_10			10
1058c2ecf20Sopenharmony_ci#define RT305X_GPIO_14			14
1068c2ecf20Sopenharmony_ci#define RT305X_GPIO_UART1_TXD		15
1078c2ecf20Sopenharmony_ci#define RT305X_GPIO_UART1_RXD		16
1088c2ecf20Sopenharmony_ci#define RT305X_GPIO_JTAG_TDO		17
1098c2ecf20Sopenharmony_ci#define RT305X_GPIO_JTAG_TDI		18
1108c2ecf20Sopenharmony_ci#define RT305X_GPIO_MDIO_MDC		22
1118c2ecf20Sopenharmony_ci#define RT305X_GPIO_MDIO_MDIO		23
1128c2ecf20Sopenharmony_ci#define RT305X_GPIO_SDRAM_MD16		24
1138c2ecf20Sopenharmony_ci#define RT305X_GPIO_SDRAM_MD31		39
1148c2ecf20Sopenharmony_ci#define RT305X_GPIO_GE0_TXD0		40
1158c2ecf20Sopenharmony_ci#define RT305X_GPIO_GE0_RXCLK		51
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_UART0_SHIFT	2
1188c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_UART0_MASK	0x7
1198c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_UART0(x)	((x) << RT305X_GPIO_MODE_UART0_SHIFT)
1208c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_UARTF		0
1218c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_PCM_UARTF	1
1228c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_PCM_I2S	2
1238c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_I2S_UARTF	3
1248c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_PCM_GPIO	4
1258c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_GPIO_UARTF	5
1268c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_GPIO_I2S	6
1278c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_GPIO		7
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_I2C		0
1308c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_SPI		1
1318c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_UART1		5
1328c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_JTAG		6
1338c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_MDIO		7
1348c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_SDRAM		8
1358c2ecf20Sopenharmony_ci#define RT305X_GPIO_MODE_RGMII		9
1368c2ecf20Sopenharmony_ci#define RT5350_GPIO_MODE_PHY_LED	14
1378c2ecf20Sopenharmony_ci#define RT5350_GPIO_MODE_SPI_CS1	21
1388c2ecf20Sopenharmony_ci#define RT3352_GPIO_MODE_LNA		18
1398c2ecf20Sopenharmony_ci#define RT3352_GPIO_MODE_PA		20
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define RT3352_SYSC_REG_SYSCFG0		0x010
1428c2ecf20Sopenharmony_ci#define RT3352_SYSC_REG_SYSCFG1         0x014
1438c2ecf20Sopenharmony_ci#define RT3352_SYSC_REG_CLKCFG1         0x030
1448c2ecf20Sopenharmony_ci#define RT3352_SYSC_REG_RSTCTRL         0x034
1458c2ecf20Sopenharmony_ci#define RT3352_SYSC_REG_USB_PS          0x05c
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#define RT3352_CLKCFG0_XTAL_SEL		BIT(20)
1488c2ecf20Sopenharmony_ci#define RT3352_CLKCFG1_UPHY0_CLK_EN	BIT(18)
1498c2ecf20Sopenharmony_ci#define RT3352_CLKCFG1_UPHY1_CLK_EN	BIT(20)
1508c2ecf20Sopenharmony_ci#define RT3352_RSTCTRL_UHST		BIT(22)
1518c2ecf20Sopenharmony_ci#define RT3352_RSTCTRL_UDEV		BIT(25)
1528c2ecf20Sopenharmony_ci#define RT3352_SYSCFG1_USB0_HOST_MODE	BIT(10)
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#define RT305X_SDRAM_BASE		0x00000000
1558c2ecf20Sopenharmony_ci#define RT305X_MEM_SIZE_MIN		2
1568c2ecf20Sopenharmony_ci#define RT305X_MEM_SIZE_MAX		64
1578c2ecf20Sopenharmony_ci#define RT3352_MEM_SIZE_MIN		2
1588c2ecf20Sopenharmony_ci#define RT3352_MEM_SIZE_MAX		256
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#endif
161