^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Universal Interface for Intel High Definition Audio Codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Generic widget tree parser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <sound/jack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <sound/hda_codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "hda_local.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "hda_auto_parser.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "hda_jack.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "hda_beep.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "hda_generic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * snd_hda_gen_spec_init - initialize hda_gen_spec struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * @spec: hda_gen_spec object to initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Initialize the given hda_gen_spec object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int snd_hda_gen_spec_init(struct hda_gen_spec *spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) snd_array_init(&spec->loopback_list, sizeof(struct hda_amp_list), 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) mutex_init(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) EXPORT_SYMBOL_GPL(snd_hda_gen_spec_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * snd_hda_gen_add_kctl - Add a new kctl_new struct from the template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @spec: hda_gen_spec object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @name: name string to override the template, NULL if unchanged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @temp: template for the new kctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Add a new kctl (actually snd_kcontrol_new to be instantiated later)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * element based on the given snd_kcontrol_new template @temp and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * name string @name to the list in @spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Returns the newly created object or NULL as error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct snd_kcontrol_new *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) const struct snd_kcontrol_new *temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *knew = *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) knew->name = kstrdup(name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) else if (knew->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) knew->name = kstrdup(knew->name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!knew->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) EXPORT_SYMBOL_GPL(snd_hda_gen_add_kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static void free_kctls(struct hda_gen_spec *spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (spec->kctls.list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct snd_kcontrol_new *kctl = spec->kctls.list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) for (i = 0; i < spec->kctls.used; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) kfree(kctl[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) snd_array_free(&spec->kctls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static void snd_hda_gen_spec_free(struct hda_gen_spec *spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) free_kctls(spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) snd_array_free(&spec->paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) snd_array_free(&spec->loopback_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #ifdef CONFIG_SND_HDA_GENERIC_LEDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (spec->led_cdevs[LED_AUDIO_MUTE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) led_classdev_unregister(spec->led_cdevs[LED_AUDIO_MUTE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (spec->led_cdevs[LED_AUDIO_MICMUTE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) led_classdev_unregister(spec->led_cdevs[LED_AUDIO_MICMUTE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * store user hints
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void parse_user_hints(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) val = snd_hda_get_bool_hint(codec, "jack_detect");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) codec->no_jack_detect = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) val = snd_hda_get_bool_hint(codec, "inv_jack_detect");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) codec->inv_jack_detect = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) val = snd_hda_get_bool_hint(codec, "trigger_sense");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) codec->no_trigger_sense = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) val = snd_hda_get_bool_hint(codec, "inv_eapd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) codec->inv_eapd = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) val = snd_hda_get_bool_hint(codec, "pcm_format_first");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) codec->pcm_format_first = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) val = snd_hda_get_bool_hint(codec, "sticky_stream");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) codec->no_sticky_stream = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) val = snd_hda_get_bool_hint(codec, "spdif_status_reset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) codec->spdif_status_reset = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) val = snd_hda_get_bool_hint(codec, "pin_amp_workaround");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) codec->pin_amp_workaround = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) val = snd_hda_get_bool_hint(codec, "single_adc_amp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) codec->single_adc_amp = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) val = snd_hda_get_bool_hint(codec, "power_save_node");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) codec->power_save_node = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) val = snd_hda_get_bool_hint(codec, "auto_mute");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) spec->suppress_auto_mute = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) val = snd_hda_get_bool_hint(codec, "auto_mic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) spec->suppress_auto_mic = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) val = snd_hda_get_bool_hint(codec, "line_in_auto_switch");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) spec->line_in_auto_switch = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) val = snd_hda_get_bool_hint(codec, "auto_mute_via_amp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) spec->auto_mute_via_amp = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) val = snd_hda_get_bool_hint(codec, "need_dac_fix");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) spec->need_dac_fix = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) val = snd_hda_get_bool_hint(codec, "primary_hp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) spec->no_primary_hp = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) val = snd_hda_get_bool_hint(codec, "multi_io");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) spec->no_multi_io = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) val = snd_hda_get_bool_hint(codec, "multi_cap_vol");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) spec->multi_cap_vol = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) val = snd_hda_get_bool_hint(codec, "inv_dmic_split");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) spec->inv_dmic_split = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) val = snd_hda_get_bool_hint(codec, "indep_hp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) spec->indep_hp = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) spec->add_stereo_mix_input = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* the following two are just for compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) val = snd_hda_get_bool_hint(codec, "add_out_jack_modes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) spec->add_jack_modes = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) val = snd_hda_get_bool_hint(codec, "add_in_jack_modes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) spec->add_jack_modes = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) val = snd_hda_get_bool_hint(codec, "add_jack_modes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) spec->add_jack_modes = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) val = snd_hda_get_bool_hint(codec, "power_down_unused");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) spec->power_down_unused = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) val = snd_hda_get_bool_hint(codec, "add_hp_mic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) spec->hp_mic = !!val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) val = snd_hda_get_bool_hint(codec, "hp_mic_detect");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) spec->suppress_hp_mic_detect = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) val = snd_hda_get_bool_hint(codec, "vmaster");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) spec->suppress_vmaster = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!snd_hda_get_int_hint(codec, "mixer_nid", &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) spec->mixer_nid = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * pin control value accesses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define update_pin_ctl(codec, pin, val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) snd_hda_codec_write_cache(codec, pin, 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) AC_VERB_SET_PIN_WIDGET_CONTROL, val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* restore the pinctl based on the cached value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static inline void restore_pin_ctl(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) update_pin_ctl(codec, pin, snd_hda_codec_get_pin_target(codec, pin));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* set the pinctl target value and write it if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void set_pin_target(struct hda_codec *codec, hda_nid_t pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) unsigned int val, bool do_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (!pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) val = snd_hda_correct_pin_ctl(codec, pin, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) snd_hda_codec_set_pin_target(codec, pin, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (do_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) update_pin_ctl(codec, pin, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* set pinctl target values for all given pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void set_pin_targets(struct hda_codec *codec, int num_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) hda_nid_t *pins, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) for (i = 0; i < num_pins; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) set_pin_target(codec, pins[i], val, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * parsing paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* return the position of NID in the list, or -1 if not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) for (i = 0; i < nums; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (list[i] == nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* return true if the given NID is contained in the path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static bool is_nid_contained(struct nid_path *path, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return find_idx_in_nid_list(nid, path->path, path->depth) >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static struct nid_path *get_nid_path(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) hda_nid_t from_nid, hda_nid_t to_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int anchor_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) snd_array_for_each(&spec->paths, i, path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (path->depth <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if ((!from_nid || path->path[0] == from_nid) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) (!to_nid || path->path[path->depth - 1] == to_nid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (!anchor_nid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) (anchor_nid > 0 && is_nid_contained(path, anchor_nid)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) (anchor_nid < 0 && !is_nid_contained(path, anchor_nid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * snd_hda_get_path_idx - get the index number corresponding to the path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * @path: nid_path object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * The returned index starts from 1, i.e. the actual array index with offset 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * and zero is handled as an invalid path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct nid_path *array = spec->paths.list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) ssize_t idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (!spec->paths.used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) idx = path - array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (idx < 0 || idx >= spec->paths.used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return idx + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) EXPORT_SYMBOL_GPL(snd_hda_get_path_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * snd_hda_get_path_from_idx - get the path instance corresponding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * given index number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * @idx: the path index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (idx <= 0 || idx > spec->paths.used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return snd_array_elem(&spec->paths, idx - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) EXPORT_SYMBOL_GPL(snd_hda_get_path_from_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* check whether the given DAC is already found in any existing paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) const struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) snd_array_for_each(&spec->paths, i, path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (path->path[0] == nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /* check whether the given two widgets can be connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static bool is_reachable_path(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) hda_nid_t from_nid, hda_nid_t to_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (!from_nid || !to_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /* nid, dir and idx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #define AMP_VAL_COMPARE_MASK (0xffff | (1U << 18) | (0x0f << 19))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* check whether the given ctl is already assigned in any path elements */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) const struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) val &= AMP_VAL_COMPARE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) snd_array_for_each(&spec->paths, i, path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if ((path->ctls[type] & AMP_VAL_COMPARE_MASK) == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /* check whether a control with the given (nid, dir, idx) was assigned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int dir, int idx, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) unsigned int val = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return is_ctl_used(codec, val, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static void print_nid_path(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) const char *pfx, struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) char buf[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) char *pos = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) *pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) for (i = 0; i < path->depth; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) pos += scnprintf(pos, sizeof(buf) - (pos - buf), "%s%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) pos != buf ? ":" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) path->path[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) codec_dbg(codec, "%s path: depth=%d '%s'\n", pfx, path->depth, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /* called recursively */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static bool __parse_nid_path(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) hda_nid_t from_nid, hda_nid_t to_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) int anchor_nid, struct nid_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) const hda_nid_t *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) int i, nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (to_nid == anchor_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) anchor_nid = 0; /* anchor passed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) else if (to_nid == (hda_nid_t)(-anchor_nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return false; /* hit the exclusive nid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) nums = snd_hda_get_conn_list(codec, to_nid, &conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) for (i = 0; i < nums; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (conn[i] != from_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /* special case: when from_nid is 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * try to find an empty DAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (from_nid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) is_dac_already_used(codec, conn[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /* anchor is not requested or already passed? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (anchor_nid <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (depth >= MAX_NID_PATH_DEPTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) for (i = 0; i < nums; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) unsigned int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) type = get_wcaps_type(get_wcaps(codec, conn[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) type == AC_WID_PIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (__parse_nid_path(codec, from_nid, conn[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) anchor_nid, path, depth + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) path->path[path->depth] = conn[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) path->idx[path->depth + 1] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) path->multi[path->depth + 1] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) path->depth++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * snd_hda_parse_nid_path - parse the widget path from the given nid to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * the target nid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * @from_nid: the NID where the path start from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * @to_nid: the NID where the path ends at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * @anchor_nid: the anchor indication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * @path: the path object to store the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * Returns true if a matching path is found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * The parsing behavior depends on parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * when @from_nid is 0, try to find an empty DAC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * when @anchor_nid is set to a positive value, only paths through the widget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * with the given value are evaluated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * when @anchor_nid is set to a negative value, paths through the widget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * with the negative of given value are excluded, only other paths are chosen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * when @anchor_nid is zero, no special handling about path selection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) hda_nid_t to_nid, int anchor_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (__parse_nid_path(codec, from_nid, to_nid, anchor_nid, path, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) path->path[path->depth] = to_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) path->depth++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * snd_hda_add_new_path - parse the path between the given NIDs and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * add to the path list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * @from_nid: the NID where the path start from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * @to_nid: the NID where the path ends at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * @anchor_nid: the anchor indication, see snd_hda_parse_nid_path()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * If no valid path is found, returns NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct nid_path *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) hda_nid_t to_nid, int anchor_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /* check whether the path has been already added */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) path = get_nid_path(codec, from_nid, to_nid, anchor_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) path = snd_array_new(&spec->paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) memset(path, 0, sizeof(*path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (snd_hda_parse_nid_path(codec, from_nid, to_nid, anchor_nid, path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* push back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) spec->paths.used--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) EXPORT_SYMBOL_GPL(snd_hda_add_new_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /* clear the given path as invalid so that it won't be picked up later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static void invalidate_nid_path(struct hda_codec *codec, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct nid_path *path = snd_hda_get_path_from_idx(codec, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) memset(path, 0, sizeof(*path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /* return a DAC if paired to the given pin by codec driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static hda_nid_t get_preferred_dac(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) const hda_nid_t *list = spec->preferred_dacs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (!list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) for (; *list; list += 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (*list == pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return list[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /* look for an empty DAC slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static hda_nid_t look_for_dac(struct hda_codec *codec, hda_nid_t pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) bool is_digital)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) bool cap_digital;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) for (i = 0; i < spec->num_all_dacs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) hda_nid_t nid = spec->all_dacs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (!nid || is_dac_already_used(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (is_digital != cap_digital)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (is_reachable_path(codec, nid, pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /* replace the channels in the composed amp value with the given number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) val &= ~(0x3U << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) val |= chs << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) hda_nid_t nid2, int dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (!(get_wcaps(codec, nid1) & (1 << (dir + 1))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return !(get_wcaps(codec, nid2) & (1 << (dir + 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return (query_amp_caps(codec, nid1, dir) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) query_amp_caps(codec, nid2, dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /* look for a widget suitable for assigning a mute switch in the path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) for (i = path->depth - 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return path->path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (i != path->depth - 1 && i != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) nid_has_mute(codec, path->path[i], HDA_INPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return path->path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* look for a widget suitable for assigning a volume ctl in the path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) for (i = path->depth - 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) hda_nid_t nid = path->path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if ((spec->out_vol_mask >> nid) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (nid_has_volume(codec, nid, HDA_OUTPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) * path activation / deactivation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) /* can have the amp-in capability? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) hda_nid_t nid = path->path[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) unsigned int caps = get_wcaps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) unsigned int type = get_wcaps_type(caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (!(caps & AC_WCAP_IN_AMP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (type == AC_WID_PIN && idx > 0) /* only for input pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /* can have the amp-out capability? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) hda_nid_t nid = path->path[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) unsigned int caps = get_wcaps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) unsigned int type = get_wcaps_type(caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (!(caps & AC_WCAP_OUT_AMP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (type == AC_WID_PIN && !idx) /* only for output pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) /* check whether the given (nid,dir,idx) is active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) unsigned int dir, unsigned int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) int type = get_wcaps_type(get_wcaps(codec, nid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) const struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) int i, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (nid == codec->core.afg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) snd_array_for_each(&spec->paths, n, path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (!path->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (codec->power_save_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (!path->stream_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) /* ignore unplugged paths except for DAC/ADC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (!(path->pin_enabled || path->pin_fixed) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) type != AC_WID_AUD_OUT && type != AC_WID_AUD_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) for (i = 0; i < path->depth; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (path->path[i] == nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (dir == HDA_OUTPUT || idx == -1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) path->idx[i] == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) /* check whether the NID is referred by any active paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) #define is_active_nid_for_any(codec, nid) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) is_active_nid(codec, nid, HDA_OUTPUT, -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* get the default amp value for the target state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) int dir, unsigned int caps, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) unsigned int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (caps & AC_AMPCAP_NUM_STEPS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) /* set to 0dB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (caps & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (!enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) val |= HDA_AMP_MUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) /* is this a stereo widget or a stereo-to-mono mix? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid, int dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) unsigned int wcaps = get_wcaps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) hda_nid_t conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (wcaps & AC_WCAP_STEREO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) if (dir != HDA_INPUT || get_wcaps_type(wcaps) != AC_WID_AUD_MIX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (snd_hda_get_num_conns(codec, nid) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (snd_hda_get_connections(codec, nid, &conn, 1) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) return !!(get_wcaps(codec, conn) & AC_WCAP_STEREO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) /* initialize the amp value (only at the first time) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) unsigned int caps = query_amp_caps(codec, nid, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) int val = get_amp_val_to_activate(codec, nid, dir, caps, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (is_stereo_amps(codec, nid, dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) snd_hda_codec_amp_init(codec, nid, 0, dir, idx, 0xff, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /* update the amp, doing in stereo or mono depending on NID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) static int update_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) unsigned int mask, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (is_stereo_amps(codec, nid, dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return snd_hda_codec_amp_stereo(codec, nid, dir, idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) mask, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) return snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) mask, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) /* calculate amp value mask we can modify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) * if the given amp is controlled by mixers, don't touch it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) static unsigned int get_amp_mask_to_modify(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) hda_nid_t nid, int dir, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) unsigned int caps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) unsigned int mask = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (caps & (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) mask &= ~0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (caps & AC_AMPCAP_NUM_STEPS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) mask &= ~0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) int idx, int idx_to_check, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) unsigned int caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) unsigned int mask, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) caps = query_amp_caps(codec, nid, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (!mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) val &= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) update_amp(codec, nid, dir, idx, mask, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) static void check_and_activate_amp(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) int dir, int idx, int idx_to_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) /* check whether the given amp is still used by others */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) activate_amp(codec, nid, dir, idx, idx_to_check, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) int i, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) hda_nid_t nid = path->path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) init_amp(codec, nid, HDA_OUTPUT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) check_and_activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) int i, bool enable, bool add_aamix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) const hda_nid_t *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) int n, nums, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) hda_nid_t nid = path->path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) nums = snd_hda_get_conn_list(codec, nid, &conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) if (nums < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) type = get_wcaps_type(get_wcaps(codec, nid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (type == AC_WID_PIN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) nums = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) idx = path->idx[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) for (n = 0; n < nums; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) init_amp(codec, nid, HDA_INPUT, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) /* here is a little bit tricky in comparison with activate_amp_out();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) * when aa-mixer is available, we need to enable the path as well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) for (n = 0; n < nums; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (n != idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (conn[n] != spec->mixer_merge_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) /* when aamix is disabled, force to off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (!add_aamix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) activate_amp(codec, nid, HDA_INPUT, n, n, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) check_and_activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) /* sync power of each widget in the given path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) static hda_nid_t path_power_update(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) struct nid_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) bool allow_powerdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) hda_nid_t nid, changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) int i, state, power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) for (i = 0; i < path->depth; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) nid = path->path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (!(get_wcaps(codec, nid) & AC_WCAP_POWER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) if (nid == codec->core.afg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (!allow_powerdown || is_active_nid_for_any(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) state = AC_PWRST_D0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) state = AC_PWRST_D3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) power = snd_hda_codec_read(codec, nid, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) AC_VERB_GET_POWER_STATE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (power != (state | (state << 4))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) snd_hda_codec_write(codec, nid, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) AC_VERB_SET_POWER_STATE, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) changed = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) /* all known codecs seem to be capable to handl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) * widgets state even in D3, so far.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) * if any new codecs need to restore the widget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * states after D0 transition, call the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) #if 0 /* disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) if (state == AC_PWRST_D0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) snd_hdac_regmap_sync_node(&codec->core, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) /* do sync with the last power state change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * snd_hda_activate_path - activate or deactivate the given path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * @path: the path to activate/deactivate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * @enable: flag to activate or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * @add_aamix: enable the input from aamix NID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) * If @add_aamix is set, enable the input from aa-mix NID as well (if any).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) bool enable, bool add_aamix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) path->active = enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) /* make sure the widget is powered up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) if (enable && (spec->power_down_unused || codec->power_save_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) path_power_update(codec, path, codec->power_save_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) for (i = path->depth - 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) hda_nid_t nid = path->path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (enable && path->multi[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) snd_hda_codec_write_cache(codec, nid, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) AC_VERB_SET_CONNECT_SEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) path->idx[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) if (has_amp_in(codec, path, i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) activate_amp_in(codec, path, i, enable, add_aamix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) if (has_amp_out(codec, path, i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) activate_amp_out(codec, path, i, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) EXPORT_SYMBOL_GPL(snd_hda_activate_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) /* if the given path is inactive, put widgets into D3 (only if suitable) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) if (!(spec->power_down_unused || codec->power_save_node) || path->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) sync_power_state_change(codec, path_power_update(codec, path, true));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) /* turn on/off EAPD on the given pin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (spec->own_eapd_ctl ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) if (spec->keep_eapd_on && !enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (codec->inv_eapd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) enable = !enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) snd_hda_codec_write_cache(codec, pin, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) AC_VERB_SET_EAPD_BTLENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) enable ? 0x02 : 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) /* re-initialize the path specified by the given path index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) static void resume_path_from_idx(struct hda_codec *codec, int path_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) snd_hda_activate_path(codec, path, path->active, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) * Helper functions for creating mixer ctl elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) static int hda_gen_mixer_mute_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) static int hda_gen_bind_mute_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) HDA_CTL_WIDGET_VOL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) HDA_CTL_WIDGET_MUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) HDA_CTL_BIND_MUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static const struct snd_kcontrol_new control_templates[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) HDA_CODEC_VOLUME(NULL, 0, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) /* only the put callback is replaced for handling the special mute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) .subdevice = HDA_SUBDEV_AMP_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) .info = snd_hda_mixer_amp_switch_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) .get = snd_hda_mixer_amp_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) .put = hda_gen_mixer_mute_put, /* replaced */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) .info = snd_hda_mixer_amp_switch_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) .get = hda_gen_bind_mute_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) .put = hda_gen_bind_mute_put, /* replaced */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) /* add dynamic controls from template */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) static struct snd_kcontrol_new *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) add_control(struct hda_gen_spec *spec, int type, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) int cidx, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) struct snd_kcontrol_new *knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) knew = snd_hda_gen_add_kctl(spec, name, &control_templates[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) knew->index = cidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (get_amp_nid_(val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) knew->subdevice = HDA_SUBDEV_AMP_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) knew->private_value = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) return knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) static int add_control_with_pfx(struct hda_gen_spec *spec, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) const char *pfx, const char *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) const char *sfx, int cidx, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) if (!add_control(spec, type, name, cidx, val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) #define add_pb_vol_ctrl(spec, type, pfx, val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) #define add_pb_sw_ctrl(spec, type, pfx, val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) unsigned int chs, struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) val = path->ctls[NID_PATH_VOL_CTL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) val = amp_val_replace_channels(val, chs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) /* return the channel bits suitable for the given path->ctls[] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) int chs = 1; /* mono (left only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) if (path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) hda_nid_t nid = get_amp_nid_(path->ctls[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) chs = 3; /* stereo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) return chs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) return add_vol_ctl(codec, pfx, cidx, chs, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) /* create a mute-switch for the given mixer widget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) unsigned int chs, struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) int type = HDA_CTL_WIDGET_MUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) val = path->ctls[NID_PATH_MUTE_CTL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) val = amp_val_replace_channels(val, chs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) if (get_amp_direction_(val) == HDA_INPUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) hda_nid_t nid = get_amp_nid_(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) int nums = snd_hda_get_num_conns(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (nums > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) type = HDA_CTL_BIND_MUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) val |= nums << 19;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) int cidx, struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) return add_sw_ctl(codec, pfx, cidx, chs, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) /* playback mute control with the software mute bit check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static void sync_auto_mute_bits(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) if (spec->auto_mute_via_amp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) hda_nid_t nid = get_amp_nid(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) bool enabled = !((spec->mute_bits >> nid) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) ucontrol->value.integer.value[0] &= enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) ucontrol->value.integer.value[1] &= enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static int hda_gen_mixer_mute_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) sync_auto_mute_bits(kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) * Bound mute controls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) #define AMP_VAL_IDX_SHIFT 19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) #define AMP_VAL_IDX_MASK (0x0f<<19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) static int hda_gen_bind_mute_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) unsigned long pval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) mutex_lock(&codec->control_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) pval = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) kcontrol->private_value = pval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) mutex_unlock(&codec->control_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) unsigned long pval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) int i, indices, err = 0, change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) sync_auto_mute_bits(kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) mutex_lock(&codec->control_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) pval = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) for (i = 0; i < indices; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) (i << AMP_VAL_IDX_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) change |= err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) kcontrol->private_value = pval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) mutex_unlock(&codec->control_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) return err < 0 ? err : change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) /* any ctl assigned to the path with the given index? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) return path && path->ctls[ctl_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) static const char * const channel_name[4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) "Front", "Surround", "CLFE", "Side"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) /* give some appropriate ctl name prefix for the given line out channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) int *index, int ctl_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) *index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) if (cfg->line_outs == 1 && !spec->multi_ios &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) !codec->force_pin_prefix &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) !cfg->hp_outs && !cfg->speaker_outs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) return spec->vmaster_mute.hook ? "PCM" : "Master";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) /* if there is really a single DAC used in the whole output paths,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) * use it master (or "PCM" if a vmaster hook is present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) !codec->force_pin_prefix &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) return spec->vmaster_mute.hook ? "PCM" : "Master";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) /* multi-io channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (ch >= cfg->line_outs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) return channel_name[ch];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) switch (cfg->line_out_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) case AUTO_PIN_SPEAKER_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) /* if the primary channel vol/mute is shared with HP volume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) * don't name it as Speaker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) if (!ch && cfg->hp_outs &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) if (cfg->line_outs == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) return "Speaker";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (cfg->line_outs == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) return ch ? "Bass Speaker" : "Speaker";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) case AUTO_PIN_HP_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) /* if the primary channel vol/mute is shared with spk volume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) * don't name it as Headphone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (!ch && cfg->speaker_outs &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) /* for multi-io case, only the primary out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) if (ch && spec->multi_ios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) *index = ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) return "Headphone";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) case AUTO_PIN_LINE_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) /* This deals with the case where one HP or one Speaker or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) * one HP + one Speaker need to share the DAC with LO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) if (!ch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) bool hp_lo_shared = false, spk_lo_shared = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) if (cfg->speaker_outs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) spk_lo_shared = !path_has_mixer(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) spec->speaker_paths[0], ctl_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) if (cfg->hp_outs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) hp_lo_shared = !path_has_mixer(codec, spec->hp_paths[0], ctl_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) if (hp_lo_shared && spk_lo_shared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return spec->vmaster_mute.hook ? "PCM" : "Master";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (hp_lo_shared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) return "Headphone+LO";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) if (spk_lo_shared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) return "Speaker+LO";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) /* for a single channel output, we don't have to name the channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if (cfg->line_outs == 1 && !spec->multi_ios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) return "Line Out";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (ch >= ARRAY_SIZE(channel_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) snd_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) return "PCM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) return channel_name[ch];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) * Parse output paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) /* badness definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) /* No primary DAC is found for the main output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) BAD_NO_PRIMARY_DAC = 0x10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) /* No DAC is found for the extra output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) BAD_NO_DAC = 0x4000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) /* No possible multi-ios */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) BAD_MULTI_IO = 0x120,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) /* No individual DAC for extra output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) BAD_NO_EXTRA_DAC = 0x102,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) /* No individual DAC for extra surrounds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) BAD_NO_EXTRA_SURR_DAC = 0x101,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) /* Primary DAC shared with main surrounds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) BAD_SHARED_SURROUND = 0x100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) /* No independent HP possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) BAD_NO_INDEP_HP = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) /* Primary DAC shared with main CLFE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) BAD_SHARED_CLFE = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) /* Primary DAC shared with extra surrounds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) BAD_SHARED_EXTRA_SURROUND = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) /* Volume widget is shared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) BAD_SHARED_VOL = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) /* look for widgets in the given path which are appropriate for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * volume and mute controls, and assign the values to ctls[].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * When no appropriate widget is found in the path, the badness value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) * is incremented depending on the situation. The function returns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) * total badness for both volume and mute controls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) int badness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) return BAD_SHARED_VOL * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (path->ctls[NID_PATH_VOL_CTL] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) path->ctls[NID_PATH_MUTE_CTL])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) return 0; /* already evaluated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) nid = look_for_out_vol_nid(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) if (nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (spec->dac_min_mute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) val |= HDA_AMP_VAL_MIN_MUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) badness += BAD_SHARED_VOL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) path->ctls[NID_PATH_VOL_CTL] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) badness += BAD_SHARED_VOL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) nid = look_for_out_mute_nid(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) nid_has_mute(codec, nid, HDA_OUTPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) badness += BAD_SHARED_VOL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) path->ctls[NID_PATH_MUTE_CTL] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) badness += BAD_SHARED_VOL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) return badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) const struct badness_table hda_main_out_badness = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) .no_primary_dac = BAD_NO_PRIMARY_DAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) .no_dac = BAD_NO_DAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) .shared_primary = BAD_NO_PRIMARY_DAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) .shared_surr = BAD_SHARED_SURROUND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) .shared_clfe = BAD_SHARED_CLFE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) .shared_surr_main = BAD_SHARED_SURROUND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) EXPORT_SYMBOL_GPL(hda_main_out_badness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) const struct badness_table hda_extra_out_badness = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) .no_primary_dac = BAD_NO_DAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) .no_dac = BAD_NO_DAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) .shared_primary = BAD_NO_EXTRA_DAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) .shared_surr = BAD_SHARED_EXTRA_SURROUND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) EXPORT_SYMBOL_GPL(hda_extra_out_badness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) /* get the DAC of the primary output corresponding to the given array index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) if (cfg->line_outs > idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) return spec->private_dac_nids[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) idx -= cfg->line_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) if (spec->multi_ios > idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) return spec->multi_io[idx].dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) /* return the DAC if it's reachable, otherwise zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) static inline hda_nid_t try_dac(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) hda_nid_t dac, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) return is_reachable_path(codec, dac, pin) ? dac : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) /* try to assign DACs to pins and return the resultant badness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) static int try_assign_dacs(struct hda_codec *codec, int num_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) const hda_nid_t *pins, hda_nid_t *dacs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) int *path_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) const struct badness_table *bad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) int badness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) hda_nid_t dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) if (!num_outs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) for (i = 0; i < num_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) hda_nid_t pin = pins[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) if (!spec->obey_preferred_dacs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) path = snd_hda_get_path_from_idx(codec, path_idx[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) badness += assign_out_path_ctls(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) dacs[i] = get_preferred_dac(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) if (dacs[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) if (is_dac_already_used(codec, dacs[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) badness += bad->shared_primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) } else if (spec->obey_preferred_dacs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) badness += BAD_NO_PRIMARY_DAC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) if (!dacs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) dacs[i] = look_for_dac(codec, pin, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) if (!dacs[i] && !i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) /* try to steal the DAC of surrounds for the front */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) for (j = 1; j < num_outs; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (is_reachable_path(codec, dacs[j], pin)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) dacs[0] = dacs[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) dacs[j] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) invalidate_nid_path(codec, path_idx[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) path_idx[j] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) dac = dacs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) if (!dac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) if (num_outs > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) dac = try_dac(codec, get_primary_out(codec, i), pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) if (!dac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) dac = try_dac(codec, dacs[0], pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (!dac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) dac = try_dac(codec, get_primary_out(codec, i), pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) if (dac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) badness += bad->shared_primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) else if (i == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) badness += bad->shared_surr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) badness += bad->shared_clfe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) dac = spec->private_dac_nids[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) badness += bad->shared_surr_main;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) } else if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) badness += bad->no_primary_dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) badness += bad->no_dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (!dac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) if (!path && !i && spec->mixer_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) /* try with aamix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) path = snd_hda_add_new_path(codec, dac, pin, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) if (!path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) dac = dacs[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) badness += bad->no_dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) /* print_nid_path(codec, "output", path); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) path->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) path_idx[i] = snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) badness += assign_out_path_ctls(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) return badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) /* return NID if the given pin has only a single connection to a certain DAC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) hda_nid_t nid_found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) for (i = 0; i < spec->num_all_dacs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) hda_nid_t nid = spec->all_dacs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) if (!nid || is_dac_already_used(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) if (is_reachable_path(codec, nid, pin)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) if (nid_found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) nid_found = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) return nid_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) /* check whether the given pin can be a multi-io pin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) static bool can_be_multiio_pin(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) unsigned int location, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) unsigned int defcfg, caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) defcfg = snd_hda_codec_get_pincfg(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) if (location && get_defcfg_location(defcfg) != location)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) caps = snd_hda_query_pin_caps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) if (!(caps & AC_PINCAP_OUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) /* count the number of input pins that are capable to be multi-io */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) unsigned int location = get_defcfg_location(defcfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) int type, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) int num_pins = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) for (i = 0; i < cfg->num_inputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) if (cfg->inputs[i].type != type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) if (can_be_multiio_pin(codec, location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) cfg->inputs[i].pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) num_pins++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) return num_pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) * multi-io helper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) * When hardwired is set, try to fill ony hardwired pins, and returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) * zero if any pins are filled, non-zero if nothing found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) * When hardwired is off, try to fill possible input pins, and returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) * the badness value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) static int fill_multi_ios(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) hda_nid_t reference_pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) bool hardwired)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) int type, i, j, num_pins, old_pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) unsigned int location = get_defcfg_location(defcfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) int badness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) old_pins = spec->multi_ios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) if (old_pins >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) goto end_fill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) num_pins = count_multiio_pins(codec, reference_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) if (num_pins < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) goto end_fill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) for (i = 0; i < cfg->num_inputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) hda_nid_t nid = cfg->inputs[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) hda_nid_t dac = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) if (cfg->inputs[i].type != type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) if (!can_be_multiio_pin(codec, location, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) for (j = 0; j < spec->multi_ios; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) if (nid == spec->multi_io[j].pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) if (j < spec->multi_ios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) if (hardwired)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) dac = get_dac_if_single(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) else if (!dac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) dac = look_for_dac(codec, nid, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) if (!dac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) badness++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) path = snd_hda_add_new_path(codec, dac, nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) -spec->mixer_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) if (!path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) badness++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) /* print_nid_path(codec, "multiio", path); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) spec->multi_io[spec->multi_ios].pin = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) spec->multi_io[spec->multi_ios].dac = dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) spec->out_paths[cfg->line_outs + spec->multi_ios] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) spec->multi_ios++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) if (spec->multi_ios >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) end_fill:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) if (badness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) badness = BAD_MULTI_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) if (old_pins == spec->multi_ios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) if (hardwired)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) return 1; /* nothing found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) return badness; /* no badness if nothing found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) if (!hardwired && spec->multi_ios < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) /* cancel newly assigned paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) spec->paths.used -= spec->multi_ios - old_pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) spec->multi_ios = old_pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) return badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) /* assign volume and mute controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) for (i = old_pins; i < spec->multi_ios; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) badness += assign_out_path_ctls(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) return badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) /* map DACs for all pins in the list if they are single connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) static bool map_singles(struct hda_codec *codec, int outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) const hda_nid_t *pins, hda_nid_t *dacs, int *path_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) for (i = 0; i < outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) hda_nid_t dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) if (dacs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) dac = get_dac_if_single(codec, pins[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) if (!dac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) path = snd_hda_add_new_path(codec, dac, pins[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) -spec->mixer_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) if (!path && !i && spec->mixer_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) path = snd_hda_add_new_path(codec, dac, pins[i], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) if (path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) dacs[i] = dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) /* print_nid_path(codec, "output", path); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) path->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) path_idx[i] = snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) static inline bool has_aamix_out_paths(struct hda_gen_spec *spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) return spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) spec->aamix_out_paths[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) /* create a new path including aamix if available, and return its index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) hda_nid_t path_dac, dac, pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) path = snd_hda_get_path_from_idx(codec, path_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) if (!path || !path->depth ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) is_nid_contained(path, spec->mixer_nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) path_dac = path->path[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) dac = spec->private_dac_nids[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) pin = path->path[path->depth - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) if (!path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) if (dac != path_dac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) dac = path_dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) else if (spec->multiout.hp_out_nid[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) dac = spec->multiout.hp_out_nid[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) else if (spec->multiout.extra_out_nid[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) dac = spec->multiout.extra_out_nid[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) dac = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) if (dac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) path = snd_hda_add_new_path(codec, dac, pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) spec->mixer_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) /* print_nid_path(codec, "output-aamix", path); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) path->active = false; /* unused as default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) path->pin_fixed = true; /* static route */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) return snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) /* check whether the independent HP is available with the current config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) static bool indep_hp_possible(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) int i, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) if (cfg->line_out_type == AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) idx = spec->out_paths[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) idx = spec->hp_paths[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) path = snd_hda_get_path_from_idx(codec, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) /* assume no path conflicts unless aamix is involved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) if (!spec->mixer_nid || !is_nid_contained(path, spec->mixer_nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) /* check whether output paths contain aamix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) for (i = 0; i < cfg->line_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) if (spec->out_paths[i] == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) if (path && is_nid_contained(path, spec->mixer_nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) for (i = 0; i < cfg->speaker_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) if (path && is_nid_contained(path, spec->mixer_nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) /* fill the empty entries in the dac array for speaker/hp with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) * shared dac pointed by the paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) hda_nid_t *dacs, int *path_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) for (i = 0; i < num_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) if (dacs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) path = snd_hda_get_path_from_idx(codec, path_idx[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) dacs[i] = path->path[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) /* fill in the dac_nids table from the parsed pin configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) static int fill_and_eval_dacs(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) bool fill_hardwired,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) bool fill_mio_first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) int i, err, badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) /* set num_dacs once to full for look_for_dac() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) spec->multiout.num_dacs = cfg->line_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) spec->multiout.dac_nids = spec->private_dac_nids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) spec->multi_ios = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) snd_array_free(&spec->paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) /* clear path indices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) memset(spec->out_paths, 0, sizeof(spec->out_paths));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) memset(spec->hp_paths, 0, sizeof(spec->hp_paths));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) memset(spec->digout_paths, 0, sizeof(spec->digout_paths));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) memset(spec->input_paths, 0, sizeof(spec->input_paths));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) memset(&spec->digin_path, 0, sizeof(spec->digin_path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) badness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) /* fill hard-wired DACs first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) if (fill_hardwired) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) bool mapped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) mapped = map_singles(codec, cfg->line_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) cfg->line_out_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) spec->private_dac_nids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) spec->out_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) mapped |= map_singles(codec, cfg->hp_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) cfg->hp_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) spec->multiout.hp_out_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) spec->hp_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) mapped |= map_singles(codec, cfg->speaker_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) cfg->speaker_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) spec->multiout.extra_out_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) spec->speaker_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) if (!spec->no_multi_io &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) fill_mio_first && cfg->line_outs == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) mapped = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) } while (mapped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) spec->private_dac_nids, spec->out_paths,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) spec->main_out_badness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) if (!spec->no_multi_io && fill_mio_first &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) /* try to fill multi-io first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) /* we don't count badness at this stage yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) spec->multiout.hp_out_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) spec->hp_paths,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) spec->extra_out_badness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) badness += err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) err = try_assign_dacs(codec, cfg->speaker_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) cfg->speaker_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) spec->multiout.extra_out_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) spec->speaker_paths,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) spec->extra_out_badness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) badness += err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) if (!spec->no_multi_io &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) badness += err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) if (spec->mixer_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) spec->aamix_out_paths[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) check_aamix_out_path(codec, spec->out_paths[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) if (cfg->line_out_type != AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) spec->aamix_out_paths[1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) check_aamix_out_path(codec, spec->hp_paths[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) spec->aamix_out_paths[2] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) check_aamix_out_path(codec, spec->speaker_paths[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) if (!spec->no_multi_io &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) spec->multi_ios = 1; /* give badness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) /* re-count num_dacs and squash invalid entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) spec->multiout.num_dacs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) for (i = 0; i < cfg->line_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) if (spec->private_dac_nids[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) spec->multiout.num_dacs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) memmove(spec->private_dac_nids + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) spec->private_dac_nids + i + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) spec->private_dac_nids[cfg->line_outs - 1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) spec->ext_channel_count = spec->min_channel_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) spec->multiout.num_dacs * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) if (spec->multi_ios == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) spec->private_dac_nids[spec->multiout.num_dacs++] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) spec->multi_io[i].dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) } else if (spec->multi_ios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) spec->multi_ios = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) badness += BAD_MULTI_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) if (spec->indep_hp && !indep_hp_possible(codec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) badness += BAD_NO_INDEP_HP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) /* re-fill the shared DAC for speaker / headphone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) if (cfg->line_out_type != AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) refill_shared_dacs(codec, cfg->hp_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) spec->multiout.hp_out_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) spec->hp_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) refill_shared_dacs(codec, cfg->speaker_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) spec->multiout.extra_out_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) spec->speaker_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) return badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) #define DEBUG_BADNESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) #ifdef DEBUG_BADNESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) #define debug_badness(fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) codec_dbg(codec, fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) #define debug_badness(fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) #ifdef DEBUG_BADNESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) static inline void print_nid_path_idx(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) const char *pfx, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) path = snd_hda_get_path_from_idx(codec, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) if (path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) print_nid_path(codec, pfx, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) static void debug_show_configs(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) struct auto_pin_cfg *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) static const char * const lo_type[3] = { "LO", "SP", "HP" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x (type %s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) cfg->line_out_pins[0], cfg->line_out_pins[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) cfg->line_out_pins[2], cfg->line_out_pins[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) spec->multiout.dac_nids[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) spec->multiout.dac_nids[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) spec->multiout.dac_nids[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) spec->multiout.dac_nids[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) lo_type[cfg->line_out_type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) for (i = 0; i < cfg->line_outs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) print_nid_path_idx(codec, " out", spec->out_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (spec->multi_ios > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) spec->multi_ios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) spec->multi_io[0].pin, spec->multi_io[1].pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) spec->multi_io[0].dac, spec->multi_io[1].dac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) for (i = 0; i < spec->multi_ios; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) print_nid_path_idx(codec, " mio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) spec->out_paths[cfg->line_outs + i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) if (cfg->hp_outs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) cfg->hp_pins[0], cfg->hp_pins[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) cfg->hp_pins[2], cfg->hp_pins[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) spec->multiout.hp_out_nid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) spec->multiout.hp_out_nid[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) spec->multiout.hp_out_nid[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) spec->multiout.hp_out_nid[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) for (i = 0; i < cfg->hp_outs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) if (cfg->speaker_outs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) cfg->speaker_pins[0], cfg->speaker_pins[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) cfg->speaker_pins[2], cfg->speaker_pins[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) spec->multiout.extra_out_nid[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) spec->multiout.extra_out_nid[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) spec->multiout.extra_out_nid[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) spec->multiout.extra_out_nid[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) for (i = 0; i < cfg->speaker_outs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) for (i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) #define debug_show_configs(codec, cfg) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) /* find all available DACs of the codec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) static void fill_all_dac_nids(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) spec->num_all_dacs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) for_each_hda_codec_node(nid, codec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) codec_err(codec, "Too many DACs!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) spec->all_dacs[spec->num_all_dacs++] = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) static int parse_output_paths(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) struct auto_pin_cfg *best_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) int best_badness = INT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) int badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) bool fill_hardwired = true, fill_mio_first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) bool best_wired = true, best_mio = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) bool hp_spk_swapped = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) if (!best_cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) *best_cfg = *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) badness = fill_and_eval_dacs(codec, fill_hardwired,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) fill_mio_first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) if (badness < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) kfree(best_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) return badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) cfg->line_out_type, fill_hardwired, fill_mio_first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) badness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) debug_show_configs(codec, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) if (badness < best_badness) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) best_badness = badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) *best_cfg = *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) best_wired = fill_hardwired;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) best_mio = fill_mio_first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) if (!badness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) fill_mio_first = !fill_mio_first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) if (!fill_mio_first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) fill_hardwired = !fill_hardwired;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) if (!fill_hardwired)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) if (hp_spk_swapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) hp_spk_swapped = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) if (cfg->speaker_outs > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) cfg->line_out_type == AUTO_PIN_HP_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) cfg->hp_outs = cfg->line_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) memcpy(cfg->hp_pins, cfg->line_out_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) sizeof(cfg->hp_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) cfg->line_outs = cfg->speaker_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) memcpy(cfg->line_out_pins, cfg->speaker_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) sizeof(cfg->speaker_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) cfg->speaker_outs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) fill_hardwired = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) if (cfg->hp_outs > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) cfg->speaker_outs = cfg->line_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) memcpy(cfg->speaker_pins, cfg->line_out_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) sizeof(cfg->speaker_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) cfg->line_outs = cfg->hp_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) memcpy(cfg->line_out_pins, cfg->hp_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) sizeof(cfg->hp_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) cfg->hp_outs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) cfg->line_out_type = AUTO_PIN_HP_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) fill_hardwired = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) if (badness) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) debug_badness("==> restoring best_cfg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) *cfg = *best_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) fill_and_eval_dacs(codec, best_wired, best_mio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) cfg->line_out_type, best_wired, best_mio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) debug_show_configs(codec, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) if (cfg->line_out_pins[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) if (path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) spec->vmaster_nid = look_for_out_vol_nid(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) if (spec->vmaster_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) HDA_OUTPUT, spec->vmaster_tlv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) if (spec->dac_min_mute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) spec->vmaster_tlv[SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP] |= TLV_DB_SCALE_MUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) /* set initial pinctl targets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) val = PIN_HP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) val = PIN_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) if (cfg->line_out_type != AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) set_pin_targets(codec, cfg->speaker_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) cfg->speaker_pins, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) /* clear indep_hp flag if not available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) if (spec->indep_hp && !indep_hp_possible(codec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) spec->indep_hp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) kfree(best_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) /* add playback controls from the parsed DAC table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) static int create_multi_out_ctls(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) const struct auto_pin_cfg *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) int i, err, noutputs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) noutputs = cfg->line_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) if (spec->multi_ios > 0 && cfg->line_outs < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) noutputs += spec->multi_ios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) for (i = 0; i < noutputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) if (!name || !strcmp(name, "CLFE")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) /* Center/LFE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) err = add_vol_ctl(codec, "Center", 0, 1, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) err = add_vol_ctl(codec, "LFE", 0, 2, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) err = add_stereo_vol(codec, name, index, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) if (!name || !strcmp(name, "CLFE")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) err = add_sw_ctl(codec, "Center", 0, 1, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) err = add_sw_ctl(codec, "LFE", 0, 2, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) err = add_stereo_sw(codec, name, index, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) static int create_extra_out(struct hda_codec *codec, int path_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) const char *pfx, int cidx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) path = snd_hda_get_path_from_idx(codec, path_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) err = add_stereo_vol(codec, pfx, cidx, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) err = add_stereo_sw(codec, pfx, cidx, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) /* add playback controls for speaker and HP outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) static int create_extra_outs(struct hda_codec *codec, int num_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) const int *paths, const char *pfx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) for (i = 0; i < num_pins; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) char tmp[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) int err, idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) name = "Bass Speaker";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) else if (num_pins >= 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) snprintf(tmp, sizeof(tmp), "%s %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) pfx, channel_name[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) name = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) name = pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) err = create_extra_out(codec, paths[i], name, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) static int create_hp_out_ctls(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) return create_extra_outs(codec, spec->autocfg.hp_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) spec->hp_paths,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) "Headphone");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) static int create_speaker_out_ctls(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) return create_extra_outs(codec, spec->autocfg.speaker_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) spec->speaker_paths,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) "Speaker");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) * independent HP controls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) static void call_hp_automute(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) struct hda_jack_callback *jack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) static int indep_hp_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) static int indep_hp_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) int nomix_path_idx, int mix_path_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) int out_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) static int indep_hp_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) unsigned int select = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) mutex_lock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) if (spec->active_streams) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) if (spec->indep_hp_enabled != select) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) hda_nid_t *dacp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) dacp = &spec->private_dac_nids[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) dacp = &spec->multiout.hp_out_nid[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) /* update HP aamix paths in case it conflicts with indep HP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) if (spec->have_aamix_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) update_aamix_paths(codec, spec->aamix_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) spec->out_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) spec->aamix_out_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) spec->autocfg.line_out_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) update_aamix_paths(codec, spec->aamix_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) spec->hp_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) spec->aamix_out_paths[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) AUTO_PIN_HP_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) spec->indep_hp_enabled = select;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) if (spec->indep_hp_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) *dacp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) *dacp = spec->alt_dac_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) call_hp_automute(codec, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) mutex_unlock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) static const struct snd_kcontrol_new indep_hp_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) .name = "Independent HP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) .info = indep_hp_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) .get = indep_hp_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) .put = indep_hp_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) static int create_indep_hp_ctls(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) hda_nid_t dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) if (!spec->indep_hp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) dac = spec->multiout.dac_nids[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) dac = spec->multiout.hp_out_nid[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) if (!dac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) spec->indep_hp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) spec->indep_hp_enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) spec->alt_dac_nid = dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) if (!snd_hda_gen_add_kctl(spec, NULL, &indep_hp_ctl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) * channel mode enum control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) static int ch_mode_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) int chs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) uinfo->value.enumerated.items = spec->multi_ios + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) if (uinfo->value.enumerated.item > spec->multi_ios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) uinfo->value.enumerated.item = spec->multi_ios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) sprintf(uinfo->value.enumerated.name, "%dch", chs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) static int ch_mode_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) ucontrol->value.enumerated.item[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) (spec->ext_channel_count - spec->min_channel_count) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) static inline struct nid_path *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) get_multiio_path(struct hda_codec *codec, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) return snd_hda_get_path_from_idx(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) spec->out_paths[spec->autocfg.line_outs + idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) static void update_automute_all(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) /* Default value to be passed as aamix argument for snd_hda_activate_path();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) * used for output paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) static bool aamix_default(struct hda_gen_spec *spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) return !spec->have_aamix_ctl || spec->aamix_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) static int set_multi_io(struct hda_codec *codec, int idx, bool output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) hda_nid_t nid = spec->multi_io[idx].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) path = get_multiio_path(codec, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) if (path->active == output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) if (output) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) set_pin_target(codec, nid, PIN_OUT, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) snd_hda_activate_path(codec, path, true, aamix_default(spec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) set_pin_eapd(codec, nid, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) set_pin_eapd(codec, nid, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) snd_hda_activate_path(codec, path, false, aamix_default(spec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) path_power_down_sync(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) /* update jack retasking in case it modifies any of them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) update_automute_all(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) static int ch_mode_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) int i, ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) ch = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) if (ch < 0 || ch > spec->multi_ios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) spec->ext_channel_count = ch * 2 + spec->min_channel_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) for (i = 0; i < spec->multi_ios; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) set_multi_io(codec, i, i < ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) spec->multiout.max_channels = max(spec->ext_channel_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) spec->const_channel_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) if (spec->need_dac_fix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) spec->multiout.num_dacs = spec->multiout.max_channels / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) static const struct snd_kcontrol_new channel_mode_enum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) .name = "Channel Mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) .info = ch_mode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) .get = ch_mode_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) .put = ch_mode_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) static int create_multi_channel_mode(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) if (spec->multi_ios > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) if (!snd_hda_gen_add_kctl(spec, NULL, &channel_mode_enum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) * aamix loopback enable/disable switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) #define loopback_mixing_info indep_hp_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) static int loopback_mixing_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) ucontrol->value.enumerated.item[0] = spec->aamix_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) int nomix_path_idx, int mix_path_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) int out_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) struct nid_path *nomix_path, *mix_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) if (!nomix_path || !mix_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) /* if HP aamix path is driven from a different DAC and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) * independent HP mode is ON, can't turn on aamix path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) mix_path->path[0] != spec->alt_dac_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) do_mix = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) if (do_mix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) snd_hda_activate_path(codec, nomix_path, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) snd_hda_activate_path(codec, mix_path, true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) path_power_down_sync(codec, nomix_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) snd_hda_activate_path(codec, mix_path, false, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) snd_hda_activate_path(codec, nomix_path, true, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) path_power_down_sync(codec, mix_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) /* re-initialize the output paths; only called from loopback_mixing_put() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) static void update_output_paths(struct hda_codec *codec, int num_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) const int *paths)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) for (i = 0; i < num_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) path = snd_hda_get_path_from_idx(codec, paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) if (path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) snd_hda_activate_path(codec, path, path->active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) spec->aamix_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) static int loopback_mixing_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) const struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) unsigned int val = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) if (val == spec->aamix_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) spec->aamix_mode = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) if (has_aamix_out_paths(spec)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) update_aamix_paths(codec, val, spec->out_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) spec->aamix_out_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) cfg->line_out_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) update_aamix_paths(codec, val, spec->hp_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) spec->aamix_out_paths[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) AUTO_PIN_HP_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) update_aamix_paths(codec, val, spec->speaker_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) spec->aamix_out_paths[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) AUTO_PIN_SPEAKER_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) update_output_paths(codec, cfg->line_outs, spec->out_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) if (cfg->line_out_type != AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) update_output_paths(codec, cfg->speaker_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) spec->speaker_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) static const struct snd_kcontrol_new loopback_mixing_enum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) .name = "Loopback Mixing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) .info = loopback_mixing_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) .get = loopback_mixing_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) .put = loopback_mixing_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) static int create_loopback_mixing_ctl(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) if (!spec->mixer_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) spec->have_aamix_ctl = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) * shared headphone/mic handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) static void call_update_outputs(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) /* for shared I/O, change the pin-control accordingly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) bool as_mic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) hda_nid_t pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) pin = spec->hp_mic_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) as_mic = spec->cur_mux[adc_mux] == spec->hp_mic_mux_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) if (!force) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) val = snd_hda_codec_get_pin_target(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) if (as_mic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) if (val & PIN_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) if (val & PIN_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) val = snd_hda_get_default_vref(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) /* if the HP pin doesn't support VREF and the codec driver gives an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) * alternative pin, set up the VREF on that pin instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) if (vref_val != AC_PINCTL_VREF_HIZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) snd_hda_set_pin_ctl_cache(codec, vref_pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) PIN_IN | (as_mic ? vref_val : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) if (!spec->hp_mic_jack_modes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) if (as_mic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) val |= PIN_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) val = PIN_HP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) set_pin_target(codec, pin, val, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) call_hp_automute(codec, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) /* create a shared input with the headphone out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) static int create_hp_mic(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) unsigned int defcfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) if (!spec->hp_mic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) if (spec->suppress_hp_mic_detect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) /* automatic detection: only if no input or a single internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) * input pin is found, try to detect the shared hp/mic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) if (cfg->num_inputs > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) else if (cfg->num_inputs == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) spec->hp_mic = 0; /* clear once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) if (cfg->num_inputs >= AUTO_CFG_MAX_INS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) nid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) if (cfg->line_out_type == AUTO_PIN_HP_OUT && cfg->line_outs > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) nid = cfg->line_out_pins[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) else if (cfg->hp_outs > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) nid = cfg->hp_pins[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) if (!nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) return 0; /* no input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) cfg->inputs[cfg->num_inputs].pin = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) cfg->inputs[cfg->num_inputs].type = AUTO_PIN_MIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) cfg->inputs[cfg->num_inputs].is_headphone_mic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) cfg->num_inputs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) spec->hp_mic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) spec->hp_mic_pin = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) /* we can't handle auto-mic together with HP-mic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) spec->suppress_auto_mic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) * output jack mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) static const char * const out_jack_texts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) "Line Out", "Headphone Out",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) static int out_jack_mode_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) return snd_hda_enum_helper_info(kcontrol, uinfo, 2, out_jack_texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) static int out_jack_mode_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) hda_nid_t nid = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) ucontrol->value.enumerated.item[0] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) ucontrol->value.enumerated.item[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) static int out_jack_mode_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) hda_nid_t nid = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) if (snd_hda_codec_get_pin_target(codec, nid) == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) snd_hda_set_pin_ctl_cache(codec, nid, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) static const struct snd_kcontrol_new out_jack_mode_enum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) .info = out_jack_mode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) .get = out_jack_mode_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) .put = out_jack_mode_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) const struct snd_kcontrol_new *kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) snd_array_for_each(&spec->kctls, i, kctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) if (!strcmp(kctl->name, name) && kctl->index == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) char *name, size_t name_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) int idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) strlcat(name, " Jack Mode", name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) for (; find_kctl_name(codec, name, idx); idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) if (spec->add_jack_modes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) hda_nid_t *pins)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) for (i = 0; i < num_pins; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) hda_nid_t pin = pins[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) if (pin == spec->hp_mic_pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) if (get_out_jack_num_items(codec, pin) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) struct snd_kcontrol_new *knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) get_jack_mode_name(codec, pin, name, sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) knew = snd_hda_gen_add_kctl(spec, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) &out_jack_mode_enum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) knew->private_value = pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) * input jack mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) /* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) #define NUM_VREFS 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) static const char * const vref_texts[NUM_VREFS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) "Line In", "Mic 50pc Bias", "Mic 0V Bias",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) "", "Mic 80pc Bias", "Mic 100pc Bias"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) unsigned int pincap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) pincap = snd_hda_query_pin_caps(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) /* filter out unusual vrefs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) pincap &= ~(AC_PINCAP_VREF_GRD | AC_PINCAP_VREF_100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) return pincap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) /* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) static int get_vref_idx(unsigned int vref_caps, unsigned int item_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) unsigned int i, n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) for (i = 0; i < NUM_VREFS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) if (vref_caps & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) if (n == item_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) /* convert back from the vref ctl index to the enum item index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) static int cvt_from_vref_idx(unsigned int vref_caps, unsigned int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) unsigned int i, n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) for (i = 0; i < NUM_VREFS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) if (i == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) if (vref_caps & (1 << i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) static int in_jack_mode_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) hda_nid_t nid = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) unsigned int vref_caps = get_vref_caps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) snd_hda_enum_helper_info(kcontrol, uinfo, hweight32(vref_caps),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) vref_texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) /* set the right text */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) strcpy(uinfo->value.enumerated.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) static int in_jack_mode_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) hda_nid_t nid = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) unsigned int vref_caps = get_vref_caps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) static int in_jack_mode_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) hda_nid_t nid = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) unsigned int vref_caps = get_vref_caps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) unsigned int val, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) val = snd_hda_codec_get_pin_target(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) idx = cvt_from_vref_idx(vref_caps, val & AC_PINCTL_VREFEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) if (idx == ucontrol->value.enumerated.item[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) val &= ~AC_PINCTL_VREFEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) snd_hda_set_pin_ctl_cache(codec, nid, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) static const struct snd_kcontrol_new in_jack_mode_enum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) .info = in_jack_mode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) .get = in_jack_mode_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) .put = in_jack_mode_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) int nitems = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) if (spec->add_jack_modes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) nitems = hweight32(get_vref_caps(codec, pin));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) return nitems ? nitems : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) struct snd_kcontrol_new *knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) unsigned int defcfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) if (pin == spec->hp_mic_pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) return 0; /* already done in create_out_jack_mode() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) /* no jack mode for fixed pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) defcfg = snd_hda_codec_get_pincfg(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) /* no multiple vref caps? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) if (get_in_jack_num_items(codec, pin) <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) get_jack_mode_name(codec, pin, name, sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) knew = snd_hda_gen_add_kctl(spec, name, &in_jack_mode_enum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) knew->private_value = pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) * HP/mic shared jack mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) static int hp_mic_jack_mode_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) hda_nid_t nid = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) int out_jacks = get_out_jack_num_items(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) int in_jacks = get_in_jack_num_items(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) const char *text = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) uinfo->value.enumerated.items = out_jacks + in_jacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) idx = uinfo->value.enumerated.item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) if (idx < out_jacks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) if (out_jacks > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) text = out_jack_texts[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) text = "Headphone Out";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) idx -= out_jacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) if (in_jacks > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) unsigned int vref_caps = get_vref_caps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) text = vref_texts[get_vref_idx(vref_caps, idx)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) text = "Mic In";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) strcpy(uinfo->value.enumerated.name, text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) int out_jacks = get_out_jack_num_items(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) int in_jacks = get_in_jack_num_items(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) unsigned int val = snd_hda_codec_get_pin_target(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) int idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) if (val & PIN_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) if (out_jacks > 1 && val == PIN_HP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) idx = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) } else if (val & PIN_IN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) idx = out_jacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) if (in_jacks > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) unsigned int vref_caps = get_vref_caps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) val &= AC_PINCTL_VREFEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) idx += cvt_from_vref_idx(vref_caps, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) return idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) static int hp_mic_jack_mode_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) hda_nid_t nid = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) ucontrol->value.enumerated.item[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) get_cur_hp_mic_jack_mode(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) static int hp_mic_jack_mode_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) hda_nid_t nid = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) int out_jacks = get_out_jack_num_items(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) int in_jacks = get_in_jack_num_items(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) unsigned int val, oldval, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) oldval = get_cur_hp_mic_jack_mode(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) idx = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) if (oldval == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) if (idx < out_jacks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) if (out_jacks > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) val = idx ? PIN_HP : PIN_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) val = PIN_HP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) idx -= out_jacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) if (in_jacks > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) unsigned int vref_caps = get_vref_caps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) val = snd_hda_codec_get_pin_target(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) val &= ~(AC_PINCTL_VREFEN | PIN_HP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) val |= get_vref_idx(vref_caps, idx) | PIN_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) val = snd_hda_get_default_vref(codec, nid) | PIN_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) snd_hda_set_pin_ctl_cache(codec, nid, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) call_hp_automute(codec, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) static const struct snd_kcontrol_new hp_mic_jack_mode_enum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) .info = hp_mic_jack_mode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) .get = hp_mic_jack_mode_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) .put = hp_mic_jack_mode_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) struct snd_kcontrol_new *knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) knew = snd_hda_gen_add_kctl(spec, "Headphone Mic Jack Mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) &hp_mic_jack_mode_enum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) knew->private_value = pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) spec->hp_mic_jack_modes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) * Parse input paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) /* add the powersave loopback-list entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) static int add_loopback_list(struct hda_gen_spec *spec, hda_nid_t mix, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) struct hda_amp_list *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) list = snd_array_new(&spec->loopback_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) if (!list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) list->nid = mix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) list->dir = HDA_INPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) list->idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) spec->loopback.amplist = spec->loopback_list.list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) /* return true if either a volume or a mute amp is found for the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) * aamix path; the amp has to be either in the mixer node or its direct leaf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) static bool look_for_mix_leaf_ctls(struct hda_codec *codec, hda_nid_t mix_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) hda_nid_t pin, unsigned int *mix_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) unsigned int *mute_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) int idx, num_conns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) const hda_nid_t *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) idx = snd_hda_get_conn_index(codec, mix_nid, pin, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) if (idx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) *mix_val = *mute_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) if (nid_has_volume(codec, mix_nid, HDA_INPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) *mix_val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) if (nid_has_mute(codec, mix_nid, HDA_INPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) *mute_val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) if (*mix_val && *mute_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) /* check leaf node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) num_conns = snd_hda_get_conn_list(codec, mix_nid, &list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) if (num_conns < idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) nid = list[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) if (!*mix_val && nid_has_volume(codec, nid, HDA_OUTPUT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_VOL_CTL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) *mix_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) if (!*mute_val && nid_has_mute(codec, nid, HDA_OUTPUT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) !is_ctl_associated(codec, nid, HDA_OUTPUT, 0, NID_PATH_MUTE_CTL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) *mute_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) return *mix_val || *mute_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) /* create input playback/capture controls for the given pin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) static int new_analog_input(struct hda_codec *codec, int input_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) hda_nid_t pin, const char *ctlname, int ctlidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) hda_nid_t mix_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) unsigned int mix_val, mute_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) int err, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) if (!look_for_mix_leaf_ctls(codec, mix_nid, pin, &mix_val, &mute_val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) print_nid_path(codec, "loopback", path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) idx = path->idx[path->depth - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) if (mix_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) err = __add_pb_vol_ctrl(spec, HDA_CTL_WIDGET_VOL, ctlname, ctlidx, mix_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) path->ctls[NID_PATH_VOL_CTL] = mix_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) if (mute_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) err = __add_pb_sw_ctrl(spec, HDA_CTL_WIDGET_MUTE, ctlname, ctlidx, mute_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) path->ctls[NID_PATH_MUTE_CTL] = mute_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) path->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) path->stream_enabled = true; /* no DAC/ADC involved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) err = add_loopback_list(spec, mix_nid, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) if (spec->mixer_nid != spec->mixer_merge_nid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) !spec->loopback_merge_path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) path = snd_hda_add_new_path(codec, spec->mixer_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) spec->mixer_merge_nid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) if (path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) print_nid_path(codec, "loopback-merge", path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) path->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) path->pin_fixed = true; /* static route */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) path->stream_enabled = true; /* no DAC/ADC involved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) spec->loopback_merge_path =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) return (pincap & AC_PINCAP_IN) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) /* Parse the codec tree and retrieve ADCs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) static int fill_adc_nids(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) hda_nid_t *adc_nids = spec->adc_nids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) int max_nums = ARRAY_SIZE(spec->adc_nids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) int nums = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) for_each_hda_codec_node(nid, codec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) unsigned int caps = get_wcaps(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) int type = get_wcaps_type(caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) adc_nids[nums] = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) if (++nums >= max_nums)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) spec->num_adc_nids = nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) /* copy the detected ADCs to all_adcs[] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) spec->num_all_adcs = nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) return nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) /* filter out invalid adc_nids that don't give all active input pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) * if needed, check whether dynamic ADC-switching is available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) static int check_dyn_adc_switch(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) struct hda_input_mux *imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) unsigned int ok_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) int i, n, nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) nums = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) ok_bits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) for (n = 0; n < spec->num_adc_nids; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) for (i = 0; i < imux->num_items; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) if (!spec->input_paths[i][n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) if (i >= imux->num_items) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) ok_bits |= (1 << n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) nums++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) if (!ok_bits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) /* check whether ADC-switch is possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) for (i = 0; i < imux->num_items; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) for (n = 0; n < spec->num_adc_nids; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) if (spec->input_paths[i][n]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) spec->dyn_adc_idx[i] = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) codec_dbg(codec, "enabling ADC switching\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) spec->dyn_adc_switch = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) } else if (nums != spec->num_adc_nids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) /* shrink the invalid adcs and input paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) nums = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) for (n = 0; n < spec->num_adc_nids; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) if (!(ok_bits & (1 << n)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) if (n != nums) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) spec->adc_nids[nums] = spec->adc_nids[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) for (i = 0; i < imux->num_items; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) invalidate_nid_path(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) spec->input_paths[i][nums]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) spec->input_paths[i][nums] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) spec->input_paths[i][n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) spec->input_paths[i][n] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) nums++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) spec->num_adc_nids = nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) if (imux->num_items == 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) (imux->num_items == 2 && spec->hp_mic)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) codec_dbg(codec, "reducing to a single ADC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) spec->num_adc_nids = 1; /* reduce to a single ADC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) /* single index for individual volumes ctls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) if (!spec->dyn_adc_switch && spec->multi_cap_vol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) spec->num_adc_nids = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) /* parse capture source paths from the given pin and create imux items */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) int cfg_idx, int num_adcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) const char *label, int anchor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) struct hda_input_mux *imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) int imux_idx = imux->num_items;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) bool imux_added = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) for (c = 0; c < num_adcs; c++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) hda_nid_t adc = spec->adc_nids[c];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) if (!is_reachable_path(codec, pin, adc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) path = snd_hda_add_new_path(codec, pin, adc, anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) print_nid_path(codec, "input", path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) spec->input_paths[imux_idx][c] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) if (!imux_added) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) if (spec->hp_mic_pin == pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) spec->hp_mic_mux_idx = imux->num_items;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) spec->imux_pins[imux->num_items] = pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) snd_hda_add_imux_item(codec, imux, label, cfg_idx, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) imux_added = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) if (spec->dyn_adc_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) spec->dyn_adc_idx[imux_idx] = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) * create playback/capture controls for input pins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) /* fill the label for each input at first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) static int fill_input_pin_labels(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) const struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) for (i = 0; i < cfg->num_inputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) hda_nid_t pin = cfg->inputs[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) const char *label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) int j, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) if (!is_input_pin(codec, pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) label = hda_get_autocfg_input_label(codec, cfg, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) for (j = i - 1; j >= 0; j--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) if (spec->input_labels[j] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) !strcmp(spec->input_labels[j], label)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) idx = spec->input_label_idxs[j] + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) spec->input_labels[i] = label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) spec->input_label_idxs[i] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) static int create_input_ctls(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) const struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) hda_nid_t mixer = spec->mixer_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) int num_adcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) num_adcs = fill_adc_nids(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) if (num_adcs < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) err = fill_input_pin_labels(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) for (i = 0; i < cfg->num_inputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) hda_nid_t pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) pin = cfg->inputs[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) if (!is_input_pin(codec, pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) val = PIN_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) if (cfg->inputs[i].type == AUTO_PIN_MIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) val |= snd_hda_get_default_vref(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) if (pin != spec->hp_mic_pin &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) !snd_hda_codec_get_pin_target(codec, pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) set_pin_target(codec, pin, val, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) if (mixer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) if (is_reachable_path(codec, pin, mixer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) err = new_analog_input(codec, i, pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) spec->input_labels[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) spec->input_label_idxs[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) err = parse_capture_source(codec, pin, i, num_adcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) spec->input_labels[i], -mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) if (spec->add_jack_modes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) err = create_in_jack_mode(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) /* add stereo mix when explicitly enabled via hint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) if (mixer && spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) "Stereo Mix", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) spec->suppress_auto_mic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) * input source mux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) /* get the input path specified by the given adc and imux indices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) if (imux_idx < 0 || imux_idx >= HDA_MAX_NUM_INPUTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) snd_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) if (spec->dyn_adc_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) adc_idx = spec->dyn_adc_idx[imux_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) if (adc_idx < 0 || adc_idx >= AUTO_CFG_MAX_INS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) snd_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) unsigned int idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) static int mux_enum_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) return snd_hda_input_mux_info(&spec->input_mux, uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) static int mux_enum_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) /* the ctls are created at once with multiple counts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) static int mux_enum_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) return mux_select(codec, adc_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) ucontrol->value.enumerated.item[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) static const struct snd_kcontrol_new cap_src_temp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) .name = "Input Source",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) .info = mux_enum_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) .get = mux_enum_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) .put = mux_enum_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) * capture volume and capture switch ctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) /* call the given amp update function for all amps in the imux list at once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) static int cap_put_caller(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) struct snd_ctl_elem_value *ucontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) put_call_t func, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) const struct hda_input_mux *imux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) int i, adc_idx, ret, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) adc_idx = kcontrol->id.index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) mutex_lock(&codec->control_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) for (i = 0; i < imux->num_items; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) path = get_input_path(codec, adc_idx, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) if (!path || !path->ctls[type])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) kcontrol->private_value = path->ctls[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) ret = func(kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) err = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) mutex_unlock(&codec->control_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) if (err >= 0 && spec->cap_sync_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) spec->cap_sync_hook(codec, kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) /* capture volume ctl callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) #define cap_vol_info snd_hda_mixer_amp_volume_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) #define cap_vol_get snd_hda_mixer_amp_volume_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) #define cap_vol_tlv snd_hda_mixer_amp_tlv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) static int cap_vol_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) return cap_put_caller(kcontrol, ucontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) snd_hda_mixer_amp_volume_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) NID_PATH_VOL_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) static const struct snd_kcontrol_new cap_vol_temp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) .name = "Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) SNDRV_CTL_ELEM_ACCESS_TLV_READ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) .info = cap_vol_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) .get = cap_vol_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) .put = cap_vol_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) .tlv = { .c = cap_vol_tlv },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) /* capture switch ctl callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) #define cap_sw_info snd_ctl_boolean_stereo_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) #define cap_sw_get snd_hda_mixer_amp_switch_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) static int cap_sw_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) return cap_put_caller(kcontrol, ucontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) snd_hda_mixer_amp_switch_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) NID_PATH_MUTE_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) static const struct snd_kcontrol_new cap_sw_temp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) .name = "Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) .info = cap_sw_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) .get = cap_sw_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) .put = cap_sw_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) int i, depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) for (depth = 0; depth < 3; depth++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) if (depth >= path->depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) i = path->depth - depth - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) nid = path->path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) if (!path->ctls[NID_PATH_VOL_CTL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) if (nid_has_volume(codec, nid, HDA_OUTPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) path->ctls[NID_PATH_VOL_CTL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) else if (nid_has_volume(codec, nid, HDA_INPUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) int idx = path->idx[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) if (!depth && codec->single_adc_amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) path->ctls[NID_PATH_VOL_CTL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) if (!path->ctls[NID_PATH_MUTE_CTL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) if (nid_has_mute(codec, nid, HDA_OUTPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) path->ctls[NID_PATH_MUTE_CTL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) else if (nid_has_mute(codec, nid, HDA_INPUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) int idx = path->idx[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) if (!depth && codec->single_adc_amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) path->ctls[NID_PATH_MUTE_CTL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) if (!spec->inv_dmic_split)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) for (i = 0; i < cfg->num_inputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) if (cfg->inputs[i].pin != nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) if (cfg->inputs[i].type != AUTO_PIN_MIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) val = snd_hda_codec_get_pincfg(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) return snd_hda_get_input_pin_attr(val) == INPUT_PIN_ATTR_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) /* capture switch put callback for a single control with hook call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) if (spec->cap_sync_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) spec->cap_sync_hook(codec, kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) int idx, bool is_switch, unsigned int ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) bool inv_dmic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) char tmpname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) int type = is_switch ? HDA_CTL_WIDGET_MUTE : HDA_CTL_WIDGET_VOL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) const char *sfx = is_switch ? "Switch" : "Volume";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) unsigned int chs = inv_dmic ? 1 : 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) struct snd_kcontrol_new *knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) if (!ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) if (label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) snprintf(tmpname, sizeof(tmpname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) "%s Capture %s", label, sfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) snprintf(tmpname, sizeof(tmpname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) "Capture %s", sfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) knew = add_control(spec, type, tmpname, idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) amp_val_replace_channels(ctl, chs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) if (is_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) knew->put = cap_single_sw_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) if (!inv_dmic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) /* Make independent right kcontrol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) if (label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) snprintf(tmpname, sizeof(tmpname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) "Inverted %s Capture %s", label, sfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) snprintf(tmpname, sizeof(tmpname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) "Inverted Capture %s", sfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) knew = add_control(spec, type, tmpname, idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) amp_val_replace_channels(ctl, 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) if (is_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) knew->put = cap_single_sw_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) /* create single (and simple) capture volume and switch controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) unsigned int vol_ctl, unsigned int sw_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) bool inv_dmic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) /* create bound capture volume and switch controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) unsigned int vol_ctl, unsigned int sw_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) struct snd_kcontrol_new *knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) if (vol_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) knew = snd_hda_gen_add_kctl(spec, NULL, &cap_vol_temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) knew->index = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) knew->private_value = vol_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) knew->subdevice = HDA_SUBDEV_AMP_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) if (sw_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) knew = snd_hda_gen_add_kctl(spec, NULL, &cap_sw_temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) knew->index = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) knew->private_value = sw_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) knew->subdevice = HDA_SUBDEV_AMP_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) /* return the vol ctl when used first in the imux list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) unsigned int ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) path = get_input_path(codec, 0, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) ctl = path->ctls[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) if (!ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) for (i = 0; i < idx - 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) path = get_input_path(codec, 0, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) if (path && path->ctls[type] == ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) return ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) /* create individual capture volume and switch controls per input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) static int create_multi_cap_vol_ctl(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) struct hda_input_mux *imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) int i, err, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) for (i = 0; i < imux->num_items; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) bool inv_dmic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) idx = imux->items[i].index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) if (idx >= spec->autocfg.num_inputs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) for (type = 0; type < 2; type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) err = add_single_cap_ctl(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) spec->input_labels[idx],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) spec->input_label_idxs[idx],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) get_first_cap_ctl(codec, i, type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) inv_dmic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) static int create_capture_mixers(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) struct hda_input_mux *imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) int i, n, nums, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) if (spec->dyn_adc_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) nums = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) nums = spec->num_adc_nids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) if (!spec->auto_mic && imux->num_items > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) struct snd_kcontrol_new *knew;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) name = nums > 1 ? "Input Source" : "Capture Source";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) knew = snd_hda_gen_add_kctl(spec, name, &cap_src_temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) if (!knew)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) knew->count = nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) for (n = 0; n < nums; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) bool multi = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) bool multi_cap_vol = spec->multi_cap_vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) bool inv_dmic = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) int vol, sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) vol = sw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) for (i = 0; i < imux->num_items; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) path = get_input_path(codec, n, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) parse_capvol_in_path(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) if (!vol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) vol = path->ctls[NID_PATH_VOL_CTL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) multi = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) if (!same_amp_caps(codec, vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) path->ctls[NID_PATH_VOL_CTL], HDA_INPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) multi_cap_vol = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) if (!sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) sw = path->ctls[NID_PATH_MUTE_CTL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) else if (sw != path->ctls[NID_PATH_MUTE_CTL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) multi = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) if (!same_amp_caps(codec, sw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) multi_cap_vol = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) inv_dmic = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) if (!multi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) err = create_single_cap_vol_ctl(codec, n, vol, sw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) inv_dmic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) else if (!multi_cap_vol && !inv_dmic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) err = create_bind_cap_vol_ctl(codec, n, vol, sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) err = create_multi_cap_vol_ctl(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) * add mic boosts if needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) /* check whether the given amp is feasible as a boost volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) int dir, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) unsigned int step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) if (!nid_has_volume(codec, nid, dir) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) >> AC_AMPCAP_STEP_SIZE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) if (step < 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) /* look for a boost amp in a widget close to the pin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) static unsigned int look_for_boost_amp(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) struct nid_path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) unsigned int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) for (depth = 0; depth < 3; depth++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) if (depth >= path->depth - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) nid = path->path[depth];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) } else if (check_boost_vol(codec, nid, HDA_INPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) path->idx[depth])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) HDA_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) static int parse_mic_boost(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) struct hda_input_mux *imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) if (!spec->num_adc_nids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) for (i = 0; i < imux->num_items; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) char boost_label[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) idx = imux->items[i].index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) if (idx >= imux->num_items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) /* check only line-in and mic pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) path = get_input_path(codec, 0, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) val = look_for_boost_amp(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) /* create a boost control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) snprintf(boost_label, sizeof(boost_label),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) "%s Boost Volume", spec->input_labels[idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) if (!add_control(spec, HDA_CTL_WIDGET_VOL, boost_label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) spec->input_label_idxs[idx], val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) path->ctls[NID_PATH_BOOST_CTL] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) #ifdef CONFIG_SND_HDA_GENERIC_LEDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) * vmaster mute LED hook helpers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) static int create_mute_led_cdev(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) int (*callback)(struct led_classdev *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) enum led_brightness),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) bool micmute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) struct led_classdev *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) int idx = micmute ? LED_AUDIO_MICMUTE : LED_AUDIO_MUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) cdev = devm_kzalloc(&codec->core.dev, sizeof(*cdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) if (!cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) cdev->name = micmute ? "hda::micmute" : "hda::mute";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) cdev->max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) cdev->default_trigger = micmute ? "audio-micmute" : "audio-mute";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) cdev->brightness_set_blocking = callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) cdev->brightness = ledtrig_audio_get(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) cdev->flags = LED_CORE_SUSPENDRESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) err = led_classdev_register(&codec->core.dev, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) spec->led_cdevs[idx] = cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) static void vmaster_update_mute_led(void *private_data, int enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) ledtrig_audio_set(LED_AUDIO_MUTE, enabled ? LED_OFF : LED_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) * snd_dha_gen_add_mute_led_cdev - Create a LED classdev and enable as vmaster mute LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) * @callback: the callback for LED classdev brightness_set_blocking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) int (*callback)(struct led_classdev *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) enum led_brightness))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) if (callback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) err = create_mute_led_cdev(codec, callback, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) codec_warn(codec, "failed to create a mute LED cdev\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) if (spec->vmaster_mute.hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) codec_err(codec, "vmaster hook already present before cdev!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) spec->vmaster_mute.hook = vmaster_update_mute_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) spec->vmaster_mute_enum = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) EXPORT_SYMBOL_GPL(snd_hda_gen_add_mute_led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) * mic mute LED hook helpers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) MICMUTE_LED_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) MICMUTE_LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) MICMUTE_LED_FOLLOW_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) MICMUTE_LED_FOLLOW_MUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) static void call_micmute_led_update(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) switch (spec->micmute_led.led_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) case MICMUTE_LED_ON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) case MICMUTE_LED_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) case MICMUTE_LED_FOLLOW_CAPTURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) val = !!spec->micmute_led.capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) case MICMUTE_LED_FOLLOW_MUTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) val = !spec->micmute_led.capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) if (val == spec->micmute_led.led_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) spec->micmute_led.led_value = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) ledtrig_audio_set(LED_AUDIO_MICMUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) spec->micmute_led.led_value ? LED_ON : LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) static void update_micmute_led(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) unsigned int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) if (spec->micmute_led.old_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) spec->micmute_led.old_hook(codec, kcontrol, ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) if (!ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) mask = 1U << snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) if (!strcmp("Capture Switch", ucontrol->id.name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) /* TODO: How do I verify if it's a mono or stereo here? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) if (ucontrol->value.integer.value[0] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) ucontrol->value.integer.value[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) spec->micmute_led.capture |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) spec->micmute_led.capture &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) call_micmute_led_update(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) static int micmute_led_mode_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) static const char * const texts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) "On", "Off", "Follow Capture", "Follow Mute",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) static int micmute_led_mode_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) ucontrol->value.enumerated.item[0] = spec->micmute_led.led_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) static int micmute_led_mode_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) unsigned int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) mode = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) if (mode > MICMUTE_LED_FOLLOW_MUTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) mode = MICMUTE_LED_FOLLOW_MUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) if (mode == spec->micmute_led.led_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) spec->micmute_led.led_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) call_micmute_led_update(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) static const struct snd_kcontrol_new micmute_led_mode_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) .name = "Mic Mute-LED Mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) .info = micmute_led_mode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) .get = micmute_led_mode_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) .put = micmute_led_mode_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) /* Set up the capture sync hook for controlling the mic-mute LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) static int add_micmute_led_hook(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) spec->micmute_led.led_mode = MICMUTE_LED_FOLLOW_MUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) spec->micmute_led.capture = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) spec->micmute_led.led_value = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) spec->micmute_led.old_hook = spec->cap_sync_hook;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) spec->cap_sync_hook = update_micmute_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) if (!snd_hda_gen_add_kctl(spec, NULL, &micmute_led_mode_ctl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) * snd_dha_gen_add_micmute_led_cdev - Create a LED classdev and enable as mic-mute LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) * @callback: the callback for LED classdev brightness_set_blocking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) * Called from the codec drivers for offering the mic mute LED controls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) * This creates a LED classdev and sets up the cap_sync_hook that is called at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) * each time when the capture mixer switch changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) * When NULL is passed to @callback, no classdev is created but only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) * LED-trigger is set up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) * Returns 0 or a negative error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) int (*callback)(struct led_classdev *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) enum led_brightness))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) if (callback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) err = create_mute_led_cdev(codec, callback, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) codec_warn(codec, "failed to create a mic-mute LED cdev\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) return add_micmute_led_hook(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) EXPORT_SYMBOL_GPL(snd_hda_gen_add_micmute_led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) #endif /* CONFIG_SND_HDA_GENERIC_LEDS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) * parse digital I/Os and set up NIDs in BIOS auto-parse mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) static void parse_digital(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) int i, nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) hda_nid_t dig_nid, pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) /* support multiple SPDIFs; the secondary is set up as a follower */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) nums = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) for (i = 0; i < spec->autocfg.dig_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) pin = spec->autocfg.dig_out_pins[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) dig_nid = look_for_dac(codec, pin, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) if (!dig_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) print_nid_path(codec, "digout", path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) path->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) path->pin_fixed = true; /* no jack detection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) set_pin_target(codec, pin, PIN_OUT, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) if (!nums) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) spec->multiout.dig_out_nid = dig_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) spec->dig_out_type = spec->autocfg.dig_out_type[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) spec->multiout.follower_dig_outs = spec->follower_dig_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) if (nums >= ARRAY_SIZE(spec->follower_dig_outs) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) spec->follower_dig_outs[nums - 1] = dig_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) nums++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) if (spec->autocfg.dig_in_pin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) pin = spec->autocfg.dig_in_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) for_each_hda_codec_node(dig_nid, codec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) unsigned int wcaps = get_wcaps(codec, dig_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) if (!(wcaps & AC_WCAP_DIGITAL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) if (path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) print_nid_path(codec, "digin", path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) path->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) path->pin_fixed = true; /* no jack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) spec->dig_in_nid = dig_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) spec->digin_path = snd_hda_get_path_idx(codec, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) set_pin_target(codec, pin, PIN_IN, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) * input MUX handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) /* select the given imux item; either unmute exclusively or select the route */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) unsigned int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) const struct hda_input_mux *imux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) struct nid_path *old_path, *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) if (!imux->num_items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) if (idx >= imux->num_items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) idx = imux->num_items - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) if (spec->cur_mux[adc_idx] == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) if (!old_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) if (old_path->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) snd_hda_activate_path(codec, old_path, false, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) spec->cur_mux[adc_idx] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) if (spec->hp_mic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) update_hp_mic(codec, adc_idx, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) if (spec->dyn_adc_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) dyn_adc_pcm_resetup(codec, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) path = get_input_path(codec, adc_idx, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) if (path->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) snd_hda_activate_path(codec, path, true, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) if (spec->cap_sync_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) spec->cap_sync_hook(codec, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) path_power_down_sync(codec, old_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) /* power up/down widgets in the all paths that match with the given NID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) * as terminals (either start- or endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) * returns the last changed NID, or zero if unchanged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) int pin_state, int stream_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) hda_nid_t last, changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) snd_array_for_each(&spec->paths, n, path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) if (!path->depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) if (path->path[0] == nid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) path->path[path->depth - 1] == nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) bool pin_old = path->pin_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) bool stream_old = path->stream_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) if (pin_state >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) path->pin_enabled = pin_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) if (stream_state >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) path->stream_enabled = stream_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) if ((!path->pin_fixed && path->pin_enabled != pin_old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) || path->stream_enabled != stream_old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) last = path_power_update(codec, path, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) if (last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) changed = last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) /* check the jack status for power control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) static bool detect_pin_state(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) if (!is_jack_detectable(codec, pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) return snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) /* power up/down the paths of the given pin according to the jack state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) * power = 0/1 : only power up/down if it matches with the jack state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) * < 0 : force power up/down to follow the jack sate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) * returns the last changed NID, or zero if unchanged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) int power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) bool on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) if (!codec->power_save_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) on = detect_pin_state(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) if (power >= 0 && on != power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) return set_path_power(codec, pin, on, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) static void pin_power_callback(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) struct hda_jack_callback *jack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) bool on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) if (jack && jack->nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) sync_power_state_change(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) set_pin_power_jack(codec, jack->nid, on));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) /* callback only doing power up -- called at first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) static void pin_power_up_callback(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) struct hda_jack_callback *jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) pin_power_callback(codec, jack, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) /* callback only doing power down -- called at last */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) static void pin_power_down_callback(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) struct hda_jack_callback *jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) pin_power_callback(codec, jack, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) /* set up the power up/down callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) const hda_nid_t *pins, bool on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) hda_jack_callback_fn cb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) on ? pin_power_up_callback : pin_power_down_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) for (i = 0; i < num_pins && pins[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) if (is_jack_detectable(codec, pins[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) set_path_power(codec, pins[i], true, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) /* enabled power callback to each available I/O pin with jack detections;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) * the digital I/O pins are excluded because of the unreliable detectsion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) if (!codec->power_save_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) if (cfg->line_out_type != AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) for (i = 0; i < cfg->num_inputs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) /* sync path power up/down with the jack states of given pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) const hda_nid_t *pins)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) for (i = 0; i < num_pins && pins[i]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) if (is_jack_detectable(codec, pins[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) set_pin_power_jack(codec, pins[i], -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) /* sync path power up/down with pins; called at init and resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) static void sync_all_pin_power_ctls(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) if (!codec->power_save_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) if (cfg->line_out_type != AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) for (i = 0; i < cfg->num_inputs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) /* add fake paths if not present yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) int num_pins, const hda_nid_t *pins)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) for (i = 0; i < num_pins; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) if (!pins[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) if (get_nid_path(codec, nid, pins[i], 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) path = snd_array_new(&spec->paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) memset(path, 0, sizeof(*path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) path->depth = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) path->path[0] = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) path->path[1] = pins[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) path->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) /* create fake paths to all outputs from beep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) static int add_fake_beep_paths(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) hda_nid_t nid = spec->beep_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) if (!codec->power_save_node || !nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) err = add_fake_paths(codec, nid, cfg->speaker_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) cfg->speaker_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) /* power up/down beep widget and its output paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) static void beep_power_hook(struct hda_beep *beep, bool on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) set_path_power(beep->codec, beep->nid, -1, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) * @pin: NID of pin to fix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) path = snd_array_new(&spec->paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) memset(path, 0, sizeof(*path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) path->depth = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) path->path[0] = pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) path->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) path->pin_fixed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) path->stream_enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) EXPORT_SYMBOL_GPL(snd_hda_gen_fix_pin_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) * Jack detections for HP auto-mute and mic-switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) /* check each pin in the given array; returns true if any of them is plugged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) static bool detect_jacks(struct hda_codec *codec, int num_pins, const hda_nid_t *pins)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) bool present = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) for (i = 0; i < num_pins; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) hda_nid_t nid = pins[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) if (!nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) /* don't detect pins retasked as inputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) if (snd_hda_jack_detect_state(codec, nid) == HDA_JACK_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) present = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) return present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) /* standard HP/line-out auto-mute helper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) static void do_automute(struct hda_codec *codec, int num_pins, const hda_nid_t *pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) int *paths, bool mute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) for (i = 0; i < num_pins; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) hda_nid_t nid = pins[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) unsigned int val, oldval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) if (!nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) oldval = snd_hda_codec_get_pin_target(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) if (oldval & PIN_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) continue; /* no mute for inputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) if (spec->auto_mute_via_amp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) hda_nid_t mute_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) path = snd_hda_get_path_from_idx(codec, paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) mute_nid = get_amp_nid_(path->ctls[NID_PATH_MUTE_CTL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) if (!mute_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) if (mute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) spec->mute_bits |= (1ULL << mute_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) spec->mute_bits &= ~(1ULL << mute_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) /* don't reset VREF value in case it's controlling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) * the amp (see alc861_fixup_asus_amp_vref_0f())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) if (spec->keep_vref_in_automute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) val = oldval & ~PIN_HP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) if (!mute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) val |= oldval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) /* here we call update_pin_ctl() so that the pinctl is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) * changed without changing the pinctl target value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) * the original target value will be still referred at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) * the init / resume again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) update_pin_ctl(codec, nid, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) set_pin_eapd(codec, nid, !mute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) if (codec->power_save_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) bool on = !mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) if (on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) on = detect_pin_state(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) set_path_power(codec, nid, on, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) * snd_hda_gen_update_outputs - Toggle outputs muting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) * Update the mute status of all outputs based on the current jack states.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) void snd_hda_gen_update_outputs(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) int *paths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) int on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) /* Control HP pins/amps depending on master_mute state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) * in general, HP pins/amps control should be enabled in all cases,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) * but currently set only for master_mute, just to be safe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) paths = spec->out_paths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) paths = spec->hp_paths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) spec->autocfg.hp_pins, paths, spec->master_mute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) if (!spec->automute_speaker)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) on = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) on = spec->hp_jack_present | spec->line_jack_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) on |= spec->master_mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) spec->speaker_muted = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) paths = spec->out_paths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) paths = spec->speaker_paths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) spec->autocfg.speaker_pins, paths, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) /* toggle line-out mutes if needed, too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) /* if LO is a copy of either HP or Speaker, don't need to handle it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) if (!spec->automute_lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) on = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) on = spec->hp_jack_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) on |= spec->master_mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) spec->line_out_muted = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) paths = spec->out_paths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) spec->autocfg.line_out_pins, paths, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) EXPORT_SYMBOL_GPL(snd_hda_gen_update_outputs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) static void call_update_outputs(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) if (spec->automute_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) spec->automute_hook(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) snd_hda_gen_update_outputs(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) /* sync the whole vmaster followers to reflect the new auto-mute status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) if (spec->auto_mute_via_amp && !codec->bus->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) snd_ctl_sync_vmaster(spec->vmaster_mute.sw_kctl, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) * snd_hda_gen_hp_automute - standard HP-automute helper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) * @jack: jack object, NULL for the whole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) void snd_hda_gen_hp_automute(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) struct hda_jack_callback *jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) hda_nid_t *pins = spec->autocfg.hp_pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) int num_pins = ARRAY_SIZE(spec->autocfg.hp_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) /* No detection for the first HP jack during indep-HP mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) if (spec->indep_hp_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) pins++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) num_pins--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) call_update_outputs(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) EXPORT_SYMBOL_GPL(snd_hda_gen_hp_automute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) * snd_hda_gen_line_automute - standard line-out-automute helper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) * @jack: jack object, NULL for the whole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) void snd_hda_gen_line_automute(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) struct hda_jack_callback *jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) /* check LO jack only when it's different from HP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) spec->line_jack_present =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) spec->autocfg.line_out_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) if (!spec->automute_speaker || !spec->detect_lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) call_update_outputs(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) EXPORT_SYMBOL_GPL(snd_hda_gen_line_automute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) * snd_hda_gen_mic_autoswitch - standard mic auto-switch helper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) * @jack: jack object, NULL for the whole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) struct hda_jack_callback *jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) if (!spec->auto_mic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) for (i = spec->am_num_entries - 1; i > 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) hda_nid_t pin = spec->am_entry[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) /* don't detect pins retasked as outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) if (snd_hda_jack_detect_state(codec, pin) == HDA_JACK_PRESENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) mux_select(codec, 0, spec->am_entry[i].idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) mux_select(codec, 0, spec->am_entry[0].idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) EXPORT_SYMBOL_GPL(snd_hda_gen_mic_autoswitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) /* call appropriate hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) static void call_hp_automute(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) struct hda_jack_callback *jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) if (spec->hp_automute_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) spec->hp_automute_hook(codec, jack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) snd_hda_gen_hp_automute(codec, jack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) static void call_line_automute(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) struct hda_jack_callback *jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) if (spec->line_automute_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) spec->line_automute_hook(codec, jack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) snd_hda_gen_line_automute(codec, jack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) static void call_mic_autoswitch(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) struct hda_jack_callback *jack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) if (spec->mic_autoswitch_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) spec->mic_autoswitch_hook(codec, jack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) snd_hda_gen_mic_autoswitch(codec, jack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) /* update jack retasking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) static void update_automute_all(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) call_hp_automute(codec, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) call_line_automute(codec, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) call_mic_autoswitch(codec, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) * Auto-Mute mode mixer enum support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) static int automute_mode_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) static const char * const texts3[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) "Disabled", "Speaker Only", "Line Out+Speaker"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) if (spec->automute_speaker_possible && spec->automute_lo_possible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) static int automute_mode_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) unsigned int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) if (spec->automute_speaker)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) val++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) if (spec->automute_lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) val++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) ucontrol->value.enumerated.item[0] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) static int automute_mode_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) switch (ucontrol->value.enumerated.item[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) if (!spec->automute_speaker && !spec->automute_lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) spec->automute_speaker = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) spec->automute_lo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) if (spec->automute_speaker_possible) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) if (!spec->automute_lo && spec->automute_speaker)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) spec->automute_speaker = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) spec->automute_lo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) } else if (spec->automute_lo_possible) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) if (spec->automute_lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) spec->automute_lo = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) if (spec->automute_speaker && spec->automute_lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) spec->automute_speaker = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) spec->automute_lo = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) call_update_outputs(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) static const struct snd_kcontrol_new automute_mode_enum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) .name = "Auto-Mute Mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) .info = automute_mode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) .get = automute_mode_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) .put = automute_mode_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) static int add_automute_mode_enum(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) if (!snd_hda_gen_add_kctl(spec, NULL, &automute_mode_enum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) * Check the availability of HP/line-out auto-mute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) * Set up appropriately if really supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) static int check_auto_mute_availability(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) int present = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) if (spec->suppress_auto_mute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) if (cfg->hp_pins[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) present++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) if (cfg->line_out_pins[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) present++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) if (cfg->speaker_pins[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) present++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) if (present < 2) /* need two different output types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) if (!cfg->speaker_pins[0] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) memcpy(cfg->speaker_pins, cfg->line_out_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) sizeof(cfg->speaker_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) cfg->speaker_outs = cfg->line_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) if (!cfg->hp_pins[0] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) cfg->line_out_type == AUTO_PIN_HP_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) memcpy(cfg->hp_pins, cfg->line_out_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) sizeof(cfg->hp_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) cfg->hp_outs = cfg->line_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) for (i = 0; i < cfg->hp_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) hda_nid_t nid = cfg->hp_pins[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) if (!is_jack_detectable(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) snd_hda_jack_detect_enable_callback(codec, nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) call_hp_automute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) spec->detect_hp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) if (cfg->speaker_outs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) for (i = 0; i < cfg->line_outs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) hda_nid_t nid = cfg->line_out_pins[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) if (!is_jack_detectable(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) snd_hda_jack_detect_enable_callback(codec, nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) call_line_automute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) spec->detect_lo = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) spec->automute_lo_possible = spec->detect_hp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) spec->automute_speaker_possible = cfg->speaker_outs &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) (spec->detect_hp || spec->detect_lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) spec->automute_lo = spec->automute_lo_possible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) spec->automute_speaker = spec->automute_speaker_possible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) if (spec->automute_speaker_possible || spec->automute_lo_possible) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) /* create a control for automute mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) err = add_automute_mode_enum(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) /* check whether all auto-mic pins are valid; setup indices if OK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) static bool auto_mic_check_imux(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) const struct hda_input_mux *imux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) for (i = 0; i < spec->am_num_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) spec->am_entry[i].idx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) find_idx_in_nid_list(spec->am_entry[i].pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) spec->imux_pins, imux->num_items);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) if (spec->am_entry[i].idx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) return false; /* no corresponding imux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) /* we don't need the jack detection for the first pin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) for (i = 1; i < spec->am_num_entries; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) snd_hda_jack_detect_enable_callback(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) spec->am_entry[i].pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) call_mic_autoswitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) static int compare_attr(const void *ap, const void *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) const struct automic_entry *a = ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) const struct automic_entry *b = bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) return (int)(a->attr - b->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) * Check the availability of auto-mic switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) * Set up if really supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) static int check_auto_mic_availability(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) unsigned int types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) int i, num_pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) if (spec->suppress_auto_mic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) types = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) num_pins = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) for (i = 0; i < cfg->num_inputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) hda_nid_t nid = cfg->inputs[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) unsigned int attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) attr = snd_hda_codec_get_pincfg(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) attr = snd_hda_get_input_pin_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) if (types & (1 << attr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) return 0; /* already occupied */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) case INPUT_PIN_ATTR_INT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) if (cfg->inputs[i].type != AUTO_PIN_MIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) return 0; /* invalid type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) case INPUT_PIN_ATTR_UNUSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) return 0; /* invalid entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) return 0; /* invalid type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) if (!spec->line_in_auto_switch &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) cfg->inputs[i].type != AUTO_PIN_MIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) return 0; /* only mic is allowed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) if (!is_jack_detectable(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) return 0; /* no unsol support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) if (num_pins >= MAX_AUTO_MIC_PINS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) types |= (1 << attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) spec->am_entry[num_pins].pin = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) spec->am_entry[num_pins].attr = attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) num_pins++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) if (num_pins < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) spec->am_num_entries = num_pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) /* sort the am_entry in the order of attr so that the pin with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) * higher attr will be selected when the jack is plugged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) compare_attr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) if (!auto_mic_check_imux(codec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) spec->auto_mic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) spec->num_adc_nids = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) spec->cur_mux[0] = spec->am_entry[0].idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) spec->am_entry[0].pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) spec->am_entry[1].pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) spec->am_entry[2].pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) * snd_hda_gen_path_power_filter - power_filter hook to make inactive widgets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) * into power down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) * @nid: NID to evalute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) * @power_state: target power state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) unsigned int power_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) if (!spec->power_down_unused && !codec->power_save_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) return power_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) if (power_state != AC_PWRST_D0 || nid == codec->core.afg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) return power_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) return power_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) if (is_active_nid_for_any(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) return power_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) return AC_PWRST_D3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) EXPORT_SYMBOL_GPL(snd_hda_gen_path_power_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) /* mute all aamix inputs initially; parse up to the first leaves */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) int i, nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) const hda_nid_t *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) bool has_amp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) nums = snd_hda_get_conn_list(codec, mix, &conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) has_amp = nid_has_mute(codec, mix, HDA_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) for (i = 0; i < nums; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) if (has_amp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) update_amp(codec, mix, HDA_INPUT, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) 0xff, HDA_AMP_MUTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) else if (nid_has_volume(codec, conn[i], HDA_OUTPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) update_amp(codec, conn[i], HDA_OUTPUT, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) 0xff, HDA_AMP_MUTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) * snd_hda_gen_stream_pm - Stream power management callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) * @nid: audio widget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) * @on: power on/off flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) * Set this in patch_ops.stream_pm. Only valid with power_save_node flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) if (codec->power_save_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) set_path_power(codec, nid, -1, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) * set up the hda_gen_spec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) * @cfg: Parsed pin configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) * return 1 if successful, 0 if the proper config is not found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) * or a negative error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) struct auto_pin_cfg *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) parse_user_hints(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) if (spec->mixer_nid && !spec->mixer_merge_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) spec->mixer_merge_nid = spec->mixer_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) if (cfg != &spec->autocfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) spec->autocfg = *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) if (!spec->main_out_badness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) spec->main_out_badness = &hda_main_out_badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) if (!spec->extra_out_badness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) spec->extra_out_badness = &hda_extra_out_badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) fill_all_dac_nids(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) if (!cfg->line_outs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) if (cfg->dig_outs || cfg->dig_in_pin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) spec->multiout.max_channels = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) spec->no_analog = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) goto dig_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) if (!cfg->num_inputs && !cfg->dig_in_pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) return 0; /* can't find valid BIOS pin config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) if (!spec->no_primary_hp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) cfg->line_outs <= cfg->hp_outs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) /* use HP as primary out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) cfg->speaker_outs = cfg->line_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) memcpy(cfg->speaker_pins, cfg->line_out_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) sizeof(cfg->speaker_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) cfg->line_outs = cfg->hp_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) cfg->hp_outs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) cfg->line_out_type = AUTO_PIN_HP_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) err = parse_output_paths(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) err = create_multi_channel_mode(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) err = create_multi_out_ctls(codec, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) err = create_hp_out_ctls(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) err = create_speaker_out_ctls(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) err = create_indep_hp_ctls(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) err = create_loopback_mixing_ctl(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) err = create_hp_mic(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) err = create_input_ctls(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) /* add power-down pin callbacks at first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) add_all_pin_power_ctls(codec, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) spec->const_channel_count = spec->ext_channel_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) /* check the multiple speaker and headphone pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) spec->const_channel_count = max(spec->const_channel_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) cfg->speaker_outs * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) if (cfg->line_out_type != AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) spec->const_channel_count = max(spec->const_channel_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) cfg->hp_outs * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) spec->multiout.max_channels = max(spec->ext_channel_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) spec->const_channel_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) err = check_auto_mute_availability(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) err = check_dyn_adc_switch(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) err = check_auto_mic_availability(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) /* add stereo mix if available and not enabled yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) if (!spec->auto_mic && spec->mixer_nid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) spec->add_stereo_mix_input == HDA_HINT_STEREO_MIX_AUTO &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) spec->input_mux.num_items > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) err = parse_capture_source(codec, spec->mixer_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) CFG_IDX_MIX, spec->num_all_adcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) "Stereo Mix", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) err = create_capture_mixers(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) err = parse_mic_boost(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) /* create "Headphone Mic Jack Mode" if no input selection is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) * available (or user specifies add_jack_modes hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) if (spec->hp_mic_pin &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) (spec->auto_mic || spec->input_mux.num_items == 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) spec->add_jack_modes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) err = create_hp_mic_jack_mode(codec, spec->hp_mic_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) if (spec->add_jack_modes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) err = create_out_jack_modes(codec, cfg->line_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) cfg->line_out_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) err = create_out_jack_modes(codec, cfg->hp_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) cfg->hp_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) /* add power-up pin callbacks at last */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) add_all_pin_power_ctls(codec, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) /* mute all aamix input initially */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) if (spec->mixer_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) mute_all_mixer_nid(codec, spec->mixer_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) dig_only:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) parse_digital(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) if (spec->power_down_unused || codec->power_save_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) if (!codec->power_filter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) codec->power_filter = snd_hda_gen_path_power_filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) if (!codec->patch_ops.stream_pm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) codec->patch_ops.stream_pm = snd_hda_gen_stream_pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) if (!spec->no_analog && spec->beep_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) err = snd_hda_attach_beep_device(codec, spec->beep_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) if (codec->beep && codec->power_save_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) err = add_fake_beep_paths(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) codec->beep->power_hook = beep_power_hook;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) EXPORT_SYMBOL_GPL(snd_hda_gen_parse_auto_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) * Build control elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) /* follower controls for virtual master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) static const char * const follower_pfxs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) "Front", "Surround", "Center", "LFE", "Side",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) "Headphone", "Speaker", "Mono", "Line Out",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) "CLFE", "Bass Speaker", "PCM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) "Headphone Front", "Headphone Surround", "Headphone CLFE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) "Headphone Side", "Headphone+LO", "Speaker+LO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) * snd_hda_gen_build_controls - Build controls from the parsed results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) * Pass this to build_controls patch_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) int snd_hda_gen_build_controls(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) if (spec->kctls.used) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) err = snd_hda_add_new_ctls(codec, spec->kctls.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) if (spec->multiout.dig_out_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) err = snd_hda_create_dig_out_ctls(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) spec->multiout.dig_out_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) spec->multiout.dig_out_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) spec->pcm_rec[1]->pcm_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) if (!spec->no_analog) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) err = snd_hda_create_spdif_share_sw(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) &spec->multiout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) spec->multiout.share_spdif = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) if (spec->dig_in_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) /* if we have no master control, let's create it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) if (!spec->no_analog && !spec->suppress_vmaster &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) err = snd_hda_add_vmaster(codec, "Master Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) spec->vmaster_tlv, follower_pfxs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) "Playback Volume");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) if (!spec->no_analog && !spec->suppress_vmaster &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) NULL, follower_pfxs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) "Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) true, &spec->vmaster_mute.sw_kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) if (spec->vmaster_mute.hook) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) spec->vmaster_mute_enum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) free_kctls(spec); /* no longer needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) EXPORT_SYMBOL_GPL(snd_hda_gen_build_controls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) * PCM definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) static void call_pcm_playback_hook(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) int action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) if (spec->pcm_playback_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) spec->pcm_playback_hook(hinfo, codec, substream, action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) static void call_pcm_capture_hook(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) int action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) if (spec->pcm_capture_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) spec->pcm_capture_hook(hinfo, codec, substream, action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) * Analog playback callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) static int playback_pcm_open(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) mutex_lock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) err = snd_hda_multi_out_analog_open(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) &spec->multiout, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) hinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) spec->active_streams |= 1 << STREAM_MULTI_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) call_pcm_playback_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) HDA_GEN_PCM_ACT_OPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) mutex_unlock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) unsigned int stream_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) unsigned int format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) stream_tag, format, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) call_pcm_playback_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) HDA_GEN_PCM_ACT_PREPARE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) call_pcm_playback_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) HDA_GEN_PCM_ACT_CLEANUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) static int playback_pcm_close(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) mutex_lock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) call_pcm_playback_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) HDA_GEN_PCM_ACT_CLOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) mutex_unlock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) static int capture_pcm_open(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) static int capture_pcm_prepare(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) unsigned int stream_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) unsigned int format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) call_pcm_capture_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) HDA_GEN_PCM_ACT_PREPARE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) static int capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) snd_hda_codec_cleanup_stream(codec, hinfo->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) call_pcm_capture_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) HDA_GEN_PCM_ACT_CLEANUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) static int capture_pcm_close(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) mutex_lock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) if (spec->indep_hp && !spec->indep_hp_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) spec->active_streams |= 1 << STREAM_INDEP_HP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) call_pcm_playback_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) HDA_GEN_PCM_ACT_OPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) mutex_unlock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) static int alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) mutex_lock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) spec->active_streams &= ~(1 << STREAM_INDEP_HP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) call_pcm_playback_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) HDA_GEN_PCM_ACT_CLOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) mutex_unlock(&spec->pcm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) static int alt_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) unsigned int stream_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) unsigned int format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) call_pcm_playback_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) HDA_GEN_PCM_ACT_PREPARE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) static int alt_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) snd_hda_codec_cleanup_stream(codec, hinfo->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) call_pcm_playback_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) HDA_GEN_PCM_ACT_CLEANUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) * Digital out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) static int dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) return snd_hda_multi_out_dig_open(codec, &spec->multiout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) static int dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) unsigned int stream_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) unsigned int format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) stream_tag, format, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) static int dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) static int dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) return snd_hda_multi_out_dig_close(codec, &spec->multiout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568) * Analog capture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) #define alt_capture_pcm_open capture_pcm_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) #define alt_capture_pcm_close capture_pcm_close
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) static int alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) unsigned int stream_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) unsigned int format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) stream_tag, 0, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) call_pcm_capture_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) HDA_GEN_PCM_ACT_PREPARE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) static int alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) snd_hda_codec_cleanup_stream(codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) spec->adc_nids[substream->number + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) call_pcm_capture_hook(hinfo, codec, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) HDA_GEN_PCM_ACT_CLEANUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603) static const struct hda_pcm_stream pcm_analog_playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) .substreams = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) .channels_max = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) /* NID is set in build_pcms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) .open = playback_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) .close = playback_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) .prepare = playback_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) .cleanup = playback_pcm_cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) static const struct hda_pcm_stream pcm_analog_capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) .substreams = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) /* NID is set in build_pcms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) .open = capture_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) .close = capture_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) .prepare = capture_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) .cleanup = capture_pcm_cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) static const struct hda_pcm_stream pcm_analog_alt_playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) .substreams = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) /* NID is set in build_pcms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) .open = alt_playback_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) .close = alt_playback_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) .prepare = alt_playback_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) .cleanup = alt_playback_pcm_cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) static const struct hda_pcm_stream pcm_analog_alt_capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) .substreams = 2, /* can be overridden */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646) /* NID is set in build_pcms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648) .open = alt_capture_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649) .close = alt_capture_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) .prepare = alt_capture_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) .cleanup = alt_capture_pcm_cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) static const struct hda_pcm_stream pcm_digital_playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) .substreams = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) /* NID is set in build_pcms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) .open = dig_playback_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) .close = dig_playback_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) .prepare = dig_playback_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) .cleanup = dig_playback_pcm_cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) static const struct hda_pcm_stream pcm_digital_capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) .substreams = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) /* NID is set in build_pcms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) /* Used by build_pcms to flag that a PCM has no playback stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) static const struct hda_pcm_stream pcm_null_stream = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) .substreams = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) .channels_min = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) .channels_max = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) * dynamic changing ADC PCM streams
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) if (spec->cur_adc && spec->cur_adc != new_adc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) /* stream is running, let's swap the current ADC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) spec->cur_adc = new_adc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) snd_hda_codec_setup_stream(codec, new_adc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) spec->cur_adc_stream_tag, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) spec->cur_adc_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) /* analog capture with dynamic dual-adc changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) unsigned int stream_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) unsigned int format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) spec->cur_adc_stream_tag = stream_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) spec->cur_adc_format = format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_PREPARE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) spec->cur_adc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLEANUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) .substreams = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) .nid = 0, /* fill later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) .prepare = dyn_adc_capture_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) .cleanup = dyn_adc_capture_pcm_cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) const char *chip_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) if (*str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) strlcpy(str, chip_name, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) /* drop non-alnum chars after a space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) for (p = strchr(str, ' '); p; p = strchr(p + 1, ' ')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) if (!isalnum(p[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) *p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) strlcat(str, sfx, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) /* copy PCM stream info from @default_str, and override non-NULL entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) * from @spec_str and @nid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) static void setup_pcm_stream(struct hda_pcm_stream *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) const struct hda_pcm_stream *default_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764) const struct hda_pcm_stream *spec_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765) hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) *str = *default_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) if (nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) str->nid = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) if (spec_str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) if (spec_str->substreams)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) str->substreams = spec_str->substreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) if (spec_str->channels_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) str->channels_min = spec_str->channels_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) if (spec_str->channels_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) str->channels_max = spec_str->channels_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) if (spec_str->rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) str->rates = spec_str->rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) if (spec_str->formats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) str->formats = spec_str->formats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781) if (spec_str->maxbps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) str->maxbps = spec_str->maxbps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) * Pass this to build_pcms patch_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) int snd_hda_gen_build_pcms(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) struct hda_pcm *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796) bool have_multi_adcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) if (spec->no_analog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) goto skip_analog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) fill_pcm_stream_name(spec->stream_name_analog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) sizeof(spec->stream_name_analog),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) " Analog", codec->core.chip_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) info = snd_hda_codec_pcm_new(codec, "%s", spec->stream_name_analog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) spec->pcm_rec[0] = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) if (spec->multiout.num_dacs > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) &pcm_analog_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) spec->stream_analog_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) spec->multiout.dac_nids[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) spec->multiout.max_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) spec->autocfg.line_outs == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) snd_pcm_2_1_chmaps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) if (spec->num_adc_nids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) (spec->dyn_adc_switch ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) &dyn_adc_pcm_analog_capture : &pcm_analog_capture),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) spec->stream_analog_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) spec->adc_nids[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) skip_analog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) /* SPDIF for stream index #1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) fill_pcm_stream_name(spec->stream_name_digital,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) sizeof(spec->stream_name_digital),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) " Digital", codec->core.chip_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) info = snd_hda_codec_pcm_new(codec, "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) spec->stream_name_digital);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) codec->follower_dig_outs = spec->multiout.follower_dig_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) spec->pcm_rec[1] = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) if (spec->dig_out_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) info->pcm_type = spec->dig_out_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) info->pcm_type = HDA_PCM_TYPE_SPDIF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) if (spec->multiout.dig_out_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847) &pcm_digital_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848) spec->stream_digital_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) spec->multiout.dig_out_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) if (spec->dig_in_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) &pcm_digital_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) spec->stream_digital_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854) spec->dig_in_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) if (spec->no_analog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) /* If the use of more than one ADC is requested for the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) * model, configure a second analog capture-only PCM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) have_multi_adcs = (spec->num_adc_nids > 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) !spec->dyn_adc_switch && !spec->auto_mic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) /* Additional Analaog capture for index #2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) if (spec->alt_dac_nid || have_multi_adcs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) fill_pcm_stream_name(spec->stream_name_alt_analog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) sizeof(spec->stream_name_alt_analog),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) " Alt Analog", codec->core.chip_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) info = snd_hda_codec_pcm_new(codec, "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) spec->stream_name_alt_analog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) spec->pcm_rec[2] = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) if (spec->alt_dac_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) &pcm_analog_alt_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) spec->stream_analog_alt_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879) spec->alt_dac_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) &pcm_null_stream, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) if (have_multi_adcs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) &pcm_analog_alt_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) spec->stream_analog_alt_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) spec->adc_nids[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) spec->num_adc_nids - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) &pcm_null_stream, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) EXPORT_SYMBOL_GPL(snd_hda_gen_build_pcms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902) * Standard auto-parser initializations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) /* configure the given path as a proper output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) hda_nid_t pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911) path = snd_hda_get_path_from_idx(codec, path_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) if (!path || !path->depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) pin = path->path[path->depth - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) restore_pin_ctl(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) snd_hda_activate_path(codec, path, path->active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) aamix_default(codec->spec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) set_pin_eapd(codec, pin, path->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) /* initialize primary output paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) static void init_multi_out(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) for (i = 0; i < spec->autocfg.line_outs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) set_output_and_unmute(codec, spec->out_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) for (i = 0; i < num_outs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) set_output_and_unmute(codec, paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) /* initialize hp and speaker paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) static void init_extra_out(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) __init_extra_out(codec, spec->autocfg.speaker_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) spec->speaker_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) /* initialize multi-io paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) static void init_multi_io(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) for (i = 0; i < spec->multi_ios; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) hda_nid_t pin = spec->multi_io[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) path = get_multiio_path(codec, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962) if (!path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) if (!spec->multi_io[i].ctl_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) spec->multi_io[i].ctl_in =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) snd_hda_codec_get_pin_target(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) snd_hda_activate_path(codec, path, path->active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) aamix_default(spec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) static void init_aamix_paths(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) if (!spec->have_aamix_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) if (!has_aamix_out_paths(spec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) spec->aamix_out_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) spec->autocfg.line_out_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983) update_aamix_paths(codec, spec->aamix_mode, spec->hp_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) spec->aamix_out_paths[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) AUTO_PIN_HP_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) update_aamix_paths(codec, spec->aamix_mode, spec->speaker_paths[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) spec->aamix_out_paths[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) AUTO_PIN_SPEAKER_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) /* set up input pins and loopback paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) static void init_analog_input(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) struct auto_pin_cfg *cfg = &spec->autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) for (i = 0; i < cfg->num_inputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) hda_nid_t nid = cfg->inputs[i].pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) if (is_input_pin(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) restore_pin_ctl(codec, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) /* init loopback inputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) if (spec->mixer_nid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) resume_path_from_idx(codec, spec->loopback_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) resume_path_from_idx(codec, spec->loopback_merge_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) /* initialize ADC paths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) static void init_input_src(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) struct hda_input_mux *imux = &spec->input_mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) struct nid_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) int i, c, nums;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) if (spec->dyn_adc_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020) nums = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022) nums = spec->num_adc_nids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024) for (c = 0; c < nums; c++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025) for (i = 0; i < imux->num_items; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) path = get_input_path(codec, c, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027) if (path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) bool active = path->active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) if (i == spec->cur_mux[c])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) snd_hda_activate_path(codec, path, active, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) if (spec->hp_mic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) update_hp_mic(codec, c, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) if (spec->cap_sync_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) spec->cap_sync_hook(codec, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) /* set right pin controls for digital I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) static void init_digital(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) hda_nid_t pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) for (i = 0; i < spec->autocfg.dig_outs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) set_output_and_unmute(codec, spec->digout_paths[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) pin = spec->autocfg.dig_in_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052) if (pin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) restore_pin_ctl(codec, pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) resume_path_from_idx(codec, spec->digin_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) * invalid unsol tags by some reason
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) static void clear_unsol_on_unused_pins(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) const struct hda_pincfg *pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) snd_array_for_each(&codec->init_pins, i, pin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) hda_nid_t nid = pin->nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) if (is_jack_detectable(codec, nid) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) !snd_hda_jack_tbl_get(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) snd_hda_codec_write_cache(codec, nid, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) AC_VERB_SET_UNSOLICITED_ENABLE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) * snd_hda_gen_init - initialize the generic spec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) * This can be put as patch_ops init function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) int snd_hda_gen_init(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) if (spec->init_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) spec->init_hook(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) if (!spec->skip_verbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089) snd_hda_apply_verbs(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091) init_multi_out(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) init_extra_out(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) init_multi_io(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) init_aamix_paths(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) init_analog_input(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) init_input_src(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) init_digital(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) clear_unsol_on_unused_pins(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) sync_all_pin_power_ctls(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) /* call init functions of standard auto-mute helpers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) update_automute_all(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) snd_hda_regmap_sync(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) hda_call_check_power_status(codec, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) EXPORT_SYMBOL_GPL(snd_hda_gen_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) * snd_hda_gen_free - free the generic spec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) * This can be put as patch_ops free function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) void snd_hda_gen_free(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) snd_hda_gen_spec_free(codec->spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) kfree(codec->spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127) codec->spec = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) EXPORT_SYMBOL_GPL(snd_hda_gen_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) * snd_hda_gen_reboot_notify - Make codec enter D3 before rebooting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) * This can be put as patch_ops reboot_notify function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) void snd_hda_gen_reboot_notify(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) /* Make the codec enter D3 to avoid spurious noises from the internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) * speaker during (and after) reboot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) snd_hda_codec_write(codec, codec->core.afg, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) EXPORT_SYMBOL_GPL(snd_hda_gen_reboot_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) * snd_hda_gen_check_power_status - check the loopback power save state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) * @nid: NID to inspect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) * This can be put as patch_ops check_power_status function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) struct hda_gen_spec *spec = codec->spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) EXPORT_SYMBOL_GPL(snd_hda_gen_check_power_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) * the generic codec support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) static const struct hda_codec_ops generic_patch_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) .build_controls = snd_hda_gen_build_controls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) .build_pcms = snd_hda_gen_build_pcms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173) .init = snd_hda_gen_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) .free = snd_hda_gen_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) .unsol_event = snd_hda_jack_unsol_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) .reboot_notify = snd_hda_gen_reboot_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) .check_power_status = snd_hda_gen_check_power_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) * snd_hda_parse_generic_codec - Generic codec parser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) * @codec: the HDA codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) static int snd_hda_parse_generic_codec(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) struct hda_gen_spec *spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) spec = kzalloc(sizeof(*spec), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) if (!spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) snd_hda_gen_spec_init(spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) codec->spec = spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) codec->patch_ops = generic_patch_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) snd_hda_gen_free(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) static const struct hda_device_id snd_hda_id_generic[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC, "Generic", snd_hda_parse_generic_codec),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) {} /* terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_generic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) static struct hda_codec_driver generic_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) .id = snd_hda_id_generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) module_hda_codec_driver(generic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) MODULE_DESCRIPTION("Generic HD-audio codec parser");