Skip to content

Commit dcaaf9f

Browse files
committed
ALSA: usb-audio - Fix the missing volume quirks at delayed init
In the recent usb-audio driver, the initialization of volume ranges may be delayed when the device doesn't respond well at the probing time. But the volume quirks for certain devices are applied only in mixer_ctl_feature_info() thus only at the very first probe and will be missing when the volume range is initialized later. This patch moves the volume quirk code to be always called from the volume-range extraction (get_min_max()), so that the quirks are properly applied in the later init time. Reported-and-tested-by: Alexey Fisher <bug-track@fisher-privat.net> Cc: <stable@kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent dccc181 commit dcaaf9f

1 file changed

Lines changed: 59 additions & 50 deletions

File tree

‎sound/usb/mixer.c‎

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,60 @@ static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
765765
* interface to ALSA control for feature/mixer units
766766
*/
767767

768+
/* volume control quirks */
769+
static void volume_control_quirks(struct usb_mixer_elem_info *cval,
770+
struct snd_kcontrol *kctl)
771+
{
772+
switch (cval->mixer->chip->usb_id) {
773+
case USB_ID(0x0471, 0x0101):
774+
case USB_ID(0x0471, 0x0104):
775+
case USB_ID(0x0471, 0x0105):
776+
case USB_ID(0x0672, 0x1041):
777+
/* quirk for UDA1321/N101.
778+
* note that detection between firmware 2.1.1.7 (N101)
779+
* and later 2.1.1.21 is not very clear from datasheets.
780+
* I hope that the min value is -15360 for newer firmware --jk
781+
*/
782+
if (!strcmp(kctl->id.name, "PCM Playback Volume") &&
783+
cval->min == -15616) {
784+
snd_printk(KERN_INFO
785+
"set volume quirk for UDA1321/N101 chip\n");
786+
cval->max = -256;
787+
}
788+
break;
789+
790+
case USB_ID(0x046d, 0x09a4):
791+
if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
792+
snd_printk(KERN_INFO
793+
"set volume quirk for QuickCam E3500\n");
794+
cval->min = 6080;
795+
cval->max = 8768;
796+
cval->res = 192;
797+
}
798+
break;
799+
800+
case USB_ID(0x046d, 0x0808):
801+
case USB_ID(0x046d, 0x0809):
802+
case USB_ID(0x046d, 0x0991):
803+
/* Most audio usb devices lie about volume resolution.
804+
* Most Logitech webcams have res = 384.
805+
* Proboly there is some logitech magic behind this number --fishor
806+
*/
807+
if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
808+
snd_printk(KERN_INFO
809+
"set resolution quirk: cval->res = 384\n");
810+
cval->res = 384;
811+
}
812+
break;
813+
814+
}
815+
}
816+
768817
/*
769818
* retrieve the minimum and maximum values for the specified control
770819
*/
771-
static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
820+
static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
821+
int default_min, struct snd_kcontrol *kctl)
772822
{
773823
/* for failsafe */
774824
cval->min = default_min;
@@ -844,6 +894,9 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
844894
cval->initialized = 1;
845895
}
846896

897+
if (kctl)
898+
volume_control_quirks(cval, kctl);
899+
847900
/* USB descriptions contain the dB scale in 1/256 dB unit
848901
* while ALSA TLV contains in 1/100 dB unit
849902
*/
@@ -864,6 +917,7 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
864917
return 0;
865918
}
866919

920+
#define get_min_max(cval, def) get_min_max_with_quirks(cval, def, NULL)
867921

868922
/* get a feature/mixer unit info */
869923
static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
@@ -882,7 +936,7 @@ static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
882936
uinfo->value.integer.max = 1;
883937
} else {
884938
if (!cval->initialized) {
885-
get_min_max(cval, 0);
939+
get_min_max_with_quirks(cval, 0, kcontrol);
886940
if (cval->initialized && cval->dBmin >= cval->dBmax) {
887941
kcontrol->vd[0].access &=
888942
~(SNDRV_CTL_ELEM_ACCESS_TLV_READ |
@@ -1045,9 +1099,6 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
10451099
cval->ch_readonly = readonly_mask;
10461100
}
10471101

1048-
/* get min/max values */
1049-
get_min_max(cval, 0);
1050-
10511102
/* if all channels in the mask are marked read-only, make the control
10521103
* read-only. set_cur_mix_value() will check the mask again and won't
10531104
* issue write commands to read-only channels. */
@@ -1069,6 +1120,9 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
10691120
len = snd_usb_copy_string_desc(state, nameid,
10701121
kctl->id.name, sizeof(kctl->id.name));
10711122

1123+
/* get min/max values */
1124+
get_min_max_with_quirks(cval, 0, kctl);
1125+
10721126
switch (control) {
10731127
case UAC_FU_MUTE:
10741128
case UAC_FU_VOLUME:
@@ -1118,51 +1172,6 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
11181172
break;
11191173
}
11201174

1121-
/* volume control quirks */
1122-
switch (state->chip->usb_id) {
1123-
case USB_ID(0x0471, 0x0101):
1124-
case USB_ID(0x0471, 0x0104):
1125-
case USB_ID(0x0471, 0x0105):
1126-
case USB_ID(0x0672, 0x1041):
1127-
/* quirk for UDA1321/N101.
1128-
* note that detection between firmware 2.1.1.7 (N101)
1129-
* and later 2.1.1.21 is not very clear from datasheets.
1130-
* I hope that the min value is -15360 for newer firmware --jk
1131-
*/
1132-
if (!strcmp(kctl->id.name, "PCM Playback Volume") &&
1133-
cval->min == -15616) {
1134-
snd_printk(KERN_INFO
1135-
"set volume quirk for UDA1321/N101 chip\n");
1136-
cval->max = -256;
1137-
}
1138-
break;
1139-
1140-
case USB_ID(0x046d, 0x09a4):
1141-
if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
1142-
snd_printk(KERN_INFO
1143-
"set volume quirk for QuickCam E3500\n");
1144-
cval->min = 6080;
1145-
cval->max = 8768;
1146-
cval->res = 192;
1147-
}
1148-
break;
1149-
1150-
case USB_ID(0x046d, 0x0808):
1151-
case USB_ID(0x046d, 0x0809):
1152-
case USB_ID(0x046d, 0x0991):
1153-
/* Most audio usb devices lie about volume resolution.
1154-
* Most Logitech webcams have res = 384.
1155-
* Proboly there is some logitech magic behind this number --fishor
1156-
*/
1157-
if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
1158-
snd_printk(KERN_INFO
1159-
"set resolution quirk: cval->res = 384\n");
1160-
cval->res = 384;
1161-
}
1162-
break;
1163-
1164-
}
1165-
11661175
range = (cval->max - cval->min) / cval->res;
11671176
/* Are there devices with volume range more than 255? I use a bit more
11681177
* to be sure. 384 is a resolution magic number found on Logitech

0 commit comments

Comments
 (0)