GNU Linux-libre 4.14.257-gnu1
[releases.git] / drivers / staging / rtlwifi / rtl8822be / led.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2016  Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25
26 #include "../wifi.h"
27 #include "../pci.h"
28 #include "reg.h"
29 #include "led.h"
30
31 static void _rtl8822be_init_led(struct ieee80211_hw *hw, struct rtl_led *pled,
32                                 enum rtl_led_pin ledpin)
33 {
34         pled->hw = hw;
35         pled->ledpin = ledpin;
36         pled->ledon = false;
37 }
38
39 void rtl8822be_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
40 {
41         struct rtl_priv *rtlpriv = rtl_priv(hw);
42
43         RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
44                  REG_LEDCFG2_8822B, pled->ledpin);
45
46         switch (pled->ledpin) {
47         case LED_PIN_GPIO0:
48                 break;
49         case LED_PIN_LED0:
50                 break;
51         case LED_PIN_LED1:
52                 break;
53         default:
54                 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
55                          "switch case not process\n");
56                 break;
57         }
58         pled->ledon = true;
59 }
60
61 void rtl8822be_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
62 {
63         struct rtl_priv *rtlpriv = rtl_priv(hw);
64
65         RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
66                  REG_LEDCFG2_8822B, pled->ledpin);
67
68         switch (pled->ledpin) {
69         case LED_PIN_GPIO0:
70                 break;
71         case LED_PIN_LED0:
72                 break;
73         case LED_PIN_LED1:
74
75                 break;
76         default:
77                 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
78                          "switch case not process\n");
79                 break;
80         }
81         pled->ledon = false;
82 }
83
84 void rtl8822be_init_sw_leds(struct ieee80211_hw *hw)
85 {
86         struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
87
88         _rtl8822be_init_led(hw, &pcipriv->ledctl.sw_led0, LED_PIN_LED0);
89         _rtl8822be_init_led(hw, &pcipriv->ledctl.sw_led1, LED_PIN_LED1);
90 }
91
92 static void _rtl8822be_sw_led_control(struct ieee80211_hw *hw,
93                                       enum led_ctl_mode ledaction)
94 {
95         struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
96         struct rtl_led *led0 = &pcipriv->ledctl.sw_led0;
97
98         switch (ledaction) {
99         case LED_CTL_POWER_ON:
100         case LED_CTL_LINK:
101         case LED_CTL_NO_LINK:
102                 rtl8822be_sw_led_on(hw, led0);
103                 break;
104         case LED_CTL_POWER_OFF:
105                 rtl8822be_sw_led_off(hw, led0);
106                 break;
107         default:
108                 break;
109         }
110 }
111
112 void rtl8822be_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
113 {
114         struct rtl_priv *rtlpriv = rtl_priv(hw);
115         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
116
117         if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
118             (ledaction == LED_CTL_TX || ledaction == LED_CTL_RX ||
119              ledaction == LED_CTL_SITE_SURVEY || ledaction == LED_CTL_LINK ||
120              ledaction == LED_CTL_NO_LINK ||
121              ledaction == LED_CTL_START_TO_LINK ||
122              ledaction == LED_CTL_POWER_ON)) {
123                 return;
124         }
125         RT_TRACE(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n", ledaction);
126         _rtl8822be_sw_led_control(hw, ledaction);
127 }