1 // SPDX-License-Identifier: GPL-2.0
2 /* Helper functions for Thinkpad LED control;
3 * to be included from codec driver
4 */
5
6 #if IS_ENABLED(CONFIG_THINKPAD_ACPI) && IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
7
8 #include <linux/acpi.h>
9 #include <linux/leds.h>
10
11 static void (*old_vmaster_hook)(void *, int);
12
is_thinkpad(struct hda_codec * codec)13 static bool is_thinkpad(struct hda_codec *codec)
14 {
15 return (codec->core.subsystem_id >> 16 == 0x17aa) &&
16 (acpi_dev_found("LEN0068") || acpi_dev_found("LEN0268") ||
17 acpi_dev_found("IBM0068"));
18 }
19
update_tpacpi_mute_led(void * private_data,int enabled)20 static void update_tpacpi_mute_led(void *private_data, int enabled)
21 {
22 if (old_vmaster_hook)
23 old_vmaster_hook(private_data, enabled);
24
25 ledtrig_audio_set(LED_AUDIO_MUTE, enabled ? LED_OFF : LED_ON);
26 }
27
hda_fixup_thinkpad_acpi(struct hda_codec * codec,const struct hda_fixup * fix,int action)28 static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
29 const struct hda_fixup *fix, int action)
30 {
31 struct hda_gen_spec *spec = codec->spec;
32
33 if (action == HDA_FIXUP_ACT_PROBE) {
34 if (!is_thinkpad(codec))
35 return;
36 old_vmaster_hook = spec->vmaster_mute.hook;
37 spec->vmaster_mute.hook = update_tpacpi_mute_led;
38 snd_hda_gen_fixup_micmute_led(codec, fix, action);
39 }
40 }
41
42 #else /* CONFIG_THINKPAD_ACPI */
43
hda_fixup_thinkpad_acpi(struct hda_codec * codec,const struct hda_fixup * fix,int action)44 static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
45 const struct hda_fixup *fix, int action)
46 {
47 }
48
49 #endif /* CONFIG_THINKPAD_ACPI */
50