]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/macsonic.c
atl1: save mac address on remove
[linux-2.6-omap-h63xx.git] / drivers / net / macsonic.c
index 405e18365edef4c353b681937ebf63eb3971def7..8ca57a0a4c11acb47ece31b99bac91e8887d4066 100644 (file)
  *
  * Based on code
  * (C) 1996 by Thomas Bogendoerfer (tsbogend@bigbug.franken.de)
- * 
+ *
  * This driver is based on work from Andreas Busse, but most of
  * the code is rewritten.
- * 
+ *
  * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
  *
  * A driver for the Mac onboard Sonic ethernet chip.
  *
- * 98/12/21 MSch: judged from tests on Q800, it's basically working, 
+ * 98/12/21 MSch: judged from tests on Q800, it's basically working,
  *               but eating up both receive and transmit resources
  *               and duplicating packets. Needs more testing.
  *
  * 99/01/03 MSch: upgraded to version 0.92 of the core driver, fixed.
- * 
+ *
  * 00/10/31 sammy@oh.verio.com: Updated driver for 2.4 kernels, fixed problems
  *          on centris.
  */
@@ -47,8 +47,9 @@
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
+#include <linux/bitrev.h>
 
 #include <asm/bootinfo.h>
 #include <asm/system.h>
@@ -76,7 +77,7 @@ static struct platform_device *mac_sonic_device;
 /* use 0 for production, 1 for verification, >1 for debug */
 #ifdef SONIC_DEBUG
 static unsigned int sonic_debug = SONIC_DEBUG;
-#else 
+#else
 static unsigned int sonic_debug = 1;
 #endif
 
