aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/mixer.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb/mixer.c')
-rw-r--r--sound/usb/mixer.c129
1 files changed, 74 insertions, 55 deletions
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index cdd19d7fe50..ab23869c01b 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -296,7 +296,7 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
296 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request, 296 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request,
297 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 297 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
298 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 298 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
299 buf, val_len, 100) >= val_len) { 299 buf, val_len) >= val_len) {
300 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len)); 300 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
301 snd_usb_autosuspend(cval->mixer->chip); 301 snd_usb_autosuspend(cval->mixer->chip);
302 return 0; 302 return 0;
@@ -333,7 +333,7 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
333 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest, 333 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest,
334 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 334 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
335 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 335 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
336 buf, size, 1000); 336 buf, size);
337 snd_usb_autosuspend(chip); 337 snd_usb_autosuspend(chip);
338 338
339 if (ret < 0) { 339 if (ret < 0) {
@@ -445,7 +445,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
445 usb_sndctrlpipe(chip->dev, 0), request, 445 usb_sndctrlpipe(chip->dev, 0), request,
446 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 446 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
447 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 447 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
448 buf, val_len, 100) >= 0) { 448 buf, val_len) >= 0) {
449 snd_usb_autosuspend(chip); 449 snd_usb_autosuspend(chip);
450 return 0; 450 return 0;
451 } 451 }
@@ -765,10 +765,61 @@ static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
765 * interface to ALSA control for feature/mixer units 765 * interface to ALSA control for feature/mixer units
766 */ 766 */
767 767
768/* volume control quirks */
769static 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, 0x081d): /* HD Webcam c510 */
803 case USB_ID(0x046d, 0x0991):
804 /* Most audio usb devices lie about volume resolution.
805 * Most Logitech webcams have res = 384.
806 * Proboly there is some logitech magic behind this number --fishor
807 */
808 if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
809 snd_printk(KERN_INFO
810 "set resolution quirk: cval->res = 384\n");
811 cval->res = 384;
812 }
813 break;
814
815 }
816}
817
768/* 818/*
769 * retrieve the minimum and maximum values for the specified control 819 * retrieve the minimum and maximum values for the specified control
770 */ 820 */
771static int get_min_max(struct usb_mixer_elem_info *cval, int default_min) 821static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
822 int default_min, struct snd_kcontrol *kctl)
772{ 823{
773 /* for failsafe */ 824 /* for failsafe */
774 cval->min = default_min; 825 cval->min = default_min;
@@ -844,6 +895,9 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
844 cval->initialized = 1; 895 cval->initialized = 1;
845 } 896 }
846 897
898 if (kctl)
899 volume_control_quirks(cval, kctl);
900
847 /* USB descriptions contain the dB scale in 1/256 dB unit 901 /* USB descriptions contain the dB scale in 1/256 dB unit
848 * while ALSA TLV contains in 1/100 dB unit 902 * while ALSA TLV contains in 1/100 dB unit
849 */ 903 */
@@ -864,6 +918,7 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
864 return 0; 918 return 0;
865} 919}
866 920
921#define get_min_max(cval, def) get_min_max_with_quirks(cval, def, NULL)
867 922
868/* get a feature/mixer unit info */ 923/* get a feature/mixer unit info */
869static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 924static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
@@ -881,8 +936,17 @@ static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
881 uinfo->value.integer.min = 0; 936 uinfo->value.integer.min = 0;
882 uinfo->value.integer.max = 1; 937 uinfo->value.integer.max = 1;
883 } else { 938 } else {
884 if (! cval->initialized) 939 if (!cval->initialized) {
885 get_min_max(cval, 0); 940 get_min_max_with_quirks(cval, 0, kcontrol);
941 if (cval->initialized && cval->dBmin >= cval->dBmax) {
942 kcontrol->vd[0].access &=
943 ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ |
944 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK);
945 snd_ctl_notify(cval->mixer->chip->card,
946 SNDRV_CTL_EVENT_MASK_INFO,
947 &kcontrol->id);
948 }
949 }
886 uinfo->value.integer.min = 0; 950 uinfo->value.integer.min = 0;
887 uinfo->value.integer.max = 951 uinfo->value.integer.max =
888 (cval->max - cval->min + cval->res - 1) / cval->res; 952 (cval->max - cval->min + cval->res - 1) / cval->res;
@@ -1036,9 +1100,6 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1036 cval->ch_readonly = readonly_mask; 1100 cval->ch_readonly = readonly_mask;
1037 } 1101 }
1038 1102
1039 /* get min/max values */
1040 get_min_max(cval, 0);
1041
1042 /* if all channels in the mask are marked read-only, make the control 1103 /* if all channels in the mask are marked read-only, make the control
1043 * read-only. set_cur_mix_value() will check the mask again and won't 1104 * read-only. set_cur_mix_value() will check the mask again and won't
1044 * issue write commands to read-only channels. */ 1105 * issue write commands to read-only channels. */
@@ -1060,6 +1121,9 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1060 len = snd_usb_copy_string_desc(state, nameid, 1121 len = snd_usb_copy_string_desc(state, nameid,
1061 kctl->id.name, sizeof(kctl->id.name)); 1122 kctl->id.name, sizeof(kctl->id.name));
1062 1123
1124 /* get min/max values */
1125 get_min_max_with_quirks(cval, 0, kctl);
1126
1063 switch (control) { 1127 switch (control) {
1064 case UAC_FU_MUTE: 1128 case UAC_FU_MUTE:
1065 case UAC_FU_VOLUME: 1129 case UAC_FU_VOLUME:
@@ -1109,51 +1173,6 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1109 break; 1173 break;
1110 } 1174 }
1111 1175
1112 /* volume control quirks */
1113 switch (state->chip->usb_id) {
1114 case USB_ID(0x0471, 0x0101):
1115 case USB_ID(0x0471, 0x0104):
1116 case USB_ID(0x0471, 0x0105):
1117 case USB_ID(0x0672, 0x1041):
1118 /* quirk for UDA1321/N101.
1119 * note that detection between firmware 2.1.1.7 (N101)
1120 * and later 2.1.1.21 is not very clear from datasheets.
1121 * I hope that the min value is -15360 for newer firmware --jk
1122 */
1123 if (!strcmp(kctl->id.name, "PCM Playback Volume") &&
1124 cval->min == -15616) {
1125 snd_printk(KERN_INFO
1126 "set volume quirk for UDA1321/N101 chip\n");
1127 cval->max = -256;
1128 }
1129 break;
1130
1131 case USB_ID(0x046d, 0x09a4):
1132 if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
1133 snd_printk(KERN_INFO
1134 "set volume quirk for QuickCam E3500\n");
1135 cval->min = 6080;
1136 cval->max = 8768;
1137 cval->res = 192;
1138 }
1139 break;
1140
1141 case USB_ID(0x046d, 0x0808):
1142 case USB_ID(0x046d, 0x0809):
1143 case USB_ID(0x046d, 0x0991):
1144 /* Most audio usb devices lie about volume resolution.
1145 * Most Logitech webcams have res = 384.
1146 * Proboly there is some logitech magic behind this number --fishor
1147 */
1148 if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
1149 snd_printk(KERN_INFO
1150 "set resolution quirk: cval->res = 384\n");
1151 cval->res = 384;
1152 }
1153 break;
1154
1155 }
1156
1157 range = (cval->max - cval->min) / cval->res; 1176 range = (cval->max - cval->min) / cval->res;
1158 /* Are there devices with volume range more than 255? I use a bit more 1177 /* Are there devices with volume range more than 255? I use a bit more
1159 * to be sure. 384 is a resolution magic number found on Logitech 1178 * to be sure. 384 is a resolution magic number found on Logitech
@@ -1250,7 +1269,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
1250 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0); 1269 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0);
1251 } 1270 }
1252 } else { /* UAC_VERSION_2 */ 1271 } else { /* UAC_VERSION_2 */
1253 for (i = 0; i < 30/2; i++) { 1272 for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) {
1254 unsigned int ch_bits = 0; 1273 unsigned int ch_bits = 0;
1255 unsigned int ch_read_only = 0; 1274 unsigned int ch_read_only = 0;
1256 1275