Lines Matching full:phydev

165 static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)  in at803x_debug_reg_read()  argument
169 ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); in at803x_debug_reg_read()
173 return phy_read(phydev, AT803X_DEBUG_DATA); in at803x_debug_reg_read()
176 static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg, in at803x_debug_reg_mask() argument
182 ret = at803x_debug_reg_read(phydev, reg); in at803x_debug_reg_mask()
190 return phy_write(phydev, AT803X_DEBUG_DATA, val); in at803x_debug_reg_mask()
193 static int at803x_enable_rx_delay(struct phy_device *phydev) in at803x_enable_rx_delay() argument
195 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0, in at803x_enable_rx_delay()
199 static int at803x_enable_tx_delay(struct phy_device *phydev) in at803x_enable_tx_delay() argument
201 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0, in at803x_enable_tx_delay()
205 static int at803x_disable_rx_delay(struct phy_device *phydev) in at803x_disable_rx_delay() argument
207 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, in at803x_disable_rx_delay()
211 static int at803x_disable_tx_delay(struct phy_device *phydev) in at803x_disable_tx_delay() argument
213 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, in at803x_disable_tx_delay()
218 static void at803x_context_save(struct phy_device *phydev, in at803x_context_save() argument
221 context->bmcr = phy_read(phydev, MII_BMCR); in at803x_context_save()
222 context->advertise = phy_read(phydev, MII_ADVERTISE); in at803x_context_save()
223 context->control1000 = phy_read(phydev, MII_CTRL1000); in at803x_context_save()
224 context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE); in at803x_context_save()
225 context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED); in at803x_context_save()
226 context->led_control = phy_read(phydev, AT803X_LED_CONTROL); in at803x_context_save()
230 static void at803x_context_restore(struct phy_device *phydev, in at803x_context_restore() argument
233 phy_write(phydev, MII_BMCR, context->bmcr); in at803x_context_restore()
234 phy_write(phydev, MII_ADVERTISE, context->advertise); in at803x_context_restore()
235 phy_write(phydev, MII_CTRL1000, context->control1000); in at803x_context_restore()
236 phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable); in at803x_context_restore()
237 phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed); in at803x_context_restore()
238 phy_write(phydev, AT803X_LED_CONTROL, context->led_control); in at803x_context_restore()
241 static int at803x_set_wol(struct phy_device *phydev, in at803x_set_wol() argument
244 struct net_device *ndev = phydev->attached_dev; in at803x_set_wol()
264 phy_write_mmd(phydev, AT803X_DEVICE_ADDR, offsets[i], in at803x_set_wol()
267 value = phy_read(phydev, AT803X_INTR_ENABLE); in at803x_set_wol()
269 ret = phy_write(phydev, AT803X_INTR_ENABLE, value); in at803x_set_wol()
272 value = phy_read(phydev, AT803X_INTR_STATUS); in at803x_set_wol()
274 value = phy_read(phydev, AT803X_INTR_ENABLE); in at803x_set_wol()
276 ret = phy_write(phydev, AT803X_INTR_ENABLE, value); in at803x_set_wol()
279 value = phy_read(phydev, AT803X_INTR_STATUS); in at803x_set_wol()
285 static void at803x_get_wol(struct phy_device *phydev, in at803x_get_wol() argument
293 value = phy_read(phydev, AT803X_INTR_ENABLE); in at803x_get_wol()
298 static int at803x_suspend(struct phy_device *phydev) in at803x_suspend() argument
303 value = phy_read(phydev, AT803X_INTR_ENABLE); in at803x_suspend()
311 phy_modify(phydev, MII_BMCR, 0, value); in at803x_suspend()
316 static int at803x_resume(struct phy_device *phydev) in at803x_resume() argument
318 return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0); in at803x_resume()
324 struct phy_device *phydev = rdev_get_drvdata(rdev); in at803x_rgmii_reg_set_voltage_sel() local
327 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, in at803x_rgmii_reg_set_voltage_sel()
330 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, in at803x_rgmii_reg_set_voltage_sel()
336 struct phy_device *phydev = rdev_get_drvdata(rdev); in at803x_rgmii_reg_get_voltage_sel() local
339 val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F); in at803x_rgmii_reg_get_voltage_sel()
380 static int at8031_register_regulators(struct phy_device *phydev) in at8031_register_regulators() argument
382 struct at803x_priv *priv = phydev->priv; in at8031_register_regulators()
383 struct device *dev = &phydev->mdio.dev; in at8031_register_regulators()
387 config.driver_data = phydev; in at8031_register_regulators()
391 phydev_err(phydev, "failed to register VDDIO regulator\n"); in at8031_register_regulators()
397 phydev_err(phydev, "failed to register VDDH regulator\n"); in at8031_register_regulators()
404 static bool at803x_match_phy_id(struct phy_device *phydev, u32 phy_id) in at803x_match_phy_id() argument
406 return (phydev->phy_id & phydev->drv->phy_id_mask) in at803x_match_phy_id()
407 == (phy_id & phydev->drv->phy_id_mask); in at803x_match_phy_id()
410 static int at803x_parse_dt(struct phy_device *phydev) in at803x_parse_dt() argument
412 struct device_node *node = phydev->mdio.dev.of_node; in at803x_parse_dt()
413 struct at803x_priv *priv = phydev->priv; in at803x_parse_dt()
437 phydev_err(phydev, "invalid qca,clk-out-frequency\n"); in at803x_parse_dt()
455 if (at803x_match_phy_id(phydev, ATH8030_PHY_ID) || in at803x_parse_dt()
456 at803x_match_phy_id(phydev, ATH8035_PHY_ID)) { in at803x_parse_dt()
476 phydev_err(phydev, "invalid qca,clk-out-strength\n"); in at803x_parse_dt()
484 if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) { in at803x_parse_dt()
488 ret = at8031_register_regulators(phydev); in at803x_parse_dt()
492 priv->vddio = devm_regulator_get_optional(&phydev->mdio.dev, in at803x_parse_dt()
495 phydev_err(phydev, "failed to get VDDIO regulator\n"); in at803x_parse_dt()
507 static int at803x_probe(struct phy_device *phydev) in at803x_probe() argument
509 struct device *dev = &phydev->mdio.dev; in at803x_probe()
516 phydev->priv = priv; in at803x_probe()
518 return at803x_parse_dt(phydev); in at803x_probe()
521 static void at803x_remove(struct phy_device *phydev) in at803x_remove() argument
523 struct at803x_priv *priv = phydev->priv; in at803x_remove()
529 static int at803x_clk_out_config(struct phy_device *phydev) in at803x_clk_out_config() argument
531 struct at803x_priv *priv = phydev->priv; in at803x_clk_out_config()
537 val = phy_read_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M); in at803x_clk_out_config()
544 return phy_write_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M, val); in at803x_clk_out_config()
547 static int at8031_pll_config(struct phy_device *phydev) in at8031_pll_config() argument
549 struct at803x_priv *priv = phydev->priv; in at8031_pll_config()
555 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, in at8031_pll_config()
558 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, in at8031_pll_config()
562 static int at803x_config_init(struct phy_device *phydev) in at803x_config_init() argument
571 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in at803x_config_init()
572 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) in at803x_config_init()
573 ret = at803x_enable_rx_delay(phydev); in at803x_config_init()
575 ret = at803x_disable_rx_delay(phydev); in at803x_config_init()
579 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in at803x_config_init()
580 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) in at803x_config_init()
581 ret = at803x_enable_tx_delay(phydev); in at803x_config_init()
583 ret = at803x_disable_tx_delay(phydev); in at803x_config_init()
587 ret = at803x_clk_out_config(phydev); in at803x_config_init()
591 if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) { in at803x_config_init()
592 ret = at8031_pll_config(phydev); in at803x_config_init()
600 static int at803x_ack_interrupt(struct phy_device *phydev) in at803x_ack_interrupt() argument
604 err = phy_read(phydev, AT803X_INTR_STATUS); in at803x_ack_interrupt()
609 static int at803x_config_intr(struct phy_device *phydev) in at803x_config_intr() argument
614 value = phy_read(phydev, AT803X_INTR_ENABLE); in at803x_config_intr()
616 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { in at803x_config_intr()
623 err = phy_write(phydev, AT803X_INTR_ENABLE, value); in at803x_config_intr()
626 err = phy_write(phydev, AT803X_INTR_ENABLE, 0); in at803x_config_intr()
631 static void at803x_link_change_notify(struct phy_device *phydev) in at803x_link_change_notify() argument
640 if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) { in at803x_link_change_notify()
643 at803x_context_save(phydev, &context); in at803x_link_change_notify()
645 phy_device_reset(phydev, 1); in at803x_link_change_notify()
647 phy_device_reset(phydev, 0); in at803x_link_change_notify()
650 at803x_context_restore(phydev, &context); in at803x_link_change_notify()
652 phydev_dbg(phydev, "%s(): phy was reset\n", __func__); in at803x_link_change_notify()
656 static int at803x_aneg_done(struct phy_device *phydev) in at803x_aneg_done() argument
660 int aneg_done = genphy_aneg_done(phydev); in at803x_aneg_done()
668 ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG); in at803x_aneg_done()
673 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr & ~AT803X_BT_BX_REG_SEL); in at803x_aneg_done()
676 if (!(phy_read(phydev, AT803X_PSSR) & AT803X_PSSR_MR_AN_COMPLETE)) { in at803x_aneg_done()
677 phydev_warn(phydev, "803x_aneg_done: SGMII link is not ok\n"); in at803x_aneg_done()
681 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr | AT803X_BT_BX_REG_SEL); in at803x_aneg_done()
686 static int at803x_read_status(struct phy_device *phydev) in at803x_read_status() argument
688 int ss, err, old_link = phydev->link; in at803x_read_status()
691 err = genphy_update_link(phydev); in at803x_read_status()
696 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) in at803x_read_status()
699 phydev->speed = SPEED_UNKNOWN; in at803x_read_status()
700 phydev->duplex = DUPLEX_UNKNOWN; in at803x_read_status()
701 phydev->pause = 0; in at803x_read_status()
702 phydev->asym_pause = 0; in at803x_read_status()
704 err = genphy_read_lpa(phydev); in at803x_read_status()
712 ss = phy_read(phydev, AT803X_SPECIFIC_STATUS); in at803x_read_status()
719 sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL); in at803x_read_status()
725 phydev->speed = SPEED_10; in at803x_read_status()
728 phydev->speed = SPEED_100; in at803x_read_status()
731 phydev->speed = SPEED_1000; in at803x_read_status()
735 phydev->duplex = DUPLEX_FULL; in at803x_read_status()
737 phydev->duplex = DUPLEX_HALF; in at803x_read_status()
740 phydev->mdix = ETH_TP_MDI_X; in at803x_read_status()
742 phydev->mdix = ETH_TP_MDI; in at803x_read_status()
746 phydev->mdix_ctrl = ETH_TP_MDI; in at803x_read_status()
749 phydev->mdix_ctrl = ETH_TP_MDI_X; in at803x_read_status()
752 phydev->mdix_ctrl = ETH_TP_MDI_AUTO; in at803x_read_status()
757 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) in at803x_read_status()
758 phy_resolve_aneg_pause(phydev); in at803x_read_status()
763 static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl) in at803x_config_mdix() argument
781 return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL, in at803x_config_mdix()
786 static int at803x_config_aneg(struct phy_device *phydev) in at803x_config_aneg() argument
790 ret = at803x_config_mdix(phydev, phydev->mdix_ctrl); in at803x_config_aneg()
799 ret = genphy_soft_reset(phydev); in at803x_config_aneg()
804 return genphy_config_aneg(phydev); in at803x_config_aneg()
807 static int at803x_get_downshift(struct phy_device *phydev, u8 *d) in at803x_get_downshift() argument
811 val = phy_read(phydev, AT803X_SMART_SPEED); in at803x_get_downshift()
823 static int at803x_set_downshift(struct phy_device *phydev, u8 cnt) in at803x_set_downshift() argument
847 ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set); in at803x_set_downshift()
854 ret = phy_init_hw(phydev); in at803x_set_downshift()
859 static int at803x_get_tunable(struct phy_device *phydev, in at803x_get_tunable() argument
864 return at803x_get_downshift(phydev, data); in at803x_get_tunable()
870 static int at803x_set_tunable(struct phy_device *phydev, in at803x_set_tunable() argument
875 return at803x_set_downshift(phydev, *(const u8 *)data); in at803x_set_tunable()
936 static int at803x_cdt_start(struct phy_device *phydev, int pair) in at803x_cdt_start() argument
943 return phy_write(phydev, AT803X_CDT, cdt); in at803x_cdt_start()
946 static int at803x_cdt_wait_for_completion(struct phy_device *phydev) in at803x_cdt_wait_for_completion() argument
951 ret = phy_read_poll_timeout(phydev, AT803X_CDT, val, in at803x_cdt_wait_for_completion()
958 static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair) in at803x_cable_test_one_pair() argument
968 ret = at803x_cdt_start(phydev, pair); in at803x_cable_test_one_pair()
972 ret = at803x_cdt_wait_for_completion(phydev); in at803x_cable_test_one_pair()
976 val = phy_read(phydev, AT803X_CDT_STATUS); in at803x_cable_test_one_pair()
983 ethnl_cable_test_result(phydev, ethtool_pair[pair], in at803x_cable_test_one_pair()
987 ethnl_cable_test_fault_length(phydev, ethtool_pair[pair], in at803x_cable_test_one_pair()
993 static int at803x_cable_test_get_status(struct phy_device *phydev, in at803x_cable_test_get_status() argument
1000 if (phydev->phy_id == ATH9331_PHY_ID || in at803x_cable_test_get_status()
1001 phydev->phy_id == ATH8032_PHY_ID) in at803x_cable_test_get_status()
1017 ret = at803x_cable_test_one_pair(phydev, pair); in at803x_cable_test_get_status()
1032 static int at803x_cable_test_start(struct phy_device *phydev) in at803x_cable_test_start() argument
1038 phy_write(phydev, MII_BMCR, BMCR_ANENABLE); in at803x_cable_test_start()
1039 phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA); in at803x_cable_test_start()
1040 if (phydev->phy_id != ATH9331_PHY_ID && in at803x_cable_test_start()
1041 phydev->phy_id != ATH8032_PHY_ID) in at803x_cable_test_start()
1042 phy_write(phydev, MII_CTRL1000, 0); in at803x_cable_test_start()