@@ -121,16 +122,12 @@ enum macsonic_type {
  * For reversing the PROM address
  */
 
-static unsigned char nibbletab[] = {0, 8, 4, 12, 2, 10, 6, 14,
-                                   1, 9, 5, 13, 3, 11, 7, 15};
-
 static inline void bit_reverse_addr(unsigned char addr[6])
 {
        int i;
 
        for(i = 0; i < 6; i++)
-               addr[i] = ((nibbletab[addr[i] & 0xf] << 4) | 
-                          nibbletab[(addr[i] >> 4) &0xf]);
+               addr[i] = bitrev8(addr[i]);
 }
 
 int __init macsonic_init(struct net_device* dev)
@@ -215,7 +212,7 @@ int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
                unsigned short val;
 
                printk(KERN_INFO "macsonic: PROM seems to be wrong, trying CAM entry 15\n");
-               
+
                SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
                SONIC_WRITE(SONIC_CEP, 15);
 
@@ -228,7 +225,7 @@ int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
                val = SONIC_READ(SONIC_CAP0);
                dev->dev_addr[1] = val >> 8;
                dev->dev_addr[0] = val & 0xff;
-               
+
                printk(KERN_INFO "HW Address from CAM 15: ");
                for (i = 0; i < 6; i++) {
                        printk("%2.2x", dev->dev_addr[i]);
@@ -258,7 +255,7 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
        struct sonic_local* lp = netdev_priv(dev);
        int sr;
        int commslot = 0;
-       
+
        if (once_is_more_than_enough)
                return -ENODEV;
        once_is_more_than_enough = 1;
@@ -268,9 +265,9 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
 
        if (macintosh_config->ether_type != MAC_ETHER_SONIC)
                return -ENODEV;
-       
+
        printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. ");
-       
+
        /* Bogus probing, on the models which may or may not have
           Ethernet (BTW, the Ethernet *is* always at the same
           address, and nothing else lives there, at least if Apple's
@@ -293,7 +290,7 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
                commslot = 1;
        }
 
-       printk("yes\n");        
+       printk("yes\n");
 
        /* Danger!  My arms are flailing wildly!  You *must* set lp->reg_offset
         * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
@@ -325,7 +322,7 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
                lp->dma_bitmode = SONIC_BITMODE16;
 
                sr = SONIC_READ(SONIC_SR);
-               if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101) 
+               if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101)
                        /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */
                        lp->dma_bitmode = SONIC_BITMODE32;
                else {
@@ -389,7 +386,7 @@ int __init mac_nubus_sonic_ethernet_addr(struct net_device* dev,
 
 int __init macsonic_ident(struct nubus_dev* ndev)
 {
-       if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC && 
+       if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
            ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
                return MACSONIC_DAYNALINK;
        if (ndev->dr_hw == NUBUS_DRHW_SONIC &&
@@ -400,11 +397,11 @@ int __init macsonic_ident(struct nubus_dev* ndev)
                else
                        return MACSONIC_APPLE;
        }
-       
+
        if (ndev->dr_hw == NUBUS_DRHW_SMC9194 &&
            ndev->dr_sw == NUBUS_DRSW_DAYNA)
                return MACSONIC_DAYNA;
-       
+
        if (ndev->dr_hw == NUBUS_DRHW_SONIC_LC &&
            ndev->dr_sw == 0) { /* huh? */
                return MACSONIC_APPLE16;
@@ -421,7 +418,7 @@ int __init mac_nubus_sonic_probe(struct net_device* dev)
        u16 sonic_dcr;
        int id = -1;
        int reg_offset, dma_bitmode;
-       
+
        /* Find the first SONIC that hasn't been initialized already */
        while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
                                       NUBUS_TYPE_ETHERNET, ndev)) != NULL)
@@ -459,7 +456,7 @@ int __init mac_nubus_sonic_probe(struct net_device* dev)
                base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
                prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
                sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
-                           SONIC_DCR_PO1 | SONIC_DCR_BMS; 
+                           SONIC_DCR_PO1 | SONIC_DCR_BMS;
                reg_offset = 0;
                dma_bitmode = SONIC_BITMODE16;
                break;
@@ -467,7 +464,7 @@ int __init mac_nubus_sonic_probe(struct net_device* dev)
                base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
                prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE;
                sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
-                           SONIC_DCR_PO1 | SONIC_DCR_BMS; 
+                           SONIC_DCR_PO1 | SONIC_DCR_BMS;
                reg_offset = 0;
                dma_bitmode = SONIC_BITMODE16;
                break;
@@ -525,7 +522,7 @@ int __init mac_nubus_sonic_probe(struct net_device* dev)
        return macsonic_init(dev);
 }
 
-static int __init mac_sonic_probe(struct device *device)
+static int __init mac_sonic_probe(struct platform_device *device)
 {
        struct net_device *dev;
        struct sonic_local *lp;
@@ -537,8 +534,8 @@ static int __init mac_sonic_probe(struct device *device)
                return -ENOMEM;
 
        lp = netdev_priv(dev);
-       lp->device = device;
-       SET_NETDEV_DEV(dev, device);
+       lp->device = &device->dev;
+       SET_NETDEV_DEV(dev, &device->dev);
        SET_MODULE_OWNER(dev);
 
        /* This will catch fatal stuff like -ENOMEM as well as success */
@@ -579,9 +576,9 @@ MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)");
 
 #include "sonic.c"
 
-static int __devexit mac_sonic_device_remove (struct device *device)
+static int __devexit mac_sonic_device_remove (struct platform_device *device)
 {
-       struct net_device *dev = device->driver_data;
+       struct net_device *dev = platform_get_drvdata(device);
        struct sonic_local* lp = netdev_priv(dev);
 
        unregister_netdev (dev);
@@ -592,60 +589,44 @@ static int __devexit mac_sonic_device_remove (struct device *device)
        return 0;
 }
 
-static struct device_driver mac_sonic_driver = {
-       .name   = mac_sonic_string,
-       .bus    = &platform_bus_type,
+static struct platform_driver mac_sonic_driver = {
        .probe  = mac_sonic_probe,
        .remove = __devexit_p(mac_sonic_device_remove),
+       .driver = {
+               .name = mac_sonic_string,
+       },
 };
 
-static void mac_sonic_platform_release(struct device *device)
-{
-       struct platform_device *pldev;
-
-       /* free device */
-       pldev = to_platform_device (device);
-       kfree (pldev);
-}
-
 static int __init mac_sonic_init_module(void)
 {
-       struct platform_device *pldev;
        int err;
 
-       if ((err = driver_register(&mac_sonic_driver))) {
+       if ((err = platform_driver_register(&mac_sonic_driver))) {
                printk(KERN_ERR "Driver registration failed\n");
                return err;
        }
 
-       mac_sonic_device = NULL;
-
-       if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL))) {
+       mac_sonic_device = platform_device_alloc(mac_sonic_string, 0);
+       if (!mac_sonic_device) {
                goto out_unregister;
        }
 
-       memset(pldev, 0, sizeof (*pldev));
-       pldev->name             = mac_sonic_string;
-       pldev->id               = 0;
-       pldev->dev.release      = mac_sonic_platform_release;
-       mac_sonic_device        = pldev;
-
-       if (platform_device_register (pldev)) {
-               kfree(pldev);
+       if (platform_device_add(mac_sonic_device)) {
+               platform_device_put(mac_sonic_device);
                mac_sonic_device = NULL;
        }
 
        return 0;
 
 out_unregister:
-       platform_device_unregister(pldev);
+       platform_driver_unregister(&mac_sonic_driver);
 
        return -ENOMEM;
 }
 
 static void __exit mac_sonic_cleanup_module(void)
 {
-       driver_unregister(&mac_sonic_driver);
+       platform_driver_unregister(&mac_sonic_driver);
 
        if (mac_sonic_device) {
                platform_device_unregister(mac_sonic_device);