Skip to content

Commit d8695bc

Browse files
committed
ALSA: usb-audio: Rewrite registration quirk handling
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/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent c208a53 commit d8695bc

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

sound/usb/card.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ static int usb_audio_probe(struct usb_interface *intf,
665665
/* we are allowed to call snd_card_register() many times, but first
666666
* check to see if a device needs to skip it or do anything special
667667
*/
668-
if (snd_usb_registration_quirk(chip, ifnum) == 0) {
668+
if (!snd_usb_registration_quirk(chip, ifnum)) {
669669
err = snd_card_register(chip->card);
670670
if (err < 0)
671671
goto __error;

sound/usb/quirks.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,16 +1809,36 @@ void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
18091809
}
18101810
}
18111811

1812-
int snd_usb_registration_quirk(struct snd_usb_audio *chip,
1813-
int iface)
1812+
/*
1813+
* registration quirk:
1814+
* the registration is skipped if a device matches with the given ID,
1815+
* unless the interface reaches to the defined one. This is for delaying
1816+
* the registration until the last known interface, so that the card and
1817+
* devices appear at the same time.
1818+
*/
1819+
1820+
struct registration_quirk {
1821+
unsigned int usb_id; /* composed via USB_ID() */
1822+
unsigned int interface; /* the interface to trigger register */
1823+
};
1824+
1825+
#define REG_QUIRK_ENTRY(vendor, product, iface) \
1826+
{ .usb_id = USB_ID(vendor, product), .interface = (iface) }
1827+
1828+
static const struct registration_quirk registration_quirks[] = {
1829+
REG_QUIRK_ENTRY(0x0951, 0x16d8, 2), /* Kingston HyperX AMP */
1830+
{ 0 } /* terminator */
1831+
};
1832+
1833+
/* return true if skipping registration */
1834+
bool snd_usb_registration_quirk(struct snd_usb_audio *chip, int iface)
18141835
{
1815-
switch (chip->usb_id) {
1816-
case USB_ID(0x0951, 0x16d8): /* Kingston HyperX AMP */
1817-
/* Register only when we reach interface 2 so that streams can
1818-
* merge correctly into PCMs from interface 0
1819-
*/
1820-
return (iface != 2);
1821-
}
1836+
const struct registration_quirk *q;
1837+
1838+
for (q = registration_quirks; q->usb_id; q++)
1839+
if (chip->usb_id == q->usb_id)
1840+
return iface != q->interface;
1841+
18221842
/* Register as normal */
1823-
return 0;
1843+
return false;
18241844
}

sound/usb/quirks.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
5151
struct audioformat *fp,
5252
int stream);
5353

54-
int snd_usb_registration_quirk(struct snd_usb_audio *chip,
55-
int iface);
54+
bool snd_usb_registration_quirk(struct snd_usb_audio *chip, int iface);
5655

5756
#endif /* __USBAUDIO_QUIRKS_H */

0 commit comments

Comments
 (0)