blob: 5f098747cf95cfc99a1e1bf877b08ffef0340d18 [file] [log] [blame]
Mohamed Abbasad97edd2008-03-28 16:21:06 -07001/******************************************************************************
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"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070036#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070037#include "iwl-core.h"
Mohamed Abbasad97edd2008-03-28 16:21:06 -070038#include "iwl-helpers.h"
39
40
Mohamed Abbasad97edd2008-03-28 16:21:06 -070041/* software rf-kill from user */
42static 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
Mohamed Abbas59003832008-04-15 16:01:46 -070050 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
51 return 0;
52
Mohamed Abbasad97edd2008-03-28 16:21:06 -070053 IWL_DEBUG_RF_KILL("we recieved soft RFKILL set to state %d\n", state);
54 mutex_lock(&priv->mutex);
55
56 switch (state) {
57 case RFKILL_STATE_ON:
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +080058 iwl_radio_kill_sw_enable_radio(priv);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070059 /* 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:
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +080064 iwl_radio_kill_sw_disable_radio(priv);
Mohamed Abbasad97edd2008-03-28 16:21:06 -070065 if (!iwl_is_rfkill(priv))
66 err = -EBUSY;
67 break;
68 }
69 mutex_unlock(&priv->mutex);
70
71 return err;
72}
73
74int iwl_rfkill_init(struct iwl_priv *priv)
75{
76 struct device *device = wiphy_dev(priv->hw->wiphy);
77 int ret = 0;
78
79 BUG_ON(device == NULL);
80
Mohamed Abbas03d29c62008-04-03 16:05:24 -070081 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -070082 priv->rfkill_mngr.rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
83 if (!priv->rfkill_mngr.rfkill) {
Mohamed Abbas03d29c62008-04-03 16:05:24 -070084 IWL_ERROR("Unable to allocate rfkill device.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -070085 ret = -ENOMEM;
86 goto error;
87 }
88
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;
94
95 priv->rfkill_mngr.rfkill->dev.class->suspend = NULL;
96 priv->rfkill_mngr.rfkill->dev.class->resume = NULL;
97
98 priv->rfkill_mngr.input_dev = input_allocate_device();
99 if (!priv->rfkill_mngr.input_dev) {
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700100 IWL_ERROR("Unable to allocate rfkill input device.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700101 ret = -ENOMEM;
102 goto freed_rfkill;
103 }
104
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);
112
113 ret = rfkill_register(priv->rfkill_mngr.rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700114 if (ret) {
115 IWL_ERROR("Unable to register rfkill: %d\n", ret);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700116 goto free_input_dev;
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700117 }
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700118
119 ret = input_register_device(priv->rfkill_mngr.input_dev);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700120 if (ret) {
121 IWL_ERROR("Unable to register rfkill input device: %d\n", ret);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700122 goto unregister_rfkill;
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700123 }
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700124
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700125 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700126 return ret;
127
128unregister_rfkill:
129 rfkill_unregister(priv->rfkill_mngr.rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700130 priv->rfkill_mngr.rfkill = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700131
132free_input_dev:
133 input_free_device(priv->rfkill_mngr.input_dev);
134 priv->rfkill_mngr.input_dev = NULL;
135
136freed_rfkill:
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700137 if (priv->rfkill_mngr.rfkill != NULL)
138 rfkill_free(priv->rfkill_mngr.rfkill);
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700139 priv->rfkill_mngr.rfkill = NULL;
140
141error:
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700142 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700143 return ret;
144}
145EXPORT_SYMBOL(iwl_rfkill_init);
146
147void iwl_rfkill_unregister(struct iwl_priv *priv)
148{
149
150 if (priv->rfkill_mngr.input_dev)
151 input_unregister_device(priv->rfkill_mngr.input_dev);
152
153 if (priv->rfkill_mngr.rfkill)
154 rfkill_unregister(priv->rfkill_mngr.rfkill);
Mohamed Abbas03d29c62008-04-03 16:05:24 -0700155
156 priv->rfkill_mngr.input_dev = NULL;
157 priv->rfkill_mngr.rfkill = NULL;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700158}
159EXPORT_SYMBOL(iwl_rfkill_unregister);
160
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700161/* set rf-kill to the right state. */
162void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
163{
164
165 if (!priv->rfkill_mngr.rfkill)
166 return;
167
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;
172}
173EXPORT_SYMBOL(iwl_rfkill_set_hw_state);