1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
9 static void _rtl8723e_init_led(struct ieee80211_hw
*hw
,
10 struct rtl_led
*pled
, enum rtl_led_pin ledpin
)
13 pled
->ledpin
= ledpin
;
17 void rtl8723e_sw_led_on(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
20 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
22 rtl_dbg(rtlpriv
, COMP_LED
, DBG_LOUD
,
23 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2
, pled
->ledpin
);
25 switch (pled
->ledpin
) {
29 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
31 rtl_write_byte(rtlpriv
,
32 REG_LEDCFG2
, (ledcfg
& 0xf0) | BIT(5));
35 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
36 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
& 0x10);
39 pr_err("switch case %#x not processed\n",
46 void rtl8723e_sw_led_off(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
48 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
51 rtl_dbg(rtlpriv
, COMP_LED
, DBG_LOUD
,
52 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2
, pled
->ledpin
);
54 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
56 switch (pled
->ledpin
) {
61 if (rtlpriv
->ledctl
.led_opendrain
) {
62 ledcfg
&= 0x90; /* Set to software control. */
63 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
|BIT(3)));
64 ledcfg
= rtl_read_byte(rtlpriv
, REG_MAC_PINMUX_CFG
);
66 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
, ledcfg
);
69 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
70 (ledcfg
| BIT(3) | BIT(5)));
74 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
75 ledcfg
&= 0x10; /* Set to software control. */
76 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
|BIT(3));
80 pr_err("switch case %#x not processed\n",
87 void rtl8723e_init_sw_leds(struct ieee80211_hw
*hw
)
89 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
91 _rtl8723e_init_led(hw
, &rtlpriv
->ledctl
.sw_led0
, LED_PIN_LED0
);
92 _rtl8723e_init_led(hw
, &rtlpriv
->ledctl
.sw_led1
, LED_PIN_LED1
);
95 static void _rtl8723e_sw_led_control(struct ieee80211_hw
*hw
,
96 enum led_ctl_mode ledaction
)
98 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
99 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
102 case LED_CTL_POWER_ON
:
104 case LED_CTL_NO_LINK
:
105 rtl8723e_sw_led_on(hw
, pled0
);
107 case LED_CTL_POWER_OFF
:
108 rtl8723e_sw_led_off(hw
, pled0
);
115 void rtl8723e_led_control(struct ieee80211_hw
*hw
,
116 enum led_ctl_mode ledaction
)
118 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
119 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
121 if ((ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
) &&
122 (ledaction
== LED_CTL_TX
||
123 ledaction
== LED_CTL_RX
||
124 ledaction
== LED_CTL_SITE_SURVEY
||
125 ledaction
== LED_CTL_LINK
||
126 ledaction
== LED_CTL_NO_LINK
||
127 ledaction
== LED_CTL_START_TO_LINK
||
128 ledaction
== LED_CTL_POWER_ON
)) {
131 rtl_dbg(rtlpriv
, COMP_LED
, DBG_LOUD
, "ledaction %d,\n",
133 _rtl8723e_sw_led_control(hw
, ledaction
);