Commit 758c5c11 authored by Woojung.Huh@microchip.com's avatar Woojung.Huh@microchip.com Committed by David S. Miller

lan78xx: Create lan78xx_get_mdix_status() and lan78xx_set_mdix_status() for MDIX control.

Create lan78xx_get_mdix_status() and lan78xx_set_mdix_status() for MDIX control.
Signed-off-by: default avatarWoojung Huh <woojung.huh@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bdfba55e
...@@ -1175,6 +1175,55 @@ static void lan78xx_set_msglevel(struct net_device *net, u32 level) ...@@ -1175,6 +1175,55 @@ static void lan78xx_set_msglevel(struct net_device *net, u32 level)
dev->msg_enable = level; dev->msg_enable = level;
} }
static int lan78xx_get_mdix_status(struct net_device *net)
{
struct phy_device *phydev = net->phydev;
int buf;
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS, LAN88XX_EXT_PAGE_SPACE_1);
buf = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS, LAN88XX_EXT_PAGE_SPACE_0);
return buf;
}
static void lan78xx_set_mdix_status(struct net_device *net, __u8 mdix_ctrl)
{
struct lan78xx_net *dev = netdev_priv(net);
struct phy_device *phydev = net->phydev;
int buf;
if (mdix_ctrl == ETH_TP_MDI) {
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_1);
buf = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
buf &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
phy_write(phydev, LAN88XX_EXT_MODE_CTRL,
buf | LAN88XX_EXT_MODE_CTRL_MDI_);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_0);
} else if (mdix_ctrl == ETH_TP_MDI_X) {
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_1);
buf = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
buf &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
phy_write(phydev, LAN88XX_EXT_MODE_CTRL,
buf | LAN88XX_EXT_MODE_CTRL_MDI_X_);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_0);
} else if (mdix_ctrl == ETH_TP_MDI_AUTO) {
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_1);
buf = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
buf &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
phy_write(phydev, LAN88XX_EXT_MODE_CTRL,
buf | LAN88XX_EXT_MODE_CTRL_AUTO_MDIX_);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_0);
}
dev->mdix_ctrl = mdix_ctrl;
}
static int lan78xx_get_settings(struct net_device *net, struct ethtool_cmd *cmd) static int lan78xx_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
{ {
struct lan78xx_net *dev = netdev_priv(net); struct lan78xx_net *dev = netdev_priv(net);
...@@ -1188,9 +1237,7 @@ static int lan78xx_get_settings(struct net_device *net, struct ethtool_cmd *cmd) ...@@ -1188,9 +1237,7 @@ static int lan78xx_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
ret = phy_ethtool_gset(phydev, cmd); ret = phy_ethtool_gset(phydev, cmd);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS, LAN88XX_EXT_PAGE_SPACE_1); buf = lan78xx_get_mdix_status(net);
buf = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS, LAN88XX_EXT_PAGE_SPACE_0);
buf &= LAN88XX_EXT_MODE_CTRL_MDIX_MASK_; buf &= LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
if (buf == LAN88XX_EXT_MODE_CTRL_AUTO_MDIX_) { if (buf == LAN88XX_EXT_MODE_CTRL_AUTO_MDIX_) {
...@@ -1221,34 +1268,7 @@ static int lan78xx_set_settings(struct net_device *net, struct ethtool_cmd *cmd) ...@@ -1221,34 +1268,7 @@ static int lan78xx_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
return ret; return ret;
if (dev->mdix_ctrl != cmd->eth_tp_mdix_ctrl) { if (dev->mdix_ctrl != cmd->eth_tp_mdix_ctrl) {
if (cmd->eth_tp_mdix_ctrl == ETH_TP_MDI) { lan78xx_set_mdix_status(net, cmd->eth_tp_mdix_ctrl);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_1);
temp = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
temp &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
phy_write(phydev, LAN88XX_EXT_MODE_CTRL,
temp | LAN88XX_EXT_MODE_CTRL_MDI_);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_0);
} else if (cmd->eth_tp_mdix_ctrl == ETH_TP_MDI_X) {
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_1);
temp = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
temp &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
phy_write(phydev, LAN88XX_EXT_MODE_CTRL,
temp | LAN88XX_EXT_MODE_CTRL_MDI_X_);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_0);
} else if (cmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO) {
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_1);
temp = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
temp &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
phy_write(phydev, LAN88XX_EXT_MODE_CTRL,
temp | LAN88XX_EXT_MODE_CTRL_AUTO_MDIX_);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
LAN88XX_EXT_PAGE_SPACE_0);
}
} }
/* change speed & duplex */ /* change speed & duplex */
...@@ -1504,13 +1524,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev) ...@@ -1504,13 +1524,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
} }
/* set to AUTOMDIX */ /* set to AUTOMDIX */
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS, LAN88XX_EXT_PAGE_SPACE_1); lan78xx_set_mdix_status(dev->net, ETH_TP_MDI_AUTO);
ret = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
ret &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
phy_write(phydev, LAN88XX_EXT_MODE_CTRL,
ret | LAN88XX_EXT_MODE_CTRL_AUTO_MDIX_);
phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS, LAN88XX_EXT_PAGE_SPACE_0);
dev->mdix_ctrl = ETH_TP_MDI_AUTO;
/* MAC doesn't support 1000T Half */ /* MAC doesn't support 1000T Half */
phydev->supported &= ~SUPPORTED_1000baseT_Half; phydev->supported &= ~SUPPORTED_1000baseT_Half;
......
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