Lines Matching +full:all +full:- +full:inputs +full:- +full:2

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * BIOS auto-parser helper functions for HD-audio
38 return (int)(a->seq - b->seq); in compare_seq()
55 /* add the found input-pin to the cfg->inputs[] table */
59 if (cfg->num_inputs < AUTO_CFG_MAX_INS) { in add_auto_cfg_input_pin()
60 cfg->inputs[cfg->num_inputs].pin = nid; in add_auto_cfg_input_pin()
61 cfg->inputs[cfg->num_inputs].type = type; in add_auto_cfg_input_pin()
62 cfg->inputs[cfg->num_inputs].has_boost_on_pin = in add_auto_cfg_input_pin()
64 cfg->num_inputs++; in add_auto_cfg_input_pin()
72 if (a->type != b->type) in compare_input_type()
73 return (int)(a->type - b->type); in compare_input_type()
76 if (a->is_headset_mic && b->is_headphone_mic) in compare_input_type()
77 return -1; /* don't swap */ in compare_input_type()
78 else if (a->is_headphone_mic && b->is_headset_mic) in compare_input_type()
83 if (a->has_boost_on_pin != b->has_boost_on_pin) in compare_input_type()
84 return (int)(b->has_boost_on_pin - a->has_boost_on_pin); in compare_input_type()
87 return a->order - b->order; in compare_input_type()
93 * 4-ch: front/surr => OK as it is
94 * 6-ch: front/clfe/surr
95 * 8-ch: front/clfe/rear/side|fc
102 swap(pins[1], pins[2]); in reorder_outputs()
135 if (item->type != AUTO_PIN_MIC) in can_be_headset_mic()
138 if (item->is_headset_mic || item->is_headphone_mic) in can_be_headset_mic()
141 def_conf = snd_hda_codec_get_pincfg(codec, item->pin); in can_be_headset_mic()
156 * Parse all pin widgets and store the useful pin nids to cfg
158 * The number of line-outs or any primary output is stored in line_outs,
163 * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack
168 * The analog input pins are assigned to inputs array.
179 struct auto_out_pin line_out[ARRAY_SIZE(cfg->line_out_pins)]; in snd_hda_parse_pin_defcfg()
180 struct auto_out_pin speaker_out[ARRAY_SIZE(cfg->speaker_pins)]; in snd_hda_parse_pin_defcfg()
181 struct auto_out_pin hp_out[ARRAY_SIZE(cfg->hp_pins)]; in snd_hda_parse_pin_defcfg()
200 /* read all default configuration for pin complex */ in snd_hda_parse_pin_defcfg()
203 /* ignore the given nids (e.g. pc-beep returns error) */ in snd_hda_parse_pin_defcfg()
230 if (!cfg->mono_out_pin) in snd_hda_parse_pin_defcfg()
231 cfg->mono_out_pin = nid; in snd_hda_parse_pin_defcfg()
242 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) { in snd_hda_parse_pin_defcfg()
248 line_out[cfg->line_outs].pin = nid; in snd_hda_parse_pin_defcfg()
249 line_out[cfg->line_outs].seq = seq; in snd_hda_parse_pin_defcfg()
250 cfg->line_outs++; in snd_hda_parse_pin_defcfg()
255 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) { in snd_hda_parse_pin_defcfg()
261 speaker_out[cfg->speaker_outs].pin = nid; in snd_hda_parse_pin_defcfg()
262 speaker_out[cfg->speaker_outs].seq = (assoc << 4) | seq; in snd_hda_parse_pin_defcfg()
263 cfg->speaker_outs++; in snd_hda_parse_pin_defcfg()
268 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) { in snd_hda_parse_pin_defcfg()
274 hp_out[cfg->hp_outs].pin = nid; in snd_hda_parse_pin_defcfg()
275 hp_out[cfg->hp_outs].seq = (assoc << 4) | seq; in snd_hda_parse_pin_defcfg()
276 cfg->hp_outs++; in snd_hda_parse_pin_defcfg()
292 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) { in snd_hda_parse_pin_defcfg()
298 cfg->dig_out_pins[cfg->dig_outs] = nid; in snd_hda_parse_pin_defcfg()
299 cfg->dig_out_type[cfg->dig_outs] = in snd_hda_parse_pin_defcfg()
302 cfg->dig_outs++; in snd_hda_parse_pin_defcfg()
306 cfg->dig_in_pin = nid; in snd_hda_parse_pin_defcfg()
308 cfg->dig_in_type = HDA_PCM_TYPE_HDMI; in snd_hda_parse_pin_defcfg()
310 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; in snd_hda_parse_pin_defcfg()
319 for (i = 0; (hsmic || hpmic) && (i < cfg->num_inputs); i++) in snd_hda_parse_pin_defcfg()
320 if (hsmic && can_be_headset_mic(codec, &cfg->inputs[i], 0xc)) { in snd_hda_parse_pin_defcfg()
321 cfg->inputs[i].is_headset_mic = 1; in snd_hda_parse_pin_defcfg()
323 } else if (hpmic && can_be_headset_mic(codec, &cfg->inputs[i], 0xd)) { in snd_hda_parse_pin_defcfg()
324 cfg->inputs[i].is_headphone_mic = 1; in snd_hda_parse_pin_defcfg()
329 for (i = 0; (hsmic || hpmic) && (i < cfg->num_inputs); i++) { in snd_hda_parse_pin_defcfg()
330 if (!can_be_headset_mic(codec, &cfg->inputs[i], -1)) in snd_hda_parse_pin_defcfg()
333 cfg->inputs[i].is_headset_mic = 1; in snd_hda_parse_pin_defcfg()
336 cfg->inputs[i].is_headphone_mic = 1; in snd_hda_parse_pin_defcfg()
347 /* FIX-UP: in snd_hda_parse_pin_defcfg()
348 * If no line-out is defined but multiple HPs are found, in snd_hda_parse_pin_defcfg()
349 * some of them might be the real line-outs. in snd_hda_parse_pin_defcfg()
351 if (!cfg->line_outs && cfg->hp_outs > 1 && in snd_hda_parse_pin_defcfg()
354 while (i < cfg->hp_outs) { in snd_hda_parse_pin_defcfg()
360 /* Move it to the line-out table */ in snd_hda_parse_pin_defcfg()
361 line_out[cfg->line_outs++] = hp_out[i]; in snd_hda_parse_pin_defcfg()
362 cfg->hp_outs--; in snd_hda_parse_pin_defcfg()
364 sizeof(hp_out[0]) * (cfg->hp_outs - i)); in snd_hda_parse_pin_defcfg()
366 memset(hp_out + cfg->hp_outs, 0, in snd_hda_parse_pin_defcfg()
367 sizeof(hp_out[0]) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs)); in snd_hda_parse_pin_defcfg()
368 if (!cfg->hp_outs) in snd_hda_parse_pin_defcfg()
369 cfg->line_out_type = AUTO_PIN_HP_OUT; in snd_hda_parse_pin_defcfg()
374 sort_pins_by_sequence(cfg->line_out_pins, line_out, cfg->line_outs); in snd_hda_parse_pin_defcfg()
375 sort_pins_by_sequence(cfg->speaker_pins, speaker_out, in snd_hda_parse_pin_defcfg()
376 cfg->speaker_outs); in snd_hda_parse_pin_defcfg()
377 sort_pins_by_sequence(cfg->hp_pins, hp_out, cfg->hp_outs); in snd_hda_parse_pin_defcfg()
380 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin in snd_hda_parse_pin_defcfg()
383 if (!cfg->line_outs && in snd_hda_parse_pin_defcfg()
385 if (cfg->speaker_outs) { in snd_hda_parse_pin_defcfg()
386 cfg->line_outs = cfg->speaker_outs; in snd_hda_parse_pin_defcfg()
387 memcpy(cfg->line_out_pins, cfg->speaker_pins, in snd_hda_parse_pin_defcfg()
388 sizeof(cfg->speaker_pins)); in snd_hda_parse_pin_defcfg()
389 cfg->speaker_outs = 0; in snd_hda_parse_pin_defcfg()
390 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); in snd_hda_parse_pin_defcfg()
391 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; in snd_hda_parse_pin_defcfg()
392 } else if (cfg->hp_outs) { in snd_hda_parse_pin_defcfg()
393 cfg->line_outs = cfg->hp_outs; in snd_hda_parse_pin_defcfg()
394 memcpy(cfg->line_out_pins, cfg->hp_pins, in snd_hda_parse_pin_defcfg()
395 sizeof(cfg->hp_pins)); in snd_hda_parse_pin_defcfg()
396 cfg->hp_outs = 0; in snd_hda_parse_pin_defcfg()
397 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); in snd_hda_parse_pin_defcfg()
398 cfg->line_out_type = AUTO_PIN_HP_OUT; in snd_hda_parse_pin_defcfg()
402 reorder_outputs(cfg->line_outs, cfg->line_out_pins); in snd_hda_parse_pin_defcfg()
403 reorder_outputs(cfg->hp_outs, cfg->hp_pins); in snd_hda_parse_pin_defcfg()
404 reorder_outputs(cfg->speaker_outs, cfg->speaker_pins); in snd_hda_parse_pin_defcfg()
406 /* sort inputs in the order of AUTO_PIN_* type */ in snd_hda_parse_pin_defcfg()
407 for (i = 0; i < cfg->num_inputs; i++) in snd_hda_parse_pin_defcfg()
408 cfg->inputs[i].order = i; in snd_hda_parse_pin_defcfg()
409 sort(cfg->inputs, cfg->num_inputs, sizeof(cfg->inputs[0]), in snd_hda_parse_pin_defcfg()
416 codec->core.chip_name, cfg->line_outs, cfg->line_out_pins[0], in snd_hda_parse_pin_defcfg()
417 cfg->line_out_pins[1], cfg->line_out_pins[2], in snd_hda_parse_pin_defcfg()
418 cfg->line_out_pins[3], cfg->line_out_pins[4], in snd_hda_parse_pin_defcfg()
419 cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : in snd_hda_parse_pin_defcfg()
420 (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ? in snd_hda_parse_pin_defcfg()
423 cfg->speaker_outs, cfg->speaker_pins[0], in snd_hda_parse_pin_defcfg()
424 cfg->speaker_pins[1], cfg->speaker_pins[2], in snd_hda_parse_pin_defcfg()
425 cfg->speaker_pins[3], cfg->speaker_pins[4]); in snd_hda_parse_pin_defcfg()
427 cfg->hp_outs, cfg->hp_pins[0], in snd_hda_parse_pin_defcfg()
428 cfg->hp_pins[1], cfg->hp_pins[2], in snd_hda_parse_pin_defcfg()
429 cfg->hp_pins[3], cfg->hp_pins[4]); in snd_hda_parse_pin_defcfg()
430 codec_info(codec, " mono: mono_out=0x%x\n", cfg->mono_out_pin); in snd_hda_parse_pin_defcfg()
431 if (cfg->dig_outs) in snd_hda_parse_pin_defcfg()
432 codec_info(codec, " dig-out=0x%x/0x%x\n", in snd_hda_parse_pin_defcfg()
433 cfg->dig_out_pins[0], cfg->dig_out_pins[1]); in snd_hda_parse_pin_defcfg()
434 codec_info(codec, " inputs:\n"); in snd_hda_parse_pin_defcfg()
435 for (i = 0; i < cfg->num_inputs; i++) { in snd_hda_parse_pin_defcfg()
438 cfg->inputs[i].pin); in snd_hda_parse_pin_defcfg()
440 if (cfg->dig_in_pin) in snd_hda_parse_pin_defcfg()
441 codec_info(codec, " dig-in=0x%x\n", cfg->dig_in_pin); in snd_hda_parse_pin_defcfg()
448 * snd_hda_get_input_pin_attr - Get the input pin attribute from pin config
476 * hda_get_input_pin_label - Give a label for the given input pin
483 * for mic and line-in pins, and set an appropriate prefix like "Front",
500 if (item && item->is_headset_mic) in hda_get_input_pin_label()
502 if (item && item->is_headphone_mic) in hda_get_input_pin_label()
509 return mic_names[attr - 1]; in hda_get_input_pin_label()
535 * If all mic-jacks are in the same location (e.g. rear panel), we don't
545 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin); in check_mic_location_need()
552 for (i = 0; i < cfg->num_inputs; i++) { in check_mic_location_need()
553 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin); in check_mic_location_need()
565 * hda_get_autocfg_input_label - Get a label for the given input
571 * Unlike hda_get_input_pin_label(), this function checks all inputs
579 int type = cfg->inputs[input].type; in hda_get_autocfg_input_label()
582 if ((input > 0 && cfg->inputs[input - 1].type == type) || in hda_get_autocfg_input_label()
583 (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type)) in hda_get_autocfg_input_label()
587 has_multiple_pins |= codec->force_pin_prefix; in hda_get_autocfg_input_label()
588 return hda_get_input_pin_label(codec, &cfg->inputs[input], in hda_get_autocfg_input_label()
589 cfg->inputs[input].pin, in hda_get_autocfg_input_label()
594 /* return the position of NID in the list, or -1 if not found */
601 return -1; in find_idx_in_nid_list()
650 return -1; in get_hp_label_index()
667 /* handle as a speaker if it's a fixed line-out */ in fill_audio_out_name()
674 sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs, in fill_audio_out_name()
677 sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs, in fill_audio_out_name()
681 int idx = get_hp_label_index(codec, nid, cfg->hp_pins, in fill_audio_out_name()
682 cfg->hp_outs); in fill_audio_out_name()
696 * snd_hda_get_pin_label - Get a label for the given I/O pin
705 * output pins. When @cfg is given as non-NULL, the function tries to get
709 * possible. For example, when the multiple line-outs are present, it adds
711 * If no unique name with a suffix is available and @indexp is non-NULL, the
743 for (i = 0; i < cfg->dig_outs; i++) { in snd_hda_get_pin_label()
744 hda_nid_t pin = cfg->dig_out_pins[i]; in snd_hda_get_pin_label()
755 for (i = 0; i < cfg->num_inputs; i++) { in snd_hda_get_pin_label()
756 if (cfg->inputs[i].pin != nid) in snd_hda_get_pin_label()
775 * snd_hda_add_verbs - Add verbs to the init list
777 * @list: zero-terminated verb list to add
786 v = snd_array_new(&codec->verbs); in snd_hda_add_verbs()
788 return -ENOMEM; in snd_hda_add_verbs()
795 * snd_hda_apply_verbs - Execute the init verb lists
803 snd_array_for_each(&codec->verbs, i, v) in snd_hda_apply_verbs()
809 * snd_hda_apply_pincfgs - Set each pin config in the given list
811 * @cfg: NULL-terminated pin config table
816 for (; cfg->nid; cfg++) in snd_hda_apply_pincfgs()
817 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); in snd_hda_apply_pincfgs()
824 for (; cfg->nid; cfg++) in set_pin_targets()
825 snd_hda_set_pin_ctl_cache(codec, cfg->nid, cfg->val); in set_pin_targets()
830 const char *modelname = codec->fixup_name; in __snd_hda_apply_fixup()
833 const struct hda_fixup *fix = codec->fixup_list + id; in __snd_hda_apply_fixup()
837 if (fix->chained_before) in __snd_hda_apply_fixup()
838 __snd_hda_apply_fixup(codec, fix->chain_id, action, depth + 1); in __snd_hda_apply_fixup()
840 switch (fix->type) { in __snd_hda_apply_fixup()
842 if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) in __snd_hda_apply_fixup()
845 codec->core.chip_name, modelname); in __snd_hda_apply_fixup()
846 snd_hda_apply_pincfgs(codec, fix->v.pins); in __snd_hda_apply_fixup()
849 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) in __snd_hda_apply_fixup()
851 codec_dbg(codec, "%s: Apply fix-verbs for %s\n", in __snd_hda_apply_fixup()
852 codec->core.chip_name, modelname); in __snd_hda_apply_fixup()
853 snd_hda_add_verbs(codec, fix->v.verbs); in __snd_hda_apply_fixup()
856 if (!fix->v.func) in __snd_hda_apply_fixup()
858 codec_dbg(codec, "%s: Apply fix-func for %s\n", in __snd_hda_apply_fixup()
859 codec->core.chip_name, modelname); in __snd_hda_apply_fixup()
860 fix->v.func(codec, fix, action); in __snd_hda_apply_fixup()
863 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins) in __snd_hda_apply_fixup()
866 codec->core.chip_name, modelname); in __snd_hda_apply_fixup()
867 set_pin_targets(codec, fix->v.pins); in __snd_hda_apply_fixup()
871 codec->core.chip_name, fix->type); in __snd_hda_apply_fixup()
874 if (!fix->chained || fix->chained_before) in __snd_hda_apply_fixup()
876 id = fix->chain_id; in __snd_hda_apply_fixup()
882 * snd_hda_apply_fixup - Apply the fixup chain with the given action
888 if (codec->fixup_list) in snd_hda_apply_fixup()
889 __snd_hda_apply_fixup(codec, codec->fixup_id, action, 0); in snd_hda_apply_fixup()
902 snd_array_for_each(&codec->init_pins, i, pin) { in pin_config_match()
903 hda_nid_t nid = pin->nid; in pin_config_match()
904 u32 cfg = pin->cfg; in pin_config_match()
910 for (; t_pins->nid; t_pins++) { in pin_config_match()
911 if (t_pins->nid == nid) { in pin_config_match()
913 if ((t_pins->val & IGNORE_SEQ_ASSOC) == (cfg & IGNORE_SEQ_ASSOC)) in pin_config_match()
915 else if ((cfg & 0xf0000000) == 0x40000000 && (t_pins->val & 0xf0000000) == 0x40000000) in pin_config_match()
930 * snd_hda_pick_pin_fixup - Pick up a fixup matching with the pin quirk list
932 * @pin_quirk: zero-terminated pin quirk list
934 * @match_all_pins: all valid pins must match with the table entries
944 if (codec->fixup_id != HDA_FIXUP_ID_NOT_SET) in snd_hda_pick_pin_fixup()
947 for (pq = pin_quirk; pq->subvendor; pq++) { in snd_hda_pick_pin_fixup()
948 if ((codec->core.subsystem_id & 0xffff0000) != (pq->subvendor << 16)) in snd_hda_pick_pin_fixup()
950 if (codec->core.vendor_id != pq->codec) in snd_hda_pick_pin_fixup()
952 if (pin_config_match(codec, pq->pins, match_all_pins)) { in snd_hda_pick_pin_fixup()
953 codec->fixup_id = pq->value; in snd_hda_pick_pin_fixup()
955 codec->fixup_name = pq->name; in snd_hda_pick_pin_fixup()
956 name = pq->name; in snd_hda_pick_pin_fixup()
959 codec->core.chip_name, name ? name : ""); in snd_hda_pick_pin_fixup()
960 codec->fixup_list = fixlist; in snd_hda_pick_pin_fixup()
970 if (q->subvendor != vendor) in hda_quirk_match()
972 return !q->subdevice || in hda_quirk_match()
973 (device & q->subdevice_mask) == q->subdevice; in hda_quirk_match()
982 for (q = list; q->subvendor || q->subdevice; q++) { in hda_quirk_lookup_id()
990 * snd_hda_pick_fixup - Pick up a fixup matching with PCI/codec SSID or model string
992 * @models: NULL-terminated model string list
993 * @quirk: zero-terminated PCI/codec SSID quirk list
1019 if (codec->fixup_id != HDA_FIXUP_ID_NOT_SET) in snd_hda_pick_fixup()
1023 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) { in snd_hda_pick_fixup()
1027 codec->core.chip_name); in snd_hda_pick_fixup()
1032 if (codec->modelname && models) { in snd_hda_pick_fixup()
1033 while (models->name) { in snd_hda_pick_fixup()
1034 if (!strcmp(codec->modelname, models->name)) { in snd_hda_pick_fixup()
1035 id = models->id; in snd_hda_pick_fixup()
1036 name = models->name; in snd_hda_pick_fixup()
1038 codec->core.chip_name, name); in snd_hda_pick_fixup()
1048 if (codec->bus->pci) { in snd_hda_pick_fixup()
1049 pci_vendor = codec->bus->pci->subsystem_vendor; in snd_hda_pick_fixup()
1050 pci_device = codec->bus->pci->subsystem_device; in snd_hda_pick_fixup()
1053 codec_vendor = codec->core.subsystem_id >> 16; in snd_hda_pick_fixup()
1054 codec_device = codec->core.subsystem_id & 0xffff; in snd_hda_pick_fixup()
1057 if (codec->modelname && in snd_hda_pick_fixup()
1058 sscanf(codec->modelname, "%04x:%04x", &vendor, &device) == 2) { in snd_hda_pick_fixup()
1067 for (q = quirk; q->subvendor || q->subdevice; q++) { in snd_hda_pick_fixup()
1069 if (!codec->bus->pci || q->match_codec_ssid) { in snd_hda_pick_fixup()
1092 id = q->value; in snd_hda_pick_fixup()
1094 name = q->name; in snd_hda_pick_fixup()
1097 codec->core.chip_name, name ? name : "", in snd_hda_pick_fixup()
1098 type, q->subvendor, q->subdevice); in snd_hda_pick_fixup()
1100 codec->fixup_id = id; in snd_hda_pick_fixup()
1101 codec->fixup_list = fixlist; in snd_hda_pick_fixup()
1102 codec->fixup_name = name; in snd_hda_pick_fixup()