1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
31 static void _rtl8821ae_init_led(struct ieee80211_hw
*hw
,
33 enum rtl_led_pin ledpin
)
36 pled
->ledpin
= ledpin
;
40 void rtl8821ae_sw_led_on(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
43 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
45 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
46 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2
, pled
->ledpin
);
48 switch (pled
->ledpin
) {
52 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
54 rtl_write_byte(rtlpriv
,
55 REG_LEDCFG2
, (ledcfg
& 0xf0) | BIT(5));
58 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
59 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
& 0x10);
62 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
63 "switch case %#x not processed\n", pled
->ledpin
);
69 void rtl8812ae_sw_led_on(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
71 u16 ledreg
= REG_LEDCFG1
;
73 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
75 switch (pled
->ledpin
) {
89 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
90 "In SwLedOn, LedAddr:%X LEDPIN=%d\n",
91 ledreg
, pled
->ledpin
);
93 ledcfg
= rtl_read_byte(rtlpriv
, ledreg
);
94 ledcfg
|= BIT(5); /*Set 0x4c[21]*/
95 ledcfg
&= ~(BIT(7) | BIT(6) | BIT(3) | BIT(2) | BIT(1) | BIT(0));
96 /*Clear 0x4c[23:22] and 0x4c[19:16]*/
97 rtl_write_byte(rtlpriv
, ledreg
, ledcfg
); /*SW control led0 on.*/
101 void rtl8821ae_sw_led_off(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
103 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
106 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
107 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2
, pled
->ledpin
);
109 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
111 switch (pled
->ledpin
) {
116 if (rtlpriv
->ledctl
.led_opendrain
) {
117 ledcfg
&= 0x90; /* Set to software control. */
118 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
|BIT(3)));
119 ledcfg
= rtl_read_byte(rtlpriv
, REG_MAC_PINMUX_CFG
);
121 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
, ledcfg
);
124 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
125 (ledcfg
| BIT(3) | BIT(5)));
129 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
130 ledcfg
&= 0x10; /* Set to software control. */
131 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
|BIT(3));
134 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
135 "switch case %#x not processed\n", pled
->ledpin
);
141 void rtl8812ae_sw_led_off(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
143 u16 ledreg
= REG_LEDCFG1
;
144 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
146 switch (pled
->ledpin
) {
148 ledreg
= REG_LEDCFG1
;
152 ledreg
= REG_LEDCFG2
;
160 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
161 "In SwLedOff,LedAddr:%X LEDPIN=%d\n",
162 ledreg
, pled
->ledpin
);
163 /*Open-drain arrangement for controlling the LED*/
164 if (rtlpriv
->ledctl
.led_opendrain
) {
165 u8 ledcfg
= rtl_read_byte(rtlpriv
, ledreg
);
167 ledreg
&= 0xd0; /* Set to software control.*/
168 rtl_write_byte(rtlpriv
, ledreg
, (ledcfg
| BIT(3)));
170 /*Open-drain arrangement*/
171 ledcfg
= rtl_read_byte(rtlpriv
, REG_MAC_PINMUX_CFG
);
172 ledcfg
&= 0xFE;/*Set GPIO[8] to input mode*/
173 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
, ledcfg
);
175 rtl_write_byte(rtlpriv
, ledreg
, 0x28);
181 void rtl8821ae_init_sw_leds(struct ieee80211_hw
*hw
)
183 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
185 _rtl8821ae_init_led(hw
, &rtlpriv
->ledctl
.sw_led0
, LED_PIN_LED0
);
186 _rtl8821ae_init_led(hw
, &rtlpriv
->ledctl
.sw_led1
, LED_PIN_LED1
);
189 static void _rtl8821ae_sw_led_control(struct ieee80211_hw
*hw
,
190 enum led_ctl_mode ledaction
)
192 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
193 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
194 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
197 case LED_CTL_POWER_ON
:
199 case LED_CTL_NO_LINK
:
200 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
201 rtl8812ae_sw_led_on(hw
, pled0
);
203 rtl8821ae_sw_led_on(hw
, pled0
);
205 case LED_CTL_POWER_OFF
:
206 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
207 rtl8812ae_sw_led_off(hw
, pled0
);
209 rtl8821ae_sw_led_off(hw
, pled0
);
216 void rtl8821ae_led_control(struct ieee80211_hw
*hw
,
217 enum led_ctl_mode ledaction
)
219 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
220 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
222 if ((ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
) &&
223 (ledaction
== LED_CTL_TX
||
224 ledaction
== LED_CTL_RX
||
225 ledaction
== LED_CTL_SITE_SURVEY
||
226 ledaction
== LED_CTL_LINK
||
227 ledaction
== LED_CTL_NO_LINK
||
228 ledaction
== LED_CTL_START_TO_LINK
||
229 ledaction
== LED_CTL_POWER_ON
)) {
232 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "ledaction %d,\n",
234 _rtl8821ae_sw_led_control(hw
, ledaction
);