Commit 854af957 authored by Clemens Ladisch's avatar Clemens Ladisch Committed by Jaroslav Kysela

[ALSA] usb-audio - change quirk type handling

USB generic driver
Make the quirk type an enum instead of a #defined integer, and use a
table for the quirk constructor functions instead of a big switch
statement.
Signed-off-by: default avatarClemens Ladisch <clemens@ladisch.de>
parent f38275fe
...@@ -2735,7 +2735,8 @@ static int create_standard_interface_quirk(snd_usb_audio_t *chip, ...@@ -2735,7 +2735,8 @@ static int create_standard_interface_quirk(snd_usb_audio_t *chip,
* to detect the sample rate is by looking at wMaxPacketSize. * to detect the sample rate is by looking at wMaxPacketSize.
*/ */
static int create_ua700_ua25_quirk(snd_usb_audio_t *chip, static int create_ua700_ua25_quirk(snd_usb_audio_t *chip,
struct usb_interface *iface) struct usb_interface *iface,
const snd_usb_audio_quirk_t *quirk)
{ {
static const struct audioformat ua_format = { static const struct audioformat ua_format = {
.format = SNDRV_PCM_FORMAT_S24_3LE, .format = SNDRV_PCM_FORMAT_S24_3LE,
...@@ -2826,7 +2827,9 @@ static int create_ua700_ua25_quirk(snd_usb_audio_t *chip, ...@@ -2826,7 +2827,9 @@ static int create_ua700_ua25_quirk(snd_usb_audio_t *chip,
/* /*
* Create a stream for an Edirol UA-1000 interface. * Create a stream for an Edirol UA-1000 interface.
*/ */
static int create_ua1000_quirk(snd_usb_audio_t *chip, struct usb_interface *iface) static int create_ua1000_quirk(snd_usb_audio_t *chip,
struct usb_interface *iface,
const snd_usb_audio_quirk_t *quirk)
{ {
static const struct audioformat ua1000_format = { static const struct audioformat ua1000_format = {
.format = SNDRV_PCM_FORMAT_S32_LE, .format = SNDRV_PCM_FORMAT_S32_LE,
...@@ -2903,6 +2906,13 @@ static int create_composite_quirk(snd_usb_audio_t *chip, ...@@ -2903,6 +2906,13 @@ static int create_composite_quirk(snd_usb_audio_t *chip,
return 0; return 0;
} }
static int ignore_interface_quirk(snd_usb_audio_t *chip,
struct usb_interface *iface,
const snd_usb_audio_quirk_t *quirk)
{
return 0;
}
/* /*
* boot quirks * boot quirks
...@@ -2965,29 +2975,28 @@ static int snd_usb_create_quirk(snd_usb_audio_t *chip, ...@@ -2965,29 +2975,28 @@ static int snd_usb_create_quirk(snd_usb_audio_t *chip,
struct usb_interface *iface, struct usb_interface *iface,
const snd_usb_audio_quirk_t *quirk) const snd_usb_audio_quirk_t *quirk)
{ {
switch (quirk->type) { typedef int (*quirk_func_t)(snd_usb_audio_t *, struct usb_interface *,
case QUIRK_MIDI_FIXED_ENDPOINT: const snd_usb_audio_quirk_t *);
case QUIRK_MIDI_YAMAHA: static const quirk_func_t quirk_funcs[] = {
case QUIRK_MIDI_MIDIMAN: [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
case QUIRK_MIDI_NOVATION: [QUIRK_COMPOSITE] = create_composite_quirk,
case QUIRK_MIDI_RAW: [QUIRK_MIDI_STANDARD_INTERFACE] = snd_usb_create_midi_interface,
case QUIRK_MIDI_EMAGIC: [QUIRK_MIDI_FIXED_ENDPOINT] = snd_usb_create_midi_interface,
case QUIRK_MIDI_MIDITECH: [QUIRK_MIDI_YAMAHA] = snd_usb_create_midi_interface,
return snd_usb_create_midi_interface(chip, iface, quirk); [QUIRK_MIDI_MIDIMAN] = snd_usb_create_midi_interface,
case QUIRK_COMPOSITE: [QUIRK_MIDI_NOVATION] = snd_usb_create_midi_interface,
return create_composite_quirk(chip, iface, quirk); [QUIRK_MIDI_RAW] = snd_usb_create_midi_interface,
case QUIRK_AUDIO_FIXED_ENDPOINT: [QUIRK_MIDI_EMAGIC] = snd_usb_create_midi_interface,
return create_fixed_stream_quirk(chip, iface, quirk); [QUIRK_MIDI_MIDITECH] = snd_usb_create_midi_interface,
case QUIRK_AUDIO_STANDARD_INTERFACE: [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_interface_quirk,
case QUIRK_MIDI_STANDARD_INTERFACE: [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
return create_standard_interface_quirk(chip, iface, quirk); [QUIRK_AUDIO_EDIROL_UA700_UA25] = create_ua700_ua25_quirk,
case QUIRK_AUDIO_EDIROL_UA700_UA25: [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk,
return create_ua700_ua25_quirk(chip, iface); };
case QUIRK_AUDIO_EDIROL_UA1000:
return create_ua1000_quirk(chip, iface); if (quirk->type < QUIRK_TYPE_COUNT) {
case QUIRK_IGNORE_INTERFACE: return quirk_funcs[quirk->type](chip, iface, quirk);
return 0; } else {
default:
snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
return -ENXIO; return -ENXIO;
} }
......
...@@ -153,21 +153,24 @@ struct snd_usb_audio { ...@@ -153,21 +153,24 @@ struct snd_usb_audio {
#define QUIRK_NO_INTERFACE -2 #define QUIRK_NO_INTERFACE -2
#define QUIRK_ANY_INTERFACE -1 #define QUIRK_ANY_INTERFACE -1
/* quirk type */ enum quirk_type {
#define QUIRK_MIDI_FIXED_ENDPOINT 0 QUIRK_IGNORE_INTERFACE,
#define QUIRK_MIDI_YAMAHA 1 QUIRK_COMPOSITE,
#define QUIRK_MIDI_MIDIMAN 2 QUIRK_MIDI_STANDARD_INTERFACE,
#define QUIRK_COMPOSITE 3 QUIRK_MIDI_FIXED_ENDPOINT,
#define QUIRK_AUDIO_FIXED_ENDPOINT 4 QUIRK_MIDI_YAMAHA,
#define QUIRK_AUDIO_STANDARD_INTERFACE 5 QUIRK_MIDI_MIDIMAN,
#define QUIRK_MIDI_STANDARD_INTERFACE 6 QUIRK_MIDI_NOVATION,
#define QUIRK_AUDIO_EDIROL_UA700_UA25 7 QUIRK_MIDI_RAW,
#define QUIRK_AUDIO_EDIROL_UA1000 8 QUIRK_MIDI_EMAGIC,
#define QUIRK_IGNORE_INTERFACE 9 QUIRK_MIDI_MIDITECH,
#define QUIRK_MIDI_NOVATION 10 QUIRK_AUDIO_STANDARD_INTERFACE,
#define QUIRK_MIDI_RAW 11 QUIRK_AUDIO_FIXED_ENDPOINT,
#define QUIRK_MIDI_EMAGIC 12 QUIRK_AUDIO_EDIROL_UA700_UA25,
#define QUIRK_MIDI_MIDITECH 13 QUIRK_AUDIO_EDIROL_UA1000,
QUIRK_TYPE_COUNT
};
typedef struct snd_usb_audio_quirk snd_usb_audio_quirk_t; typedef struct snd_usb_audio_quirk snd_usb_audio_quirk_t;
typedef struct snd_usb_midi_endpoint_info snd_usb_midi_endpoint_info_t; typedef struct snd_usb_midi_endpoint_info snd_usb_midi_endpoint_info_t;
...@@ -176,7 +179,7 @@ struct snd_usb_audio_quirk { ...@@ -176,7 +179,7 @@ struct snd_usb_audio_quirk {
const char *vendor_name; const char *vendor_name;
const char *product_name; const char *product_name;
int16_t ifnum; int16_t ifnum;
int16_t type; uint16_t type;
const void *data; const void *data;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment