1 /******************************************************************************
3 * Copyright(c) 2009-2014 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 _rtl8723be_init_led(struct ieee80211_hw
*hw
, struct rtl_led
*pled
,
32 enum rtl_led_pin ledpin
)
35 pled
->ledpin
= ledpin
;
39 void rtl8723be_sw_led_on(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
42 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
44 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
45 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2
, pled
->ledpin
);
47 switch (pled
->ledpin
) {
51 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
53 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
& 0xf0) | BIT(5));
56 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
57 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
& 0x10);
60 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
61 "switch case not process\n");
67 void rtl8723be_sw_led_off(struct ieee80211_hw
*hw
, struct rtl_led
*pled
)
69 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
70 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
73 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
,
74 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2
, pled
->ledpin
);
76 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG2
);
78 switch (pled
->ledpin
) {
83 if (pcipriv
->ledctl
.led_opendrain
) {
84 ledcfg
&= 0x90; /* Set to software control. */
85 rtl_write_byte(rtlpriv
, REG_LEDCFG2
, (ledcfg
|BIT(3)));
86 ledcfg
= rtl_read_byte(rtlpriv
, REG_MAC_PINMUX_CFG
);
88 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
, ledcfg
);
91 rtl_write_byte(rtlpriv
, REG_LEDCFG2
,
92 (ledcfg
| BIT(3) | BIT(5)));
96 ledcfg
= rtl_read_byte(rtlpriv
, REG_LEDCFG1
);
97 ledcfg
&= 0x10; /* Set to software control. */
98 rtl_write_byte(rtlpriv
, REG_LEDCFG1
, ledcfg
|BIT(3));
102 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
103 "switch case not process\n");
109 void rtl8723be_init_sw_leds(struct ieee80211_hw
*hw
)
111 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
112 _rtl8723be_init_led(hw
, &(pcipriv
->ledctl
.sw_led0
), LED_PIN_LED0
);
113 _rtl8723be_init_led(hw
, &(pcipriv
->ledctl
.sw_led1
), LED_PIN_LED1
);
116 static void _rtl8723be_sw_led_control(struct ieee80211_hw
*hw
,
117 enum led_ctl_mode ledaction
)
119 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
120 struct rtl_led
*pled0
= &(pcipriv
->ledctl
.sw_led0
);
122 case LED_CTL_POWER_ON
:
124 case LED_CTL_NO_LINK
:
125 rtl8723be_sw_led_on(hw
, pled0
);
127 case LED_CTL_POWER_OFF
:
128 rtl8723be_sw_led_off(hw
, pled0
);
135 void rtl8723be_led_control(struct ieee80211_hw
*hw
,
136 enum led_ctl_mode ledaction
)
138 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
139 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
141 if ((ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
) &&
142 (ledaction
== LED_CTL_TX
||
143 ledaction
== LED_CTL_RX
||
144 ledaction
== LED_CTL_SITE_SURVEY
||
145 ledaction
== LED_CTL_LINK
||
146 ledaction
== LED_CTL_NO_LINK
||
147 ledaction
== LED_CTL_START_TO_LINK
||
148 ledaction
== LED_CTL_POWER_ON
)) {
151 RT_TRACE(rtlpriv
, COMP_LED
, DBG_LOUD
, "ledaction %d,\n", ledaction
);
152 _rtl8723be_sw_led_control(hw
, ledaction
);