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