]> Pileus Git - ~andy/linux/blob - drivers/staging/rtl8192e/rtl_pm.c
Merge branch 'next/cleanup3' of git://git.linaro.org/people/arnd/arm-soc
[~andy/linux] / drivers / staging / rtl8192e / rtl_pm.c
1 /******************************************************************************
2  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3  *
4  * This program is distributed in the hope that it will be useful, but WITHOUT
5  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
7  * more details.
8  *
9  * You should have received a copy of the GNU General Public License along with
10  * this program; if not, write to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
12  *
13  * The full GNU General Public License is included in this distribution in the
14  * file called LICENSE.
15  *
16  * Contact Information:
17  * wlanfae <wlanfae@realtek.com>
18 ******************************************************************************/
19
20 #ifdef CONFIG_PM_RTL
21 #include "rtl_core.h"
22 #include "r8192E_hw.h"
23 #include "r8190P_rtl8256.h"
24 #include "rtl_pm.h"
25
26 int rtl8192E_save_state(struct pci_dev *dev, pm_message_t state)
27 {
28         printk(KERN_NOTICE "r8192E save state call (state %u).\n", state.event);
29         return -EAGAIN;
30 }
31
32
33 int rtl8192E_suspend(struct pci_dev *pdev, pm_message_t state)
34 {
35         struct net_device *dev = pci_get_drvdata(pdev);
36         struct r8192_priv *priv = rtllib_priv(dev);
37         u32     ulRegRead;
38
39         printk(KERN_INFO "============> r8192E suspend call.\n");
40         del_timer_sync(&priv->gpio_polling_timer);
41         cancel_delayed_work(&priv->gpio_change_rf_wq);
42         priv->polling_timer_on = 0;
43
44         if (!netif_running(dev)) {
45                 printk(KERN_INFO "RTL819XE:UI is open out of suspend "
46                        "function\n");
47                 goto out_pci_suspend;
48         }
49
50         if (dev->netdev_ops->ndo_stop)
51                 dev->netdev_ops->ndo_stop(dev);
52         netif_device_detach(dev);
53
54         if (!priv->rtllib->bSupportRemoteWakeUp) {
55                 MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_INIT, true);
56                 ulRegRead = read_nic_dword(dev, CPU_GEN);
57                 ulRegRead |= CPU_GEN_SYSTEM_RESET;
58                 write_nic_dword(dev, CPU_GEN, ulRegRead);
59         } else {
60                 write_nic_dword(dev, WFCRC0, 0xffffffff);
61                 write_nic_dword(dev, WFCRC1, 0xffffffff);
62                 write_nic_dword(dev, WFCRC2, 0xffffffff);
63                 write_nic_byte(dev, PMR, 0x5);
64                 write_nic_byte(dev, MacBlkCtrl, 0xa);
65         }
66 out_pci_suspend:
67         printk("r8192E support WOL call??????????????????????\n");
68         if (priv->rtllib->bSupportRemoteWakeUp)
69                 RT_TRACE(COMP_POWER, "r8192E support WOL call!!!!!!!"
70                          "!!!!!!!!!!!.\n");
71         pci_save_state(pdev);
72         pci_disable_device(pdev);
73         pci_enable_wake(pdev, pci_choose_state(pdev, state),
74                         priv->rtllib->bSupportRemoteWakeUp ? 1 : 0);
75         pci_set_power_state(pdev, pci_choose_state(pdev, state));
76
77         mdelay(20);
78
79         return 0;
80 }
81
82 int rtl8192E_resume(struct pci_dev *pdev)
83 {
84         struct net_device *dev = pci_get_drvdata(pdev);
85         struct r8192_priv *priv = rtllib_priv(dev);
86         int err;
87         u32 val;
88
89         printk(KERN_INFO "================>r8192E resume call.\n");
90
91         pci_set_power_state(pdev, PCI_D0);
92
93         err = pci_enable_device(pdev);
94         if (err) {
95                 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
96                        dev->name);
97                 return err;
98         }
99         pci_restore_state(pdev);
100
101         pci_read_config_dword(pdev, 0x40, &val);
102         if ((val & 0x0000ff00) != 0)
103                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
104
105         pci_enable_wake(pdev, PCI_D0, 0);
106
107         if (priv->polling_timer_on == 0)
108                 check_rfctrl_gpio_timer((unsigned long)dev);
109
110         if (!netif_running(dev)) {
111                 printk(KERN_INFO "RTL819XE:UI is open out of resume "
112                        "function\n");
113                 goto out;
114         }
115
116         netif_device_attach(dev);
117         if (dev->netdev_ops->ndo_open)
118                 dev->netdev_ops->ndo_open(dev);
119
120         if (!priv->rtllib->bSupportRemoteWakeUp)
121                 MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_INIT, true);
122
123 out:
124         RT_TRACE(COMP_POWER, "<================r8192E resume call.\n");
125         return 0;
126 }
127
128
129 int rtl8192E_enable_wake(struct pci_dev *dev, pm_message_t state, int enable)
130 {
131         printk(KERN_NOTICE "r8192E enable wake call (state %u, enable %d).\n",
132                state.event, enable);
133         return -EAGAIN;
134 }
135
136 #endif