Linux-libre 3.16.85-gnu
[librecmc/linux-libre.git] / drivers / staging / rtl8192ee / rtl8192ee / 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  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25
26 #include "../wifi.h"
27 #include "../pci.h"
28 #include "led.h"
29 #include "reg.h"
30
31 static void _rtl92ee_init_led(struct ieee80211_hw *hw,
32                               struct rtl_led *pled, enum rtl_led_pin ledpin)
33 {
34         pled->hw = hw;
35         pled->ledpin = ledpin;
36         pled->b_ledon = false;
37 }
38
39 void rtl92ee_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
40 {
41         u32 ledcfg;
42         struct rtl_priv *rtlpriv = rtl_priv(hw);
43
44         RT_TRACE(COMP_LED, DBG_LOUD,
45                  ("LedAddr:%X ledpin =%d\n", REG_LEDCFG2, pled->ledpin));
46
47         switch (pled->ledpin) {
48         case LED_PIN_GPIO0:
49                 break;
50         case LED_PIN_LED0:
51                 ledcfg = rtl_read_dword(rtlpriv, REG_GPIO_PIN_CTRL) | BIT(21);
52                 ledcfg &= ~BIT(13) & ~BIT(29);
53                 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
54                 break;
55         case LED_PIN_LED1:
56                 break;
57         default:
58                 RT_TRACE(COMP_ERR, DBG_EMERG,
59                          ("switch case not process\n"));
60                 break;
61         }
62         pled->b_ledon = true;
63 }
64
65 void rtl92ee_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
66 {
67         struct rtl_priv *rtlpriv = rtl_priv(hw);
68         u32 ledcfg;
69
70         RT_TRACE(COMP_LED, DBG_LOUD,
71                  ("LedAddr:%X ledpin =%d\n", REG_LEDCFG2, pled->ledpin));
72
73         switch (pled->ledpin) {
74         case LED_PIN_GPIO0:
75                 break;
76         case LED_PIN_LED0:
77                 ledcfg = rtl_read_dword(rtlpriv , REG_GPIO_PIN_CTRL) | ~BIT(21);
78                 ledcfg &= ~BIT(29);
79                 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, ledcfg);
80                 break;
81         case LED_PIN_LED1:
82                 break;
83         default:
84                 RT_TRACE(COMP_ERR, DBG_LOUD,
85                          ("switch case not process\n"));
86                 break;
87         }
88         pled->b_ledon = false;
89 }
90
91 void rtl92ee_init_sw_leds(struct ieee80211_hw *hw)
92 {
93         struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
94         _rtl92ee_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
95         _rtl92ee_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
96 }
97
98 static void _rtl92ee_sw_led_control(struct ieee80211_hw *hw,
99                                     enum led_ctl_mode ledaction)
100 {
101         struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
102         struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
103         switch (ledaction) {
104         case LED_CTL_POWER_ON:
105         case LED_CTL_LINK:
106         case LED_CTL_NO_LINK:
107                 rtl92ee_sw_led_on(hw, pLed0);
108                 break;
109         case LED_CTL_POWER_OFF:
110                 rtl92ee_sw_led_off(hw, pLed0);
111                 break;
112         default:
113                 break;
114         }
115 }
116
117 void rtl92ee_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
118 {
119         struct rtl_priv *rtlpriv = rtl_priv(hw);
120         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
121
122         if ((ppsc->rfoff_reason > RF_CHANGE_BY_PS) &&
123             (ledaction == LED_CTL_TX ||
124              ledaction == LED_CTL_RX ||
125              ledaction == LED_CTL_SITE_SURVEY ||
126              ledaction == LED_CTL_LINK ||
127              ledaction == LED_CTL_NO_LINK ||
128              ledaction == LED_CTL_START_TO_LINK ||
129              ledaction == LED_CTL_POWER_ON)) {
130                 return;
131         }
132         RT_TRACE(COMP_LED, DBG_TRACE, ("ledaction %d,\n", ledaction));
133         _rtl92ee_sw_led_control(hw, ledaction);
134 }