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
55 * @RFKILL_OP_ADD: a device was added
56 * @RFKILL_OP_DEL: a device was removed
57 * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device
58 * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all)
60 enum rfkill_operation
{
68 * struct rfkill_event - events for userspace on /dev/rfkill
69 * @idx: index of dev rfkill
70 * @type: type of the rfkill struct
72 * @hard: hard state (0/1)
73 * @soft: soft state (0/1)
75 * Structure used for userspace communication on /dev/rfkill,
76 * used for events from the kernel and control to the kernel.
85 /* ioctl for turning off rfkill-input (if present) */
86 #define RFKILL_IOC_MAGIC 'R'
87 #define RFKILL_IOC_NOINPUT 1
88 #define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT)
90 /* and that's all userspace gets */
92 /* don't allow anyone to use these in the kernel */
93 enum rfkill_user_states
{
94 RFKILL_USER_STATE_SOFT_BLOCKED
= RFKILL_STATE_SOFT_BLOCKED
,
95 RFKILL_USER_STATE_UNBLOCKED
= RFKILL_STATE_UNBLOCKED
,
96 RFKILL_USER_STATE_HARD_BLOCKED
= RFKILL_STATE_HARD_BLOCKED
,
98 #undef RFKILL_STATE_SOFT_BLOCKED
99 #undef RFKILL_STATE_UNBLOCKED
100 #undef RFKILL_STATE_HARD_BLOCKED
102 #include <linux/types.h>
103 #include <linux/kernel.h>
104 #include <linux/list.h>
105 #include <linux/mutex.h>
106 #include <linux/device.h>
107 #include <linux/leds.h>
108 #include <linux/err.h>
114 * struct rfkill_ops - rfkill driver methods
116 * @poll: poll the rfkill block state(s) -- only assign this method
117 * when you need polling. When called, simply call one of the
118 * rfkill_set{,_hw,_sw}_state family of functions. If the hw
119 * is getting unblocked you need to take into account the return
120 * value of those functions to make sure the software block is
122 * @query: query the rfkill block state(s) and call exactly one of the
123 * rfkill_set{,_hw,_sw}_state family of functions. Assign this
124 * method if input events can cause hardware state changes to make
125 * the rfkill core query your driver before setting a requested
127 * @set_block: turn the transmitter on (blocked == false) or off
128 * (blocked == true) -- ignore and return 0 when hard blocked.
129 * This callback must be assigned.
132 void (*poll
)(struct rfkill
*rfkill
, void *data
);
133 void (*query
)(struct rfkill
*rfkill
, void *data
);
134 int (*set_block
)(void *data
, bool blocked
);
137 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
139 * rfkill_alloc - allocate rfkill structure
140 * @name: name of the struct -- the string is not copied internally
141 * @parent: device that has rf switch on it
142 * @type: type of the switch (RFKILL_TYPE_*)
143 * @ops: rfkill methods
144 * @ops_data: data passed to each method
146 * This function should be called by the transmitter driver to allocate an
147 * rfkill structure. Returns %NULL on failure.
149 struct rfkill
* __must_check
rfkill_alloc(const char *name
,
150 struct device
*parent
,
151 const enum rfkill_type type
,
152 const struct rfkill_ops
*ops
,
156 * rfkill_register - Register a rfkill structure.
157 * @rfkill: rfkill structure to be registered
159 * This function should be called by the transmitter driver to register
160 * the rfkill structure needs to be registered. Before calling this function
161 * the driver needs to be ready to service method calls from rfkill.
163 int __must_check
rfkill_register(struct rfkill
*rfkill
);
166 * rfkill_pause_polling(struct rfkill *rfkill)
168 * Pause polling -- say transmitter is off for other reasons.
169 * NOTE: not necessary for suspend/resume -- in that case the
170 * core stops polling anyway
172 void rfkill_pause_polling(struct rfkill
*rfkill
);
175 * rfkill_resume_polling(struct rfkill *rfkill)
177 * Pause polling -- say transmitter is off for other reasons.
178 * NOTE: not necessary for suspend/resume -- in that case the
179 * core stops polling anyway
181 void rfkill_resume_polling(struct rfkill
*rfkill
);
185 * rfkill_unregister - Unregister a rfkill structure.
186 * @rfkill: rfkill structure to be unregistered
188 * This function should be called by the network driver during device
189 * teardown to destroy rfkill structure. Until it returns, the driver
190 * needs to be able to service method calls.
192 void rfkill_unregister(struct rfkill
*rfkill
);
195 * rfkill_destroy - free rfkill structure
196 * @rfkill: rfkill structure to be destroyed
198 * Destroys the rfkill structure.
200 void rfkill_destroy(struct rfkill
*rfkill
);
203 * rfkill_set_hw_state - Set the internal rfkill hardware block state
204 * @rfkill: pointer to the rfkill class to modify.
205 * @state: the current hardware block state to set
207 * rfkill drivers that get events when the hard-blocked state changes
208 * use this function to notify the rfkill core (and through that also
209 * userspace) of the current state -- they should also use this after
210 * resume if the state could have changed.
212 * You need not (but may) call this function if poll_state is assigned.
214 * This function can be called in any context, even from within rfkill
217 * The function returns the combined block state (true if transmitter
218 * should be blocked) so that drivers need not keep track of the soft
219 * block state -- which they might not be able to.
221 bool __must_check
rfkill_set_hw_state(struct rfkill
*rfkill
, bool blocked
);
224 * rfkill_set_sw_state - Set the internal rfkill software block state
225 * @rfkill: pointer to the rfkill class to modify.
226 * @state: the current software block state to set
228 * rfkill drivers that get events when the soft-blocked state changes
229 * (yes, some platforms directly act on input but allow changing again)
230 * use this function to notify the rfkill core (and through that also
231 * userspace) of the current state -- they should also use this after
232 * resume if the state could have changed.
234 * This function can be called in any context, even from within rfkill
237 * The function returns the combined block state (true if transmitter
238 * should be blocked).
240 bool rfkill_set_sw_state(struct rfkill
*rfkill
, bool blocked
);
243 * rfkill_set_states - Set the internal rfkill block states
244 * @rfkill: pointer to the rfkill class to modify.
245 * @sw: the current software block state to set
246 * @hw: the current hardware block state to set
248 * This function can be called in any context, even from within rfkill
251 void rfkill_set_states(struct rfkill
*rfkill
, bool sw
, bool hw
);
254 * rfkill_set_global_sw_state - set global sw block default
255 * @type: rfkill type to set default for
256 * @blocked: default to set
258 * This function sets the global default -- use at boot if your platform has
259 * an rfkill switch. If not early enough this call may be ignored.
261 * XXX: instead of ignoring -- how about just updating all currently
262 * registered drivers?
264 void rfkill_set_global_sw_state(const enum rfkill_type type
, bool blocked
);
267 * rfkill_blocked - query rfkill block
269 * @rfkill: rfkill struct to query
271 bool rfkill_blocked(struct rfkill
*rfkill
);
273 static inline struct rfkill
* __must_check
274 rfkill_alloc(const char *name
,
275 struct device
*parent
,
276 const enum rfkill_type type
,
277 const struct rfkill_ops
*ops
,
280 return ERR_PTR(-ENODEV
);
283 static inline int __must_check
rfkill_register(struct rfkill
*rfkill
)
285 if (rfkill
== ERR_PTR(-ENODEV
))
290 static inline void rfkill_pause_polling(struct rfkill
*rfkill
)
294 static inline void rfkill_resume_polling(struct rfkill
*rfkill
)
298 static inline void rfkill_unregister(struct rfkill
*rfkill
)
302 static inline void rfkill_destroy(struct rfkill
*rfkill
)
306 static inline bool rfkill_set_hw_state(struct rfkill
*rfkill
, bool blocked
)
311 static inline bool rfkill_set_sw_state(struct rfkill
*rfkill
, bool blocked
)
316 static inline void rfkill_set_states(struct rfkill
*rfkill
, bool sw
, bool hw
)
320 static inline void rfkill_set_global_sw_state(const enum rfkill_type type
,
325 static inline bool rfkill_blocked(struct rfkill
*rfkill
)
329 #endif /* RFKILL || RFKILL_MODULE */
332 #ifdef CONFIG_RFKILL_LEDS
334 * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED.
335 * This function might return a NULL pointer if registering of the
336 * LED trigger failed. Use this as "default_trigger" for the LED.
338 const char *rfkill_get_led_trigger_name(struct rfkill
*rfkill
);
341 * rfkill_set_led_trigger_name -- set the LED trigger name
342 * @rfkill: rfkill struct
343 * @name: LED trigger name
345 * This function sets the LED trigger name of the radio LED
346 * trigger that rfkill creates. It is optional, but if called
347 * must be called before rfkill_register() to be effective.
349 void rfkill_set_led_trigger_name(struct rfkill
*rfkill
, const char *name
);
351 static inline const char *rfkill_get_led_trigger_name(struct rfkill
*rfkill
)
357 rfkill_set_led_trigger_name(struct rfkill
*rfkill
, const char *name
)
362 #endif /* __KERNEL__ */
364 #endif /* RFKILL_H */