From 04f7791b7a4ba6ff3f53b3f3978b353924d10e78 Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Fri, 5 Mar 2021 17:26:08 +0800 Subject: ALSA: hda - bind headset buttons to the headphone jack With the HDA driver, if the headset buttons are supported, an audio Jack will be created for them. This audio Jack is a bit confusing to users since it can't report headphone/mic insertion events but it claims to support these events. And in addition, the driver already builds a headphone Jack and a mic Jack, and most of those buttons are used for headphone playback, so do some change to bind those buttons to the headphone Jack. After this change, the key events are generated from NID 0x55, and are reported to the input layer via headphone jack (NID 0x21). If there is no headphone Jack, then build an audio jack to support those buttons same as previously. Signed-off-by: Hui Wang Link: https://lore.kernel.org/r/20210305092608.109599-1-hui.wang@canonical.com Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_realtek.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'sound/pci/hda/patch_realtek.c') diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 4871507cd4bf..ee8d70afe636 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -3102,7 +3102,7 @@ static void alc_headset_btn_callback(struct hda_codec *codec, if (jack->unsol_res & (7 << 10)) report |= SND_JACK_BTN_3; - jack->jack->button_state = report; + snd_hda_jack_set_button_state(codec, jack->nid, report); } static void alc_disable_headset_jack_key(struct hda_codec *codec) @@ -3163,16 +3163,23 @@ static void alc_fixup_headset_jack(struct hda_codec *codec, const struct hda_fixup *fix, int action) { struct alc_spec *spec = codec->spec; + hda_nid_t hp_pin; switch (action) { case HDA_FIXUP_ACT_PRE_PROBE: spec->has_hs_key = 1; snd_hda_jack_detect_enable_callback(codec, 0x55, alc_headset_btn_callback); - snd_hda_jack_add_kctl(codec, 0x55, "Headset Jack", false, - SND_JACK_HEADSET, alc_headset_btn_keymap); break; - case HDA_FIXUP_ACT_INIT: + case HDA_FIXUP_ACT_BUILD: + hp_pin = alc_get_hp_pin(spec); + if (!hp_pin || snd_hda_jack_bind_keymap(codec, 0x55, + alc_headset_btn_keymap, + hp_pin)) + snd_hda_jack_add_kctl(codec, 0x55, "Headset Jack", + false, SND_JACK_HEADSET, + alc_headset_btn_keymap); + alc_enable_headset_jack_key(codec); break; } -- cgit v1.2.3-59-g8ed1b