aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c69
-rw-r--r--drivers/net/fs_enet/mii-bitbang.c29
-rw-r--r--drivers/net/fs_enet/mii-fec.c26
-rw-r--r--include/linux/fs_enet_pd.h6
4 files changed, 16 insertions, 114 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
965static 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
1009out_put_mdio:
1010 of_node_put(mdionode);
1011out_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:
1136out_free_dev: 1088out_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);
1139out_free_fpi: 1092out_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}
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
index 49b6645d7e0c..93b481b0e3c7 100644
--- a/drivers/net/fs_enet/mii-bitbang.c
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -22,6 +22,7 @@
22#include <linux/mii.h> 22#include <linux/mii.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/mdio-bitbang.h> 24#include <linux/mdio-bitbang.h>
25#include <linux/of_mdio.h>
25#include <linux/of_platform.h> 26#include <linux/of_platform.h>
26 27
27#include "fs_enet.h" 28#include "fs_enet.h"
@@ -149,31 +150,12 @@ static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
149 return 0; 150 return 0;
150} 151}
151 152
152static void __devinit add_phy(struct mii_bus *bus, struct device_node *np)
153{
154 const u32 *data;
155 int len, id, irq;
156
157 data = of_get_property(np, "reg", &len);
158 if (!data || len != 4)
159 return;
160
161 id = *data;
162 bus->phy_mask &= ~(1 << id);
163
164 irq = of_irq_to_resource(np, 0, NULL);
165 if (irq != NO_IRQ)
166 bus->irq[id] = irq;
167}
168
169static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, 153static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
170 const struct of_device_id *match) 154 const struct of_device_id *match)
171{ 155{
172 struct device_node *np = NULL;
173 struct mii_bus *new_bus; 156 struct mii_bus *new_bus;
174 struct bb_info *bitbang; 157 struct bb_info *bitbang;
175 int ret = -ENOMEM; 158 int ret = -ENOMEM;
176 int i;
177 159
178 bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL); 160 bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
179 if (!bitbang) 161 if (!bitbang)
@@ -196,17 +178,10 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
196 if (!new_bus->irq) 178 if (!new_bus->irq)
197 goto out_unmap_regs; 179 goto out_unmap_regs;
198 180
199 for (i = 0; i < PHY_MAX_ADDR; i++)
200 new_bus->irq[i] = -1;
201
202 while ((np = of_get_next_child(ofdev->node, np)))
203 if (!strcmp(np->type, "ethernet-phy"))
204 add_phy(new_bus, np);
205
206 new_bus->parent = &ofdev->dev; 181 new_bus->parent = &ofdev->dev;
207 dev_set_drvdata(&ofdev->dev, new_bus); 182 dev_set_drvdata(&ofdev->dev, new_bus);
208 183
209 ret = mdiobus_register(new_bus); 184 ret = of_mdiobus_register(new_bus, ofdev->node);
210 if (ret) 185 if (ret)
211 goto out_free_irqs; 186 goto out_free_irqs;
212 187
diff --git a/drivers/net/fs_enet/mii-fec.c b/drivers/net/fs_enet/mii-fec.c
index 61aaae444b40..75a09994d665 100644
--- a/drivers/net/fs_enet/mii-fec.c
+++ b/drivers/net/fs_enet/mii-fec.c
@@ -100,23 +100,6 @@ static int fs_enet_fec_mii_reset(struct mii_bus *bus)
100 return 0; 100 return 0;
101} 101}
102 102
103static void __devinit add_phy(struct mii_bus *bus, struct device_node *np)
104{
105 const u32 *data;
106 int len, id, irq;
107
108 data = of_get_property(np, "reg", &len);
109 if (!data || len != 4)
110 return;
111
112 id = *data;
113 bus->phy_mask &= ~(1 << id);
114
115 irq = of_irq_to_resource(np, 0, NULL);
116 if (irq != NO_IRQ)
117 bus->irq[id] = irq;
118}
119
120static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, 103static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
121 const struct of_device_id *match) 104 const struct of_device_id *match)
122{ 105{
@@ -163,17 +146,10 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
163 if (!new_bus->irq) 146 if (!new_bus->irq)
164 goto out_unmap_regs; 147 goto out_unmap_regs;
165 148
166 for (i = 0; i < PHY_MAX_ADDR; i++)
167 new_bus->irq[i] = -1;
168
169 while ((np = of_get_next_child(ofdev->node, np)))
170 if (!strcmp(np->type, "ethernet-phy"))
171 add_phy(new_bus, np);
172
173 new_bus->parent = &ofdev->dev; 149 new_bus->parent = &ofdev->dev;
174 dev_set_drvdata(&ofdev->dev, new_bus); 150 dev_set_drvdata(&ofdev->dev, new_bus);
175 151
176 ret = mdiobus_register(new_bus); 152 ret = of_mdiobus_register(new_bus, ofdev->node);
177 if (ret) 153 if (ret)
178 goto out_free_irqs; 154 goto out_free_irqs;
179 155
diff --git a/include/linux/fs_enet_pd.h b/include/linux/fs_enet_pd.h
index 8300cab30f9a..51b793466ff3 100644
--- a/include/linux/fs_enet_pd.h
+++ b/include/linux/fs_enet_pd.h
@@ -17,6 +17,7 @@
17#define FS_ENET_PD_H 17#define FS_ENET_PD_H
18 18
19#include <linux/string.h> 19#include <linux/string.h>
20#include <linux/of_mdio.h>
20#include <asm/types.h> 21#include <asm/types.h>
21 22
22#define FS_ENET_NAME "fs_enet" 23#define FS_ENET_NAME "fs_enet"
@@ -130,10 +131,7 @@ struct fs_platform_info {
130 131
131 u32 device_flags; 132 u32 device_flags;
132 133
133 int phy_addr; /* the phy address (-1 no phy) */ 134 struct device_node *phy_node;
134 char bus_id[16];
135 int phy_irq; /* the phy irq (if it exists) */
136
137 const struct fs_mii_bus_info *bus_info; 135 const struct fs_mii_bus_info *bus_info;
138 136
139 int rx_ring, tx_ring; /* number of buffers on rx */ 137 int rx_ring, tx_ring; /* number of buffers on rx */