1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2013 Realtek Corporation.*/
9 static void _rtl88ee_init_led(struct ieee80211_hw
*hw
,
10 struct rtl_led
*pled
, enum rtl_led_pin ledpin
)
13 pled
->ledpin
= ledpin
;
17 void rtl88ee_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
);
30 rtl_write_byte(rtlpriv
,
31 REG_LEDCFG2
, (ledcfg
& 0xf0) | BIT(5) | BIT(6));
34 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
35 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
& 0x10);
38 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
39 "switch case %#x not processed\n", pled
->ledpin
);
45 void rtl88ee_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 switch (pled
->ledpin
) {
57 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
59 if (rtlpriv
->ledctl
.led_opendrain
) {
60 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
61 (ledcfg
| BIT(3) | BIT(5) | BIT(6)));
62 ledcfg
= rtl_read_byte(rtlpriv
, REG_MAC_PINMUX_CFG
);
63 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
,
66 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
67 (ledcfg
| BIT(3) | BIT(5) | BIT(6)));
70 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
72 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, (ledcfg
| BIT(3)));
75 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
76 "switch case %#x not processed\n", pled
->ledpin
);
82 void rtl88ee_init_sw_leds(struct ieee80211_hw
*hw
)
84 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
86 _rtl88ee_init_led(hw
, &rtlpriv
->ledctl
.sw_led0
, LED_PIN_LED0
);
87 _rtl88ee_init_led(hw
, &rtlpriv
->ledctl
.sw_led1
, LED_PIN_LED1
);
90 static void _rtl88ee_sw_led_control(struct ieee80211_hw
*hw
,
91 enum led_ctl_mode ledaction
)
93 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
94 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
97 case LED_CTL_POWER_ON
:
100 rtl88ee_sw_led_on(hw
, pled0
);
102 case LED_CTL_POWER_OFF
:
103 rtl88ee_sw_led_off(hw
, pled0
);
110 void rtl88ee_led_control(struct ieee80211_hw
*hw
,
111 enum led_ctl_mode ledaction
)
113 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
114 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
116 if ((ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
) &&
117 (ledaction
== LED_CTL_TX
||
118 ledaction
== LED_CTL_RX
||
119 ledaction
== LED_CTL_SITE_SURVEY
||
120 ledaction
== LED_CTL_LINK
||
121 ledaction
== LED_CTL_NO_LINK
||
122 ledaction
== LED_CTL_START_TO_LINK
||
123 ledaction
== LED_CTL_POWER_ON
)) {
126 RT_TRACE(rtlpriv
, COMP_LED
, DBG_TRACE
, "ledaction %d,\n",
128 _rtl88ee_sw_led_control(hw
, ledaction
);