Merge tag 'media/v4.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / rtl8192e / 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 #include "rtl_core.h"
21 #include "r8192E_hw.h"
22 #include "r8190P_rtl8256.h"
23 #include "rtl_pm.h"
24
25
26 int rtl92e_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                 rtl92e_set_rf_state(dev, eRfOff, RF_CHANGE_BY_INIT);
49                 ulRegRead = rtl92e_readl(dev, CPU_GEN);
50                 ulRegRead |= CPU_GEN_SYSTEM_RESET;
51                 rtl92e_writel(dev, CPU_GEN, ulRegRead);
52         } else {
53                 rtl92e_writel(dev, WFCRC0, 0xffffffff);
54                 rtl92e_writel(dev, WFCRC1, 0xffffffff);
55                 rtl92e_writel(dev, WFCRC2, 0xffffffff);
56                 rtl92e_writeb(dev, PMR, 0x5);
57                 rtl92e_writeb(dev, MacBlkCtrl, 0xa);
58         }
59 out_pci_suspend:
60         netdev_info(dev, "WOL is %s\n", priv->rtllib->bSupportRemoteWakeUp ?
61                             "Supported" : "Not supported");
62         pci_save_state(pdev);
63         pci_disable_device(pdev);
64         pci_enable_wake(pdev, pci_choose_state(pdev, state),
65                         priv->rtllib->bSupportRemoteWakeUp ? 1 : 0);
66         pci_set_power_state(pdev, pci_choose_state(pdev, state));
67
68         mdelay(20);
69
70         return 0;
71 }
72
73 int rtl92e_resume(struct pci_dev *pdev)
74 {
75         struct net_device *dev = pci_get_drvdata(pdev);
76         struct r8192_priv *priv = rtllib_priv(dev);
77         int err;
78         u32 val;
79
80         netdev_info(dev, "================>r8192E resume call.\n");
81
82         pci_set_power_state(pdev, PCI_D0);
83
84         err = pci_enable_device(pdev);
85         if (err) {
86                 netdev_err(dev, "pci_enable_device failed on resume\n");
87                 return err;
88         }
89         pci_restore_state(pdev);
90
91         pci_read_config_dword(pdev, 0x40, &val);
92         if ((val & 0x0000ff00) != 0)
93                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
94
95         pci_enable_wake(pdev, PCI_D0, 0);
96
97         if (priv->polling_timer_on == 0)
98                 rtl92e_check_rfctrl_gpio_timer((unsigned long)dev);
99
100         if (!netif_running(dev)) {
101                 netdev_info(dev,
102                             "RTL819XE:UI is open out of resume function\n");
103                 goto out;
104         }
105
106         netif_device_attach(dev);
107         if (dev->netdev_ops->ndo_open)
108                 dev->netdev_ops->ndo_open(dev);
109
110         if (!priv->rtllib->bSupportRemoteWakeUp)
111                 rtl92e_set_rf_state(dev, eRfOn, RF_CHANGE_BY_INIT);
112
113 out:
114         RT_TRACE(COMP_POWER, "<================r8192E resume call.\n");
115         return 0;
116 }
117