blob: 4b69da30665c3b1bd74c93f0dd516aaf4e89809e [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:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Mohamed Abbasad97edd2008-03-28 16:21:06 -070026 * 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
Mohamed Abbasad97edd2008-03-28 16:21:06 -070038/* software rf-kill from user */
39static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
40{
41 struct iwl_priv *priv = data;
42 int err = 0;
43
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020044 if (!priv->rfkill)
Mohamed Abbasad97edd2008-03-28 16:21:06 -070045 return 0;
46
Mohamed Abbas59003832008-04-15 16:01:46 -070047 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
48 return 0;
49
John W. Linvilleedd4b532008-06-27 13:04:25 -040050 IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070051 mutex_lock(&priv->mutex);
52
53 switch (state) {
John W. Linvilleff28bd92008-06-27 10:27:47 -040054 case RFKILL_STATE_UNBLOCKED:
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020055 if (iwl_is_rfkill_hw(priv)) {
Mohamed Abbasad97edd2008-03-28 16:21:06 -070056 err = -EBUSY;
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020057 goto out_unlock;
58 }
59 iwl_radio_kill_sw_enable_radio(priv);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070060 break;
John W. Linvilleff28bd92008-06-27 10:27:47 -040061 case RFKILL_STATE_SOFT_BLOCKED:
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +080062 iwl_radio_kill_sw_disable_radio(priv);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070063 break;
John W. Linvilleff28bd92008-06-27 10:27:47 -040064 default:
Tomas Winklera96a27f2008-10-23 23:48:56 -070065 IWL_WARNING("we received unexpected RFKILL state %d\n", state);
John W. Linvilleff28bd92008-06-27 10:27:47 -040066 break;
Mohamed Abbasad97edd2008-03-28 16:21:06 -070067 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020068out_unlock:
Mohamed Abbasad97edd2008-03-28 16:21:06 -070069 mutex_unlock(&priv->mutex);
70
71 return err;
72}
73
74int iwl_rfkill_init(struct iwl_priv *priv)
75{
76 struct device *device = wiphy_dev(priv->hw->wiphy);
77 int ret = 0;
78
79 BUG_ON(device == NULL);
80
Mohamed Abbas03d29c62008-04-03 16:05:24 -070081 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020082 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
83 if (!priv->rfkill) {
Tomas Winklera96a27f2008-10-23 23:48:56 -070084 IWL_ERROR("Unable to allocate RFKILL device.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -070085 ret = -ENOMEM;
86 goto error;
87 }
88
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020089 priv->rfkill->name = priv->cfg->name;
90 priv->rfkill->data = priv;
91 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
92 priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
93 priv->rfkill->user_claim_unsupported = 1;
Mohamed Abbasad97edd2008-03-28 16:21:06 -070094
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020095 priv->rfkill->dev.class->suspend = NULL;
96 priv->rfkill->dev.class->resume = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -070097
Adel Gadllah80fcc9e2008-07-01 17:49:50 +020098 ret = rfkill_register(priv->rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -070099 if (ret) {
Tomas Winklera96a27f2008-10-23 23:48:56 -0700100 IWL_ERROR("Unable to register RFKILL: %d\n", ret);
Tomas Winkler8fa74252008-07-01 10:44:48 +0300101 goto free_rfkill;
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700102 }
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700103
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700104 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700105 return ret;
106
Tomas Winkler8fa74252008-07-01 10:44:48 +0300107free_rfkill:
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200108 if (priv->rfkill != NULL)
109 rfkill_free(priv->rfkill);
110 priv->rfkill = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700111
112error:
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700113 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700114 return ret;
115}
116EXPORT_SYMBOL(iwl_rfkill_init);
117
118void iwl_rfkill_unregister(struct iwl_priv *priv)
119{
120
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200121 if (priv->rfkill)
122 rfkill_unregister(priv->rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700123
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200124 priv->rfkill = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700125}
126EXPORT_SYMBOL(iwl_rfkill_unregister);
127
Tomas Winklera96a27f2008-10-23 23:48:56 -0700128/* set RFKILL to the right state. */
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700129void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
130{
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200131 if (!priv->rfkill)
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700132 return;
133
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200134 if (iwl_is_rfkill_hw(priv)) {
135 rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
136 return;
137 }
138
139 if (!iwl_is_rfkill_sw(priv))
140 rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700141 else
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200142 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700143}
144EXPORT_SYMBOL(iwl_rfkill_set_hw_state);