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
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"
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
;
47 if (!priv
->rfkill_mngr
.rfkill
)
50 IWL_DEBUG_RF_KILL("we recieved soft RFKILL set to state %d\n", state
);
51 mutex_lock(&priv
->mutex
);
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
))
60 case RFKILL_STATE_OFF
:
61 priv
->cfg
->ops
->lib
->radio_kill_sw(priv
, 1);
62 if (!iwl_is_rfkill(priv
))
66 mutex_unlock(&priv
->mutex
);
71 int iwl_rfkill_init(struct iwl_priv
*priv
)
73 struct device
*device
= wiphy_dev(priv
->hw
->wiphy
);
76 BUG_ON(device
== NULL
);
78 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
79 priv
->rfkill_mngr
.rfkill
= rfkill_allocate(device
, RFKILL_TYPE_WLAN
);
80 if (!priv
->rfkill_mngr
.rfkill
) {
81 IWL_ERROR("Unable to allocate rfkill device.\n");
86 priv
->rfkill_mngr
.rfkill
->name
= priv
->cfg
->name
;
87 priv
->rfkill_mngr
.rfkill
->data
= priv
;
88 priv
->rfkill_mngr
.rfkill
->state
= RFKILL_STATE_ON
;
89 priv
->rfkill_mngr
.rfkill
->toggle_radio
= iwl_rfkill_soft_rf_kill
;
90 priv
->rfkill_mngr
.rfkill
->user_claim_unsupported
= 1;
92 priv
->rfkill_mngr
.rfkill
->dev
.class->suspend
= NULL
;
93 priv
->rfkill_mngr
.rfkill
->dev
.class->resume
= NULL
;
95 priv
->rfkill_mngr
.input_dev
= input_allocate_device();
96 if (!priv
->rfkill_mngr
.input_dev
) {
97 IWL_ERROR("Unable to allocate rfkill input device.\n");
102 priv
->rfkill_mngr
.input_dev
->name
= priv
->cfg
->name
;
103 priv
->rfkill_mngr
.input_dev
->phys
= wiphy_name(priv
->hw
->wiphy
);
104 priv
->rfkill_mngr
.input_dev
->id
.bustype
= BUS_HOST
;
105 priv
->rfkill_mngr
.input_dev
->id
.vendor
= priv
->pci_dev
->vendor
;
106 priv
->rfkill_mngr
.input_dev
->dev
.parent
= device
;
107 priv
->rfkill_mngr
.input_dev
->evbit
[0] = BIT(EV_KEY
);
108 set_bit(KEY_WLAN
, priv
->rfkill_mngr
.input_dev
->keybit
);
110 ret
= rfkill_register(priv
->rfkill_mngr
.rfkill
);
112 IWL_ERROR("Unable to register rfkill: %d\n", ret
);
116 ret
= input_register_device(priv
->rfkill_mngr
.input_dev
);
118 IWL_ERROR("Unable to register rfkill input device: %d\n", ret
);
119 goto unregister_rfkill
;
122 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
126 rfkill_unregister(priv
->rfkill_mngr
.rfkill
);
127 priv
->rfkill_mngr
.rfkill
= NULL
;
130 input_free_device(priv
->rfkill_mngr
.input_dev
);
131 priv
->rfkill_mngr
.input_dev
= NULL
;
134 if (priv
->rfkill_mngr
.rfkill
!= NULL
)
135 rfkill_free(priv
->rfkill_mngr
.rfkill
);
136 priv
->rfkill_mngr
.rfkill
= NULL
;
139 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
142 EXPORT_SYMBOL(iwl_rfkill_init
);
144 void iwl_rfkill_unregister(struct iwl_priv
*priv
)
147 if (priv
->rfkill_mngr
.input_dev
)
148 input_unregister_device(priv
->rfkill_mngr
.input_dev
);
150 if (priv
->rfkill_mngr
.rfkill
)
151 rfkill_unregister(priv
->rfkill_mngr
.rfkill
);
153 priv
->rfkill_mngr
.input_dev
= NULL
;
154 priv
->rfkill_mngr
.rfkill
= NULL
;
156 EXPORT_SYMBOL(iwl_rfkill_unregister
);
158 /* set rf-kill to the right state. */
159 void iwl_rfkill_set_hw_state(struct iwl_priv
*priv
)
162 if (!priv
->rfkill_mngr
.rfkill
)
165 if (!iwl_is_rfkill(priv
))
166 priv
->rfkill_mngr
.rfkill
->state
= RFKILL_STATE_ON
;
168 priv
->rfkill_mngr
.rfkill
->state
= RFKILL_STATE_OFF
;
170 EXPORT_SYMBOL(iwl_rfkill_set_hw_state
);