Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 2 | /* Helper functions for Dell Mic Mute LED control; |
| 3 | * to be included from codec driver |
| 4 | */ |
| 5 | |
Michał Kępień | 44319ab | 2017-02-17 08:57:50 +0100 | [diff] [blame] | 6 | #if IS_ENABLED(CONFIG_DELL_LAPTOP) |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 7 | #include <linux/dell-led.h> |
| 8 | |
Takashi Iwai | 62a9394 | 2017-08-22 16:52:10 +0200 | [diff] [blame] | 9 | enum { |
| 10 | MICMUTE_LED_ON, |
| 11 | MICMUTE_LED_OFF, |
| 12 | MICMUTE_LED_FOLLOW_CAPTURE, |
| 13 | MICMUTE_LED_FOLLOW_MUTE, |
| 14 | }; |
| 15 | |
| 16 | static int dell_led_mode = MICMUTE_LED_FOLLOW_MUTE; |
| 17 | static int dell_capture; |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 18 | static int dell_led_value; |
Michał Kępień | 5dba880 | 2017-02-17 08:57:49 +0100 | [diff] [blame] | 19 | static int (*dell_micmute_led_set_func)(int); |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 20 | static void (*dell_old_cap_hook)(struct hda_codec *, |
| 21 | struct snd_kcontrol *, |
| 22 | struct snd_ctl_elem_value *); |
| 23 | |
Takashi Iwai | 62a9394 | 2017-08-22 16:52:10 +0200 | [diff] [blame] | 24 | static void call_micmute_led_update(void) |
| 25 | { |
| 26 | int val; |
| 27 | |
| 28 | switch (dell_led_mode) { |
| 29 | case MICMUTE_LED_ON: |
| 30 | val = 1; |
| 31 | break; |
| 32 | case MICMUTE_LED_OFF: |
| 33 | val = 0; |
| 34 | break; |
| 35 | case MICMUTE_LED_FOLLOW_CAPTURE: |
| 36 | val = dell_capture; |
| 37 | break; |
| 38 | case MICMUTE_LED_FOLLOW_MUTE: |
| 39 | default: |
| 40 | val = !dell_capture; |
| 41 | break; |
| 42 | } |
| 43 | |
| 44 | if (val == dell_led_value) |
| 45 | return; |
| 46 | dell_led_value = val; |
| 47 | dell_micmute_led_set_func(dell_led_value); |
| 48 | } |
| 49 | |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 50 | static void update_dell_wmi_micmute_led(struct hda_codec *codec, |
| 51 | struct snd_kcontrol *kcontrol, |
| 52 | struct snd_ctl_elem_value *ucontrol) |
| 53 | { |
| 54 | if (dell_old_cap_hook) |
| 55 | dell_old_cap_hook(codec, kcontrol, ucontrol); |
| 56 | |
Michał Kępień | 5dba880 | 2017-02-17 08:57:49 +0100 | [diff] [blame] | 57 | if (!ucontrol || !dell_micmute_led_set_func) |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 58 | return; |
| 59 | if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) { |
| 60 | /* TODO: How do I verify if it's a mono or stereo here? */ |
Takashi Iwai | 62a9394 | 2017-08-22 16:52:10 +0200 | [diff] [blame] | 61 | dell_capture = (ucontrol->value.integer.value[0] || |
| 62 | ucontrol->value.integer.value[1]); |
| 63 | call_micmute_led_update(); |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
Takashi Iwai | 62a9394 | 2017-08-22 16:52:10 +0200 | [diff] [blame] | 67 | static int dell_mic_mute_led_mode_info(struct snd_kcontrol *kcontrol, |
| 68 | struct snd_ctl_elem_info *uinfo) |
| 69 | { |
| 70 | static const char * const texts[] = { |
| 71 | "On", "Off", "Follow Capture", "Follow Mute", |
| 72 | }; |
| 73 | |
| 74 | return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
| 75 | } |
| 76 | |
| 77 | static int dell_mic_mute_led_mode_get(struct snd_kcontrol *kcontrol, |
| 78 | struct snd_ctl_elem_value *ucontrol) |
| 79 | { |
| 80 | ucontrol->value.enumerated.item[0] = dell_led_mode; |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int dell_mic_mute_led_mode_put(struct snd_kcontrol *kcontrol, |
| 85 | struct snd_ctl_elem_value *ucontrol) |
| 86 | { |
| 87 | unsigned int mode; |
| 88 | |
| 89 | mode = ucontrol->value.enumerated.item[0]; |
| 90 | if (mode > MICMUTE_LED_FOLLOW_MUTE) |
| 91 | mode = MICMUTE_LED_FOLLOW_MUTE; |
| 92 | if (mode == dell_led_mode) |
| 93 | return 0; |
| 94 | dell_led_mode = mode; |
| 95 | call_micmute_led_update(); |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | static const struct snd_kcontrol_new dell_mic_mute_mode_ctls[] = { |
| 100 | { |
| 101 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 102 | .name = "Mic Mute-LED Mode", |
| 103 | .info = dell_mic_mute_led_mode_info, |
| 104 | .get = dell_mic_mute_led_mode_get, |
| 105 | .put = dell_mic_mute_led_mode_put, |
| 106 | }, |
| 107 | {} |
| 108 | }; |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 109 | |
| 110 | static void alc_fixup_dell_wmi(struct hda_codec *codec, |
| 111 | const struct hda_fixup *fix, int action) |
| 112 | { |
| 113 | struct alc_spec *spec = codec->spec; |
| 114 | bool removefunc = false; |
| 115 | |
| 116 | if (action == HDA_FIXUP_ACT_PROBE) { |
Michał Kępień | 5dba880 | 2017-02-17 08:57:49 +0100 | [diff] [blame] | 117 | if (!dell_micmute_led_set_func) |
| 118 | dell_micmute_led_set_func = symbol_request(dell_micmute_led_set); |
| 119 | if (!dell_micmute_led_set_func) { |
Michał Kępień | fa5923c | 2017-02-17 08:57:48 +0100 | [diff] [blame] | 120 | codec_warn(codec, "Failed to find dell wmi symbol dell_micmute_led_set\n"); |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 121 | return; |
| 122 | } |
| 123 | |
| 124 | removefunc = true; |
Michał Kępień | 5dba880 | 2017-02-17 08:57:49 +0100 | [diff] [blame] | 125 | if (dell_micmute_led_set_func(false) >= 0) { |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 126 | dell_led_value = 0; |
Hui Wang | 4875a5f | 2016-10-11 10:48:58 +0800 | [diff] [blame] | 127 | if (spec->gen.num_adc_nids > 1 && !spec->gen.dyn_adc_switch) |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 128 | codec_dbg(codec, "Skipping micmute LED control due to several ADCs"); |
| 129 | else { |
| 130 | dell_old_cap_hook = spec->gen.cap_sync_hook; |
| 131 | spec->gen.cap_sync_hook = update_dell_wmi_micmute_led; |
| 132 | removefunc = false; |
Takashi Iwai | 62a9394 | 2017-08-22 16:52:10 +0200 | [diff] [blame] | 133 | add_mixer(spec, dell_mic_mute_mode_ctls); |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | } |
| 138 | |
Michał Kępień | 5dba880 | 2017-02-17 08:57:49 +0100 | [diff] [blame] | 139 | if (dell_micmute_led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) { |
Michał Kępień | fa5923c | 2017-02-17 08:57:48 +0100 | [diff] [blame] | 140 | symbol_put(dell_micmute_led_set); |
Michał Kępień | 5dba880 | 2017-02-17 08:57:49 +0100 | [diff] [blame] | 141 | dell_micmute_led_set_func = NULL; |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 142 | dell_old_cap_hook = NULL; |
| 143 | } |
| 144 | } |
| 145 | |
Michał Kępień | 44319ab | 2017-02-17 08:57:50 +0100 | [diff] [blame] | 146 | #else /* CONFIG_DELL_LAPTOP */ |
Hui Wang | 00ef994 | 2014-07-31 11:52:38 +0800 | [diff] [blame] | 147 | static void alc_fixup_dell_wmi(struct hda_codec *codec, |
| 148 | const struct hda_fixup *fix, int action) |
| 149 | { |
| 150 | } |
| 151 | |
Michał Kępień | 44319ab | 2017-02-17 08:57:50 +0100 | [diff] [blame] | 152 | #endif /* CONFIG_DELL_LAPTOP */ |