mirror of https://github.com/torvalds/linux.git
ALSA: usb-audio: improve module param quirk_flags
It accepts strings like `VID:PID:quirk_flag_name1|quirk_flag_name2;...` from now on, so that we can use it to debug USB audio devices more intuitive and flexible. The compatibility of previous form is kept. Co-developed-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
ce01726273
commit
ffd586126a
|
|
@ -73,7 +73,7 @@ static bool lowlatency = true;
|
||||||
static char *quirk_alias[SNDRV_CARDS];
|
static char *quirk_alias[SNDRV_CARDS];
|
||||||
static char *delayed_register[SNDRV_CARDS];
|
static char *delayed_register[SNDRV_CARDS];
|
||||||
static bool implicit_fb[SNDRV_CARDS];
|
static bool implicit_fb[SNDRV_CARDS];
|
||||||
static unsigned int quirk_flags[SNDRV_CARDS];
|
static char *quirk_flags[SNDRV_CARDS];
|
||||||
|
|
||||||
bool snd_usb_use_vmalloc = true;
|
bool snd_usb_use_vmalloc = true;
|
||||||
bool snd_usb_skip_validation;
|
bool snd_usb_skip_validation;
|
||||||
|
|
@ -103,7 +103,7 @@ module_param_array(delayed_register, charp, NULL, 0444);
|
||||||
MODULE_PARM_DESC(delayed_register, "Quirk for delayed registration, given by id:iface, e.g. 0123abcd:4.");
|
MODULE_PARM_DESC(delayed_register, "Quirk for delayed registration, given by id:iface, e.g. 0123abcd:4.");
|
||||||
module_param_array(implicit_fb, bool, NULL, 0444);
|
module_param_array(implicit_fb, bool, NULL, 0444);
|
||||||
MODULE_PARM_DESC(implicit_fb, "Apply generic implicit feedback sync mode.");
|
MODULE_PARM_DESC(implicit_fb, "Apply generic implicit feedback sync mode.");
|
||||||
module_param_array(quirk_flags, uint, NULL, 0444);
|
module_param_array(quirk_flags, charp, NULL, 0444);
|
||||||
MODULE_PARM_DESC(quirk_flags, "Driver quirk bit flags.");
|
MODULE_PARM_DESC(quirk_flags, "Driver quirk bit flags.");
|
||||||
module_param_named(use_vmalloc, snd_usb_use_vmalloc, bool, 0444);
|
module_param_named(use_vmalloc, snd_usb_use_vmalloc, bool, 0444);
|
||||||
MODULE_PARM_DESC(use_vmalloc, "Use vmalloc for PCM intermediate buffers (default: yes).");
|
MODULE_PARM_DESC(use_vmalloc, "Use vmalloc for PCM intermediate buffers (default: yes).");
|
||||||
|
|
@ -692,6 +692,29 @@ static void usb_audio_make_longname(struct usb_device *dev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void snd_usb_init_quirk_flags(int idx, struct snd_usb_audio *chip)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
/* old style option found: the position-based integer value */
|
||||||
|
if (quirk_flags[idx] &&
|
||||||
|
!kstrtou32(quirk_flags[idx], 0, &chip->quirk_flags)) {
|
||||||
|
snd_usb_apply_flag_dbg("module param", chip, chip->quirk_flags);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* take the default quirk from the quirk table */
|
||||||
|
snd_usb_init_quirk_flags_table(chip);
|
||||||
|
|
||||||
|
/* add or correct quirk bits from options */
|
||||||
|
for (i = 0; i < ARRAY_SIZE(quirk_flags); i++) {
|
||||||
|
if (!quirk_flags[i] || !*quirk_flags[i])
|
||||||
|
break;
|
||||||
|
|
||||||
|
snd_usb_init_quirk_flags_parse_string(chip, quirk_flags[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create a chip instance and set its names.
|
* create a chip instance and set its names.
|
||||||
*/
|
*/
|
||||||
|
|
@ -750,10 +773,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,
|
||||||
INIT_LIST_HEAD(&chip->midi_v2_list);
|
INIT_LIST_HEAD(&chip->midi_v2_list);
|
||||||
INIT_LIST_HEAD(&chip->mixer_list);
|
INIT_LIST_HEAD(&chip->mixer_list);
|
||||||
|
|
||||||
if (quirk_flags[idx])
|
snd_usb_init_quirk_flags(idx, chip);
|
||||||
chip->quirk_flags = quirk_flags[idx];
|
|
||||||
else
|
|
||||||
snd_usb_init_quirk_flags(chip);
|
|
||||||
|
|
||||||
card->private_free = snd_usb_audio_free;
|
card->private_free = snd_usb_audio_free;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2521,7 +2521,7 @@ void snd_usb_apply_flag_dbg(const char *reason,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void snd_usb_init_quirk_flags(struct snd_usb_audio *chip)
|
void snd_usb_init_quirk_flags_table(struct snd_usb_audio *chip)
|
||||||
{
|
{
|
||||||
const struct usb_audio_quirk_flags_table *p;
|
const struct usb_audio_quirk_flags_table *p;
|
||||||
|
|
||||||
|
|
@ -2535,3 +2535,91 @@ void snd_usb_init_quirk_flags(struct snd_usb_audio *chip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void snd_usb_init_quirk_flags_parse_string(struct snd_usb_audio *chip,
|
||||||
|
const char *str)
|
||||||
|
{
|
||||||
|
u16 chip_vid = USB_ID_VENDOR(chip->usb_id);
|
||||||
|
u16 chip_pid = USB_ID_PRODUCT(chip->usb_id);
|
||||||
|
u32 mask_flags, unmask_flags, bit;
|
||||||
|
char *p, *field, *flag;
|
||||||
|
bool is_unmask;
|
||||||
|
u16 vid, pid;
|
||||||
|
|
||||||
|
char *val __free(kfree) = kstrdup(str, GFP_KERNEL);
|
||||||
|
|
||||||
|
if (!val)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (p = val; p && *p;) {
|
||||||
|
/* Each entry consists of VID:PID:flags */
|
||||||
|
field = strsep(&p, ":");
|
||||||
|
if (!field)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (strcmp(field, "*") == 0)
|
||||||
|
vid = 0;
|
||||||
|
else if (kstrtou16(field, 16, &vid))
|
||||||
|
break;
|
||||||
|
|
||||||
|
field = strsep(&p, ":");
|
||||||
|
if (!field)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (strcmp(field, "*") == 0)
|
||||||
|
pid = 0;
|
||||||
|
else if (kstrtou16(field, 16, &pid))
|
||||||
|
break;
|
||||||
|
|
||||||
|
field = strsep(&p, ";");
|
||||||
|
if (!field || !*field)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ((vid != 0 && vid != chip_vid) ||
|
||||||
|
(pid != 0 && pid != chip_pid))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Collect the flags */
|
||||||
|
mask_flags = 0;
|
||||||
|
unmask_flags = 0;
|
||||||
|
while (field && *field) {
|
||||||
|
flag = strsep(&field, "|");
|
||||||
|
|
||||||
|
if (!flag)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (*flag == '!') {
|
||||||
|
is_unmask = true;
|
||||||
|
flag++;
|
||||||
|
} else {
|
||||||
|
is_unmask = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!kstrtou32(flag, 16, &bit)) {
|
||||||
|
if (is_unmask)
|
||||||
|
unmask_flags |= bit;
|
||||||
|
else
|
||||||
|
mask_flags |= bit;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bit = snd_usb_quirk_flags_from_name(flag);
|
||||||
|
|
||||||
|
if (bit) {
|
||||||
|
if (is_unmask)
|
||||||
|
unmask_flags |= bit;
|
||||||
|
else
|
||||||
|
mask_flags |= bit;
|
||||||
|
} else {
|
||||||
|
pr_warn("snd_usb_audio: unknown flag %s while parsing param quirk_flags\n",
|
||||||
|
flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chip->quirk_flags &= ~unmask_flags;
|
||||||
|
chip->quirk_flags |= mask_flags;
|
||||||
|
snd_usb_apply_flag_dbg("module param", chip,
|
||||||
|
chip->quirk_flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,9 @@ void snd_usb_apply_flag_dbg(const char *reason,
|
||||||
struct snd_usb_audio *chip,
|
struct snd_usb_audio *chip,
|
||||||
unsigned long flag);
|
unsigned long flag);
|
||||||
|
|
||||||
void snd_usb_init_quirk_flags(struct snd_usb_audio *chip);
|
void snd_usb_init_quirk_flags_table(struct snd_usb_audio *chip);
|
||||||
|
void snd_usb_init_quirk_flags_parse_string(struct snd_usb_audio *chip,
|
||||||
|
const char *str);
|
||||||
|
|
||||||
const char *snd_usb_quirk_flag_find_name(unsigned long flag);
|
const char *snd_usb_quirk_flag_find_name(unsigned long flag);
|
||||||
u32 snd_usb_quirk_flags_from_name(const char *name);
|
u32 snd_usb_quirk_flags_from_name(const char *name);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue