1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Audio Mute LED trigger
4 //
5 
6 #include <linux/kernel.h>
7 #include <linux/leds.h>
8 #include <linux/module.h>
9 #include "../leds.h"
10 
11 static enum led_brightness audio_state[NUM_AUDIO_LEDS];
12 
ledtrig_audio_mute_activate(struct led_classdev * led_cdev)13 static int ledtrig_audio_mute_activate(struct led_classdev *led_cdev)
14 {
15 	led_set_brightness_nosleep(led_cdev, audio_state[LED_AUDIO_MUTE]);
16 	return 0;
17 }
18 
ledtrig_audio_micmute_activate(struct led_classdev * led_cdev)19 static int ledtrig_audio_micmute_activate(struct led_classdev *led_cdev)
20 {
21 	led_set_brightness_nosleep(led_cdev, audio_state[LED_AUDIO_MICMUTE]);
22 	return 0;
23 }
24 
25 static struct led_trigger ledtrig_audio[NUM_AUDIO_LEDS] = {
26 	[LED_AUDIO_MUTE] = {
27 		.name     = "audio-mute",
28 		.activate = ledtrig_audio_mute_activate,
29 	},
30 	[LED_AUDIO_MICMUTE] = {
31 		.name     = "audio-micmute",
32 		.activate = ledtrig_audio_micmute_activate,
33 	},
34 };
35 
ledtrig_audio_get(enum led_audio type)36 enum led_brightness ledtrig_audio_get(enum led_audio type)
37 {
38 	return audio_state[type];
39 }
40 EXPORT_SYMBOL_GPL(ledtrig_audio_get);
41 
ledtrig_audio_set(enum led_audio type,enum led_brightness state)42 void ledtrig_audio_set(enum led_audio type, enum led_brightness state)
43 {
44 	audio_state[type] = state;
45 	led_trigger_event(&ledtrig_audio[type], state);
46 }
47 EXPORT_SYMBOL_GPL(ledtrig_audio_set);
48 
ledtrig_audio_init(void)49 static int __init ledtrig_audio_init(void)
50 {
51 	led_trigger_register(&ledtrig_audio[LED_AUDIO_MUTE]);
52 	led_trigger_register(&ledtrig_audio[LED_AUDIO_MICMUTE]);
53 	return 0;
54 }
55 module_init(ledtrig_audio_init);
56 
ledtrig_audio_exit(void)57 static void __exit ledtrig_audio_exit(void)
58 {
59 	led_trigger_unregister(&ledtrig_audio[LED_AUDIO_MUTE]);
60 	led_trigger_unregister(&ledtrig_audio[LED_AUDIO_MICMUTE]);
61 }
62 module_exit(ledtrig_audio_exit);
63 
64 MODULE_DESCRIPTION("LED trigger for audio mute control");
65 MODULE_LICENSE("GPL v2");
66