1 /******************************************************************************
3 * Copyright(c) 2003 - 2009 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 * 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>
32 #include <net/mac80211.h>
34 #include "iwl-eeprom.h"
38 /* software rf-kill from user */
39 static int iwl_rfkill_soft_rf_kill(void *data
, enum rfkill_state state
)
41 struct iwl_priv
*priv
= data
;
47 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
50 IWL_DEBUG_RF_KILL(priv
, "we received soft RFKILL set to state %d\n", state
);
51 mutex_lock(&priv
->mutex
);
54 case RFKILL_STATE_UNBLOCKED
:
55 if (iwl_is_rfkill_hw(priv
)) {
59 iwl_radio_kill_sw_enable_radio(priv
);
61 case RFKILL_STATE_SOFT_BLOCKED
:
62 iwl_radio_kill_sw_disable_radio(priv
);
65 IWL_WARN(priv
, "we received unexpected RFKILL state %d\n",
70 mutex_unlock(&priv
->mutex
);
75 int iwl_rfkill_init(struct iwl_priv
*priv
)
77 struct device
*device
= wiphy_dev(priv
->hw
->wiphy
);
80 BUG_ON(device
== NULL
);
82 IWL_DEBUG_RF_KILL(priv
, "Initializing RFKILL.\n");
83 priv
->rfkill
= rfkill_allocate(device
, RFKILL_TYPE_WLAN
);
85 IWL_ERR(priv
, "Unable to allocate RFKILL device.\n");
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 priv
->rfkill
->user_claim_unsupported
= 1;
96 priv
->rfkill
->dev
.class->suspend
= NULL
;
97 priv
->rfkill
->dev
.class->resume
= NULL
;
99 ret
= rfkill_register(priv
->rfkill
);
101 IWL_ERR(priv
, "Unable to register RFKILL: %d\n", ret
);
105 IWL_DEBUG_RF_KILL(priv
, "RFKILL initialization complete.\n");
109 if (priv
->rfkill
!= NULL
)
110 rfkill_free(priv
->rfkill
);
114 IWL_DEBUG_RF_KILL(priv
, "RFKILL initialization complete.\n");
117 EXPORT_SYMBOL(iwl_rfkill_init
);
119 void iwl_rfkill_unregister(struct iwl_priv
*priv
)
123 rfkill_unregister(priv
->rfkill
);
127 EXPORT_SYMBOL(iwl_rfkill_unregister
);
129 /* set RFKILL to the right state. */
130 void iwl_rfkill_set_hw_state(struct iwl_priv
*priv
)
135 if (iwl_is_rfkill_hw(priv
)) {
136 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_HARD_BLOCKED
);
140 if (!iwl_is_rfkill_sw(priv
))
141 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_UNBLOCKED
);
143 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_SOFT_BLOCKED
);
145 EXPORT_SYMBOL(iwl_rfkill_set_hw_state
);