include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / net / wireless / rtlwifi / rtl8192de / led.c
blobf1552f4df65805aea48848d402c6d71e2188395a
1 /******************************************************************************
3 * Copyright(c) 2009-2010 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
12 * more details.
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
30 #include "../wifi.h"
31 #include "../pci.h"
32 #include "reg.h"
33 #include "led.h"
35 static void _rtl92ce_init_led(struct ieee80211_hw *hw,
36 struct rtl_led *pled, enum rtl_led_pin ledpin)
38 pled->hw = hw;
39 pled->ledpin = ledpin;
40 pled->ledon = false;
43 void rtl92de_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled)
45 u8 ledcfg;
46 struct rtl_priv *rtlpriv = rtl_priv(hw);
48 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
49 ("LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin));
51 switch (pled->ledpin) {
52 case LED_PIN_GPIO0:
53 break;
54 case LED_PIN_LED0:
55 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
57 if ((rtlpriv->efuse.eeprom_did == 0x8176) ||
58 (rtlpriv->efuse.eeprom_did == 0x8193))
59 /* BIT7 of REG_LEDCFG2 should be set to
60 * make sure we could emit the led2. */
61 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) |
62 BIT(7) | BIT(5) | BIT(6));
63 else
64 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0xf0) |
65 BIT(7) | BIT(5));
66 break;
67 case LED_PIN_LED1:
68 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG1);
70 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg & 0x0f) | BIT(5));
71 break;
72 default:
73 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
74 ("switch case not process\n"));
75 break;
77 pled->ledon = true;
80 void rtl92de_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
82 struct rtl_priv *rtlpriv = rtl_priv(hw);
83 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
84 u8 ledcfg;
86 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD,
87 ("LedAddr:%X ledpin=%d\n", REG_LEDCFG2, pled->ledpin));
89 ledcfg = rtl_read_byte(rtlpriv, REG_LEDCFG2);
91 switch (pled->ledpin) {
92 case LED_PIN_GPIO0:
93 break;
94 case LED_PIN_LED0:
95 ledcfg &= 0xf0;
96 if (pcipriv->ledctl.led_opendrain)
97 rtl_write_byte(rtlpriv, REG_LEDCFG2,
98 (ledcfg | BIT(1) | BIT(5) | BIT(6)));
99 else
100 rtl_write_byte(rtlpriv, REG_LEDCFG2,
101 (ledcfg | BIT(3) | BIT(5) | BIT(6)));
102 break;
103 case LED_PIN_LED1:
104 ledcfg &= 0x0f;
105 rtl_write_byte(rtlpriv, REG_LEDCFG2, (ledcfg | BIT(3)));
106 break;
107 default:
108 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
109 ("switch case not process\n"));
110 break;
112 pled->ledon = false;
115 void rtl92de_init_sw_leds(struct ieee80211_hw *hw)
117 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
118 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
119 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
122 static void _rtl92ce_sw_led_control(struct ieee80211_hw *hw,
123 enum led_ctl_mode ledaction)
125 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
126 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
127 switch (ledaction) {
128 case LED_CTL_POWER_ON:
129 case LED_CTL_LINK:
130 case LED_CTL_NO_LINK:
131 rtl92de_sw_led_on(hw, pLed0);
132 break;
133 case LED_CTL_POWER_OFF:
134 rtl92de_sw_led_off(hw, pLed0);
135 break;
136 default:
137 break;
141 void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
143 struct rtl_priv *rtlpriv = rtl_priv(hw);
144 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
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;
156 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, ("ledaction %d,\n", ledaction));
158 _rtl92ce_sw_led_control(hw, ledaction);