Lines Matching full:phydev

376  * @phydev: a pointer to a &struct phy_device
383 static int ytphy_read_ext(struct phy_device *phydev, u16 regnum) in ytphy_read_ext() argument
387 ret = __phy_write(phydev, YTPHY_PAGE_SELECT, regnum); in ytphy_read_ext()
391 return __phy_read(phydev, YTPHY_PAGE_DATA); in ytphy_read_ext()
396 * @phydev: a pointer to a &struct phy_device
401 static int ytphy_read_ext_with_lock(struct phy_device *phydev, u16 regnum) in ytphy_read_ext_with_lock() argument
405 phy_lock_mdio_bus(phydev); in ytphy_read_ext_with_lock()
406 ret = ytphy_read_ext(phydev, regnum); in ytphy_read_ext_with_lock()
407 phy_unlock_mdio_bus(phydev); in ytphy_read_ext_with_lock()
414 * @phydev: a pointer to a &struct phy_device
422 static int ytphy_write_ext(struct phy_device *phydev, u16 regnum, u16 val) in ytphy_write_ext() argument
426 ret = __phy_write(phydev, YTPHY_PAGE_SELECT, regnum); in ytphy_write_ext()
430 return __phy_write(phydev, YTPHY_PAGE_DATA, val); in ytphy_write_ext()
435 * @phydev: a pointer to a &struct phy_device
441 static int ytphy_write_ext_with_lock(struct phy_device *phydev, u16 regnum, in ytphy_write_ext_with_lock() argument
446 phy_lock_mdio_bus(phydev); in ytphy_write_ext_with_lock()
447 ret = ytphy_write_ext(phydev, regnum, val); in ytphy_write_ext_with_lock()
448 phy_unlock_mdio_bus(phydev); in ytphy_write_ext_with_lock()
455 * @phydev: a pointer to a &struct phy_device
466 static int ytphy_modify_ext(struct phy_device *phydev, u16 regnum, u16 mask, in ytphy_modify_ext() argument
471 ret = __phy_write(phydev, YTPHY_PAGE_SELECT, regnum); in ytphy_modify_ext()
475 return __phy_modify(phydev, YTPHY_PAGE_DATA, mask, set); in ytphy_modify_ext()
480 * @phydev: a pointer to a &struct phy_device
490 static int ytphy_modify_ext_with_lock(struct phy_device *phydev, u16 regnum, in ytphy_modify_ext_with_lock() argument
495 phy_lock_mdio_bus(phydev); in ytphy_modify_ext_with_lock()
496 ret = ytphy_modify_ext(phydev, regnum, mask, set); in ytphy_modify_ext_with_lock()
497 phy_unlock_mdio_bus(phydev); in ytphy_modify_ext_with_lock()
504 * @phydev: a pointer to a &struct phy_device
509 static void ytphy_get_wol(struct phy_device *phydev, in ytphy_get_wol() argument
517 wol_config = ytphy_read_ext_with_lock(phydev, YTPHY_WOL_CONFIG_REG); in ytphy_get_wol()
527 * @phydev: a pointer to a &struct phy_device
536 static int ytphy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) in ytphy_set_wol() argument
552 p_attached_dev = phydev->attached_dev; in ytphy_set_wol()
561 old_page = phy_select_page(phydev, YT8521_RSSR_UTP_SPACE); in ytphy_set_wol()
567 ret = ytphy_write_ext(phydev, mac_addr_reg[i], in ytphy_set_wol()
578 ret = ytphy_modify_ext(phydev, YTPHY_WOL_CONFIG_REG, mask, val); in ytphy_set_wol()
583 ret = __phy_modify(phydev, YTPHY_INTERRUPT_ENABLE_REG, 0, in ytphy_set_wol()
589 old_page = phy_select_page(phydev, YT8521_RSSR_UTP_SPACE); in ytphy_set_wol()
595 ret = ytphy_modify_ext(phydev, YTPHY_WOL_CONFIG_REG, mask, 0); in ytphy_set_wol()
598 ret = __phy_modify(phydev, YTPHY_INTERRUPT_ENABLE_REG, in ytphy_set_wol()
605 return phy_restore_page(phydev, old_page, ret); in ytphy_set_wol()
608 static int yt8531_set_wol(struct phy_device *phydev, in yt8531_set_wol() argument
622 mac_addr = phydev->attached_dev->dev_addr; in yt8531_set_wol()
626 ret = ytphy_write_ext_with_lock(phydev, mac_addr_reg[i], in yt8531_set_wol()
637 ret = ytphy_modify_ext_with_lock(phydev, YTPHY_WOL_CONFIG_REG, in yt8531_set_wol()
643 ret = phy_modify(phydev, YTPHY_INTERRUPT_ENABLE_REG, 0, in yt8531_set_wol()
650 ret = ytphy_modify_ext_with_lock(phydev, YTPHY_WOL_CONFIG_REG, in yt8531_set_wol()
654 ret = phy_modify(phydev, YTPHY_INTERRUPT_ENABLE_REG, in yt8531_set_wol()
663 static int yt8511_read_page(struct phy_device *phydev) in yt8511_read_page() argument
665 return __phy_read(phydev, YT8511_PAGE_SELECT); in yt8511_read_page()
668 static int yt8511_write_page(struct phy_device *phydev, int page) in yt8511_write_page() argument
670 return __phy_write(phydev, YT8511_PAGE_SELECT, page); in yt8511_write_page()
673 static int yt8511_config_init(struct phy_device *phydev) in yt8511_config_init() argument
678 oldpage = phy_select_page(phydev, YT8511_EXT_CLK_GATE); in yt8511_config_init()
683 switch (phydev->interface) { in yt8511_config_init()
705 ret = __phy_modify(phydev, YT8511_PAGE, (YT8511_DELAY_RX | YT8511_DELAY_GE_TX_EN), ge); in yt8511_config_init()
710 ret = __phy_modify(phydev, YT8511_PAGE, 0, YT8511_CLK_125M); in yt8511_config_init()
715 ret = __phy_write(phydev, YT8511_PAGE_SELECT, YT8511_EXT_DELAY_DRIVE); in yt8511_config_init()
719 ret = __phy_modify(phydev, YT8511_PAGE, YT8511_DELAY_FE_TX_EN, fe); in yt8511_config_init()
724 ret = __phy_write(phydev, YT8511_PAGE_SELECT, YT8511_EXT_SLEEP_CTRL); in yt8511_config_init()
728 ret = __phy_modify(phydev, YT8511_PAGE, 0, YT8511_PLLON_SLP); in yt8511_config_init()
733 return phy_restore_page(phydev, oldpage, ret); in yt8511_config_init()
738 * @phydev: a pointer to a &struct phy_device
743 static int yt8521_read_page(struct phy_device *phydev) in yt8521_read_page() argument
747 old_page = ytphy_read_ext(phydev, YT8521_REG_SPACE_SELECT_REG); in yt8521_read_page()
759 * @phydev: a pointer to a &struct phy_device
764 static int yt8521_write_page(struct phy_device *phydev, int page) in yt8521_write_page() argument
774 return ytphy_modify_ext(phydev, YT8521_REG_SPACE_SELECT_REG, mask, set); in yt8521_write_page()
825 static u32 ytphy_get_delay_reg_value(struct phy_device *phydev, in ytphy_get_delay_reg_value() argument
832 struct device_node *node = phydev->mdio.dev.of_node; in ytphy_get_delay_reg_value()
854 phydev_warn(phydev, "Unsupported value %d for %s using default (%u)\n", in ytphy_get_delay_reg_value()
868 static int ytphy_rgmii_clk_delay_config(struct phy_device *phydev) in ytphy_rgmii_clk_delay_config() argument
876 rx_reg = ytphy_get_delay_reg_value(phydev, "rx-internal-delay-ps", in ytphy_rgmii_clk_delay_config()
880 tx_reg = ytphy_get_delay_reg_value(phydev, "tx-internal-delay-ps", in ytphy_rgmii_clk_delay_config()
884 switch (phydev->interface) { in ytphy_rgmii_clk_delay_config()
903 ret = ytphy_modify_ext(phydev, YT8521_CHIP_CONFIG_REG, in ytphy_rgmii_clk_delay_config()
910 return ytphy_modify_ext(phydev, YT8521_RGMII_CONFIG1_REG, mask, val); in ytphy_rgmii_clk_delay_config()
913 static int ytphy_rgmii_clk_delay_config_with_lock(struct phy_device *phydev) in ytphy_rgmii_clk_delay_config_with_lock() argument
917 phy_lock_mdio_bus(phydev); in ytphy_rgmii_clk_delay_config_with_lock()
918 ret = ytphy_rgmii_clk_delay_config(phydev); in ytphy_rgmii_clk_delay_config_with_lock()
919 phy_unlock_mdio_bus(phydev); in ytphy_rgmii_clk_delay_config_with_lock()
955 static u32 yt8531_get_ldo_vol(struct phy_device *phydev) in yt8531_get_ldo_vol() argument
959 val = ytphy_read_ext_with_lock(phydev, YT8521_CHIP_CONFIG_REG); in yt8531_get_ldo_vol()
965 static int yt8531_get_ds_map(struct phy_device *phydev, u32 cur) in yt8531_get_ds_map() argument
970 vol = yt8531_get_ldo_vol(phydev); in yt8531_get_ds_map()
979 static int yt8531_set_ds(struct phy_device *phydev) in yt8531_set_ds() argument
981 struct device_node *node = phydev->mdio.dev.of_node; in yt8531_set_ds()
987 ds = yt8531_get_ds_map(phydev, val); in yt8531_set_ds()
989 return dev_err_probe(&phydev->mdio.dev, ds, in yt8531_set_ds()
995 ret = ytphy_modify_ext_with_lock(phydev, in yt8531_set_ds()
1004 ds = yt8531_get_ds_map(phydev, val); in yt8531_set_ds()
1006 return dev_err_probe(&phydev->mdio.dev, ds, in yt8531_set_ds()
1018 ret = ytphy_modify_ext_with_lock(phydev, in yt8531_set_ds()
1030 * @phydev: a pointer to a &struct phy_device
1034 static int yt8521_probe(struct phy_device *phydev) in yt8521_probe() argument
1036 struct device_node *node = phydev->mdio.dev.of_node; in yt8521_probe()
1037 struct device *dev = &phydev->mdio.dev; in yt8521_probe()
1048 phydev->priv = priv; in yt8521_probe()
1050 chip_config = ytphy_read_ext_with_lock(phydev, YT8521_CHIP_CONFIG_REG); in yt8521_probe()
1061 phydev->port = PORT_FIBRE; in yt8521_probe()
1068 phydev->port = PORT_NONE; in yt8521_probe()
1074 phydev->port = PORT_TP; in yt8521_probe()
1079 ret = ytphy_write_ext_with_lock(phydev, in yt8521_probe()
1089 if (phydev->drv->phy_id == PHY_ID_YT8521) { in yt8521_probe()
1113 phydev_warn(phydev, "Freq err:%u\n", freq); in yt8521_probe()
1116 } else if (phydev->drv->phy_id == PHY_ID_YT8531S) { in yt8521_probe()
1140 phydev_warn(phydev, "Freq err:%u\n", freq); in yt8521_probe()
1144 phydev_warn(phydev, "PHY id err\n"); in yt8521_probe()
1148 return ytphy_modify_ext_with_lock(phydev, YTPHY_SYNCE_CFG_REG, mask, in yt8521_probe()
1152 static int yt8531_probe(struct phy_device *phydev) in yt8531_probe() argument
1154 struct device_node *node = phydev->mdio.dev.of_node; in yt8531_probe()
1181 phydev_warn(phydev, "Freq err:%u\n", freq); in yt8531_probe()
1185 return ytphy_modify_ext_with_lock(phydev, YTPHY_SYNCE_CFG_REG, mask, in yt8531_probe()
1191 * @phydev: a pointer to a &struct phy_device
1197 static int ytphy_utp_read_lpa(struct phy_device *phydev) in ytphy_utp_read_lpa() argument
1201 if (phydev->autoneg == AUTONEG_ENABLE) { in ytphy_utp_read_lpa()
1202 if (!phydev->autoneg_complete) { in ytphy_utp_read_lpa()
1203 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in ytphy_utp_read_lpa()
1205 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, 0); in ytphy_utp_read_lpa()
1209 if (phydev->is_gigabit_capable) { in ytphy_utp_read_lpa()
1210 lpagb = __phy_read(phydev, MII_STAT1000); in ytphy_utp_read_lpa()
1215 int adv = __phy_read(phydev, MII_CTRL1000); in ytphy_utp_read_lpa()
1221 phydev_err(phydev, "Master/Slave resolution failed, maybe conflicting manual settings?\n"); in ytphy_utp_read_lpa()
1223 phydev_err(phydev, "Master/Slave resolution failed\n"); in ytphy_utp_read_lpa()
1227 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in ytphy_utp_read_lpa()
1231 lpa = __phy_read(phydev, MII_LPA); in ytphy_utp_read_lpa()
1235 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa); in ytphy_utp_read_lpa()
1237 linkmode_zero(phydev->lp_advertising); in ytphy_utp_read_lpa()
1244 * yt8521_adjust_status() - update speed and duplex to phydev. when in fiber
1246 * @phydev: a pointer to a &struct phy_device
1254 static int yt8521_adjust_status(struct phy_device *phydev, int status, in yt8521_adjust_status() argument
1290 phydev->speed = speed; in yt8521_adjust_status()
1291 phydev->duplex = duplex; in yt8521_adjust_status()
1294 err = ytphy_utp_read_lpa(phydev); in yt8521_adjust_status()
1298 phy_resolve_aneg_pause(phydev); in yt8521_adjust_status()
1300 lpa = __phy_read(phydev, MII_LPA); in yt8521_adjust_status()
1306 phydev->lp_advertising, lpa & LPA_1000XFULL); in yt8521_adjust_status()
1309 phydev->pause = 0; in yt8521_adjust_status()
1310 phydev->asym_pause = 0; in yt8521_adjust_status()
1312 phydev->pause = 1; in yt8521_adjust_status()
1313 phydev->asym_pause = 1; in yt8521_adjust_status()
1315 phydev->pause = 1; in yt8521_adjust_status()
1316 phydev->asym_pause = 0; in yt8521_adjust_status()
1325 * @phydev: a pointer to a &struct phy_device
1331 static int yt8521_read_status_paged(struct phy_device *phydev, int page) in yt8521_read_status_paged() argument
1340 linkmode_zero(phydev->lp_advertising); in yt8521_read_status_paged()
1341 phydev->duplex = DUPLEX_UNKNOWN; in yt8521_read_status_paged()
1342 phydev->speed = SPEED_UNKNOWN; in yt8521_read_status_paged()
1343 phydev->asym_pause = 0; in yt8521_read_status_paged()
1344 phydev->pause = 0; in yt8521_read_status_paged()
1354 old_page = phy_select_page(phydev, page); in yt8521_read_status_paged()
1361 ret = __phy_read(phydev, YTPHY_SPECIFIC_STATUS_REG); in yt8521_read_status_paged()
1373 ret = __phy_read(phydev, MII_BMSR); in yt8521_read_status_paged()
1378 ret = __phy_read(phydev, MII_BMSR); in yt8521_read_status_paged()
1385 phydev_info(phydev, in yt8521_read_status_paged()
1391 ret = __phy_read(phydev, MII_BMSR); in yt8521_read_status_paged()
1395 phydev->autoneg_complete = ret & BMSR_ANEGCOMPLETE ? 1 : 0; in yt8521_read_status_paged()
1400 yt8521_adjust_status(phydev, status, true); in yt8521_read_status_paged()
1402 yt8521_adjust_status(phydev, status, false); in yt8521_read_status_paged()
1404 return phy_restore_page(phydev, old_page, link); in yt8521_read_status_paged()
1407 return phy_restore_page(phydev, old_page, ret); in yt8521_read_status_paged()
1412 * @phydev: a pointer to a &struct phy_device
1416 static int yt8521_read_status(struct phy_device *phydev) in yt8521_read_status() argument
1418 struct yt8521_priv *priv = phydev->priv; in yt8521_read_status()
1425 link = yt8521_read_status_paged(phydev, priv->reg_page); in yt8521_read_status()
1433 link_utp = yt8521_read_status_paged(phydev, in yt8521_read_status()
1439 link_fiber = yt8521_read_status_paged(phydev, in yt8521_read_status()
1449 if (phydev->link == 0) { in yt8521_read_status()
1459 ret = ytphy_write_ext_with_lock(phydev, in yt8521_read_status()
1465 phydev->port = link_fiber ? PORT_FIBRE : PORT_TP; in yt8521_read_status()
1467 phydev_info(phydev, "%s, link up, media: %s\n", in yt8521_read_status()
1469 (phydev->port == PORT_TP) ? in yt8521_read_status()
1473 phydev->link = 1; in yt8521_read_status()
1475 if (phydev->link == 1) { in yt8521_read_status()
1476 phydev_info(phydev, "%s, link down, media: %s\n", in yt8521_read_status()
1477 __func__, (phydev->port == PORT_TP) ? in yt8521_read_status()
1485 phydev->port = PORT_NONE; in yt8521_read_status()
1489 phydev->link = 0; in yt8521_read_status()
1497 * @phydev: the phy_device struct
1510 static int yt8521_modify_bmcr_paged(struct phy_device *phydev, int page, in yt8521_modify_bmcr_paged() argument
1517 old_page = phy_select_page(phydev, page & YT8521_RSSR_SPACE_MASK); in yt8521_modify_bmcr_paged()
1521 ret = __phy_modify(phydev, MII_BMCR, mask, set); in yt8521_modify_bmcr_paged()
1529 ret = __phy_read(phydev, MII_BMCR); in yt8521_modify_bmcr_paged()
1534 return phy_restore_page(phydev, old_page, 0); in yt8521_modify_bmcr_paged()
1539 return phy_restore_page(phydev, old_page, ret); in yt8521_modify_bmcr_paged()
1544 * @phydev: the phy_device struct
1555 static int yt8521_modify_utp_fiber_bmcr(struct phy_device *phydev, u16 mask, in yt8521_modify_utp_fiber_bmcr() argument
1558 struct yt8521_priv *priv = phydev->priv; in yt8521_modify_utp_fiber_bmcr()
1562 ret = yt8521_modify_bmcr_paged(phydev, priv->reg_page, mask, in yt8521_modify_utp_fiber_bmcr()
1567 ret = yt8521_modify_bmcr_paged(phydev, YT8521_RSSR_UTP_SPACE, in yt8521_modify_utp_fiber_bmcr()
1572 ret = yt8521_modify_bmcr_paged(phydev, YT8521_RSSR_FIBER_SPACE, in yt8521_modify_utp_fiber_bmcr()
1582 * @phydev: a pointer to a &struct phy_device
1586 static int yt8521_soft_reset(struct phy_device *phydev) in yt8521_soft_reset() argument
1588 return yt8521_modify_utp_fiber_bmcr(phydev, 0, BMCR_RESET); in yt8521_soft_reset()
1593 * @phydev: a pointer to a &struct phy_device
1597 static int yt8521_suspend(struct phy_device *phydev) in yt8521_suspend() argument
1602 wol_config = ytphy_read_ext_with_lock(phydev, YTPHY_WOL_CONFIG_REG); in yt8521_suspend()
1610 return yt8521_modify_utp_fiber_bmcr(phydev, 0, BMCR_PDOWN); in yt8521_suspend()
1615 * @phydev: a pointer to a &struct phy_device
1619 static int yt8521_resume(struct phy_device *phydev) in yt8521_resume() argument
1625 ret = ytphy_modify_ext_with_lock(phydev, in yt8521_resume()
1631 wol_config = ytphy_read_ext_with_lock(phydev, YTPHY_WOL_CONFIG_REG); in yt8521_resume()
1639 return yt8521_modify_utp_fiber_bmcr(phydev, BMCR_PDOWN, 0); in yt8521_resume()
1644 * @phydev: a pointer to a &struct phy_device
1648 static int yt8521_config_init(struct phy_device *phydev) in yt8521_config_init() argument
1650 struct device_node *node = phydev->mdio.dev.of_node; in yt8521_config_init()
1654 old_page = phy_select_page(phydev, YT8521_RSSR_UTP_SPACE); in yt8521_config_init()
1659 if (phydev->interface != PHY_INTERFACE_MODE_SGMII) { in yt8521_config_init()
1660 ret = ytphy_rgmii_clk_delay_config(phydev); in yt8521_config_init()
1667 ret = ytphy_modify_ext(phydev, YT8521_EXTREG_SLEEP_CONTROL1_REG, in yt8521_config_init()
1675 ret = ytphy_modify_ext(phydev, YT8521_CLOCK_GATING_REG, in yt8521_config_init()
1681 return phy_restore_page(phydev, old_page, ret); in yt8521_config_init()
1684 static int yt8531_config_init(struct phy_device *phydev) in yt8531_config_init() argument
1686 struct device_node *node = phydev->mdio.dev.of_node; in yt8531_config_init()
1689 ret = ytphy_rgmii_clk_delay_config_with_lock(phydev); in yt8531_config_init()
1695 ret = ytphy_modify_ext_with_lock(phydev, in yt8531_config_init()
1704 ret = ytphy_modify_ext_with_lock(phydev, in yt8531_config_init()
1711 ret = yt8531_set_ds(phydev); in yt8531_config_init()
1721 * @phydev: a pointer to a &struct phy_device
1727 static void yt8531_link_change_notify(struct phy_device *phydev) in yt8531_link_change_notify() argument
1729 struct device_node *node = phydev->mdio.dev.of_node; in yt8531_link_change_notify()
1750 if (phydev->speed < 0) in yt8531_link_change_notify()
1753 switch (phydev->speed) { in yt8531_link_change_notify()
1770 ret = ytphy_modify_ext_with_lock(phydev, YT8521_RGMII_CONFIG1_REG, in yt8531_link_change_notify()
1773 phydev_warn(phydev, "Modify TX_CLK_SEL err:%d\n", ret); in yt8531_link_change_notify()
1779 * @phydev: a pointer to a &struct phy_device
1782 static void yt8521_prepare_fiber_features(struct phy_device *phydev, in yt8521_prepare_fiber_features() argument
1792 * yt8521_fiber_setup_forced - configures/forces speed from @phydev
1793 * @phydev: target phy_device struct
1799 static int yt8521_fiber_setup_forced(struct phy_device *phydev) in yt8521_fiber_setup_forced() argument
1804 if (phydev->speed == SPEED_1000) in yt8521_fiber_setup_forced()
1806 else if (phydev->speed == SPEED_100) in yt8521_fiber_setup_forced()
1811 ret = __phy_modify(phydev, MII_BMCR, BMCR_ANENABLE, 0); in yt8521_fiber_setup_forced()
1816 ret = ytphy_modify_ext(phydev, YT8521_LINK_TIMER_CFG2_REG, in yt8521_fiber_setup_forced()
1821 ret = ytphy_modify_ext(phydev, YTPHY_MISC_CONFIG_REG, in yt8521_fiber_setup_forced()
1826 return ytphy_modify_ext(phydev, YT8521_CHIP_CONFIG_REG, in yt8521_fiber_setup_forced()
1832 * @phydev: target phy_device struct
1839 static int ytphy_check_and_restart_aneg(struct phy_device *phydev, bool restart) in ytphy_check_and_restart_aneg() argument
1847 ret = __phy_read(phydev, MII_BMCR); in ytphy_check_and_restart_aneg()
1858 return __phy_modify(phydev, MII_BMCR, BMCR_ISOLATE, in ytphy_check_and_restart_aneg()
1867 * @phydev: target phy_device struct
1873 static int yt8521_fiber_config_aneg(struct phy_device *phydev) in yt8521_fiber_config_aneg() argument
1879 if (phydev->autoneg != AUTONEG_ENABLE) in yt8521_fiber_config_aneg()
1880 return yt8521_fiber_setup_forced(phydev); in yt8521_fiber_config_aneg()
1883 err = ytphy_modify_ext(phydev, YT8521_LINK_TIMER_CFG2_REG, in yt8521_fiber_config_aneg()
1888 err = ytphy_modify_ext(phydev, YT8521_CHIP_CONFIG_REG, in yt8521_fiber_config_aneg()
1893 bmcr = __phy_read(phydev, MII_BMCR); in yt8521_fiber_config_aneg()
1901 __phy_modify(phydev, MII_BMCR, 0, BMCR_PDOWN); in yt8521_fiber_config_aneg()
1903 __phy_modify(phydev, MII_BMCR, BMCR_PDOWN, 0); in yt8521_fiber_config_aneg()
1906 adv = linkmode_adv_to_mii_adv_x(phydev->advertising, in yt8521_fiber_config_aneg()
1910 err = __phy_modify_changed(phydev, MII_ADVERTISE, in yt8521_fiber_config_aneg()
1921 return ytphy_check_and_restart_aneg(phydev, changed); in yt8521_fiber_config_aneg()
1926 * @phydev: target phy_device struct
1932 static int ytphy_setup_master_slave(struct phy_device *phydev) in ytphy_setup_master_slave() argument
1936 if (!phydev->is_gigabit_capable) in ytphy_setup_master_slave()
1939 switch (phydev->master_slave_set) { in ytphy_setup_master_slave()
1955 phydev_warn(phydev, "Unsupported Master/Slave mode\n"); in ytphy_setup_master_slave()
1959 return __phy_modify_changed(phydev, MII_CTRL1000, in ytphy_setup_master_slave()
1966 * @phydev: target phy_device struct
1976 static int ytphy_utp_config_advert(struct phy_device *phydev) in ytphy_utp_config_advert() argument
1982 linkmode_and(phydev->advertising, phydev->advertising, in ytphy_utp_config_advert()
1983 phydev->supported); in ytphy_utp_config_advert()
1985 adv = linkmode_adv_to_mii_adv_t(phydev->advertising); in ytphy_utp_config_advert()
1988 err = __phy_modify_changed(phydev, MII_ADVERTISE, in ytphy_utp_config_advert()
1997 bmsr = __phy_read(phydev, MII_BMSR); in ytphy_utp_config_advert()
2008 adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising); in ytphy_utp_config_advert()
2010 err = __phy_modify_changed(phydev, MII_CTRL1000, in ytphy_utp_config_advert()
2023 * @phydev: target phy_device struct
2033 static int ytphy_utp_config_aneg(struct phy_device *phydev, bool changed) in ytphy_utp_config_aneg() argument
2038 err = ytphy_setup_master_slave(phydev); in ytphy_utp_config_aneg()
2044 if (phydev->autoneg != AUTONEG_ENABLE) { in ytphy_utp_config_aneg()
2045 /* configures/forces speed/duplex from @phydev */ in ytphy_utp_config_aneg()
2047 ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); in ytphy_utp_config_aneg()
2049 return __phy_modify(phydev, MII_BMCR, ~(BMCR_LOOPBACK | in ytphy_utp_config_aneg()
2053 err = ytphy_utp_config_advert(phydev); in ytphy_utp_config_aneg()
2059 return ytphy_check_and_restart_aneg(phydev, changed); in ytphy_utp_config_aneg()
2065 * @phydev: a pointer to a &struct phy_device
2071 static int yt8521_config_aneg_paged(struct phy_device *phydev, int page) in yt8521_config_aneg_paged() argument
2074 struct yt8521_priv *priv = phydev->priv; in yt8521_config_aneg_paged()
2080 old_page = phy_select_page(phydev, page); in yt8521_config_aneg_paged()
2085 * phydev->advertising should be updated. in yt8521_config_aneg_paged()
2089 yt8521_prepare_fiber_features(phydev, fiber_supported); in yt8521_config_aneg_paged()
2097 linkmode_and(phydev->advertising, in yt8521_config_aneg_paged()
2103 linkmode_andnot(phydev->advertising, in yt8521_config_aneg_paged()
2110 ret = yt8521_fiber_config_aneg(phydev); in yt8521_config_aneg_paged()
2112 ret = ytphy_utp_config_aneg(phydev, false); in yt8521_config_aneg_paged()
2115 return phy_restore_page(phydev, old_page, ret); in yt8521_config_aneg_paged()
2120 * @phydev: a pointer to a &struct phy_device
2124 static int yt8521_config_aneg(struct phy_device *phydev) in yt8521_config_aneg() argument
2126 struct yt8521_priv *priv = phydev->priv; in yt8521_config_aneg()
2130 ret = yt8521_config_aneg_paged(phydev, priv->reg_page); in yt8521_config_aneg()
2135 * phydev->advertising need to be saved at first run. in yt8521_config_aneg()
2141 phydev->advertising); in yt8521_config_aneg()
2144 ret = yt8521_config_aneg_paged(phydev, YT8521_RSSR_UTP_SPACE); in yt8521_config_aneg()
2148 ret = yt8521_config_aneg_paged(phydev, YT8521_RSSR_FIBER_SPACE); in yt8521_config_aneg()
2153 * phydev->advertising as default value. in yt8521_config_aneg()
2155 linkmode_copy(phydev->advertising, priv->combo_advertising); in yt8521_config_aneg()
2163 * @phydev: a pointer to a &struct phy_device
2169 static int yt8521_aneg_done_paged(struct phy_device *phydev, int page) in yt8521_aneg_done_paged() argument
2175 old_page = phy_select_page(phydev, page & YT8521_RSSR_SPACE_MASK); in yt8521_aneg_done_paged()
2179 ret = __phy_read(phydev, YTPHY_SPECIFIC_STATUS_REG); in yt8521_aneg_done_paged()
2187 return phy_restore_page(phydev, old_page, ret); in yt8521_aneg_done_paged()
2192 * @phydev: a pointer to a &struct phy_device
2196 static int yt8521_aneg_done(struct phy_device *phydev) in yt8521_aneg_done() argument
2198 struct yt8521_priv *priv = phydev->priv; in yt8521_aneg_done()
2204 link = yt8521_aneg_done_paged(phydev, priv->reg_page); in yt8521_aneg_done()
2206 link_utp = yt8521_aneg_done_paged(phydev, in yt8521_aneg_done()
2212 link_fiber = yt8521_aneg_done_paged(phydev, in yt8521_aneg_done()
2218 phydev_info(phydev, "%s, link_fiber: %d, link_utp: %d\n", in yt8521_aneg_done()
2227 * @phydev: target phy_device struct
2230 * phydev->supported accordingly.
2235 static int ytphy_utp_read_abilities(struct phy_device *phydev) in ytphy_utp_read_abilities() argument
2241 phydev->supported); in ytphy_utp_read_abilities()
2243 val = __phy_read(phydev, MII_BMSR); in ytphy_utp_read_abilities()
2247 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported, in ytphy_utp_read_abilities()
2250 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, phydev->supported, in ytphy_utp_read_abilities()
2252 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, phydev->supported, in ytphy_utp_read_abilities()
2254 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, phydev->supported, in ytphy_utp_read_abilities()
2256 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, phydev->supported, in ytphy_utp_read_abilities()
2260 val = __phy_read(phydev, MII_ESTATUS); in ytphy_utp_read_abilities()
2265 phydev->supported, val & ESTATUS_1000_TFULL); in ytphy_utp_read_abilities()
2267 phydev->supported, val & ESTATUS_1000_THALF); in ytphy_utp_read_abilities()
2269 phydev->supported, val & ESTATUS_1000_XFULL); in ytphy_utp_read_abilities()
2277 * @phydev: a pointer to a &struct phy_device
2283 static int yt8521_get_features_paged(struct phy_device *phydev, int page) in yt8521_get_features_paged() argument
2289 old_page = phy_select_page(phydev, page); in yt8521_get_features_paged()
2294 linkmode_zero(phydev->supported); in yt8521_get_features_paged()
2295 yt8521_prepare_fiber_features(phydev, phydev->supported); in yt8521_get_features_paged()
2297 ret = ytphy_utp_read_abilities(phydev); in yt8521_get_features_paged()
2303 return phy_restore_page(phydev, old_page, ret); in yt8521_get_features_paged()
2308 * @phydev: target phy_device struct
2312 static int yt8521_get_features(struct phy_device *phydev) in yt8521_get_features() argument
2314 struct yt8521_priv *priv = phydev->priv; in yt8521_get_features()
2318 ret = yt8521_get_features_paged(phydev, priv->reg_page); in yt8521_get_features()
2320 ret = yt8521_get_features_paged(phydev, in yt8521_get_features()
2325 /* add fiber's features to phydev->supported */ in yt8521_get_features()
2326 yt8521_prepare_fiber_features(phydev, phydev->supported); in yt8521_get_features()
2333 * @phydev: target phy_device struct
2337 static int yt8821_get_features(struct phy_device *phydev) in yt8821_get_features() argument
2341 ret = genphy_c45_pma_read_ext_abilities(phydev); in yt8821_get_features()
2345 return genphy_read_abilities(phydev); in yt8821_get_features()
2350 * @phydev: target phy_device struct
2355 static int yt8821_get_rate_matching(struct phy_device *phydev, in yt8821_get_rate_matching() argument
2360 val = ytphy_read_ext_with_lock(phydev, YT8521_CHIP_CONFIG_REG); in yt8821_get_rate_matching()
2373 * @phydev: a pointer to a &struct phy_device
2377 static int yt8821_aneg_done(struct phy_device *phydev) in yt8821_aneg_done() argument
2379 return yt8521_aneg_done_paged(phydev, YT8521_RSSR_UTP_SPACE); in yt8821_aneg_done()
2384 * @phydev: a pointer to a &struct phy_device
2388 static int yt8821_serdes_init(struct phy_device *phydev) in yt8821_serdes_init() argument
2395 old_page = phy_select_page(phydev, YT8521_RSSR_FIBER_SPACE); in yt8821_serdes_init()
2397 phydev_err(phydev, "Failed to select page: %d\n", in yt8821_serdes_init()
2402 ret = __phy_modify(phydev, MII_BMCR, BMCR_ANENABLE, 0); in yt8821_serdes_init()
2409 ret = ytphy_modify_ext(phydev, YT8821_SDS_EXT_CSR_CTRL_REG, mask, in yt8821_serdes_init()
2413 return phy_restore_page(phydev, old_page, ret); in yt8821_serdes_init()
2418 * @phydev: a pointer to a &struct phy_device
2422 static int yt8821_utp_init(struct phy_device *phydev) in yt8821_utp_init() argument
2430 old_page = phy_select_page(phydev, YT8521_RSSR_UTP_SPACE); in yt8821_utp_init()
2432 phydev_err(phydev, "Failed to select page: %d\n", in yt8821_utp_init()
2442 ret = ytphy_modify_ext(phydev, YT8821_UTP_EXT_RPDN_CTRL_REG, in yt8821_utp_init()
2449 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2457 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2467 ret = ytphy_modify_ext(phydev, YT8821_UTP_EXT_TRACE_CTRL_REG, in yt8821_utp_init()
2474 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2482 ret = ytphy_modify_ext(phydev, YT8821_UTP_EXT_ECHO_CTRL_REG, in yt8821_utp_init()
2489 ret = ytphy_modify_ext(phydev, YT8821_UTP_EXT_GAIN_CTRL_REG, in yt8821_utp_init()
2496 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2506 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2516 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2523 ret = ytphy_read_ext(phydev, YT8821_UTP_EXT_PI_CTRL_REG); in yt8821_utp_init()
2534 ret = ytphy_modify_ext(phydev, YT8821_UTP_EXT_PI_CTRL_REG, in yt8821_utp_init()
2540 ret = ytphy_write_ext(phydev, YT8821_UTP_EXT_PI_CTRL_REG, save); in yt8821_utp_init()
2546 ret = ytphy_modify_ext(phydev, YT8821_UTP_EXT_VCT_CFG6_CTRL_REG, in yt8821_utp_init()
2553 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2561 ret = ytphy_modify_ext(phydev, YT8821_UTP_EXT_PLL_CTRL_REG, in yt8821_utp_init()
2570 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2580 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2590 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2600 ret = ytphy_modify_ext(phydev, in yt8821_utp_init()
2605 return phy_restore_page(phydev, old_page, ret); in yt8821_utp_init()
2610 * @phydev: a pointer to a &struct phy_device
2615 static int yt8821_auto_sleep_config(struct phy_device *phydev, in yt8821_auto_sleep_config() argument
2621 old_page = phy_select_page(phydev, YT8521_RSSR_UTP_SPACE); in yt8821_auto_sleep_config()
2623 phydev_err(phydev, "Failed to select page: %d\n", in yt8821_auto_sleep_config()
2628 ret = ytphy_modify_ext(phydev, in yt8821_auto_sleep_config()
2634 return phy_restore_page(phydev, old_page, ret); in yt8821_auto_sleep_config()
2639 * @phydev: a pointer to a &struct phy_device
2643 static int yt8821_soft_reset(struct phy_device *phydev) in yt8821_soft_reset() argument
2645 return ytphy_modify_ext_with_lock(phydev, YT8521_CHIP_CONFIG_REG, in yt8821_soft_reset()
2651 * @phydev: a pointer to a &struct phy_device
2655 static int yt8821_config_init(struct phy_device *phydev) in yt8821_config_init() argument
2661 if (phydev->interface == PHY_INTERFACE_MODE_2500BASEX) in yt8821_config_init()
2665 ret = ytphy_modify_ext_with_lock(phydev, in yt8821_config_init()
2673 phydev->possible_interfaces); in yt8821_config_init()
2677 phydev->possible_interfaces); in yt8821_config_init()
2679 phydev->rate_matching = RATE_MATCH_NONE; in yt8821_config_init()
2681 phydev->rate_matching = RATE_MATCH_PAUSE; in yt8821_config_init()
2684 ret = yt8821_serdes_init(phydev); in yt8821_config_init()
2688 ret = yt8821_utp_init(phydev); in yt8821_config_init()
2693 ret = yt8821_auto_sleep_config(phydev, false); in yt8821_config_init()
2698 return yt8821_soft_reset(phydev); in yt8821_config_init()
2702 * yt8821_adjust_status() - update speed and duplex to phydev
2703 * @phydev: a pointer to a &struct phy_device
2706 static void yt8821_adjust_status(struct phy_device *phydev, int val) in yt8821_adjust_status() argument
2731 phydev->speed = speed; in yt8821_adjust_status()
2732 phydev->duplex = duplex; in yt8821_adjust_status()
2737 * @phydev: a pointer to a &struct phy_device
2739 static void yt8821_update_interface(struct phy_device *phydev) in yt8821_update_interface() argument
2741 if (!phydev->link) in yt8821_update_interface()
2744 switch (phydev->speed) { in yt8821_update_interface()
2746 phydev->interface = PHY_INTERFACE_MODE_2500BASEX; in yt8821_update_interface()
2751 phydev->interface = PHY_INTERFACE_MODE_SGMII; in yt8821_update_interface()
2754 phydev_warn(phydev, "phy speed err :%d\n", phydev->speed); in yt8821_update_interface()
2761 * @phydev: a pointer to a &struct phy_device
2765 static int yt8821_read_status(struct phy_device *phydev) in yt8821_read_status() argument
2771 ret = ytphy_write_ext_with_lock(phydev, in yt8821_read_status()
2777 ret = genphy_read_status(phydev); in yt8821_read_status()
2781 if (phydev->autoneg_complete) { in yt8821_read_status()
2782 ret = genphy_c45_read_lpa(phydev); in yt8821_read_status()
2787 ret = phy_read(phydev, YTPHY_SPECIFIC_STATUS_REG); in yt8821_read_status()
2795 yt8821_adjust_status(phydev, val); in yt8821_read_status()
2798 if (phydev->link == 0) in yt8821_read_status()
2799 phydev_dbg(phydev, in yt8821_read_status()
2801 __func__, phydev->mdio.addr); in yt8821_read_status()
2802 phydev->link = 1; in yt8821_read_status()
2804 if (phydev->link == 1) in yt8821_read_status()
2805 phydev_dbg(phydev, in yt8821_read_status()
2807 __func__, phydev->mdio.addr); in yt8821_read_status()
2808 phydev->link = 0; in yt8821_read_status()
2811 val = ytphy_read_ext_with_lock(phydev, YT8521_CHIP_CONFIG_REG); in yt8821_read_status()
2817 yt8821_update_interface(phydev); in yt8821_read_status()
2824 * @phydev: the phy_device struct
2833 static int yt8821_modify_utp_fiber_bmcr(struct phy_device *phydev, in yt8821_modify_utp_fiber_bmcr() argument
2838 ret = yt8521_modify_bmcr_paged(phydev, YT8521_RSSR_UTP_SPACE, in yt8821_modify_utp_fiber_bmcr()
2843 return yt8521_modify_bmcr_paged(phydev, YT8521_RSSR_FIBER_SPACE, in yt8821_modify_utp_fiber_bmcr()
2849 * @phydev: a pointer to a &struct phy_device
2853 static int yt8821_suspend(struct phy_device *phydev) in yt8821_suspend() argument
2857 wol_config = ytphy_read_ext_with_lock(phydev, in yt8821_suspend()
2866 return yt8821_modify_utp_fiber_bmcr(phydev, 0, BMCR_PDOWN); in yt8821_suspend()
2871 * @phydev: a pointer to a &struct phy_device
2875 static int yt8821_resume(struct phy_device *phydev) in yt8821_resume() argument
2881 ret = yt8821_auto_sleep_config(phydev, false); in yt8821_resume()
2885 wol_config = ytphy_read_ext_with_lock(phydev, in yt8821_resume()
2894 return yt8821_modify_utp_fiber_bmcr(phydev, BMCR_PDOWN, 0); in yt8821_resume()