~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to ubuntu/rtl8192se/rtl_rfkill.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************************
2
 
 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms of version 2 of the GNU General Public License as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11
 
 * more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along with
14
 
 * this program; if not, write to the Free Software Foundation, Inc.,
15
 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
16
 
 *
17
 
 * The full GNU General Public License is included in this distribution in the
18
 
 * file called LICENSE.
19
 
 *
20
 
 * Contact Information:
21
 
 * wlanfae <wlanfae@realtek.com>
22
 
 ******************************************************************************/
23
 
#include "rtl_core.h"
24
 
#include "rtl_dm.h"
25
 
#include "rtl_rfkill.h"
26
 
 
27
 
#ifdef CONFIG_RTL_RFKILL
28
 
static void rtl8192_before_radio_check(struct net_device *dev, 
29
 
                                       bool *rf_state, 
30
 
                                       bool *turnonbypowerdomain)
31
 
{  
32
 
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
33
 
        PRT_POWER_SAVE_CONTROL   pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
34
 
 
35
 
        *rf_state = (priv->rtllib->eRFPowerState != eRfOn);     
36
 
#ifdef CONFIG_ASPM_OR_D3
37
 
        if((pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_ASPM) && RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_ASPM))
38
 
        {
39
 
                RT_DISABLE_ASPM(dev);
40
 
                RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_ASPM);
41
 
        }
42
 
        else if((pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_PCI_D3) && RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_PCI_D3))
43
 
        {
44
 
#ifdef TODO             
45
 
                RT_LEAVE_D3(dev, false);
46
 
                RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_PCI_D3);
47
 
#endif
48
 
        }
49
 
#endif  
50
 
        if (RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC)) {
51
 
                Power_DomainInit92SE(dev);
52
 
                *turnonbypowerdomain = true;
53
 
        }
54
 
 
55
 
}
56
 
 
57
 
static bool rtl8192_radio_on_off_checking(struct net_device *dev)
58
 
{
59
 
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
60
 
        u8      u1Tmp = 0;
61
 
        u8      gpio;
62
 
        
63
 
        if (priv->pwrdown) {
64
 
                u1Tmp = read_nic_byte(dev, 0x06);
65
 
                gpio = u1Tmp & BIT6;
66
 
        } else  
67
 
#ifdef CONFIG_BT_COEXIST
68
 
        if (pHalData->bt_coexist.BluetoothCoexist) {
69
 
                if (pHalData->bt_coexist.BT_CoexistType == BT_2Wire) {
70
 
                        PlatformEFIOWrite1Byte(pAdapter, MAC_PINMUX_CFG, 0xa);
71
 
                        u1Tmp = PlatformEFIORead1Byte(pAdapter, GPIO_IO_SEL);
72
 
                        delay_us(100);
73
 
                        u1Tmp = PlatformEFIORead1Byte(pAdapter, GPIO_IN);
74
 
                        RTPRINT(FPWR, PWRHW, ("GPIO_IN=%02x\n", u1Tmp));
75
 
                        retval = (u1Tmp & HAL_8192S_HW_GPIO_OFF_BIT) ? eRfOn : eRfOff;
76
 
                } else if ((pHalData->bt_coexist.BT_CoexistType == BT_ISSC_3Wire) ||
77
 
                                (pHalData->bt_coexist.BT_CoexistType == BT_Accel) ||
78
 
                                (pHalData->bt_coexist.BT_CoexistType == BT_CSR)) {
79
 
                        u4tmp = PHY_QueryBBReg(pAdapter, 0x87c, bMaskDWord);
80
 
                        if ((u4tmp & BIT17) != 0) {
81
 
                                PHY_SetBBReg(pAdapter, 0x87c, bMaskDWord, u4tmp & ~BIT17);
82
 
                                delay_us(50);
83
 
                                RTPRINT(FBT, BT_RFPoll, ("BT write 0x87c (~BIT17) = 0x%x\n", u4tmp &~BIT17));
84
 
                        }
85
 
                        u4tmp = PHY_QueryBBReg(pAdapter, 0x8e0, bMaskDWord);
86
 
                        RTPRINT(FBT, BT_RFPoll, ("BT read 0x8e0 (BIT24)= 0x%x\n", u4tmp));
87
 
                        retval = (u4tmp & BIT24) ? eRfOn : eRfOff;
88
 
                        RTPRINT(FBT, BT_RFPoll, ("BT check RF state to %s\n", (retval==eRfOn)? "ON":"OFF"));
89
 
                }
90
 
        } else 
91
 
#endif
92
 
        {
93
 
                write_nic_byte(dev, MAC_PINMUX_CFG, (GPIOMUX_EN | GPIOSEL_GPIO));
94
 
                u1Tmp = read_nic_byte(dev, GPIO_IO_SEL);
95
 
 
96
 
                u1Tmp &= HAL_8192S_HW_GPIO_OFF_MASK;
97
 
                write_nic_byte(dev, GPIO_IO_SEL, u1Tmp);
98
 
 
99
 
                mdelay(10);
100
 
 
101
 
                u1Tmp = read_nic_byte(dev, GPIO_IN);
102
 
                gpio = u1Tmp & HAL_8192S_HW_GPIO_OFF_BIT;
103
 
        }
104
 
#ifdef DEBUG_RFKILL 
105
 
        {
106
 
                static u8       gpio_test;
107
 
                printk("%s: gpio = %x\n", __FUNCTION__, gpio);
108
 
                if(gpio_test % 5 == 0) {
109
 
                        gpio = 0;
110
 
                } else {
111
 
                        gpio = 1;
112
 
                }
113
 
                printk("%s: gpio_test = %d, gpio = %x\n", __FUNCTION__, gpio_test++ % 20, gpio);
114
 
        }
115
 
#endif 
116
 
 
117
 
        return gpio;
118
 
}
119
 
 
120
 
