mm-only debug patch...
[mmotm.git] / drivers / staging / rtl8192e / r8192_pm.c
blobfeef29b0a8939335966a62f166b5acd6c89aad3f
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 #ifdef CONFIG_PM_RTL
14 #include "r8192E.h"
15 #include "r8192E_hw.h"
16 #include "r8192_pm.h"
17 #include "r8190_rtl8256.h"
19 int rtl8192E_save_state (struct pci_dev *dev, pm_message_t state)
21 printk(KERN_NOTICE "r8192E save state call (state %u).\n", state.event);
22 return(-EAGAIN);
26 int rtl8192E_suspend (struct pci_dev *pdev, pm_message_t state)
28 struct net_device *dev = pci_get_drvdata(pdev);
29 struct r8192_priv *priv = ieee80211_priv(dev);
30 u8 ucRegRead;
31 u32 ulRegRead;
33 RT_TRACE(COMP_POWER, "============> r8192E suspend call.\n");
34 if (!netif_running(dev))
35 goto out_pci_suspend;
37 if (dev->netdev_ops->ndo_stop)
38 dev->netdev_ops->ndo_stop(dev);
39 // dev->stop(dev);
40 #if 0
42 netif_carrier_off(dev);
44 ieee80211_softmac_stop_protocol(priv->ieee80211);
46 write_nic_byte(dev,MSR,(read_nic_byte(dev,MSR)&0xfc)|MSR_LINK_NONE);
47 if(!priv->ieee80211->bSupportRemoteWakeUp) {
48 /* disable tx/rx. In 8185 we write 0x10 (Reset bit),
49 * but here we make reference to WMAC and wirte 0x0.
50 * 2006.11.21 Emily
52 write_nic_byte(dev, CMDR, 0);
54 //disable interrupt
55 write_nic_dword(dev,INTA_MASK,0);
56 priv->irq_enabled = 0;
57 write_nic_dword(dev,ISR,read_nic_dword(dev, ISR));
59 /* need to free DM related functions */
60 cancel_work_sync(&priv->reset_wq);
61 del_timer_sync(&priv->fsync_timer);
62 del_timer_sync(&priv->watch_dog_timer);
63 cancel_delayed_work(&priv->watch_dog_wq);
64 cancel_delayed_work(&priv->update_beacon_wq);
65 cancel_work_sync(&priv->qos_activate);
67 /* TODO
68 #if ((DEV_BUS_TYPE == PCI_INTERFACE) && (HAL_CODE_BASE == RTL8192))
69 pHalData->bHwRfOffAction = 2;
70 #endif
72 #endif
73 // Call MgntActSet_RF_State instead to prevent RF config race condition.
74 // By Bruce, 2008-01-17.
76 if(!priv->ieee80211->bSupportRemoteWakeUp) {
77 MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_INIT);
78 // 2006.11.30. System reset bit
79 ulRegRead = read_nic_dword(dev, CPU_GEN);
80 ulRegRead|=CPU_GEN_SYSTEM_RESET;
81 write_nic_dword(dev, CPU_GEN, ulRegRead);
82 } else {
83 //2008.06.03 for WOL
84 write_nic_dword(dev, WFCRC0, 0xffffffff);
85 write_nic_dword(dev, WFCRC1, 0xffffffff);
86 write_nic_dword(dev, WFCRC2, 0xffffffff);
87 #ifdef RTL8190P
88 //GPIO 0 = TRUE
89 ucRegRead = read_nic_byte(dev, GPO);
90 ucRegRead |= BIT0;
91 write_nic_byte(dev, GPO, ucRegRead);
92 #endif
93 //Write PMR register
94 write_nic_byte(dev, PMR, 0x5);
95 //Disable tx, enanble rx
96 write_nic_byte(dev, MacBlkCtrl, 0xa);
99 out_pci_suspend:
100 RT_TRACE(COMP_POWER, "r8192E support WOL call??????????????????????\n");
101 if(priv->ieee80211->bSupportRemoteWakeUp) {
102 RT_TRACE(COMP_POWER, "r8192E support WOL call!!!!!!!!!!!!!!!!!!.\n");
104 netif_device_detach(dev);
105 pci_save_state(pdev);
106 pci_disable_device(pdev);
107 pci_enable_wake(pdev, pci_choose_state(pdev,state),\
108 priv->ieee80211->bSupportRemoteWakeUp?1:0);
109 pci_set_power_state(pdev,pci_choose_state(pdev,state));
111 return 0;
114 int rtl8192E_resume (struct pci_dev *pdev)
116 struct net_device *dev = pci_get_drvdata(pdev);
117 //struct r8192_priv *priv = ieee80211_priv(dev);
118 //union iwreq_data wrqu;
119 int err;
120 u32 val;
122 RT_TRACE(COMP_POWER, "================>r8192E resume call.");
124 pci_set_power_state(pdev, PCI_D0);
126 err = pci_enable_device(pdev);
127 if(err) {
128 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
129 dev->name);
130 return err;
133 pci_restore_state(pdev);
136 * Suspend/Resume resets the PCI configuration space, so we have to
137 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
138 * from interfering with C3 CPU state. pci_restore_state won't help
139 * here since it only restores the first 64 bytes pci config header.
141 pci_read_config_dword(pdev, 0x40, &val);
142 if ((val & 0x0000ff00) != 0) {
143 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
148 pci_enable_wake(pdev, PCI_D0, 0);
150 if(!netif_running(dev))
151 goto out;
153 netif_device_attach(dev);
155 if (dev->netdev_ops->ndo_open)
156 dev->netdev_ops->ndo_open(dev);
158 // dev->open(dev);
159 out:
160 RT_TRACE(COMP_POWER, "<================r8192E resume call.\n");
161 return 0;
165 int rtl8192E_enable_wake (struct pci_dev *dev, pm_message_t state, int enable)
167 printk(KERN_NOTICE "r8192E enable wake call (state %u, enable %d).\n",
168 state.event, enable);
169 return(-EAGAIN);
172 #endif //CONFIG_PM_RTL