5 * Copyright (C) 2006 - 2007 Ivo van Doorn
6 * Copyright (C) 2007 Dmitry Torokhov
7 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the
21 * Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <linux/types.h>
27 /* define userspace visible states */
28 #define RFKILL_STATE_SOFT_BLOCKED 0
29 #define RFKILL_STATE_UNBLOCKED 1
30 #define RFKILL_STATE_HARD_BLOCKED 2
33 * enum rfkill_type - type of rfkill switch.
35 * @RFKILL_TYPE_ALL: toggles all switches (userspace only)
36 * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
37 * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
38 * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
39 * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
40 * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
41 * @NUM_RFKILL_TYPES: number of defined rfkill types
46 RFKILL_TYPE_BLUETOOTH
,
54 * enum rfkill_operation - operation types
56 enum rfkill_operation
{
63 * struct rfkill_event - events for userspace on /dev/rfkill
64 * @len: length of this structure
65 * @idx: index of dev rfkill
66 * @type: type of the rfkill struct
68 * @hard: hard state (0/1)
69 * @soft: soft state (0/1)
81 /* and that's all userspace gets */
83 /* don't allow anyone to use these in the kernel */
84 enum rfkill_user_states
{
85 RFKILL_USER_STATE_SOFT_BLOCKED
= RFKILL_STATE_SOFT_BLOCKED
,
86 RFKILL_USER_STATE_UNBLOCKED
= RFKILL_STATE_UNBLOCKED
,
87 RFKILL_USER_STATE_HARD_BLOCKED
= RFKILL_STATE_HARD_BLOCKED
,
89 #undef RFKILL_STATE_SOFT_BLOCKED
90 #undef RFKILL_STATE_UNBLOCKED
91 #undef RFKILL_STATE_HARD_BLOCKED
93 #include <linux/types.h>
94 #include <linux/kernel.h>
95 #include <linux/list.h>
96 #include <linux/mutex.h>
97 #include <linux/device.h>
98 #include <linux/leds.h>
104 * struct rfkill_ops - rfkill driver methods
106 * @poll: poll the rfkill block state(s) -- only assign this method
107 * when you need polling. When called, simply call one of the
108 * rfkill_set{,_hw,_sw}_state family of functions. If the hw
109 * is getting unblocked you need to take into account the return
110 * value of those functions to make sure the software block is
112 * @query: query the rfkill block state(s) and call exactly one of the
113 * rfkill_set{,_hw,_sw}_state family of functions. Assign this
114 * method if input events can cause hardware state changes to make
115 * the rfkill core query your driver before setting a requested
117 * @set_block: turn the transmitter on (blocked == false) or off
118 * (blocked == true) -- this is called only while the transmitter
119 * is not hard-blocked, but note that the core's view of whether
120 * the transmitter is hard-blocked might differ from your driver's
121 * view due to race conditions, so it is possible that it is still
122 * called at the same time as you are calling rfkill_set_hw_state().
123 * This callback must be assigned.
126 void (*poll
)(struct rfkill
*rfkill
, void *data
);
127 void (*query
)(struct rfkill
*rfkill
, void *data
);
128 int (*set_block
)(void *data
, bool blocked
);
131 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
133 * rfkill_alloc - allocate rfkill structure
134 * @name: name of the struct -- the string is not copied internally
135 * @parent: device that has rf switch on it
136 * @type: type of the switch (RFKILL_TYPE_*)
137 * @ops: rfkill methods
138 * @ops_data: data passed to each method
140 * This function should be called by the transmitter driver to allocate an
141 * rfkill structure. Returns %NULL on failure.
143 struct rfkill
* __must_check
rfkill_alloc(const char *name
,
144 struct device
*parent
,
145 const enum rfkill_type type
,
146 const struct rfkill_ops
*ops
,
150 * rfkill_register - Register a rfkill structure.
151 * @rfkill: rfkill structure to be registered
153 * This function should be called by the transmitter driver to register
154 * the rfkill structure needs to be registered. Before calling this function
155 * the driver needs to be ready to service method calls from rfkill.
157 int __must_check
rfkill_register(struct rfkill
*rfkill
);
160 * rfkill_pause_polling(struct rfkill *rfkill)
162 * Pause polling -- say transmitter is off for other reasons.
163 * NOTE: not necessary for suspend/resume -- in that case the
164 * core stops polling anyway
166 void rfkill_pause_polling(struct rfkill
*rfkill
);
169 * rfkill_resume_polling(struct rfkill *rfkill)
171 * Pause polling -- say transmitter is off for other reasons.
172 * NOTE: not necessary for suspend/resume -- in that case the
173 * core stops polling anyway
175 void rfkill_resume_polling(struct rfkill
*rfkill
);
179 * rfkill_unregister - Unregister a rfkill structure.
180 * @rfkill: rfkill structure to be unregistered
182 * This function should be called by the network driver during device
183 * teardown to destroy rfkill structure. Until it returns, the driver
184 * needs to be able to service method calls.
186 void rfkill_unregister(struct rfkill
*rfkill
);
189 * rfkill_destroy - free rfkill structure
190 * @rfkill: rfkill structure to be destroyed
192 * Destroys the rfkill structure.
194 void rfkill_destroy(struct rfkill
*rfkill
);
197 * rfkill_set_hw_state - Set the internal rfkill hardware block state
198 * @rfkill: pointer to the rfkill class to modify.
199 * @state: the current hardware block state to set
201 * rfkill drivers that get events when the hard-blocked state changes
202 * use this function to notify the rfkill core (and through that also
203 * userspace) of the current state -- they should also use this after
204 * resume if the state could have changed.
206 * You need not (but may) call this function if poll_state is assigned.
208 * This function can be called in any context, even from within rfkill
211 * The function returns the combined block state (true if transmitter
212 * should be blocked) so that drivers need not keep track of the soft
213 * block state -- which they might not be able to.
215 bool __must_check
rfkill_set_hw_state(struct rfkill
*rfkill
, bool blocked
);
218 * rfkill_set_sw_state - Set the internal rfkill software block state
219 * @rfkill: pointer to the rfkill class to modify.
220 * @state: the current software block state to set
222 * rfkill drivers that get events when the soft-blocked state changes
223 * (yes, some platforms directly act on input but allow changing again)
224 * use this function to notify the rfkill core (and through that also
225 * userspace) of the current state -- they should also use this after
226 * resume if the state could have changed.
228 * This function can be called in any context, even from within rfkill
231 * The function returns the combined block state (true if transmitter
232 * should be blocked).
234 bool rfkill_set_sw_state(struct rfkill
*rfkill
, bool blocked
);
237 * rfkill_set_states - Set the internal rfkill block states
238 * @rfkill: pointer to the rfkill class to modify.
239 * @sw: the current software block state to set
240 * @hw: the current hardware block state to set
242 * This function can be called in any context, even from within rfkill
245 void rfkill_set_states(struct rfkill
*rfkill
, bool sw
, bool hw
);
248 * rfkill_set_global_sw_state - set global sw block default
249 * @type: rfkill type to set default for
250 * @blocked: default to set
252 * This function sets the global default -- use at boot if your platform has
253 * an rfkill switch. If not early enough this call may be ignored.
255 * XXX: instead of ignoring -- how about just updating all currently
256 * registered drivers?
258 void rfkill_set_global_sw_state(const enum rfkill_type type
, bool blocked
);
261 * rfkill_blocked - query rfkill block
263 * @rfkill: rfkill struct to query
265 bool rfkill_blocked(struct rfkill
*rfkill
);
267 static inline struct rfkill
* __must_check
268 rfkill_alloc(const char *name
,
269 struct device
*parent
,
270 const enum rfkill_type type
,
271 const struct rfkill_ops
*ops
,
274 return ERR_PTR(-ENODEV
);
277 static inline int __must_check
rfkill_register(struct rfkill
*rfkill
)
279 if (rfkill
== ERR_PTR(-ENODEV
))
284 static inline void rfkill_pause_polling(struct rfkill
*rfkill
)
288 static inline void rfkill_resume_polling(struct rfkill
*rfkill
)
292 static inline void rfkill_unregister(struct rfkill
*rfkill
)
296 static inline void rfkill_destroy(struct rfkill
*rfkill
)
300 static inline bool rfkill_set_hw_state(struct rfkill
*rfkill
, bool blocked
)
305 static inline bool rfkill_set_sw_state(struct rfkill
*rfkill
, bool blocked
)
310 static inline void rfkill_set_states(struct rfkill
*rfkill
, bool sw
, bool hw
)
314 static inline void rfkill_set_global_sw_state(const enum rfkill_type type
,
319 static inline bool rfkill_blocked(struct rfkill
*rfkill
)
323 #endif /* RFKILL || RFKILL_MODULE */
326 #ifdef CONFIG_RFKILL_LEDS
328 * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED.
329 * This function might return a NULL pointer if registering of the
330 * LED trigger failed. Use this as "default_trigger" for the LED.
332 const char *rfkill_get_led_trigger_name(struct rfkill
*rfkill
);
335 * rfkill_set_led_trigger_name -- set the LED trigger name
336 * @rfkill: rfkill struct
337 * @name: LED trigger name
339 * This function sets the LED trigger name of the radio LED
340 * trigger that rfkill creates. It is optional, but if called
341 * must be called before rfkill_register() to be effective.
343 void rfkill_set_led_trigger_name(struct rfkill
*rfkill
, const char *name
);
345 static inline const char *rfkill_get_led_trigger_name(struct rfkill
*rfkill
)
351 rfkill_set_led_trigger_name(struct rfkill
*rfkill
, const char *name
)
356 #endif /* __KERNEL__ */
358 #endif /* RFKILL_H */