Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-rfkill.c
1 /******************************************************************************
2 *
3 * Copyright(c) 2003 - 2009 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 * Intel Linux Wireless <ilw@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>
31
32 #include <net/mac80211.h>
33
34 #include "iwl-eeprom.h"
35 #include "iwl-dev.h"
36 #include "iwl-core.h"
37
38 /* software rf-kill from user */
39 static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
40 {
41 struct iwl_priv *priv = data;
42 int err = 0;
43
44 if (!priv->rfkill)
45 return 0;
46
47 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
48 return 0;
49
50 IWL_DEBUG_RF_KILL(priv, "we received soft RFKILL set to state %d\n", state);
51 mutex_lock(&priv->mutex);
52
53 switch (state) {
54 case RFKILL_STATE_UNBLOCKED:
55 if (iwl_is_rfkill_hw(priv)) {
56 err = -EBUSY;
57 goto out_unlock;
58 }
59 iwl_radio_kill_sw_enable_radio(priv);
60 break;
61 case RFKILL_STATE_SOFT_BLOCKED:
62 iwl_radio_kill_sw_disable_radio(priv);
63 break;
64 default:
65 IWL_WARN(priv, "we received unexpected RFKILL state %d\n",
66 state);
67 break;
68 }
69 out_unlock:
70 mutex_unlock(&priv->mutex);
71
72 return err;
73 }
74
75 int iwl_rfkill_init(struct iwl_priv *priv)
76 {
77 struct device *device = wiphy_dev(priv->hw->wiphy);
78 int ret = 0;
79
80 BUG_ON(device == NULL);
81
82 IWL_DEBUG_RF_KILL(priv, "Initializing RFKILL.\n");
83 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
84 if (!priv->rfkill) {
85 IWL_ERR(priv, "Unable to allocate RFKILL device.\n");
86 ret = -ENOMEM;
87 goto error;
88 }
89
90 priv->rfkill->name = priv->cfg->name;
91 priv->rfkill->data = priv;
92 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
93 priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
94
95 priv->rfkill->dev.class->suspend = NULL;
96 priv->rfkill->dev.class->resume = NULL;
97
98 ret = rfkill_register(priv->rfkill);
99 if (ret) {
100 IWL_ERR(priv, "Unable to register RFKILL: %d\n", ret);
101 goto free_rfkill;
102 }
103
104 IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n");
105 return ret;
106
107 free_rfkill:
108 if (priv->rfkill != NULL)
109 rfkill_free(priv->rfkill);
110 priv->rfkill = NULL;
111
112 error:
113 IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n");
114 return ret;
115 }
116 EXPORT_SYMBOL(iwl_rfkill_init);
117
118 void iwl_rfkill_unregister(struct iwl_priv *priv)
119 {
120
121 if (priv->rfkill)
122 rfkill_unregister(priv->rfkill);
123
124 priv->rfkill = NULL;
125 }
126 EXPORT_SYMBOL(iwl_rfkill_unregister);
127
128 /* set RFKILL to the right state. */
129 void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
130 {
131 if (!priv->rfkill)
132 return;
133
134 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);
141 else
142 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
143 }
144 EXPORT_SYMBOL(iwl_rfkill_set_hw_state);
This page took 0.033854 seconds and 6 git commands to generate.