Commit c332177e authored by Philippe Reynes's avatar Philippe Reynes Committed by David S. Miller

net: ethernet: davinci_emac: use phydev from struct net_device

The private structure contain a pointer to phydev, but the structure
net_device already contain such pointer. So we can remove the pointer
phy in the private structure, and update the driver to use the
one contained in struct net_device.
Signed-off-by: default avatarPhilippe Reynes <tremyfr@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 513334e1
...@@ -348,7 +348,6 @@ struct emac_priv { ...@@ -348,7 +348,6 @@ struct emac_priv {
u32 rx_addr_type; u32 rx_addr_type;
const char *phy_id; const char *phy_id;
struct device_node *phy_node; struct device_node *phy_node;
struct phy_device *phydev;
spinlock_t lock; spinlock_t lock;
/*platform specific members*/ /*platform specific members*/
void (*int_enable) (void); void (*int_enable) (void);
...@@ -496,9 +495,8 @@ static void emac_get_drvinfo(struct net_device *ndev, ...@@ -496,9 +495,8 @@ static void emac_get_drvinfo(struct net_device *ndev,
static int emac_get_settings(struct net_device *ndev, static int emac_get_settings(struct net_device *ndev,
struct ethtool_cmd *ecmd) struct ethtool_cmd *ecmd)
{ {
struct emac_priv *priv = netdev_priv(ndev); if (ndev->phydev)
if (priv->phydev) return phy_ethtool_gset(ndev->phydev, ecmd);
return phy_ethtool_gset(priv->phydev, ecmd);
else else
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -514,9 +512,8 @@ static int emac_get_settings(struct net_device *ndev, ...@@ -514,9 +512,8 @@ static int emac_get_settings(struct net_device *ndev,
*/ */
static int emac_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd) static int emac_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd)
{ {
struct emac_priv *priv = netdev_priv(ndev); if (ndev->phydev)
if (priv->phydev) return phy_ethtool_sset(ndev->phydev, ecmd);
return phy_ethtool_sset(priv->phydev, ecmd);
else else
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -651,8 +648,8 @@ static void emac_update_phystatus(struct emac_priv *priv) ...@@ -651,8 +648,8 @@ static void emac_update_phystatus(struct emac_priv *priv)
mac_control = emac_read(EMAC_MACCONTROL); mac_control = emac_read(EMAC_MACCONTROL);
cur_duplex = (mac_control & EMAC_MACCONTROL_FULLDUPLEXEN) ? cur_duplex = (mac_control & EMAC_MACCONTROL_FULLDUPLEXEN) ?
DUPLEX_FULL : DUPLEX_HALF; DUPLEX_FULL : DUPLEX_HALF;
if (priv->phydev) if (ndev->phydev)
new_duplex = priv->phydev->duplex; new_duplex = ndev->phydev->duplex;
else else
new_duplex = DUPLEX_FULL; new_duplex = DUPLEX_FULL;
...@@ -1454,7 +1451,7 @@ static void emac_poll_controller(struct net_device *ndev) ...@@ -1454,7 +1451,7 @@ static void emac_poll_controller(struct net_device *ndev)
static void emac_adjust_link(struct net_device *ndev) static void emac_adjust_link(struct net_device *ndev)
{ {
struct emac_priv *priv = netdev_priv(ndev); struct emac_priv *priv = netdev_priv(ndev);
struct phy_device *phydev = priv->phydev; struct phy_device *phydev = ndev->phydev;
unsigned long flags; unsigned long flags;
int new_state = 0; int new_state = 0;
...@@ -1483,7 +1480,7 @@ static void emac_adjust_link(struct net_device *ndev) ...@@ -1483,7 +1480,7 @@ static void emac_adjust_link(struct net_device *ndev)
} }
if (new_state) { if (new_state) {
emac_update_phystatus(priv); emac_update_phystatus(priv);
phy_print_status(priv->phydev); phy_print_status(ndev->phydev);
} }
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
...@@ -1505,15 +1502,13 @@ static void emac_adjust_link(struct net_device *ndev) ...@@ -1505,15 +1502,13 @@ static void emac_adjust_link(struct net_device *ndev)
*/ */
static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd) static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
{ {
struct emac_priv *priv = netdev_priv(ndev);
if (!(netif_running(ndev))) if (!(netif_running(ndev)))
return -EINVAL; return -EINVAL;
/* TODO: Add phy read and write and private statistics get feature */ /* TODO: Add phy read and write and private statistics get feature */
if (priv->phydev) if (ndev->phydev)
return phy_mii_ioctl(priv->phydev, ifrq, cmd); return phy_mii_ioctl(ndev->phydev, ifrq, cmd);
else else
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -1542,6 +1537,7 @@ static int emac_dev_open(struct net_device *ndev) ...@@ -1542,6 +1537,7 @@ static int emac_dev_open(struct net_device *ndev)
int res_num = 0, irq_num = 0; int res_num = 0, irq_num = 0;
int i = 0; int i = 0;
struct emac_priv *priv = netdev_priv(ndev); struct emac_priv *priv = netdev_priv(ndev);
struct phy_device *phydev = NULL;
ret = pm_runtime_get_sync(&priv->pdev->dev); ret = pm_runtime_get_sync(&priv->pdev->dev);
if (ret < 0) { if (ret < 0) {
...@@ -1607,12 +1603,10 @@ static int emac_dev_open(struct net_device *ndev) ...@@ -1607,12 +1603,10 @@ static int emac_dev_open(struct net_device *ndev)
cpdma_ctlr_start(priv->dma); cpdma_ctlr_start(priv->dma);
priv->phydev = NULL;
if (priv->phy_node) { if (priv->phy_node) {
priv->phydev = of_phy_connect(ndev, priv->phy_node, phydev = of_phy_connect(ndev, priv->phy_node,
&emac_adjust_link, 0, 0); &emac_adjust_link, 0, 0);
if (!priv->phydev) { if (!phydev) {
dev_err(emac_dev, "could not connect to phy %s\n", dev_err(emac_dev, "could not connect to phy %s\n",
priv->phy_node->full_name); priv->phy_node->full_name);
ret = -ENODEV; ret = -ENODEV;
...@@ -1621,7 +1615,7 @@ static int emac_dev_open(struct net_device *ndev) ...@@ -1621,7 +1615,7 @@ static int emac_dev_open(struct net_device *ndev)
} }
/* use the first phy on the bus if pdata did not give us a phy id */ /* use the first phy on the bus if pdata did not give us a phy id */
if (!priv->phydev && !priv->phy_id) { if (!phydev && !priv->phy_id) {
struct device *phy; struct device *phy;
phy = bus_find_device(&mdio_bus_type, NULL, NULL, phy = bus_find_device(&mdio_bus_type, NULL, NULL,
...@@ -1630,16 +1624,15 @@ static int emac_dev_open(struct net_device *ndev) ...@@ -1630,16 +1624,15 @@ static int emac_dev_open(struct net_device *ndev)
priv->phy_id = dev_name(phy); priv->phy_id = dev_name(phy);
} }
if (!priv->phydev && priv->phy_id && *priv->phy_id) { if (!phydev && priv->phy_id && *priv->phy_id) {
priv->phydev = phy_connect(ndev, priv->phy_id, phydev = phy_connect(ndev, priv->phy_id,
&emac_adjust_link, &emac_adjust_link,
PHY_INTERFACE_MODE_MII); PHY_INTERFACE_MODE_MII);
if (IS_ERR(priv->phydev)) { if (IS_ERR(phydev)) {
dev_err(emac_dev, "could not connect to phy %s\n", dev_err(emac_dev, "could not connect to phy %s\n",
priv->phy_id); priv->phy_id);
ret = PTR_ERR(priv->phydev); ret = PTR_ERR(phydev);
priv->phydev = NULL;
goto err; goto err;
} }
...@@ -1647,10 +1640,10 @@ static int emac_dev_open(struct net_device *ndev) ...@@ -1647,10 +1640,10 @@ static int emac_dev_open(struct net_device *ndev)
priv->speed = 0; priv->speed = 0;
priv->duplex = ~0; priv->duplex = ~0;
phy_attached_info(priv->phydev); phy_attached_info(phydev);
} }
if (!priv->phydev) { if (!phydev) {
/* No PHY , fix the link, speed and duplex settings */ /* No PHY , fix the link, speed and duplex settings */
dev_notice(emac_dev, "no phy, defaulting to 100/full\n"); dev_notice(emac_dev, "no phy, defaulting to 100/full\n");
priv->link = 1; priv->link = 1;
...@@ -1665,8 +1658,8 @@ static int emac_dev_open(struct net_device *ndev) ...@@ -1665,8 +1658,8 @@ static int emac_dev_open(struct net_device *ndev)
if (netif_msg_drv(priv)) if (netif_msg_drv(priv))
dev_notice(emac_dev, "DaVinci EMAC: Opened %s\n", ndev->name); dev_notice(emac_dev, "DaVinci EMAC: Opened %s\n", ndev->name);
if (priv->phydev) if (phydev)
phy_start(priv->phydev); phy_start(phydev);
return 0; return 0;
...@@ -1717,8 +1710,8 @@ static int emac_dev_stop(struct net_device *ndev) ...@@ -1717,8 +1710,8 @@ static int emac_dev_stop(struct net_device *ndev)
cpdma_ctlr_stop(priv->dma); cpdma_ctlr_stop(priv->dma);
emac_write(EMAC_SOFTRESET, 1); emac_write(EMAC_SOFTRESET, 1);
if (priv->phydev) if (ndev->phydev)
phy_disconnect(priv->phydev); phy_disconnect(ndev->phydev);
/* Free IRQ */ /* Free IRQ */
while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, i))) { while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, i))) {
......
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