]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/wireless/iwlwifi/iwl-rfkill.c
308d69b184045de8f1b176a6613e887cc43badb2
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / iwlwifi / iwl-rfkill.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2003 - 2008 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  * 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>
32
33 #include <net/mac80211.h>
34
35 #include "iwl-eeprom.h"
36 #include "iwl-4965.h"
37 #include "iwl-core.h"
38 #include "iwl-helpers.h"
39
40
41 /* software rf-kill from user */
42 static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
43 {
44         struct iwl_priv *priv = data;
45         int err = 0;
46
47         if (!priv->rfkill_mngr.rfkill)
48                 return 0;
49
50         IWL_DEBUG_RF_KILL("we recieved soft RFKILL set to state %d\n", state);
51         mutex_lock(&priv->mutex);
52
53         switch (state) {
54         case RFKILL_STATE_ON:
55                 priv->cfg->ops->lib->radio_kill_sw(priv, 0);
56                 /* if HW rf-kill is set dont allow ON state */
57                 if (iwl_is_rfkill(priv))
58                         err = -EBUSY;
59                 break;
60         case RFKILL_STATE_OFF:
61                 priv->cfg->ops->lib->radio_kill_sw(priv, 1);
62                 if (!iwl_is_rfkill(priv))
63                         err = -EBUSY;
64                 break;
65         }
66         mutex_unlock(&priv->mutex);
67
68         return err;
69 }
70
71 int iwl_rfkill_init(struct iwl_priv *priv)
72 {
73         struct device *device = wiphy_dev(priv->hw->wiphy);
74         int ret = 0;
75
76         BUG_ON(device == NULL);
77
78         priv->rfkill_mngr.rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
79         if (!priv->rfkill_mngr.rfkill) {
80                 ret = -ENOMEM;
81                 goto error;
82         }
83
84         priv->rfkill_mngr.rfkill->name = priv->cfg->name;
85         priv->rfkill_mngr.rfkill->data = priv;
86         priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON;
87         priv->rfkill_mngr.rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
88         priv->rfkill_mngr.rfkill->user_claim_unsupported = 1;
89
90         priv->rfkill_mngr.rfkill->dev.class->suspend = NULL;
91         priv->rfkill_mngr.rfkill->dev.class->resume = NULL;
92
93         priv->rfkill_mngr.input_dev = input_allocate_device();
94         if (!priv->rfkill_mngr.input_dev) {
95                 ret = -ENOMEM;
96                 goto freed_rfkill;
97         }
98
99         priv->rfkill_mngr.input_dev->name = priv->cfg->name;
100         priv->rfkill_mngr.input_dev->phys = wiphy_name(priv->hw->wiphy);
101         priv->rfkill_mngr.input_dev->id.bustype = BUS_HOST;
102         priv->rfkill_mngr.input_dev->id.vendor = priv->pci_dev->vendor;
103         priv->rfkill_mngr.input_dev->dev.parent = device;
104         priv->rfkill_mngr.input_dev->evbit[0] = BIT(EV_KEY);
105         set_bit(KEY_WLAN, priv->rfkill_mngr.input_dev->keybit);
106
107         ret = rfkill_register(priv->rfkill_mngr.rfkill);
108         if (ret)
109                 goto free_input_dev;
110
111         ret = input_register_device(priv->rfkill_mngr.input_dev);
112         if (ret)
113                 goto unregister_rfkill;
114
115         return ret;
116
117 unregister_rfkill:
118         rfkill_unregister(priv->rfkill_mngr.rfkill);
119
120 free_input_dev:
121         input_free_device(priv->rfkill_mngr.input_dev);
122         priv->rfkill_mngr.input_dev = NULL;
123
124 freed_rfkill:
125         rfkill_free(priv->rfkill_mngr.rfkill);
126         priv->rfkill_mngr.rfkill = NULL;
127
128 error:
129         return ret;
130 }
131 EXPORT_SYMBOL(iwl_rfkill_init);
132
133 void iwl_rfkill_unregister(struct iwl_priv *priv)
134 {
135
136         if (priv->rfkill_mngr.input_dev)
137                 input_unregister_device(priv->rfkill_mngr.input_dev);
138
139         if (priv->rfkill_mngr.rfkill)
140                 rfkill_unregister(priv->rfkill_mngr.rfkill);
141 }
142 EXPORT_SYMBOL(iwl_rfkill_unregister);
143
144
145 void iwl_rfkill_free(struct iwl_priv *priv)
146 {
147         if (priv->rfkill_mngr.input_dev)
148                 input_free_device(priv->rfkill_mngr.input_dev);
149
150         if (priv->rfkill_mngr.rfkill)
151                 rfkill_free(priv->rfkill_mngr.rfkill);
152 }
153 EXPORT_SYMBOL(iwl_rfkill_free);
154
155 /* set rf-kill to the right state. */
156 void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
157 {
158
159         if (!priv->rfkill_mngr.rfkill)
160                 return;
161
162         if (!iwl_is_rfkill(priv))
163                 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON;
164         else
165                 priv->rfkill_mngr.rfkill->state = RFKILL_STATE_OFF;
166 }
167 EXPORT_SYMBOL(iwl_rfkill_set_hw_state);