1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include "../wifi.h"
27#include "../pci.h"
28#include "reg.h"
29#include "led.h"
30
31static void _rtl8723be_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
39void rtl8723be_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
40{
41 u8 ledcfg;
42 struct rtl_priv *rtlpriv = rtl_priv(hw);
43
44 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
45 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
46
47 switch (pled->ledpin) {
48 case LED_PIN_GPIO0:
49 break;
50 case LED_PIN_LED0:
51 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
52 ledcfg &= ~BIT(6);
53 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5));
54 break;
55 case LED_PIN_LED1:
56 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
57 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
58 break;
59 default:
60 pr_err("switch case %#x not processed\n",
61 pled->ledpin);
62 break;
63 }
64 pled->ledon = true;
65}
66
67void rtl8723be_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
68{
69 struct rtl_priv *rtlpriv = rtl_priv(hw);
70 u8 ledcfg;
71
72 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
73 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
74
75 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
76
77 switch (pled->ledpin) {
78 case LED_PIN_GPIO0:
79 break;
80 case LED_PIN_LED0:
81 ledcfg &= 0xf0;
82 if (rtlpriv->ledctl.led_opendrain) {
83 ledcfg &= 0x90;
84 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg|BIT(3)));
85 ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
86 ledcfg &= 0xFE;
87 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, ledcfg);
88 } else {
89 ledcfg &= ~BIT(6);
90 rtl_write_byte(rtlpriv, REG_LEDCFG2,
91 (ledcfg | BIT(3) | BIT(5)));
92 }
93 break;
94 case LED_PIN_LED1:
95 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
96 ledcfg &= 0x10;
97 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg|BIT(3));
98
99 break;
100 default:
101 pr_err("switch case %#x not processed\n",
102 pled->ledpin);
103 break;
104 }
105 pled->ledon = false;
106}
107
108void rtl8723be_init_sw_leds(struct ieee80211_hw *hw)
109{
110 struct rtl_priv *rtlpriv = rtl_priv(hw);
111
112 _rtl8723be_init_led(hw, &rtlpriv->ledctl.sw_led0, LED_PIN_LED0);
113 _rtl8723be_init_led(hw, &rtlpriv->ledctl.sw_led1, LED_PIN_LED1);
114}
115
116static void _rtl8723be_sw_led_control(struct ieee80211_hw *hw,
117 enum led_ctl_mode ledaction)
118{
119 struct rtl_priv *rtlpriv = rtl_priv(hw);
120 struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
121
122 switch (ledaction) {
123 case LED_CTL_POWER_ON:
124 case LED_CTL_LINK:
125 case LED_CTL_NO_LINK:
126 rtl8723be_sw_led_on(hw, pled0);
127 break;
128 case LED_CTL_POWER_OFF:
129 rtl8723be_sw_led_off(hw, pled0);
130 break;
131 default:
132 break;
133 }
134}
135
136void rtl8723be_led_control(struct ieee80211_hw *hw,
137 enum led_ctl_mode ledaction)
138{
139 struct rtl_priv *rtlpriv = rtl_priv(hw);
140 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
141
142 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
143 (ledaction == LED_CTL_TX ||
144 ledaction == LED_CTL_RX ||
145 ledaction == LED_CTL_SITE_SURVEY ||
146 ledaction == LED_CTL_LINK ||
147 ledaction == LED_CTL_NO_LINK ||
148 ledaction == LED_CTL_START_TO_LINK ||
149 ledaction == LED_CTL_POWER_ON)) {
150 return;
151 }
152 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n", ledaction);
153 _rtl8723be_sw_led_control(hw, ledaction);
154}
155