Skip to content

Commit 5b1913a

Browse files
committed
ALSA: hda: Use own quirk lookup helper
For allowing the primary codec SSID matching (that works around the conflicting PCI SSID problems), introduce a new struct hda_quirk, which is compatible with the existing struct snd_pci_quirk along with new helper functions and macros. The existing snd_pci_quirk tables are replaced with hda_quirk tables accordingly, while keeping SND_PCI_QUIRK() entry definitions as is. This patch shouldn't bring any behavior change, just some renaming and shifting the code. The actual change for the codec SSID matching will follow after this. Signed-off-by: Takashi Iwai <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 1ceb43e commit 5b1913a

File tree

10 files changed

+106
-47
lines changed

10 files changed

+106
-47
lines changed

sound/pci/hda/hda_auto_parser.c

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,28 @@ void snd_hda_pick_pin_fixup(struct hda_codec *codec,
956956
}
957957
EXPORT_SYMBOL_GPL(snd_hda_pick_pin_fixup);
958958

959+
/* check whether the given quirk entry matches with vendor/device pair */
960+
static bool hda_quirk_match(u16 vendor, u16 device, const struct hda_quirk *q)
961+
{
962+
if (q->subvendor != vendor)
963+
return false;
964+
return !q->subdevice ||
965+
(device & q->subdevice_mask) == q->subdevice;
966+
}
967+
968+
/* look through the quirk list and return the matching entry */
969+
static const struct hda_quirk *
970+
hda_quirk_lookup_id(u16 vendor, u16 device, const struct hda_quirk *list)
971+
{
972+
const struct hda_quirk *q;
973+
974+
for (q = list; q->subvendor || q->subdevice; q++) {
975+
if (hda_quirk_match(vendor, device, q))
976+
return q;
977+
}
978+
return NULL;
979+
}
980+
959981
/**
960982
* snd_hda_pick_fixup - Pick up a fixup matching with PCI/codec SSID or model string
961983
* @codec: the HDA codec
@@ -975,14 +997,16 @@ EXPORT_SYMBOL_GPL(snd_hda_pick_pin_fixup);
975997
*/
976998
void snd_hda_pick_fixup(struct hda_codec *codec,
977999
const struct hda_model_fixup *models,
978-
const struct snd_pci_quirk *quirk,
1000+
const struct hda_quirk *quirk,
9791001
const struct hda_fixup *fixlist)
9801002
{
981-
const struct snd_pci_quirk *q;
1003+
const struct hda_quirk *q;
9821004
int id = HDA_FIXUP_ID_NOT_SET;
9831005
const char *name = NULL;
9841006
const char *type = NULL;
9851007
unsigned int vendor, device;
1008+
u16 pci_vendor, pci_device;
1009+
u16 codec_vendor, codec_device;
9861010

9871011
if (codec->fixup_id != HDA_FIXUP_ID_NOT_SET)
9881012
return;
@@ -1013,27 +1037,42 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
10131037
if (!quirk)
10141038
return;
10151039

1040+
if (codec->bus->pci) {
1041+
pci_vendor = codec->bus->pci->subsystem_vendor;
1042+
pci_device = codec->bus->pci->subsystem_device;
1043+
}
1044+
1045+
codec_vendor = codec->core.subsystem_id >> 16;
1046+
codec_device = codec->core.subsystem_id & 0xffff;
1047+
10161048
/* match with the SSID alias given by the model string "XXXX:YYYY" */
10171049
if (codec->modelname &&
10181050
sscanf(codec->modelname, "%04x:%04x", &vendor, &device) == 2) {
1019-
q = snd_pci_quirk_lookup_id(vendor, device, quirk);
1051+
q = hda_quirk_lookup_id(vendor, device, quirk);
10201052
if (q) {
10211053
type = "alias SSID";
10221054
goto found_device;
10231055
}
10241056
}
10251057

1026-
/* match with the PCI SSID */
1027-
q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1028-
if (q) {
1029-
type = "PCI SSID";
1030-
goto found_device;
1058+
/* match primarily with the PCI SSID */
1059+
for (q = quirk; q->subvendor || q->subdevice; q++) {
1060+
/* if the entry is specific to codec SSID, check with it */
1061+
if (!codec->bus->pci || q->match_codec_ssid) {
1062+
if (hda_quirk_match(codec_vendor, codec_device, q)) {
1063+
type = "codec SSID";
1064+
goto found_device;
1065+
}
1066+
} else {
1067+
if (hda_quirk_match(pci_vendor, pci_device, q)) {
1068+
type = "PCI SSID";
1069+
goto found_device;
1070+
}
1071+
}
10311072
}
10321073

10331074
/* match with the codec SSID */
1034-
q = snd_pci_quirk_lookup_id(codec->core.subsystem_id >> 16,
1035-
codec->core.subsystem_id & 0xffff,
1036-
quirk);
1075+
q = hda_quirk_lookup_id(codec_vendor, codec_device, quirk);
10371076
if (q) {
10381077
type = "codec SSID";
10391078
goto found_device;

sound/pci/hda/hda_local.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,26 @@ struct hda_fixup {
292292
} v;
293293
};
294294

295+
/*
296+
* extended form of snd_pci_quirk:
297+
* for PCI SSID matching, use SND_PCI_QUIRK() like before;
298+
* for codec SSID matching, use the new HDA_CODEC_QUIRK() instead
299+
*/
300+
struct hda_quirk {
301+
unsigned short subvendor; /* PCI subvendor ID */
302+
unsigned short subdevice; /* PCI subdevice ID */
303+
unsigned short subdevice_mask; /* bitmask to match */
304+
bool match_codec_ssid; /* match only with codec SSID */
305+
int value; /* value */
306+
#ifdef CONFIG_SND_DEBUG_VERBOSE
307+
const char *name; /* name of the device (optional) */
308+
#endif
309+
};
310+
311+
#define HDA_CODEC_QUIRK(vend, dev, xname, val) \
312+
{ _SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname),\
313+
.match_codec_ssid = true }
314+
295315
struct snd_hda_pin_quirk {
296316
unsigned int codec; /* Codec vendor/device ID */
297317
unsigned short subvendor; /* PCI subvendor ID */
@@ -351,7 +371,7 @@ void snd_hda_apply_fixup(struct hda_codec *codec, int action);
351371
void __snd_hda_apply_fixup(struct hda_codec *codec, int id, int action, int depth);
352372
void snd_hda_pick_fixup(struct hda_codec *codec,
353373
const struct hda_model_fixup *models,
354-
const struct snd_pci_quirk *quirk,
374+
const struct hda_quirk *quirk,
355375
const struct hda_fixup *fixlist);
356376
void snd_hda_pick_pin_fixup(struct hda_codec *codec,
357377
const struct snd_hda_pin_quirk *pin_quirk,

sound/pci/hda/patch_analog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static const struct hda_fixup ad1986a_fixups[] = {
345345
},
346346
};
347347

348-
static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
348+
static const struct hda_quirk ad1986a_fixup_tbl[] = {
349349
SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
350350
SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9V", AD1986A_FIXUP_LAPTOP_IMIC),
351351
SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD),
@@ -588,7 +588,7 @@ static const struct hda_fixup ad1981_fixups[] = {
588588
},
589589
};
590590

591-
static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
591+
static const struct hda_quirk ad1981_fixup_tbl[] = {
592592
SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
593593
SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
594594
SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
@@ -1061,7 +1061,7 @@ static const struct hda_fixup ad1884_fixups[] = {
10611061
},
10621062
};
10631063

1064-
static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1064+
static const struct hda_quirk ad1884_fixup_tbl[] = {
10651065
SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
10661066
SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
10671067
SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),

sound/pci/hda/patch_cirrus.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static const struct hda_model_fixup cs420x_models[] = {
385385
{}
386386
};
387387

388-
static const struct snd_pci_quirk cs420x_fixup_tbl[] = {
388+
static const struct hda_quirk cs420x_fixup_tbl[] = {
389389
SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53),
390390
SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55),
391391
SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
@@ -634,13 +634,13 @@ static const struct hda_model_fixup cs4208_models[] = {
634634
{}
635635
};
636636

637-
static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
637+
static const struct hda_quirk cs4208_fixup_tbl[] = {
638638
SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS4208_MAC_AUTO),
639639
{} /* terminator */
640640
};
641641

