1 /* Helper functions for Thinkpad LED control;
2 * to be included from codec driver
5 #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
7 #include <linux/acpi.h>
8 #include <linux/thinkpad_acpi.h>
10 static int (*led_set_func)(int, bool);
11 static void (*old_vmaster_hook)(void *, int);
13 static bool is_thinkpad(struct hda_codec *codec)
15 return (codec->core.subsystem_id >> 16 == 0x17aa) &&
16 (acpi_dev_found("LEN0068") || acpi_dev_found("LEN0268") ||
17 acpi_dev_found("IBM0068"));
20 static void update_tpacpi_mute_led(void *private_data, int enabled)
23 old_vmaster_hook(private_data, enabled);
26 led_set_func(TPACPI_LED_MUTE, !enabled);
29 static void update_tpacpi_micmute_led(struct hda_codec *codec,
30 struct snd_kcontrol *kcontrol,
31 struct snd_ctl_elem_value *ucontrol)
33 if (!ucontrol || !led_set_func)
35 if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
36 /* TODO: How do I verify if it's a mono or stereo here? */
37 bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1];
38 led_set_func(TPACPI_LED_MICMUTE, !val);
42 static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
43 const struct hda_fixup *fix, int action)
45 struct hda_gen_spec *spec = codec->spec;
46 bool removefunc = false;
48 if (action == HDA_FIXUP_ACT_PROBE) {
49 if (!is_thinkpad(codec))
52 led_set_func = symbol_request(tpacpi_led_set);
55 "Failed to find thinkpad-acpi symbol tpacpi_led_set\n");
60 if (led_set_func(TPACPI_LED_MUTE, false) >= 0) {
61 old_vmaster_hook = spec->vmaster_mute.hook;
62 spec->vmaster_mute.hook = update_tpacpi_mute_led;
65 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) {
66 if (spec->num_adc_nids > 1 && !spec->dyn_adc_switch)
68 "Skipping micmute LED control due to several ADCs");
70 spec->cap_sync_hook = update_tpacpi_micmute_led;
76 if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
77 symbol_put(tpacpi_led_set);
79 old_vmaster_hook = NULL;
83 #else /* CONFIG_THINKPAD_ACPI */
85 static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
86 const struct hda_fixup *fix, int action)
90 #endif /* CONFIG_THINKPAD_ACPI */