Commit 1dd2d06c0459a2f1bffc56765e3cc57427818867

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

net: Rework pasemi_mac 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>
Tested-by: Olof Johansson <olof@lixom.net>
Acked-by: Olof Johansson <olof@lixom.net>
Acked-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 3 changed files with 9 additions and 52 deletions Side-by-side Diff

arch/powerpc/platforms/pasemi/gpio_mdio.c
... ... @@ -29,7 +29,7 @@
29 29 #include <linux/ioport.h>
30 30 #include <linux/interrupt.h>
31 31 #include <linux/phy.h>
32   -#include <linux/platform_device.h>
  32 +#include <linux/of_mdio.h>
33 33 #include <linux/of_platform.h>
34 34  
35 35 #define DELAY 1
... ... @@ -39,6 +39,7 @@
39 39 struct gpio_priv {
40 40 int mdc_pin;
41 41 int mdio_pin;
  42 + int mdio_irqs[PHY_MAX_ADDR];
42 43 };
43 44  
44 45 #define MDC_PIN(bus) (((struct gpio_priv *)bus->priv)->mdc_pin)
45 46  
... ... @@ -218,12 +219,11 @@
218 219 const struct of_device_id *match)
219 220 {
220 221 struct device *dev = &ofdev->dev;
221   - struct device_node *phy_dn, *np = ofdev->node;
  222 + struct device_node *np = ofdev->node;
222 223 struct mii_bus *new_bus;
223 224 struct gpio_priv *priv;
224 225 const unsigned int *prop;
225 226 int err;
226   - int i;
227 227  
228 228 err = -ENOMEM;
229 229 priv = kzalloc(sizeof(struct gpio_priv), GFP_KERNEL);
230 230  
... ... @@ -244,28 +244,8 @@
244 244 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", *prop);
245 245 new_bus->priv = priv;
246 246  
247   - new_bus->phy_mask = 0;
  247 + new_bus->irq = priv->mdio_irqs;
248 248  
249   - new_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
250   -
251   - if (!new_bus->irq)
252   - goto out_free_bus;
253   -
254   - for (i = 0; i < PHY_MAX_ADDR; i++)
255   - new_bus->irq[i] = NO_IRQ;
256   -
257   - for (phy_dn = of_get_next_child(np, NULL);
258   - phy_dn != NULL;
259   - phy_dn = of_get_next_child(np, phy_dn)) {
260   - const unsigned int *ip, *regp;
261   -
262   - ip = of_get_property(phy_dn, "interrupts", NULL);
263   - regp = of_get_property(phy_dn, "reg", NULL);
264   - if (!ip || !regp || *regp >= PHY_MAX_ADDR)
265   - continue;
266   - new_bus->irq[*regp] = irq_create_mapping(NULL, *ip);
267   - }
268   -
269 249 prop = of_get_property(np, "mdc-pin", NULL);
270 250 priv->mdc_pin = *prop;
271 251  
... ... @@ -275,7 +255,7 @@
275 255 new_bus->parent = dev;
276 256 dev_set_drvdata(dev, new_bus);
277 257  
278   - err = mdiobus_register(new_bus);
  258 + err = of_mdiobus_register(new_bus, np);
279 259  
280 260 if (err != 0) {
281 261 printk(KERN_ERR "%s: Cannot register as MDIO bus, err %d\n",
... ... @@ -286,8 +266,6 @@
286 266 return 0;
287 267  
288 268 out_free_irq:
289   - kfree(new_bus->irq);
290   -out_free_bus:
291 269 kfree(new_bus);
292 270 out_free_priv:
293 271 kfree(priv);
drivers/net/pasemi_mac.c
... ... @@ -24,6 +24,7 @@
24 24 #include <linux/dmaengine.h>
25 25 #include <linux/delay.h>
26 26 #include <linux/netdevice.h>
  27 +#include <linux/of_mdio.h>
27 28 #include <linux/etherdevice.h>
28 29 #include <asm/dma-mapping.h>
29 30 #include <linux/in.h>
30 31  
31 32  
... ... @@ -1086,34 +1087,17 @@
1086 1087 struct pasemi_mac *mac = netdev_priv(dev);
1087 1088 struct device_node *dn, *phy_dn;
1088 1089 struct phy_device *phydev;
1089   - unsigned int phy_id;
1090   - const phandle *ph;
1091   - const unsigned int *prop;
1092   - struct resource r;
1093   - int ret;
1094 1090  
1095 1091 dn = pci_device_to_OF_node(mac->pdev);
1096   - ph = of_get_property(dn, "phy-handle", NULL);
1097   - if (!ph)
1098   - return -ENODEV;
1099   - phy_dn = of_find_node_by_phandle(*ph);
1100   -
1101   - prop = of_get_property(phy_dn, "reg", NULL);
1102   - ret = of_address_to_resource(phy_dn->parent, 0, &r);
1103   - if (ret)
1104   - goto err;
1105   -
1106   - phy_id = *prop;
1107   - snprintf(mac->phy_id, sizeof(mac->phy_id), "%x:%02x",
1108   - (int)r.start, phy_id);
1109   -
  1092 + phy_dn = of_parse_phandle(dn, "phy-handle", 0);
1110 1093 of_node_put(phy_dn);
1111 1094  
1112 1095 mac->link = 0;
1113 1096 mac->speed = 0;
1114 1097 mac->duplex = -1;
1115 1098  
1116   - phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII);
  1099 + phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0,
  1100 + PHY_INTERFACE_MODE_SGMII);
1117 1101  
1118 1102 if (IS_ERR(phydev)) {
1119 1103 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
... ... @@ -1123,10 +1107,6 @@
1123 1107 mac->phydev = phydev;
1124 1108  
1125 1109 return 0;
1126   -
1127   -err:
1128   - of_node_put(phy_dn);
1129   - return -ENODEV;
1130 1110 }
1131 1111  
1132 1112  
drivers/net/pasemi_mac.h
... ... @@ -100,7 +100,6 @@
100 100 int duplex;
101 101  
102 102 unsigned int msg_enable;
103   - char phy_id[BUS_ID_SIZE];
104 103 };
105 104  
106 105 /* Software status descriptor (ring_info) */