| 223 | } |
| 224 | |
| 225 | int rt_phy_reset(struct rt_phy_device *phydev) |
| 226 | { |
| 227 | int reg; |
| 228 | int timeout = 500; |
| 229 | int devad = RT_MDIO_DEVAD_NONE; |
| 230 | |
| 231 | if (phydev->flags & RT_PHY_FLAG_BROKEN_RESET) |
| 232 | return 0; |
| 233 | |
| 234 | if (rt_phy_write(phydev, devad, RT_MII_BMCR, RT_BMCR_RESET) < 0) |
| 235 | { |
| 236 | LOG_D("PHY reset failed\n"); |
| 237 | return -1; |
| 238 | } |
| 239 | |
| 240 | reg = rt_phy_read(phydev, devad, RT_MII_BMCR); |
| 241 | while ((reg & RT_BMCR_RESET) && timeout--) |
| 242 | { |
| 243 | reg = rt_phy_read(phydev, devad, RT_MII_BMCR); |
| 244 | |
| 245 | if (reg < 0) |
| 246 | { |
| 247 | LOG_D("PHY status read failed\n"); |
| 248 | return -1; |
| 249 | } |
| 250 | rt_thread_mdelay(1); |
| 251 | } |
| 252 | |
| 253 | if (reg & RT_BMCR_RESET) |
| 254 | { |
| 255 | LOG_D("PHY reset timed out\n"); |
| 256 | return -1; |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | static struct rt_bus rt_phy_bus; |
| 263 |
no test coverage detected