/include/linux/rfkill.h

https://github.com/airy09/android_kernel_sony_apq8064 · C Header · 362 lines · 123 code · 35 blank · 204 comment · 3 complexity · e2c07e3391a22a99c8e7f0a81b4e5a81 MD5 · raw file

  1. #ifndef __RFKILL_H
  2. #define __RFKILL_H
  3. /*
  4. * Copyright (C) 2006 - 2007 Ivo van Doorn
  5. * Copyright (C) 2007 Dmitry Torokhov
  6. * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
  7. *
  8. * Permission to use, copy, modify, and/or distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. */
  20. #include <linux/types.h>
  21. /* define userspace visible states */
  22. #define RFKILL_STATE_SOFT_BLOCKED 0
  23. #define RFKILL_STATE_UNBLOCKED 1
  24. #define RFKILL_STATE_HARD_BLOCKED 2
  25. /**
  26. * enum rfkill_type - type of rfkill switch.
  27. *
  28. * @RFKILL_TYPE_ALL: toggles all switches (requests only - not a switch type)
  29. * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
  30. * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
  31. * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
  32. * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
  33. * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
  34. * @RFKILL_TYPE_GPS: switch is on a GPS device.
  35. * @RFKILL_TYPE_FM: switch is on a FM radio device.
  36. * @NUM_RFKILL_TYPES: number of defined rfkill types
  37. */
  38. enum rfkill_type {
  39. RFKILL_TYPE_ALL = 0,
  40. RFKILL_TYPE_WLAN,
  41. RFKILL_TYPE_BLUETOOTH,
  42. RFKILL_TYPE_UWB,
  43. RFKILL_TYPE_WIMAX,
  44. RFKILL_TYPE_WWAN,
  45. RFKILL_TYPE_GPS,
  46. RFKILL_TYPE_FM,
  47. NUM_RFKILL_TYPES,
  48. };
  49. /**
  50. * enum rfkill_operation - operation types
  51. * @RFKILL_OP_ADD: a device was added
  52. * @RFKILL_OP_DEL: a device was removed
  53. * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device
  54. * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all)
  55. */
  56. enum rfkill_operation {
  57. RFKILL_OP_ADD = 0,
  58. RFKILL_OP_DEL,
  59. RFKILL_OP_CHANGE,
  60. RFKILL_OP_CHANGE_ALL,
  61. };
  62. /**
  63. * struct rfkill_event - events for userspace on /dev/rfkill
  64. * @idx: index of dev rfkill
  65. * @type: type of the rfkill struct
  66. * @op: operation code
  67. * @hard: hard state (0/1)
  68. * @soft: soft state (0/1)
  69. *
  70. * Structure used for userspace communication on /dev/rfkill,
  71. * used for events from the kernel and control to the kernel.
  72. */
  73. struct rfkill_event {
  74. __u32 idx;
  75. __u8 type;
  76. __u8 op;
  77. __u8 soft, hard;
  78. } __attribute__((packed));
  79. /*
  80. * We are planning to be backward and forward compatible with changes
  81. * to the event struct, by adding new, optional, members at the end.
  82. * When reading an event (whether the kernel from userspace or vice
  83. * versa) we need to accept anything that's at least as large as the
  84. * version 1 event size, but might be able to accept other sizes in
  85. * the future.
  86. *
  87. * One exception is the kernel -- we already have two event sizes in
  88. * that we've made the 'hard' member optional since our only option
  89. * is to ignore it anyway.
  90. */
  91. #define RFKILL_EVENT_SIZE_V1 8
  92. /* ioctl for turning off rfkill-input (if present) */
  93. #define RFKILL_IOC_MAGIC 'R'
  94. #define RFKILL_IOC_NOINPUT 1
  95. #define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT)
  96. /* and that's all userspace gets */
  97. #ifdef __KERNEL__
  98. /* don't allow anyone to use these in the kernel */
  99. enum rfkill_user_states {
  100. RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED,
  101. RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED,
  102. RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED,
  103. };
  104. #undef RFKILL_STATE_SOFT_BLOCKED
  105. #undef RFKILL_STATE_UNBLOCKED
  106. #undef RFKILL_STATE_HARD_BLOCKED
  107. #include <linux/kernel.h>
  108. #include <linux/list.h>
  109. #include <linux/mutex.h>
  110. #include <linux/leds.h>
  111. #include <linux/err.h>
  112. struct device;
  113. /* this is opaque */
  114. struct rfkill;
  115. /**
  116. * struct rfkill_ops - rfkill driver methods
  117. *
  118. * @poll: poll the rfkill block state(s) -- only assign this method
  119. * when you need polling. When called, simply call one of the
  120. * rfkill_set{,_hw,_sw}_state family of functions. If the hw
  121. * is getting unblocked you need to take into account the return
  122. * value of those functions to make sure the software block is
  123. * properly used.
  124. * @query: query the rfkill block state(s) and call exactly one of the
  125. * rfkill_set{,_hw,_sw}_state family of functions. Assign this
  126. * method if input events can cause hardware state changes to make
  127. * the rfkill core query your driver before setting a requested
  128. * block.
  129. * @set_block: turn the transmitter on (blocked == false) or off
  130. * (blocked == true) -- ignore and return 0 when hard blocked.
  131. * This callback must be assigned.
  132. */
  133. struct rfkill_ops {
  134. void (*poll)(struct rfkill *rfkill, void *data);
  135. void (*query)(struct rfkill *rfkill, void *data);
  136. int (*set_block)(void *data, bool blocked);
  137. };
  138. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  139. /**
  140. * rfkill_alloc - allocate rfkill structure
  141. * @name: name of the struct -- the string is not copied internally
  142. * @parent: device that has rf switch on it
  143. * @type: type of the switch (RFKILL_TYPE_*)
  144. * @ops: rfkill methods
  145. * @ops_data: data passed to each method
  146. *
  147. * This function should be called by the transmitter driver to allocate an
  148. * rfkill structure. Returns %NULL on failure.
  149. */
  150. struct rfkill * __must_check rfkill_alloc(const char *name,
  151. struct device *parent,
  152. const enum rfkill_type type,
  153. const struct rfkill_ops *ops,
  154. void *ops_data);
  155. /**
  156. * rfkill_register - Register a rfkill structure.
  157. * @rfkill: rfkill structure to be registered
  158. *
  159. * This function should be called by the transmitter driver to register
  160. * the rfkill structure. Before calling this function the driver needs
  161. * to be ready to service method calls from rfkill.
  162. *
  163. * If rfkill_init_sw_state() is not called before registration,
  164. * set_block() will be called to initialize the software blocked state
  165. * to a default value.
  166. *
  167. * If the hardware blocked state is not set before registration,
  168. * it is assumed to be unblocked.
  169. */
  170. int __must_check rfkill_register(struct rfkill *rfkill);
  171. /**
  172. * rfkill_pause_polling(struct rfkill *rfkill)
  173. *
  174. * Pause polling -- say transmitter is off for other reasons.
  175. * NOTE: not necessary for suspend/resume -- in that case the
  176. * core stops polling anyway
  177. */
  178. void rfkill_pause_polling(struct rfkill *rfkill);
  179. /**
  180. * rfkill_resume_polling(struct rfkill *rfkill)
  181. *
  182. * Pause polling -- say transmitter is off for other reasons.
  183. * NOTE: not necessary for suspend/resume -- in that case the
  184. * core stops polling anyway
  185. */
  186. #ifdef CONFIG_RFKILL_PM
  187. void rfkill_resume_polling(struct rfkill *rfkill);
  188. #else
  189. static inline void rfkill_resume_polling(struct rfkill *rfkill) { }
  190. #endif
  191. /**
  192. * rfkill_unregister - Unregister a rfkill structure.
  193. * @rfkill: rfkill structure to be unregistered
  194. *
  195. * This function should be called by the network driver during device
  196. * teardown to destroy rfkill structure. Until it returns, the driver
  197. * needs to be able to service method calls.
  198. */
  199. void rfkill_unregister(struct rfkill *rfkill);
  200. /**
  201. * rfkill_destroy - free rfkill structure
  202. * @rfkill: rfkill structure to be destroyed
  203. *
  204. * Destroys the rfkill structure.
  205. */
  206. void rfkill_destroy(struct rfkill *rfkill);
  207. /**
  208. * rfkill_set_hw_state - Set the internal rfkill hardware block state
  209. * @rfkill: pointer to the rfkill class to modify.
  210. * @state: the current hardware block state to set
  211. *
  212. * rfkill drivers that get events when the hard-blocked state changes
  213. * use this function to notify the rfkill core (and through that also
  214. * userspace) of the current state. They should also use this after
  215. * resume if the state could have changed.
  216. *
  217. * You need not (but may) call this function if poll_state is assigned.
  218. *
  219. * This function can be called in any context, even from within rfkill
  220. * callbacks.
  221. *
  222. * The function returns the combined block state (true if transmitter
  223. * should be blocked) so that drivers need not keep track of the soft
  224. * block state -- which they might not be able to.
  225. */
  226. bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked);
  227. /**
  228. * rfkill_set_sw_state - Set the internal rfkill software block state
  229. * @rfkill: pointer to the rfkill class to modify.
  230. * @state: the current software block state to set
  231. *
  232. * rfkill drivers that get events when the soft-blocked state changes
  233. * (yes, some platforms directly act on input but allow changing again)
  234. * use this function to notify the rfkill core (and through that also
  235. * userspace) of the current state.
  236. *
  237. * Drivers should also call this function after resume if the state has
  238. * been changed by the user. This only makes sense for "persistent"
  239. * devices (see rfkill_init_sw_state()).
  240. *
  241. * This function can be called in any context, even from within rfkill
  242. * callbacks.
  243. *
  244. * The function returns the combined block state (true if transmitter
  245. * should be blocked).
  246. */
  247. bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked);
  248. /**
  249. * rfkill_init_sw_state - Initialize persistent software block state
  250. * @rfkill: pointer to the rfkill class to modify.
  251. * @state: the current software block state to set
  252. *
  253. * rfkill drivers that preserve their software block state over power off
  254. * use this function to notify the rfkill core (and through that also
  255. * userspace) of their initial state. It should only be used before
  256. * registration.
  257. *
  258. * In addition, it marks the device as "persistent", an attribute which
  259. * can be read by userspace. Persistent devices are expected to preserve
  260. * their own state when suspended.
  261. */
  262. void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked);
  263. /**
  264. * rfkill_set_states - Set the internal rfkill block states
  265. * @rfkill: pointer to the rfkill class to modify.
  266. * @sw: the current software block state to set
  267. * @hw: the current hardware block state to set
  268. *
  269. * This function can be called in any context, even from within rfkill
  270. * callbacks.
  271. */
  272. void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
  273. /**
  274. * rfkill_blocked - query rfkill block
  275. *
  276. * @rfkill: rfkill struct to query
  277. */
  278. bool rfkill_blocked(struct rfkill *rfkill);
  279. #else /* !RFKILL */
  280. static inline struct rfkill * __must_check
  281. rfkill_alloc(const char *name,
  282. struct device *parent,
  283. const enum rfkill_type type,
  284. const struct rfkill_ops *ops,
  285. void *ops_data)
  286. {
  287. return ERR_PTR(-ENODEV);
  288. }
  289. static inline int __must_check rfkill_register(struct rfkill *rfkill)
  290. {
  291. if (rfkill == ERR_PTR(-ENODEV))
  292. return 0;
  293. return -EINVAL;
  294. }
  295. static inline void rfkill_pause_polling(struct rfkill *rfkill)
  296. {
  297. }
  298. static inline void rfkill_resume_polling(struct rfkill *rfkill)
  299. {
  300. }
  301. static inline void rfkill_unregister(struct rfkill *rfkill)
  302. {
  303. }
  304. static inline void rfkill_destroy(struct rfkill *rfkill)
  305. {
  306. }
  307. static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
  308. {
  309. return blocked;
  310. }
  311. static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
  312. {
  313. return blocked;
  314. }
  315. static inline void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked)
  316. {
  317. }
  318. static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
  319. {
  320. }
  321. static inline bool rfkill_blocked(struct rfkill *rfkill)
  322. {
  323. return false;
  324. }
  325. #endif /* RFKILL || RFKILL_MODULE */
  326. #endif /* __KERNEL__ */
  327. #endif /* RFKILL_H */