642642
/* codec SSID matching */
643-
static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
643+
static const struct hda_quirk cs4208_mac_fixup_tbl[] = {
644644
SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
645645
SND_PCI_QUIRK(0x106b, 0x6c00, "MacMini 7,1", CS4208_MACMINI),
646646
SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
@@ -818,7 +818,7 @@ static const struct hda_model_fixup cs421x_models[] = {
818818
{}
819819
};
820820

821-
static const struct snd_pci_quirk cs421x_fixup_tbl[] = {
821+
static const struct hda_quirk cs421x_fixup_tbl[] = {
822822
/* Test Intel board + CDB2410 */
823823
SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210),
824824
{} /* terminator */

sound/pci/hda/patch_conexant.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ static const struct hda_fixup cxt_fixups[] = {
998998
},
999999
};
10001000

1001-
static const struct snd_pci_quirk cxt5045_fixups[] = {
1001+
static const struct hda_quirk cxt5045_fixups[] = {
10021002
SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
10031003
SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
10041004
/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
@@ -1018,7 +1018,7 @@ static const struct hda_model_fixup cxt5045_fixup_models[] = {
10181018
{}
10191019
};
10201020

1021-
static const struct snd_pci_quirk cxt5047_fixups[] = {
1021+
static const struct hda_quirk cxt5047_fixups[] = {
10221022
/* HP laptops have really bad sound over 0 dB on NID 0x10.
10231023
*/
10241024
SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
@@ -1030,7 +1030,7 @@ static const struct hda_model_fixup cxt5047_fixup_models[] = {
10301030
{}
10311031
};
10321032

1033-
static const struct snd_pci_quirk cxt5051_fixups[] = {
1033+
static const struct hda_quirk cxt5051_fixups[] = {
10341034
SND_PCI_QUIRK(0x103c, 0x360b, "Compaq CQ60", CXT_PINCFG_COMPAQ_CQ60),
10351035
SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
10361036
{}
@@ -1041,7 +1041,7 @@ static const struct hda_model_fixup cxt5051_fixup_models[] = {
10411041
{}
10421042
};
10431043

1044-
static const struct snd_pci_quirk cxt5066_fixups[] = {
1044+
static const struct hda_quirk cxt5066_fixups[] = {
10451045
SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
10461046
SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC),
10471047
SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC),

sound/pci/hda/patch_cs8409-tables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ struct sub_codec dolphin_cs42l42_1 = {
473473
* Arrays Used for all projects using CS8409
474474
******************************************************************************/
475475

476-
const struct snd_pci_quirk cs8409_fixup_tbl[] = {
476+
const struct hda_quirk cs8409_fixup_tbl[] = {
477477
SND_PCI_QUIRK(0x1028, 0x0A11, "Bullseye", CS8409_BULLSEYE),
478478
SND_PCI_QUIRK(0x1028, 0x0A12, "Bullseye", CS8409_BULLSEYE),
479479
SND_PCI_QUIRK(0x1028, 0x0A23, "Bullseye", CS8409_BULLSEYE),

sound/pci/hda/patch_cs8409.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ int cs42l42_volume_put(struct snd_kcontrol *kctrl, struct snd_ctl_elem_value *uc
355355

356356
extern const struct hda_pcm_stream cs42l42_48k_pcm_analog_playback;
357357
extern const struct hda_pcm_stream cs42l42_48k_pcm_analog_capture;
358-
extern const struct snd_pci_quirk cs8409_fixup_tbl[];
358+
extern const struct hda_quirk cs8409_fixup_tbl[];
359359
extern const struct hda_model_fixup cs8409_models[];
360360
extern const struct hda_fixup cs8409_fixups[];
361361
extern const struct hda_verb cs8409_cs42l42_init_verbs[];

sound/pci/hda/patch_realtek.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ static const struct hda_fixup alc880_fixups[] = {
15651565
},
15661566
};
15671567

1568-
static const struct snd_pci_quirk alc880_fixup_tbl[] = {
1568+
static const struct hda_quirk alc880_fixup_tbl[] = {
15691569
SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
15701570
SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS W5A", ALC880_FIXUP_ASUS_W5A),
15711571
SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
@@ -1874,7 +1874,7 @@ static const struct hda_fixup alc260_fixups[] = {
18741874
},
18751875
};
18761876

1877-
static const struct snd_pci_quirk alc260_fixup_tbl[] = {
1877+
static const struct hda_quirk alc260_fixup_tbl[] = {
18781878
SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
18791879
SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
18801880
SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
@@ -2566,7 +2566,7 @@ static const struct hda_fixup alc882_fixups[] = {
25662566
},
25672567
};
25682568

2569-
static const struct snd_pci_quirk alc882_fixup_tbl[] = {
2569+
static const struct hda_quirk alc882_fixup_tbl[] = {
25702570
SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
25712571
SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
25722572
SND_PCI_QUIRK(0x1025, 0x0107, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
@@ -2910,7 +2910,7 @@ static const struct hda_fixup alc262_fixups[] = {
29102910
},
29112911
};
29122912

2913-
static const struct snd_pci_quirk alc262_fixup_tbl[] = {
2913+
static const struct hda_quirk alc262_fixup_tbl[] = {
29142914
SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
29152915
SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu Lifebook S7110", ALC262_FIXUP_FSC_S7110),
29162916
SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
@@ -3071,7 +3071,7 @@ static const struct hda_model_fixup alc268_fixup_models[] = {
30713071
{}
30723072
};
30733073

3074-
static const struct snd_pci_quirk alc268_fixup_tbl[] = {
3074+
static const struct hda_quirk alc268_fixup_tbl[] = {
30753075
SND_PCI_QUIRK(0x1025, 0x0139, "Acer TravelMate 6293", ALC268_FIXUP_SPDIF),
30763076
SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC),
30773077
/* below is codec SSID since multiple Toshiba laptops have the
@@ -10079,7 +10079,7 @@ static const struct hda_fixup alc269_fixups[] = {
1007910079
},
1008010080
};
1008110081

10082-
static const struct snd_pci_quirk alc269_fixup_tbl[] = {
10082+
static const struct hda_quirk alc269_fixup_tbl[] = {
1008310083
SND_PCI_QUIRK(0x1025, 0x0283, "Acer TravelMate 8371", ALC269_FIXUP_INV_DMIC),
1008410084
SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
1008510085
SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
@@ -10967,7 +10967,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
1096710967
{}
1096810968
};
1096910969

10970-
static const struct snd_pci_quirk alc269_fixup_vendor_tbl[] = {
10970+
static const struct hda_quirk alc269_fixup_vendor_tbl[] = {
1097110971
SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
1097210972
SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
1097310973
SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
@@ -11900,7 +11900,7 @@ static const struct hda_fixup alc861_fixups[] = {
1190011900
}
1190111901
};
1190211902

11903-
static const struct snd_pci_quirk alc861_fixup_tbl[] = {
11903+
static const struct hda_quirk alc861_fixup_tbl[] = {
1190411904
SND_PCI_QUIRK(0x1043, 0x1253, "ASUS W7J", ALC660_FIXUP_ASUS_W7J),
1190511905
SND_PCI_QUIRK(0x1043, 0x1263, "ASUS Z35HL", ALC660_FIXUP_ASUS_W7J),
1190611906
SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
@@ -12004,7 +12004,7 @@ static const struct hda_fixup alc861vd_fixups[] = {
1200412004
},
1200512005
};
1200612006

12007-
static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
12007+
static const struct hda_quirk alc861vd_fixup_tbl[] = {
1200812008
SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
1200912009
SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
1201012010
SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
@@ -12805,7 +12805,7 @@ static const struct hda_fixup alc662_fixups[] = {
1280512805
},
1280612806
};
1280712807

12808-
static const struct snd_pci_quirk alc662_fixup_tbl[] = {
12808+
static const struct hda_quirk alc662_fixup_tbl[] = {
1280912809
SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
1281012810
SND_PCI_QUIRK(0x1019, 0x9859, "JP-IK LEAP W502", ALC897_FIXUP_HEADSET_MIC_PIN3),
1281112811
SND_PCI_QUIRK(0x1025, 0x022f, "Acer Aspire One", ALC662_FIXUP_INV_DMIC),

0 commit comments

Comments
 (0)