summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2020-03-25 13:33:19 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-07-22 10:32:59 +0300
commitdc1e4db658a6597a377397d4ce6f34cbbaa031b5 (patch)
tree90be517d81bbfea025c00f9fedb3bb97ed3c0f71 /sound
parent592b179fa1492b53554a405924db0669c00548be (diff)
downloadlinux-dc1e4db658a6597a377397d4ce6f34cbbaa031b5.tar.xz
ALSA: usb-audio: Rewrite registration quirk handling
[ Upstream commit d8695bc5b1fe88305396b1f788d3b5f218e28a30 ] A slight refactoring of the registration quirk code. Now it uses the table lookup for easy additions in future. Also the return type was changed to bool, and got a few more comments. Link: https://lore.kernel.org/r/20200325103322.2508-2-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'sound')
-rw-r--r--sound/usb/card.c2
-rw-r--r--sound/usb/quirks.c40
-rw-r--r--sound/usb/quirks.h3
3 files changed, 32 insertions, 13 deletions
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 2284377cbb98..230d862cfa3a 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -662,7 +662,7 @@ static int usb_audio_probe(struct usb_interface *intf,
/* we are allowed to call snd_card_register() many times, but first
* check to see if a device needs to skip it or do anything special
*/
- if (snd_usb_registration_quirk(chip, ifnum) == 0) {
+ if (!snd_usb_registration_quirk(chip, ifnum)) {
err = snd_card_register(chip->card);
if (err < 0)
goto __error;
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index f3e26e65c325..ad557ab65e04 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1783,16 +1783,36 @@ void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
}
}
-int snd_usb_registration_quirk(struct snd_usb_audio *chip,
- int iface)
+/*
+ * registration quirk:
+ * the registration is skipped if a device matches with the given ID,
+ * unless the interface reaches to the defined one. This is for delaying
+ * the registration until the last known interface, so that the card and
+ * devices appear at the same time.
+ */
+
+struct registration_quirk {
+ unsigned int usb_id; /* composed via USB_ID() */
+ unsigned int interface; /* the interface to trigger register */
+};
+
+#define REG_QUIRK_ENTRY(vendor, product, iface) \
+ { .usb_id = USB_ID(vendor, product), .interface = (iface) }
+
+static const struct registration_quirk registration_quirks[] = {
+ REG_QUIRK_ENTRY(0x0951, 0x16d8, 2), /* Kingston HyperX AMP */
+ { 0 } /* terminator */
+};
+
+/* return true if skipping registration */
+bool snd_usb_registration_quirk(struct snd_usb_audio *chip, int iface)
{
- switch (chip->usb_id) {
- case USB_ID(0x0951, 0x16d8): /* Kingston HyperX AMP */
- /* Register only when we reach interface 2 so that streams can
- * merge correctly into PCMs from interface 0
- */
- return (iface != 2);
- }
+ const struct registration_quirk *q;
+
+ for (q = registration_quirks; q->usb_id; q++)
+ if (chip->usb_id == q->usb_id)
+ return iface != q->interface;
+
/* Register as normal */
- return 0;
+ return false;
}
diff --git a/sound/usb/quirks.h b/sound/usb/quirks.h
index 3afc01eabc7e..c76cf24a640a 100644
--- a/sound/usb/quirks.h
+++ b/sound/usb/quirks.h
@@ -51,7 +51,6 @@ void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
struct audioformat *fp,
int stream);
-int snd_usb_registration_quirk(struct snd_usb_audio *chip,
- int iface);
+bool snd_usb_registration_quirk(struct snd_usb_audio *chip, int iface);
#endif /* __USBAUDIO_QUIRKS_H */