iwlwifi-5000: add run time calibrations for 5000
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / iwlwifi / iwl-rfkill.c
blob5980a5621cb8de9d4afae1d47272f30c4effdb84
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/version.h>
31 #include <linux/init.h>
33 #include <net/mac80211.h>
35 #include "iwl-eeprom.h"
36 #include "iwl-4965.h"
37 #include "iwl-core.h"
38 #include "iwl-helpers.h"
41 /* software rf-kill from user */
42 static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
44 struct iwl_priv *priv = data;
45 int err = 0;
47 if (!priv->rfkill_mngr.rfkill)
48 return 0;
50 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
51 return 0;
53 IWL_DEBUG_RF_KILL("we recieved soft RFKILL set to state %d\n", state);
54 mutex_lock(&priv->mutex);
56 switch (state) {
57 case RFKILL_STATE_ON:
58 priv->cfg->ops->lib->radio_kill_sw(priv, 0);
59 /* if HW rf-kill is set dont allow ON state */
60 if (iwl_is_rfkill(priv))
61 err = -EBUSY;
62 break;
63 case RFKILL_STATE_OFF:
64 priv->cfg->ops->lib->radio_kill_sw(priv, 1);
65 if (!iwl_is_rfkill(priv))
66 err = -EBUSY;
67 break;
69 mutex_unlock(&priv->mutex);
71 return err;
74 int iwl_rfkill_init(struct iwl_priv *priv)
76 struct device *device = wiphy_dev(priv->hw->wiphy);
77 int ret = 0;
79 BUG_ON(device == NULL);
81 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
82 priv->rfkill_mngr.rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
83 if (!priv->rfkill_mngr.rfkill) {
84 IWL_ERROR("Unable to allocate rfkill device.\n");
85 ret = -ENOMEM;
86 goto error;
89 priv->rfkill_mngr.rfkill->name = priv->cfg->name;
90 priv->rfkill_mngr.rfkill->data = priv;
91 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON;
92 priv->rfkill_mngr.rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
93 priv->rfkill_mngr.rfkill->user_claim_unsupported = 1;
95 priv->rfkill_mngr.rfkill->dev.class->suspend = NULL;
96 priv->rfkill_mngr.rfkill->dev.class->resume = NULL;
98 priv->rfkill_mngr.input_dev = input_allocate_device();
99 if (!priv->rfkill_mngr.input_dev) {
100 IWL_ERROR("Unable to allocate rfkill input device.\n");
101 ret = -ENOMEM;
102 goto freed_rfkill;
105 priv->rfkill_mngr.input_dev->name = priv->cfg->name;
106 priv->rfkill_mngr.input_dev->phys = wiphy_name(priv->hw->wiphy);
107 priv->rfkill_mngr.input_dev->id.bustype = BUS_HOST;
108 priv->rfkill_mngr.input_dev->id.vendor = priv->pci_dev->vendor;
109 priv->rfkill_mngr.input_dev->dev.parent = device;
110 priv->rfkill_mngr.input_dev->evbit[0] = BIT(EV_KEY);
111 set_bit(KEY_WLAN, priv->rfkill_mngr.input_dev->keybit);
113 ret = rfkill_register(priv->rfkill_mngr.rfkill);
114 if (ret) {
115 IWL_ERROR("Unable to register rfkill: %d\n", ret);
116 goto free_input_dev;
119 ret = input_register_device(priv->rfkill_mngr.input_dev);
120 if (ret) {
121 IWL_ERROR("Unable to register rfkill input device: %d\n", ret);
122 goto unregister_rfkill;
125 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
126 return ret;
128 unregister_rfkill:
129 rfkill_unregister(priv->rfkill_mngr.rfkill);
130 priv->rfkill_mngr.rfkill = NULL;
132 free_input_dev:
133 input_free_device(priv->rfkill_mngr.input_dev);
134 priv->rfkill_mngr.input_dev = NULL;
136 freed_rfkill:
137 if (priv->rfkill_mngr.rfkill != NULL)
138 rfkill_free(priv->rfkill_mngr.rfkill);
139 priv->rfkill_mngr.rfkill = NULL;
141 error:
142 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
143 return ret;
145 EXPORT_SYMBOL(iwl_rfkill_init);
147 void iwl_rfkill_unregister(struct iwl_priv *priv)
150 if (priv->rfkill_mngr.input_dev)
151 input_unregister_device(priv->rfkill_mngr.input_dev);
153 if (priv->rfkill_mngr.rfkill)
154 rfkill_unregister(priv->rfkill_mngr.rfkill);
156 priv->rfkill_mngr.input_dev = NULL;
157 priv->rfkill_mngr.rfkill = NULL;
159 EXPORT_SYMBOL(iwl_rfkill_unregister);
161 /* set rf-kill to the right state. */
162 void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
165 if (!priv->rfkill_mngr.rfkill)
166 return;
168 if (!iwl_is_rfkill(priv))
169 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON;
170 else
171 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_OFF;
173 EXPORT_SYMBOL(iwl_rfkill_set_hw_state);