diff options
author | Takashi Iwai <tiwai@suse.de> | 2010-06-15 06:24:05 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2010-06-15 06:24:05 -0400 |
commit | eb6e70417bfef869324b8452f11ba7f300da4f81 (patch) | |
tree | aaeeb53783f5fb16e8a0d1069104f8e7aed8e624 /sound | |
parent | 8fda43c1a02baf093b63bca9770363642a7098e7 (diff) | |
parent | e8bdb6bbab60a8731f21823c86391f176d052348 (diff) |
Merge branch 'fix/misc' into for-linus
Diffstat (limited to 'sound')
-rw-r--r-- | sound/usb/clock.c | 12 | ||||
-rw-r--r-- | sound/usb/format.c | 104 | ||||
-rw-r--r-- | sound/usb/helper.h | 4 | ||||
-rw-r--r-- | sound/usb/mixer.c | 19 |
4 files changed, 110 insertions, 29 deletions
diff --git a/sound/usb/clock.c b/sound/usb/clock.c index b7aadd614c70..b5855114667e 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/format.c b/sound/usb/format.c index 5367cd1e52d9..30364aba79cc 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 | */ | ||
214 | static 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 | ||
275 | err_free: | 339 | err_free: |
276 | kfree(data); | 340 | kfree(data); |
diff --git a/sound/usb/helper.h b/sound/usb/helper.h index a6b0e51b3a9a..09bd943c43bf 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 | ||
31 | static 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 a060d005e209..6939d0f517d9 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 | ||
298 | static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret) | 298 | static 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; |