12 #include <linux/slab.h>
13 #include <linux/export.h>
19 #define SFX "hda_codec: "
37 static void sort_pins_by_sequence(
hda_nid_t *
pins,
short *sequences,
44 for (i = 0; i < num_pins; i++) {
45 for (j = i + 1; j < num_pins; j++) {
46 if (sequences[i] > sequences[j]) {
48 sequences[
i] = sequences[
j];
71 static void sort_autocfg_input_pins(
struct auto_pin_cfg *cfg)
94 static void reorder_outputs(
unsigned int nums,
hda_nid_t *pins)
128 unsigned int cond_flags)
131 short seq, assoc_line_out;
137 memset(cfg, 0,
sizeof(*cfg));
139 memset(sequences_line_out, 0,
sizeof(sequences_line_out));
140 memset(sequences_speaker, 0,
sizeof(sequences_speaker));
141 memset(sequences_hp, 0,
sizeof(sequences_hp));
145 for (nid = codec->
start_nid; nid < end_nid; nid++) {
146 unsigned int wid_caps = get_wcaps(codec, nid);
147 unsigned int wid_type = get_wcaps_type(wid_caps);
148 unsigned int def_conf;
149 short assoc,
loc, conn,
dev;
155 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
182 assoc_line_out = assoc;
183 else if (assoc_line_out != assoc)
188 sequences_line_out[cfg->
line_outs] = seq;
197 sequences_speaker[cfg->
speaker_outs] = (assoc << 4) | seq;
206 sequences_hp[cfg->
hp_outs] = (assoc << 4) | seq;
249 while (i < cfg->hp_outs) {
251 if ((sequences_hp[i] & 0x0f) == 0x0f) {
257 sequences_line_out[cfg->
line_outs] = sequences_hp[
i];
262 memmove(sequences_hp + i, sequences_hp + i + 1,
263 sizeof(sequences_hp[0]) * (cfg->
hp_outs - i));
273 sort_pins_by_sequence(cfg->
line_out_pins, sequences_line_out,
275 sort_pins_by_sequence(cfg->
speaker_pins, sequences_speaker,
277 sort_pins_by_sequence(cfg->
hp_pins, sequences_hp,
307 sort_autocfg_input_pins(cfg);
312 snd_printd(
"autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n",
318 "speaker" :
"line"));
319 snd_printd(
" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
323 snd_printd(
" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
373 static const char *hda_get_input_pin_label(
struct hda_codec *
codec,
376 unsigned int def_conf;
377 static const char *
const mic_names[] = {
378 "Internal Mic",
"Dock Mic",
"Mic",
"Front Mic",
"Rear Mic",
391 return mic_names[attr - 1];
418 static int check_mic_location_need(
struct hda_codec *codec,
436 if (attr && attr != attr2)
457 int has_multiple_pins = 0;
459 if ((input > 0 && cfg->
inputs[input - 1].type == type) ||
460 (input < cfg->num_inputs - 1 && cfg->
inputs[input + 1].type == type))
461 has_multiple_pins = 1;
463 has_multiple_pins &= check_mic_location_need(codec, cfg, input);
464 return hda_get_input_pin_label(codec, cfg->
inputs[input].pin,
473 for (i = 0; i < nums; i++)
481 int num_pins,
int *indexp)
483 static const char *
const channel_sfx[] = {
484 " Front",
" Surround",
" CLFE",
" Side"
488 i = find_idx_in_nid_list(nid, pins, num_pins);
498 return channel_sfx[
i];
521 const char *pfx = check_output_pfx(codec, nid);
523 i = find_idx_in_nid_list(nid, pins, num_pins);
526 for (j = 0; j <
i; j++)
527 if (pfx == check_output_pfx(codec, pins[j]))
535 const char *
name,
char *
label,
int maxlen,
540 const char *pfx, *sfx =
"";
545 pfx = check_output_pfx(codec, nid);
556 int idx = get_hp_label_index(codec, nid, cfg->
hp_pins,
563 snprintf(label, maxlen,
"%s%s%s", pfx, name, sfx);
582 char *label,
int maxlen,
int *indexp)
585 const char *name =
NULL;
595 return fill_audio_out_name(codec, nid, cfg,
"Line Out",
596 label, maxlen, indexp);
598 return fill_audio_out_name(codec, nid, cfg,
"Speaker",
599 label, maxlen, indexp);
601 return fill_audio_out_name(codec, nid, cfg,
"Headphone",
602 label, maxlen, indexp);
619 if (cfg->
inputs[i].pin != nid)
627 name = hda_get_input_pin_label(codec, nid,
true);
653 for (i = 0; i < spec->
verbs.used; i++) {
663 for (; cfg->
nid; cfg++)
672 #ifdef CONFIG_SND_DEBUG_VERBOSE
688 "%s: Apply pincfg for %s\n",
696 "%s: Apply fix-verbs for %s\n",
704 "%s: Apply fix-func for %s\n",
706 fix->
v.
func(codec, fix, action);
710 "%s: Invalid fixup type %d\n",
725 const struct snd_pci_quirk *quirk,
729 const struct snd_pci_quirk *
q;
731 const char *name =
NULL;
741 while (models->
name) {
750 if (
id < 0 && quirk) {
751 q = snd_pci_quirk_lookup(codec->
bus->pci, quirk);
754 #ifdef CONFIG_SND_DEBUG_VERBOSE
759 if (
id < 0 && quirk) {
760 for (q = quirk; q->subvendor; q++) {
761 unsigned int vendorid =
762 q->subdevice | (q->subvendor << 16);
763 unsigned int mask = 0xffff0000 | q->subdevice_mask;
766 #ifdef CONFIG_SND_DEBUG_VERBOSE