aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorDaniel Mack <daniel@caiaq.de>2010-06-16 11:57:31 -0400
committerTakashi Iwai <tiwai@suse.de>2010-06-23 10:10:23 -0400
commit3d8d4dcfd423b01ef7ea7c3c97720764b7adb6df (patch)
tree4bb52394ecfe1f2bda274ab6af3dbe1be9d7bbf2 /sound
parent157a57b6fae7d3c6d24b7623dcc6679c6d244621 (diff)
ALSA: usb-audio: simplify control interface access
As the control interface is now carried in struct snd_usb_audio, we can simplify the API a little and also drop the private ctrlif field from struct usb_mixer_interface. Also remove a left-over function prototype in pcm.h. Signed-off-by: Daniel Mack <daniel@caiaq.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r--sound/usb/clock.c22
-rw-r--r--sound/usb/clock.h4
-rw-r--r--sound/usb/endpoint.c1
-rw-r--r--sound/usb/format.c9
-rw-r--r--sound/usb/mixer.c37
-rw-r--r--sound/usb/mixer.h1
-rw-r--r--sound/usb/pcm.h3
-rw-r--r--sound/usb/quirks.c1
8 files changed, 34 insertions, 44 deletions
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index 7279d6190875..66bd1574d80b 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -121,7 +121,6 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
121} 121}
122 122
123static int __uac_clock_find_source(struct snd_usb_audio *chip, 123static int __uac_clock_find_source(struct snd_usb_audio *chip,
124 struct usb_host_interface *host_iface,
125 int entity_id, unsigned long *visited) 124 int entity_id, unsigned long *visited)
126{ 125{
127 struct uac_clock_source_descriptor *source; 126 struct uac_clock_source_descriptor *source;
@@ -138,11 +137,11 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
138 } 137 }
139 138
140 /* first, see if the ID we're looking for is a clock source already */ 139 /* first, see if the ID we're looking for is a clock source already */
141 source = snd_usb_find_clock_source(host_iface, entity_id); 140 source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id);
142 if (source) 141 if (source)
143 return source->bClockID; 142 return source->bClockID;
144 143
145 selector = snd_usb_find_clock_selector(host_iface, entity_id); 144 selector = snd_usb_find_clock_selector(chip->ctrl_intf, entity_id);
146 if (selector) { 145 if (selector) {
147 int ret; 146 int ret;
148 147
@@ -162,16 +161,15 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
162 return -EINVAL; 161 return -EINVAL;
163 } 162 }
164 163
165 return __uac_clock_find_source(chip, host_iface, 164 return __uac_clock_find_source(chip, selector->baCSourceID[ret-1],
166 selector->baCSourceID[ret-1],
167 visited); 165 visited);
168 } 166 }
169 167
170 /* FIXME: multipliers only act as pass-thru element for now */ 168 /* FIXME: multipliers only act as pass-thru element for now */
171 multiplier = snd_usb_find_clock_multiplier(host_iface, entity_id); 169 multiplier = snd_usb_find_clock_multiplier(chip->ctrl_intf, entity_id);
172 if (multiplier) 170 if (multiplier)
173 return __uac_clock_find_source(chip, host_iface, 171 return __uac_clock_find_source(chip, multiplier->bCSourceID,
174 multiplier->bCSourceID, visited); 172 visited);
175 173
176 return -EINVAL; 174 return -EINVAL;
177} 175}
@@ -187,13 +185,11 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
187 * 185 *
188 * Returns the clock source UnitID (>=0) on success, or an error. 186 * Returns the clock source UnitID (>=0) on success, or an error.
189 */ 187 */
190int snd_usb_clock_find_source(struct snd_usb_audio *chip, 188int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id)
191 struct usb_host_interface *host_iface,
192 int entity_id)
193{ 189{
194 DECLARE_BITMAP(visited, 256); 190 DECLARE_BITMAP(visited, 256);
195 memset(visited, 0, sizeof(visited)); 191 memset(visited, 0, sizeof(visited));
196 return __uac_clock_find_source(chip, host_iface, entity_id, visited); 192 return __uac_clock_find_source(chip, entity_id, visited);
197} 193}
198 194
199static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, 195static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
@@ -251,7 +247,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
251 struct usb_device *dev = chip->dev; 247 struct usb_device *dev = chip->dev;
252 unsigned char data[4]; 248 unsigned char data[4];
253 int err, crate; 249 int err, crate;
254 int clock = snd_usb_clock_find_source(chip, chip->ctrl_intf, fmt->clock); 250 int clock = snd_usb_clock_find_source(chip, fmt->clock);
255 251
256 if (clock < 0) 252 if (clock < 0)
257 return clock; 253 return clock;
diff --git a/sound/usb/clock.h b/sound/usb/clock.h
index beb253684e2d..46630936d31f 100644
--- a/sound/usb/clock.h
+++ b/sound/usb/clock.h
@@ -5,8 +5,6 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
5 struct usb_host_interface *alts, 5 struct usb_host_interface *alts,
6 struct audioformat *fmt, int rate); 6 struct audioformat *fmt, int rate);
7 7
8int snd_usb_clock_find_source(struct snd_usb_audio *chip, 8int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id);
9 struct usb_host_interface *host_iface,
10 int entity_id);
11 9
12#endif /* __USBAUDIO_CLOCK_H */ 10#endif /* __USBAUDIO_CLOCK_H */
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 2af0f9e3dcdf..1a701f1e8f50 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -33,6 +33,7 @@
33#include "pcm.h" 33#include "pcm.h"
34#include "helper.h" 34#include "helper.h"
35#include "format.h" 35#include "format.h"
36#include "clock.h"
36 37
37/* 38/*
38 * free a substream 39 * free a substream
diff --git a/sound/usb/format.c b/sound/usb/format.c
index 30364aba79cc..4387f54d73db 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -264,13 +264,12 @@ static int parse_uac2_sample_rate_range(struct audioformat *fp, int nr_triplets,
264 * on the audioformat table (audio class v2). 264 * on the audioformat table (audio class v2).
265 */ 265 */
266static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, 266static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
267 struct audioformat *fp, 267 struct audioformat *fp)
268 struct usb_host_interface *iface)
269{ 268{
270 struct usb_device *dev = chip->dev; 269 struct usb_device *dev = chip->dev;
271 unsigned char tmp[2], *data; 270 unsigned char tmp[2], *data;
272 int nr_triplets, data_size, ret = 0; 271 int nr_triplets, data_size, ret = 0;
273 int clock = snd_usb_clock_find_source(chip, chip->ctrl_intf, fp->clock); 272 int clock = snd_usb_clock_find_source(chip, fp->clock);
274 273
275 if (clock < 0) { 274 if (clock < 0) {
276 snd_printk(KERN_ERR "%s(): unable to find clock source (clock %d)\n", 275 snd_printk(KERN_ERR "%s(): unable to find clock source (clock %d)\n",
@@ -391,7 +390,7 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
391 break; 390 break;
392 case UAC_VERSION_2: 391 case UAC_VERSION_2:
393 /* fp->channels is already set in this case */ 392 /* fp->channels is already set in this case */
394 ret = parse_audio_format_rates_v2(chip, fp, iface); 393 ret = parse_audio_format_rates_v2(chip, fp);
395 break; 394 break;
396 } 395 }
397 396
@@ -450,7 +449,7 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
450 framesize = le16_to_cpu(fmt->wSamplesPerFrame); 449 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
451 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 450 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
452 fp->frame_size = framesize; 451 fp->frame_size = framesize;
453 ret = parse_audio_format_rates_v2(chip, fp, iface); 452 ret = parse_audio_format_rates_v2(chip, fp);
454 break; 453 break;
455 } 454 }
456 } 455 }
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 1163ec3ca8a0..035a77bd67a6 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -291,16 +291,15 @@ static int get_abs_value(struct usb_mixer_elem_info *cval, int val)
291 291
292static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret) 292static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
293{ 293{
294 struct snd_usb_audio *chip = cval->mixer->chip;
294 unsigned char buf[2]; 295 unsigned char buf[2];
295 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 296 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
296 int timeout = 10; 297 int timeout = 10;
297 298
298 while (timeout-- > 0) { 299 while (timeout-- > 0) {
299 if (snd_usb_ctl_msg(cval->mixer->chip->dev, 300 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request,
300 usb_rcvctrlpipe(cval->mixer->chip->dev, 0),
301 request,
302 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 301 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
303 validx, cval->mixer->ctrlif | (cval->id << 8), 302 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
304 buf, val_len, 100) >= val_len) { 303 buf, val_len, 100) >= val_len) {
305 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len)); 304 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
306 return 0; 305 return 0;
@@ -313,6 +312,7 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
313 312
314static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret) 313static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
315{ 314{
315 struct snd_usb_audio *chip = cval->mixer->chip;
316 unsigned char buf[2 + 3*sizeof(__u16)]; /* enough space for one range */ 316 unsigned char buf[2 + 3*sizeof(__u16)]; /* enough space for one range */
317 unsigned char *val; 317 unsigned char *val;
318 int ret, size; 318 int ret, size;
@@ -328,16 +328,14 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
328 328
329 memset(buf, 0, sizeof(buf)); 329 memset(buf, 0, sizeof(buf));
330 330
331 ret = snd_usb_ctl_msg(cval->mixer->chip->dev, 331 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest,
332 usb_rcvctrlpipe(cval->mixer->chip->dev, 0),
333 bRequest,
334 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 332 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
335 validx, cval->mixer->ctrlif | (cval->id << 8), 333 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
336 buf, size, 1000); 334 buf, size, 1000);
337 335
338 if (ret < 0) { 336 if (ret < 0) {
339 snd_printk(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n", 337 snd_printk(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
340 request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type); 338 request, validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), cval->val_type);
341 return ret; 339 return ret;
342 } 340 }
343 341
@@ -413,6 +411,7 @@ static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
413int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval, 411int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
414 int request, int validx, int value_set) 412 int request, int validx, int value_set)
415{ 413{
414 struct snd_usb_audio *chip = cval->mixer->chip;
416 unsigned char buf[2]; 415 unsigned char buf[2];
417 int val_len, timeout = 10; 416 int val_len, timeout = 10;
418 417
@@ -435,15 +434,14 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
435 buf[0] = value_set & 0xff; 434 buf[0] = value_set & 0xff;
436 buf[1] = (value_set >> 8) & 0xff; 435 buf[1] = (value_set >> 8) & 0xff;
437 while (timeout-- > 0) 436 while (timeout-- > 0)
438 if (snd_usb_ctl_msg(cval->mixer->chip->dev, 437 if (snd_usb_ctl_msg(chip->dev,
439 usb_sndctrlpipe(cval->mixer->chip->dev, 0), 438 usb_sndctrlpipe(chip->dev, 0), request,
440 request,
441 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 439 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
442 validx, cval->mixer->ctrlif | (cval->id << 8), 440 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
443 buf, val_len, 100) >= 0) 441 buf, val_len, 100) >= 0)
444 return 0; 442 return 0;
445 snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n", 443 snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n",
446 request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type, buf[0], buf[1]); 444 request, validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), cval->val_type, buf[0], buf[1]);
447 return -EINVAL; 445 return -EINVAL;
448} 446}
449 447
@@ -761,6 +759,8 @@ static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
761 */ 759 */
762static int get_min_max(struct usb_mixer_elem_info *cval, int default_min) 760static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
763{ 761{
762 struct snd_usb_audio *chip = cval->mixer->chip;
763
764 /* for failsafe */ 764 /* for failsafe */
765 cval->min = default_min; 765 cval->min = default_min;
766 cval->max = cval->min + 1; 766 cval->max = cval->min + 1;
@@ -783,7 +783,7 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
783 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 || 783 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 ||
784 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) { 784 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) {
785 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n", 785 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n",
786 cval->id, cval->mixer->ctrlif, cval->control, cval->id); 786 cval->id, snd_usb_ctrl_intf(chip), cval->control, cval->id);
787 return -EINVAL; 787 return -EINVAL;
788 } 788 }
789 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) { 789 if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) {
@@ -1913,7 +1913,7 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
1913 struct usb_host_interface *hostif; 1913 struct usb_host_interface *hostif;
1914 void *p; 1914 void *p;
1915 1915
1916 hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0]; 1916 hostif = mixer->chip->ctrl_intf;
1917 memset(&state, 0, sizeof(state)); 1917 memset(&state, 0, sizeof(state));
1918 state.chip = mixer->chip; 1918 state.chip = mixer->chip;
1919 state.mixer = mixer; 1919 state.mixer = mixer;
@@ -2005,7 +2005,7 @@ static void snd_usb_mixer_proc_read(struct snd_info_entry *entry,
2005 list_for_each_entry(mixer, &chip->mixer_list, list) { 2005 list_for_each_entry(mixer, &chip->mixer_list, list) {
2006 snd_iprintf(buffer, 2006 snd_iprintf(buffer,
2007 "USB Mixer: usb_id=0x%08x, ctrlif=%i, ctlerr=%i\n", 2007 "USB Mixer: usb_id=0x%08x, ctrlif=%i, ctlerr=%i\n",
2008 chip->usb_id, mixer->ctrlif, 2008 chip->usb_id, snd_usb_ctrl_intf(chip),
2009 mixer->ignore_ctl_error); 2009 mixer->ignore_ctl_error);
2010 snd_iprintf(buffer, "Card: %s\n", chip->card->longname); 2010 snd_iprintf(buffer, "Card: %s\n", chip->card->longname);
2011 for (unitid = 0; unitid < MAX_ID_ELEMS; unitid++) { 2011 for (unitid = 0; unitid < MAX_ID_ELEMS; unitid++) {
@@ -2123,7 +2123,7 @@ static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
2123 int buffer_length; 2123 int buffer_length;
2124 unsigned int epnum; 2124 unsigned int epnum;
2125 2125
2126 hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0]; 2126 hostif = mixer->chip->ctrl_intf;
2127 /* we need one interrupt input endpoint */ 2127 /* we need one interrupt input endpoint */
2128 if (get_iface_desc(hostif)->bNumEndpoints < 1) 2128 if (get_iface_desc(hostif)->bNumEndpoints < 1)
2129 return 0; 2129 return 0;
@@ -2166,7 +2166,6 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2166 if (!mixer) 2166 if (!mixer)
2167 return -ENOMEM; 2167 return -ENOMEM;
2168 mixer->chip = chip; 2168 mixer->chip = chip;
2169 mixer->ctrlif = ctrlif;
2170 mixer->ignore_ctl_error = ignore_error; 2169 mixer->ignore_ctl_error = ignore_error;
2171 mixer->id_elems = kcalloc(MAX_ID_ELEMS, sizeof(*mixer->id_elems), 2170 mixer->id_elems = kcalloc(MAX_ID_ELEMS, sizeof(*mixer->id_elems),
2172 GFP_KERNEL); 2171 GFP_KERNEL);
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index a7cf1007fbb0..26c636c5c93a 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -3,7 +3,6 @@
3 3
4struct usb_mixer_interface { 4struct usb_mixer_interface {
5 struct snd_usb_audio *chip; 5 struct snd_usb_audio *chip;
6 unsigned int ctrlif;
7 struct list_head list; 6 struct list_head list;
8 unsigned int ignore_ctl_error; 7 unsigned int ignore_ctl_error;
9 struct urb *urb; 8 struct urb *urb;
diff --git a/sound/usb/pcm.h b/sound/usb/pcm.h
index 1c931b68f3b5..ed3e283f618d 100644
--- a/sound/usb/pcm.h
+++ b/sound/usb/pcm.h
@@ -7,8 +7,5 @@ int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
7 struct usb_host_interface *alts, 7 struct usb_host_interface *alts,
8 struct audioformat *fmt); 8 struct audioformat *fmt);
9 9
10int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
11 struct usb_host_interface *alts,
12 struct audioformat *fmt, int rate);
13 10
14#endif /* __USBAUDIO_PCM_H */ 11#endif /* __USBAUDIO_PCM_H */
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index b45e54c09ba2..9a9da09586a5 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -32,6 +32,7 @@
32#include "helper.h" 32#include "helper.h"
33#include "endpoint.h" 33#include "endpoint.h"
34#include "pcm.h" 34#include "pcm.h"
35#include "clock.h"
35 36
36/* 37/*
37 * handle the quirks for the contained interfaces 38 * handle the quirks for the contained interfaces