Merge branch 'overlayfs-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszer...
[deliverable/linux.git] / drivers / net / wireless / realtek / rtlwifi / rtl8723ae / led.c
CommitLineData
c592e631
LF
1/******************************************************************************
2 *
3 * Copyright(c) 2009-2012 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
30#include "../wifi.h"
31#include "../pci.h"
32#include "reg.h"
33#include "led.h"
34
0529c6b8
LF
35static void _rtl8723e_init_led(struct ieee80211_hw *hw,
36 struct rtl_led *pled, enum rtl_led_pin ledpin)
c592e631
LF
37{
38 pled->hw = hw;
39 pled->ledpin = ledpin;
40 pled->ledon = false;
41}
42
0529c6b8 43void rtl8723e_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
c592e631 44{
c592e631 45 u8 ledcfg;
0529c6b8 46 struct rtl_priv *rtlpriv = rtl_priv(hw);
c592e631
LF
47
48 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
49 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
50
c592e631
LF
51 switch (pled->ledpin) {
52 case LED_PIN_GPIO0:
53 break;
54 case LED_PIN_LED0:
0529c6b8 55 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
e6deaf81 56 ledcfg &= ~BIT(6);
c592e631 57 rtl_write_byte(rtlpriv,
e6deaf81 58 REG_LEDCFG2, (ledcfg & 0xf0) | BIT(5));
c592e631
LF
59 break;
60 case LED_PIN_LED1:
0529c6b8
LF
61 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
62 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg & 0x10);
c592e631
LF
63 break;
64 default:
65 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
0529c6b8 66 "switch case not process\n");
c592e631
LF
67 break;
68 }
69 pled->ledon = true;
70}
71
0529c6b8 72void rtl8723e_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
c592e631
LF
73{
74 struct rtl_priv *rtlpriv = rtl_priv(hw);
75 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
76 u8 ledcfg;
77
78 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
79 "LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin);
80
81 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
82
83 switch (pled->ledpin) {
84 case LED_PIN_GPIO0:
85 break;
86 case LED_PIN_LED0:
87 ledcfg &= 0xf0;
e6deaf81 88 if (pcipriv->ledctl.led_opendrain) {
0529c6b8 89 ledcfg &= 0x90; /* Set to software control. */
e6deaf81
LF
90 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg|BIT(3)));
91 ledcfg = rtl_read_byte(rtlpriv, REG_MAC_PINMUX_CFG);
92 ledcfg &= 0xFE;
93 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, ledcfg);
94 } else {
95 ledcfg &= ~BIT(6);
c592e631 96 rtl_write_byte(rtlpriv, REG_LEDCFG2,
0529c6b8 97 (ledcfg | BIT(3) | BIT(5)));
e6deaf81 98 }
c592e631
LF
99 break;
100 case LED_PIN_LED1:
0529c6b8
LF
101 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
102 ledcfg &= 0x10; /* Set to software control. */
103 rtl_write_byte(rtlpriv, REG_LEDCFG1, ledcfg|BIT(3));
104
c592e631
LF
105 break;
106 default:
107 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
0529c6b8 108 "switch case not process\n");
c592e631
LF
109 break;
110 }
111 pled->ledon = false;
112}
113
0529c6b8 114void rtl8723e_init_sw_leds(struct ieee80211_hw *hw)
c592e631
LF
115{
116 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
0529c6b8
LF
117 _rtl8723e_init_led(hw, &pcipriv->ledctl.sw_led0, LED_PIN_LED0);
118 _rtl8723e_init_led(hw, &pcipriv->ledctl.sw_led1, LED_PIN_LED1);
c592e631
LF
119}
120
0529c6b8
LF
121static void _rtl8723e_sw_led_control(struct ieee80211_hw *hw,
122 enum led_ctl_mode ledaction)
c592e631
LF
123{
124 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
125 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
c592e631
LF
126 switch (ledaction) {
127 case LED_CTL_POWER_ON:
128 case LED_CTL_LINK:
129 case LED_CTL_NO_LINK:
0529c6b8 130 rtl8723e_sw_led_on(hw, pLed0);
c592e631
LF
131 break;
132 case LED_CTL_POWER_OFF:
0529c6b8 133 rtl8723e_sw_led_off(hw, pLed0);
c592e631
LF
134 break;
135 default:
136 break;
137 }
138}
139
0529c6b8
LF
140void rtl8723e_led_control(struct ieee80211_hw *hw,
141 enum led_ctl_mode ledaction)
c592e631
LF
142{
143 struct rtl_priv *rtlpriv = rtl_priv(hw);
144 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
145
146 if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
147 (ledaction == LED_CTL_TX ||
148 ledaction == LED_CTL_RX ||
149 ledaction == LED_CTL_SITE_SURVEY ||
150 ledaction == LED_CTL_LINK ||
151 ledaction == LED_CTL_NO_LINK ||
152 ledaction == LED_CTL_START_TO_LINK ||
153 ledaction == LED_CTL_POWER_ON)) {
154 return;
155 }
0529c6b8
LF
156 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, "ledaction %d,\n",
157 ledaction);
158 _rtl8723e_sw_led_control(hw, ledaction);
c592e631 159}
This page took 0.237624 seconds and 5 git commands to generate.