]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/net/wireless/iwlwifi/iwl-rfkill.c
rfkill: rewrite
[net-next-2.6.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, bool blocked)
40 {
41         struct iwl_priv *priv = data;
42
43         if (!priv->rfkill)
44                 return -EINVAL;
45
46         if (test_bit(STATUS_EXIT_PENDING, &priv->status))
47                 return 0;
48
49         IWL_DEBUG_RF_KILL(priv, "received soft RFKILL: block=%d\n", blocked);
50
51         mutex_lock(&priv->mutex);
52
53         if (iwl_is_rfkill_hw(priv))
54                 goto out_unlock;
55
56         if (!blocked)
57                 iwl_radio_kill_sw_enable_radio(priv);
58         else
59                 iwl_radio_kill_sw_disable_radio(priv);
60
61 out_unlock:
62         mutex_unlock(&priv->mutex);
63         return 0;
64 }
65
66 static const struct rfkill_ops iwl_rfkill_ops = {
67         .set_block = iwl_rfkill_soft_rf_kill,
68 };
69
70 int iwl_rfkill_init(struct iwl_priv *priv)
71 {
72         struct device *device = wiphy_dev(priv->hw->wiphy);
73         int ret = 0;
74
75         BUG_ON(device == NULL);
76
77         IWL_DEBUG_RF_KILL(priv, "Initializing RFKILL.\n");
78         priv->rfkill = rfkill_alloc(priv->cfg->name,
79                                     device,
80                                     RFKILL_TYPE_WLAN,
81                                     &iwl_rfkill_ops, priv);
82         if (!priv->rfkill) {
83                 IWL_ERR(priv, "Unable to allocate RFKILL device.\n");
84                 ret = -ENOMEM;
85                 goto error;
86         }
87
88         ret = rfkill_register(priv->rfkill);
89         if (ret) {
90                 IWL_ERR(priv, "Unable to register RFKILL: %d\n", ret);
91                 goto free_rfkill;
92         }
93
94         IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n");
95         return 0;
96
97 free_rfkill:
98         rfkill_destroy(priv->rfkill);
99         priv->rfkill = NULL;
100
101 error:
102         IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n");
103         return ret;
104 }
105 EXPORT_SYMBOL(iwl_rfkill_init);
106
107 void iwl_rfkill_unregister(struct iwl_priv *priv)
108 {
109
110         if (priv->rfkill) {
111                 rfkill_unregister(priv->rfkill);
112                 rfkill_destroy(priv->rfkill);
113         }
114
115         priv->rfkill = NULL;
116 }
117 EXPORT_SYMBOL(iwl_rfkill_unregister);
118
119 /* set RFKILL to the right state. */
120 void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
121 {
122         if (!priv->rfkill)
123                 return;
124
125         if (rfkill_set_hw_state(priv->rfkill,
126                                 !!iwl_is_rfkill_hw(priv)))
127                 iwl_radio_kill_sw_disable_radio(priv);
128         else
129                 iwl_radio_kill_sw_enable_radio(priv);
130 }
131 EXPORT_SYMBOL(iwl_rfkill_set_hw_state);