iwl-rfkill.c 5.4 KB

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