aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-06-27 10:39:57 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-06-27 10:39:57 -0400
commit29ccb201a28f20885c90954152db8421a2efe779 (patch)
tree21e29b86d002cc9635e8929882f4b31435266bd1 /sound
parentd94b20497b419e8394654f995f94742bd6b06640 (diff)
parentd69f309f0477fc13418f7526639f9ed527ff01e5 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6: ALSA: usb/endpoint, fix dangling pointer use ALSA: asihpi - Get rid of incorrect "long" types and casts. ASoC: DaVinci: Fix McASP hardware FIFO configuration ALSA: hda - Fix line-in for mb5 model MacBook (Pro) 5,1 / 5,2 ALSA: usb-audio: fix UAC2 control value queries ALSA: usb-audio: parse UAC2 sample rate ranges correctly ALSA: usb-audio: fix control messages for USB_RECIP_INTERFACE ALSA: usb-audio: add check for faulty clock in parse_audio_format_rates_v2() ALSA: hda - Don't check capture source mixer if no ADC is available
Diffstat (limited to 'sound')
-rw-r--r--sound/pci/asihpi/hpi6205.c22
-rw-r--r--sound/pci/hda/patch_realtek.c35
-rw-r--r--sound/soc/davinci/davinci-mcasp.c2
-rw-r--r--sound/usb/clock.c12
-rw-r--r--sound/usb/endpoint.c1
-rw-r--r--sound/usb/format.c104
-rw-r--r--sound/usb/helper.h4
-rw-r--r--sound/usb/mixer.c19
8 files changed, 140 insertions, 59 deletions
diff --git a/sound/pci/asihpi/hpi6205.c b/sound/pci/asihpi/hpi6205.c
index e89991ea354..3b441344822 100644
--- a/sound/pci/asihpi/hpi6205.c
+++ b/sound/pci/asihpi/hpi6205.c
@@ -941,11 +941,11 @@ static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
941 941
942} 942}
943 943
944static long outstream_get_space_available(struct hpi_hostbuffer_status 944static u32 outstream_get_space_available(struct hpi_hostbuffer_status
945 *status) 945 *status)
946{ 946{
947 return status->size_in_bytes - ((long)(status->host_index) - 947 return status->size_in_bytes - (status->host_index -
948 (long)(status->dSP_index)); 948 status->dSP_index);
949} 949}
950 950
951static void outstream_write(struct hpi_adapter_obj *pao, 951static void outstream_write(struct hpi_adapter_obj *pao,
@@ -954,7 +954,7 @@ static void outstream_write(struct hpi_adapter_obj *pao,
954 struct hpi_hw_obj *phw = pao->priv; 954 struct hpi_hw_obj *phw = pao->priv;
955 struct bus_master_interface *interface = phw->p_interface_buffer; 955 struct bus_master_interface *interface = phw->p_interface_buffer;
956 struct hpi_hostbuffer_status *status; 956 struct hpi_hostbuffer_status *status;
957 long space_available; 957 u32 space_available;
958 958
959 if (!phw->outstream_host_buffer_size[phm->obj_index]) { 959 if (!phw->outstream_host_buffer_size[phm->obj_index]) {
960 /* there is no BBM buffer, write via message */ 960 /* there is no BBM buffer, write via message */
@@ -1007,7 +1007,7 @@ static void outstream_write(struct hpi_adapter_obj *pao,
1007 } 1007 }
1008 1008
1009 space_available = outstream_get_space_available(status); 1009 space_available = outstream_get_space_available(status);
1010 if (space_available < (long)phm->u.d.u.data.data_size) { 1010 if (space_available < phm->u.d.u.data.data_size) {
1011 phr->error = HPI_ERROR_INVALID_DATASIZE; 1011 phr->error = HPI_ERROR_INVALID_DATASIZE;
1012 return; 1012 return;
1013 } 1013 }
@@ -1018,7 +1018,7 @@ static void outstream_write(struct hpi_adapter_obj *pao,
1018 && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm-> 1018 && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
1019 obj_index])) { 1019 obj_index])) {
1020 u8 *p_bbm_data; 1020 u8 *p_bbm_data;
1021 long l_first_write; 1021 u32 l_first_write;
1022 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data; 1022 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
1023 1023
1024 if (hpios_locked_mem_get_virt_addr(&phw-> 1024 if (hpios_locked_mem_get_virt_addr(&phw->
@@ -1248,9 +1248,9 @@ static void instream_start(struct hpi_adapter_obj *pao,
1248 hw_message(pao, phm, phr); 1248 hw_message(pao, phm, phr);
1249} 1249}
1250 1250
1251static long instream_get_bytes_available(struct hpi_hostbuffer_status *status) 1251static u32 instream_get_bytes_available(struct hpi_hostbuffer_status *status)
1252{ 1252{
1253 return (long)(status->dSP_index) - (long)(status->host_index); 1253 return status->dSP_index - status->host_index;
1254} 1254}
1255 1255
1256static void instream_read(struct hpi_adapter_obj *pao, 1256static void instream_read(struct hpi_adapter_obj *pao,
@@ -1259,9 +1259,9 @@ static void instream_read(struct hpi_adapter_obj *pao,
1259 struct hpi_hw_obj *phw = pao->priv; 1259 struct hpi_hw_obj *phw = pao->priv;
1260 struct bus_master_interface *interface = phw->p_interface_buffer; 1260 struct bus_master_interface *interface = phw->p_interface_buffer;
1261 struct hpi_hostbuffer_status *status; 1261 struct hpi_hostbuffer_status *status;
1262 long data_available; 1262 u32 data_available;
1263 u8 *p_bbm_data; 1263 u8 *p_bbm_data;
1264 long l_first_read; 1264 u32 l_first_read;
1265 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data; 1265 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
1266 1266
1267 if (!phw->instream_host_buffer_size[phm->obj_index]) { 1267 if (!phw->instream_host_buffer_size[phm->obj_index]) {
@@ -1272,7 +1272,7 @@ static void instream_read(struct hpi_adapter_obj *pao,
1272 1272
1273 status = &interface->instream_host_buffer_status[phm->obj_index]; 1273 status = &interface->instream_host_buffer_status[phm->obj_index];
1274 data_available = instream_get_bytes_available(status); 1274 data_available = instream_get_bytes_available(status);
1275 if (data_available < (long)phm->u.d.u.data.data_size) { 1275 if (data_available < phm->u.d.u.data.data_size) {
1276 phr->error = HPI_ERROR_INVALID_DATASIZE; 1276 phr->error = HPI_ERROR_INVALID_DATASIZE;
1277 return; 1277 return;
1278 } 1278 }
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index fc767b6b478..f1ce7d7f5aa 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -2619,16 +2619,18 @@ static int alc_build_controls(struct hda_codec *codec)
2619 } 2619 }
2620 2620
2621 /* assign Capture Source enums to NID */ 2621 /* assign Capture Source enums to NID */
2622 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); 2622 if (spec->capsrc_nids || spec->adc_nids) {
2623 if (!kctl) 2623 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
2624 kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); 2624 if (!kctl)
2625 for (i = 0; kctl && i < kctl->count; i++) { 2625 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
2626 hda_nid_t *nids = spec->capsrc_nids; 2626 for (i = 0; kctl && i < kctl->count; i++) {
2627 if (!nids) 2627 hda_nid_t *nids = spec->capsrc_nids;
2628 nids = spec->adc_nids; 2628 if (!nids)
2629 err = snd_hda_add_nid(codec, kctl, i, nids[i]); 2629 nids = spec->adc_nids;
2630 if (err < 0) 2630 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
2631 return err; 2631 if (err < 0)
2632 return err;
2633 }
2632 } 2634 }
2633 if (spec->cap_mixer) { 2635 if (spec->cap_mixer) {
2634 const char *kname = kctl ? kctl->id.name : NULL; 2636 const char *kname = kctl ? kctl->id.name : NULL;
@@ -6948,7 +6950,7 @@ static struct hda_input_mux mb5_capture_source = {
6948 .num_items = 3, 6950 .num_items = 3,
6949 .items = { 6951 .items = {
6950 { "Mic", 0x1 }, 6952 { "Mic", 0x1 },
6951 { "Line", 0x2 }, 6953 { "Line", 0x7 },
6952 { "CD", 0x4 }, 6954 { "CD", 0x4 },
6953 }, 6955 },
6954}; 6956};
@@ -7469,8 +7471,8 @@ static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7469 HDA_BIND_MUTE ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT), 7471 HDA_BIND_MUTE ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7470 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT), 7472 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7471 HDA_BIND_MUTE ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT), 7473 HDA_BIND_MUTE ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
7472 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 7474 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
7473 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 7475 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
7474 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 7476 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7475 HDA_CODEC_MUTE ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 7477 HDA_CODEC_MUTE ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7476 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT), 7478 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
@@ -7853,10 +7855,9 @@ static struct hda_verb alc885_mb5_init_verbs[] = {
7853 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 7855 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7854 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 7856 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7855 7857
7856 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 7858 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0x1)},
7857 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 7859 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0x7)},
7858 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 7860 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0x4)},
7859 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7860 { } 7861 { }
7861}; 7862};
7862 7863
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 79f0f4ad242..d3955096d87 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -612,7 +612,6 @@ static void davinci_hw_common_param(struct davinci_audio_dev *dev, int stream)
612 NUMDMA_MASK); 612 NUMDMA_MASK);
613 mcasp_mod_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, 613 mcasp_mod_bits(dev->base + DAVINCI_MCASP_WFIFOCTL,
614 ((dev->txnumevt * tx_ser) << 8), NUMEVT_MASK); 614 ((dev->txnumevt * tx_ser) << 8), NUMEVT_MASK);
615 mcasp_set_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE);
616 } 615 }
617 616
618 if (dev->rxnumevt && stream == SNDRV_PCM_STREAM_CAPTURE) { 617 if (dev->rxnumevt && stream == SNDRV_PCM_STREAM_CAPTURE) {
@@ -623,7 +622,6 @@ static void davinci_hw_common_param(struct davinci_audio_dev *dev, int stream)
623 NUMDMA_MASK); 622 NUMDMA_MASK);
624 mcasp_mod_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, 623 mcasp_mod_bits(dev->base + DAVINCI_MCASP_RFIFOCTL,
625 ((dev->rxnumevt * rx_ser) << 8), NUMEVT_MASK); 624 ((dev->rxnumevt * rx_ser) << 8), NUMEVT_MASK);
626 mcasp_set_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE);
627 } 625 }
628} 626}
629 627
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index b7aadd614c7..b5855114667 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -103,7 +103,8 @@ static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_i
103 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), 103 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0),
104 UAC2_CS_CUR, 104 UAC2_CS_CUR,
105 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 105 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
106 UAC2_CX_CLOCK_SELECTOR << 8, selector_id << 8, 106 UAC2_CX_CLOCK_SELECTOR << 8,
107 snd_usb_ctrl_intf(chip) | (selector_id << 8),
107 &buf, sizeof(buf), 1000); 108 &buf, sizeof(buf), 1000);
108 109
109 if (ret < 0) 110 if (ret < 0)
@@ -120,7 +121,8 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
120 121
121 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, 122 err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
122 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 123 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
123 UAC2_CS_CONTROL_CLOCK_VALID << 8, source_id << 8, 124 UAC2_CS_CONTROL_CLOCK_VALID << 8,
125 snd_usb_ctrl_intf(chip) | (source_id << 8),
124 &data, sizeof(data), 1000); 126 &data, sizeof(data), 1000);
125 127
126 if (err < 0) { 128 if (err < 0) {
@@ -269,7 +271,8 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
269 data[3] = rate >> 24; 271 data[3] = rate >> 24;
270 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, 272 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
271 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, 273 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
272 UAC2_CS_CONTROL_SAM_FREQ << 8, clock << 8, 274 UAC2_CS_CONTROL_SAM_FREQ << 8,
275 snd_usb_ctrl_intf(chip) | (clock << 8),
273 data, sizeof(data), 1000)) < 0) { 276 data, sizeof(data), 1000)) < 0) {
274 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n", 277 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n",
275 dev->devnum, iface, fmt->altsetting, rate); 278 dev->devnum, iface, fmt->altsetting, rate);
@@ -278,7 +281,8 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
278 281
279 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, 282 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
280 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 283 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
281 UAC2_CS_CONTROL_SAM_FREQ << 8, clock << 8, 284 UAC2_CS_CONTROL_SAM_FREQ << 8,
285 snd_usb_ctrl_intf(chip) | (clock << 8),
282 data, sizeof(data), 1000)) < 0) { 286 data, sizeof(data), 1000)) < 0) {
283 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", 287 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n",
284 dev->devnum, iface, fmt->altsetting); 288 dev->devnum, iface, fmt->altsetting);
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 9593b91452b..6f6596cf2b1 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -427,6 +427,7 @@ int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
427 if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) { 427 if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
428 kfree(fp->rate_table); 428 kfree(fp->rate_table);
429 kfree(fp); 429 kfree(fp);
430 fp = NULL;
430 continue; 431 continue;
431 } 432 }
432 433
diff --git a/sound/usb/format.c b/sound/usb/format.c
index 5367cd1e52d..30364aba79c 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -206,6 +206,60 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof
206} 206}
207 207
208/* 208/*
209 * Helper function to walk the array of sample rate triplets reported by
210 * the device. The problem is that we need to parse whole array first to
211 * get to know how many sample rates we have to expect.
212 * Then fp->rate_table can be allocated and filled.
213 */
214static int parse_uac2_sample_rate_range(struct audioformat *fp, int nr_triplets,
215 const unsigned char *data)
216{
217 int i, nr_rates = 0;
218
219 fp->rates = fp->rate_min = fp->rate_max = 0;
220
221 for (i = 0; i < nr_triplets; i++) {
222 int min = combine_quad(&data[2 + 12 * i]);
223 int max = combine_quad(&data[6 + 12 * i]);
224 int res = combine_quad(&data[10 + 12 * i]);
225 int rate;
226
227 if ((max < 0) || (min < 0) || (res < 0) || (max < min))
228 continue;
229
230 /*
231 * for ranges with res == 1, we announce a continuous sample
232 * rate range, and this function should return 0 for no further
233 * parsing.
234 */
235 if (res == 1) {
236 fp->rate_min = min;
237 fp->rate_max = max;
238 fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
239 return 0;
240 }
241
242 for (rate = min; rate <= max; rate += res) {
243 if (fp->rate_table)
244 fp->rate_table[nr_rates] = rate;
245 if (!fp->rate_min || rate < fp->rate_min)
246 fp->rate_min = rate;
247 if (!fp->rate_max || rate > fp->rate_max)
248 fp->rate_max = rate;
249 fp->rates |= snd_pcm_rate_to_rate_bit(rate);
250
251 nr_rates++;
252
253 /* avoid endless loop */
254 if (res == 0)
255 break;
256 }
257 }
258
259 return nr_rates;
260}
261
262/*
209 * parse the format descriptor and stores the possible sample rates 263 * parse the format descriptor and stores the possible sample rates
210 * on the audioformat table (audio class v2). 264 * on the audioformat table (audio class v2).
211 */ 265 */
@@ -215,13 +269,20 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
215{ 269{
216 struct usb_device *dev = chip->dev; 270 struct usb_device *dev = chip->dev;
217 unsigned char tmp[2], *data; 271 unsigned char tmp[2], *data;
218 int i, nr_rates, data_size, ret = 0; 272 int nr_triplets, data_size, ret = 0;
219 int clock = snd_usb_clock_find_source(chip, chip->ctrl_intf, fp->clock); 273 int clock = snd_usb_clock_find_source(chip, chip->ctrl_intf, fp->clock);
220 274
275 if (clock < 0) {
276 snd_printk(KERN_ERR "%s(): unable to find clock source (clock %d)\n",
277 __func__, clock);
278 goto err;
279 }
280
221 /* get the number of sample rates first by only fetching 2 bytes */ 281 /* get the number of sample rates first by only fetching 2 bytes */
222 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE, 282 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
223 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 283 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
224 UAC2_CS_CONTROL_SAM_FREQ << 8, clock << 8, 284 UAC2_CS_CONTROL_SAM_FREQ << 8,
285 snd_usb_ctrl_intf(chip) | (clock << 8),
225 tmp, sizeof(tmp), 1000); 286 tmp, sizeof(tmp), 1000);
226 287
227 if (ret < 0) { 288 if (ret < 0) {
@@ -230,8 +291,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
230 goto err; 291 goto err;
231 } 292 }
232 293
233 nr_rates = (tmp[1] << 8) | tmp[0]; 294 nr_triplets = (tmp[1] << 8) | tmp[0];
234 data_size = 2 + 12 * nr_rates; 295 data_size = 2 + 12 * nr_triplets;
235 data = kzalloc(data_size, GFP_KERNEL); 296 data = kzalloc(data_size, GFP_KERNEL);
236 if (!data) { 297 if (!data) {
237 ret = -ENOMEM; 298 ret = -ENOMEM;
@@ -241,7 +302,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
241 /* now get the full information */ 302 /* now get the full information */
242 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE, 303 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
243 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 304 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
244 UAC2_CS_CONTROL_SAM_FREQ << 8, clock << 8, 305 UAC2_CS_CONTROL_SAM_FREQ << 8,
306 snd_usb_ctrl_intf(chip) | (clock << 8),
245 data, data_size, 1000); 307 data, data_size, 1000);
246 308
247 if (ret < 0) { 309 if (ret < 0) {
@@ -251,26 +313,28 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
251 goto err_free; 313 goto err_free;
252 } 314 }
253 315
254 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL); 316 /* Call the triplet parser, and make sure fp->rate_table is NULL.
317 * We just use the return value to know how many sample rates we
318 * will have to deal with. */
319 kfree(fp->rate_table);
320 fp->rate_table = NULL;
321 fp->nr_rates = parse_uac2_sample_rate_range(fp, nr_triplets, data);
322
323 if (fp->nr_rates == 0) {
324 /* SNDRV_PCM_RATE_CONTINUOUS */
325 ret = 0;
326 goto err_free;
327 }
328
329 fp->rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
255 if (!fp->rate_table) { 330 if (!fp->rate_table) {
256 ret = -ENOMEM; 331 ret = -ENOMEM;
257 goto err_free; 332 goto err_free;
258 } 333 }
259 334
260 fp->nr_rates = 0; 335 /* Call the triplet parser again, but this time, fp->rate_table is
261 fp->rate_min = fp->rate_max = 0; 336 * allocated, so the rates will be stored */
262 337 parse_uac2_sample_rate_range(fp, nr_triplets, data);
263 for (i = 0; i < nr_rates; i++) {
264 int rate = combine_quad(&data[2 + 12 * i]);
265
266 fp->rate_table[fp->nr_rates] = rate;
267 if (!fp->rate_min || rate < fp->rate_min)
268 fp->rate_min = rate;
269 if (!fp->rate_max || rate > fp->rate_max)
270 fp->rate_max = rate;
271 fp->rates |= snd_pcm_rate_to_rate_bit(rate);
272 fp->nr_rates++;
273 }
274 338
275err_free: 339err_free:
276 kfree(data); 340 kfree(data);
diff --git a/sound/usb/helper.h b/sound/usb/helper.h
index a6b0e51b3a9..09bd943c43b 100644
--- a/sound/usb/helper.h
+++ b/sound/usb/helper.h
@@ -28,5 +28,9 @@ unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
28#define snd_usb_get_speed(dev) ((dev)->speed) 28#define snd_usb_get_speed(dev) ((dev)->speed)
29#endif 29#endif
30 30
31static inline int snd_usb_ctrl_intf(struct snd_usb_audio *chip)
32{
33 return get_iface_desc(chip->ctrl_intf)->bInterfaceNumber;
34}
31 35
32#endif /* __USBAUDIO_HELPER_H */ 36#endif /* __USBAUDIO_HELPER_H */
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index a060d005e20..6939d0f517d 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -297,20 +297,27 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
297 297
298static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret) 298static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
299{ 299{
300 unsigned char buf[14]; /* enough space for one range of 4 bytes */ 300 unsigned char buf[2 + 3*sizeof(__u16)]; /* enough space for one range */
301 unsigned char *val; 301 unsigned char *val;
302 int ret; 302 int ret, size;
303 __u8 bRequest; 303 __u8 bRequest;
304 304
305 bRequest = (request == UAC_GET_CUR) ? 305 if (request == UAC_GET_CUR) {
306 UAC2_CS_CUR : UAC2_CS_RANGE; 306 bRequest = UAC2_CS_CUR;
307 size = sizeof(__u16);
308 } else {
309 bRequest = UAC2_CS_RANGE;
310 size = sizeof(buf);
311 }
312
313 memset(buf, 0, sizeof(buf));
307 314
308 ret = snd_usb_ctl_msg(cval->mixer->chip->dev, 315 ret = snd_usb_ctl_msg(cval->mixer->chip->dev,
309 usb_rcvctrlpipe(cval->mixer->chip->dev, 0), 316 usb_rcvctrlpipe(cval->mixer->chip->dev, 0),
310 bRequest, 317 bRequest,
311 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 318 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
312 validx, cval->mixer->ctrlif | (cval->id << 8), 319 validx, cval->mixer->ctrlif | (cval->id << 8),
313 buf, sizeof(buf), 1000); 320 buf, size, 1000);
314 321
315 if (ret < 0) { 322 if (ret < 0) {
316 snd_printk(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n", 323 snd_printk(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
@@ -318,6 +325,8 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
318 return ret; 325 return ret;
319 } 326 }
320 327
328 /* FIXME: how should we handle multiple triplets here? */
329
321 switch (request) { 330 switch (request) {
322 case UAC_GET_CUR: 331 case UAC_GET_CUR:
323 val = buf; 332 val = buf;