![]() |
|
|||
0001 /* 0002 * Copyright (C) 2006 - 2007 Ivo van Doorn 0003 * Copyright (C) 2007 Dmitry Torokhov 0004 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> 0005 * 0006 * Permission to use, copy, modify, and/or distribute this software for any 0007 * purpose with or without fee is hereby granted, provided that the above 0008 * copyright notice and this permission notice appear in all copies. 0009 * 0010 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 0011 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 0012 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 0013 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 0014 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 0015 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 0016 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 0017 */ 0018 #ifndef __RFKILL_H 0019 #define __RFKILL_H 0020 0021 #include <uapi/linux/rfkill.h> 0022 0023 /* don't allow anyone to use these in the kernel */ 0024 enum rfkill_user_states { 0025 RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED, 0026 RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED, 0027 RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED, 0028 }; 0029 #undef RFKILL_STATE_SOFT_BLOCKED 0030 #undef RFKILL_STATE_UNBLOCKED 0031 #undef RFKILL_STATE_HARD_BLOCKED 0032 0033 #include <linux/kernel.h> 0034 #include <linux/list.h> 0035 #include <linux/mutex.h> 0036 #include <linux/leds.h> 0037 #include <linux/err.h> 0038 0039 struct device; 0040 /* this is opaque */ 0041 struct rfkill; 0042 0043 /** 0044 * struct rfkill_ops - rfkill driver methods 0045 * 0046 * @poll: poll the rfkill block state(s) -- only assign this method 0047 * when you need polling. When called, simply call one of the 0048 * rfkill_set{,_hw,_sw}_state family of functions. If the hw 0049 * is getting unblocked you need to take into account the return 0050 * value of those functions to make sure the software block is 0051 * properly used. 0052 * @query: query the rfkill block state(s) and call exactly one of the 0053 * rfkill_set{,_hw,_sw}_state family of functions. Assign this 0054 * method if input events can cause hardware state changes to make 0055 * the rfkill core query your driver before setting a requested 0056 * block. 0057 * @set_block: turn the transmitter on (blocked == false) or off 0058 * (blocked == true) -- ignore and return 0 when hard blocked. 0059 * This callback must be assigned. 0060 */ 0061 struct rfkill_ops { 0062 void (*poll)(struct rfkill *rfkill, void *data); 0063 void (*query)(struct rfkill *rfkill, void *data); 0064 int (*set_block)(void *data, bool blocked); 0065 }; 0066 0067 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) 0068 /** 0069 * rfkill_alloc - Allocate rfkill structure 0070 * @name: name of the struct -- the string is not copied internally 0071 * @parent: device that has rf switch on it 0072 * @type: type of the switch (RFKILL_TYPE_*) 0073 * @ops: rfkill methods 0074 * @ops_data: data passed to each method 0075 * 0076 * This function should be called by the transmitter driver to allocate an 0077 * rfkill structure. Returns %NULL on failure. 0078 */ 0079 struct rfkill * __must_check rfkill_alloc(const char *name, 0080 struct device *parent, 0081 const enum rfkill_type type, 0082 const struct rfkill_ops *ops, 0083 void *ops_data); 0084 0085 /** 0086 * rfkill_register - Register a rfkill structure. 0087 * @rfkill: rfkill structure to be registered 0088 * 0089 * This function should be called by the transmitter driver to register 0090 * the rfkill structure. Before calling this function the driver needs 0091 * to be ready to service method calls from rfkill. 0092 * 0093 * If rfkill_init_sw_state() is not called before registration, 0094 * set_block() will be called to initialize the software blocked state 0095 * to a default value. 0096 * 0097 * If the hardware blocked state is not set before registration, 0098 * it is assumed to be unblocked. 0099 */ 0100 int __must_check rfkill_register(struct rfkill *rfkill); 0101 0102 /** 0103 * rfkill_pause_polling(struct rfkill *rfkill) 0104 * 0105 * Pause polling -- say transmitter is off for other reasons. 0106 * NOTE: not necessary for suspend/resume -- in that case the 0107 * core stops polling anyway (but will also correctly handle 0108 * the case of polling having been paused before suspend.) 0109 */ 0110 void rfkill_pause_polling(struct rfkill *rfkill); 0111 0112 /** 0113 * rfkill_resume_polling(struct rfkill *rfkill) 0114 * 0115 * Resume polling 0116 * NOTE: not necessary for suspend/resume -- in that case the 0117 * core stops polling anyway 0118 */ 0119 void rfkill_resume_polling(struct rfkill *rfkill); 0120 0121 0122 /** 0123 * rfkill_unregister - Unregister a rfkill structure. 0124 * @rfkill: rfkill structure to be unregistered 0125 * 0126 * This function should be called by the network driver during device 0127 * teardown to destroy rfkill structure. Until it returns, the driver 0128 * needs to be able to service method calls. 0129 */ 0130 void rfkill_unregister(struct rfkill *rfkill); 0131 0132 /** 0133 * rfkill_destroy - Free rfkill structure 0134 * @rfkill: rfkill structure to be destroyed 0135 * 0136 * Destroys the rfkill structure. 0137 */ 0138 void rfkill_destroy(struct rfkill *rfkill); 0139 0140 /** 0141 * rfkill_set_hw_state_reason - Set the internal rfkill hardware block state 0142 * with a reason 0143 * @rfkill: pointer to the rfkill class to modify. 0144 * @blocked: the current hardware block state to set 0145 * @reason: one of &enum rfkill_hard_block_reasons 0146 * 0147 * Prefer to use rfkill_set_hw_state if you don't need any special reason. 0148 */ 0149 bool rfkill_set_hw_state_reason(struct rfkill *rfkill, 0150 bool blocked, unsigned long reason); 0151 /** 0152 * rfkill_set_hw_state - Set the internal rfkill hardware block state 0153 * @rfkill: pointer to the rfkill class to modify. 0154 * @blocked: the current hardware block state to set 0155 * 0156 * rfkill drivers that get events when the hard-blocked state changes 0157 * use this function to notify the rfkill core (and through that also 0158 * userspace) of the current state. They should also use this after 0159 * resume if the state could have changed. 0160 * 0161 * You need not (but may) call this function if poll_state is assigned. 0162 * 0163 * This function can be called in any context, even from within rfkill 0164 * callbacks. 0165 * 0166 * The function returns the combined block state (true if transmitter 0167 * should be blocked) so that drivers need not keep track of the soft 0168 * block state -- which they might not be able to. 0169 */ 0170 static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked) 0171 { 0172 return rfkill_set_hw_state_reason(rfkill, blocked, 0173 RFKILL_HARD_BLOCK_SIGNAL); 0174 } 0175 0176 /** 0177 * rfkill_set_sw_state - Set the internal rfkill software block state 0178 * @rfkill: pointer to the rfkill class to modify. 0179 * @blocked: the current software block state to set 0180 * 0181 * rfkill drivers that get events when the soft-blocked state changes 0182 * (yes, some platforms directly act on input but allow changing again) 0183 * use this function to notify the rfkill core (and through that also 0184 * userspace) of the current state. 0185 * 0186 * Drivers should also call this function after resume if the state has 0187 * been changed by the user. This only makes sense for "persistent" 0188 * devices (see rfkill_init_sw_state()). 0189 * 0190 * This function can be called in any context, even from within rfkill 0191 * callbacks. 0192 * 0193 * The function returns the combined block state (true if transmitter 0194 * should be blocked). 0195 */ 0196 bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked); 0197 0198 /** 0199 * rfkill_init_sw_state - Initialize persistent software block state 0200 * @rfkill: pointer to the rfkill class to modify. 0201 * @blocked: the current software block state to set 0202 * 0203 * rfkill drivers that preserve their software block state over power off 0204 * use this function to notify the rfkill core (and through that also 0205 * userspace) of their initial state. It should only be used before 0206 * registration. 0207 * 0208 * In addition, it marks the device as "persistent", an attribute which 0209 * can be read by userspace. Persistent devices are expected to preserve 0210 * their own state when suspended. 0211 */ 0212 void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked); 0213 0214 /** 0215 * rfkill_set_states - Set the internal rfkill block states 0216 * @rfkill: pointer to the rfkill class to modify. 0217 * @sw: the current software block state to set 0218 * @hw: the current hardware block state to set 0219 * 0220 * This function can be called in any context, even from within rfkill 0221 * callbacks. 0222 */ 0223 void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw); 0224 0225 /** 0226 * rfkill_blocked - Query rfkill block state 0227 * 0228 * @rfkill: rfkill struct to query 0229 */ 0230 bool rfkill_blocked(struct rfkill *rfkill); 0231 0232 /** 0233 * rfkill_soft_blocked - Query soft rfkill block state 0234 * 0235 * @rfkill: rfkill struct to query 0236 */ 0237 bool rfkill_soft_blocked(struct rfkill *rfkill); 0238 0239 /** 0240 * rfkill_find_type - Helper for finding rfkill type by name 0241 * @name: the name of the type 0242 * 0243 * Returns enum rfkill_type that corresponds to the name. 0244 */ 0245 enum rfkill_type rfkill_find_type(const char *name); 0246 0247 #else /* !RFKILL */ 0248 static inline struct rfkill * __must_check 0249 rfkill_alloc(const char *name, 0250 struct device *parent, 0251 const enum rfkill_type type, 0252 const struct rfkill_ops *ops, 0253 void *ops_data) 0254 { 0255 return ERR_PTR(-ENODEV); 0256 } 0257 0258 static inline int __must_check rfkill_register(struct rfkill *rfkill) 0259 { 0260 if (rfkill == ERR_PTR(-ENODEV)) 0261 return 0; 0262 return -EINVAL; 0263 } 0264 0265 static inline void rfkill_pause_polling(struct rfkill *rfkill) 0266 { 0267 } 0268 0269 static inline void rfkill_resume_polling(struct rfkill *rfkill) 0270 { 0271 } 0272 0273 static inline void rfkill_unregister(struct rfkill *rfkill) 0274 { 0275 } 0276 0277 static inline void rfkill_destroy(struct rfkill *rfkill) 0278 { 0279 } 0280 0281 static inline bool rfkill_set_hw_state_reason(struct rfkill *rfkill, 0282 bool blocked, 0283 unsigned long reason) 0284 { 0285 return blocked; 0286 } 0287 0288 static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked) 0289 { 0290 return blocked; 0291 } 0292 0293 static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked) 0294 { 0295 return blocked; 0296 } 0297 0298 static inline void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked) 0299 { 0300 } 0301 0302 static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw) 0303 { 0304 } 0305 0306 static inline bool rfkill_blocked(struct rfkill *rfkill) 0307 { 0308 return false; 0309 } 0310 0311 static inline bool rfkill_soft_blocked(struct rfkill *rfkill) 0312 { 0313 return false; 0314 } 0315 0316 static inline enum rfkill_type rfkill_find_type(const char *name) 0317 { 0318 return RFKILL_TYPE_ALL; 0319 } 0320 0321 #endif /* RFKILL || RFKILL_MODULE */ 0322 0323 0324 #ifdef CONFIG_RFKILL_LEDS 0325 /** 0326 * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED. 0327 * This function might return a NULL pointer if registering of the 0328 * LED trigger failed. Use this as "default_trigger" for the LED. 0329 */ 0330 const char *rfkill_get_led_trigger_name(struct rfkill *rfkill); 0331 0332 /** 0333 * rfkill_set_led_trigger_name - Set the LED trigger name 0334 * @rfkill: rfkill struct 0335 * @name: LED trigger name 0336 * 0337 * This function sets the LED trigger name of the radio LED 0338 * trigger that rfkill creates. It is optional, but if called 0339 * must be called before rfkill_register() to be effective. 0340 */ 0341 void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name); 0342 #else 0343 static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill) 0344 { 0345 return NULL; 0346 } 0347 0348 static inline void 0349 rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name) 0350 { 0351 } 0352 #endif 0353 0354 #endif /* RFKILL_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |