Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/upstream-linus
[linux-btrfs-devel.git] / drivers / staging / rtl8192e / r8192_pm.c
blob7bcc4a35099170e0fc50cd4f5d0ca050cdfd94ef
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.
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)
12 #include "r8192E.h"
13 #include "r8192E_hw.h"
14 #include "r8192_pm.h"
15 #include "r8190_rtl8256.h"
17 int rtl8192E_save_state (struct pci_dev *dev, pm_message_t state)
19 printk(KERN_NOTICE "r8192E save state call (state %u).\n", state.event);
20 return -EAGAIN;
24 int rtl8192E_suspend (struct pci_dev *pdev, pm_message_t state)
26 struct net_device *dev = pci_get_drvdata(pdev);
27 struct r8192_priv *priv = ieee80211_priv(dev);
28 u32 ulRegRead;
30 RT_TRACE(COMP_POWER, "============> r8192E suspend call.\n");
31 if (!netif_running(dev))
32 goto out_pci_suspend;
34 if (dev->netdev_ops->ndo_stop)
35 dev->netdev_ops->ndo_stop(dev);
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);
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");
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));
67 return 0;
70 int rtl8192E_resume (struct pci_dev *pdev)
72 struct net_device *dev = pci_get_drvdata(pdev);
73 int err;
74 u32 val;
76 RT_TRACE(COMP_POWER, "================>r8192E resume call.\n");
78 pci_set_power_state(pdev, PCI_D0);
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;
87 pci_restore_state(pdev);
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.
95 pci_read_config_dword(pdev, 0x40, &val);
96 if ((val & 0x0000ff00) != 0) {
97 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
102 pci_enable_wake(pdev, PCI_D0, 0);
104 if(!netif_running(dev))
105 goto out;
107 netif_device_attach(dev);
109 if (dev->netdev_ops->ndo_open)
110 dev->netdev_ops->ndo_open(dev);
112 out:
113 RT_TRACE(COMP_POWER, "<================r8192E resume call.\n");
114 return 0;
118 int rtl8192E_enable_wake (struct pci_dev *dev, pm_message_t state, int enable)
120 printk(KERN_NOTICE "r8192E enable wake call (state %u, enable %d).\n",
121 state.event, enable);
122 return -EAGAIN;