1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
5 #include "ngbe_phy_yt.h"
7 #define YT_PHY_RST_WAIT_PERIOD 5
9 s32 ngbe_read_phy_reg_yt(struct ngbe_hw *hw,
10 u32 reg_addr, u32 device_type, u16 *phy_data)
15 reg.device_type = device_type;
18 ngbe_mdi_map_register(®, ®22);
20 /* Read MII reg according to media type */
21 if (hw->phy.media_type == ngbe_media_type_fiber) {
22 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY,
23 reg22.device_type, YT_SMI_PHY_SDS);
24 ngbe_read_phy_reg_mdi(hw, reg22.addr,
25 reg22.device_type, phy_data);
26 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY,
27 reg22.device_type, 0);
29 ngbe_read_phy_reg_mdi(hw, reg22.addr,
30 reg22.device_type, phy_data);
36 s32 ngbe_write_phy_reg_yt(struct ngbe_hw *hw,
37 u32 reg_addr, u32 device_type, u16 phy_data)
42 reg.device_type = device_type;
45 ngbe_mdi_map_register(®, ®22);
47 /* Write MII reg according to media type */
48 if (hw->phy.media_type == ngbe_media_type_fiber) {
49 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY,
50 reg22.device_type, YT_SMI_PHY_SDS);
51 ngbe_write_phy_reg_mdi(hw, reg22.addr,
52 reg22.device_type, phy_data);
53 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY,
54 reg22.device_type, 0);
56 ngbe_write_phy_reg_mdi(hw, reg22.addr,
57 reg22.device_type, phy_data);
63 s32 ngbe_read_phy_reg_ext_yt(struct ngbe_hw *hw,
64 u32 reg_addr, u32 device_type, u16 *phy_data)
66 ngbe_write_phy_reg_mdi(hw, 0x1E, device_type, reg_addr);
67 ngbe_read_phy_reg_mdi(hw, 0x1F, device_type, phy_data);
72 s32 ngbe_write_phy_reg_ext_yt(struct ngbe_hw *hw,
73 u32 reg_addr, u32 device_type, u16 phy_data)
75 ngbe_write_phy_reg_mdi(hw, 0x1E, device_type, reg_addr);
76 ngbe_write_phy_reg_mdi(hw, 0x1F, device_type, phy_data);
81 s32 ngbe_read_phy_reg_sds_ext_yt(struct ngbe_hw *hw,
82 u32 reg_addr, u32 device_type, u16 *phy_data)
84 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY, device_type, YT_SMI_PHY_SDS);
85 ngbe_read_phy_reg_ext_yt(hw, reg_addr, device_type, phy_data);
86 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY, device_type, 0);
91 s32 ngbe_write_phy_reg_sds_ext_yt(struct ngbe_hw *hw,
92 u32 reg_addr, u32 device_type, u16 phy_data)
94 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY, device_type, YT_SMI_PHY_SDS);
95 ngbe_write_phy_reg_ext_yt(hw, reg_addr, device_type, phy_data);
96 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY, device_type, 0);
101 s32 ngbe_setup_phy_link_yt(struct ngbe_hw *hw, u32 speed,
102 bool autoneg_wait_to_complete)
108 DEBUGFUNC("ngbe_setup_phy_link_yt");
109 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
111 hw->phy.autoneg_advertised = 0;
113 if (hw->phy.type == ngbe_phy_yt8521s) {
114 /*disable 100/10base-T Self-negotiation ability*/
115 hw->phy.read_reg(hw, YT_ANA, 0, &value);
116 value &= ~(YT_ANA_100BASET_FULL | YT_ANA_10BASET_FULL);
117 hw->phy.write_reg(hw, YT_ANA, 0, value);
119 /*disable 1000base-T Self-negotiation ability*/
120 hw->phy.read_reg(hw, YT_MS_CTRL, 0, &value);
121 value &= ~YT_MS_1000BASET_FULL;
122 hw->phy.write_reg(hw, YT_MS_CTRL, 0, value);
124 if (speed & NGBE_LINK_SPEED_1GB_FULL) {
125 hw->phy.autoneg_advertised |= NGBE_LINK_SPEED_1GB_FULL;
126 value_r9 |= YT_MS_1000BASET_FULL;
128 if (speed & NGBE_LINK_SPEED_100M_FULL) {
129 hw->phy.autoneg_advertised |= NGBE_LINK_SPEED_100M_FULL;
130 value_r4 |= YT_ANA_100BASET_FULL;
132 if (speed & NGBE_LINK_SPEED_10M_FULL) {
133 hw->phy.autoneg_advertised |= NGBE_LINK_SPEED_10M_FULL;
134 value_r4 |= YT_ANA_10BASET_FULL;
137 /* enable 1000base-T Self-negotiation ability */
138 hw->phy.read_reg(hw, YT_MS_CTRL, 0, &value);
140 hw->phy.write_reg(hw, YT_MS_CTRL, 0, value);
142 /* enable 100/10base-T Self-negotiation ability */
143 hw->phy.read_reg(hw, YT_ANA, 0, &value);
145 hw->phy.write_reg(hw, YT_ANA, 0, value);
147 /* software reset to make the above configuration take effect*/
148 hw->phy.read_reg(hw, YT_BCR, 0, &value);
149 value |= YT_BCR_RESET;
150 hw->phy.write_reg(hw, YT_BCR, 0, value);
152 hw->phy.autoneg_advertised |= NGBE_LINK_SPEED_1GB_FULL;
154 /* RGMII_Config1 : Config rx and tx training delay */
155 value = YT_RGMII_CONF1_RXDELAY |
156 YT_RGMII_CONF1_TXDELAY_FE |
157 YT_RGMII_CONF1_TXDELAY;
158 ngbe_write_phy_reg_ext_yt(hw, YT_RGMII_CONF1, 0, value);
159 value = YT_CHIP_MODE_SEL(1) |
162 ngbe_write_phy_reg_ext_yt(hw, YT_CHIP, 0, value);
165 ngbe_write_phy_reg_sds_ext_yt(hw, 0x0, 0, 0x9140);
168 hw->phy.read_reg(hw, YT_BCR, 0, &value);
169 value &= ~YT_BCR_PWDN;
170 hw->phy.write_reg(hw, YT_BCR, 0, value);
173 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY, 0, 0);
174 ngbe_read_phy_reg_mdi(hw, YT_INTR_STATUS, 0, &value);
179 s32 ngbe_reset_phy_yt(struct ngbe_hw *hw)
185 DEBUGFUNC("ngbe_reset_phy_yt");
187 if (hw->phy.type != ngbe_phy_yt8521s &&
188 hw->phy.type != ngbe_phy_yt8521s_sfi)
189 return NGBE_ERR_PHY_TYPE;
191 status = hw->phy.read_reg(hw, YT_BCR, 0, &ctrl);
192 /* sds software reset */
193 ctrl |= YT_BCR_RESET;
194 status = hw->phy.write_reg(hw, YT_BCR, 0, ctrl);
196 for (i = 0; i < YT_PHY_RST_WAIT_PERIOD; i++) {
197 status = hw->phy.read_reg(hw, YT_BCR, 0, &ctrl);
198 if (!(ctrl & YT_BCR_RESET))
203 if (i == YT_PHY_RST_WAIT_PERIOD) {
204 DEBUGOUT("PHY reset polling failed to complete.\n");
205 return NGBE_ERR_RESET_FAILED;
211 s32 ngbe_check_phy_link_yt(struct ngbe_hw *hw,
212 u32 *speed, bool *link_up)
220 DEBUGFUNC("ngbe_check_phy_link_yt");
222 /* Initialize speed and link to default case */
224 *speed = NGBE_LINK_SPEED_UNKNOWN;
226 ngbe_write_phy_reg_ext_yt(hw, YT_SMI_PHY, 0, 0);
227 ngbe_read_phy_reg_mdi(hw, YT_INTR_STATUS, 0, &insr);
229 status = hw->phy.read_reg(hw, YT_SPST, 0, &phy_data);
230 phy_link = phy_data & YT_SPST_LINK;
231 phy_speed = phy_data & YT_SPST_SPEED_MASK;
236 if (phy_speed == YT_SPST_SPEED_1000M)
237 *speed = NGBE_LINK_SPEED_1GB_FULL;
238 else if (phy_speed == YT_SPST_SPEED_100M)
239 *speed = NGBE_LINK_SPEED_100M_FULL;
240 else if (phy_speed == YT_SPST_SPEED_10M)
241 *speed = NGBE_LINK_SPEED_10M_FULL;