developer | 29d9d9f | 2025-01-10 16:41:13 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (C) 2025 MediaTek Inc. |
| 4 | * |
| 5 | * Author: Weijie Gao <weijie.gao@mediatek.com> |
| 6 | * Author: Mark Lee <mark-mc.lee@mediatek.com> |
| 7 | */ |
| 8 | |
| 9 | #ifndef _MTK_ETH_MT753X_H_ |
| 10 | #define _MTK_ETH_MT753X_H_ |
| 11 | |
| 12 | #include <phy.h> |
| 13 | #include <miiphy.h> |
| 14 | #include <linux/bitops.h> |
| 15 | #include <linux/bitfield.h> |
| 16 | |
| 17 | struct mtk_eth_priv; |
| 18 | |
| 19 | #define MT753X_NUM_PHYS 5 |
| 20 | #define MT753X_NUM_PORTS 7 |
| 21 | #define MT753X_DFL_SMI_ADDR 31 |
| 22 | #define MT753X_SMI_ADDR_MASK 0x1f |
| 23 | |
| 24 | #define MT753X_PHY_ADDR(base, addr) \ |
| 25 | (((base) + (addr)) & 0x1f) |
| 26 | |
| 27 | /* MT7530 Registers */ |
| 28 | #define PCR_REG(p) (0x2004 + (p) * 0x100) |
| 29 | #define PORT_MATRIX_S 16 |
| 30 | #define PORT_MATRIX_M 0xff0000 |
| 31 | |
| 32 | #define PVC_REG(p) (0x2010 + (p) * 0x100) |
| 33 | #define STAG_VPID_S 16 |
| 34 | #define STAG_VPID_M 0xffff0000 |
| 35 | #define VLAN_ATTR_S 6 |
| 36 | #define VLAN_ATTR_M 0xc0 |
| 37 | |
| 38 | /* VLAN_ATTR: VLAN attributes */ |
| 39 | #define VLAN_ATTR_USER 0 |
| 40 | #define VLAN_ATTR_STACK 1 |
| 41 | #define VLAN_ATTR_TRANSLATION 2 |
| 42 | #define VLAN_ATTR_TRANSPARENT 3 |
| 43 | |
| 44 | #define PMCR_REG(p) (0x3000 + (p) * 0x100) |
| 45 | /* XXX: all fields of MT7530 are defined under GMAC_PORT_MCR |
| 46 | * MT7531 specific fields are defined below |
| 47 | */ |
| 48 | #define FORCE_MODE_EEE1G BIT(25) |
| 49 | #define FORCE_MODE_EEE100 BIT(26) |
| 50 | #define FORCE_MODE_TX_FC BIT(27) |
| 51 | #define FORCE_MODE_RX_FC BIT(28) |
| 52 | #define FORCE_MODE_DPX BIT(29) |
| 53 | #define FORCE_MODE_SPD BIT(30) |
| 54 | #define FORCE_MODE_LNK BIT(31) |
| 55 | #define MT7531_FORCE_MODE FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \ |
| 56 | FORCE_MODE_DPX | FORCE_MODE_SPD | \ |
| 57 | FORCE_MODE_LNK |
| 58 | #define MT7988_FORCE_MODE FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \ |
| 59 | FORCE_MODE_DPX | FORCE_MODE_SPD | \ |
| 60 | FORCE_MODE_LNK |
| 61 | |
| 62 | /* MT7531 SGMII Registers */ |
| 63 | #define MT7531_SGMII_REG_BASE 0x5000 |
| 64 | #define MT7531_SGMII_REG_PORT_BASE 0x1000 |
| 65 | #define MT7531_SGMII_REG(p, r) (MT7531_SGMII_REG_BASE + \ |
| 66 | (p) * MT7531_SGMII_REG_PORT_BASE + (r)) |
| 67 | #define MT7531_PCS_CONTROL_1(p) MT7531_SGMII_REG(((p) - 5), 0x00) |
| 68 | #define MT7531_SGMII_MODE(p) MT7531_SGMII_REG(((p) - 5), 0x20) |
| 69 | #define MT7531_QPHY_PWR_STATE_CTRL(p) MT7531_SGMII_REG(((p) - 5), 0xe8) |
| 70 | #define MT7531_PHYA_CTRL_SIGNAL3(p) MT7531_SGMII_REG(((p) - 5), 0x128) |
| 71 | #define MT7531_PHYA_ANA_SYSPLL(p) MT7531_SGMII_REG(((p) - 5), 0x158) |
| 72 | /* XXX: all fields of MT7531 SGMII are defined under SGMSYS */ |
| 73 | |
| 74 | /* MT753x System Control Register */ |
| 75 | #define SYS_CTRL_REG 0x7000 |
| 76 | #define SW_PHY_RST BIT(2) |
| 77 | #define SW_SYS_RST BIT(1) |
| 78 | #define SW_REG_RST BIT(0) |
| 79 | |
| 80 | /* MT7531 */ |
| 81 | #define MT7531_PHY_IAC 0x701c |
| 82 | /* XXX: all fields are defined under GMAC_PIAC_REG */ |
| 83 | |
| 84 | #define MT7531_CLKGEN_CTRL 0x7500 |
| 85 | #define CLK_SKEW_OUT_S 8 |
| 86 | #define CLK_SKEW_OUT_M 0x300 |
| 87 | #define CLK_SKEW_IN_S 6 |
| 88 | #define CLK_SKEW_IN_M 0xc0 |
| 89 | #define RXCLK_NO_DELAY BIT(5) |
| 90 | #define TXCLK_NO_REVERSE BIT(4) |
| 91 | #define GP_MODE_S 1 |
| 92 | #define GP_MODE_M 0x06 |
| 93 | #define GP_CLK_EN BIT(0) |
| 94 | |
| 95 | /* Values of GP_MODE */ |
| 96 | #define GP_MODE_RGMII 0 |
| 97 | #define GP_MODE_MII 1 |
| 98 | #define GP_MODE_REV_MII 2 |
| 99 | |
| 100 | /* Values of CLK_SKEW_IN */ |
| 101 | #define CLK_SKEW_IN_NO_CHANGE 0 |
| 102 | #define CLK_SKEW_IN_DELAY_100PPS 1 |
| 103 | #define CLK_SKEW_IN_DELAY_200PPS 2 |
| 104 | #define CLK_SKEW_IN_REVERSE 3 |
| 105 | |
| 106 | /* Values of CLK_SKEW_OUT */ |
| 107 | #define CLK_SKEW_OUT_NO_CHANGE 0 |
| 108 | #define CLK_SKEW_OUT_DELAY_100PPS 1 |
| 109 | #define CLK_SKEW_OUT_DELAY_200PPS 2 |
| 110 | #define CLK_SKEW_OUT_REVERSE 3 |
| 111 | |
| 112 | #define HWTRAP_REG 0x7800 |
| 113 | /* MT7530 Modified Hardware Trap Status Registers */ |
| 114 | #define MHWTRAP_REG 0x7804 |
| 115 | #define CHG_TRAP BIT(16) |
| 116 | #define LOOPDET_DIS BIT(14) |
| 117 | #define P5_INTF_SEL_S 13 |
| 118 | #define P5_INTF_SEL_M 0x2000 |
| 119 | #define SMI_ADDR_S 11 |
| 120 | #define SMI_ADDR_M 0x1800 |
| 121 | #define XTAL_FSEL_S 9 |
| 122 | #define XTAL_FSEL_M 0x600 |
| 123 | #define P6_INTF_DIS BIT(8) |
| 124 | #define P5_INTF_MODE_S 7 |
| 125 | #define P5_INTF_MODE_M 0x80 |
| 126 | #define P5_INTF_DIS BIT(6) |
| 127 | #define C_MDIO_BPS BIT(5) |
| 128 | #define CHIP_MODE_S 0 |
| 129 | #define CHIP_MODE_M 0x0f |
| 130 | |
| 131 | /* P5_INTF_SEL: Interface type of Port5 */ |
| 132 | #define P5_INTF_SEL_GPHY 0 |
| 133 | #define P5_INTF_SEL_GMAC5 1 |
| 134 | |
| 135 | /* P5_INTF_MODE: Interface mode of Port5 */ |
| 136 | #define P5_INTF_MODE_GMII_MII 0 |
| 137 | #define P5_INTF_MODE_RGMII 1 |
| 138 | |
| 139 | #define MT7530_P6ECR 0x7830 |
| 140 | #define P6_INTF_MODE_M 0x3 |
| 141 | #define P6_INTF_MODE_S 0 |
| 142 | |
| 143 | /* P6_INTF_MODE: Interface mode of Port6 */ |
| 144 | #define P6_INTF_MODE_RGMII 0 |
| 145 | #define P6_INTF_MODE_TRGMII 1 |
| 146 | |
| 147 | #define MT7530_TRGMII_RD(n) (0x7a10 + (n) * 8) |
| 148 | #define RD_TAP_S 0 |
| 149 | #define RD_TAP_M 0x7f |
| 150 | |
| 151 | #define MT7530_TRGMII_TD_ODT(n) (0x7a54 + (n) * 8) |
| 152 | /* XXX: all fields are defined under GMAC_TRGMII_TD_ODT */ |
| 153 | |
| 154 | /* TOP Signals Status Register */ |
| 155 | #define MT7531_TOP_SIG_SR 0x780c |
| 156 | #define PAD_MCM_SMI_EN BIT(0) |
| 157 | #define PAD_DUAL_SGMII_EN BIT(1) |
| 158 | |
| 159 | /* MT7531 PLLGP Registers */ |
| 160 | #define MT7531_PLLGP_EN 0x7820 |
| 161 | #define EN_COREPLL BIT(2) |
| 162 | #define SW_CLKSW BIT(1) |
| 163 | #define SW_PLLGP BIT(0) |
| 164 | |
| 165 | #define MT7531_PLLGP_CR0 0x78a8 |
| 166 | #define RG_COREPLL_EN BIT(22) |
| 167 | #define RG_COREPLL_POSDIV_S 23 |
| 168 | #define RG_COREPLL_POSDIV_M 0x3800000 |
| 169 | #define RG_COREPLL_SDM_PCW_S 1 |
| 170 | #define RG_COREPLL_SDM_PCW_M 0x3ffffe |
| 171 | #define RG_COREPLL_SDM_PCW_CHG BIT(0) |
| 172 | |
| 173 | /* MT7531 RGMII and SGMII PLL clock */ |
| 174 | #define MT7531_ANA_PLLGP_CR2 0x78b0 |
| 175 | #define MT7531_ANA_PLLGP_CR5 0x78bc |
| 176 | |
| 177 | /* MT7531 GPIO GROUP IOLB SMT0 Control */ |
| 178 | #define MT7531_SMT0_IOLB 0x7f04 |
| 179 | #define SMT_IOLB_5_SMI_MDC_EN BIT(5) |
| 180 | |
| 181 | /* MT7530 GPHY MDIO MMD Registers */ |
| 182 | #define CORE_PLL_GROUP2 0x401 |
| 183 | #define RG_SYSPLL_EN_NORMAL BIT(15) |
| 184 | #define RG_SYSPLL_VODEN BIT(14) |
| 185 | #define RG_SYSPLL_POSDIV_S 5 |
| 186 | #define RG_SYSPLL_POSDIV_M 0x60 |
| 187 | |
| 188 | #define CORE_PLL_GROUP4 0x403 |
| 189 | #define MT7531_BYPASS_MODE BIT(4) |
| 190 | #define MT7531_POWER_ON_OFF BIT(5) |
| 191 | #define RG_SYSPLL_DDSFBK_EN BIT(12) |
| 192 | #define RG_SYSPLL_BIAS_EN BIT(11) |
| 193 | #define RG_SYSPLL_BIAS_LPF_EN BIT(10) |
| 194 | |
| 195 | #define CORE_PLL_GROUP5 0x404 |
| 196 | #define RG_LCDDS_PCW_NCPO1_S 0 |
| 197 | #define RG_LCDDS_PCW_NCPO1_M 0xffff |
| 198 | |
| 199 | #define CORE_PLL_GROUP6 0x405 |
| 200 | #define RG_LCDDS_PCW_NCPO0_S 0 |
| 201 | #define RG_LCDDS_PCW_NCPO0_M 0xffff |
| 202 | |
| 203 | #define CORE_PLL_GROUP7 0x406 |
| 204 | #define RG_LCDDS_PWDB BIT(15) |
| 205 | #define RG_LCDDS_ISO_EN BIT(13) |
| 206 | #define RG_LCCDS_C_S 4 |
| 207 | #define RG_LCCDS_C_M 0x70 |
| 208 | #define RG_LCDDS_PCW_NCPO_CHG BIT(3) |
| 209 | |
| 210 | #define CORE_PLL_GROUP10 0x409 |
| 211 | #define RG_LCDDS_SSC_DELTA_S 0 |
| 212 | #define RG_LCDDS_SSC_DELTA_M 0xfff |
| 213 | |
| 214 | #define CORE_PLL_GROUP11 0x40a |
| 215 | #define RG_LCDDS_SSC_DELTA1_S 0 |
| 216 | #define RG_LCDDS_SSC_DELTA1_M 0xfff |
| 217 | |
| 218 | #define CORE_GSWPLL_GRP1 0x40d |
| 219 | #define RG_GSWPLL_POSDIV_200M_S 12 |
| 220 | #define RG_GSWPLL_POSDIV_200M_M 0x3000 |
| 221 | #define RG_GSWPLL_EN_PRE BIT(11) |
| 222 | #define RG_GSWPLL_FBKDIV_200M_S 0 |
| 223 | #define RG_GSWPLL_FBKDIV_200M_M 0xff |
| 224 | |
| 225 | #define CORE_GSWPLL_GRP2 0x40e |
| 226 | #define RG_GSWPLL_POSDIV_500M_S 8 |
| 227 | #define RG_GSWPLL_POSDIV_500M_M 0x300 |
| 228 | #define RG_GSWPLL_FBKDIV_500M_S 0 |
| 229 | #define RG_GSWPLL_FBKDIV_500M_M 0xff |
| 230 | |
| 231 | #define CORE_TRGMII_GSW_CLK_CG 0x410 |
| 232 | #define REG_GSWCK_EN BIT(0) |
| 233 | #define REG_TRGMIICK_EN BIT(1) |
| 234 | |
| 235 | /* Extend PHY Control Register 3 */ |
| 236 | #define PHY_EXT_REG_14 0x14 |
| 237 | |
| 238 | /* Fields of PHY_EXT_REG_14 */ |
| 239 | #define PHY_EN_DOWN_SHFIT BIT(4) |
| 240 | |
| 241 | /* Extend PHY Control Register 4 */ |
| 242 | #define PHY_EXT_REG_17 0x17 |
| 243 | |
| 244 | /* Fields of PHY_EXT_REG_17 */ |
| 245 | #define PHY_LINKDOWN_POWER_SAVING_EN BIT(4) |
| 246 | |
| 247 | /* PHY RXADC Control Register 7 */ |
| 248 | #define PHY_DEV1E_REG_0C6 0x0c6 |
| 249 | |
| 250 | /* Fields of PHY_DEV1E_REG_0C6 */ |
| 251 | #define PHY_POWER_SAVING_S 8 |
| 252 | #define PHY_POWER_SAVING_M 0x300 |
| 253 | #define PHY_POWER_SAVING_TX 0x0 |
| 254 | |
| 255 | struct mt753x_switch_priv { |
| 256 | struct mtk_eth_switch_priv epriv; |
| 257 | struct mii_dev *mdio_bus; |
| 258 | u32 smi_addr; |
| 259 | u32 phy_base; |
| 260 | u32 pmcr; |
| 261 | |
| 262 | int (*reg_read)(struct mt753x_switch_priv *priv, u32 reg, u32 *data); |
| 263 | int (*reg_write)(struct mt753x_switch_priv *priv, u32 reg, u32 data); |
| 264 | }; |
| 265 | |
| 266 | int __mt753x_mdio_reg_read(struct mtk_eth_priv *priv, u32 smi_addr, u32 reg, |
| 267 | u32 *data); |
| 268 | int mt753x_mdio_reg_read(struct mt753x_switch_priv *priv, u32 reg, u32 *data); |
| 269 | int mt753x_mdio_reg_write(struct mt753x_switch_priv *priv, u32 reg, u32 data); |
| 270 | |
| 271 | int mt753x_reg_read(struct mt753x_switch_priv *priv, u32 reg, u32 *data); |
| 272 | int mt753x_reg_write(struct mt753x_switch_priv *priv, u32 reg, u32 data); |
| 273 | void mt753x_reg_rmw(struct mt753x_switch_priv *priv, u32 reg, u32 clr, u32 set); |
| 274 | |
| 275 | int mt7531_mii_read(struct mt753x_switch_priv *priv, u8 phy, u8 reg); |
| 276 | int mt7531_mii_write(struct mt753x_switch_priv *priv, u8 phy, u8 reg, u16 val); |
| 277 | int mt7531_mmd_read(struct mt753x_switch_priv *priv, u8 addr, u8 devad, |
| 278 | u16 reg); |
| 279 | int mt7531_mmd_write(struct mt753x_switch_priv *priv, u8 addr, u8 devad, |
| 280 | u16 reg, u16 val); |
| 281 | |
| 282 | int mt7531_mdio_register(struct mt753x_switch_priv *priv); |
| 283 | |
| 284 | void mt753x_port_isolation(struct mt753x_switch_priv *priv); |
| 285 | |
| 286 | #endif /* _MTK_ETH_MT753X_H_ */ |