Staging: unisys: Remove RETINT macro
[linux/fpc-iii.git] / sound / pci / hda / thinkpad_helper.c
blob8fe3b8c18ed4b2c25c00b4963ec766b7671829d9
1 /* Helper functions for Thinkpad LED control;
2 * to be included from codec driver
3 */
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 acpi_status acpi_check_cb(acpi_handle handle, u32 lvl, void *context,
14 void **rv)
16 bool *found = context;
17 *found = true;
18 return AE_OK;
21 static bool is_thinkpad(struct hda_codec *codec)
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;
32 static void update_tpacpi_mute_led(void *private_data, int enabled)
34 if (old_vmaster_hook)
35 old_vmaster_hook(private_data, enabled);
37 if (led_set_func)
38 led_set_func(TPACPI_LED_MUTE, !enabled);
41 static void update_tpacpi_micmute_led(struct hda_codec *codec,
42 struct snd_kcontrol *kcontrol,
43 struct snd_ctl_elem_value *ucontrol)
45 if (!ucontrol || !led_set_func)
46 return;
47 if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
48 /* TODO: How do I verify if it's a mono or stereo here? */
49 bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1];
50 led_set_func(TPACPI_LED_MICMUTE, !val);
54 static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
55 const struct hda_fixup *fix, int action)
57 struct hda_gen_spec *spec = codec->spec;
58 bool removefunc = false;
60 if (action == HDA_FIXUP_ACT_PROBE) {
61 if (!is_thinkpad(codec))
62 return;
63 if (!led_set_func)
64 led_set_func = symbol_request(tpacpi_led_set);
65 if (!led_set_func) {
66 snd_printk(KERN_WARNING "Failed to find thinkpad-acpi symbol tpacpi_led_set\n");
67 return;
70 removefunc = true;
71 if (led_set_func(TPACPI_LED_MUTE, false) >= 0) {
72 old_vmaster_hook = spec->vmaster_mute.hook;
73 spec->vmaster_mute.hook = update_tpacpi_mute_led;
74 removefunc = false;
76 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) {
77 if (spec->num_adc_nids > 1)
78 snd_printdd("Skipping micmute LED control due to several ADCs");
79 else {
80 spec->cap_sync_hook = update_tpacpi_micmute_led;
81 removefunc = false;
86 if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
87 symbol_put(tpacpi_led_set);
88 led_set_func = NULL;
89 old_vmaster_hook = NULL;
93 #else /* CONFIG_THINKPAD_ACPI */
95 static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
96 const struct hda_fixup *fix, int action)
100 #endif /* CONFIG_THINKPAD_ACPI */