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 not process\n");
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
);
104 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
107 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
108 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2
, pled
->ledpin
);
110 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
112 switch (pled
->ledpin
) {
117 if (pcipriv
->ledctl
.led_opendrain
) {
118 ledcfg
&= 0x90; /* Set to software control. */
119 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
|BIT(3)));
120 ledcfg
= rtl_read_byte(rtlpriv
, REG_MAC_PINMUX_CFG
);
122 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
, ledcfg
);
125 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
126 (ledcfg
| BIT(3) | BIT(5)));
130 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
131 ledcfg
&= 0x10; /* Set to software control. */
132 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
|BIT(3));
135 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
136 "switch case not process\n");
142 void rtl8812ae_sw_led_off(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
144 u16 ledreg
= REG_LEDCFG1
;
145 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
146 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
148 switch (pled
->ledpin
) {
150 ledreg
= REG_LEDCFG1
;
154 ledreg
= REG_LEDCFG2
;
162 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
163 "In SwLedOff,LedAddr:%X LEDPIN=%d\n",
164 ledreg
, pled
->ledpin
);
165 /*Open-drain arrangement for controlling the LED*/
166 if (pcipriv
->ledctl
.led_opendrain
) {
167 u8 ledcfg
= rtl_read_byte(rtlpriv
, ledreg
);
169 ledreg
&= 0xd0; /* Set to software control.*/
170 rtl_write_byte(rtlpriv
, ledreg
, (ledcfg
| BIT(3)));
172 /*Open-drain arrangement*/
173 ledcfg
= rtl_read_byte(rtlpriv
, REG_MAC_PINMUX_CFG
);
174 ledcfg
&= 0xFE;/*Set GPIO[8] to input mode*/
175 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
, ledcfg
);
177 rtl_write_byte(rtlpriv
, ledreg
, 0x28);
183 void rtl8821ae_init_sw_leds(struct ieee80211_hw
*hw
)
185 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
187 _rtl8821ae_init_led(hw
, &pcipriv
->ledctl
.sw_led0
, LED_PIN_LED0
);
188 _rtl8821ae_init_led(hw
, &pcipriv
->ledctl
.sw_led1
, LED_PIN_LED1
);
191 static void _rtl8821ae_sw_led_control(struct ieee80211_hw
*hw
,
192 enum led_ctl_mode ledaction
)
194 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
195 struct rtl_led
*pLed0
= &pcipriv
->ledctl
.sw_led0
;
196 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
199 case LED_CTL_POWER_ON
:
201 case LED_CTL_NO_LINK
:
202 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
203 rtl8812ae_sw_led_on(hw
, pLed0
);
205 rtl8821ae_sw_led_on(hw
, pLed0
);
207 case LED_CTL_POWER_OFF
:
208 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
209 rtl8812ae_sw_led_off(hw
, pLed0
);
211 rtl8821ae_sw_led_off(hw
, pLed0
);
218 void rtl8821ae_led_control(struct ieee80211_hw
*hw
,
219 enum led_ctl_mode ledaction
)
221 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
222 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
224 if ((ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
) &&
225 (ledaction
== LED_CTL_TX
||
226 ledaction
== LED_CTL_RX
||
227 ledaction
== LED_CTL_SITE_SURVEY
||
228 ledaction
== LED_CTL_LINK
||
229 ledaction
== LED_CTL_NO_LINK
||
230 ledaction
== LED_CTL_START_TO_LINK
||
231 ledaction
== LED_CTL_POWER_ON
)) {
234 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "ledaction %d,\n",
236 _rtl8821ae_sw_led_control(hw
, ledaction
);