rfkill.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Intel Wireless Multicomm 3200 WiFi driver
  3. *
  4. * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com>
  5. * Samuel Ortiz <samuel.ortiz@intel.com>
  6. * Zhu Yi <yi.zhu@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. */
  23. #include <linux/rfkill.h>
  24. #include "iwm.h"
  25. static int iwm_rfkill_soft_toggle(void *data, enum rfkill_state state)
  26. {
  27. struct iwm_priv *iwm = data;
  28. switch (state) {
  29. case RFKILL_STATE_UNBLOCKED:
  30. if (test_bit(IWM_RADIO_RFKILL_HW, &iwm->radio))
  31. return -EBUSY;
  32. if (test_and_clear_bit(IWM_RADIO_RFKILL_SW, &iwm->radio) &&
  33. (iwm_to_ndev(iwm)->flags & IFF_UP))
  34. iwm_up(iwm);
  35. break;
  36. case RFKILL_STATE_SOFT_BLOCKED:
  37. if (!test_and_set_bit(IWM_RADIO_RFKILL_SW, &iwm->radio))
  38. iwm_down(iwm);
  39. break;
  40. default:
  41. break;
  42. }
  43. return 0;
  44. }
  45. int iwm_rfkill_init(struct iwm_priv *iwm)
  46. {
  47. int ret;
  48. iwm->rfkill = rfkill_allocate(iwm_to_dev(iwm), RFKILL_TYPE_WLAN);
  49. if (!iwm->rfkill) {
  50. IWM_ERR(iwm, "Unable to allocate rfkill device\n");
  51. return -ENOMEM;
  52. }
  53. iwm->rfkill->name = KBUILD_MODNAME;
  54. iwm->rfkill->data = iwm;
  55. iwm->rfkill->state = RFKILL_STATE_UNBLOCKED;
  56. iwm->rfkill->toggle_radio = iwm_rfkill_soft_toggle;
  57. ret = rfkill_register(iwm->rfkill);
  58. if (ret) {
  59. IWM_ERR(iwm, "Failed to register rfkill device\n");
  60. goto fail;
  61. }
  62. return 0;
  63. fail:
  64. rfkill_free(iwm->rfkill);
  65. return ret;
  66. }
  67. void iwm_rfkill_exit(struct iwm_priv *iwm)
  68. {
  69. if (iwm->rfkill)
  70. rfkill_unregister(iwm->rfkill);
  71. rfkill_free(iwm->rfkill);
  72. iwm->rfkill = NULL;
  73. }