static void  rtl8192_after_radio_check(struct net_device *dev, bool rf_state, bool turnonbypowerdomain)
121
 
{
122
 
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
123
 
        PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->rtllib->PowerSaveControl));
124
 
 
125
 
        if (turnonbypowerdomain) {
126
 
                PHY_SetRtl8192seRfHalt(dev);
127
 
                RT_SET_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
128
 
        }
129
 
#ifdef CONFIG_ASPM_OR_D3
130
 
        if (!rf_state) {
131
 
                if (pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_ASPM) {
132
 
                        RT_ENABLE_ASPM(dev);
133
 
                        RT_SET_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_ASPM);
134
 
                }
135
 
#ifdef TODO             
136
 
                else if(pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_PCI_D3) {
137
 
                        RT_ENTER_D3(dev, false);
138
 
                        RT_SET_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_PCI_D3);
139
 
                }
140
 
#endif
141
 
        }
142
 
#endif
143
 
        return;
144
 
}
145
 
 
146
 
static bool rtl8192_is_radio_enabled(struct net_device *dev, bool *radio_enabled)
147
 
{
148
 
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
149
 
        bool rf_state = false;
150
 
        bool turnonbypowerdomain = false;
151
 
        bool valid;
152
 
 
153
 
        rtl8192_before_radio_check(dev, &rf_state, &turnonbypowerdomain);
154
 
        *radio_enabled = rtl8192_radio_on_off_checking(dev);
155
 
        rtl8192_after_radio_check(dev, rf_state, turnonbypowerdomain);
156
 
        if (priv->bResetInProgress) {
157
 
                priv->RFChangeInProgress = false;
158
 
                valid = false;
159
 
        } else {
160
 
                valid = true;
161
 
        }
162
 
        
163
 
        return valid;
164
 
}
165
 
 
166
 
bool rtl8192_rfkill_init(struct net_device *dev)
167
 
{
168
 
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
169
 
        struct wireless_dev *wdev = &priv->rtllib->wdev;
170
 
        bool radio_enabled;
171
 
        bool valid = rtl8192_is_radio_enabled(dev, &radio_enabled);
172
 
 
173
 
        if (valid) {
174
 
                priv->rfkill_off = radio_enabled;
175
 
                printk(KERN_INFO "rtl8192: wireless switch is %s\n",
176
 
                                priv->rfkill_off ? "on" : "off");
177
 
                wiphy_rfkill_set_hw_state(wdev->wiphy, !priv->rfkill_off);
178
 
                wiphy_rfkill_start_polling(wdev->wiphy);
179
 
                return true;
180
 
        } else {
181
 
                return false;
182
 
        }
183
 
}
184
 
 
185
 
void rtl8192_rfkill_poll(struct net_device *dev)
186
 
{
187
 
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
188
 
        struct wireless_dev *wdev = &priv->rtllib->wdev;
189
 
        bool radio_enabled;
190
 
        bool valid;
191
 
        
192
 
        if (priv->being_init_adapter) {
193
 
                return;
194
 
        }
195
 
 
196
 
        if (priv->ResetProgress == RESET_TYPE_SILENT) {
197
 
                RT_TRACE((COMP_INIT | COMP_POWER | COMP_RF), 
198
 
                                "%s(): silent Reseting, ignore rf polling!\n", __FUNCTION__);
199
 
                return;
200
 
        }
201
 
 
202
 
        valid = rtl8192_is_radio_enabled(dev, &radio_enabled);
203
 
        if (valid) {
204
 
                if (unlikely(radio_enabled != priv->rfkill_off)) {
205
 
                        priv->rfkill_off = radio_enabled;
206
 
                        printk(KERN_INFO "rtl8192: wireless radio switch turned %s\n",
207
 
                                        radio_enabled ? "on" : "off");
208
 
                        wiphy_rfkill_set_hw_state(wdev->wiphy, !radio_enabled);
209
 
                }
210
 
        }
211
 
}
212
 
 
213
 
void rtl8192_rfkill_exit(struct net_device *dev)
214
 
{
215
 
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
216
 
        struct wireless_dev *wdev = &priv->rtllib->wdev;
217
 
 
218
 
        wiphy_rfkill_stop_polling(wdev->wiphy);
219
 
}
220
 
 
221
 
#endif