linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / net / 3c509.c
index cbdae54..830528d 100644 (file)
@@ -68,6 +68,7 @@
 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
 static int max_interrupt_work = 10;
 
+#include <linux/config.h>
 #include <linux/module.h>
 #ifdef CONFIG_MCA
 #include <linux/mca.h>
@@ -99,10 +100,6 @@ static int max_interrupt_work = 10;
 static char versionA[] __initdata = DRV_NAME ".c:" DRV_VERSION " " DRV_RELDATE " becker@scyld.com\n";
 static char versionB[] __initdata = "http://www.scyld.com/network/3c509.html\n";
 
-#if defined(CONFIG_PM) && (defined(CONFIG_MCA) || defined(CONFIG_EISA))
-#define EL3_SUSPEND
-#endif
-
 #ifdef EL3_DEBUG
 static int el3_debug = EL3_DEBUG;
 #else
@@ -177,6 +174,9 @@ struct el3_private {
        /* skb send-queue */
        int head, size;
        struct sk_buff *queue[SKB_QUEUE_SIZE];
+#ifdef CONFIG_PM_LEGACY
+       struct pm_dev *pmdev;
+#endif
        enum {
                EL3_MCA,
                EL3_PNP,
@@ -201,15 +201,11 @@ static void el3_tx_timeout (struct net_device *dev);
 static void el3_down(struct net_device *dev);
 static void el3_up(struct net_device *dev);
 static struct ethtool_ops ethtool_ops;
-#ifdef EL3_SUSPEND
-static int el3_suspend(struct device *, pm_message_t);
-static int el3_resume(struct device *);
-#else
-#define el3_suspend NULL
-#define el3_resume NULL
+#ifdef CONFIG_PM_LEGACY
+static int el3_suspend(struct pm_dev *pdev);
+static int el3_resume(struct pm_dev *pdev);
+static int el3_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data);
 #endif
-
-
 /* generic device remove for all device types */
 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
 static int el3_device_remove (struct device *device);
@@ -233,9 +229,7 @@ static struct eisa_driver el3_eisa_driver = {
                .driver   = {
                                .name    = "3c509",
                                .probe   = el3_eisa_probe,
-                               .remove  = __devexit_p (el3_device_remove),
-                               .suspend = el3_suspend,
-                               .resume  = el3_resume,
+                               .remove  = __devexit_p (el3_device_remove)
                }
 };
 #endif
@@ -268,8 +262,6 @@ static struct mca_driver el3_mca_driver = {
                                .bus = &mca_bus_type,
                                .probe = el3_mca_probe,
                                .remove = __devexit_p(el3_device_remove),
-                               .suspend = el3_suspend,
-                               .resume  = el3_resume,
                },
 };
 #endif /* CONFIG_MCA */
@@ -370,6 +362,10 @@ static void el3_common_remove (struct net_device *dev)
        struct el3_private *lp = netdev_priv(dev);
 
        (void) lp;                              /* Keep gcc quiet... */
+#ifdef CONFIG_PM_LEGACY
+       if (lp->pmdev)
+               pm_unregister(lp->pmdev);
+#endif
 #if defined(__ISAPNP__)
        if (lp->type == EL3_PNP)
                pnp_device_detach(to_pnp_dev(lp->dev));
@@ -576,6 +572,16 @@ no_pnp:
        if (err)
                goto out1;
 
+#ifdef CONFIG_PM_LEGACY
+       /* register power management */
+       lp->pmdev = pm_register(PM_ISA_DEV, card_idx, el3_pm_callback);
+       if (lp->pmdev) {
+               struct pm_dev *p;
+               p = lp->pmdev;
+               p->data = (struct net_device *)dev;
+       }
+#endif
+
        el3_cards++;
        lp->next_dev = el3_root_dev;
        el3_root_dev = dev;
@@ -1474,17 +1480,20 @@ el3_up(struct net_device *dev)
 }
 
 /* Power Management support functions */
-#ifdef EL3_SUSPEND
+#ifdef CONFIG_PM_LEGACY
 
 static int
-el3_suspend(struct device *pdev, pm_message_t state)
+el3_suspend(struct pm_dev *pdev)
 {
        unsigned long flags;
        struct net_device *dev;
        struct el3_private *lp;
        int ioaddr;
        
-       dev = pdev->driver_data;
+       if (!pdev && !pdev->data)
+               return -EINVAL;
+
+       dev = (struct net_device *)pdev->data;
        lp = netdev_priv(dev);
        ioaddr = dev->base_addr;
 
@@ -1501,14 +1510,17 @@ el3_suspend(struct device *pdev, pm_message_t state)
 }
 
 static int
-el3_resume(struct device *pdev)
+el3_resume(struct pm_dev *pdev)
 {
        unsigned long flags;
        struct net_device *dev;
        struct el3_private *lp;
        int ioaddr;
        
-       dev = pdev->driver_data;
+       if (!pdev && !pdev->data)
+               return -EINVAL;
+
+       dev = (struct net_device *)pdev->data;
        lp = netdev_priv(dev);
        ioaddr = dev->base_addr;
 
@@ -1524,7 +1536,20 @@ el3_resume(struct device *pdev)
        return 0;
 }
 
-#endif /* EL3_SUSPEND */
+static int
+el3_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)
+{
+       switch (rqst) {
+               case PM_SUSPEND:
+                       return el3_suspend(pdev);
+
+               case PM_RESUME:
+                       return el3_resume(pdev);
+       }
+       return 0;
+}
+
+#endif /* CONFIG_PM_LEGACY */
 
 /* Parameters that may be passed into the module. */
 static int debug = -1;