diff options
| author | Grant Likely <grant.likely@secretlab.ca> | 2009-04-25 08:53:17 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2009-04-27 05:53:49 -0400 |
| commit | 1dd2d06c0459a2f1bffc56765e3cc57427818867 (patch) | |
| tree | 5cf5b6aebdc4aa8cb66d21198ee87641f9ec67f6 | |
| parent | fe192a49118f5b1272317d60c7930ece4e13ae49 (diff) | |
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>
| -rw-r--r-- | arch/powerpc/platforms/pasemi/gpio_mdio.c | 32 | ||||
| -rw-r--r-- | drivers/net/pasemi_mac.c | 28 | ||||
| -rw-r--r-- | drivers/net/pasemi_mac.h | 1 |
3 files changed, 9 insertions, 52 deletions
diff --git a/arch/powerpc/platforms/pasemi/gpio_mdio.c b/arch/powerpc/platforms/pasemi/gpio_mdio.c index 75cc165d5be..3bf546797cb 100644 --- a/arch/powerpc/platforms/pasemi/gpio_mdio.c +++ b/arch/powerpc/platforms/pasemi/gpio_mdio.c | |||
| @@ -29,7 +29,7 @@ | |||
| 29 | #include <linux/ioport.h> | 29 | #include <linux/ioport.h> |
| 30 | #include <linux/interrupt.h> | 30 | #include <linux/interrupt.h> |
| 31 | #include <linux/phy.h> | 31 | #include <linux/phy.h> |
| 32 | #include <linux/platform_device.h> | 32 | #include <linux/of_mdio.h> |
| 33 | #include <linux/of_platform.h> | 33 | #include <linux/of_platform.h> |
| 34 | 34 | ||
| 35 | #define DELAY 1 | 35 | #define DELAY 1 |
| @@ -39,6 +39,7 @@ static void __iomem *gpio_regs; | |||
| 39 | struct gpio_priv { | 39 | struct gpio_priv { |
| 40 | int mdc_pin; | 40 | int mdc_pin; |
| 41 | int mdio_pin; | 41 | int mdio_pin; |
| 42 | int mdio_irqs[PHY_MAX_ADDR]; | ||
| 42 | }; | 43 | }; |
| 43 | 44 | ||
| 44 | #define MDC_PIN(bus) (((struct gpio_priv *)bus->priv)->mdc_pin) | 45 | #define MDC_PIN(bus) (((struct gpio_priv *)bus->priv)->mdc_pin) |
| @@ -218,12 +219,11 @@ static int __devinit gpio_mdio_probe(struct of_device *ofdev, | |||
| 218 | const struct of_device_id *match) | 219 | const struct of_device_id *match) |
| 219 | { | 220 | { |
| 220 | struct device *dev = &ofdev->dev; | 221 | struct device *dev = &ofdev->dev; |
| 221 | struct device_node *phy_dn, *np = ofdev->node; | 222 | struct device_node *np = ofdev->node; |
| 222 | struct mii_bus *new_bus; | 223 | struct mii_bus *new_bus; |
| 223 | struct gpio_priv *priv; | 224 | struct gpio_priv *priv; |
| 224 | const unsigned int *prop; | 225 | const unsigned int *prop; |
| 225 | int err; | 226 | int err; |
| 226 | int i; | ||
| 227 | 227 | ||
| 228 | err = -ENOMEM; | 228 | err = -ENOMEM; |
| 229 | priv = kzalloc(sizeof(struct gpio_priv), GFP_KERNEL); | 229 | priv = kzalloc(sizeof(struct gpio_priv), GFP_KERNEL); |
| @@ -244,27 +244,7 @@ static int __devinit gpio_mdio_probe(struct of_device *ofdev, | |||
| 244 | snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", *prop); | 244 | snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", *prop); |
| 245 | new_bus->priv = priv; | 245 | new_bus->priv = priv; |
| 246 | 246 | ||
| 247 | new_bus->phy_mask = 0; | 247 | new_bus->irq = priv->mdio_irqs; |
| 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 | 248 | ||
| 269 | prop = of_get_property(np, "mdc-pin", NULL); | 249 | prop = of_get_property(np, "mdc-pin", NULL); |
| 270 | priv->mdc_pin = *prop; | 250 | priv->mdc_pin = *prop; |
| @@ -275,7 +255,7 @@ static int __devinit gpio_mdio_probe(struct of_device *ofdev, | |||
| 275 | new_bus->parent = dev; | 255 | new_bus->parent = dev; |
| 276 | dev_set_drvdata(dev, new_bus); | 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 | if (err != 0) { | 260 | if (err != 0) { |
| 281 | printk(KERN_ERR "%s: Cannot register as MDIO bus, err %d\n", | 261 | printk(KERN_ERR "%s: Cannot register as MDIO bus, err %d\n", |
| @@ -286,8 +266,6 @@ static int __devinit gpio_mdio_probe(struct of_device *ofdev, | |||
| 286 | return 0; | 266 | return 0; |
| 287 | 267 | ||
| 288 | out_free_irq: | 268 | out_free_irq: |
| 289 | kfree(new_bus->irq); | ||
| 290 | out_free_bus: | ||
| 291 | kfree(new_bus); | 269 | kfree(new_bus); |
| 292 | out_free_priv: | 270 | out_free_priv: |
| 293 | kfree(priv); | 271 | kfree(priv); |
diff --git a/drivers/net/pasemi_mac.c b/drivers/net/pasemi_mac.c index 067caba4365..6ea4539085d 100644 --- a/drivers/net/pasemi_mac.c +++ b/drivers/net/pasemi_mac.c | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include <linux/dmaengine.h> | 24 | #include <linux/dmaengine.h> |
| 25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
| 26 | #include <linux/netdevice.h> | 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/of_mdio.h> | ||
| 27 | #include <linux/etherdevice.h> | 28 | #include <linux/etherdevice.h> |
| 28 | #include <asm/dma-mapping.h> | 29 | #include <asm/dma-mapping.h> |
| 29 | #include <linux/in.h> | 30 | #include <linux/in.h> |
| @@ -1086,34 +1087,17 @@ static int pasemi_mac_phy_init(struct net_device *dev) | |||
| 1086 | struct pasemi_mac *mac = netdev_priv(dev); | 1087 | struct pasemi_mac *mac = netdev_priv(dev); |
| 1087 | struct device_node *dn, *phy_dn; | 1088 | struct device_node *dn, *phy_dn; |
| 1088 | struct phy_device *phydev; | 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 | dn = pci_device_to_OF_node(mac->pdev); | 1091 | dn = pci_device_to_OF_node(mac->pdev); |
| 1096 | ph = of_get_property(dn, "phy-handle", NULL); | 1092 | phy_dn = of_parse_phandle(dn, "phy-handle", 0); |
| 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 | |||
| 1110 | of_node_put(phy_dn); | 1093 | of_node_put(phy_dn); |
| 1111 | 1094 | ||
| 1112 | mac->link = 0; | 1095 | mac->link = 0; |
| 1113 | mac->speed = 0; | 1096 | mac->speed = 0; |
| 1114 | mac->duplex = -1; | 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 | if (IS_ERR(phydev)) { | 1102 | if (IS_ERR(phydev)) { |
| 1119 | printk(KERN_ERR "%s: Could not attach to phy\n", dev->name); | 1103 | printk(KERN_ERR "%s: Could not attach to phy\n", dev->name); |
| @@ -1123,10 +1107,6 @@ static int pasemi_mac_phy_init(struct net_device *dev) | |||
| 1123 | mac->phydev = phydev; | 1107 | mac->phydev = phydev; |
| 1124 | 1108 | ||
| 1125 | return 0; | 1109 | return 0; |
| 1126 | |||
| 1127 | err: | ||
| 1128 | of_node_put(phy_dn); | ||
| 1129 | return -ENODEV; | ||
| 1130 | } | 1110 | } |
| 1131 | 1111 | ||
| 1132 | 1112 | ||
diff --git a/drivers/net/pasemi_mac.h b/drivers/net/pasemi_mac.h index 1a115ec60b5..e2f4efa8ad4 100644 --- a/drivers/net/pasemi_mac.h +++ b/drivers/net/pasemi_mac.h | |||
| @@ -100,7 +100,6 @@ struct pasemi_mac { | |||
| 100 | int duplex; | 100 | int duplex; |
| 101 | 101 | ||
| 102 | unsigned int msg_enable; | 102 | unsigned int msg_enable; |
| 103 | char phy_id[BUS_ID_SIZE]; | ||
| 104 | }; | 103 | }; |
| 105 | 104 | ||
| 106 | /* Software status descriptor (ring_info) */ | 105 | /* Software status descriptor (ring_info) */ |
