blob: b504bd092fc4b36e62416a6cf6dedba94b9230f3 [file] [log] [blame]
Larry Fingerf0eb8562013-03-24 22:06:42 -05001/******************************************************************************
2 *
3 * Copyright(c) 2009-2013 Realtek Corporation.
4 *
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.
8 *
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
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
28 *****************************************************************************/
29
Chen, Chien-Chia2a2ac752013-04-02 22:01:55 +080030#include "../wifi.h"
31#include "../pci.h"
Larry Fingerf0eb8562013-03-24 22:06:42 -050032#include "reg.h"
33#include "led.h"
34
Larry Fingerc151aed2014-09-22 09:39:25 -050035static void _rtl88ee_init_led(struct ieee80211_hw *hw,
36 struct rtl_led *pled, enum rtl_led_pin ledpin)
Larry Fingerf0eb8562013-03-24 22:06:42 -050037{
38 pled->hw = hw;
39 pled->ledpin = ledpin;
40 pled->ledon = false;
41}
42
43void rtl88ee_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
44{
45 u8 ledcfg;
46 struct rtl_priv *rtlpriv = rtl_priv(hw);
47
48 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
Larry Fingerc151aed2014-09-22 09:39:25 -050049 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
Larry Fingerf0eb8562013-03-24 22:06:42 -050050
51 switch (pled->ledpin) {
52 case LED_PIN_GPIO0:
53 break;
54 case LED_PIN_LED0:
55 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
Larry Fingerc151aed2014-09-22 09:39:25 -050056 rtl_write_byte(rtlpriv,
57 REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5) | BIT(6));
Larry Fingerf0eb8562013-03-24 22:06:42 -050058 break;
59 case LED_PIN_LED1:
60 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
61 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
62 break;
63 default:
Larry Fingerc151aed2014-09-22 09:39:25 -050064 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
65 "switch case not process\n");
Larry Fingerf0eb8562013-03-24 22:06:42 -050066 break;
67 }
68 pled->ledon = true;
69}
70
71void rtl88ee_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
72{
73 struct rtl_priv *rtlpriv = rtl_priv(hw);
74 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
75 u8 ledcfg;
Larry Fingerf0eb8562013-03-24 22:06:42 -050076
77 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
Larry Fingerc151aed2014-09-22 09:39:25 -050078 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
Larry Fingerf0eb8562013-03-24 22:06:42 -050079
80 switch (pled->ledpin) {
81 case LED_PIN_GPIO0:
82 break;
83 case LED_PIN_LED0:
84 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
85 ledcfg &= 0xf0;
Larry Fingerc151aed2014-09-22 09:39:25 -050086 if (pcipriv->ledctl.led_opendrain) {
87 rtl_write_byte(rtlpriv, REG_LEDCFG2,
88 (ledcfg | BIT(3) | BIT(5) | BIT(6)));
Larry Fingerf0eb8562013-03-24 22:06:42 -050089 ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
Larry Fingerc151aed2014-09-22 09:39:25 -050090 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG,
91 (ledcfg & 0xFE));
92 } else
93 rtl_write_byte(rtlpriv, REG_LEDCFG2,
94 (ledcfg | BIT(3) | BIT(5) | BIT(6)));
Larry Fingerf0eb8562013-03-24 22:06:42 -050095 break;
96 case LED_PIN_LED1:
97 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
98 ledcfg &= 0x10;
99 rtl_write_byte(rtlpriv, REG_LEDCFG1, (ledcfg | BIT(3)));
100 break;
101 default:
Larry Fingerc151aed2014-09-22 09:39:25 -0500102 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
103 "switch case not process\n");
Larry Fingerf0eb8562013-03-24 22:06:42 -0500104 break;
105 }
106 pled->ledon = false;
107}
108
109void rtl88ee_init_sw_leds(struct ieee80211_hw *hw)
110{
111 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
Larry Fingerc151aed2014-09-22 09:39:25 -0500112 _rtl88ee_init_led(hw, &pcipriv->ledctl.sw_led0, LED_PIN_LED0);
113 _rtl88ee_init_led(hw, &pcipriv->ledctl.sw_led1, LED_PIN_LED1);
Larry Fingerf0eb8562013-03-24 22:06:42 -0500114}
115
Larry Fingerc151aed2014-09-22 09:39:25 -0500116static void _rtl88ee_sw_led_control(struct ieee80211_hw *hw,
Larry Fingerf0eb8562013-03-24 22:06:42 -0500117 enum led_ctl_mode ledaction)
118{
119 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
120 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
Larry Fingerf0eb8562013-03-24 22:06:42 -0500121 switch (ledaction) {
122 case LED_CTL_POWER_ON:
123 case LED_CTL_LINK:
124 case LED_CTL_NO_LINK:
125 rtl88ee_sw_led_on(hw, pLed0);
126 break;
127 case LED_CTL_POWER_OFF:
128 rtl88ee_sw_led_off(hw, pLed0);
129 break;
130 default:
131 break;
132 }
133}
134
135void rtl88ee_led_control(struct ieee80211_hw *hw,
136 enum led_ctl_mode ledaction)
137{
138 struct rtl_priv *rtlpriv = rtl_priv(hw);
139 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
140
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)) {
149 return;
150 }
151 RT_TRACE(rtlpriv, COMP_LED, DBG_TRACE, "ledaction %d,\n",
Larry Fingerc151aed2014-09-22 09:39:25 -0500152 ledaction);
153 _rtl88ee_sw_led_control(hw, ledaction);
Larry Fingerf0eb8562013-03-24 22:06:42 -0500154}