blob: 618841a53b9014f7dc5a92fa6da9b020086f9083 [file] [log] [blame]
Mohamed Abbasad97edd2008-03-28 16:21:06 -07001/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#include <linux/kernel.h>
29#include <linux/module.h>
Mohamed Abbasad97edd2008-03-28 16:21:06 -070030#include <linux/init.h>
31
32#include <net/mac80211.h>
33
34#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070035#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070036#include "iwl-core.h"
Mohamed Abbasad97edd2008-03-28 16:21:06 -070037#include "iwl-helpers.h"
38
39
Mohamed Abbasad97edd2008-03-28 16:21:06 -070040/* software rf-kill from user */
41static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
42{
43 struct iwl_priv *priv = data;
44 int err = 0;
45
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020046 if (!priv->rfkill)
Mohamed Abbasad97edd2008-03-28 16:21:06 -070047 return 0;
48
Mohamed Abbas59003832008-04-15 16:01:46 -070049 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
50 return 0;
51
John W. Linvilleedd4b532008-06-27 13:04:25 -040052 IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070053 mutex_lock(&priv->mutex);
54
55 switch (state) {
John W. Linvilleff28bd92008-06-27 10:27:47 -040056 case RFKILL_STATE_UNBLOCKED:
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020057 if (iwl_is_rfkill_hw(priv)) {
Mohamed Abbasad97edd2008-03-28 16:21:06 -070058 err = -EBUSY;
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020059 goto out_unlock;
60 }
61 iwl_radio_kill_sw_enable_radio(priv);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070062 break;
John W. Linvilleff28bd92008-06-27 10:27:47 -040063 case RFKILL_STATE_SOFT_BLOCKED:
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +080064 iwl_radio_kill_sw_disable_radio(priv);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070065 break;
John W. Linvilleff28bd92008-06-27 10:27:47 -040066 default:
Tomas Winklera96a27f2008-10-23 23:48:56 -070067 IWL_WARNING("we received unexpected RFKILL state %d\n", state);
John W. Linvilleff28bd92008-06-27 10:27:47 -040068 break;
Mohamed Abbasad97edd2008-03-28 16:21:06 -070069 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020070out_unlock:
Mohamed Abbasad97edd2008-03-28 16:21:06 -070071 mutex_unlock(&priv->mutex);
72
73 return err;
74}
75
76int iwl_rfkill_init(struct iwl_priv *priv)
77{
78 struct device *device = wiphy_dev(priv->hw->wiphy);
79 int ret = 0;
80
81 BUG_ON(device == NULL);
82
Mohamed Abbas03d29c62008-04-03 16:05:24 -070083 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020084 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
85 if (!priv->rfkill) {
Tomas Winklera96a27f2008-10-23 23:48:56 -070086 IWL_ERROR("Unable to allocate RFKILL device.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -070087 ret = -ENOMEM;
88 goto error;
89 }
90
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020091 priv->rfkill->name = priv->cfg->name;
92 priv->rfkill->data = priv;
93 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
94 priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
95 priv->rfkill->user_claim_unsupported = 1;
Mohamed Abbasad97edd2008-03-28 16:21:06 -070096
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020097 priv->rfkill->dev.class->suspend = NULL;
98 priv->rfkill->dev.class->resume = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -070099
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200100 ret = rfkill_register(priv->rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700101 if (ret) {
Tomas Winklera96a27f2008-10-23 23:48:56 -0700102 IWL_ERROR("Unable to register RFKILL: %d\n", ret);
Tomas Winkler8fa74252008-07-01 10:44:48 +0300103 goto free_rfkill;
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700104 }
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700105
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700106 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700107 return ret;
108
Tomas Winkler8fa74252008-07-01 10:44:48 +0300109free_rfkill:
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200110 if (priv->rfkill != NULL)
111 rfkill_free(priv->rfkill);
112 priv->rfkill = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700113
114error:
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700115 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700116 return ret;
117}
118EXPORT_SYMBOL(iwl_rfkill_init);
119
120void iwl_rfkill_unregister(struct iwl_priv *priv)
121{
122
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200123 if (priv->rfkill)
124 rfkill_unregister(priv->rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700125
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200126 priv->rfkill = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700127}
128EXPORT_SYMBOL(iwl_rfkill_unregister);
129
Tomas Winklera96a27f2008-10-23 23:48:56 -0700130/* set RFKILL to the right state. */
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700131void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
132{
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200133 if (!priv->rfkill)
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700134 return;
135
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200136 if (iwl_is_rfkill_hw(priv)) {
137 rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
138 return;
139 }
140
141 if (!iwl_is_rfkill_sw(priv))
142 rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700143 else
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200144 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700145}
146EXPORT_SYMBOL(iwl_rfkill_set_hw_state);