Linux-libre 4.19.20-gnu
[librecmc/linux-libre.git] / sound / pci / hda / dell_wmi_helper.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Helper functions for Dell Mic Mute LED control;
3  * to be included from codec driver
4  */
5
6 #if IS_ENABLED(CONFIG_DELL_LAPTOP)
7 #include <linux/dell-led.h>
8
9 static int (*dell_micmute_led_set_func)(int);
10
11 static void dell_micmute_update(struct hda_codec *codec)
12 {
13         struct hda_gen_spec *spec = codec->spec;
14
15         dell_micmute_led_set_func(spec->micmute_led.led_value);
16 }
17
18 static void alc_fixup_dell_wmi(struct hda_codec *codec,
19                                const struct hda_fixup *fix, int action)
20 {
21         bool removefunc = false;
22
23         if (action == HDA_FIXUP_ACT_PROBE) {
24                 if (!dell_micmute_led_set_func)
25                         dell_micmute_led_set_func = symbol_request(dell_micmute_led_set);
26                 if (!dell_micmute_led_set_func) {
27                         codec_warn(codec, "Failed to find dell wmi symbol dell_micmute_led_set\n");
28                         return;
29                 }
30
31                 removefunc = (dell_micmute_led_set_func(false) < 0) ||
32                         (snd_hda_gen_add_micmute_led(codec,
33                                                      dell_micmute_update) < 0);
34         }
35
36         if (dell_micmute_led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
37                 symbol_put(dell_micmute_led_set);
38                 dell_micmute_led_set_func = NULL;
39         }
40 }
41
42 #else /* CONFIG_DELL_LAPTOP */
43 static void alc_fixup_dell_wmi(struct hda_codec *codec,
44                                const struct hda_fixup *fix, int action)
45 {
46 }
47
48 #endif /* CONFIG_DELL_LAPTOP */