Skip to content

Commit 135900c

Browse files
Michael BueschDavid S. Miller
authored andcommitted
[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>
1 parent 937a049 commit 135900c

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

‎include/linux/rfkill.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/list.h>
2727
#include <linux/mutex.h>
2828
#include <linux/device.h>
29+
#include <linux/leds.h>
2930

3031
/**
3132
* enum rfkill_type - type of rfkill switch.
@@ -56,6 +57,7 @@ enum rfkill_state {
5657
* @data: Pointer to the RF button drivers private data which will be
5758
* passed along when toggling radio state.
5859
* @toggle_radio(): Mandatory handler to control state of the radio.
60+
* @led_trigger: A LED trigger for this button's LED.
5961
* @dev: Device structure integrating the switch into device tree.
6062
* @node: Used to place switch into list of all switches known to the
6163
* the system.
@@ -74,6 +76,10 @@ struct rfkill {
7476
void *data;
7577
int (*toggle_radio)(void *data, enum rfkill_state state);
7678

79+
#ifdef CONFIG_RFKILL_LEDS
80+
struct led_trigger led_trigger;
81+
#endif
82+
7783
struct device dev;
7884
struct list_head node;
7985
};
@@ -84,4 +90,19 @@ void rfkill_free(struct rfkill *rfkill);
8490
int rfkill_register(struct rfkill *rfkill);
8591
void rfkill_unregister(struct rfkill *rfkill);
8692

93+
/**
94+
* rfkill_get_led_name - Get the LED trigger name for the button's LED.
95+
* This function might return a NULL pointer if registering of the
96+
* LED trigger failed.
97+
* Use this as "default_trigger" for the LED.
98+
*/
99+
static inline char *rfkill_get_led_name(struct rfkill *rfkill)
100+
{
101+
#ifdef CONFIG_RFKILL_LEDS
102+
return (char *)(rfkill->led_trigger.name);
103+
#else
104+
return NULL;
105+
#endif
106+
}
107+
87108
#endif /* RFKILL_H */

‎net/rfkill/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ config RFKILL_INPUT
2222

2323
To compile this driver as a module, choose M here: the
2424
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+

‎net/rfkill/rfkill.c‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ static DEFINE_MUTEX(rfkill_mutex);
3737

3838
static enum rfkill_state rfkill_states[RFKILL_TYPE_MAX];
3939

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+
4056
static int rfkill_toggle_radio(struct rfkill *rfkill,
4157
enum rfkill_state state)
4258
{
@@ -48,8 +64,10 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
4864

4965
if (state != rfkill->state) {
5066
retval = rfkill->toggle_radio(rfkill->data, state);
51-
if (!retval)
67+
if (!retval) {
5268
rfkill->state = state;
69+
rfkill_led_trigger(rfkill, state);
70+
}
5371
}
5472

5573
mutex_unlock(&rfkill->mutex);
@@ -328,6 +346,26 @@ void rfkill_free(struct rfkill *rfkill)
328346
}
329347
EXPORT_SYMBOL(rfkill_free);
330348

349+
static void rfkill_led_trigger_register(struct rfkill *rfkill)
350+
{
351+
#ifdef CONFIG_RFKILL_LEDS
352+
int error;
353+
354+
rfkill->led_trigger.name = rfkill->dev.bus_id;
355+
error = led_trigger_register(&rfkill->led_trigger);
356+
if (error)
357+
rfkill->led_trigger.name = NULL;
358+
#endif /* CONFIG_RFKILL_LEDS */
359+
}
360+
361+
static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
362+
{
363+
#ifdef CONFIG_RFKILL_LEDS
364+
if (rfkill->led_trigger.name)
365+
led_trigger_unregister(&rfkill->led_trigger);
366+
#endif
367+
}
368+
331369
/**
332370
* rfkill_register - Register a rfkill structure.
333371
* @rfkill: rfkill structure to be registered
@@ -357,6 +395,7 @@ int rfkill_register(struct rfkill *rfkill)
357395
rfkill_remove_switch(rfkill);
358396
return error;
359397
}
398+
rfkill_led_trigger_register(rfkill);
360399

361400
return 0;
362401
}
@@ -372,6 +411,7 @@ EXPORT_SYMBOL(rfkill_register);
372411
*/
373412
void rfkill_unregister(struct rfkill *rfkill)
374413
{
414+
rfkill_led_trigger_unregister(rfkill);
375415
device_del(&rfkill->dev);
376416
rfkill_remove_switch(rfkill);
377417
put_device(&rfkill->dev);

0 commit comments

Comments
 (0)