Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[linux-2.6.git] / drivers / net / wireless / rtlwifi / rtl8192se / led.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2010  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
35 static void _rtl92se_init_led(struct ieee80211_hw *hw,
36                               struct rtl_led *pled, enum rtl_led_pin ledpin)
37 {
38         pled->hw = hw;
39         pled->ledpin = ledpin;
40         pled->ledon = false;
41 }
42
43 void rtl92se_init_sw_leds(struct ieee80211_hw *hw)
44 {
45         struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
46         _rtl92se_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
47         _rtl92se_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
48 }
49
50 void rtl92se_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
51 {
52         u8 ledcfg;
53         struct rtl_priv *rtlpriv = rtl_priv(hw);
54
55         RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
56                  ("LedAddr:%X ledpin=%d\n", LEDCFG, pled->ledpin));
57
58         ledcfg = rtl_read_byte(rtlpriv, LEDCFG);
59
60         switch (pled->ledpin) {
61         case LED_PIN_GPIO0:
62                 break;
63         case LED_PIN_LED0:
64                 rtl_write_byte(rtlpriv, LEDCFG, ledcfg & 0xf0);
65                 break;
66         case LED_PIN_LED1:
67                 rtl_write_byte(rtlpriv, LEDCFG, ledcfg & 0x0f);
68                 break;
69         default:
70                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
71                          ("switch case not process\n"));
72                 break;
73         }
74         pled->ledon = true;
75 }
76
77 void rtl92se_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
78 {
79         struct rtl_priv *rtlpriv = rtl_priv(hw);
80         struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
81         u8 ledcfg;
82
83         RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
84                  ("LedAddr:%X ledpin=%d\n", LEDCFG, pled->ledpin));
85
86         ledcfg = rtl_read_byte(rtlpriv, LEDCFG);
87
88         switch (pled->ledpin) {
89         case LED_PIN_GPIO0:
90                 break;
91         case LED_PIN_LED0:
92                 ledcfg &= 0xf0;
93                 if (pcipriv->ledctl.led_opendrain)
94                         rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(1)));
95                 else
96                         rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(3)));
97                 break;
98         case LED_PIN_LED1:
99                 ledcfg &= 0x0f;
100                 rtl_write_byte(rtlpriv, LEDCFG, (ledcfg | BIT(3)));
101                 break;
102         default:
103                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
104                          ("switch case not process\n"));
105                 break;
106         }
107         pled->ledon = false;
108 }
109
110 static void _rtl92se_sw_led_control(struct ieee80211_hw *hw,
111                                     enum led_ctl_mode ledaction)
112 {
113         struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
114         struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
115         switch (ledaction) {
116         case LED_CTL_POWER_ON:
117         case LED_CTL_LINK:
118         case LED_CTL_NO_LINK:
119                 rtl92se_sw_led_on(hw, pLed0);
120                 break;
121         case LED_CTL_POWER_OFF:
122                 rtl92se_sw_led_off(hw, pLed0);
123                 break;
124         default:
125                 break;
126         }
127 }
128
129 void rtl92se_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
130 {
131         struct rtl_priv *rtlpriv = rtl_priv(hw);
132         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
133
134         if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
135             (ledaction == LED_CTL_TX ||
136             ledaction == LED_CTL_RX ||
137             ledaction == LED_CTL_SITE_SURVEY ||
138             ledaction == LED_CTL_LINK ||
139             ledaction == LED_CTL_NO_LINK ||
140             ledaction == LED_CTL_START_TO_LINK ||
141             ledaction == LED_CTL_POWER_ON)) {
142                 return;
143         }
144         RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, ("ledaction %d,\n",
145                  ledaction));
146
147         _rtl92se_sw_led_control(hw, ledaction);
148 }
149