1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2014 Realtek Corporation.*/
9 static void _rtl8723be_init_led(struct ieee80211_hw
*hw
, struct rtl_led
*pled
,
10 enum rtl_led_pin ledpin
)
13 pled
->ledpin
= ledpin
;
17 void rtl8723be_sw_led_on(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
20 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
22 RT_TRACE(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
, REG_LEDCFG2
, (ledcfg
& 0xf0) | BIT(5));
34 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
35 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
& 0x10);
38 pr_err("switch case %#x not processed\n",
45 void rtl8723be_sw_led_off(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
47 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
50 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
51 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2
, pled
->ledpin
);
53 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
55 switch (pled
->ledpin
) {
60 if (rtlpriv
->ledctl
.led_opendrain
) {
61 ledcfg
&= 0x90; /* Set to software control. */
62 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
|BIT(3)));
63 ledcfg
= rtl_read_byte(rtlpriv
, REG_MAC_PINMUX_CFG
);
65 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
, ledcfg
);
68 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
69 (ledcfg
| BIT(3) | BIT(5)));
73 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
74 ledcfg
&= 0x10; /* Set to software control. */
75 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
|BIT(3));
79 pr_err("switch case %#x not processed\n",
86 void rtl8723be_init_sw_leds(struct ieee80211_hw
*hw
)
88 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
90 _rtl8723be_init_led(hw
, &rtlpriv
->ledctl
.sw_led0
, LED_PIN_LED0
);
91 _rtl8723be_init_led(hw
, &rtlpriv
->ledctl
.sw_led1
, LED_PIN_LED1
);
94 static void _rtl8723be_sw_led_control(struct ieee80211_hw
*hw
,
95 enum led_ctl_mode ledaction
)
97 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
98 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
101 case LED_CTL_POWER_ON
:
103 case LED_CTL_NO_LINK
:
104 rtl8723be_sw_led_on(hw
, pled0
);
106 case LED_CTL_POWER_OFF
:
107 rtl8723be_sw_led_off(hw
, pled0
);
114 void rtl8723be_led_control(struct ieee80211_hw
*hw
,
115 enum led_ctl_mode ledaction
)
117 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
118 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
120 if ((ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
) &&
121 (ledaction
== LED_CTL_TX
||
122 ledaction
== LED_CTL_RX
||
123 ledaction
== LED_CTL_SITE_SURVEY
||
124 ledaction
== LED_CTL_LINK
||
125 ledaction
== LED_CTL_NO_LINK
||
126 ledaction
== LED_CTL_START_TO_LINK
||
127 ledaction
== LED_CTL_POWER_ON
)) {
130 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "ledaction %d,\n", ledaction
);
131 _rtl8723be_sw_led_control(hw
, ledaction
);