blob: 4089feb8c68e339fc33bbbb26591a13b909daf0f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Takashi Iwaib317b032014-01-08 11:44:21 +01002/* Helper functions for Thinkpad LED control;
3 * to be included from codec driver
4 */
5
Takashi Iwaib3802782018-11-26 17:47:46 +01006#if IS_ENABLED(CONFIG_THINKPAD_ACPI) && IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
Takashi Iwaib317b032014-01-08 11:44:21 +01007
8#include <linux/acpi.h>
Takashi Iwaib3802782018-11-26 17:47:46 +01009#include <linux/leds.h>
Takashi Iwaib317b032014-01-08 11:44:21 +010010
Takashi Iwaicf67c8e2014-01-14 14:56:55 +010011static void (*old_vmaster_hook)(void *, int);
Takashi Iwaib317b032014-01-08 11:44:21 +010012
Takashi Iwaib317b032014-01-08 11:44:21 +010013static bool is_thinkpad(struct hda_codec *codec)
14{
Lukas Wunnerc3a90052016-01-14 22:05:03 +010015 return (codec->core.subsystem_id >> 16 == 0x17aa) &&
Hui Wang2ecb7042016-11-10 13:20:05 +080016 (acpi_dev_found("LEN0068") || acpi_dev_found("LEN0268") ||
17 acpi_dev_found("IBM0068"));
Takashi Iwaib317b032014-01-08 11:44:21 +010018}
19
20static void update_tpacpi_mute_led(void *private_data, int enabled)
21{
Takashi Iwaicf67c8e2014-01-14 14:56:55 +010022 if (old_vmaster_hook)
23 old_vmaster_hook(private_data, enabled);
Takashi Iwaib317b032014-01-08 11:44:21 +010024
Takashi Iwaib3802782018-11-26 17:47:46 +010025 ledtrig_audio_set(LED_AUDIO_MUTE, enabled ? LED_OFF : LED_ON);
Takashi Iwaib317b032014-01-08 11:44:21 +010026}
27
28static 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;
Takashi Iwaib317b032014-01-08 11:44:21 +010032
33 if (action == HDA_FIXUP_ACT_PROBE) {
34 if (!is_thinkpad(codec))
35 return;
Takashi Iwaib3802782018-11-26 17:47:46 +010036 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);
Takashi Iwaib317b032014-01-08 11:44:21 +010039 }
40}
41
42#else /* CONFIG_THINKPAD_ACPI */
43
44static 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 */