1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
3
4 #include "../wifi.h"
5 #include "../pci.h"
6 #include "reg.h"
7 #include "led.h"
8
rtl8723e_sw_led_on(struct ieee80211_hw * hw,enum rtl_led_pin pin)9 void rtl8723e_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 ledcfg &= ~BIT(6);
23 rtl_write_byte(rtlpriv,
24 REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5));
25 break;
26 case LED_PIN_LED1:
27 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
28 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
29 break;
30 default:
31 pr_err("switch case %#x not processed\n", pin);
32 break;
33 }
34 }
35
rtl8723e_sw_led_off(struct ieee80211_hw * hw,enum rtl_led_pin pin)36 void rtl8723e_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 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
45
46 switch (pin) {
47 case LED_PIN_GPIO0:
48 break;
49 case LED_PIN_LED0:
50 ledcfg &= 0xf0;
51 if (rtlpriv->ledctl.led_opendrain) {
52 ledcfg &= 0x90; /* Set to software control. */
53 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg|BIT(3)));
54 ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
55 ledcfg &= 0xFE;
56 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, ledcfg);
57 } else {
58 ledcfg &= ~BIT(6);
59 rtl_write_byte(rtlpriv, REG_LEDCFG2,
60 (ledcfg | BIT(3) | BIT(5)));
61 }
62 break;
63 case LED_PIN_LED1:
64 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
65 ledcfg &= 0x10; /* Set to software control. */
66 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg|BIT(3));
67
68 break;
69 default:
70 pr_err("switch case %#x not processed\n", pin);
71 break;
72 }
73 }
74
_rtl8723e_sw_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)75 static void _rtl8723e_sw_led_control(struct ieee80211_hw *hw,
76 enum led_ctl_mode ledaction)
77 {
78 struct rtl_priv *rtlpriv = rtl_priv(hw);
79 enum rtl_led_pin pin0 = rtlpriv->ledctl.sw_led0;
80
81 switch (ledaction) {
82 case LED_CTL_POWER_ON:
83 case LED_CTL_LINK:
84 case LED_CTL_NO_LINK:
85 rtl8723e_sw_led_on(hw, pin0);
86 break;
87 case LED_CTL_POWER_OFF:
88 rtl8723e_sw_led_off(hw, pin0);
89 break;
90 default:
91 break;
92 }
93 }
94
rtl8723e_led_control(struct ieee80211_hw * hw,enum led_ctl_mode ledaction)95 void rtl8723e_led_control(struct ieee80211_hw *hw,
96 enum led_ctl_mode ledaction)
97 {
98 struct rtl_priv *rtlpriv = rtl_priv(hw);
99 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
100
101 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
102 (ledaction == LED_CTL_TX ||
103 ledaction == LED_CTL_RX ||
104 ledaction == LED_CTL_SITE_SURVEY ||
105 ledaction == LED_CTL_LINK ||
106 ledaction == LED_CTL_NO_LINK ||
107 ledaction == LED_CTL_START_TO_LINK ||
108 ledaction == LED_CTL_POWER_ON)) {
109 return;
110 }
111 rtl_dbg(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n",
112 ledaction);
113 _rtl8723e_sw_led_control(hw, ledaction);
114 }
115