[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: Clemens Ladisch <clemens@ladisch.de>

authored by Clemens Ladisch and committed by Jaroslav Kysela 854af957 f38275fe

+53 -41
+34 -25
sound/usb/usbaudio.c
··· 2735 2735 * to detect the sample rate is by looking at wMaxPacketSize. 2736 2736 */ 2737 2737 static int create_ua700_ua25_quirk(snd_usb_audio_t *chip, 2738 - struct usb_interface *iface) 2738 + struct usb_interface *iface, 2739 + const snd_usb_audio_quirk_t *quirk) 2739 2740 { 2740 2741 static const struct audioformat ua_format = { 2741 2742 .format = SNDRV_PCM_FORMAT_S24_3LE, ··· 2827 2826 /* 2828 2827 * Create a stream for an Edirol UA-1000 interface. 2829 2828 */ 2830 - static int create_ua1000_quirk(snd_usb_audio_t *chip, struct usb_interface *iface) 2829 + static int create_ua1000_quirk(snd_usb_audio_t *chip, 2830 + struct usb_interface *iface, 2831 + const snd_usb_audio_quirk_t *quirk) 2831 2832 { 2832 2833 static const struct audioformat ua1000_format = { 2833 2834 .format = SNDRV_PCM_FORMAT_S32_LE, ··· 2906 2903 return 0; 2907 2904 } 2908 2905 2906 + static int ignore_interface_quirk(snd_usb_audio_t *chip, 2907 + struct usb_interface *iface, 2908 + const snd_usb_audio_quirk_t *quirk) 2909 + { 2910 + return 0; 2911 + } 2912 + 2909 2913 2910 2914 /* 2911 2915 * boot quirks ··· 2975 2965 struct usb_interface *iface, 2976 2966 const snd_usb_audio_quirk_t *quirk) 2977 2967 { 2978 - switch (quirk->type) { 2979 - case QUIRK_MIDI_FIXED_ENDPOINT: 2980 - case QUIRK_MIDI_YAMAHA: 2981 - case QUIRK_MIDI_MIDIMAN: 2982 - case QUIRK_MIDI_NOVATION: 2983 - case QUIRK_MIDI_RAW: 2984 - case QUIRK_MIDI_EMAGIC: 2985 - case QUIRK_MIDI_MIDITECH: 2986 - return snd_usb_create_midi_interface(chip, iface, quirk); 2987 - case QUIRK_COMPOSITE: 2988 - return create_composite_quirk(chip, iface, quirk); 2989 - case QUIRK_AUDIO_FIXED_ENDPOINT: 2990 - return create_fixed_stream_quirk(chip, iface, quirk); 2991 - case QUIRK_AUDIO_STANDARD_INTERFACE: 2992 - case QUIRK_MIDI_STANDARD_INTERFACE: 2993 - return create_standard_interface_quirk(chip, iface, quirk); 2994 - case QUIRK_AUDIO_EDIROL_UA700_UA25: 2995 - return create_ua700_ua25_quirk(chip, iface); 2996 - case QUIRK_AUDIO_EDIROL_UA1000: 2997 - return create_ua1000_quirk(chip, iface); 2998 - case QUIRK_IGNORE_INTERFACE: 2999 - return 0; 3000 - default: 2968 + typedef int (*quirk_func_t)(snd_usb_audio_t *, struct usb_interface *, 2969 + const snd_usb_audio_quirk_t *); 2970 + static const quirk_func_t quirk_funcs[] = { 2971 + [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk, 2972 + [QUIRK_COMPOSITE] = create_composite_quirk, 2973 + [QUIRK_MIDI_STANDARD_INTERFACE] = snd_usb_create_midi_interface, 2974 + [QUIRK_MIDI_FIXED_ENDPOINT] = snd_usb_create_midi_interface, 2975 + [QUIRK_MIDI_YAMAHA] = snd_usb_create_midi_interface, 2976 + [QUIRK_MIDI_MIDIMAN] = snd_usb_create_midi_interface, 2977 + [QUIRK_MIDI_NOVATION] = snd_usb_create_midi_interface, 2978 + [QUIRK_MIDI_RAW] = snd_usb_create_midi_interface, 2979 + [QUIRK_MIDI_EMAGIC] = snd_usb_create_midi_interface, 2980 + [QUIRK_MIDI_MIDITECH] = snd_usb_create_midi_interface, 2981 + [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_interface_quirk, 2982 + [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 2983 + [QUIRK_AUDIO_EDIROL_UA700_UA25] = create_ua700_ua25_quirk, 2984 + [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, 2985 + }; 2986 + 2987 + if (quirk->type < QUIRK_TYPE_COUNT) { 2988 + return quirk_funcs[quirk->type](chip, iface, quirk); 2989 + } else { 3001 2990 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); 3002 2991 return -ENXIO; 3003 2992 }
+19 -16
sound/usb/usbaudio.h
··· 153 153 #define QUIRK_NO_INTERFACE -2 154 154 #define QUIRK_ANY_INTERFACE -1 155 155 156 - /* quirk type */ 157 - #define QUIRK_MIDI_FIXED_ENDPOINT 0 158 - #define QUIRK_MIDI_YAMAHA 1 159 - #define QUIRK_MIDI_MIDIMAN 2 160 - #define QUIRK_COMPOSITE 3 161 - #define QUIRK_AUDIO_FIXED_ENDPOINT 4 162 - #define QUIRK_AUDIO_STANDARD_INTERFACE 5 163 - #define QUIRK_MIDI_STANDARD_INTERFACE 6 164 - #define QUIRK_AUDIO_EDIROL_UA700_UA25 7 165 - #define QUIRK_AUDIO_EDIROL_UA1000 8 166 - #define QUIRK_IGNORE_INTERFACE 9 167 - #define QUIRK_MIDI_NOVATION 10 168 - #define QUIRK_MIDI_RAW 11 169 - #define QUIRK_MIDI_EMAGIC 12 170 - #define QUIRK_MIDI_MIDITECH 13 156 + enum quirk_type { 157 + QUIRK_IGNORE_INTERFACE, 158 + QUIRK_COMPOSITE, 159 + QUIRK_MIDI_STANDARD_INTERFACE, 160 + QUIRK_MIDI_FIXED_ENDPOINT, 161 + QUIRK_MIDI_YAMAHA, 162 + QUIRK_MIDI_MIDIMAN, 163 + QUIRK_MIDI_NOVATION, 164 + QUIRK_MIDI_RAW, 165 + QUIRK_MIDI_EMAGIC, 166 + QUIRK_MIDI_MIDITECH, 167 + QUIRK_AUDIO_STANDARD_INTERFACE, 168 + QUIRK_AUDIO_FIXED_ENDPOINT, 169 + QUIRK_AUDIO_EDIROL_UA700_UA25, 170 + QUIRK_AUDIO_EDIROL_UA1000, 171 + 172 + QUIRK_TYPE_COUNT 173 + }; 171 174 172 175 typedef struct snd_usb_audio_quirk snd_usb_audio_quirk_t; 173 176 typedef struct snd_usb_midi_endpoint_info snd_usb_midi_endpoint_info_t; ··· 179 176 const char *vendor_name; 180 177 const char *product_name; 181 178 int16_t ifnum; 182 - int16_t type; 179 + uint16_t type; 183 180 const void *data; 184 181 }; 185 182