18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __MT7530_H 78c2ecf20Sopenharmony_ci#define __MT7530_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define MT7530_NUM_PORTS 7 108c2ecf20Sopenharmony_ci#define MT7530_CPU_PORT 6 118c2ecf20Sopenharmony_ci#define MT7530_NUM_FDB_RECORDS 2048 128c2ecf20Sopenharmony_ci#define MT7530_ALL_MEMBERS 0xff 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cienum mt753x_id { 158c2ecf20Sopenharmony_ci ID_MT7530 = 0, 168c2ecf20Sopenharmony_ci ID_MT7621 = 1, 178c2ecf20Sopenharmony_ci ID_MT7531 = 2, 188c2ecf20Sopenharmony_ci}; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define NUM_TRGMII_CTRL 5 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define TRGMII_BASE(x) (0x10000 + (x)) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* Registers to ethsys access */ 258c2ecf20Sopenharmony_ci#define ETHSYS_CLKCFG0 0x2c 268c2ecf20Sopenharmony_ci#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11) 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define SYSC_REG_RSTCTRL 0x34 298c2ecf20Sopenharmony_ci#define RESET_MCM BIT(2) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* Registers to mac forward control for unknown frames */ 328c2ecf20Sopenharmony_ci#define MT7530_MFC 0x10 338c2ecf20Sopenharmony_ci#define BC_FFP(x) (((x) & 0xff) << 24) 348c2ecf20Sopenharmony_ci#define UNM_FFP(x) (((x) & 0xff) << 16) 358c2ecf20Sopenharmony_ci#define UNM_FFP_MASK UNM_FFP(~0) 368c2ecf20Sopenharmony_ci#define UNU_FFP(x) (((x) & 0xff) << 8) 378c2ecf20Sopenharmony_ci#define UNU_FFP_MASK UNU_FFP(~0) 388c2ecf20Sopenharmony_ci#define CPU_EN BIT(7) 398c2ecf20Sopenharmony_ci#define CPU_PORT(x) ((x) << 4) 408c2ecf20Sopenharmony_ci#define CPU_MASK (0xf << 4) 418c2ecf20Sopenharmony_ci#define MIRROR_EN BIT(3) 428c2ecf20Sopenharmony_ci#define MIRROR_PORT(x) ((x) & 0x7) 438c2ecf20Sopenharmony_ci#define MIRROR_MASK 0x7 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* Registers for CPU forward control */ 468c2ecf20Sopenharmony_ci#define MT7531_CFC 0x4 478c2ecf20Sopenharmony_ci#define MT7531_MIRROR_EN BIT(19) 488c2ecf20Sopenharmony_ci#define MT7531_MIRROR_MASK (MIRROR_MASK << 16) 498c2ecf20Sopenharmony_ci#define MT7531_MIRROR_PORT_GET(x) (((x) >> 16) & MIRROR_MASK) 508c2ecf20Sopenharmony_ci#define MT7531_MIRROR_PORT_SET(x) (((x) & MIRROR_MASK) << 16) 518c2ecf20Sopenharmony_ci#define MT7531_CPU_PMAP_MASK GENMASK(7, 0) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define MT753X_MIRROR_REG(id) (((id) == ID_MT7531) ? \ 548c2ecf20Sopenharmony_ci MT7531_CFC : MT7530_MFC) 558c2ecf20Sopenharmony_ci#define MT753X_MIRROR_EN(id) (((id) == ID_MT7531) ? \ 568c2ecf20Sopenharmony_ci MT7531_MIRROR_EN : MIRROR_EN) 578c2ecf20Sopenharmony_ci#define MT753X_MIRROR_MASK(id) (((id) == ID_MT7531) ? \ 588c2ecf20Sopenharmony_ci MT7531_MIRROR_MASK : MIRROR_MASK) 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* Registers for BPDU and PAE frame control*/ 618c2ecf20Sopenharmony_ci#define MT753X_BPC 0x24 628c2ecf20Sopenharmony_ci#define MT753X_BPDU_PORT_FW_MASK GENMASK(2, 0) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cienum mt753x_bpdu_port_fw { 658c2ecf20Sopenharmony_ci MT753X_BPDU_FOLLOW_MFC, 668c2ecf20Sopenharmony_ci MT753X_BPDU_CPU_EXCLUDE = 4, 678c2ecf20Sopenharmony_ci MT753X_BPDU_CPU_INCLUDE = 5, 688c2ecf20Sopenharmony_ci MT753X_BPDU_CPU_ONLY = 6, 698c2ecf20Sopenharmony_ci MT753X_BPDU_DROP = 7, 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* Registers for address table access */ 738c2ecf20Sopenharmony_ci#define MT7530_ATA1 0x74 748c2ecf20Sopenharmony_ci#define STATIC_EMP 0 758c2ecf20Sopenharmony_ci#define STATIC_ENT 3 768c2ecf20Sopenharmony_ci#define MT7530_ATA2 0x78 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* Register for address table write data */ 798c2ecf20Sopenharmony_ci#define MT7530_ATWD 0x7c 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/* Register for address table control */ 828c2ecf20Sopenharmony_ci#define MT7530_ATC 0x80 838c2ecf20Sopenharmony_ci#define ATC_HASH (((x) & 0xfff) << 16) 848c2ecf20Sopenharmony_ci#define ATC_BUSY BIT(15) 858c2ecf20Sopenharmony_ci#define ATC_SRCH_END BIT(14) 868c2ecf20Sopenharmony_ci#define ATC_SRCH_HIT BIT(13) 878c2ecf20Sopenharmony_ci#define ATC_INVALID BIT(12) 888c2ecf20Sopenharmony_ci#define ATC_MAT(x) (((x) & 0xf) << 8) 898c2ecf20Sopenharmony_ci#define ATC_MAT_MACTAB ATC_MAT(0) 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cienum mt7530_fdb_cmd { 928c2ecf20Sopenharmony_ci MT7530_FDB_READ = 0, 938c2ecf20Sopenharmony_ci MT7530_FDB_WRITE = 1, 948c2ecf20Sopenharmony_ci MT7530_FDB_FLUSH = 2, 958c2ecf20Sopenharmony_ci MT7530_FDB_START = 4, 968c2ecf20Sopenharmony_ci MT7530_FDB_NEXT = 5, 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* Registers for table search read address */ 1008c2ecf20Sopenharmony_ci#define MT7530_TSRA1 0x84 1018c2ecf20Sopenharmony_ci#define MAC_BYTE_0 24 1028c2ecf20Sopenharmony_ci#define MAC_BYTE_1 16 1038c2ecf20Sopenharmony_ci#define MAC_BYTE_2 8 1048c2ecf20Sopenharmony_ci#define MAC_BYTE_3 0 1058c2ecf20Sopenharmony_ci#define MAC_BYTE_MASK 0xff 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define MT7530_TSRA2 0x88 1088c2ecf20Sopenharmony_ci#define MAC_BYTE_4 24 1098c2ecf20Sopenharmony_ci#define MAC_BYTE_5 16 1108c2ecf20Sopenharmony_ci#define CVID 0 1118c2ecf20Sopenharmony_ci#define CVID_MASK 0xfff 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#define MT7530_ATRD 0x8C 1148c2ecf20Sopenharmony_ci#define AGE_TIMER 24 1158c2ecf20Sopenharmony_ci#define AGE_TIMER_MASK 0xff 1168c2ecf20Sopenharmony_ci#define PORT_MAP 4 1178c2ecf20Sopenharmony_ci#define PORT_MAP_MASK 0xff 1188c2ecf20Sopenharmony_ci#define ENT_STATUS 2 1198c2ecf20Sopenharmony_ci#define ENT_STATUS_MASK 0x3 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* Register for vlan table control */ 1228c2ecf20Sopenharmony_ci#define MT7530_VTCR 0x90 1238c2ecf20Sopenharmony_ci#define VTCR_BUSY BIT(31) 1248c2ecf20Sopenharmony_ci#define VTCR_INVALID BIT(16) 1258c2ecf20Sopenharmony_ci#define VTCR_FUNC(x) (((x) & 0xf) << 12) 1268c2ecf20Sopenharmony_ci#define VTCR_VID ((x) & 0xfff) 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cienum mt7530_vlan_cmd { 1298c2ecf20Sopenharmony_ci /* Read/Write the specified VID entry from VAWD register based 1308c2ecf20Sopenharmony_ci * on VID. 1318c2ecf20Sopenharmony_ci */ 1328c2ecf20Sopenharmony_ci MT7530_VTCR_RD_VID = 0, 1338c2ecf20Sopenharmony_ci MT7530_VTCR_WR_VID = 1, 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci/* Register for setup vlan and acl write data */ 1378c2ecf20Sopenharmony_ci#define MT7530_VAWD1 0x94 1388c2ecf20Sopenharmony_ci#define PORT_STAG BIT(31) 1398c2ecf20Sopenharmony_ci/* Independent VLAN Learning */ 1408c2ecf20Sopenharmony_ci#define IVL_MAC BIT(30) 1418c2ecf20Sopenharmony_ci/* Per VLAN Egress Tag Control */ 1428c2ecf20Sopenharmony_ci#define VTAG_EN BIT(28) 1438c2ecf20Sopenharmony_ci/* VLAN Member Control */ 1448c2ecf20Sopenharmony_ci#define PORT_MEM(x) (((x) & 0xff) << 16) 1458c2ecf20Sopenharmony_ci/* VLAN Entry Valid */ 1468c2ecf20Sopenharmony_ci#define VLAN_VALID BIT(0) 1478c2ecf20Sopenharmony_ci#define PORT_MEM_SHFT 16 1488c2ecf20Sopenharmony_ci#define PORT_MEM_MASK 0xff 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci#define MT7530_VAWD2 0x98 1518c2ecf20Sopenharmony_ci/* Egress Tag Control */ 1528c2ecf20Sopenharmony_ci#define ETAG_CTRL_P(p, x) (((x) & 0x3) << ((p) << 1)) 1538c2ecf20Sopenharmony_ci#define ETAG_CTRL_P_MASK(p) ETAG_CTRL_P(p, 3) 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cienum mt7530_vlan_egress_attr { 1568c2ecf20Sopenharmony_ci MT7530_VLAN_EGRESS_UNTAG = 0, 1578c2ecf20Sopenharmony_ci MT7530_VLAN_EGRESS_TAG = 2, 1588c2ecf20Sopenharmony_ci MT7530_VLAN_EGRESS_STACK = 3, 1598c2ecf20Sopenharmony_ci}; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci/* Register for port STP state control */ 1628c2ecf20Sopenharmony_ci#define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100)) 1638c2ecf20Sopenharmony_ci#define FID_PST(x) ((x) & 0x3) 1648c2ecf20Sopenharmony_ci#define FID_PST_MASK FID_PST(0x3) 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cienum mt7530_stp_state { 1678c2ecf20Sopenharmony_ci MT7530_STP_DISABLED = 0, 1688c2ecf20Sopenharmony_ci MT7530_STP_BLOCKING = 1, 1698c2ecf20Sopenharmony_ci MT7530_STP_LISTENING = 1, 1708c2ecf20Sopenharmony_ci MT7530_STP_LEARNING = 2, 1718c2ecf20Sopenharmony_ci MT7530_STP_FORWARDING = 3 1728c2ecf20Sopenharmony_ci}; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci/* Register for port control */ 1758c2ecf20Sopenharmony_ci#define MT7530_PCR_P(x) (0x2004 + ((x) * 0x100)) 1768c2ecf20Sopenharmony_ci#define PORT_TX_MIR BIT(9) 1778c2ecf20Sopenharmony_ci#define PORT_RX_MIR BIT(8) 1788c2ecf20Sopenharmony_ci#define PORT_VLAN(x) ((x) & 0x3) 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_cienum mt7530_port_mode { 1818c2ecf20Sopenharmony_ci /* Port Matrix Mode: Frames are forwarded by the PCR_MATRIX members. */ 1828c2ecf20Sopenharmony_ci MT7530_PORT_MATRIX_MODE = PORT_VLAN(0), 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci /* Fallback Mode: Forward received frames with ingress ports that do 1858c2ecf20Sopenharmony_ci * not belong to the VLAN member. Frames whose VID is not listed on 1868c2ecf20Sopenharmony_ci * the VLAN table are forwarded by the PCR_MATRIX members. 1878c2ecf20Sopenharmony_ci */ 1888c2ecf20Sopenharmony_ci MT7530_PORT_FALLBACK_MODE = PORT_VLAN(1), 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci /* Security Mode: Discard any frame due to ingress membership 1918c2ecf20Sopenharmony_ci * violation or VID missed on the VLAN table. 1928c2ecf20Sopenharmony_ci */ 1938c2ecf20Sopenharmony_ci MT7530_PORT_SECURITY_MODE = PORT_VLAN(3), 1948c2ecf20Sopenharmony_ci}; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#define PCR_MATRIX(x) (((x) & 0xff) << 16) 1978c2ecf20Sopenharmony_ci#define PORT_PRI(x) (((x) & 0x7) << 24) 1988c2ecf20Sopenharmony_ci#define EG_TAG(x) (((x) & 0x3) << 28) 1998c2ecf20Sopenharmony_ci#define PCR_MATRIX_MASK PCR_MATRIX(0xff) 2008c2ecf20Sopenharmony_ci#define PCR_MATRIX_CLR PCR_MATRIX(0) 2018c2ecf20Sopenharmony_ci#define PCR_PORT_VLAN_MASK PORT_VLAN(3) 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci/* Register for port security control */ 2048c2ecf20Sopenharmony_ci#define MT7530_PSC_P(x) (0x200c + ((x) * 0x100)) 2058c2ecf20Sopenharmony_ci#define SA_DIS BIT(4) 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci/* Register for port vlan control */ 2088c2ecf20Sopenharmony_ci#define MT7530_PVC_P(x) (0x2010 + ((x) * 0x100)) 2098c2ecf20Sopenharmony_ci#define PORT_SPEC_TAG BIT(5) 2108c2ecf20Sopenharmony_ci#define PVC_EG_TAG(x) (((x) & 0x7) << 8) 2118c2ecf20Sopenharmony_ci#define PVC_EG_TAG_MASK PVC_EG_TAG(7) 2128c2ecf20Sopenharmony_ci#define VLAN_ATTR(x) (((x) & 0x3) << 6) 2138c2ecf20Sopenharmony_ci#define VLAN_ATTR_MASK VLAN_ATTR(3) 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_cienum mt7530_vlan_port_eg_tag { 2168c2ecf20Sopenharmony_ci MT7530_VLAN_EG_DISABLED = 0, 2178c2ecf20Sopenharmony_ci MT7530_VLAN_EG_CONSISTENT = 1, 2188c2ecf20Sopenharmony_ci}; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_cienum mt7530_vlan_port_attr { 2218c2ecf20Sopenharmony_ci MT7530_VLAN_USER = 0, 2228c2ecf20Sopenharmony_ci MT7530_VLAN_TRANSPARENT = 3, 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci#define STAG_VPID (((x) & 0xffff) << 16) 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci/* Register for port port-and-protocol based vlan 1 control */ 2288c2ecf20Sopenharmony_ci#define MT7530_PPBV1_P(x) (0x2014 + ((x) * 0x100)) 2298c2ecf20Sopenharmony_ci#define G0_PORT_VID(x) (((x) & 0xfff) << 0) 2308c2ecf20Sopenharmony_ci#define G0_PORT_VID_MASK G0_PORT_VID(0xfff) 2318c2ecf20Sopenharmony_ci#define G0_PORT_VID_DEF G0_PORT_VID(1) 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci/* Register for port MAC control register */ 2348c2ecf20Sopenharmony_ci#define MT7530_PMCR_P(x) (0x3000 + ((x) * 0x100)) 2358c2ecf20Sopenharmony_ci#define PMCR_IFG_XMIT(x) (((x) & 0x3) << 18) 2368c2ecf20Sopenharmony_ci#define PMCR_EXT_PHY BIT(17) 2378c2ecf20Sopenharmony_ci#define PMCR_MAC_MODE BIT(16) 2388c2ecf20Sopenharmony_ci#define PMCR_FORCE_MODE BIT(15) 2398c2ecf20Sopenharmony_ci#define PMCR_TX_EN BIT(14) 2408c2ecf20Sopenharmony_ci#define PMCR_RX_EN BIT(13) 2418c2ecf20Sopenharmony_ci#define PMCR_BACKOFF_EN BIT(9) 2428c2ecf20Sopenharmony_ci#define PMCR_BACKPR_EN BIT(8) 2438c2ecf20Sopenharmony_ci#define PMCR_TX_FC_EN BIT(5) 2448c2ecf20Sopenharmony_ci#define PMCR_RX_FC_EN BIT(4) 2458c2ecf20Sopenharmony_ci#define PMCR_FORCE_SPEED_1000 BIT(3) 2468c2ecf20Sopenharmony_ci#define PMCR_FORCE_SPEED_100 BIT(2) 2478c2ecf20Sopenharmony_ci#define PMCR_FORCE_FDX BIT(1) 2488c2ecf20Sopenharmony_ci#define PMCR_FORCE_LNK BIT(0) 2498c2ecf20Sopenharmony_ci#define PMCR_SPEED_MASK (PMCR_FORCE_SPEED_100 | \ 2508c2ecf20Sopenharmony_ci PMCR_FORCE_SPEED_1000) 2518c2ecf20Sopenharmony_ci#define MT7531_FORCE_LNK BIT(31) 2528c2ecf20Sopenharmony_ci#define MT7531_FORCE_SPD BIT(30) 2538c2ecf20Sopenharmony_ci#define MT7531_FORCE_DPX BIT(29) 2548c2ecf20Sopenharmony_ci#define MT7531_FORCE_RX_FC BIT(28) 2558c2ecf20Sopenharmony_ci#define MT7531_FORCE_TX_FC BIT(27) 2568c2ecf20Sopenharmony_ci#define MT7531_FORCE_MODE (MT7531_FORCE_LNK | \ 2578c2ecf20Sopenharmony_ci MT7531_FORCE_SPD | \ 2588c2ecf20Sopenharmony_ci MT7531_FORCE_DPX | \ 2598c2ecf20Sopenharmony_ci MT7531_FORCE_RX_FC | \ 2608c2ecf20Sopenharmony_ci MT7531_FORCE_TX_FC) 2618c2ecf20Sopenharmony_ci#define PMCR_FORCE_MODE_ID(id) (((id) == ID_MT7531) ? \ 2628c2ecf20Sopenharmony_ci MT7531_FORCE_MODE : \ 2638c2ecf20Sopenharmony_ci PMCR_FORCE_MODE) 2648c2ecf20Sopenharmony_ci#define PMCR_LINK_SETTINGS_MASK (PMCR_TX_EN | PMCR_FORCE_SPEED_1000 | \ 2658c2ecf20Sopenharmony_ci PMCR_RX_EN | PMCR_FORCE_SPEED_100 | \ 2668c2ecf20Sopenharmony_ci PMCR_TX_FC_EN | PMCR_RX_FC_EN | \ 2678c2ecf20Sopenharmony_ci PMCR_FORCE_FDX | PMCR_FORCE_LNK) 2688c2ecf20Sopenharmony_ci#define PMCR_CPU_PORT_SETTING(id) (PMCR_FORCE_MODE_ID((id)) | \ 2698c2ecf20Sopenharmony_ci PMCR_IFG_XMIT(1) | PMCR_MAC_MODE | \ 2708c2ecf20Sopenharmony_ci PMCR_BACKOFF_EN | PMCR_BACKPR_EN | \ 2718c2ecf20Sopenharmony_ci PMCR_TX_EN | PMCR_RX_EN | \ 2728c2ecf20Sopenharmony_ci PMCR_TX_FC_EN | PMCR_RX_FC_EN | \ 2738c2ecf20Sopenharmony_ci PMCR_FORCE_SPEED_1000 | \ 2748c2ecf20Sopenharmony_ci PMCR_FORCE_FDX | PMCR_FORCE_LNK) 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci#define MT7530_PMSR_P(x) (0x3008 + (x) * 0x100) 2778c2ecf20Sopenharmony_ci#define PMSR_EEE1G BIT(7) 2788c2ecf20Sopenharmony_ci#define PMSR_EEE100M BIT(6) 2798c2ecf20Sopenharmony_ci#define PMSR_RX_FC BIT(5) 2808c2ecf20Sopenharmony_ci#define PMSR_TX_FC BIT(4) 2818c2ecf20Sopenharmony_ci#define PMSR_SPEED_1000 BIT(3) 2828c2ecf20Sopenharmony_ci#define PMSR_SPEED_100 BIT(2) 2838c2ecf20Sopenharmony_ci#define PMSR_SPEED_10 0x00 2848c2ecf20Sopenharmony_ci#define PMSR_SPEED_MASK (PMSR_SPEED_100 | PMSR_SPEED_1000) 2858c2ecf20Sopenharmony_ci#define PMSR_DPX BIT(1) 2868c2ecf20Sopenharmony_ci#define PMSR_LINK BIT(0) 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci/* Register for port debug count */ 2898c2ecf20Sopenharmony_ci#define MT7531_DBG_CNT(x) (0x3018 + (x) * 0x100) 2908c2ecf20Sopenharmony_ci#define MT7531_DIS_CLR BIT(31) 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci/* Register for MIB */ 2938c2ecf20Sopenharmony_ci#define MT7530_PORT_MIB_COUNTER(x) (0x4000 + (x) * 0x100) 2948c2ecf20Sopenharmony_ci#define MT7530_MIB_CCR 0x4fe0 2958c2ecf20Sopenharmony_ci#define CCR_MIB_ENABLE BIT(31) 2968c2ecf20Sopenharmony_ci#define CCR_RX_OCT_CNT_GOOD BIT(7) 2978c2ecf20Sopenharmony_ci#define CCR_RX_OCT_CNT_BAD BIT(6) 2988c2ecf20Sopenharmony_ci#define CCR_TX_OCT_CNT_GOOD BIT(5) 2998c2ecf20Sopenharmony_ci#define CCR_TX_OCT_CNT_BAD BIT(4) 3008c2ecf20Sopenharmony_ci#define CCR_MIB_FLUSH (CCR_RX_OCT_CNT_GOOD | \ 3018c2ecf20Sopenharmony_ci CCR_RX_OCT_CNT_BAD | \ 3028c2ecf20Sopenharmony_ci CCR_TX_OCT_CNT_GOOD | \ 3038c2ecf20Sopenharmony_ci CCR_TX_OCT_CNT_BAD) 3048c2ecf20Sopenharmony_ci#define CCR_MIB_ACTIVATE (CCR_MIB_ENABLE | \ 3058c2ecf20Sopenharmony_ci CCR_RX_OCT_CNT_GOOD | \ 3068c2ecf20Sopenharmony_ci CCR_RX_OCT_CNT_BAD | \ 3078c2ecf20Sopenharmony_ci CCR_TX_OCT_CNT_GOOD | \ 3088c2ecf20Sopenharmony_ci CCR_TX_OCT_CNT_BAD) 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci/* MT7531 SGMII register group */ 3118c2ecf20Sopenharmony_ci#define MT7531_SGMII_REG_BASE 0x5000 3128c2ecf20Sopenharmony_ci#define MT7531_SGMII_REG(p, r) (MT7531_SGMII_REG_BASE + \ 3138c2ecf20Sopenharmony_ci ((p) - 5) * 0x1000 + (r)) 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci/* Register forSGMII PCS_CONTROL_1 */ 3168c2ecf20Sopenharmony_ci#define MT7531_PCS_CONTROL_1(p) MT7531_SGMII_REG(p, 0x00) 3178c2ecf20Sopenharmony_ci#define MT7531_SGMII_LINK_STATUS BIT(18) 3188c2ecf20Sopenharmony_ci#define MT7531_SGMII_AN_ENABLE BIT(12) 3198c2ecf20Sopenharmony_ci#define MT7531_SGMII_AN_RESTART BIT(9) 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci/* Register for SGMII PCS_SPPED_ABILITY */ 3228c2ecf20Sopenharmony_ci#define MT7531_PCS_SPEED_ABILITY(p) MT7531_SGMII_REG(p, 0x08) 3238c2ecf20Sopenharmony_ci#define MT7531_SGMII_TX_CONFIG_MASK GENMASK(15, 0) 3248c2ecf20Sopenharmony_ci#define MT7531_SGMII_TX_CONFIG BIT(0) 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci/* Register for SGMII_MODE */ 3278c2ecf20Sopenharmony_ci#define MT7531_SGMII_MODE(p) MT7531_SGMII_REG(p, 0x20) 3288c2ecf20Sopenharmony_ci#define MT7531_SGMII_REMOTE_FAULT_DIS BIT(8) 3298c2ecf20Sopenharmony_ci#define MT7531_SGMII_IF_MODE_MASK GENMASK(5, 1) 3308c2ecf20Sopenharmony_ci#define MT7531_SGMII_FORCE_DUPLEX BIT(4) 3318c2ecf20Sopenharmony_ci#define MT7531_SGMII_FORCE_SPEED_MASK GENMASK(3, 2) 3328c2ecf20Sopenharmony_ci#define MT7531_SGMII_FORCE_SPEED_1000 BIT(3) 3338c2ecf20Sopenharmony_ci#define MT7531_SGMII_FORCE_SPEED_100 BIT(2) 3348c2ecf20Sopenharmony_ci#define MT7531_SGMII_FORCE_SPEED_10 0 3358c2ecf20Sopenharmony_ci#define MT7531_SGMII_SPEED_DUPLEX_AN BIT(1) 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_cienum mt7531_sgmii_force_duplex { 3388c2ecf20Sopenharmony_ci MT7531_SGMII_FORCE_FULL_DUPLEX = 0, 3398c2ecf20Sopenharmony_ci MT7531_SGMII_FORCE_HALF_DUPLEX = 0x10, 3408c2ecf20Sopenharmony_ci}; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci/* Fields of QPHY_PWR_STATE_CTRL */ 3438c2ecf20Sopenharmony_ci#define MT7531_QPHY_PWR_STATE_CTRL(p) MT7531_SGMII_REG(p, 0xe8) 3448c2ecf20Sopenharmony_ci#define MT7531_SGMII_PHYA_PWD BIT(4) 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci/* Values of SGMII SPEED */ 3478c2ecf20Sopenharmony_ci#define MT7531_PHYA_CTRL_SIGNAL3(p) MT7531_SGMII_REG(p, 0x128) 3488c2ecf20Sopenharmony_ci#define MT7531_RG_TPHY_SPEED_MASK (BIT(2) | BIT(3)) 3498c2ecf20Sopenharmony_ci#define MT7531_RG_TPHY_SPEED_1_25G 0x0 3508c2ecf20Sopenharmony_ci#define MT7531_RG_TPHY_SPEED_3_125G BIT(2) 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci/* Register for system reset */ 3538c2ecf20Sopenharmony_ci#define MT7530_SYS_CTRL 0x7000 3548c2ecf20Sopenharmony_ci#define SYS_CTRL_PHY_RST BIT(2) 3558c2ecf20Sopenharmony_ci#define SYS_CTRL_SW_RST BIT(1) 3568c2ecf20Sopenharmony_ci#define SYS_CTRL_REG_RST BIT(0) 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci/* Register for PHY Indirect Access Control */ 3598c2ecf20Sopenharmony_ci#define MT7531_PHY_IAC 0x701C 3608c2ecf20Sopenharmony_ci#define MT7531_PHY_ACS_ST BIT(31) 3618c2ecf20Sopenharmony_ci#define MT7531_MDIO_REG_ADDR_MASK (0x1f << 25) 3628c2ecf20Sopenharmony_ci#define MT7531_MDIO_PHY_ADDR_MASK (0x1f << 20) 3638c2ecf20Sopenharmony_ci#define MT7531_MDIO_CMD_MASK (0x3 << 18) 3648c2ecf20Sopenharmony_ci#define MT7531_MDIO_ST_MASK (0x3 << 16) 3658c2ecf20Sopenharmony_ci#define MT7531_MDIO_RW_DATA_MASK (0xffff) 3668c2ecf20Sopenharmony_ci#define MT7531_MDIO_REG_ADDR(x) (((x) & 0x1f) << 25) 3678c2ecf20Sopenharmony_ci#define MT7531_MDIO_DEV_ADDR(x) (((x) & 0x1f) << 25) 3688c2ecf20Sopenharmony_ci#define MT7531_MDIO_PHY_ADDR(x) (((x) & 0x1f) << 20) 3698c2ecf20Sopenharmony_ci#define MT7531_MDIO_CMD(x) (((x) & 0x3) << 18) 3708c2ecf20Sopenharmony_ci#define MT7531_MDIO_ST(x) (((x) & 0x3) << 16) 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_cienum mt7531_phy_iac_cmd { 3738c2ecf20Sopenharmony_ci MT7531_MDIO_ADDR = 0, 3748c2ecf20Sopenharmony_ci MT7531_MDIO_WRITE = 1, 3758c2ecf20Sopenharmony_ci MT7531_MDIO_READ = 2, 3768c2ecf20Sopenharmony_ci MT7531_MDIO_READ_CL45 = 3, 3778c2ecf20Sopenharmony_ci}; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci/* MDIO_ST: MDIO start field */ 3808c2ecf20Sopenharmony_cienum mt7531_mdio_st { 3818c2ecf20Sopenharmony_ci MT7531_MDIO_ST_CL45 = 0, 3828c2ecf20Sopenharmony_ci MT7531_MDIO_ST_CL22 = 1, 3838c2ecf20Sopenharmony_ci}; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci#define MT7531_MDIO_CL22_READ (MT7531_MDIO_ST(MT7531_MDIO_ST_CL22) | \ 3868c2ecf20Sopenharmony_ci MT7531_MDIO_CMD(MT7531_MDIO_READ)) 3878c2ecf20Sopenharmony_ci#define MT7531_MDIO_CL22_WRITE (MT7531_MDIO_ST(MT7531_MDIO_ST_CL22) | \ 3888c2ecf20Sopenharmony_ci MT7531_MDIO_CMD(MT7531_MDIO_WRITE)) 3898c2ecf20Sopenharmony_ci#define MT7531_MDIO_CL45_ADDR (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \ 3908c2ecf20Sopenharmony_ci MT7531_MDIO_CMD(MT7531_MDIO_ADDR)) 3918c2ecf20Sopenharmony_ci#define MT7531_MDIO_CL45_READ (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \ 3928c2ecf20Sopenharmony_ci MT7531_MDIO_CMD(MT7531_MDIO_READ)) 3938c2ecf20Sopenharmony_ci#define MT7531_MDIO_CL45_WRITE (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \ 3948c2ecf20Sopenharmony_ci MT7531_MDIO_CMD(MT7531_MDIO_WRITE)) 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci/* Register for RGMII clock phase */ 3978c2ecf20Sopenharmony_ci#define MT7531_CLKGEN_CTRL 0x7500 3988c2ecf20Sopenharmony_ci#define CLK_SKEW_OUT(x) (((x) & 0x3) << 8) 3998c2ecf20Sopenharmony_ci#define CLK_SKEW_OUT_MASK GENMASK(9, 8) 4008c2ecf20Sopenharmony_ci#define CLK_SKEW_IN(x) (((x) & 0x3) << 6) 4018c2ecf20Sopenharmony_ci#define CLK_SKEW_IN_MASK GENMASK(7, 6) 4028c2ecf20Sopenharmony_ci#define RXCLK_NO_DELAY BIT(5) 4038c2ecf20Sopenharmony_ci#define TXCLK_NO_REVERSE BIT(4) 4048c2ecf20Sopenharmony_ci#define GP_MODE(x) (((x) & 0x3) << 1) 4058c2ecf20Sopenharmony_ci#define GP_MODE_MASK GENMASK(2, 1) 4068c2ecf20Sopenharmony_ci#define GP_CLK_EN BIT(0) 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_cienum mt7531_gp_mode { 4098c2ecf20Sopenharmony_ci MT7531_GP_MODE_RGMII = 0, 4108c2ecf20Sopenharmony_ci MT7531_GP_MODE_MII = 1, 4118c2ecf20Sopenharmony_ci MT7531_GP_MODE_REV_MII = 2 4128c2ecf20Sopenharmony_ci}; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_cienum mt7531_clk_skew { 4158c2ecf20Sopenharmony_ci MT7531_CLK_SKEW_NO_CHG = 0, 4168c2ecf20Sopenharmony_ci MT7531_CLK_SKEW_DLY_100PPS = 1, 4178c2ecf20Sopenharmony_ci MT7531_CLK_SKEW_DLY_200PPS = 2, 4188c2ecf20Sopenharmony_ci MT7531_CLK_SKEW_REVERSE = 3, 4198c2ecf20Sopenharmony_ci}; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci/* Register for hw trap status */ 4228c2ecf20Sopenharmony_ci#define MT7530_HWTRAP 0x7800 4238c2ecf20Sopenharmony_ci#define HWTRAP_XTAL_MASK (BIT(10) | BIT(9)) 4248c2ecf20Sopenharmony_ci#define HWTRAP_XTAL_25MHZ (BIT(10) | BIT(9)) 4258c2ecf20Sopenharmony_ci#define HWTRAP_XTAL_40MHZ (BIT(10)) 4268c2ecf20Sopenharmony_ci#define HWTRAP_XTAL_20MHZ (BIT(9)) 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci#define MT7531_HWTRAP 0x7800 4298c2ecf20Sopenharmony_ci#define HWTRAP_XTAL_FSEL_MASK BIT(7) 4308c2ecf20Sopenharmony_ci#define HWTRAP_XTAL_FSEL_25MHZ BIT(7) 4318c2ecf20Sopenharmony_ci#define HWTRAP_XTAL_FSEL_40MHZ 0 4328c2ecf20Sopenharmony_ci/* Unique fields of (M)HWSTRAP for MT7531 */ 4338c2ecf20Sopenharmony_ci#define XTAL_FSEL_S 7 4348c2ecf20Sopenharmony_ci#define XTAL_FSEL_M BIT(7) 4358c2ecf20Sopenharmony_ci#define PHY_EN BIT(6) 4368c2ecf20Sopenharmony_ci#define CHG_STRAP BIT(8) 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci/* Register for hw trap modification */ 4398c2ecf20Sopenharmony_ci#define MT7530_MHWTRAP 0x7804 4408c2ecf20Sopenharmony_ci#define MHWTRAP_PHY0_SEL BIT(20) 4418c2ecf20Sopenharmony_ci#define MHWTRAP_MANUAL BIT(16) 4428c2ecf20Sopenharmony_ci#define MHWTRAP_P5_MAC_SEL BIT(13) 4438c2ecf20Sopenharmony_ci#define MHWTRAP_P6_DIS BIT(8) 4448c2ecf20Sopenharmony_ci#define MHWTRAP_P5_RGMII_MODE BIT(7) 4458c2ecf20Sopenharmony_ci#define MHWTRAP_P5_DIS BIT(6) 4468c2ecf20Sopenharmony_ci#define MHWTRAP_PHY_ACCESS BIT(5) 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci/* Register for TOP signal control */ 4498c2ecf20Sopenharmony_ci#define MT7530_TOP_SIG_CTRL 0x7808 4508c2ecf20Sopenharmony_ci#define TOP_SIG_CTRL_NORMAL (BIT(17) | BIT(16)) 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci#define MT7531_TOP_SIG_SR 0x780c 4538c2ecf20Sopenharmony_ci#define PAD_DUAL_SGMII_EN BIT(1) 4548c2ecf20Sopenharmony_ci#define PAD_MCM_SMI_EN BIT(0) 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci#define MT7530_IO_DRV_CR 0x7810 4578c2ecf20Sopenharmony_ci#define P5_IO_CLK_DRV(x) ((x) & 0x3) 4588c2ecf20Sopenharmony_ci#define P5_IO_DATA_DRV(x) (((x) & 0x3) << 4) 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci#define MT7531_CHIP_REV 0x781C 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci#define MT7531_PLLGP_EN 0x7820 4638c2ecf20Sopenharmony_ci#define EN_COREPLL BIT(2) 4648c2ecf20Sopenharmony_ci#define SW_CLKSW BIT(1) 4658c2ecf20Sopenharmony_ci#define SW_PLLGP BIT(0) 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci#define MT7530_P6ECR 0x7830 4688c2ecf20Sopenharmony_ci#define P6_INTF_MODE_MASK 0x3 4698c2ecf20Sopenharmony_ci#define P6_INTF_MODE(x) ((x) & 0x3) 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci#define MT7531_PLLGP_CR0 0x78a8 4728c2ecf20Sopenharmony_ci#define RG_COREPLL_EN BIT(22) 4738c2ecf20Sopenharmony_ci#define RG_COREPLL_POSDIV_S 23 4748c2ecf20Sopenharmony_ci#define RG_COREPLL_POSDIV_M 0x3800000 4758c2ecf20Sopenharmony_ci#define RG_COREPLL_SDM_PCW_S 1 4768c2ecf20Sopenharmony_ci#define RG_COREPLL_SDM_PCW_M 0x3ffffe 4778c2ecf20Sopenharmony_ci#define RG_COREPLL_SDM_PCW_CHG BIT(0) 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci/* Registers for RGMII and SGMII PLL clock */ 4808c2ecf20Sopenharmony_ci#define MT7531_ANA_PLLGP_CR2 0x78b0 4818c2ecf20Sopenharmony_ci#define MT7531_ANA_PLLGP_CR5 0x78bc 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci/* Registers for TRGMII on the both side */ 4848c2ecf20Sopenharmony_ci#define MT7530_TRGMII_RCK_CTRL 0x7a00 4858c2ecf20Sopenharmony_ci#define RX_RST BIT(31) 4868c2ecf20Sopenharmony_ci#define RXC_DQSISEL BIT(30) 4878c2ecf20Sopenharmony_ci#define DQSI1_TAP_MASK (0x7f << 8) 4888c2ecf20Sopenharmony_ci#define DQSI0_TAP_MASK 0x7f 4898c2ecf20Sopenharmony_ci#define DQSI1_TAP(x) (((x) & 0x7f) << 8) 4908c2ecf20Sopenharmony_ci#define DQSI0_TAP(x) ((x) & 0x7f) 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci#define MT7530_TRGMII_RCK_RTT 0x7a04 4938c2ecf20Sopenharmony_ci#define DQS1_GATE BIT(31) 4948c2ecf20Sopenharmony_ci#define DQS0_GATE BIT(30) 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci#define MT7530_TRGMII_RD(x) (0x7a10 + (x) * 8) 4978c2ecf20Sopenharmony_ci#define BSLIP_EN BIT(31) 4988c2ecf20Sopenharmony_ci#define EDGE_CHK BIT(30) 4998c2ecf20Sopenharmony_ci#define RD_TAP_MASK 0x7f 5008c2ecf20Sopenharmony_ci#define RD_TAP(x) ((x) & 0x7f) 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci#define MT7530_TRGMII_TXCTRL 0x7a40 5038c2ecf20Sopenharmony_ci#define TRAIN_TXEN BIT(31) 5048c2ecf20Sopenharmony_ci#define TXC_INV BIT(30) 5058c2ecf20Sopenharmony_ci#define TX_RST BIT(28) 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci#define MT7530_TRGMII_TD_ODT(i) (0x7a54 + 8 * (i)) 5088c2ecf20Sopenharmony_ci#define TD_DM_DRVP(x) ((x) & 0xf) 5098c2ecf20Sopenharmony_ci#define TD_DM_DRVN(x) (((x) & 0xf) << 4) 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci#define MT7530_TRGMII_TCK_CTRL 0x7a78 5128c2ecf20Sopenharmony_ci#define TCK_TAP(x) (((x) & 0xf) << 8) 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci#define MT7530_P5RGMIIRXCR 0x7b00 5158c2ecf20Sopenharmony_ci#define CSR_RGMII_EDGE_ALIGN BIT(8) 5168c2ecf20Sopenharmony_ci#define CSR_RGMII_RXC_0DEG_CFG(x) ((x) & 0xf) 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci#define MT7530_P5RGMIITXCR 0x7b04 5198c2ecf20Sopenharmony_ci#define CSR_RGMII_TXC_CFG(x) ((x) & 0x1f) 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci/* Registers for GPIO mode */ 5228c2ecf20Sopenharmony_ci#define MT7531_GPIO_MODE0 0x7c0c 5238c2ecf20Sopenharmony_ci#define MT7531_GPIO0_MASK GENMASK(3, 0) 5248c2ecf20Sopenharmony_ci#define MT7531_GPIO0_INTERRUPT 1 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci#define MT7531_GPIO_MODE1 0x7c10 5278c2ecf20Sopenharmony_ci#define MT7531_GPIO11_RG_RXD2_MASK GENMASK(15, 12) 5288c2ecf20Sopenharmony_ci#define MT7531_EXT_P_MDC_11 (2 << 12) 5298c2ecf20Sopenharmony_ci#define MT7531_GPIO12_RG_RXD3_MASK GENMASK(19, 16) 5308c2ecf20Sopenharmony_ci#define MT7531_EXT_P_MDIO_12 (2 << 16) 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci#define MT7530_CREV 0x7ffc 5338c2ecf20Sopenharmony_ci#define CHIP_NAME_SHIFT 16 5348c2ecf20Sopenharmony_ci#define MT7530_ID 0x7530 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci#define MT7531_CREV 0x781C 5378c2ecf20Sopenharmony_ci#define CHIP_REV_M 0x0f 5388c2ecf20Sopenharmony_ci#define MT7531_ID 0x7531 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci/* Registers for core PLL access through mmd indirect */ 5418c2ecf20Sopenharmony_ci#define CORE_PLL_GROUP2 0x401 5428c2ecf20Sopenharmony_ci#define RG_SYSPLL_EN_NORMAL BIT(15) 5438c2ecf20Sopenharmony_ci#define RG_SYSPLL_VODEN BIT(14) 5448c2ecf20Sopenharmony_ci#define RG_SYSPLL_LF BIT(13) 5458c2ecf20Sopenharmony_ci#define RG_SYSPLL_RST_DLY(x) (((x) & 0x3) << 12) 5468c2ecf20Sopenharmony_ci#define RG_SYSPLL_LVROD_EN BIT(10) 5478c2ecf20Sopenharmony_ci#define RG_SYSPLL_PREDIV(x) (((x) & 0x3) << 8) 5488c2ecf20Sopenharmony_ci#define RG_SYSPLL_POSDIV(x) (((x) & 0x3) << 5) 5498c2ecf20Sopenharmony_ci#define RG_SYSPLL_FBKSEL BIT(4) 5508c2ecf20Sopenharmony_ci#define RT_SYSPLL_EN_AFE_OLT BIT(0) 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci#define CORE_PLL_GROUP4 0x403 5538c2ecf20Sopenharmony_ci#define RG_SYSPLL_DDSFBK_EN BIT(12) 5548c2ecf20Sopenharmony_ci#define RG_SYSPLL_BIAS_EN BIT(11) 5558c2ecf20Sopenharmony_ci#define RG_SYSPLL_BIAS_LPF_EN BIT(10) 5568c2ecf20Sopenharmony_ci#define MT7531_PHY_PLL_OFF BIT(5) 5578c2ecf20Sopenharmony_ci#define MT7531_PHY_PLL_BYPASS_MODE BIT(4) 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci#define MT753X_CTRL_PHY_ADDR 0 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci#define CORE_PLL_GROUP5 0x404 5628c2ecf20Sopenharmony_ci#define RG_LCDDS_PCW_NCPO1(x) ((x) & 0xffff) 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci#define CORE_PLL_GROUP6 0x405 5658c2ecf20Sopenharmony_ci#define RG_LCDDS_PCW_NCPO0(x) ((x) & 0xffff) 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci#define CORE_PLL_GROUP7 0x406 5688c2ecf20Sopenharmony_ci#define RG_LCDDS_PWDB BIT(15) 5698c2ecf20Sopenharmony_ci#define RG_LCDDS_ISO_EN BIT(13) 5708c2ecf20Sopenharmony_ci#define RG_LCCDS_C(x) (((x) & 0x7) << 4) 5718c2ecf20Sopenharmony_ci#define RG_LCDDS_PCW_NCPO_CHG BIT(3) 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci#define CORE_PLL_GROUP10 0x409 5748c2ecf20Sopenharmony_ci#define RG_LCDDS_SSC_DELTA(x) ((x) & 0xfff) 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci#define CORE_PLL_GROUP11 0x40a 5778c2ecf20Sopenharmony_ci#define RG_LCDDS_SSC_DELTA1(x) ((x) & 0xfff) 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci#define CORE_GSWPLL_GRP1 0x40d 5808c2ecf20Sopenharmony_ci#define RG_GSWPLL_PREDIV(x) (((x) & 0x3) << 14) 5818c2ecf20Sopenharmony_ci#define RG_GSWPLL_POSDIV_200M(x) (((x) & 0x3) << 12) 5828c2ecf20Sopenharmony_ci#define RG_GSWPLL_EN_PRE BIT(11) 5838c2ecf20Sopenharmony_ci#define RG_GSWPLL_FBKSEL BIT(10) 5848c2ecf20Sopenharmony_ci#define RG_GSWPLL_BP BIT(9) 5858c2ecf20Sopenharmony_ci#define RG_GSWPLL_BR BIT(8) 5868c2ecf20Sopenharmony_ci#define RG_GSWPLL_FBKDIV_200M(x) ((x) & 0xff) 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci#define CORE_GSWPLL_GRP2 0x40e 5898c2ecf20Sopenharmony_ci#define RG_GSWPLL_POSDIV_500M(x) (((x) & 0x3) << 8) 5908c2ecf20Sopenharmony_ci#define RG_GSWPLL_FBKDIV_500M(x) ((x) & 0xff) 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci#define CORE_TRGMII_GSW_CLK_CG 0x410 5938c2ecf20Sopenharmony_ci#define REG_GSWCK_EN BIT(0) 5948c2ecf20Sopenharmony_ci#define REG_TRGMIICK_EN BIT(1) 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci#define MIB_DESC(_s, _o, _n) \ 5978c2ecf20Sopenharmony_ci { \ 5988c2ecf20Sopenharmony_ci .size = (_s), \ 5998c2ecf20Sopenharmony_ci .offset = (_o), \ 6008c2ecf20Sopenharmony_ci .name = (_n), \ 6018c2ecf20Sopenharmony_ci } 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_cistruct mt7530_mib_desc { 6048c2ecf20Sopenharmony_ci unsigned int size; 6058c2ecf20Sopenharmony_ci unsigned int offset; 6068c2ecf20Sopenharmony_ci const char *name; 6078c2ecf20Sopenharmony_ci}; 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_cistruct mt7530_fdb { 6108c2ecf20Sopenharmony_ci u16 vid; 6118c2ecf20Sopenharmony_ci u8 port_mask; 6128c2ecf20Sopenharmony_ci u8 aging; 6138c2ecf20Sopenharmony_ci u8 mac[6]; 6148c2ecf20Sopenharmony_ci bool noarp; 6158c2ecf20Sopenharmony_ci}; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci/* struct mt7530_port - This is the main data structure for holding the state 6188c2ecf20Sopenharmony_ci * of the port. 6198c2ecf20Sopenharmony_ci * @enable: The status used for show port is enabled or not. 6208c2ecf20Sopenharmony_ci * @pm: The matrix used to show all connections with the port. 6218c2ecf20Sopenharmony_ci * @pvid: The VLAN specified is to be considered a PVID at ingress. Any 6228c2ecf20Sopenharmony_ci * untagged frames will be assigned to the related VLAN. 6238c2ecf20Sopenharmony_ci * @vlan_filtering: The flags indicating whether the port that can recognize 6248c2ecf20Sopenharmony_ci * VLAN-tagged frames. 6258c2ecf20Sopenharmony_ci */ 6268c2ecf20Sopenharmony_cistruct mt7530_port { 6278c2ecf20Sopenharmony_ci bool enable; 6288c2ecf20Sopenharmony_ci u32 pm; 6298c2ecf20Sopenharmony_ci u16 pvid; 6308c2ecf20Sopenharmony_ci}; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci/* Port 5 interface select definitions */ 6338c2ecf20Sopenharmony_cienum p5_interface_select { 6348c2ecf20Sopenharmony_ci P5_DISABLED = 0, 6358c2ecf20Sopenharmony_ci P5_INTF_SEL_PHY_P0, 6368c2ecf20Sopenharmony_ci P5_INTF_SEL_PHY_P4, 6378c2ecf20Sopenharmony_ci P5_INTF_SEL_GMAC5, 6388c2ecf20Sopenharmony_ci P5_INTF_SEL_GMAC5_SGMII, 6398c2ecf20Sopenharmony_ci}; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_cistatic const char *p5_intf_modes(unsigned int p5_interface) 6428c2ecf20Sopenharmony_ci{ 6438c2ecf20Sopenharmony_ci switch (p5_interface) { 6448c2ecf20Sopenharmony_ci case P5_DISABLED: 6458c2ecf20Sopenharmony_ci return "DISABLED"; 6468c2ecf20Sopenharmony_ci case P5_INTF_SEL_PHY_P0: 6478c2ecf20Sopenharmony_ci return "PHY P0"; 6488c2ecf20Sopenharmony_ci case P5_INTF_SEL_PHY_P4: 6498c2ecf20Sopenharmony_ci return "PHY P4"; 6508c2ecf20Sopenharmony_ci case P5_INTF_SEL_GMAC5: 6518c2ecf20Sopenharmony_ci return "GMAC5"; 6528c2ecf20Sopenharmony_ci case P5_INTF_SEL_GMAC5_SGMII: 6538c2ecf20Sopenharmony_ci return "GMAC5_SGMII"; 6548c2ecf20Sopenharmony_ci default: 6558c2ecf20Sopenharmony_ci return "unknown"; 6568c2ecf20Sopenharmony_ci } 6578c2ecf20Sopenharmony_ci} 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci/* struct mt753x_info - This is the main data structure for holding the specific 6608c2ecf20Sopenharmony_ci * part for each supported device 6618c2ecf20Sopenharmony_ci * @sw_setup: Holding the handler to a device initialization 6628c2ecf20Sopenharmony_ci * @phy_read: Holding the way reading PHY port 6638c2ecf20Sopenharmony_ci * @phy_write: Holding the way writing PHY port 6648c2ecf20Sopenharmony_ci * @pad_setup: Holding the way setting up the bus pad for a certain 6658c2ecf20Sopenharmony_ci * MAC port 6668c2ecf20Sopenharmony_ci * @phy_mode_supported: Check if the PHY type is being supported on a certain 6678c2ecf20Sopenharmony_ci * port 6688c2ecf20Sopenharmony_ci * @mac_port_validate: Holding the way to set addition validate type for a 6698c2ecf20Sopenharmony_ci * certan MAC port 6708c2ecf20Sopenharmony_ci * @mac_port_get_state: Holding the way getting the MAC/PCS state for a certain 6718c2ecf20Sopenharmony_ci * MAC port 6728c2ecf20Sopenharmony_ci * @mac_port_config: Holding the way setting up the PHY attribute to a 6738c2ecf20Sopenharmony_ci * certain MAC port 6748c2ecf20Sopenharmony_ci * @mac_pcs_an_restart Holding the way restarting PCS autonegotiation for a 6758c2ecf20Sopenharmony_ci * certain MAC port 6768c2ecf20Sopenharmony_ci * @mac_pcs_link_up: Holding the way setting up the PHY attribute to the pcs 6778c2ecf20Sopenharmony_ci * of the certain MAC port 6788c2ecf20Sopenharmony_ci */ 6798c2ecf20Sopenharmony_cistruct mt753x_info { 6808c2ecf20Sopenharmony_ci enum mt753x_id id; 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci int (*sw_setup)(struct dsa_switch *ds); 6838c2ecf20Sopenharmony_ci int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 6848c2ecf20Sopenharmony_ci int (*phy_write)(struct dsa_switch *ds, int port, int regnum, u16 val); 6858c2ecf20Sopenharmony_ci int (*pad_setup)(struct dsa_switch *ds, phy_interface_t interface); 6868c2ecf20Sopenharmony_ci int (*cpu_port_config)(struct dsa_switch *ds, int port); 6878c2ecf20Sopenharmony_ci bool (*phy_mode_supported)(struct dsa_switch *ds, int port, 6888c2ecf20Sopenharmony_ci const struct phylink_link_state *state); 6898c2ecf20Sopenharmony_ci void (*mac_port_validate)(struct dsa_switch *ds, int port, 6908c2ecf20Sopenharmony_ci unsigned long *supported); 6918c2ecf20Sopenharmony_ci int (*mac_port_get_state)(struct dsa_switch *ds, int port, 6928c2ecf20Sopenharmony_ci struct phylink_link_state *state); 6938c2ecf20Sopenharmony_ci int (*mac_port_config)(struct dsa_switch *ds, int port, 6948c2ecf20Sopenharmony_ci unsigned int mode, 6958c2ecf20Sopenharmony_ci phy_interface_t interface); 6968c2ecf20Sopenharmony_ci void (*mac_pcs_an_restart)(struct dsa_switch *ds, int port); 6978c2ecf20Sopenharmony_ci void (*mac_pcs_link_up)(struct dsa_switch *ds, int port, 6988c2ecf20Sopenharmony_ci unsigned int mode, phy_interface_t interface, 6998c2ecf20Sopenharmony_ci int speed, int duplex); 7008c2ecf20Sopenharmony_ci}; 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci/* struct mt7530_priv - This is the main data structure for holding the state 7038c2ecf20Sopenharmony_ci * of the driver 7048c2ecf20Sopenharmony_ci * @dev: The device pointer 7058c2ecf20Sopenharmony_ci * @ds: The pointer to the dsa core structure 7068c2ecf20Sopenharmony_ci * @bus: The bus used for the device and built-in PHY 7078c2ecf20Sopenharmony_ci * @rstc: The pointer to reset control used by MCM 7088c2ecf20Sopenharmony_ci * @core_pwr: The power supplied into the core 7098c2ecf20Sopenharmony_ci * @io_pwr: The power supplied into the I/O 7108c2ecf20Sopenharmony_ci * @reset: The descriptor for GPIO line tied to its reset pin 7118c2ecf20Sopenharmony_ci * @mcm: Flag for distinguishing if standalone IC or module 7128c2ecf20Sopenharmony_ci * coupling 7138c2ecf20Sopenharmony_ci * @ports: Holding the state among ports 7148c2ecf20Sopenharmony_ci * @reg_mutex: The lock for protecting among process accessing 7158c2ecf20Sopenharmony_ci * registers 7168c2ecf20Sopenharmony_ci * @p6_interface Holding the current port 6 interface 7178c2ecf20Sopenharmony_ci * @p5_intf_sel: Holding the current port 5 interface select 7188c2ecf20Sopenharmony_ci */ 7198c2ecf20Sopenharmony_cistruct mt7530_priv { 7208c2ecf20Sopenharmony_ci struct device *dev; 7218c2ecf20Sopenharmony_ci struct dsa_switch *ds; 7228c2ecf20Sopenharmony_ci struct mii_bus *bus; 7238c2ecf20Sopenharmony_ci struct reset_control *rstc; 7248c2ecf20Sopenharmony_ci struct regulator *core_pwr; 7258c2ecf20Sopenharmony_ci struct regulator *io_pwr; 7268c2ecf20Sopenharmony_ci struct gpio_desc *reset; 7278c2ecf20Sopenharmony_ci const struct mt753x_info *info; 7288c2ecf20Sopenharmony_ci unsigned int id; 7298c2ecf20Sopenharmony_ci bool mcm; 7308c2ecf20Sopenharmony_ci phy_interface_t p6_interface; 7318c2ecf20Sopenharmony_ci phy_interface_t p5_interface; 7328c2ecf20Sopenharmony_ci unsigned int p5_intf_sel; 7338c2ecf20Sopenharmony_ci u8 mirror_rx; 7348c2ecf20Sopenharmony_ci u8 mirror_tx; 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci struct mt7530_port ports[MT7530_NUM_PORTS]; 7378c2ecf20Sopenharmony_ci /* protect among processes for registers access*/ 7388c2ecf20Sopenharmony_ci struct mutex reg_mutex; 7398c2ecf20Sopenharmony_ci}; 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_cistruct mt7530_hw_vlan_entry { 7428c2ecf20Sopenharmony_ci int port; 7438c2ecf20Sopenharmony_ci u8 old_members; 7448c2ecf20Sopenharmony_ci bool untagged; 7458c2ecf20Sopenharmony_ci}; 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_cistatic inline void mt7530_hw_vlan_entry_init(struct mt7530_hw_vlan_entry *e, 7488c2ecf20Sopenharmony_ci int port, bool untagged) 7498c2ecf20Sopenharmony_ci{ 7508c2ecf20Sopenharmony_ci e->port = port; 7518c2ecf20Sopenharmony_ci e->untagged = untagged; 7528c2ecf20Sopenharmony_ci} 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_citypedef void (*mt7530_vlan_op)(struct mt7530_priv *, 7558c2ecf20Sopenharmony_ci struct mt7530_hw_vlan_entry *); 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_cistruct mt7530_hw_stats { 7588c2ecf20Sopenharmony_ci const char *string; 7598c2ecf20Sopenharmony_ci u16 reg; 7608c2ecf20Sopenharmony_ci u8 sizeof_stat; 7618c2ecf20Sopenharmony_ci}; 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_cistruct mt7530_dummy_poll { 7648c2ecf20Sopenharmony_ci struct mt7530_priv *priv; 7658c2ecf20Sopenharmony_ci u32 reg; 7668c2ecf20Sopenharmony_ci}; 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_cistatic inline void INIT_MT7530_DUMMY_POLL(struct mt7530_dummy_poll *p, 7698c2ecf20Sopenharmony_ci struct mt7530_priv *priv, u32 reg) 7708c2ecf20Sopenharmony_ci{ 7718c2ecf20Sopenharmony_ci p->priv = priv; 7728c2ecf20Sopenharmony_ci p->reg = reg; 7738c2ecf20Sopenharmony_ci} 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci#endif /* __MT7530_H */ 776