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
27
28
29
30#include "../wifi.h"
31#include "../pci.h"
32#include "reg.h"
33#include "led.h"
34
35static void rtl88ee_init_led(struct ieee80211_hw *hw,
36 struct rtl_led *pled, enum rtl_led_pin ledpin)
37{
38 pled->hw = hw;
39 pled->ledpin = ledpin;
40 pled->ledon = false;
41}
42
43void rtl88ee_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
44{
45 u8 ledcfg;
46 struct rtl_priv *rtlpriv = rtl_priv(hw);
47
48 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
49 "LedAddr:%X ledpin =%d\n", REG_LEDCFG2, pled->ledpin);
50
51 switch (pled->ledpin) {
52 case LED_PIN_GPIO0:
53 break;
54 case LED_PIN_LED0:
55 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
56 rtl_write_byte(rtlpriv, REG_LEDCFG2,
57 (ledcfg & 0xf0) | BIT(5) | BIT(6));
58 break;
59 case LED_PIN_LED1:
60 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
61 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
62 break;
63 default:
64 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
65 "switch case not processed\n");
66 break;
67 }
68 pled->ledon = true;
69}
70
71void rtl88ee_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
72{
73 struct rtl_priv *rtlpriv = rtl_priv(hw);
74 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
75 u8 ledcfg;
76 u8 val;
77
78 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
79 "LedAddr:%X ledpin =%d\n", REG_LEDCFG2, pled->ledpin);
80
81 switch (pled->ledpin) {
82 case LED_PIN_GPIO0:
83 break;
84 case LED_PIN_LED0:
85 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
86 ledcfg &= 0xf0;
87 val = ledcfg | BIT(3) | BIT(5) | BIT(6);
88 if (pcipriv->ledctl.led_opendrain == true) {
89 rtl_write_byte(rtlpriv, REG_LEDCFG2, val);
90 ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
91 val = ledcfg & 0xFE;
92 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, val);
93 } else {
94 rtl_write_byte(rtlpriv, REG_LEDCFG2, val);
95 }
96 break;
97 case LED_PIN_LED1:
98 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
99 ledcfg &= 0x10;
100 rtl_write_byte(rtlpriv, REG_LEDCFG1, (ledcfg | BIT(3)));
101 break;
102 default:
103 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
104 "switch case not processed\n");
105 break;
106 }
107 pled->ledon = false;
108}
109
110void rtl88ee_init_sw_leds(struct ieee80211_hw *hw)
111{
112 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
113
114 rtl88ee_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
115 rtl88ee_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
116}
117
118static void rtl88ee_sw_led_control(struct ieee80211_hw *hw,
119 enum led_ctl_mode ledaction)
120{
121 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
122 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
123
124 switch (ledaction) {
125 case LED_CTL_POWER_ON:
126 case LED_CTL_LINK:
127 case LED_CTL_NO_LINK:
128 rtl88ee_sw_led_on(hw, pLed0);
129 break;
130 case LED_CTL_POWER_OFF:
131 rtl88ee_sw_led_off(hw, pLed0);
132 break;
133 default:
134 break;
135 }
136}
137
138void rtl88ee_led_control(struct ieee80211_hw *hw,
139 enum led_ctl_mode ledaction)
140{
141 struct rtl_priv *rtlpriv = rtl_priv(hw);
142 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
143
144 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
145 (ledaction == LED_CTL_TX ||
146 ledaction == LED_CTL_RX ||
147 ledaction == LED_CTL_SITE_SURVEY ||
148 ledaction == LED_CTL_LINK ||
149 ledaction == LED_CTL_NO_LINK ||
150 ledaction == LED_CTL_START_TO_LINK ||
151 ledaction == LED_CTL_POWER_ON)) {
152 return;
153 }
154 RT_TRACE(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n",
155 ledaction);
156 rtl88ee_sw_led_control(hw, ledaction);
157}
158