diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2009-04-25 08:53:33 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-04-27 05:53:51 -0400 |
commit | aa73832c5a80d6c52c69b18af858d88fa595dd3c (patch) | |
tree | 8649f4137178fc1cb6f3c1116fe713b937a82f61 /drivers/net/fs_enet/fs_enet-main.c | |
parent | fd84f0ee50d3abedd11454b016823aa3ffcdc919 (diff) |
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: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/fs_enet/fs_enet-main.c')
-rw-r--r-- | drivers/net/fs_enet/fs_enet-main.c | 69 |
1 files changed, 11 insertions, 58 deletions
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c index a9cbc3191a2a..9604aaed61d6 100644 --- a/drivers/net/fs_enet/fs_enet-main.c +++ b/drivers/net/fs_enet/fs_enet-main.c | |||
@@ -36,6 +36,8 @@ | |||
36 | #include <linux/fs.h> | 36 | #include <linux/fs.h> |
37 | #include <linux/platform_device.h> | 37 | #include <linux/platform_device.h> |
38 | #include <linux/phy.h> | 38 | #include <linux/phy.h> |
39 | #include <linux/of.h> | ||
40 | #include <linux/of_mdio.h> | ||
39 | #include <linux/of_platform.h> | 41 | #include <linux/of_platform.h> |
40 | #include <linux/of_gpio.h> | 42 | #include <linux/of_gpio.h> |
41 | 43 | ||
@@ -752,9 +754,10 @@ static int fs_init_phy(struct net_device *dev) | |||
752 | fep->oldlink = 0; | 754 | fep->oldlink = 0; |
753 | fep->oldspeed = 0; | 755 | fep->oldspeed = 0; |
754 | fep->oldduplex = -1; | 756 | fep->oldduplex = -1; |
755 | if(fep->fpi->bus_id) | 757 | if(fep->fpi->phy_node) |
756 | phydev = phy_connect(dev, fep->fpi->bus_id, &fs_adjust_link, 0, | 758 | phydev = of_phy_connect(dev, fep->fpi->phy_node, |
757 | PHY_INTERFACE_MODE_MII); | 759 | &fs_adjust_link, 0, |
760 | PHY_INTERFACE_MODE_MII); | ||
758 | else { | 761 | else { |
759 | printk("No phy bus ID specified in BSP code\n"); | 762 | printk("No phy bus ID specified in BSP code\n"); |
760 | return -EINVAL; | 763 | return -EINVAL; |
@@ -962,57 +965,6 @@ static void cleanup_immap(void) | |||
962 | 965 | ||
963 | /**************************************************************************************/ | 966 | /**************************************************************************************/ |
964 | 967 | ||
965 | static int __devinit find_phy(struct device_node *np, | ||
966 | struct fs_platform_info *fpi) | ||
967 | { | ||
968 | struct device_node *phynode, *mdionode; | ||
969 | int ret = 0, len, bus_id; | ||
970 | const u32 *data; | ||
971 | |||
972 | data = of_get_property(np, "fixed-link", NULL); | ||
973 | if (data) { | ||
974 | snprintf(fpi->bus_id, 16, "%x:%02x", 0, *data); | ||
975 | return 0; | ||
976 | } | ||
977 | |||
978 | data = of_get_property(np, "phy-handle", &len); | ||
979 | if (!data || len != 4) | ||
980 | return -EINVAL; | ||
981 | |||
982 | phynode = of_find_node_by_phandle(*data); | ||
983 | if (!phynode) | ||
984 | return -EINVAL; | ||
985 | |||
986 | data = of_get_property(phynode, "reg", &len); | ||
987 | if (!data || len != 4) { | ||
988 | ret = -EINVAL; | ||
989 | goto out_put_phy; | ||
990 | } | ||
991 | |||
992 | mdionode = of_get_parent(phynode); | ||
993 | if (!mdionode) { | ||
994 | ret = -EINVAL; | ||
995 | goto out_put_phy; | ||
996 | } | ||
997 | |||
998 | bus_id = of_get_gpio(mdionode, 0); | ||
999 | if (bus_id < 0) { | ||
1000 | struct resource res; | ||
1001 | ret = of_address_to_resource(mdionode, 0, &res); | ||
1002 | if (ret) | ||
1003 | goto out_put_mdio; | ||
1004 | bus_id = res.start; | ||
1005 | } | ||
1006 | |||
1007 | snprintf(fpi->bus_id, 16, "%x:%02x", bus_id, *data); | ||
1008 | |||
1009 | out_put_mdio: | ||
1010 | of_node_put(mdionode); | ||
1011 | out_put_phy: | ||
1012 | of_node_put(phynode); | ||
1013 | return ret; | ||
1014 | } | ||
1015 | |||
1016 | #ifdef CONFIG_FS_ENET_HAS_FEC | 968 | #ifdef CONFIG_FS_ENET_HAS_FEC |
1017 | #define IS_FEC(match) ((match)->data == &fs_fec_ops) | 969 | #define IS_FEC(match) ((match)->data == &fs_fec_ops) |
1018 | #else | 970 | #else |
@@ -1062,9 +1014,9 @@ static int __devinit fs_enet_probe(struct of_device *ofdev, | |||
1062 | fpi->rx_copybreak = 240; | 1014 | fpi->rx_copybreak = 240; |
1063 | fpi->use_napi = 1; | 1015 | fpi->use_napi = 1; |
1064 | fpi->napi_weight = 17; | 1016 | fpi->napi_weight = 17; |
1065 | 1017 | fpi->phy_node = of_parse_phandle(ofdev->node, "phy-handle", 0); | |
1066 | ret = find_phy(ofdev->node, fpi); | 1018 | if ((!fpi->phy_node) && (!of_get_property(ofdev->node, "fixed-link", |
1067 | if (ret) | 1019 | NULL))) |
1068 | goto out_free_fpi; | 1020 | goto out_free_fpi; |
1069 | 1021 | ||
1070 | privsize = sizeof(*fep) + | 1022 | privsize = sizeof(*fep) + |
@@ -1136,6 +1088,7 @@ out_cleanup_data: | |||
1136 | out_free_dev: | 1088 | out_free_dev: |
1137 | free_netdev(ndev); | 1089 | free_netdev(ndev); |
1138 | dev_set_drvdata(&ofdev->dev, NULL); | 1090 | dev_set_drvdata(&ofdev->dev, NULL); |
1091 | of_node_put(fpi->phy_node); | ||
1139 | out_free_fpi: | 1092 | out_free_fpi: |
1140 | kfree(fpi); | 1093 | kfree(fpi); |
1141 | return ret; | 1094 | return ret; |
@@ -1151,7 +1104,7 @@ static int fs_enet_remove(struct of_device *ofdev) | |||
1151 | fep->ops->free_bd(ndev); | 1104 | fep->ops->free_bd(ndev); |
1152 | fep->ops->cleanup_data(ndev); | 1105 | fep->ops->cleanup_data(ndev); |
1153 | dev_set_drvdata(fep->dev, NULL); | 1106 | dev_set_drvdata(fep->dev, NULL); |
1154 | 1107 | of_node_put(fep->fpi->phy_node); | |
1155 | free_netdev(ndev); | 1108 | free_netdev(ndev); |
1156 | return 0; | 1109 | return 0; |
1157 | } | 1110 | } |