]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - sound/pci/hda/thinkpad_helper.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[thirdparty/kernel/linux.git] / sound / pci / hda / thinkpad_helper.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
b317b032
TI
2/* Helper functions for Thinkpad LED control;
3 * to be included from codec driver
4 */
5
6#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
7
8#include <linux/acpi.h>
9#include <linux/thinkpad_acpi.h>
10
11static int (*led_set_func)(int, bool);
cf67c8e7 12static void (*old_vmaster_hook)(void *, int);
b317b032 13
b317b032
TI
14static bool is_thinkpad(struct hda_codec *codec)
15{
c3a90058 16 return (codec->core.subsystem_id >> 16 == 0x17aa) &&
2ecb704a
HW
17 (acpi_dev_found("LEN0068") || acpi_dev_found("LEN0268") ||
18 acpi_dev_found("IBM0068"));
b317b032
TI
19}
20
21static void update_tpacpi_mute_led(void *private_data, int enabled)
22{
cf67c8e7
TI
23 if (old_vmaster_hook)
24 old_vmaster_hook(private_data, enabled);
b317b032
TI
25
26 if (led_set_func)
27 led_set_func(TPACPI_LED_MUTE, !enabled);
28}
29
30static void update_tpacpi_micmute_led(struct hda_codec *codec,
7fe30711 31 struct snd_kcontrol *kcontrol,
b317b032
TI
32 struct snd_ctl_elem_value *ucontrol)
33{
34 if (!ucontrol || !led_set_func)
35 return;
36 if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
37 /* TODO: How do I verify if it's a mono or stereo here? */
38 bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1];
39 led_set_func(TPACPI_LED_MICMUTE, !val);
40 }
41}
42
43static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
44 const struct hda_fixup *fix, int action)
45{
46 struct hda_gen_spec *spec = codec->spec;
47 bool removefunc = false;
48
49 if (action == HDA_FIXUP_ACT_PROBE) {
50 if (!is_thinkpad(codec))
51 return;
52 if (!led_set_func)
53 led_set_func = symbol_request(tpacpi_led_set);
54 if (!led_set_func) {
4e76a883
TI
55 codec_warn(codec,
56 "Failed to find thinkpad-acpi symbol tpacpi_led_set\n");
b317b032
TI
57 return;
58 }
59
60 removefunc = true;
61 if (led_set_func(TPACPI_LED_MUTE, false) >= 0) {
cf67c8e7 62 old_vmaster_hook = spec->vmaster_mute.hook;
b317b032
TI
63 spec->vmaster_mute.hook = update_tpacpi_mute_led;
64 removefunc = false;
65 }
66 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) {
4875a5f7 67 if (spec->num_adc_nids > 1 && !spec->dyn_adc_switch)
4e76a883
TI
68 codec_dbg(codec,
69 "Skipping micmute LED control due to several ADCs");
b317b032
TI
70 else {
71 spec->cap_sync_hook = update_tpacpi_micmute_led;
72 removefunc = false;
73 }
74 }
75 }
76
77 if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
78 symbol_put(tpacpi_led_set);
79 led_set_func = NULL;
cf67c8e7 80 old_vmaster_hook = NULL;
b317b032
TI
81 }
82}
83
84#else /* CONFIG_THINKPAD_ACPI */
85
86static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
87 const struct hda_fixup *fix, int action)
88{
89}
90
91#endif /* CONFIG_THINKPAD_ACPI */