56a5ff92db5f09b04b3ff733b333bc8185010622
[sfrench/cifs-2.6.git] / drivers / staging / rtl8187se / r8180_pm.c
1 /*
2    Power management interface routines.
3    Written by Mariusz Matuszek.
4    This code is currently just a placeholder for later work and
5    does not do anything useful.
6
7    This is part of rtl8180 OpenSource driver.
8    Copyright (C) Andrea Merello 2004  <andreamrl@tiscali.it>
9    Released under the terms of GPL (General Public Licence)
10 */
11
12
13
14 #include "r8180_hw.h"
15 #include "r8180_pm.h"
16 #include "r8180.h"
17
18 int rtl8180_suspend(struct pci_dev *pdev, pm_message_t state)
19 {
20         struct net_device *dev = pci_get_drvdata(pdev);
21
22         if (!netif_running(dev))
23                 goto out_pci_suspend;
24
25         if (dev->netdev_ops->ndo_stop)
26                 dev->netdev_ops->ndo_stop(dev);
27
28         netif_device_detach(dev);
29
30 out_pci_suspend:
31         pci_save_state(pdev);
32         pci_disable_device(pdev);
33         pci_set_power_state(pdev, pci_choose_state(pdev, state));
34         return 0;
35 }
36
37 int rtl8180_resume(struct pci_dev *pdev)
38 {
39         struct net_device *dev = pci_get_drvdata(pdev);
40         int err;
41         u32 val;
42
43         pci_set_power_state(pdev, PCI_D0);
44
45         err = pci_enable_device(pdev);
46         if (err) {
47                 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
48                                 dev->name);
49
50                 return err;
51         }
52
53         pci_restore_state(pdev);
54
55         /*
56          * Suspend/Resume resets the PCI configuration space, so we have to
57          * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
58          * from interfering with C3 CPU state. pci_restore_state won't help
59          * here since it only restores the first 64 bytes pci config header.
60          */
61         pci_read_config_dword(pdev, 0x40, &val);
62         if ((val & 0x0000ff00) != 0)
63                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
64
65         if (!netif_running(dev))
66                 goto out;
67
68         if (dev->netdev_ops->ndo_open)
69                 dev->netdev_ops->ndo_open(dev);
70
71         netif_device_attach(dev);
72 out:
73         return 0;
74 }