1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4 *
5 * Contact Information: wlanfae <wlanfae@realtek.com>
6 */
7 #include "rtl_core.h"
8 #include "r8192E_hw.h"
9 #include "r8190P_rtl8256.h"
10 #include "rtl_pm.h"
11
rtl92e_suspend(struct device * dev_d)12 int rtl92e_suspend(struct device *dev_d)
13 {
14 struct net_device *dev = dev_get_drvdata(dev_d);
15 struct r8192_priv *priv = rtllib_priv(dev);
16 u32 ulRegRead;
17
18 netdev_info(dev, "============> r8192E suspend call.\n");
19 del_timer_sync(&priv->gpio_polling_timer);
20 cancel_delayed_work_sync(&priv->gpio_change_rf_wq);
21 priv->polling_timer_on = 0;
22
23 if (!netif_running(dev)) {
24 netdev_info(dev,
25 "RTL819XE:UI is open out of suspend function\n");
26 goto out_pci_suspend;
27 }
28
29 if (dev->netdev_ops->ndo_stop)
30 dev->netdev_ops->ndo_stop(dev);
31 netif_device_detach(dev);
32
33 if (!priv->rtllib->bSupportRemoteWakeUp) {
34 rtl92e_set_rf_state(dev, rf_off, RF_CHANGE_BY_INIT);
35 ulRegRead = rtl92e_readl(dev, CPU_GEN);
36 ulRegRead |= CPU_GEN_SYSTEM_RESET;
37 rtl92e_writel(dev, CPU_GEN, ulRegRead);
38 } else {
39 rtl92e_writel(dev, WFCRC0, 0xffffffff);
40 rtl92e_writel(dev, WFCRC1, 0xffffffff);
41 rtl92e_writel(dev, WFCRC2, 0xffffffff);
42 rtl92e_writeb(dev, PMR, 0x5);
43 rtl92e_writeb(dev, MAC_BLK_CTRL, 0xa);
44 }
45 out_pci_suspend:
46 netdev_info(dev, "WOL is %s\n", priv->rtllib->bSupportRemoteWakeUp ?
47 "Supported" : "Not supported");
48 device_set_wakeup_enable(dev_d, priv->rtllib->bSupportRemoteWakeUp);
49
50 mdelay(20);
51
52 return 0;
53 }
54
rtl92e_resume(struct device * dev_d)55 int rtl92e_resume(struct device *dev_d)
56 {
57 struct pci_dev *pdev = to_pci_dev(dev_d);
58 struct net_device *dev = dev_get_drvdata(dev_d);
59 struct r8192_priv *priv = rtllib_priv(dev);
60 u32 val;
61
62 netdev_info(dev, "================>r8192E resume call.\n");
63
64 pci_read_config_dword(pdev, 0x40, &val);
65 if ((val & 0x0000ff00) != 0)
66 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
67
68 device_wakeup_disable(dev_d);
69
70 if (priv->polling_timer_on == 0)
71 rtl92e_check_rfctrl_gpio_timer(&priv->gpio_polling_timer);
72
73 if (!netif_running(dev)) {
74 netdev_info(dev,
75 "RTL819XE:UI is open out of resume function\n");
76 goto out;
77 }
78
79 netif_device_attach(dev);
80 if (dev->netdev_ops->ndo_open)
81 dev->netdev_ops->ndo_open(dev);
82
83 if (!priv->rtllib->bSupportRemoteWakeUp)
84 rtl92e_set_rf_state(dev, rf_on, RF_CHANGE_BY_INIT);
85
86 out:
87 return 0;
88 }
89
90