ALSA: hda - Fix leftover ifdef checks after modularization
[deliverable/linux.git] / sound / pci / hda / thinkpad_helper.c
CommitLineData
b317b032
TI
1/* Helper functions for Thinkpad LED control;
2 * to be included from codec driver
3 */
4
5#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
6
7#include <linux/acpi.h>
8#include <linux/thinkpad_acpi.h>
9
10static int (*led_set_func)(int, bool);
cf67c8e7 11static void (*old_vmaster_hook)(void *, int);
b317b032
TI
12
13static acpi_status acpi_check_cb(acpi_handle handle, u32 lvl, void *context,
14 void **rv)
15{
16 bool *found = context;
17 *found = true;
18 return AE_OK;
19}
20
21static bool is_thinkpad(struct hda_codec *codec)
22{
23 bool found = false;
24 if (codec->subsystem_id >> 16 != 0x17aa)
25 return false;
26 if (ACPI_SUCCESS(acpi_get_devices("LEN0068", acpi_check_cb, &found, NULL)) && found)
27 return true;
28 found = false;
29 return ACPI_SUCCESS(acpi_get_devices("IBM0068", acpi_check_cb, &found, NULL)) && found;
30}
31
32static void update_tpacpi_mute_led(void *private_data, int enabled)
33{
cf67c8e7
TI
34 if (old_vmaster_hook)
35 old_vmaster_hook(private_data, enabled);
b317b032
TI
36
37 if (led_set_func)
38 led_set_func(TPACPI_LED_MUTE, !enabled);
39}
40
41static void update_tpacpi_micmute_led(struct hda_codec *codec,
42 struct snd_ctl_elem_value *ucontrol)
43{
44 if (!ucontrol || !led_set_func)
45 return;
46 if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
47 /* TODO: How do I verify if it's a mono or stereo here? */
48 bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1];
49 led_set_func(TPACPI_LED_MICMUTE, !val);
50 }
51}
52
53static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
54 const struct hda_fixup *fix, int action)
55{
56 struct hda_gen_spec *spec = codec->spec;
57 bool removefunc = false;
58
59 if (action == HDA_FIXUP_ACT_PROBE) {
60 if (!is_thinkpad(codec))
61 return;
62 if (!led_set_func)
63 led_set_func = symbol_request(tpacpi_led_set);
64 if (!led_set_func) {
65 snd_printk(KERN_WARNING "Failed to find thinkpad-acpi symbol tpacpi_led_set\n");
66 return;
67 }
68
69 removefunc = true;
70 if (led_set_func(TPACPI_LED_MUTE, false) >= 0) {
cf67c8e7 71 old_vmaster_hook = spec->vmaster_mute.hook;
b317b032
TI
72 spec->vmaster_mute.hook = update_tpacpi_mute_led;
73 removefunc = false;
74 }
75 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) {
76 if (spec->num_adc_nids > 1)
77 snd_printdd("Skipping micmute LED control due to several ADCs");
78 else {
79 spec->cap_sync_hook = update_tpacpi_micmute_led;
80 removefunc = false;
81 }
82 }
83 }
84
85 if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
86 symbol_put(tpacpi_led_set);
87 led_set_func = NULL;
cf67c8e7 88 old_vmaster_hook = NULL;
b317b032
TI
89 }
90}
91
92#else /* CONFIG_THINKPAD_ACPI */
93
94static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
95 const struct hda_fixup *fix, int action)
96{
97}
98
99#endif /* CONFIG_THINKPAD_ACPI */
This page took 0.055507 seconds and 5 git commands to generate.