Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 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 | |
| 10 | static int (*led_set_func)(int, bool); |
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 | |
| 25 | if (led_set_func) |
| 26 | led_set_func(TPACPI_LED_MUTE, !enabled); |
| 27 | } |
| 28 | |
| 29 | static void update_tpacpi_micmute_led(struct hda_codec *codec, |
Takashi Iwai | 7fe3071 | 2014-01-30 17:59:02 +0100 | [diff] [blame] | 30 | struct snd_kcontrol *kcontrol, |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 31 | struct snd_ctl_elem_value *ucontrol) |
| 32 | { |
| 33 | if (!ucontrol || !led_set_func) |
| 34 | return; |
| 35 | if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) { |
| 36 | /* TODO: How do I verify if it's a mono or stereo here? */ |
| 37 | bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]; |
| 38 | led_set_func(TPACPI_LED_MICMUTE, !val); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | static void hda_fixup_thinkpad_acpi(struct hda_codec *codec, |
| 43 | const struct hda_fixup *fix, int action) |
| 44 | { |
| 45 | struct hda_gen_spec *spec = codec->spec; |
| 46 | bool removefunc = false; |
| 47 | |
| 48 | if (action == HDA_FIXUP_ACT_PROBE) { |
| 49 | if (!is_thinkpad(codec)) |
| 50 | return; |
| 51 | if (!led_set_func) |
| 52 | led_set_func = symbol_request(tpacpi_led_set); |
| 53 | if (!led_set_func) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 54 | codec_warn(codec, |
| 55 | "Failed to find thinkpad-acpi symbol tpacpi_led_set\n"); |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 56 | return; |
| 57 | } |
| 58 | |
| 59 | removefunc = true; |
| 60 | if (led_set_func(TPACPI_LED_MUTE, false) >= 0) { |
Takashi Iwai | cf67c8e | 2014-01-14 14:56:55 +0100 | [diff] [blame] | 61 | old_vmaster_hook = spec->vmaster_mute.hook; |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 62 | spec->vmaster_mute.hook = update_tpacpi_mute_led; |
| 63 | removefunc = false; |
| 64 | } |
| 65 | if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) { |
Hui Wang | 4875a5f | 2016-10-11 10:48:58 +0800 | [diff] [blame] | 66 | if (spec->num_adc_nids > 1 && !spec->dyn_adc_switch) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 67 | codec_dbg(codec, |
| 68 | "Skipping micmute LED control due to several ADCs"); |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 69 | else { |
| 70 | spec->cap_sync_hook = update_tpacpi_micmute_led; |
| 71 | removefunc = false; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) { |
| 77 | symbol_put(tpacpi_led_set); |
| 78 | led_set_func = NULL; |
Takashi Iwai | cf67c8e | 2014-01-14 14:56:55 +0100 | [diff] [blame] | 79 | old_vmaster_hook = NULL; |
Takashi Iwai | b317b03 | 2014-01-08 11:44:21 +0100 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | #else /* CONFIG_THINKPAD_ACPI */ |
| 84 | |
| 85 | static void hda_fixup_thinkpad_acpi(struct hda_codec *codec, |
| 86 | const struct hda_fixup *fix, int action) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | #endif /* CONFIG_THINKPAD_ACPI */ |