Merge branches 'tracing/ftrace', 'tracing/textedit' and 'linus' into tracing/core
[safe/jmp/linux-2.6] / drivers / net / ucc_geth_mii.c
index 27a1ef3..0ada4ed 100644 (file)
@@ -1,12 +1,13 @@
 /*
  * drivers/net/ucc_geth_mii.c
  *
- * Gianfar Ethernet Driver -- MIIM bus implementation
- * Provides Bus interface for MIIM regs
+ * QE UCC Gigabit Ethernet Driver -- MII Management Bus Implementation
+ * Provides Bus interface for MII Management regs in the UCC register space
  *
- * Author: Li Yang
+ * Copyright (C) 2007 Freescale Semiconductor, Inc.
  *
- * Copyright (c) 2002-2004 Freescale Semiconductor, Inc.
+ * Authors: Li Yang <leoli@freescale.com>
+ *         Kim Phillips <kim.phillips@freescale.com>
  *
  * This program is free software; you can redistribute  it and/or modify it
  * under  the terms of  the GNU General  Public License as published by the
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
-#include <asm/ocp.h>
 #include <linux/crc32.h>
 #include <linux/mii.h>
 #include <linux/phy.h>
 #include <linux/fsl_devices.h>
+#include <linux/of_platform.h>
 
-#include <asm/of_platform.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
@@ -53,8 +53,8 @@
 #define vdbg(format, arg...) do {} while(0)
 #endif
 
-#define DRV_DESC "QE UCC Ethernet Controller MII Bus"
-#define DRV_NAME "fsl-uec_mdio"
+#define MII_DRV_DESC "QE UCC Ethernet Controller MII Bus"
+#define MII_DRV_NAME "fsl-uec_mdio"
 
 /* Write value to the PHY for this device to the register at regnum, */
 /* waiting until the write is done before it returns.  All PHY */
@@ -104,12 +104,12 @@ int uec_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 }
 
 /* Reset the MIIM registers, and wait for the bus to free */
-int uec_mdio_reset(struct mii_bus *bus)
+static int uec_mdio_reset(struct mii_bus *bus)
 {
        struct ucc_mii_mng __iomem *regs = (void __iomem *)bus->priv;
-       unsigned int timeout = PHY_INIT_TIMEOUT;
+       int timeout = PHY_INIT_TIMEOUT;
 
-       spin_lock_bh(&bus->mdio_lock);
+       mutex_lock(&bus->mdio_lock);
 
        /* Reset the management interface */
        out_be32(&regs->miimcfg, MIIMCFG_RESET_MANAGEMENT);
@@ -121,9 +121,9 @@ int uec_mdio_reset(struct mii_bus *bus)
        while ((in_be32(&regs->miimind) & MIIMIND_BUSY) && timeout--)
                cpu_relax();
 
-       spin_unlock_bh(&bus->mdio_lock);
+       mutex_unlock(&bus->mdio_lock);
 
-       if (timeout <= 0) {
+       if (timeout < 0) {
                printk(KERN_ERR "%s: The MII Bus is stuck!\n", bus->name);
                return -EBUSY;
        }
@@ -141,8 +141,7 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
        struct resource res;
        int k, err = 0;
 
-       new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
-
+       new_bus = mdiobus_alloc();
        if (NULL == new_bus)
                return -ENOMEM;
 
@@ -157,7 +156,7 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
        if (err)
                goto reg_map_fail;
 
-       new_bus->id = res.start;
+       uec_mdio_bus_name(new_bus->id, np);
 
        new_bus->irq = kmalloc(32 * sizeof(int), GFP_KERNEL);
 
@@ -187,7 +186,7 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
 
        new_bus->priv = (void __force *)regs;
 
-       new_bus->dev = device;
+       new_bus->parent = device;
        dev_set_drvdata(device, new_bus);
 
        /* Read MII management master from device tree */
@@ -203,9 +202,14 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
                if ((res.start >= tempres.start) &&
                    (res.end <= tempres.end)) {
                        /* set this UCC to be the MII master */
-                       const u32 *id = of_get_property(tempnp, "device-id", NULL);
-                       if (id == NULL)
-                               goto bus_register_fail;
+                       const u32 *id;
+
+                       id = of_get_property(tempnp, "cell-index", NULL);
+                       if (!id) {
+                               id = of_get_property(tempnp, "device-id", NULL);
+                               if (!id)
+                                       goto bus_register_fail;
+                       }
 
                        ucc_set_qe_mux_mii_mng(*id - 1);
 
@@ -230,12 +234,12 @@ bus_register_fail:
 ioremap_fail:
        kfree(new_bus->irq);
 reg_map_fail:
-       kfree(new_bus);
+       mdiobus_free(new_bus);
 
        return err;
 }
 
-int uec_mdio_remove(struct of_device *ofdev)
+static int uec_mdio_remove(struct of_device *ofdev)
 {
        struct device *device = &ofdev->dev;
        struct mii_bus *bus = dev_get_drvdata(device);
@@ -246,7 +250,7 @@ int uec_mdio_remove(struct of_device *ofdev)
 
        iounmap((void __iomem *)bus->priv);
        bus->priv = NULL;
-       kfree(bus);
+       mdiobus_free(bus);
 
        return 0;
 }
@@ -256,13 +260,14 @@ static struct of_device_id uec_mdio_match[] = {
                .type = "mdio",
                .compatible = "ucc_geth_phy",
        },
+       {
+               .compatible = "fsl,ucc-mdio",
+       },
        {},
 };
 
-MODULE_DEVICE_TABLE(of, uec_mdio_match);
-
 static struct of_platform_driver uec_mdio_driver = {
-       .name   = DRV_NAME,
+       .name   = MII_DRV_NAME,
        .probe  = uec_mdio_probe,
        .remove = uec_mdio_remove,
        .match_table    = uec_mdio_match,
@@ -273,7 +278,18 @@ int __init uec_mdio_init(void)
        return of_register_platform_driver(&uec_mdio_driver);
 }
 
-void __exit uec_mdio_exit(void)
+/* called from __init ucc_geth_init, therefore can not be __exit */
+void uec_mdio_exit(void)
 {
        of_unregister_platform_driver(&uec_mdio_driver);
 }
+
+void uec_mdio_bus_name(char *name, struct device_node *np)
+{
+        const u32 *reg;
+
+        reg = of_get_property(np, "reg", NULL);
+
+        snprintf(name, MII_BUS_ID_SIZE, "%s@%x", np->name, reg ? *reg : 0);
+}
+