1 --- a/drivers/net/ethernet/ramips/ramips_main.c
2 +++ b/drivers/net/ethernet/ramips/ramips_main.c
4 #include <linux/of_device.h>
6 #include <linux/of_net.h>
7 +#include <linux/of_mdio.h>
9 #include "ramips_eth.h"
11 @@ -406,12 +407,25 @@ ramips_mdio_reset(struct mii_bus *bus)
13 ramips_mdio_init(struct raeth_priv *re)
15 + struct device_node *mii_np;
19 + mii_np = of_get_child_by_name(re->of_node, "mdio-bus");
21 + dev_err(re->parent, "no %s child node found", "mdio-bus");
25 + if (!of_device_is_available(mii_np)) {
30 re->mii_bus = mdiobus_alloc();
31 - if (re->mii_bus == NULL)
33 + if (re->mii_bus == NULL) {
38 re->mii_bus->name = "ramips_mdio";
39 re->mii_bus->read = ramips_mdio_read;
40 @@ -422,12 +436,7 @@ ramips_mdio_init(struct raeth_priv *re)
41 re->mii_bus->parent = re->parent;
43 snprintf(re->mii_bus->id, MII_BUS_ID_SIZE, "%s", "ramips_mdio");
44 - re->mii_bus->phy_mask = 0;
46 - for (i = 0; i < PHY_MAX_ADDR; i++)
47 - re->mii_irq[i] = PHY_POLL;
49 - err = mdiobus_register(re->mii_bus);
50 + err = of_mdiobus_register(re->mii_bus, mii_np);
54 @@ -435,13 +444,20 @@ ramips_mdio_init(struct raeth_priv *re)
59 + of_node_put(mii_np);
65 ramips_mdio_cleanup(struct raeth_priv *re)
70 mdiobus_unregister(re->mii_bus);
71 + of_node_put(re->mii_bus->dev.of_node);
75 @@ -474,106 +490,86 @@ ramips_phy_link_adjust(struct net_device
79 -ramips_phy_connect_multi(struct raeth_priv *re)
80 +ramips_phy_connect_by_node(struct raeth_priv *re, struct device_node *phy_node)
82 - struct net_device *netdev = re->netdev;
83 - struct phy_device *phydev = NULL;
87 - for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
88 - if (!(re->phy_mask & (1 << phy_addr)))
91 - if (re->mii_bus->phy_map[phy_addr] == NULL)
93 + struct phy_device *phydev;
96 - RADEBUG("%s: PHY found at %s, uid=%08x\n",
98 - dev_name(&re->mii_bus->phy_map[phy_addr]->dev),
99 - re->mii_bus->phy_map[phy_addr]->phy_id);
101 - if (phydev == NULL)
102 - phydev = re->mii_bus->phy_map[phy_addr];
106 - netdev_err(netdev, "no PHY found with phy_mask=%08x\n",
109 + phy_mode = of_get_phy_mode(re->of_node);
110 + if (phy_mode < 0) {
111 + dev_err(re->parent, "incorrect phy-mode\n");
115 - re->phy_dev = phy_connect(netdev, dev_name(&phydev->dev),
116 - ramips_phy_link_adjust, 0, re->phy_if_mode);
118 - if (IS_ERR(re->phy_dev)) {
119 - netdev_err(netdev, "could not connect to PHY at %s\n",
120 - dev_name(&phydev->dev));
121 + phydev = of_phy_connect(re->netdev, phy_node, ramips_phy_link_adjust,
123 + if (IS_ERR(phydev)) {
124 + dev_err(re->parent, "could not connect to PHY\n");
125 return PTR_ERR(re->phy_dev);
128 phydev->supported &= PHY_GBIT_FEATURES;
129 phydev->advertising = phydev->supported;
131 - RADEBUG("%s: connected to PHY at %s [uid=%08x, driver=%s]\n",
132 - netdev->name, dev_name(&phydev->dev),
133 - phydev->phy_id, phydev->drv->name);
134 + dev_info(re->parent,
135 + "connected to PHY at %s [uid=%08x, driver=%s]\n",
136 + dev_name(&phydev->dev), phydev->phy_id,
137 + phydev->drv->name);
139 + re->phy_dev = phydev;
151 -ramips_phy_connect_fixed(struct raeth_priv *re)
152 +ramips_phy_connect_fixed(struct raeth_priv *re, const __be32 *link, int size)
155 - const __be32 *link;
158 - link = of_get_property(re->of_node,
159 - "ralink,fixed-link", &size);
160 - if (!link || size != (4 * sizeof(*link)))
163 - re->speed = be32_to_cpup(link++);
164 - re->duplex = be32_to_cpup(link++);
165 - re->tx_fc = be32_to_cpup(link++);
166 - re->rx_fc = be32_to_cpup(link++);
167 + if (size != (4 * sizeof(*link))) {
168 + dev_err(re->parent, "invalid fixed-link property\n");
172 + re->speed = be32_to_cpup(link++);
173 + re->duplex = be32_to_cpup(link++);
174 + re->tx_fc = be32_to_cpup(link++);
175 + re->rx_fc = be32_to_cpup(link++);
183 - netdev_err(re->netdev, "invalid speed specified\n");
184 + dev_err(re->parent, "invalid link speed: %d\n", re->speed);
188 - pr_info("%s: using fixed link parameters\n", re->netdev->name);
189 + dev_info(re->parent, "using fixed link parameters\n");
194 ramips_phy_connect(struct raeth_priv *re)
196 - const __be32 *mask;
198 - mask = of_get_property(re->of_node, "ralink,phy-mask", NULL);
199 - re->phy_if_mode = of_get_phy_mode(re->of_node);
201 - if (!re->phy_if_mode || !mask)
202 - return ramips_phy_connect_fixed(re);
204 - re->phy_mask = be32_to_cpup(mask);
205 - return ramips_phy_connect_multi(re);
206 + struct device_node *phy_node;
210 + phy_node = of_parse_phandle(re->of_node, "phy-handle", 0);
212 + return ramips_phy_connect_by_node(re, phy_node);
214 + p32 = of_get_property(re->of_node, "ralink,fixed-link", &size);
216 + return ramips_phy_connect_fixed(re, p32, size);
218 + dev_err(re->parent, "unable to get connection type\n");