xref: /linux/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/led.c (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2013  Realtek Corporation.*/
3 
4 #include "../wifi.h"
5 #include "../pci.h"
6 #include "reg.h"
7 #include "led.h"
8 
rtl88ee_sw_led_on(struct ieee80211_hw * hw,enum rtl_led_pin pin)9 void rtl88ee_sw_led_on(struct ieee80211_hw *hw, enum rtl_led_pin pin)
10 {
11 	u8 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_byte(rtlpriv, REG_LEDCFG2);
22 		rtl_write_byte(rtlpriv,
23 			       REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
24 		break;
25 	case LED_PIN_LED1:
26 		ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
27 		rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
28 		break;
29 	default:
30 		rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
31 			"switch case %#x not processed\n", pin);
32 		break;
33 	}
34 }
35 
rtl88ee_sw_led_off(struct ieee80211_hw * hw,enum rtl_led_pin pin)36 void rtl88ee_sw_led_off(struct ieee80211_hw *hw, enum rtl_led_pin pin)
37 {
38 	struct rtl_priv *rtlpriv = rtl_priv(hw);
39 	u8 ledcfg;
40 
41 	rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD,
42 		"LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pin);
43 
44 	switch (pin) {
45 	case LED_PIN_GPIO0:
46 		break;
47 	case LED_PIN_LED0:
48 		ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
49 		ledcfg &= 0xf0;
50 		if (rtlpriv->ledctl.led_opendrain) {
51 			rtl_write_byte(rtlpriv, REG_LEDCFG2,
52 				       (ledcfg | BIT(3) | BIT(5) | BIT(6)));
53 			ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
54 			rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG,
55 				       (ledcfg & 0xFE));
56 		} else
57 			rtl_write_byte(rtlpriv, REG_LEDCFG2,
58 				       (ledcfg | BIT(3) | BIT(5) | BIT(6)));
59 		break;
60 	case LED_PIN_LED1:
61 		ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
62 		ledcfg &= 0x10;
63 		rtl_write_byte(rtlpriv, REG_LEDCFG1, (ledcfg | BIT(3)));
64 		break;
65 	default:
66 		rtl_dbg(rtlpriv, COMP_ERR, DBG_LOUD,
67 			"switch case %#x not processed\n", pin);
68 		break;
69 	}
70 }
71 
_rtl88ee_sw_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)72 static void _rtl88ee_sw_led_control(struct ieee80211_hw *hw,
73 				    enum led_ctl_mode ledaction)
74 {
75 	struct rtl_priv *rtlpriv = rtl_priv(hw);
76 	enum rtl_led_pin pin0 = rtlpriv->ledctl.sw_led0;
77 
78 	switch (ledaction) {
79 	case LED_CTL_POWER_ON:
80 	case LED_CTL_LINK:
81 	case LED_CTL_NO_LINK:
82 		rtl88ee_sw_led_on(hw, pin0);
83 		break;
84 	case LED_CTL_POWER_OFF:
85 		rtl88ee_sw_led_off(hw, pin0);
86 		break;
87 	default:
88 		break;
89 	}
90 }
91 
rtl88ee_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)92 void rtl88ee_led_control(struct ieee80211_hw *hw,
93 			enum led_ctl_mode ledaction)
94 {
95 	struct rtl_priv *rtlpriv = rtl_priv(hw);
96 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
97 
98 	if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
99 	    (ledaction == LED_CTL_TX ||
100 	     ledaction == LED_CTL_RX ||
101 	     ledaction == LED_CTL_SITE_SURVEY ||
102 	     ledaction == LED_CTL_LINK ||
103 	     ledaction == LED_CTL_NO_LINK ||
104 	     ledaction == LED_CTL_START_TO_LINK ||
105 	     ledaction == LED_CTL_POWER_ON)) {
106 		return;
107 	}
108 	rtl_dbg(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n",
109 		ledaction);
110 	_rtl88ee_sw_led_control(hw, ledaction);
111 }
112