wireless: remove unused #include <version.h>
[linux-2.6/mini2440.git] / drivers / net / wireless / iwlwifi / iwl-rfkill.c
blob5d642298f04c33014c896e5cec97d143a38f1b66
1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
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.
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.
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
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
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/init.h>
32 #include <net/mac80211.h>
34 #include "iwl-eeprom.h"
35 #include "iwl-dev.h"
36 #include "iwl-core.h"
37 #include "iwl-helpers.h"
40 /* software rf-kill from user */
41 static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
43 struct iwl_priv *priv = data;
44 int err = 0;
46 if (!priv->rfkill)
47 return 0;
49 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
50 return 0;
52 IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
53 mutex_lock(&priv->mutex);
55 switch (state) {
56 case RFKILL_STATE_UNBLOCKED:
57 if (iwl_is_rfkill_hw(priv)) {
58 err = -EBUSY;
59 goto out_unlock;
61 iwl_radio_kill_sw_enable_radio(priv);
62 break;
63 case RFKILL_STATE_SOFT_BLOCKED:
64 iwl_radio_kill_sw_disable_radio(priv);
65 break;
66 default:
67 IWL_WARNING("we recieved unexpected RFKILL state %d\n", state);
68 break;
70 out_unlock:
71 mutex_unlock(&priv->mutex);
73 return err;
76 int iwl_rfkill_init(struct iwl_priv *priv)
78 struct device *device = wiphy_dev(priv->hw->wiphy);
79 int ret = 0;
81 BUG_ON(device == NULL);
83 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
84 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
85 if (!priv->rfkill) {
86 IWL_ERROR("Unable to allocate rfkill device.\n");
87 ret = -ENOMEM;
88 goto error;
91 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;
97 priv->rfkill->dev.class->suspend = NULL;
98 priv->rfkill->dev.class->resume = NULL;
100 ret = rfkill_register(priv->rfkill);
101 if (ret) {
102 IWL_ERROR("Unable to register rfkill: %d\n", ret);
103 goto free_rfkill;
106 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
107 return ret;
109 free_rfkill:
110 if (priv->rfkill != NULL)
111 rfkill_free(priv->rfkill);
112 priv->rfkill = NULL;
114 error:
115 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
116 return ret;
118 EXPORT_SYMBOL(iwl_rfkill_init);
120 void iwl_rfkill_unregister(struct iwl_priv *priv)
123 if (priv->rfkill)
124 rfkill_unregister(priv->rfkill);
126 priv->rfkill = NULL;
128 EXPORT_SYMBOL(iwl_rfkill_unregister);
130 /* set rf-kill to the right state. */
131 void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
133 if (!priv->rfkill)
134 return;
136 if (iwl_is_rfkill_hw(priv)) {
137 rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
138 return;
141 if (!iwl_is_rfkill_sw(priv))
142 rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
143 else
144 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
146 EXPORT_SYMBOL(iwl_rfkill_set_hw_state);