Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[RFKILL]: Add support for an rfkill LED.

This adds a LED trigger.

Signed-off-by: Michael Buesch <mb@bu3sch.de>
Acked-by: Ivo van Doorn <IvDoorn@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Michael Buesch and committed by
David S. Miller
135900c1 937a049d

+69 -1
+21
include/linux/rfkill.h
··· 26 26 #include <linux/list.h> 27 27 #include <linux/mutex.h> 28 28 #include <linux/device.h> 29 + #include <linux/leds.h> 29 30 30 31 /** 31 32 * enum rfkill_type - type of rfkill switch. ··· 57 56 * @data: Pointer to the RF button drivers private data which will be 58 57 * passed along when toggling radio state. 59 58 * @toggle_radio(): Mandatory handler to control state of the radio. 59 + * @led_trigger: A LED trigger for this button's LED. 60 60 * @dev: Device structure integrating the switch into device tree. 61 61 * @node: Used to place switch into list of all switches known to the 62 62 * the system. ··· 76 74 void *data; 77 75 int (*toggle_radio)(void *data, enum rfkill_state state); 78 76 77 + #ifdef CONFIG_RFKILL_LEDS 78 + struct led_trigger led_trigger; 79 + #endif 80 + 79 81 struct device dev; 80 82 struct list_head node; 81 83 }; ··· 89 83 void rfkill_free(struct rfkill *rfkill); 90 84 int rfkill_register(struct rfkill *rfkill); 91 85 void rfkill_unregister(struct rfkill *rfkill); 86 + 87 + /** 88 + * rfkill_get_led_name - Get the LED trigger name for the button's LED. 89 + * This function might return a NULL pointer if registering of the 90 + * LED trigger failed. 91 + * Use this as "default_trigger" for the LED. 92 + */ 93 + static inline char *rfkill_get_led_name(struct rfkill *rfkill) 94 + { 95 + #ifdef CONFIG_RFKILL_LEDS 96 + return (char *)(rfkill->led_trigger.name); 97 + #else 98 + return NULL; 99 + #endif 100 + } 92 101 93 102 #endif /* RFKILL_H */
+7
net/rfkill/Kconfig
··· 22 22 23 23 To compile this driver as a module, choose M here: the 24 24 module will be called rfkill-input. 25 + 26 + # LED trigger support 27 + config RFKILL_LEDS 28 + bool 29 + depends on RFKILL && LEDS_TRIGGERS 30 + default y 31 +
+41 -1
net/rfkill/rfkill.c
··· 37 37 38 38 static enum rfkill_state rfkill_states[RFKILL_TYPE_MAX]; 39 39 40 + 41 + static void rfkill_led_trigger(struct rfkill *rfkill, 42 + enum rfkill_state state) 43 + { 44 + #ifdef CONFIG_RFKILL_LEDS 45 + struct led_trigger *led = &rfkill->led_trigger; 46 + 47 + if (!led->name) 48 + return; 49 + if (state == RFKILL_STATE_OFF) 50 + led_trigger_event(led, LED_OFF); 51 + else 52 + led_trigger_event(led, LED_FULL); 53 + #endif /* CONFIG_RFKILL_LEDS */ 54 + } 55 + 40 56 static int rfkill_toggle_radio(struct rfkill *rfkill, 41 57 enum rfkill_state state) 42 58 { ··· 64 48 65 49 if (state != rfkill->state) { 66 50 retval = rfkill->toggle_radio(rfkill->data, state); 67 - if (!retval) 51 + if (!retval) { 68 52 rfkill->state = state; 53 + rfkill_led_trigger(rfkill, state); 54 + } 69 55 } 70 56 71 57 mutex_unlock(&rfkill->mutex); ··· 346 328 } 347 329 EXPORT_SYMBOL(rfkill_free); 348 330 331 + static void rfkill_led_trigger_register(struct rfkill *rfkill) 332 + { 333 + #ifdef CONFIG_RFKILL_LEDS 334 + int error; 335 + 336 + rfkill->led_trigger.name = rfkill->dev.bus_id; 337 + error = led_trigger_register(&rfkill->led_trigger); 338 + if (error) 339 + rfkill->led_trigger.name = NULL; 340 + #endif /* CONFIG_RFKILL_LEDS */ 341 + } 342 + 343 + static void rfkill_led_trigger_unregister(struct rfkill *rfkill) 344 + { 345 + #ifdef CONFIG_RFKILL_LEDS 346 + if (rfkill->led_trigger.name) 347 + led_trigger_unregister(&rfkill->led_trigger); 348 + #endif 349 + } 350 + 349 351 /** 350 352 * rfkill_register - Register a rfkill structure. 351 353 * @rfkill: rfkill structure to be registered ··· 395 357 rfkill_remove_switch(rfkill); 396 358 return error; 397 359 } 360 + rfkill_led_trigger_register(rfkill); 398 361 399 362 return 0; 400 363 } ··· 411 372 */ 412 373 void rfkill_unregister(struct rfkill *rfkill) 413 374 { 375 + rfkill_led_trigger_unregister(rfkill); 414 376 device_del(&rfkill->dev); 415 377 rfkill_remove_switch(rfkill); 416 378 put_device(&rfkill->dev);