1 /******************************************************************************
3 * Copyright(c) 2007 - 2017 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 *****************************************************************************/
16 #include <drv_types.h>
20 void dump_led_config(void *sel, _adapter *adapter)
22 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
23 struct led_priv *ledpriv = adapter_to_led(adapter);
26 RTW_PRINT_SEL(sel, "strategy:%u\n", ledpriv->LedStrategy);
27 #ifdef CONFIG_RTW_SW_LED
28 RTW_PRINT_SEL(sel, "bRegUseLed:%u\n", ledpriv->bRegUseLed);
29 RTW_PRINT_SEL(sel, "iface_en_mask:0x%02X\n", ledpriv->iface_en_mask);
30 for (i = 0; i < dvobj->iface_nums; i++)
31 RTW_PRINT_SEL(sel, "ctl_en_mask[%d]:0x%08X\n", i, ledpriv->ctl_en_mask[i]);
35 void rtw_led_set_strategy(_adapter *adapter, u8 strategy)
37 struct led_priv *ledpriv = adapter_to_led(adapter);
38 _adapter *pri_adapter = GET_PRIMARY_ADAPTER(adapter);
40 #ifndef CONFIG_RTW_SW_LED
41 if (IS_SW_LED_STRATEGY(strategy)) {
42 RTW_WARN("CONFIG_RTW_SW_LED is not defined\n");
47 #ifdef CONFIG_RTW_SW_LED
48 if (!ledpriv->bRegUseLed)
52 if (ledpriv->LedStrategy == strategy)
55 if (IS_HW_LED_STRATEGY(strategy) || IS_HW_LED_STRATEGY(ledpriv->LedStrategy)) {
56 RTW_WARN("switching on/off HW_LED strategy is not supported\n");
60 ledpriv->LedStrategy = strategy;
62 #ifdef CONFIG_RTW_SW_LED
63 rtw_hal_sw_led_deinit(pri_adapter);
66 rtw_led_control(pri_adapter, RTW_LED_OFF);
69 #ifdef CONFIG_RTW_SW_LED
70 #if CONFIG_RTW_SW_LED_TRX_DA_CLASSIFY
71 void rtw_sw_led_blink_uc_trx_only(LED_DATA *led)
73 _adapter *adapter = led->padapter;
74 BOOLEAN bStopBlinking = _FALSE;
76 if (led->BlinkingLedState == RTW_LED_ON)
77 SwLedOn(adapter, led);
79 SwLedOff(adapter, led);
81 switch (led->CurrLedState) {
83 SwLedOn(adapter, led);
87 SwLedOff(adapter, led);
92 if (led->BlinkTimes == 0)
93 bStopBlinking = _TRUE;
95 if (adapter_to_pwrctl(adapter)->rf_pwrstate != rf_on
96 && adapter_to_pwrctl(adapter)->rfoff_reason > RF_CHANGE_BY_PS
98 SwLedOff(adapter, led);
99 led->bLedBlinkInProgress = _FALSE;
102 led->BlinkingLedState = RTW_LED_OFF;
104 led->BlinkingLedState = RTW_LED_ON;
107 led->CurrLedState = RTW_LED_OFF;
108 led->bLedBlinkInProgress = _FALSE;
110 _set_timer(&(led->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
119 void rtw_sw_led_ctl_mode_uc_trx_only(_adapter *adapter, LED_CTL_MODE ctl)
121 struct led_priv *ledpriv = adapter_to_led(adapter);
122 LED_DATA *led = &(ledpriv->SwLed0);
123 LED_DATA *led1 = &(ledpriv->SwLed1);
124 LED_DATA *led2 = &(ledpriv->SwLed2);
129 if (led->bLedBlinkInProgress == _FALSE) {
130 led->bLedBlinkInProgress = _TRUE;
131 led->CurrLedState = LED_BLINK_TXRX;
134 led->BlinkingLedState = RTW_LED_OFF;
136 led->BlinkingLedState = RTW_LED_ON;
137 _set_timer(&(led->BlinkTimer), LED_BLINK_FASTER_INTERVAL_ALPHA);
141 case LED_CTL_POWER_OFF:
142 led->CurrLedState = RTW_LED_OFF;
143 led->BlinkingLedState = RTW_LED_OFF;
145 if (led->bLedBlinkInProgress) {
146 _cancel_timer_ex(&(led->BlinkTimer));
147 led->bLedBlinkInProgress = _FALSE;
150 SwLedOff(adapter, led);
151 SwLedOff(adapter, led1);
152 SwLedOff(adapter, led2);
159 #endif /* CONFIG_RTW_SW_LED_TRX_DA_CLASSIFY */
161 void rtw_led_control(_adapter *adapter, LED_CTL_MODE ctl)
163 struct led_priv *ledpriv = adapter_to_led(adapter);
165 if (ledpriv->LedControlHandler) {
166 #if CONFIG_RTW_SW_LED_TRX_DA_CLASSIFY
167 if (ledpriv->LedStrategy != SW_LED_MODE_UC_TRX_ONLY) {
168 if (ctl == LED_CTL_UC_TX || ctl == LED_CTL_BMC_TX) {
169 if (ledpriv->ctl_en_mask[adapter->iface_id] & BIT(LED_CTL_TX))
170 ctl = LED_CTL_TX; /* transform specific TX ctl to general TX ctl */
171 } else if (ctl == LED_CTL_UC_RX || ctl == LED_CTL_BMC_RX) {
172 if (ledpriv->ctl_en_mask[adapter->iface_id] & BIT(LED_CTL_RX))
173 ctl = LED_CTL_RX; /* transform specific RX ctl to general RX ctl */
178 if ((ledpriv->iface_en_mask & BIT(adapter->iface_id))
179 && (ledpriv->ctl_en_mask[adapter->iface_id] & BIT(ctl)))
180 ledpriv->LedControlHandler(adapter, ctl);
184 void rtw_led_tx_control(_adapter *adapter, const u8 *da)
186 #if CONFIG_RTW_SW_LED_TRX_DA_CLASSIFY
188 rtw_led_control(adapter, LED_CTL_BMC_TX);
190 rtw_led_control(adapter, LED_CTL_UC_TX);
192 rtw_led_control(adapter, LED_CTL_TX);
196 void rtw_led_rx_control(_adapter *adapter, const u8 *da)
198 #if CONFIG_RTW_SW_LED_TRX_DA_CLASSIFY
200 rtw_led_control(adapter, LED_CTL_BMC_RX);
202 rtw_led_control(adapter, LED_CTL_UC_RX);
204 rtw_led_control(adapter, LED_CTL_RX);
208 void rtw_led_set_iface_en(_adapter *adapter, u8 en)
210 struct led_priv *ledpriv = adapter_to_led(adapter);
213 ledpriv->iface_en_mask |= BIT(adapter->iface_id);
215 ledpriv->iface_en_mask &= ~BIT(adapter->iface_id);
218 void rtw_led_set_iface_en_mask(_adapter *adapter, u8 mask)
220 struct led_priv *ledpriv = adapter_to_led(adapter);
222 ledpriv->iface_en_mask = mask;
225 void rtw_led_set_ctl_en_mask(_adapter *adapter, u32 ctl_mask)
227 struct led_priv *ledpriv = adapter_to_led(adapter);
229 #if CONFIG_RTW_SW_LED_TRX_DA_CLASSIFY
230 if (ctl_mask & BIT(LED_CTL_TX))
231 ctl_mask |= BIT(LED_CTL_UC_TX) | BIT(LED_CTL_BMC_TX);
232 if (ctl_mask & BIT(LED_CTL_RX))
233 ctl_mask |= BIT(LED_CTL_UC_RX) | BIT(LED_CTL_BMC_RX);
236 ledpriv->ctl_en_mask[adapter->iface_id] = ctl_mask;
239 void rtw_led_set_ctl_en_mask_primary(_adapter *adapter)
241 rtw_led_set_ctl_en_mask(adapter, 0xFFFFFFFF);
244 void rtw_led_set_ctl_en_mask_virtual(_adapter *adapter)
246 rtw_led_set_ctl_en_mask(adapter
247 , BIT(LED_CTL_POWER_ON) | BIT(LED_CTL_POWER_OFF)
248 | BIT(LED_CTL_TX) | BIT(LED_CTL_RX)
251 #endif /* CONFIG_RTW_SW_LED */
253 #endif /* CONFIG_RTW_LED */