iwl-rfkill.c 3.8 KB

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