Commit cd690e48 authored by Andrew Lunn's avatar Andrew Lunn Committed by David S. Miller

phy: Use phy_read() instead of mdiobus_read()

Since we have a phydev, make use of it and the phy_read() function.
This will help with later refactoring.
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bac83c65
...@@ -77,18 +77,16 @@ static void hns_get_mdix_mode(struct net_device *net_dev, ...@@ -77,18 +77,16 @@ static void hns_get_mdix_mode(struct net_device *net_dev,
return; return;
} }
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, HNS_PHY_PAGE_REG, phy_write(phy_dev, HNS_PHY_PAGE_REG, HNS_PHY_PAGE_MDIX);
HNS_PHY_PAGE_MDIX);
retval = mdiobus_read(phy_dev->bus, phy_dev->addr, HNS_PHY_CSC_REG); retval = phy_read(phy_dev, HNS_PHY_CSC_REG);
mdix_ctrl = hnae_get_field(retval, PHY_MDIX_CTRL_M, PHY_MDIX_CTRL_S); mdix_ctrl = hnae_get_field(retval, PHY_MDIX_CTRL_M, PHY_MDIX_CTRL_S);
retval = mdiobus_read(phy_dev->bus, phy_dev->addr, HNS_PHY_CSS_REG); retval = phy_read(phy_dev, HNS_PHY_CSS_REG);
mdix = hnae_get_bit(retval, PHY_MDIX_STATUS_B); mdix = hnae_get_bit(retval, PHY_MDIX_STATUS_B);
is_resolved = hnae_get_bit(retval, PHY_SPEED_DUP_RESOLVE_B); is_resolved = hnae_get_bit(retval, PHY_SPEED_DUP_RESOLVE_B);
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, HNS_PHY_PAGE_REG, phy_write(phy_dev, HNS_PHY_PAGE_REG, HNS_PHY_PAGE_COPPER);
HNS_PHY_PAGE_COPPER);
switch (mdix_ctrl) { switch (mdix_ctrl) {
case 0x0: case 0x0:
...@@ -253,53 +251,36 @@ static int hns_nic_config_phy_loopback(struct phy_device *phy_dev, u8 en) ...@@ -253,53 +251,36 @@ static int hns_nic_config_phy_loopback(struct phy_device *phy_dev, u8 en)
if (en) { if (en) {
/* speed : 1000M */ /* speed : 1000M */
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, HNS_PHY_PAGE_REG, 2);
HNS_PHY_PAGE_REG, 2); phy_write(phy_dev, 21, 0x1046);
(void)mdiobus_write(phy_dev->bus, phy_dev->addr,
21, 0x1046);
/* Force Master */ /* Force Master */
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, 9, 0x1F00);
9, 0x1F00);
/* Soft-reset */ /* Soft-reset */
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, 0, 0x9140);
0, 0x9140);
/* If autoneg disabled,two soft-reset operations */ /* If autoneg disabled,two soft-reset operations */
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, 0, 0x9140);
0, 0x9140); phy_write(phy_dev, 22, 0xFA);
(void)mdiobus_write(phy_dev->bus, phy_dev->addr,
22, 0xFA);
/* Default is 0x0400 */ /* Default is 0x0400 */
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, 1, 0x418);
1, 0x418);
/* Force 1000M Link, Default is 0x0200 */ /* Force 1000M Link, Default is 0x0200 */
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, 7, 0x20C);
7, 0x20C); phy_write(phy_dev, 22, 0);
(void)mdiobus_write(phy_dev->bus, phy_dev->addr,
22, 0);
/* Enable MAC loop-back */ /* Enable MAC loop-back */
val = (u16)mdiobus_read(phy_dev->bus, phy_dev->addr, val = phy_read(phy_dev, COPPER_CONTROL_REG);
COPPER_CONTROL_REG);
val |= PHY_LOOP_BACK; val |= PHY_LOOP_BACK;
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, COPPER_CONTROL_REG, val);
COPPER_CONTROL_REG, val);
} else { } else {
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, 22, 0xFA);
22, 0xFA); phy_write(phy_dev, 1, 0x400);
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, 7, 0x200);
1, 0x400); phy_write(phy_dev, 22, 0);
(void)mdiobus_write(phy_dev->bus, phy_dev->addr,
7, 0x200); val = phy_read(phy_dev, COPPER_CONTROL_REG);
(void)mdiobus_write(phy_dev->bus, phy_dev->addr,
22, 0);
val = (u16)mdiobus_read(phy_dev->bus, phy_dev->addr,
COPPER_CONTROL_REG);
val &= ~PHY_LOOP_BACK; val &= ~PHY_LOOP_BACK;
(void)mdiobus_write(phy_dev->bus, phy_dev->addr, phy_write(phy_dev, COPPER_CONTROL_REG, val);
COPPER_CONTROL_REG, val);
} }
return 0; return 0;
} }
...@@ -1018,16 +999,9 @@ int hns_phy_led_set(struct net_device *netdev, int value) ...@@ -1018,16 +999,9 @@ int hns_phy_led_set(struct net_device *netdev, int value)
struct hns_nic_priv *priv = netdev_priv(netdev); struct hns_nic_priv *priv = netdev_priv(netdev);
struct phy_device *phy_dev = priv->phy; struct phy_device *phy_dev = priv->phy;
if (!phy_dev->bus) { retval = phy_write(phy_dev, HNS_PHY_PAGE_REG, HNS_PHY_PAGE_LED);
netdev_err(netdev, "phy_dev->bus is null!\n"); retval = phy_write(phy_dev, HNS_LED_FC_REG, value);
return -EINVAL; retval = phy_write(phy_dev, HNS_PHY_PAGE_REG, HNS_PHY_PAGE_COPPER);
}
retval = mdiobus_write(phy_dev->bus, phy_dev->addr,
HNS_PHY_PAGE_REG, HNS_PHY_PAGE_LED);
retval = mdiobus_write(phy_dev->bus, phy_dev->addr, HNS_LED_FC_REG,
value);
retval = mdiobus_write(phy_dev->bus, phy_dev->addr,
HNS_PHY_PAGE_REG, HNS_PHY_PAGE_COPPER);
if (retval) { if (retval) {
netdev_err(netdev, "mdiobus_write fail !\n"); netdev_err(netdev, "mdiobus_write fail !\n");
return retval; return retval;
...@@ -1052,19 +1026,15 @@ int hns_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state) ...@@ -1052,19 +1026,15 @@ int hns_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
if (phy_dev) if (phy_dev)
switch (state) { switch (state) {
case ETHTOOL_ID_ACTIVE: case ETHTOOL_ID_ACTIVE:
ret = mdiobus_write(phy_dev->bus, phy_dev->addr, ret = phy_write(phy_dev, HNS_PHY_PAGE_REG,
HNS_PHY_PAGE_REG, HNS_PHY_PAGE_LED);
HNS_PHY_PAGE_LED);
if (ret) if (ret)
return ret; return ret;
priv->phy_led_val = (u16)mdiobus_read(phy_dev->bus, priv->phy_led_val = phy_read(phy_dev, HNS_LED_FC_REG);
phy_dev->addr,
HNS_LED_FC_REG);
ret = mdiobus_write(phy_dev->bus, phy_dev->addr, ret = phy_write(phy_dev, HNS_PHY_PAGE_REG,
HNS_PHY_PAGE_REG, HNS_PHY_PAGE_COPPER);
HNS_PHY_PAGE_COPPER);
if (ret) if (ret)
return ret; return ret;
return 2; return 2;
...@@ -1079,20 +1049,18 @@ int hns_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state) ...@@ -1079,20 +1049,18 @@ int hns_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
return ret; return ret;
break; break;
case ETHTOOL_ID_INACTIVE: case ETHTOOL_ID_INACTIVE:
ret = mdiobus_write(phy_dev->bus, phy_dev->addr, ret = phy_write(phy_dev, HNS_PHY_PAGE_REG,
HNS_PHY_PAGE_REG, HNS_PHY_PAGE_LED);
HNS_PHY_PAGE_LED);
if (ret) if (ret)
return ret; return ret;
ret = mdiobus_write(phy_dev->bus, phy_dev->addr, ret = phy_write(phy_dev, HNS_LED_FC_REG,
HNS_LED_FC_REG, priv->phy_led_val); priv->phy_led_val);
if (ret) if (ret)
return ret; return ret;
ret = mdiobus_write(phy_dev->bus, phy_dev->addr, ret = phy_write(phy_dev, HNS_PHY_PAGE_REG,
HNS_PHY_PAGE_REG, HNS_PHY_PAGE_COPPER);
HNS_PHY_PAGE_COPPER);
if (ret) if (ret)
return ret; return ret;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment