natsemi: fix MMIO for PPC 44x platforms
[safe/jmp/linux-2.6] / drivers / net / gianfar_mii.c
index 1eca1db..b889892 100644 (file)
@@ -1,11 +1,11 @@
-/* 
+/*
  * drivers/net/gianfar_mii.c
  *
  * Gianfar Ethernet Driver -- MIIM bus implementation
  * Provides Bus interface for MIIM regs
  *
  * Author: Andy Fleming
- * Maintainer: Kumar Gala (kumar.gala@freescale.com)
+ * Maintainer: Kumar Gala
  *
  * Copyright (c) 2002-2004 Freescale Semiconductor, Inc.
  *
@@ -16,9 +16,7 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <linux/unistd.h>
@@ -32,8 +30,7 @@
 #include <linux/spinlock.h>
 #include <linux/mm.h>
 #include <linux/module.h>
-#include <linux/version.h>
-#include <asm/ocp.h>
+#include <linux/platform_device.h>
 #include <linux/crc32.h>
 #include <linux/mii.h>
 #include <linux/phy.h>
 #include "gianfar.h"
 #include "gianfar_mii.h"
 
-/* Write value to the PHY at mii_id at register regnum,
- * on the bus, waiting until the write is done before returning.
- * All PHY configuration is done through the TSEC1 MIIM regs */
-int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value)
+/*
+ * Write value to the PHY at mii_id at register regnum,
+ * on the bus attached to the local interface, which may be different from the
+ * generic mdio bus (tied to a single interface), waiting until the write is
+ * done before returning. This is helpful in programming interfaces like
+ * the TBI which control interfaces like onchip SERDES and are always tied to
+ * the local mdio pins, which may not be the same as system mdio bus, used for
+ * controlling the external PHYs, for example.
+ */
+int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id,
+                         int regnum, u16 value)
 {
-       struct gfar_mii *regs = bus->priv;
-
        /* Set the PHY address and the register address we want to write */
        gfar_write(&regs->miimadd, (mii_id << 8) | regnum);
 
@@ -65,12 +67,19 @@ int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value)
        return 0;
 }
 
-/* Read the bus for PHY at addr mii_id, register regnum, and
- * return the value.  Clears miimcom first.  All PHY
- * configuration has to be done through the TSEC1 MIIM regs */
-int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
+/*
+ * Read the bus for PHY at addr mii_id, register regnum, and
+ * return the value.  Clears miimcom first.  All PHY operation
+ * done on the bus attached to the local interface,
+ * which may be different from the generic mdio bus
+ * This is helpful in programming interfaces like
+ * the TBI which, inturn, control interfaces like onchip SERDES
+ * and are always tied to the local mdio pins, which may not be the
+ * same as system mdio bus, used for controlling the external PHYs, for eg.
+ */
+int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum)
+
 {
-       struct gfar_mii *regs = bus->priv;
        u16 value;
 
        /* Set the PHY address and the register address we want to read */
@@ -90,14 +99,35 @@ int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
        return value;
 }
 
+/* Write value to the PHY at mii_id at register regnum,
+ * on the bus, waiting until the write is done before returning.
+ * All PHY configuration is done through the TSEC1 MIIM regs */
+int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value)
+{
+       struct gfar_mii __iomem *regs = (void __iomem *)bus->priv;
+
+       /* Write to the local MII regs */
+       return(gfar_local_mdio_write(regs, mii_id, regnum, value));
+}
+
+/* Read the bus for PHY at addr mii_id, register regnum, and
+ * return the value.  Clears miimcom first.  All PHY
+ * configuration has to be done through the TSEC1 MIIM regs */
+int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
+{
+       struct gfar_mii __iomem *regs = (void __iomem *)bus->priv;
+
+       /* Read the local MII regs */
+       return(gfar_local_mdio_read(regs, mii_id, regnum));
+}
 
 /* Reset the MIIM registers, and wait for the bus to free */
 int gfar_mdio_reset(struct mii_bus *bus)
 {
-       struct gfar_mii *regs = bus->priv;
+       struct gfar_mii __iomem *regs = (void __iomem *)bus->priv;
        unsigned int timeout = PHY_INIT_TIMEOUT;
 
-       spin_lock_bh(&bus->mdio_lock);
+       mutex_lock(&bus->mdio_lock);
 
        /* Reset the management interface */
        gfar_write(&regs->miimcfg, MIIMCFG_RESET);
@@ -110,7 +140,7 @@ int gfar_mdio_reset(struct mii_bus *bus)
                        timeout--)
                cpu_relax();
 
-       spin_unlock_bh(&bus->mdio_lock);
+       mutex_unlock(&bus->mdio_lock);
 
        if(timeout <= 0) {
                printk(KERN_ERR "%s: The MII Bus is stuck!\n",
@@ -126,14 +156,15 @@ int gfar_mdio_probe(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct gianfar_mdio_data *pdata;
-       struct gfar_mii *regs;
+       struct gfar_mii __iomem *regs;
        struct mii_bus *new_bus;
+       struct resource *r;
        int err = 0;
 
        if (NULL == dev)
                return -EINVAL;
 
-       new_bus = kmalloc(sizeof(struct mii_bus), GFP_KERNEL);
+       new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
 
        if (NULL == new_bus)
                return -ENOMEM;
@@ -142,7 +173,7 @@ int gfar_mdio_probe(struct device *dev)
        new_bus->read = &gfar_mdio_read,
        new_bus->write = &gfar_mdio_write,
        new_bus->reset = &gfar_mdio_reset,
-       new_bus->id = pdev->id;
+       snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);
 
        pdata = (struct gianfar_mdio_data *)pdev->dev.platform_data;
 
@@ -151,16 +182,17 @@ int gfar_mdio_probe(struct device *dev)
                return -ENODEV;
        }
 
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
        /* Set the PHY base address */
-       regs = (struct gfar_mii *) ioremap(pdata->paddr, 
-                       sizeof (struct gfar_mii));
+       regs = ioremap(r->start, sizeof (struct gfar_mii));
 
        if (NULL == regs) {
                err = -ENOMEM;
                goto reg_map_fail;
        }
 
-       new_bus->priv = regs;
+       new_bus->priv = (void __force *)regs;
 
        new_bus->irq = pdata->irq;
 
@@ -170,7 +202,7 @@ int gfar_mdio_probe(struct device *dev)
        err = mdiobus_register(new_bus);
 
        if (0 != err) {
-               printk (KERN_ERR "%s: Cannot register as MDIO bus\n", 
+               printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
                                new_bus->name);
                goto bus_register_fail;
        }
@@ -178,7 +210,7 @@ int gfar_mdio_probe(struct device *dev)
        return 0;
 
 bus_register_fail:
-       iounmap((void *) regs);
+       iounmap(regs);
 reg_map_fail:
        kfree(new_bus);
 
@@ -194,7 +226,7 @@ int gfar_mdio_remove(struct device *dev)
 
        dev_set_drvdata(dev, NULL);
 
-       iounmap((void *) (&bus->priv));
+       iounmap((void __iomem *)bus->priv);
        bus->priv = NULL;
        kfree(bus);
 
@@ -213,7 +245,7 @@ int __init gfar_mdio_init(void)
        return driver_register(&gianfar_mdio_driver);
 }
 
-void __exit gfar_mdio_exit(void)
+void gfar_mdio_exit(void)
 {
        driver_unregister(&gianfar_mdio_driver);
 }