| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 2 | * | 
| Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved. | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 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: | 
| Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | *  Intel Linux Wireless <ilw@linux.intel.com> | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | 
|  | 27 | *****************************************************************************/ | 
|  | 28 | #include <linux/kernel.h> | 
|  | 29 | #include <linux/module.h> | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 30 | #include <linux/init.h> | 
|  | 31 |  | 
|  | 32 | #include <net/mac80211.h> | 
|  | 33 |  | 
|  | 34 | #include "iwl-eeprom.h" | 
| Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 35 | #include "iwl-dev.h" | 
| Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 36 | #include "iwl-core.h" | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 37 |  | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 38 | /* software rf-kill from user */ | 
|  | 39 | static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state) | 
|  | 40 | { | 
|  | 41 | struct iwl_priv *priv = data; | 
|  | 42 | int err = 0; | 
|  | 43 |  | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 44 | if (!priv->rfkill) | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 45 | return 0; | 
|  | 46 |  | 
| Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 47 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | 
|  | 48 | return 0; | 
|  | 49 |  | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 50 | IWL_DEBUG_RF_KILL(priv, "we received soft RFKILL set to state %d\n", state); | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 51 | mutex_lock(&priv->mutex); | 
|  | 52 |  | 
|  | 53 | switch (state) { | 
| John W. Linville | ff28bd9 | 2008-06-27 10:27:47 -0400 | [diff] [blame] | 54 | case RFKILL_STATE_UNBLOCKED: | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 55 | if (iwl_is_rfkill_hw(priv)) { | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 56 | err = -EBUSY; | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 57 | goto out_unlock; | 
|  | 58 | } | 
|  | 59 | iwl_radio_kill_sw_enable_radio(priv); | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 60 | break; | 
| John W. Linville | ff28bd9 | 2008-06-27 10:27:47 -0400 | [diff] [blame] | 61 | case RFKILL_STATE_SOFT_BLOCKED: | 
| Emmanuel Grumbach | 14a08a7 | 2008-06-13 15:44:55 +0800 | [diff] [blame] | 62 | iwl_radio_kill_sw_disable_radio(priv); | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 63 | break; | 
| John W. Linville | ff28bd9 | 2008-06-27 10:27:47 -0400 | [diff] [blame] | 64 | default: | 
| Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 65 | IWL_WARN(priv, "we received unexpected RFKILL state %d\n", | 
|  | 66 | state); | 
| John W. Linville | ff28bd9 | 2008-06-27 10:27:47 -0400 | [diff] [blame] | 67 | break; | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 68 | } | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 69 | out_unlock: | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 70 | mutex_unlock(&priv->mutex); | 
|  | 71 |  | 
|  | 72 | return err; | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | int iwl_rfkill_init(struct iwl_priv *priv) | 
|  | 76 | { | 
|  | 77 | struct device *device = wiphy_dev(priv->hw->wiphy); | 
|  | 78 | int ret = 0; | 
|  | 79 |  | 
|  | 80 | BUG_ON(device == NULL); | 
|  | 81 |  | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 82 | IWL_DEBUG_RF_KILL(priv, "Initializing RFKILL.\n"); | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 83 | priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); | 
|  | 84 | if (!priv->rfkill) { | 
| Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 85 | IWL_ERR(priv, "Unable to allocate RFKILL device.\n"); | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 86 | ret = -ENOMEM; | 
|  | 87 | goto error; | 
|  | 88 | } | 
|  | 89 |  | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 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; | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 95 |  | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 96 | priv->rfkill->dev.class->suspend = NULL; | 
|  | 97 | priv->rfkill->dev.class->resume = NULL; | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 98 |  | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 99 | ret = rfkill_register(priv->rfkill); | 
| Mohamed Abbas | 03d29c6 | 2008-04-03 16:05:24 -0700 | [diff] [blame] | 100 | if (ret) { | 
| Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 101 | IWL_ERR(priv, "Unable to register RFKILL: %d\n", ret); | 
| Tomas Winkler | 8fa7425 | 2008-07-01 10:44:48 +0300 | [diff] [blame] | 102 | goto free_rfkill; | 
| Mohamed Abbas | 03d29c6 | 2008-04-03 16:05:24 -0700 | [diff] [blame] | 103 | } | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 104 |  | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 105 | IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n"); | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 106 | return ret; | 
|  | 107 |  | 
| Tomas Winkler | 8fa7425 | 2008-07-01 10:44:48 +0300 | [diff] [blame] | 108 | free_rfkill: | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 109 | if (priv->rfkill != NULL) | 
|  | 110 | rfkill_free(priv->rfkill); | 
|  | 111 | priv->rfkill = NULL; | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 112 |  | 
|  | 113 | error: | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 114 | IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n"); | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 115 | return ret; | 
|  | 116 | } | 
|  | 117 | EXPORT_SYMBOL(iwl_rfkill_init); | 
|  | 118 |  | 
|  | 119 | void iwl_rfkill_unregister(struct iwl_priv *priv) | 
|  | 120 | { | 
|  | 121 |  | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 122 | if (priv->rfkill) | 
|  | 123 | rfkill_unregister(priv->rfkill); | 
| Mohamed Abbas | 03d29c6 | 2008-04-03 16:05:24 -0700 | [diff] [blame] | 124 |  | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 125 | priv->rfkill = NULL; | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 126 | } | 
|  | 127 | EXPORT_SYMBOL(iwl_rfkill_unregister); | 
|  | 128 |  | 
| Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 129 | /* set RFKILL to the right state. */ | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 130 | void iwl_rfkill_set_hw_state(struct iwl_priv *priv) | 
|  | 131 | { | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 132 | if (!priv->rfkill) | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 133 | return; | 
|  | 134 |  | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 135 | if (iwl_is_rfkill_hw(priv)) { | 
|  | 136 | rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED); | 
|  | 137 | return; | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | if (!iwl_is_rfkill_sw(priv)) | 
|  | 141 | rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED); | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 142 | else | 
| Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 143 | rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED); | 
| Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 144 | } | 
|  | 145 | EXPORT_SYMBOL(iwl_rfkill_set_hw_state); |