blob: e5e5846e9f252f63f7fdbe3e3fc7a6b3039d9047 [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>
30#include <linux/version.h>
31#include <linux/init.h>
32
33#include <net/mac80211.h>
34
35#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070036#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070037#include "iwl-core.h"
Mohamed Abbasad97edd2008-03-28 16:21:06 -070038#include "iwl-helpers.h"
39
40
Mohamed Abbasad97edd2008-03-28 16:21:06 -070041/* software rf-kill from user */
42static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
43{
44 struct iwl_priv *priv = data;
45 int err = 0;
46
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020047 if (!priv->rfkill)
Mohamed Abbasad97edd2008-03-28 16:21:06 -070048 return 0;
49
Mohamed Abbas59003832008-04-15 16:01:46 -070050 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
51 return 0;
52
John W. Linvilleedd4b532008-06-27 13:04:25 -040053 IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070054 mutex_lock(&priv->mutex);
55
56 switch (state) {
John W. Linvilleff28bd92008-06-27 10:27:47 -040057 case RFKILL_STATE_UNBLOCKED:
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020058 if (iwl_is_rfkill_hw(priv)) {
Mohamed Abbasad97edd2008-03-28 16:21:06 -070059 err = -EBUSY;
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020060 goto out_unlock;
61 }
62 iwl_radio_kill_sw_enable_radio(priv);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070063 break;
John W. Linvilleff28bd92008-06-27 10:27:47 -040064 case RFKILL_STATE_SOFT_BLOCKED:
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +080065 iwl_radio_kill_sw_disable_radio(priv);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070066 break;
John W. Linvilleff28bd92008-06-27 10:27:47 -040067 default:
68 IWL_WARNING("we recieved unexpected RFKILL state %d\n", state);
69 break;
Mohamed Abbasad97edd2008-03-28 16:21:06 -070070 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020071out_unlock:
Mohamed Abbasad97edd2008-03-28 16:21:06 -070072 mutex_unlock(&priv->mutex);
73
74 return err;
75}
76
77int iwl_rfkill_init(struct iwl_priv *priv)
78{
79 struct device *device = wiphy_dev(priv->hw->wiphy);
80 int ret = 0;
81
82 BUG_ON(device == NULL);
83
Mohamed Abbas03d29c62008-04-03 16:05:24 -070084 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020085 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
86 if (!priv->rfkill) {
Mohamed Abbas03d29c62008-04-03 16:05:24 -070087 IWL_ERROR("Unable to allocate rfkill device.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -070088 ret = -ENOMEM;
89 goto error;
90 }
91
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020092 priv->rfkill->name = priv->cfg->name;
93 priv->rfkill->data = priv;
94 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
95 priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
96 priv->rfkill->user_claim_unsupported = 1;
Mohamed Abbasad97edd2008-03-28 16:21:06 -070097
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020098 priv->rfkill->dev.class->suspend = NULL;
99 priv->rfkill->dev.class->resume = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700100
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200101 ret = rfkill_register(priv->rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700102 if (ret) {
103 IWL_ERROR("Unable to register rfkill: %d\n", ret);
Tomas Winkler8fa74252008-07-01 10:44:48 +0300104 goto free_rfkill;
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700105 }
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700106
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700107 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700108 return ret;
109
Tomas Winkler8fa74252008-07-01 10:44:48 +0300110free_rfkill:
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200111 if (priv->rfkill != NULL)
112 rfkill_free(priv->rfkill);
113 priv->rfkill = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700114
115error:
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700116 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700117 return ret;
118}
119EXPORT_SYMBOL(iwl_rfkill_init);
120
121void iwl_rfkill_unregister(struct iwl_priv *priv)
122{
123
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200124 if (priv->rfkill)
125 rfkill_unregister(priv->rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700126
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200127 priv->rfkill = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700128}
129EXPORT_SYMBOL(iwl_rfkill_unregister);
130
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700131/* set rf-kill to the right state. */
132void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
133{
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200134 if (!priv->rfkill)
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700135 return;
136
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200137 if (iwl_is_rfkill_hw(priv)) {
138 rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
139 return;
140 }
141
142 if (!iwl_is_rfkill_sw(priv))
143 rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700144 else
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200145 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700146}
147EXPORT_SYMBOL(iwl_rfkill_set_hw_state);