linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / net / depca.c
index 28109cb..03804cc 100644 (file)
 #include <linux/unistd.h>
 #include <linux/ctype.h>
 #include <linux/moduleparam.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/bitops.h>
 
 #include <asm/uaccess.h>
@@ -342,14 +342,15 @@ static char depca_string[] = "depca";
 static int depca_device_remove (struct device *device);
 
 #ifdef CONFIG_EISA
-struct eisa_device_id depca_eisa_ids[] = {
+static struct eisa_device_id depca_eisa_ids[] = {
        { "DEC4220", de422 },
        { "" }
 };
+MODULE_DEVICE_TABLE(eisa, depca_eisa_ids);
 
 static int depca_eisa_probe  (struct device *device);
 
-struct eisa_driver depca_eisa_driver = {
+static struct eisa_driver depca_eisa_driver = {
        .id_table = depca_eisa_ids,
        .driver   = {
                .name    = depca_string,
@@ -397,13 +398,19 @@ static struct mca_driver depca_mca_driver = {
 };
 #endif
 
-static int depca_isa_probe (struct device *);
+static int depca_isa_probe (struct platform_device *);
 
-static struct device_driver depca_isa_driver = {
-       .name   = depca_string,
-       .bus    = &platform_bus_type,
+static int __devexit depca_isa_remove(struct platform_device *pdev)
+{
+       return depca_device_remove(&pdev->dev);
+}
+
+static struct platform_driver depca_isa_driver = {
        .probe  = depca_isa_probe,
-       .remove = __devexit_p(depca_device_remove),
+       .remove = __devexit_p(depca_isa_remove),
+       .driver = {
+               .name   = depca_string,
+       },
 };
        
 /*
@@ -463,11 +470,11 @@ struct depca_private {
         } depca_bus;           /* type of bus */
        struct depca_init init_block;   /* Shadow Initialization block            */
 /* CPU address space fields */
-       struct depca_rx_desc *rx_ring;  /* Pointer to start of RX descriptor ring */
-       struct depca_tx_desc *tx_ring;  /* Pointer to start of TX descriptor ring */
-       void *rx_buff[NUM_RX_DESC];     /* CPU virt address of sh'd memory buffs  */
-       void *tx_buff[NUM_TX_DESC];     /* CPU virt address of sh'd memory buffs  */
-       void *sh_mem;           /* CPU mapped virt address of device RAM  */
+       struct depca_rx_desc __iomem *rx_ring;  /* Pointer to start of RX descriptor ring */
+       struct depca_tx_desc __iomem *tx_ring;  /* Pointer to start of TX descriptor ring */
+       void __iomem *rx_buff[NUM_RX_DESC];     /* CPU virt address of sh'd memory buffs  */
+       void __iomem *tx_buff[NUM_TX_DESC];     /* CPU virt address of sh'd memory buffs  */
+       void __iomem *sh_mem;   /* CPU mapped virt address of device RAM  */
        u_long mem_start;       /* Bus address of device RAM (before remap) */
        u_long mem_len;         /* device memory size */
 /* Device address space fields */
@@ -693,11 +700,11 @@ static int __init depca_hw_init (struct net_device *dev, struct device *device)
 
        /* Tx & Rx descriptors (aligned to a quadword boundary) */
        offset = (offset + DEPCA_ALIGN) & ~DEPCA_ALIGN;
-       lp->rx_ring = (struct depca_rx_desc *) (lp->sh_mem + offset);
+       lp->rx_ring = (struct depca_rx_desc __iomem *) (lp->sh_mem + offset);
        lp->rx_ring_offset = offset;
 
        offset += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
-       lp->tx_ring = (struct depca_tx_desc *) (lp->sh_mem + offset);
+       lp->tx_ring = (struct depca_tx_desc __iomem *) (lp->sh_mem + offset);
        lp->tx_ring_offset = offset;
 
        offset += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
@@ -1469,15 +1476,6 @@ static int __init depca_mca_probe(struct device *device)
 ** ISA bus I/O device probe
 */
 
-static void depca_platform_release (struct device *device)
-{
-       struct platform_device *pldev;
-
-       /* free device */
-       pldev = to_platform_device (device);
-       kfree (pldev);
-}
-
 static void __init depca_platform_probe (void)
 {
        int i;
@@ -1490,19 +1488,16 @@ static void __init depca_platform_probe (void)
                 * line, use it (if valid) */
                if (io && io != depca_io_ports[i].iobase)
                        continue;
-               
-               if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL)))
+
+               pldev = platform_device_alloc(depca_string, i);
+               if (!pldev)
                        continue;
 
-               memset (pldev, 0, sizeof (*pldev));
-               pldev->name = depca_string;
-               pldev->id   = i;
                pldev->dev.platform_data = (void *) depca_io_ports[i].iobase;
-               pldev->dev.release       = depca_platform_release;
                depca_io_ports[i].device = pldev;
 
-               if (platform_device_register (pldev)) {
-                       kfree (pldev);
+               if (platform_device_add(pldev)) {
+                       platform_device_put(pldev);
                        depca_io_ports[i].device = NULL;
                        continue;
                }
@@ -1514,6 +1509,7 @@ static void __init depca_platform_probe (void)
                 * allocated structure */
                        
                        depca_io_ports[i].device = NULL;
+                       pldev->dev.platform_data = NULL;
                        platform_device_unregister (pldev);
                }
        }
@@ -1535,7 +1531,7 @@ static enum depca_type __init depca_shmem_probe (ulong *mem_start)
        return adapter;
 }
 
-static int __init depca_isa_probe (struct device *device)
+static int __init depca_isa_probe (struct platform_device *device)
 {
        struct net_device *dev;
        struct depca_private *lp;
@@ -1543,7 +1539,7 @@ static int __init depca_isa_probe (struct device *device)
        enum depca_type adapter = unknown;
        int status = 0;
 
-       ioaddr = (u_long) device->platform_data;
+       ioaddr = (u_long) device->dev.platform_data;
 
        if ((status = depca_common_init (ioaddr, &dev)))
                goto out;
@@ -1563,7 +1559,7 @@ static int __init depca_isa_probe (struct device *device)
        lp->adapter = adapter;
        lp->mem_start = mem_start;
        
-       if ((status = depca_hw_init(dev, device)))
+       if ((status = depca_hw_init(dev, &device->dev)))
                goto out_free;
        
        return 0;
@@ -1649,7 +1645,7 @@ static int __devexit depca_device_remove (struct device *device)
 static int __init DepcaSignature(char *name, u_long base_addr)
 {
        u_int i, j, k;
-       void *ptr;
+       void __iomem *ptr;
        char tmpstr[16];
        u_long prom_addr = base_addr + 0xc000;
        u_long mem_addr = base_addr + 0x8000; /* 32KB */
@@ -1826,7 +1822,7 @@ static int load_packet(struct net_device *dev, struct sk_buff *skb)
 
                /* set up the buffer descriptors */
                len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
-               for (i = entry; i != end; i = (++i) & lp->txRingMask) {
+               for (i = entry; i != end; i = (i+1) & lp->txRingMask) {
                        /* clean out flags */
                        writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
                        writew(0x0000, &lp->tx_ring[i].misc);   /* clears other error flags */
@@ -1876,17 +1872,17 @@ static void depca_dbg_open(struct net_device *dev)
                printk("Descriptor addresses (CPU):\nRX: ");
                for (i = 0; i < lp->rxRingMask; i++) {
                        if (i < 3) {
-                               printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
+                               printk("%p ", &lp->rx_ring[i].base);
                        }
                }
-               printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
+               printk("...%p\n", &lp->rx_ring[i].base);
                printk("TX: ");
                for (i = 0; i < lp->txRingMask; i++) {
                        if (i < 3) {
-                               printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
+                               printk("%p ", &lp->tx_ring[i].base);
                        }
                }
-               printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
+               printk("...%p\n", &lp->tx_ring[i].base);
                printk("\nDescriptor buffers (Device):\nRX: ");
                for (i = 0; i < lp->rxRingMask; i++) {
                        if (i < 3) {
@@ -2092,7 +2088,7 @@ static int __init depca_module_init (void)
 #ifdef CONFIG_EISA
         err |= eisa_driver_register (&depca_eisa_driver);
 #endif
-       err |= driver_register (&depca_isa_driver);
+       err |= platform_driver_register (&depca_isa_driver);
        depca_platform_probe ();
        
         return err;
@@ -2107,10 +2103,11 @@ static void __exit depca_module_exit (void)
 #ifdef CONFIG_EISA
         eisa_driver_unregister (&depca_eisa_driver);
 #endif
-       driver_unregister (&depca_isa_driver);
+       platform_driver_unregister (&depca_isa_driver);
 
        for (i = 0; depca_io_ports[i].iobase; i++) {
                if (depca_io_ports[i].device) {
+                       depca_io_ports[i].device->dev.platform_data = NULL;
                        platform_device_unregister (depca_io_ports[i].device);
                        depca_io_ports[i].device = NULL;
                }