1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
9 static void _rtl92ce_init_led(struct ieee80211_hw
*hw
,
10 struct rtl_led
*pled
, enum rtl_led_pin ledpin
)
13 pled
->ledpin
= ledpin
;
17 void rtl92de_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
, "LedAddr:%X ledpin=%d\n",
23 REG_LEDCFG2
, pled
->ledpin
);
25 switch (pled
->ledpin
) {
29 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
31 if ((rtlpriv
->efuse
.eeprom_did
== 0x8176) ||
32 (rtlpriv
->efuse
.eeprom_did
== 0x8193))
33 /* BIT7 of REG_LEDCFG2 should be set to
34 * make sure we could emit the led2. */
35 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
& 0xf0) |
36 BIT(7) | BIT(5) | BIT(6));
38 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
& 0xf0) |
42 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
44 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
& 0x0f) | BIT(5));
47 pr_err("switch case %#x not processed\n",
54 void rtl92de_sw_led_off(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
56 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
59 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "LedAddr:%X ledpin=%d\n",
60 REG_LEDCFG2
, pled
->ledpin
);
62 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
64 switch (pled
->ledpin
) {
69 if (rtlpriv
->ledctl
.led_opendrain
)
70 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
71 (ledcfg
| BIT(1) | BIT(5) | BIT(6)));
73 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
74 (ledcfg
| BIT(3) | BIT(5) | BIT(6)));
78 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
| BIT(3)));
81 pr_err("switch case %#x not processed\n",
88 void rtl92de_init_sw_leds(struct ieee80211_hw
*hw
)
90 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
92 _rtl92ce_init_led(hw
, &rtlpriv
->ledctl
.sw_led0
, LED_PIN_LED0
);
93 _rtl92ce_init_led(hw
, &rtlpriv
->ledctl
.sw_led1
, LED_PIN_LED1
);
96 static void _rtl92ce_sw_led_control(struct ieee80211_hw
*hw
,
97 enum led_ctl_mode ledaction
)
99 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
100 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
103 case LED_CTL_POWER_ON
:
105 case LED_CTL_NO_LINK
:
106 rtl92de_sw_led_on(hw
, pled0
);
108 case LED_CTL_POWER_OFF
:
109 rtl92de_sw_led_off(hw
, pled0
);
116 void rtl92de_led_control(struct ieee80211_hw
*hw
, 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 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "ledaction %d,\n", ledaction
);
133 _rtl92ce_sw_led_control(hw
, ledaction
);