Skip to content

Commit 73355dd

Browse files
committed
ALSA: hda: Code refactoring snd_hda_pick_fixup()
This contains a slight code refactoring of snd_hda_pick_fixup(): - Unify the ID setup - Unify the debug print message - Use snd_pci_quirk_lookup_id() for the codec SSID matching Mostly for simplifying the code flow but also it makes easier to add the codec alias handling in the upcoming patch. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 23c671b commit 73355dd

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

sound/pci/hda/hda_auto_parser.c

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -982,65 +982,66 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
982982
const struct snd_pci_quirk *q;
983983
int id = HDA_FIXUP_ID_NOT_SET;
984984
const char *name = NULL;
985+
const char *type = NULL;
985986

986987
if (codec->fixup_id != HDA_FIXUP_ID_NOT_SET)
987988
return;
988989

989990
/* when model=nofixup is given, don't pick up any fixups */
990991
if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
991-
codec->fixup_list = NULL;
992-
codec->fixup_name = NULL;
993-
codec->fixup_id = HDA_FIXUP_ID_NO_FIXUP;
992+
id = HDA_FIXUP_ID_NO_FIXUP;
993+
fixlist = NULL;
994994
codec_dbg(codec, "%s: picked no fixup (nofixup specified)\n",
995995
codec->core.chip_name);
996-
return;
996+
goto found;
997997
}
998998

999+
/* match with the model name string */
9991000
if (codec->modelname && models) {
10001001
while (models->name) {
10011002
if (!strcmp(codec->modelname, models->name)) {
1002-
codec->fixup_id = models->id;
1003-
codec->fixup_name = models->name;
1004-
codec->fixup_list = fixlist;
1003+
id = models->id;
1004+
name = models->name;
10051005
codec_dbg(codec, "%s: picked fixup %s (model specified)\n",
10061006
codec->core.chip_name, codec->fixup_name);
1007-
return;
1007+
goto found;
10081008
}
10091009
models++;
10101010
}
10111011
}
1012-
if (quirk) {
1013-
q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1014-
if (q) {
1015-
id = q->value;
1016-
#ifdef CONFIG_SND_DEBUG_VERBOSE
1017-
name = q->name;
1018-
codec_dbg(codec, "%s: picked fixup %s (PCI SSID%s)\n",
1019-
codec->core.chip_name, name, q->subdevice_mask ? "" : " - vendor generic");
1020-
#endif
1021-
}
1012+
1013+
if (!quirk)
1014+
return;
1015+
1016+
/* match with the PCI SSID */
1017+
q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1018+
if (q) {
1019+
type = "PCI SSID";
1020+
goto found_device;
10221021
}
1023-
if (id < 0 && quirk) {
1024-
for (q = quirk; q->subvendor || q->subdevice; q++) {
1025-
unsigned int vendorid =
1026-
q->subdevice | (q->subvendor << 16);
1027-
unsigned int mask = 0xffff0000 | q->subdevice_mask;
1028-
if ((codec->core.subsystem_id & mask) == (vendorid & mask)) {
1029-
id = q->value;
1030-
#ifdef CONFIG_SND_DEBUG_VERBOSE
1031-
name = q->name;
1032-
codec_dbg(codec, "%s: picked fixup %s (codec SSID)\n",
1033-
codec->core.chip_name, name);
1034-
#endif
1035-
break;
1036-
}
1037-
}
1022+
1023+
/* match with the codec SSID */
1024+
q = snd_pci_quirk_lookup_id(codec->core.subsystem_id >> 16,
1025+
codec->core.subsystem_id & 0xffff,
1026+
quirk);
1027+
if (q) {
1028+
type = "codec SSID";
1029+
goto found_device;
10381030
}
10391031

1032+
return; /* no matching */
1033+
1034+
found_device:
1035+
id = q->value;
1036+
#ifdef CONFIG_SND_DEBUG_VERBOSE
1037+
name = q->name;
1038+
#endif
1039+
codec_dbg(codec, "%s: picked fixup %s for %s %04x:%04x\n",
1040+
codec->core.chip_name, name ? name : "",
1041+
type, q->subvendor, q->subdevice);
1042+
found:
10401043
codec->fixup_id = id;
1041-
if (id >= 0) {
1042-
codec->fixup_list = fixlist;
1043-
codec->fixup_name = name;
1044-
}
1044+
codec->fixup_list = fixlist;
1045+
codec->fixup_name = name;
10451046
}
10461047
EXPORT_SYMBOL_GPL(snd_hda_pick_fixup);

0 commit comments

Comments
 (0)