blob: 7efa7bd7acb25089e1ff2f8ece32d97ccd7e3113 [file] [log] [blame]
Hui Wang00ef9942014-07-31 11:52:38 +08001/* Helper functions for Dell Mic Mute LED control;
2 * to be included from codec driver
3 */
4
Michał Kępień44319ab2017-02-17 08:57:50 +01005#if IS_ENABLED(CONFIG_DELL_LAPTOP)
Hui Wang00ef9942014-07-31 11:52:38 +08006#include <linux/dell-led.h>
7
8static int dell_led_value;
Michał Kępień5dba8802017-02-17 08:57:49 +01009static int (*dell_micmute_led_set_func)(int);
Hui Wang00ef9942014-07-31 11:52:38 +080010static void (*dell_old_cap_hook)(struct hda_codec *,
11 struct snd_kcontrol *,
12 struct snd_ctl_elem_value *);
13
14static void update_dell_wmi_micmute_led(struct hda_codec *codec,
15 struct snd_kcontrol *kcontrol,
16 struct snd_ctl_elem_value *ucontrol)
17{
18 if (dell_old_cap_hook)
19 dell_old_cap_hook(codec, kcontrol, ucontrol);
20
Michał Kępień5dba8802017-02-17 08:57:49 +010021 if (!ucontrol || !dell_micmute_led_set_func)
Hui Wang00ef9942014-07-31 11:52:38 +080022 return;
23 if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
24 /* TODO: How do I verify if it's a mono or stereo here? */
25 int val = (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) ? 0 : 1;
26 if (val == dell_led_value)
27 return;
28 dell_led_value = val;
Michał Kępień5dba8802017-02-17 08:57:49 +010029 if (dell_micmute_led_set_func)
30 dell_micmute_led_set_func(dell_led_value);
Hui Wang00ef9942014-07-31 11:52:38 +080031 }
32}
33
34
35static void alc_fixup_dell_wmi(struct hda_codec *codec,
36 const struct hda_fixup *fix, int action)
37{
38 struct alc_spec *spec = codec->spec;
39 bool removefunc = false;
40
41 if (action == HDA_FIXUP_ACT_PROBE) {
Michał Kępień5dba8802017-02-17 08:57:49 +010042 if (!dell_micmute_led_set_func)
43 dell_micmute_led_set_func = symbol_request(dell_micmute_led_set);
44 if (!dell_micmute_led_set_func) {
Michał Kępieńfa5923c2017-02-17 08:57:48 +010045 codec_warn(codec, "Failed to find dell wmi symbol dell_micmute_led_set\n");
Hui Wang00ef9942014-07-31 11:52:38 +080046 return;
47 }
48
49 removefunc = true;
Michał Kępień5dba8802017-02-17 08:57:49 +010050 if (dell_micmute_led_set_func(false) >= 0) {
Hui Wang00ef9942014-07-31 11:52:38 +080051 dell_led_value = 0;
Hui Wang4875a5f2016-10-11 10:48:58 +080052 if (spec->gen.num_adc_nids > 1 && !spec->gen.dyn_adc_switch)
Hui Wang00ef9942014-07-31 11:52:38 +080053 codec_dbg(codec, "Skipping micmute LED control due to several ADCs");
54 else {
55 dell_old_cap_hook = spec->gen.cap_sync_hook;
56 spec->gen.cap_sync_hook = update_dell_wmi_micmute_led;
57 removefunc = false;
58 }
59 }
60
61 }
62
Michał Kępień5dba8802017-02-17 08:57:49 +010063 if (dell_micmute_led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
Michał Kępieńfa5923c2017-02-17 08:57:48 +010064 symbol_put(dell_micmute_led_set);
Michał Kępień5dba8802017-02-17 08:57:49 +010065 dell_micmute_led_set_func = NULL;
Hui Wang00ef9942014-07-31 11:52:38 +080066 dell_old_cap_hook = NULL;
67 }
68}
69
Michał Kępień44319ab2017-02-17 08:57:50 +010070#else /* CONFIG_DELL_LAPTOP */
Hui Wang00ef9942014-07-31 11:52:38 +080071static void alc_fixup_dell_wmi(struct hda_codec *codec,
72 const struct hda_fixup *fix, int action)
73{
74}
75
Michał Kępień44319ab2017-02-17 08:57:50 +010076#endif /* CONFIG_DELL_LAPTOP */