iwlwifi: fix error path of iwl_rfkill_init
[linux/fpc-iii.git] / drivers / net / wireless / iwlwifi / iwl-rfkill.c
blobeebaf43f66b250294fbb37c908f7afaf214a24b5
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-dev.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 received soft RFKILL set to state %d\n", state);
54 mutex_lock(&priv->mutex);
56 switch (state) {
57 case RFKILL_STATE_UNBLOCKED:
58 iwl_radio_kill_sw_enable_radio(priv);
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_SOFT_BLOCKED:
64 iwl_radio_kill_sw_disable_radio(priv);
65 if (!iwl_is_rfkill(priv))
66 err = -EBUSY;
67 break;
68 default:
69 IWL_WARNING("we recieved unexpected RFKILL state %d\n", state);
70 break;
72 mutex_unlock(&priv->mutex);
74 return err;
77 int iwl_rfkill_init(struct iwl_priv *priv)
79 struct device *device = wiphy_dev(priv->hw->wiphy);
80 int ret = 0;
82 BUG_ON(device == NULL);
84 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
85 priv->rfkill_mngr.rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
86 if (!priv->rfkill_mngr.rfkill) {
87 IWL_ERROR("Unable to allocate rfkill device.\n");
88 ret = -ENOMEM;
89 goto error;
92 priv->rfkill_mngr.rfkill->name = priv->cfg->name;
93 priv->rfkill_mngr.rfkill->data = priv;
94 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON;
95 priv->rfkill_mngr.rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
96 priv->rfkill_mngr.rfkill->user_claim_unsupported = 1;
98 priv->rfkill_mngr.rfkill->dev.class->suspend = NULL;
99 priv->rfkill_mngr.rfkill->dev.class->resume = NULL;
101 ret = rfkill_register(priv->rfkill_mngr.rfkill);
102 if (ret) {
103 IWL_ERROR("Unable to register rfkill: %d\n", ret);
104 goto free_rfkill;
107 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
108 return ret;
110 free_rfkill:
111 if (priv->rfkill_mngr.rfkill != NULL)
112 rfkill_free(priv->rfkill_mngr.rfkill);
113 priv->rfkill_mngr.rfkill = NULL;
115 error:
116 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
117 return ret;
119 EXPORT_SYMBOL(iwl_rfkill_init);
121 void iwl_rfkill_unregister(struct iwl_priv *priv)
124 if (priv->rfkill_mngr.rfkill)
125 rfkill_unregister(priv->rfkill_mngr.rfkill);
127 priv->rfkill_mngr.rfkill = NULL;
129 EXPORT_SYMBOL(iwl_rfkill_unregister);
131 /* set rf-kill to the right state. */
132 void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
134 if (!priv->rfkill_mngr.rfkill)
135 return;
137 if (!iwl_is_rfkill(priv))
138 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON;
139 else
140 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_OFF;
142 EXPORT_SYMBOL(iwl_rfkill_set_hw_state);