Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 2 | /* Helper functions for Thinkpad LED control; |
| 3 | * to be included from codec driver |
| 4 | */ |
| 5 | |
Takashi Iwai | b380278 | 2018-11-26 17:47:46 +0100 | [diff] [blame] | 6 | #if IS_ENABLED(CONFIG_THINKPAD_ACPI) && IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO) |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 7 | |
| 8 | #include <linux/acpi.h> |
Takashi Iwai | b380278 | 2018-11-26 17:47:46 +0100 | [diff] [blame] | 9 | #include <linux/leds.h> |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 10 | |
Takashi Iwai | cf67c8e | 2014-01-14 14:56:55 +0100 | [diff] [blame] | 11 | static void (*old_vmaster_hook)(void *, int); |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 12 | |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 13 | static bool is_thinkpad(struct hda_codec *codec) |
| 14 | { |
Lukas Wunner | c3a9005 | 2016-01-14 22:05:03 +0100 | [diff] [blame] | 15 | return (codec->core.subsystem_id >> 16 == 0x17aa) && |
Hui Wang | 2ecb704 | 2016-11-10 13:20:05 +0800 | [diff] [blame] | 16 | (acpi_dev_found("LEN0068") || acpi_dev_found("LEN0268") || |
| 17 | acpi_dev_found("IBM0068")); |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | static void update_tpacpi_mute_led(void *private_data, int enabled) |
| 21 | { |
Takashi Iwai | cf67c8e | 2014-01-14 14:56:55 +0100 | [diff] [blame] | 22 | if (old_vmaster_hook) |
| 23 | old_vmaster_hook(private_data, enabled); |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 24 | |
Takashi Iwai | b380278 | 2018-11-26 17:47:46 +0100 | [diff] [blame] | 25 | ledtrig_audio_set(LED_AUDIO_MUTE, enabled ? LED_OFF : LED_ON); |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 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; |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 32 | |
| 33 | if (action == HDA_FIXUP_ACT_PROBE) { |
| 34 | if (!is_thinkpad(codec)) |
| 35 | return; |
Takashi Iwai | b380278 | 2018-11-26 17:47:46 +0100 | [diff] [blame] | 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); |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | #else /* CONFIG_THINKPAD_ACPI */ |
| 43 | |
| 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 */ |