Merge git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squashfs-linus
[pandora-kernel.git] / drivers / staging / rtl8192e / r8192_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 #include "r8192E.h"
13 #include "r8192E_hw.h"
14 #include "r8192_pm.h"
15 #include "r8190_rtl8256.h"
16
17 int rtl8192E_save_state (struct pci_dev *dev, pm_message_t state)
18 {
19         printk(KERN_NOTICE "r8192E save state call (state %u).\n", state.event);
20         return -EAGAIN;
21 }
22
23
24 int rtl8192E_suspend (struct pci_dev *pdev, pm_message_t state)
25 {
26         struct net_device *dev = pci_get_drvdata(pdev);
27         struct r8192_priv *priv = ieee80211_priv(dev);
28         u32     ulRegRead;
29
30         RT_TRACE(COMP_POWER, "============> r8192E suspend call.\n");
31         if (!netif_running(dev))
32                 goto out_pci_suspend;
33
34         if (dev->netdev_ops->ndo_stop)
35                 dev->netdev_ops->ndo_stop(dev);
36
37         // Call MgntActSet_RF_State instead to prevent RF config race condition.
38         if(!priv->ieee80211->bSupportRemoteWakeUp) {
39                 MgntActSet_RF_State(priv, eRfOff, RF_CHANGE_BY_INIT);
40                 // 2006.11.30. System reset bit
41                 ulRegRead = read_nic_dword(priv, CPU_GEN);
42                 ulRegRead|=CPU_GEN_SYSTEM_RESET;
43                 write_nic_dword(priv, CPU_GEN, ulRegRead);
44         } else {
45                 //2008.06.03 for WOL
46                 write_nic_dword(priv, WFCRC0, 0xffffffff);
47                 write_nic_dword(priv, WFCRC1, 0xffffffff);
48                 write_nic_dword(priv, WFCRC2, 0xffffffff);
49                 //Write PMR register
50                 write_nic_byte(priv, PMR, 0x5);
51                 //Disable tx, enanble rx
52                 write_nic_byte(priv, MacBlkCtrl, 0xa);
53         }
54
55 out_pci_suspend:
56         RT_TRACE(COMP_POWER, "r8192E support WOL call??????????????????????\n");
57         if(priv->ieee80211->bSupportRemoteWakeUp) {
58                 RT_TRACE(COMP_POWER, "r8192E support WOL call!!!!!!!!!!!!!!!!!!.\n");
59         }
60         netif_device_detach(dev);
61         pci_save_state(pdev);
62         pci_disable_device(pdev);
63         pci_enable_wake(pdev, pci_choose_state(pdev,state),
64                         priv->ieee80211->bSupportRemoteWakeUp?1:0);
65         pci_set_power_state(pdev,pci_choose_state(pdev,state));
66
67         return 0;
68 }
69
70 int rtl8192E_resume (struct pci_dev *pdev)
71 {
72         struct net_device *dev = pci_get_drvdata(pdev);
73         int err;
74         u32 val;
75
76         RT_TRACE(COMP_POWER, "================>r8192E resume call.\n");
77
78         pci_set_power_state(pdev, PCI_D0);
79
80         err = pci_enable_device(pdev);
81         if(err) {
82                 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
83                                 dev->name);
84                 return err;
85         }
86
87         pci_restore_state(pdev);
88
89         /*
90          * Suspend/Resume resets the PCI configuration space, so we have to
91          * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
92          * from interfering with C3 CPU state. pci_restore_state won't help
93          * here since it only restores the first 64 bytes pci config header.
94          */
95         pci_read_config_dword(pdev, 0x40, &val);
96         if ((val & 0x0000ff00) != 0) {
97                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
98         }
99
100
101
102         pci_enable_wake(pdev, PCI_D0, 0);
103
104         if(!netif_running(dev))
105                 goto out;
106
107         netif_device_attach(dev);
108
109         if (dev->netdev_ops->ndo_open)
110                 dev->netdev_ops->ndo_open(dev);
111
112 out:
113         RT_TRACE(COMP_POWER, "<================r8192E resume call.\n");
114         return 0;
115 }
116
117
118 int rtl8192E_enable_wake (struct pci_dev *dev, pm_message_t state, int enable)
119 {
120         printk(KERN_NOTICE "r8192E enable wake call (state %u, enable %d).\n",
121                state.event, enable);
122         return -EAGAIN;
123 }