162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Parts of this file are based on Ralink's 2.6.21 BSP
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
762306a36Sopenharmony_ci * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
862306a36Sopenharmony_ci * Copyright (C) 2013 John Crispin <john@phrozen.org>
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef _MT7620_REGS_H_
1262306a36Sopenharmony_ci#define _MT7620_REGS_H_
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define IOMEM(x)			((void __iomem *)(KSEG1ADDR(x)))
1562306a36Sopenharmony_ci#define MT7620_SYSC_BASE		IOMEM(0x10000000)
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#define SYSC_REG_CHIP_NAME0		0x00
1862306a36Sopenharmony_ci#define SYSC_REG_CHIP_NAME1		0x04
1962306a36Sopenharmony_ci#define SYSC_REG_EFUSE_CFG		0x08
2062306a36Sopenharmony_ci#define SYSC_REG_CHIP_REV		0x0c
2162306a36Sopenharmony_ci#define SYSC_REG_SYSTEM_CONFIG0		0x10
2262306a36Sopenharmony_ci#define SYSC_REG_SYSTEM_CONFIG1		0x14
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define MT7620_CHIP_NAME0		0x3637544d
2562306a36Sopenharmony_ci#define MT7620_CHIP_NAME1		0x20203032
2662306a36Sopenharmony_ci#define MT7628_CHIP_NAME1		0x20203832
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define CHIP_REV_PKG_MASK		0x1
2962306a36Sopenharmony_ci#define CHIP_REV_PKG_SHIFT		16
3062306a36Sopenharmony_ci#define CHIP_REV_VER_MASK		0xf
3162306a36Sopenharmony_ci#define CHIP_REV_VER_SHIFT		8
3262306a36Sopenharmony_ci#define CHIP_REV_ECO_MASK		0xf
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_MASK		0x3
3562306a36Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_SHIFT		4
3662306a36Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_SDRAM		0
3762306a36Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_DDR1		1
3862306a36Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_DDR2		2
3962306a36Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_UNKNOWN	3
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_DDR2_MT7628	0
4262306a36Sopenharmony_ci#define SYSCFG0_DRAM_TYPE_DDR1_MT7628	1
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#define MT7620_DRAM_BASE		0x0
4562306a36Sopenharmony_ci#define MT7620_SDRAM_SIZE_MIN		2
4662306a36Sopenharmony_ci#define MT7620_SDRAM_SIZE_MAX		64
4762306a36Sopenharmony_ci#define MT7620_DDR1_SIZE_MIN		32
4862306a36Sopenharmony_ci#define MT7620_DDR1_SIZE_MAX		128
4962306a36Sopenharmony_ci#define MT7620_DDR2_SIZE_MIN		32
5062306a36Sopenharmony_ci#define MT7620_DDR2_SIZE_MAX		256
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciextern enum ralink_soc_type ralink_soc;
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistatic inline int is_mt76x8(void)
5562306a36Sopenharmony_ci{
5662306a36Sopenharmony_ci	return ralink_soc == MT762X_SOC_MT7628AN ||
5762306a36Sopenharmony_ci	       ralink_soc == MT762X_SOC_MT7688;
5862306a36Sopenharmony_ci}
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistatic inline int mt7620_get_eco(void)
6162306a36Sopenharmony_ci{
6262306a36Sopenharmony_ci	return rt_sysc_r32(SYSC_REG_CHIP_REV) & CHIP_REV_ECO_MASK;
6362306a36Sopenharmony_ci}
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#endif
66