iwl-rfkill.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/init.h>
  31. #include <net/mac80211.h>
  32. #include "iwl-eeprom.h"
  33. #include "iwl-dev.h"
  34. #include "iwl-core.h"
  35. #include "iwl-helpers.h"
  36. /* software rf-kill from user */
  37. static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
  38. {
  39. struct iwl_priv *priv = data;
  40. int err = 0;
  41. if (!priv->rfkill)
  42. return 0;
  43. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  44. return 0;
  45. IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
  46. mutex_lock(&priv->mutex);
  47. switch (state) {
  48. case RFKILL_STATE_UNBLOCKED:
  49. if (iwl_is_rfkill_hw(priv)) {
  50. err = -EBUSY;
  51. goto out_unlock;
  52. }
  53. iwl_radio_kill_sw_enable_radio(priv);
  54. break;
  55. case RFKILL_STATE_SOFT_BLOCKED:
  56. iwl_radio_kill_sw_disable_radio(priv);
  57. break;
  58. default:
  59. IWL_WARNING("we recieved unexpected RFKILL state %d\n", state);
  60. break;
  61. }
  62. out_unlock:
  63. mutex_unlock(&priv->mutex);
  64. return err;
  65. }
  66. int iwl_rfkill_init(struct iwl_priv *priv)
  67. {
  68. struct device *device = wiphy_dev(priv->hw->wiphy);
  69. int ret = 0;
  70. BUG_ON(device == NULL);
  71. IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
  72. priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
  73. if (!priv->rfkill) {
  74. IWL_ERROR("Unable to allocate rfkill device.\n");
  75. ret = -ENOMEM;
  76. goto error;
  77. }
  78. priv->rfkill->name = priv->cfg->name;
  79. priv->rfkill->data = priv;
  80. priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
  81. priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
  82. priv->rfkill->user_claim_unsupported = 1;
  83. priv->rfkill->dev.class->suspend = NULL;
  84. priv->rfkill->dev.class->resume = NULL;
  85. ret = rfkill_register(priv->rfkill);
  86. if (ret) {
  87. IWL_ERROR("Unable to register rfkill: %d\n", ret);
  88. goto free_rfkill;
  89. }
  90. IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
  91. return ret;
  92. free_rfkill:
  93. if (priv->rfkill != NULL)
  94. rfkill_free(priv->rfkill);
  95. priv->rfkill = NULL;
  96. error:
  97. IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
  98. return ret;
  99. }
  100. EXPORT_SYMBOL(iwl_rfkill_init);
  101. void iwl_rfkill_unregister(struct iwl_priv *priv)
  102. {
  103. if (priv->rfkill)
  104. rfkill_unregister(priv->rfkill);
  105. priv->rfkill = NULL;
  106. }
  107. EXPORT_SYMBOL(iwl_rfkill_unregister);
  108. /* set rf-kill to the right state. */
  109. void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
  110. {
  111. if (!priv->rfkill)
  112. return;
  113. if (iwl_is_rfkill_hw(priv)) {
  114. rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
  115. return;
  116. }
  117. if (!iwl_is_rfkill_sw(priv))
  118. rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
  119. else
  120. rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
  121. }
  122. EXPORT_SYMBOL(iwl_rfkill_set_hw_state);