1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2016  Realtek Corporation.
5  *
6  * Contact Information:
7  * wlanfae <wlanfae@realtek.com>
8  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
9  * Hsinchu 300, Taiwan.
10  *
11  * Larry Finger <Larry.Finger@lwfinger.net>
12  *
13  *****************************************************************************/
14 
15 #include "../wifi.h"
16 #include "../pci.h"
17 #include "reg.h"
18 #include "led.h"
19 
_rtl8822be_init_led(struct ieee80211_hw * hw,struct rtl_led * pled,enum rtl_led_pin ledpin)20 static void _rtl8822be_init_led(struct ieee80211_hw *hw, struct rtl_led *pled,
21 				enum rtl_led_pin ledpin)
22 {
23 	pled->hw = hw;
24 	pled->ledpin = ledpin;
25 	pled->ledon = false;
26 }
27 
rtl8822be_sw_led_on(struct ieee80211_hw * hw,struct rtl_led * pled)28 void rtl8822be_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
29 {
30 	struct rtl_priv *rtlpriv = rtl_priv(hw);
31 
32 	RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
33 		 REG_LEDCFG2_8822B, pled->ledpin);
34 
35 	switch (pled->ledpin) {
36 	case LED_PIN_GPIO0:
37 		break;
38 	case LED_PIN_LED0:
39 		break;
40 	case LED_PIN_LED1:
41 		break;
42 	default:
43 		RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
44 			 "switch case not process\n");
45 		break;
46 	}
47 	pled->ledon = true;
48 }
49 
rtl8822be_sw_led_off(struct ieee80211_hw * hw,struct rtl_led * pled)50 void rtl8822be_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
51 {
52 	struct rtl_priv *rtlpriv = rtl_priv(hw);
53 
54 	RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "LedAddr:%X ledpin=%d\n",
55 		 REG_LEDCFG2_8822B, pled->ledpin);
56 
57 	switch (pled->ledpin) {
58 	case LED_PIN_GPIO0:
59 		break;
60 	case LED_PIN_LED0:
61 		break;
62 	case LED_PIN_LED1:
63 
64 		break;
65 	default:
66 		RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
67 			 "switch case not process\n");
68 		break;
69 	}
70 	pled->ledon = false;
71 }
72 
rtl8822be_init_sw_leds(struct ieee80211_hw * hw)73 void rtl8822be_init_sw_leds(struct ieee80211_hw *hw)
74 {
75 	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
76 
77 	_rtl8822be_init_led(hw, &pcipriv->ledctl.sw_led0, LED_PIN_LED0);
78 	_rtl8822be_init_led(hw, &pcipriv->ledctl.sw_led1, LED_PIN_LED1);
79 }
80 
_rtl8822be_sw_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)81 static void _rtl8822be_sw_led_control(struct ieee80211_hw *hw,
82 				      enum led_ctl_mode ledaction)
83 {
84 	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
85 	struct rtl_led *led0 = &pcipriv->ledctl.sw_led0;
86 
87 	switch (ledaction) {
88 	case LED_CTL_POWER_ON:
89 	case LED_CTL_LINK:
90 	case LED_CTL_NO_LINK:
91 		rtl8822be_sw_led_on(hw, led0);
92 		break;
93 	case LED_CTL_POWER_OFF:
94 		rtl8822be_sw_led_off(hw, led0);
95 		break;
96 	default:
97 		break;
98 	}
99 }
100 
rtl8822be_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)101 void rtl8822be_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
102 {
103 	struct rtl_priv *rtlpriv = rtl_priv(hw);
104 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
105 
106 	if (ppsc->rfoff_reason > RF_CHANGE_BY_PS &&
107 	    (ledaction == LED_CTL_TX || ledaction == LED_CTL_RX ||
108 	     ledaction == LED_CTL_SITE_SURVEY || ledaction == LED_CTL_LINK ||
109 	     ledaction == LED_CTL_NO_LINK ||
110 	     ledaction == LED_CTL_START_TO_LINK ||
111 	     ledaction == LED_CTL_POWER_ON)) {
112 		return;
113 	}
114 	RT_TRACE(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n", ledaction);
115 	_rtl8822be_sw_led_control(hw, ledaction);
116 }
117