Commit aa73832c5a80d6c52c69b18af858d88fa595dd3c

Authored by Grant Likely
Committed by David S. Miller
1 parent fd84f0ee50

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>

Showing 4 changed files with 16 additions and 114 deletions Side-by-side Diff

drivers/net/fs_enet/fs_enet-main.c
... ... @@ -36,6 +36,8 @@
36 36 #include <linux/fs.h>
37 37 #include <linux/platform_device.h>
38 38 #include <linux/phy.h>
  39 +#include <linux/of.h>
  40 +#include <linux/of_mdio.h>
39 41 #include <linux/of_platform.h>
40 42 #include <linux/of_gpio.h>
41 43  
... ... @@ -752,9 +754,10 @@
752 754 fep->oldlink = 0;
753 755 fep->oldspeed = 0;
754 756 fep->oldduplex = -1;
755   - if(fep->fpi->bus_id)
756   - phydev = phy_connect(dev, fep->fpi->bus_id, &fs_adjust_link, 0,
757   - PHY_INTERFACE_MODE_MII);
  757 + if(fep->fpi->phy_node)
  758 + phydev = of_phy_connect(dev, fep->fpi->phy_node,
  759 + &fs_adjust_link, 0,
  760 + PHY_INTERFACE_MODE_MII);
758 761 else {
759 762 printk("No phy bus ID specified in BSP code\n");
760 763 return -EINVAL;
... ... @@ -962,57 +965,6 @@
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 968 #ifdef CONFIG_FS_ENET_HAS_FEC
1017 969 #define IS_FEC(match) ((match)->data == &fs_fec_ops)
1018 970 #else
... ... @@ -1062,9 +1014,9 @@
1062 1014 fpi->rx_copybreak = 240;
1063 1015 fpi->use_napi = 1;
1064 1016 fpi->napi_weight = 17;
1065   -
1066   - ret = find_phy(ofdev->node, fpi);
1067   - if (ret)
  1017 + fpi->phy_node = of_parse_phandle(ofdev->node, "phy-handle", 0);
  1018 + if ((!fpi->phy_node) && (!of_get_property(ofdev->node, "fixed-link",
  1019 + NULL)))
1068 1020 goto out_free_fpi;
1069 1021  
1070 1022 privsize = sizeof(*fep) +
... ... @@ -1136,6 +1088,7 @@
1136 1088 out_free_dev:
1137 1089 free_netdev(ndev);
1138 1090 dev_set_drvdata(&ofdev->dev, NULL);
  1091 + of_node_put(fpi->phy_node);
1139 1092 out_free_fpi:
1140 1093 kfree(fpi);
1141 1094 return ret;
... ... @@ -1151,7 +1104,7 @@
1151 1104 fep->ops->free_bd(ndev);
1152 1105 fep->ops->cleanup_data(ndev);
1153 1106 dev_set_drvdata(fep->dev, NULL);
1154   -
  1107 + of_node_put(fep->fpi->phy_node);
1155 1108 free_netdev(ndev);
1156 1109 return 0;
1157 1110 }
drivers/net/fs_enet/mii-bitbang.c
... ... @@ -22,6 +22,7 @@
22 22 #include <linux/mii.h>
23 23 #include <linux/platform_device.h>
24 24 #include <linux/mdio-bitbang.h>
  25 +#include <linux/of_mdio.h>
25 26 #include <linux/of_platform.h>
26 27  
27 28 #include "fs_enet.h"
28 29  
29 30  
... ... @@ -149,31 +150,12 @@
149 150 return 0;
150 151 }
151 152  
152   -static 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   -
169 153 static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
170 154 const struct of_device_id *match)
171 155 {
172   - struct device_node *np = NULL;
173 156 struct mii_bus *new_bus;
174 157 struct bb_info *bitbang;
175 158 int ret = -ENOMEM;
176   - int i;
177 159  
178 160 bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
179 161 if (!bitbang)
180 162  
... ... @@ -196,17 +178,10 @@
196 178 if (!new_bus->irq)
197 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 181 new_bus->parent = &ofdev->dev;
207 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 185 if (ret)
211 186 goto out_free_irqs;
212 187  
drivers/net/fs_enet/mii-fec.c
... ... @@ -100,23 +100,6 @@
100 100 return 0;
101 101 }
102 102  
103   -static 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   -
120 103 static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
121 104 const struct of_device_id *match)
122 105 {
123 106  
... ... @@ -163,17 +146,10 @@
163 146 if (!new_bus->irq)
164 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 149 new_bus->parent = &ofdev->dev;
174 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 153 if (ret)
178 154 goto out_free_irqs;
179 155  
include/linux/fs_enet_pd.h
... ... @@ -17,6 +17,7 @@
17 17 #define FS_ENET_PD_H
18 18  
19 19 #include <linux/string.h>
  20 +#include <linux/of_mdio.h>
20 21 #include <asm/types.h>
21 22  
22 23 #define FS_ENET_NAME "fs_enet"
... ... @@ -130,10 +131,7 @@
130 131  
131 132 u32 device_flags;
132 133  
133   - int phy_addr; /* the phy address (-1 no phy) */
134   - char bus_id[16];
135   - int phy_irq; /* the phy irq (if it exists) */
136   -
  134 + struct device_node *phy_node;
137 135 const struct fs_mii_bus_info *bus_info;
138 136  
139 137 int rx_ring, tx_ring; /* number of buffers on rx */