drivers/video/msm: update to new kernel
[safe/jmp/linux-2.6] / drivers / net / fsl_pq_mdio.c
index b0ce144..efbf676 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/mii.h>
 #include <linux/phy.h>
 #include <linux/of.h>
+#include <linux/of_mdio.h>
 #include <linux/of_platform.h>
 
 #include <asm/io.h>
@@ -154,52 +155,19 @@ static int fsl_pq_mdio_reset(struct mii_bus *bus)
        return 0;
 }
 
-/* Allocate an array which provides irq #s for each PHY on the given bus */
-static int *create_irq_map(struct device_node *np)
-{
-       int *irqs;
-       int i;
-       struct device_node *child = NULL;
-
-       irqs = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
-
-       if (!irqs)
-               return NULL;
-
-       for (i = 0; i < PHY_MAX_ADDR; i++)
-               irqs[i] = PHY_POLL;
-
-       while ((child = of_get_next_child(np, child)) != NULL) {
-               int irq = irq_of_parse_and_map(child, 0);
-               const u32 *id;
-
-               if (irq == NO_IRQ)
-                       continue;
-
-               id = of_get_property(child, "reg", NULL);
-
-               if (!id)
-                       continue;
-
-               if (*id < PHY_MAX_ADDR && *id >= 0)
-                       irqs[*id] = irq;
-               else
-                       printk(KERN_WARNING "%s: "
-                                       "%d is not a valid PHY address\n",
-                                       np->full_name, *id);
-       }
-
-       return irqs;
-}
-
 void fsl_pq_mdio_bus_name(char *name, struct device_node *np)
 {
-       const u32 *reg;
+       const u32 *addr;
+       u64 taddr = OF_BAD_ADDR;
 
-       reg = of_get_property(np, "reg", NULL);
+       addr = of_get_address(np, 0, NULL, NULL);
+       if (addr)
+               taddr = of_translate_address(np, addr);
 
-       snprintf(name, MII_BUS_ID_SIZE, "%s@%x", np->name, reg ? *reg : 0);
+       snprintf(name, MII_BUS_ID_SIZE, "%s@%llx", np->name,
+               (unsigned long long)taddr);
 }
+EXPORT_SYMBOL_GPL(fsl_pq_mdio_bus_name);
 
 /* Scan the bus in reverse, looking for an empty spot */
 static int fsl_pq_mdio_find_free(struct mii_bus *new_bus)
@@ -220,7 +188,7 @@ static int fsl_pq_mdio_find_free(struct mii_bus *new_bus)
 }
 
 
-#ifdef CONFIG_GIANFAR
+#if defined(CONFIG_GIANFAR) || defined(CONFIG_GIANFAR_MODULE)
 static u32 __iomem *get_gfar_tbipa(struct fsl_pq_mdio __iomem *regs)
 {
        struct gfar __iomem *enet_regs;
@@ -238,7 +206,7 @@ static u32 __iomem *get_gfar_tbipa(struct fsl_pq_mdio __iomem *regs)
 #endif
 
 
-#ifdef CONFIG_UCC_GETH
+#if defined(CONFIG_UCC_GETH) || defined(CONFIG_UCC_GETH_MODULE)
 static int get_ucc_id_for_range(u64 start, u64 end, u32 *ucc_id)
 {
        struct device_node *np = NULL;
@@ -310,7 +278,7 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev,
 
        new_bus->priv = (void __force *)regs;
 
-       new_bus->irq = create_irq_map(np);
+       new_bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
 
        if (NULL == new_bus->irq) {
                err = -ENOMEM;
@@ -321,8 +289,9 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev,
        dev_set_drvdata(&ofdev->dev, new_bus);
 
        if (of_device_is_compatible(np, "fsl,gianfar-mdio") ||
+                       of_device_is_compatible(np, "fsl,gianfar-tbi") ||
                        of_device_is_compatible(np, "gianfar")) {
-#ifdef CONFIG_GIANFAR
+#if defined(CONFIG_GIANFAR) || defined(CONFIG_GIANFAR_MODULE)
                tbipa = get_gfar_tbipa(regs);
 #else
                err = -ENODEV;
@@ -330,15 +299,19 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev,
 #endif
        } else if (of_device_is_compatible(np, "fsl,ucc-mdio") ||
                        of_device_is_compatible(np, "ucc_geth_phy")) {
-#ifdef CONFIG_UCC_GETH
+#if defined(CONFIG_UCC_GETH) || defined(CONFIG_UCC_GETH_MODULE)
                u32 id;
+               static u32 mii_mng_master;
 
                tbipa = &regs->utbipar;
 
                if ((err = get_ucc_id_for_range(addr, addr + size, &id)))
                        goto err_free_irqs;
 
-               ucc_set_qe_mux_mii_mng(id - 1);
+               if (!mii_mng_master) {
+                       mii_mng_master = id;
+                       ucc_set_qe_mux_mii_mng(id - 1);
+               }
 #else
                err = -ENODEV;
                goto err_free_irqs;
@@ -378,15 +351,7 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev,
 
        out_be32(tbipa, tbiaddr);
 
-       /*
-        * The TBIPHY-only buses will find PHYs at every address,
-        * so we mask them all but the TBI
-        */
-       if (!of_device_is_compatible(np, "fsl,gianfar-mdio"))
-               new_bus->phy_mask = ~(1 << tbiaddr);
-
-       err = mdiobus_register(new_bus);
-
+       err = of_mdiobus_register(new_bus, np);
        if (err) {
                printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
                                new_bus->name);
@@ -442,6 +407,7 @@ static struct of_device_id fsl_pq_mdio_match[] = {
        },
        {},
 };
+MODULE_DEVICE_TABLE(of, fsl_pq_mdio_match);
 
 static struct of_platform_driver fsl_pq_mdio_driver = {
        .name = "fsl-pq_mdio",
@@ -454,10 +420,11 @@ int __init fsl_pq_mdio_init(void)
 {
        return of_register_platform_driver(&fsl_pq_mdio_driver);
 }
+module_init(fsl_pq_mdio_init);
 
 void fsl_pq_mdio_exit(void)
 {
        of_unregister_platform_driver(&fsl_pq_mdio_driver);
 }
-subsys_initcall_sync(fsl_pq_mdio_init);
 module_exit(fsl_pq_mdio_exit);
+MODULE_LICENSE("GPL");