xref: /linux/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/led.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2014  Realtek Corporation.*/
3 
4 #include "../wifi.h"
5 #include "../pci.h"
6 #include "reg.h"
7 #include "led.h"
8 
9 void rtl92ee_sw_led_on(struct ieee80211_hw *hw, enum rtl_led_pin pin)
10 {
11 	u32 ledcfg;
12 	struct rtl_priv *rtlpriv = rtl_priv(hw);
13 
14 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD,
15 		"LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pin);
16 
17 	switch (pin) {
18 	case LED_PIN_GPIO0:
19 		break;
20 	case LED_PIN_LED0:
21 		ledcfg = rtl_read_dword(rtlpriv , REG_GPIO_PIN_CTRL);
22 		ledcfg &= ~BIT(13);
23 		ledcfg |= BIT(21);
24 		ledcfg &= ~BIT(29);
25 
26 		rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
27 
28 		break;
29 	case LED_PIN_LED1:
30 
31 		break;
32 	default:
33 		rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
34 			"switch case %#x not processed\n", pin);
35 		break;
36 	}
37 }
38 
39 void rtl92ee_sw_led_off(struct ieee80211_hw *hw, enum rtl_led_pin pin)
40 {
41 	struct rtl_priv *rtlpriv = rtl_priv(hw);
42 	u32 ledcfg;
43 
44 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD,
45 		"LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pin);
46 
47 	switch (pin) {
48 	case LED_PIN_GPIO0:
49 		break;
50 	case LED_PIN_LED0:
51 
52 		ledcfg = rtl_read_dword(rtlpriv , REG_GPIO_PIN_CTRL);
53 		ledcfg |= ~BIT(21);
54 		ledcfg &= ~BIT(29);
55 		rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
56 
57 		break;
58 	case LED_PIN_LED1:
59 
60 		break;
61 	default:
62 		rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
63 			"switch case %#x not processed\n", pin);
64 		break;
65 	}
66 }
67 
68 static void _rtl92ee_sw_led_control(struct ieee80211_hw *hw,
69 				    enum led_ctl_mode ledaction)
70 {
71 	struct rtl_priv *rtlpriv = rtl_priv(hw);
72 	enum rtl_led_pin pin0 = rtlpriv->ledctl.sw_led0;
73 
74 	switch (ledaction) {
75 	case LED_CTL_POWER_ON:
76 	case LED_CTL_LINK:
77 	case LED_CTL_NO_LINK:
78 		rtl92ee_sw_led_on(hw, pin0);
79 		break;
80 	case LED_CTL_POWER_OFF:
81 		rtl92ee_sw_led_off(hw, pin0);
82 		break;
83 	default:
84 		break;
85 	}
86 }
87 
88 void rtl92ee_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
89 {
90 	struct rtl_priv *rtlpriv = rtl_priv(hw);
91 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
92 
93 	if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
94 	    (ledaction == LED_CTL_TX ||
95 	     ledaction == LED_CTL_RX ||
96 	     ledaction == LED_CTL_SITE_SURVEY ||
97 	     ledaction == LED_CTL_LINK ||
98 	     ledaction == LED_CTL_NO_LINK ||
99 	     ledaction == LED_CTL_START_TO_LINK ||
100 	     ledaction == LED_CTL_POWER_ON)) {
101 		return;
102 	}
103 	rtl_dbg(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n", ledaction);
104 	_rtl92ee_sw_led_control(hw, ledaction);
105 }
106