Commit aa73832c authored by Grant Likely's avatar Grant Likely Committed by David S. Miller

net: Rework fs_enet driver to use of_mdio infrastructure

This patch simplifies the driver by making use of more common code.
Signed-off-by: default avatarGrant Likely <grant.likely@secretlab.ca>
Acked-by: default avatarAndy Fleming <afleming@freescale.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fd84f0ee
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/of.h>
#include <linux/of_mdio.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
...@@ -752,9 +754,10 @@ static int fs_init_phy(struct net_device *dev) ...@@ -752,9 +754,10 @@ static int fs_init_phy(struct net_device *dev)
fep->oldlink = 0; fep->oldlink = 0;
fep->oldspeed = 0; fep->oldspeed = 0;
fep->oldduplex = -1; fep->oldduplex = -1;
if(fep->fpi->bus_id) if(fep->fpi->phy_node)
phydev = phy_connect(dev, fep->fpi->bus_id, &fs_adjust_link, 0, phydev = of_phy_connect(dev, fep->fpi->phy_node,
PHY_INTERFACE_MODE_MII); &fs_adjust_link, 0,
PHY_INTERFACE_MODE_MII);
else { else {
printk("No phy bus ID specified in BSP code\n"); printk("No phy bus ID specified in BSP code\n");
return -EINVAL; return -EINVAL;
...@@ -962,57 +965,6 @@ static void cleanup_immap(void) ...@@ -962,57 +965,6 @@ static void cleanup_immap(void)
/**************************************************************************************/ /**************************************************************************************/
static int __devinit find_phy(struct device_node *np,
struct fs_platform_info *fpi)
{
struct device_node *phynode, *mdionode;
int ret = 0, len, bus_id;
const u32 *data;
data = of_get_property(np, "fixed-link", NULL);
if (data) {
snprintf(fpi->bus_id, 16, "%x:%02x", 0, *data);
return 0;
}
data = of_get_property(np, "phy-handle", &len);
if (!data || len != 4)
return -EINVAL;
phynode = of_find_node_by_phandle(*data);
if (!phynode)
return -EINVAL;
data = of_get_property(phynode, "reg", &len);
if (!data || len != 4) {
ret = -EINVAL;
goto out_put_phy;
}
mdionode = of_get_parent(phynode);
if (!mdionode) {
ret = -EINVAL;
goto out_put_phy;
}
bus_id = of_get_gpio(mdionode, 0);
if (bus_id < 0) {
struct resource res;
ret = of_address_to_resource(mdionode, 0, &res);
if (ret)
goto out_put_mdio;
bus_id = res.start;
}
snprintf(fpi->bus_id, 16, "%x:%02x", bus_id, *data);
out_put_mdio:
of_node_put(mdionode);
out_put_phy:
of_node_put(phynode);
return ret;
}
#ifdef CONFIG_FS_ENET_HAS_FEC #ifdef CONFIG_FS_ENET_HAS_FEC
#define IS_FEC(match) ((match)->data == &fs_fec_ops) #define IS_FEC(match) ((match)->data == &fs_fec_ops)
#else #else
...@@ -1062,9 +1014,9 @@ static int __devinit fs_enet_probe(struct of_device *ofdev, ...@@ -1062,9 +1014,9 @@ static int __devinit fs_enet_probe(struct of_device *ofdev,
fpi->rx_copybreak = 240; fpi->rx_copybreak = 240;
fpi->use_napi = 1; fpi->use_napi = 1;
fpi->napi_weight = 17; fpi->napi_weight = 17;
fpi->phy_node = of_parse_phandle(ofdev->node, "phy-handle", 0);
ret = find_phy(ofdev->node, fpi); if ((!fpi->phy_node) && (!of_get_property(ofdev->node, "fixed-link",
if (ret) NULL)))
goto out_free_fpi; goto out_free_fpi;
privsize = sizeof(*fep) + privsize = sizeof(*fep) +
...@@ -1136,6 +1088,7 @@ out_cleanup_data: ...@@ -1136,6 +1088,7 @@ out_cleanup_data:
out_free_dev: out_free_dev:
free_netdev(ndev); free_netdev(ndev);
dev_set_drvdata(&ofdev->dev, NULL); dev_set_drvdata(&ofdev->dev, NULL);
of_node_put(fpi->phy_node);
out_free_fpi: out_free_fpi:
kfree(fpi); kfree(fpi);
return ret; return ret;
...@@ -1151,7 +1104,7 @@ static int fs_enet_remove(struct of_device *ofdev) ...@@ -1151,7 +1104,7 @@ static int fs_enet_remove(struct of_device *ofdev)
fep->ops->free_bd(ndev); fep->ops->free_bd(ndev);
fep->ops->cleanup_data(ndev); fep->ops->cleanup_data(ndev);
dev_set_drvdata(fep->dev, NULL); dev_set_drvdata(fep->dev, NULL);
of_node_put(fep->fpi->phy_node);
free_netdev(ndev); free_netdev(ndev);
return 0; return 0;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/mii.h> #include <linux/mii.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/mdio-bitbang.h> #include <linux/mdio-bitbang.h>
#include <linux/of_mdio.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include "fs_enet.h" #include "fs_enet.h"
...@@ -149,31 +150,12 @@ static int __devinit fs_mii_bitbang_init(struct mii_bus *bus, ...@@ -149,31 +150,12 @@ static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
return 0; return 0;
} }
static void __devinit add_phy(struct mii_bus *bus, struct device_node *np)
{
const u32 *data;
int len, id, irq;
data = of_get_property(np, "reg", &len);
if (!data || len != 4)
return;
id = *data;
bus->phy_mask &= ~(1 << id);
irq = of_irq_to_resource(np, 0, NULL);
if (irq != NO_IRQ)
bus->irq[id] = irq;
}
static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
const struct of_device_id *match) const struct of_device_id *match)
{ {
struct device_node *np = NULL;
struct mii_bus *new_bus; struct mii_bus *new_bus;
struct bb_info *bitbang; struct bb_info *bitbang;
int ret = -ENOMEM; int ret = -ENOMEM;
int i;
bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL); bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
if (!bitbang) if (!bitbang)
...@@ -196,17 +178,10 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, ...@@ -196,17 +178,10 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
if (!new_bus->irq) if (!new_bus->irq)
goto out_unmap_regs; goto out_unmap_regs;
for (i = 0; i < PHY_MAX_ADDR; i++)
new_bus->irq[i] = -1;
while ((np = of_get_next_child(ofdev->node, np)))
if (!strcmp(np->type, "ethernet-phy"))
add_phy(new_bus, np);
new_bus->parent = &ofdev->dev; new_bus->parent = &ofdev->dev;
dev_set_drvdata(&ofdev->dev, new_bus); dev_set_drvdata(&ofdev->dev, new_bus);
ret = mdiobus_register(new_bus); ret = of_mdiobus_register(new_bus, ofdev->node);
if (ret) if (ret)
goto out_free_irqs; goto out_free_irqs;
......
...@@ -100,23 +100,6 @@ static int fs_enet_fec_mii_reset(struct mii_bus *bus) ...@@ -100,23 +100,6 @@ static int fs_enet_fec_mii_reset(struct mii_bus *bus)
return 0; return 0;
} }
static void __devinit add_phy(struct mii_bus *bus, struct device_node *np)
{
const u32 *data;
int len, id, irq;
data = of_get_property(np, "reg", &len);
if (!data || len != 4)
return;
id = *data;
bus->phy_mask &= ~(1 << id);
irq = of_irq_to_resource(np, 0, NULL);
if (irq != NO_IRQ)
bus->irq[id] = irq;
}
static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
const struct of_device_id *match) const struct of_device_id *match)
{ {
...@@ -163,17 +146,10 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, ...@@ -163,17 +146,10 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
if (!new_bus->irq) if (!new_bus->irq)
goto out_unmap_regs; goto out_unmap_regs;
for (i = 0; i < PHY_MAX_ADDR; i++)
new_bus->irq[i] = -1;
while ((np = of_get_next_child(ofdev->node, np)))
if (!strcmp(np->type, "ethernet-phy"))
add_phy(new_bus, np);
new_bus->parent = &ofdev->dev; new_bus->parent = &ofdev->dev;
dev_set_drvdata(&ofdev->dev, new_bus); dev_set_drvdata(&ofdev->dev, new_bus);
ret = mdiobus_register(new_bus); ret = of_mdiobus_register(new_bus, ofdev->node);
if (ret) if (ret)
goto out_free_irqs; goto out_free_irqs;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#define FS_ENET_PD_H #define FS_ENET_PD_H
#include <linux/string.h> #include <linux/string.h>
#include <linux/of_mdio.h>
#include <asm/types.h> #include <asm/types.h>
#define FS_ENET_NAME "fs_enet" #define FS_ENET_NAME "fs_enet"
...@@ -130,10 +131,7 @@ struct fs_platform_info { ...@@ -130,10 +131,7 @@ struct fs_platform_info {
u32 device_flags; u32 device_flags;
int phy_addr; /* the phy address (-1 no phy) */ struct device_node *phy_node;
char bus_id[16];
int phy_irq; /* the phy irq (if it exists) */
const struct fs_mii_bus_info *bus_info; const struct fs_mii_bus_info *bus_info;
int rx_ring, tx_ring; /* number of buffers on rx */ int rx_ring, tx_ring; /* number of buffers on rx */
......
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