fsl_pq_mdio: Fix compiler/sparse warnings (part 1)
[safe/jmp/linux-2.6] / drivers / net / fsl_pq_mdio.c
index b01daa1..fb8c8d9 100644 (file)
@@ -3,8 +3,9 @@
  * Provides Bus interface for MIIM regs
  *
  * Author: Andy Fleming <afleming@freescale.com>
+ * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
  *
- * Copyright (c) 2002-2004,2008 Freescale Semiconductor, Inc.
+ * Copyright 2002-2004, 2008-2009 Freescale Semiconductor, Inc.
  *
  * Based on gianfar_mii.c and ucc_geth_mii.c (Li Yang, Kim Phillips)
  *
@@ -188,25 +189,35 @@ static int fsl_pq_mdio_find_free(struct mii_bus *new_bus)
 }
 
 
-#ifdef CONFIG_GIANFAR
-static u32 __iomem *get_gfar_tbipa(struct fsl_pq_mdio __iomem *regs)
+#if defined(CONFIG_GIANFAR) || defined(CONFIG_GIANFAR_MODULE)
+static u32 __iomem *get_gfar_tbipa(struct fsl_pq_mdio __iomem *regs, struct device_node *np)
 {
        struct gfar __iomem *enet_regs;
+       u32 __iomem *ioremap_tbipa;
+       u64 addr, size;
 
        /*
         * This is mildly evil, but so is our hardware for doing this.
         * Also, we have to cast back to struct gfar because of
         * definition weirdness done in gianfar.h.
         */
-       enet_regs = (struct gfar __iomem *)
-               ((char __iomem *)regs - offsetof(struct gfar, gfar_mii_regs));
-
-       return &enet_regs->tbipa;
+       if(of_device_is_compatible(np, "fsl,gianfar-mdio") ||
+               of_device_is_compatible(np, "fsl,gianfar-tbi") ||
+               of_device_is_compatible(np, "gianfar")) {
+               enet_regs = (struct gfar __iomem *)regs;
+               return &enet_regs->tbipa;
+       } else if (of_device_is_compatible(np, "fsl,etsec2-mdio") ||
+                       of_device_is_compatible(np, "fsl,etsec2-tbi")) {
+               addr = of_translate_address(np, of_get_address(np, 1, &size, NULL));
+               ioremap_tbipa = ioremap(addr, size);
+               return ioremap_tbipa;
+       } else
+               return NULL;
 }
 #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;
@@ -250,11 +261,12 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev,
 {
        struct device_node *np = ofdev->node;
        struct device_node *tbi;
-       struct fsl_pq_mdio __iomem *regs;
+       struct fsl_pq_mdio __iomem *regs = NULL;
+       void __iomem *map;
        u32 __iomem *tbipa;
        struct mii_bus *new_bus;
        int tbiaddr = -1;
-       u64 addr, size;
+       u64 addr = 0, size = 0;
        int err = 0;
 
        new_bus = mdiobus_alloc();
@@ -269,13 +281,19 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev,
 
        /* Set the PHY base address */
        addr = of_translate_address(np, of_get_address(np, 0, &size, NULL));
-       regs = ioremap(addr, size);
-
-       if (NULL == regs) {
+       map = ioremap(addr, size);
+       if (!map) {
                err = -ENOMEM;
                goto err_free_bus;
        }
 
+       if (of_device_is_compatible(np, "fsl,gianfar-mdio") ||
+                       of_device_is_compatible(np, "fsl,gianfar-tbi") ||
+                       of_device_is_compatible(np, "fsl,ucc-mdio") ||
+                       of_device_is_compatible(np, "ucc_geth_phy"))
+               map -= offsetof(struct fsl_pq_mdio, miimcfg);
+       regs = map;
+
        new_bus->priv = (void __force *)regs;
 
        new_bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
@@ -290,24 +308,34 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev,
 
        if (of_device_is_compatible(np, "fsl,gianfar-mdio") ||
                        of_device_is_compatible(np, "fsl,gianfar-tbi") ||
+                       of_device_is_compatible(np, "fsl,etsec2-mdio") ||
+                       of_device_is_compatible(np, "fsl,etsec2-tbi") ||
                        of_device_is_compatible(np, "gianfar")) {
-#ifdef CONFIG_GIANFAR
-               tbipa = get_gfar_tbipa(regs);
+#if defined(CONFIG_GIANFAR) || defined(CONFIG_GIANFAR_MODULE)
+               tbipa = get_gfar_tbipa(regs, np);
+               if (!tbipa) {
+                       err = -EINVAL;
+                       goto err_free_irqs;
+               }
 #else
                err = -ENODEV;
                goto err_free_irqs;
 #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;
@@ -401,8 +429,15 @@ static struct of_device_id fsl_pq_mdio_match[] = {
        {
                .compatible = "fsl,gianfar-mdio",
        },
+       {
+               .compatible = "fsl,etsec2-tbi",
+       },
+       {
+               .compatible = "fsl,etsec2-mdio",
+       },
        {},
 };
+MODULE_DEVICE_TABLE(of, fsl_pq_mdio_match);
 
 static struct of_platform_driver fsl_pq_mdio_driver = {
        .name = "fsl-pq_mdio",
@@ -415,10 +450,10 @@ 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);