rfkill.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef __RFKILL_H
  2. #define __RFKILL_H
  3. /*
  4. * Copyright (C) 2006 - 2007 Ivo van Doorn
  5. * Copyright (C) 2007 Dmitry Torokhov
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  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
  19. * Free Software Foundation, Inc.,
  20. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. #include <linux/types.h>
  23. #include <linux/kernel.h>
  24. #include <linux/list.h>
  25. #include <linux/mutex.h>
  26. #include <linux/device.h>
  27. #include <linux/leds.h>
  28. /**
  29. * enum rfkill_type - type of rfkill switch.
  30. * RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
  31. * RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
  32. * RFKILL_TYPE_UWB: switch is on a ultra wideband device.
  33. */
  34. enum rfkill_type {
  35. RFKILL_TYPE_WLAN ,
  36. RFKILL_TYPE_BLUETOOTH,
  37. RFKILL_TYPE_UWB,
  38. RFKILL_TYPE_MAX,
  39. };
  40. enum rfkill_state {
  41. RFKILL_STATE_OFF = 0,
  42. RFKILL_STATE_ON = 1,
  43. };
  44. /**
  45. * struct rfkill - rfkill control structure.
  46. * @name: Name of the switch.
  47. * @type: Radio type which the button controls, the value stored
  48. * here should be a value from enum rfkill_type.
  49. * @state: State of the switch (on/off).
  50. * @user_claim_unsupported: Whether the hardware supports exclusive
  51. * RF-kill control by userspace. Set this before registering.
  52. * @user_claim: Set when the switch is controlled exlusively by userspace.
  53. * @mutex: Guards switch state transitions
  54. * @data: Pointer to the RF button drivers private data which will be
  55. * passed along when toggling radio state.
  56. * @toggle_radio(): Mandatory handler to control state of the radio.
  57. * @led_trigger: A LED trigger for this button's LED.
  58. * @dev: Device structure integrating the switch into device tree.
  59. * @node: Used to place switch into list of all switches known to the
  60. * the system.
  61. *
  62. * This structure represents a RF switch located on a network device.
  63. */
  64. struct rfkill {
  65. const char *name;
  66. enum rfkill_type type;
  67. enum rfkill_state state;
  68. bool user_claim_unsupported;
  69. bool user_claim;
  70. struct mutex mutex;
  71. void *data;
  72. int (*toggle_radio)(void *data, enum rfkill_state state);
  73. #ifdef CONFIG_RFKILL_LEDS
  74. struct led_trigger led_trigger;
  75. #endif
  76. struct device dev;
  77. struct list_head node;
  78. };
  79. #define to_rfkill(d) container_of(d, struct rfkill, dev)
  80. struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type);
  81. void rfkill_free(struct rfkill *rfkill);
  82. int rfkill_register(struct rfkill *rfkill);
  83. void rfkill_unregister(struct rfkill *rfkill);
  84. /**
  85. * rfkill_get_led_name - Get the LED trigger name for the button's LED.
  86. * This function might return a NULL pointer if registering of the
  87. * LED trigger failed.
  88. * Use this as "default_trigger" for the LED.
  89. */
  90. static inline char *rfkill_get_led_name(struct rfkill *rfkill)
  91. {
  92. #ifdef CONFIG_RFKILL_LEDS
  93. return (char *)(rfkill->led_trigger.name);
  94. #else
  95. return NULL;
  96. #endif
  97. }
  98. #endif /* RFKILL_H */