xref: /linux/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/led.c (revision cbac924200b838cfb8d8b1415113d788089dc50b)
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 static void _rtl92ee_init_led(struct ieee80211_hw *hw,
10 			      struct rtl_led *pled, enum rtl_led_pin ledpin)
11 {
12 	pled->hw = hw;
13 	pled->ledpin = ledpin;
14 	pled->ledon = false;
15 }
16 
17 void rtl92ee_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
18 {
19 	u32 ledcfg;
20 	struct rtl_priv *rtlpriv = rtl_priv(hw);
21 
22 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD,
23 		"LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
24 
25 	switch (pled->ledpin) {
26 	case LED_PIN_GPIO0:
27 		break;
28 	case LED_PIN_LED0:
29 		ledcfg = rtl_read_dword(rtlpriv , REG_GPIO_PIN_CTRL);
30 		ledcfg &= ~BIT(13);
31 		ledcfg |= BIT(21);
32 		ledcfg &= ~BIT(29);
33 
34 		rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
35 
36 		break;
37 	case LED_PIN_LED1:
38 
39 		break;
40 	default:
41 		rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
42 			"switch case %#x not processed\n", pled->ledpin);
43 		break;
44 	}
45 	pled->ledon = true;
46 }
47 
48 void rtl92ee_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
49 {
50 	struct rtl_priv *rtlpriv = rtl_priv(hw);
51 	u32 ledcfg;
52 
53 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD,
54 		"LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
55 
56 	switch (pled->ledpin) {
57 	case LED_PIN_GPIO0:
58 		break;
59 	case LED_PIN_LED0:
60 
61 		ledcfg = rtl_read_dword(rtlpriv , REG_GPIO_PIN_CTRL);
62 		ledcfg |= ~BIT(21);
63 		ledcfg &= ~BIT(29);
64 		rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
65 
66 		break;
67 	case LED_PIN_LED1:
68 
69 		break;
70 	default:
71 		rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
72 			"switch case %#x not processed\n", pled->ledpin);
73 		break;
74 	}
75 	pled->ledon = false;
76 }
77 
78 void rtl92ee_init_sw_leds(struct ieee80211_hw *hw)
79 {
80 	struct rtl_priv *rtlpriv = rtl_priv(hw);
81 
82 	_rtl92ee_init_led(hw, &rtlpriv->ledctl.sw_led0, LED_PIN_LED0);
83 	_rtl92ee_init_led(hw, &rtlpriv->ledctl.sw_led1, LED_PIN_LED1);
84 }
85 
86 static void _rtl92ee_sw_led_control(struct ieee80211_hw *hw,
87 				    enum led_ctl_mode ledaction)
88 {
89 	struct rtl_priv *rtlpriv = rtl_priv(hw);
90 	struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
91 
92 	switch (ledaction) {
93 	case LED_CTL_POWER_ON:
94 	case LED_CTL_LINK:
95 	case LED_CTL_NO_LINK:
96 		rtl92ee_sw_led_on(hw, pled0);
97 		break;
98 	case LED_CTL_POWER_OFF:
99 		rtl92ee_sw_led_off(hw, pled0);
100 		break;
101 	default:
102 		break;
103 	}
104 }
105 
106 void rtl92ee_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
107 {
108 	struct rtl_priv *rtlpriv = rtl_priv(hw);
109 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
110 
111 	if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
112 	    (ledaction == LED_CTL_TX ||
113 	     ledaction == LED_CTL_RX ||
114 	     ledaction == LED_CTL_SITE_SURVEY ||
115 	     ledaction == LED_CTL_LINK ||
116 	     ledaction == LED_CTL_NO_LINK ||
117 	     ledaction == LED_CTL_START_TO_LINK ||
118 	     ledaction == LED_CTL_POWER_ON)) {
119 		return;
120 	}
121 	rtl_dbg(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n", ledaction);
122 	_rtl92ee_sw_led_control(hw, ledaction);
123 }
124