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 #include "rtl_core.h"
21 #include "r8192E_hw.h"
22 #include "r8190P_rtl8256.h"
23 #include "rtl_pm.h"
24 
25 
rtl8192E_suspend(struct pci_dev * pdev,pm_message_t state)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 = rtllib_priv(dev);
30 	u32	ulRegRead;
31 
32 	netdev_info(dev, "============> r8192E suspend call.\n");
33 	del_timer_sync(&priv->gpio_polling_timer);
34 	cancel_delayed_work(&priv->gpio_change_rf_wq);
35 	priv->polling_timer_on = 0;
36 
37 	if (!netif_running(dev)) {
38 		netdev_info(dev,
39 			    "RTL819XE:UI is open out of suspend function\n");
40 		goto out_pci_suspend;
41 	}
42 
43 	if (dev->netdev_ops->ndo_stop)
44 		dev->netdev_ops->ndo_stop(dev);
45 	netif_device_detach(dev);
46 
47 	if (!priv->rtllib->bSupportRemoteWakeUp) {
48 		MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_INIT, true);
49 		ulRegRead = read_nic_dword(dev, CPU_GEN);
50 		ulRegRead |= CPU_GEN_SYSTEM_RESET;
51 		write_nic_dword(dev, CPU_GEN, ulRegRead);
52 	} else {
53 		write_nic_dword(dev, WFCRC0, 0xffffffff);
54 		write_nic_dword(dev, WFCRC1, 0xffffffff);
55 		write_nic_dword(dev, WFCRC2, 0xffffffff);
56 		write_nic_byte(dev, PMR, 0x5);
57 		write_nic_byte(dev, MacBlkCtrl, 0xa);
58 	}
59 out_pci_suspend:
60 	netdev_info(dev, "r8192E support WOL call??????????????????????\n");
61 	if (priv->rtllib->bSupportRemoteWakeUp)
62 		RT_TRACE(COMP_POWER,
63 			 "r8192E support WOL call!!!!!!!!!!!!!!!!!!.\n");
64 	pci_save_state(pdev);
65 	pci_disable_device(pdev);
66 	pci_enable_wake(pdev, pci_choose_state(pdev, state),
67 			priv->rtllib->bSupportRemoteWakeUp ? 1 : 0);
68 	pci_set_power_state(pdev, pci_choose_state(pdev, state));
69 
70 	mdelay(20);
71 
72 	return 0;
73 }
74 
rtl8192E_resume(struct pci_dev * pdev)75 int rtl8192E_resume(struct pci_dev *pdev)
76 {
77 	struct net_device *dev = pci_get_drvdata(pdev);
78 	struct r8192_priv *priv = rtllib_priv(dev);
79 	int err;
80 	u32 val;
81 
82 	netdev_info(dev, "================>r8192E resume call.\n");
83 
84 	pci_set_power_state(pdev, PCI_D0);
85 
86 	err = pci_enable_device(pdev);
87 	if (err) {
88 		netdev_err(dev, "pci_enable_device failed on resume\n");
89 		return err;
90 	}
91 	pci_restore_state(pdev);
92 
93 	pci_read_config_dword(pdev, 0x40, &val);
94 	if ((val & 0x0000ff00) != 0)
95 		pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
96 
97 	pci_enable_wake(pdev, PCI_D0, 0);
98 
99 	if (priv->polling_timer_on == 0)
100 		check_rfctrl_gpio_timer((unsigned long)dev);
101 
102 	if (!netif_running(dev)) {
103 		netdev_info(dev,
104 			    "RTL819XE:UI is open out of resume function\n");
105 		goto out;
106 	}
107 
108 	netif_device_attach(dev);
109 	if (dev->netdev_ops->ndo_open)
110 		dev->netdev_ops->ndo_open(dev);
111 
112 	if (!priv->rtllib->bSupportRemoteWakeUp)
113 		MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_INIT, true);
114 
115 out:
116 	RT_TRACE(COMP_POWER, "<================r8192E resume call.\n");
117 	return 0;
118 }
119 
120