iwl-rfkill.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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-4965.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. IWL_DEBUG_RF_KILL("we recieved soft RFKILL set to state %d\n", state);
  45. mutex_lock(&priv->mutex);
  46. switch (state) {
  47. case RFKILL_STATE_ON:
  48. priv->cfg->ops->lib->radio_kill_sw(priv, 0);
  49. /* if HW rf-kill is set dont allow ON state */
  50. if (iwl_is_rfkill(priv))
  51. err = -EBUSY;
  52. break;
  53. case RFKILL_STATE_OFF:
  54. priv->cfg->ops->lib->radio_kill_sw(priv, 1);
  55. if (!iwl_is_rfkill(priv))
  56. err = -EBUSY;
  57. break;
  58. }
  59. mutex_unlock(&priv->mutex);
  60. return err;
  61. }
  62. int iwl_rfkill_init(struct iwl_priv *priv)
  63. {
  64. struct device *device = wiphy_dev(priv->hw->wiphy);
  65. int ret = 0;
  66. BUG_ON(device == NULL);
  67. priv->rfkill_mngr.rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
  68. if (!priv->rfkill_mngr.rfkill) {
  69. ret = -ENOMEM;
  70. goto error;
  71. }
  72. priv->rfkill_mngr.rfkill->name = priv->cfg->name;
  73. priv->rfkill_mngr.rfkill->data = priv;
  74. priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON;
  75. priv->rfkill_mngr.rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
  76. priv->rfkill_mngr.rfkill->user_claim_unsupported = 1;
  77. priv->rfkill_mngr.rfkill->dev.class->suspend = NULL;
  78. priv->rfkill_mngr.rfkill->dev.class->resume = NULL;
  79. priv->rfkill_mngr.input_dev = input_allocate_device();
  80. if (!priv->rfkill_mngr.input_dev) {
  81. ret = -ENOMEM;
  82. goto freed_rfkill;
  83. }
  84. priv->rfkill_mngr.input_dev->name = priv->cfg->name;
  85. priv->rfkill_mngr.input_dev->phys = wiphy_name(priv->hw->wiphy);
  86. priv->rfkill_mngr.input_dev->id.bustype = BUS_HOST;
  87. priv->rfkill_mngr.input_dev->id.vendor = priv->pci_dev->vendor;
  88. priv->rfkill_mngr.input_dev->dev.parent = device;
  89. priv->rfkill_mngr.input_dev->evbit[0] = BIT(EV_KEY);
  90. set_bit(KEY_WLAN, priv->rfkill_mngr.input_dev->keybit);
  91. ret = rfkill_register(priv->rfkill_mngr.rfkill);
  92. if (ret)
  93. goto free_input_dev;
  94. ret = input_register_device(priv->rfkill_mngr.input_dev);
  95. if (ret)
  96. goto unregister_rfkill;
  97. return ret;
  98. unregister_rfkill:
  99. rfkill_unregister(priv->rfkill_mngr.rfkill);
  100. free_input_dev:
  101. input_free_device(priv->rfkill_mngr.input_dev);
  102. priv->rfkill_mngr.input_dev = NULL;
  103. freed_rfkill:
  104. rfkill_free(priv->rfkill_mngr.rfkill);
  105. priv->rfkill_mngr.rfkill = NULL;
  106. error:
  107. return ret;
  108. }
  109. EXPORT_SYMBOL(iwl_rfkill_init);
  110. void iwl_rfkill_unregister(struct iwl_priv *priv)
  111. {
  112. if (priv->rfkill_mngr.input_dev)
  113. input_unregister_device(priv->rfkill_mngr.input_dev);
  114. if (priv->rfkill_mngr.rfkill)
  115. rfkill_unregister(priv->rfkill_mngr.rfkill);
  116. }
  117. EXPORT_SYMBOL(iwl_rfkill_unregister);
  118. void iwl_rfkill_free(struct iwl_priv *priv)
  119. {
  120. if (priv->rfkill_mngr.input_dev)
  121. input_free_device(priv->rfkill_mngr.input_dev);
  122. if (priv->rfkill_mngr.rfkill)
  123. rfkill_free(priv->rfkill_mngr.rfkill);
  124. }
  125. EXPORT_SYMBOL(iwl_rfkill_free);
  126. /* set rf-kill to the right state. */
  127. void iwl_rfkill_set_hw_state(struct iwl_priv *priv)
  128. {
  129. if (!priv->rfkill_mngr.rfkill)
  130. return;
  131. if (!iwl_is_rfkill(priv))
  132. priv->rfkill_mngr.rfkill->state = RFKILL_STATE_ON;
  133. else
  134. priv->rfkill_mngr.rfkill->state = RFKILL_STATE_OFF;
  135. }
  136. EXPORT_SYMBOL(iwl_rfkill_set_hw_state);