diff options
author | Takashi Iwai <tiwai@suse.de> | 2013-04-03 13:08:29 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2013-04-03 13:08:29 -0400 |
commit | 7c51746517e46806c59da6d780e7a14e8ae2bf78 (patch) | |
tree | 2bf23205e1d0557b623bff95e6a86ef80d443dc0 /sound/usb | |
parent | efc33ce197e4b6aaddf1eb2ba6293f51daf3c283 (diff) |
ALSA: usb-audio: Clean up the code in set_sample_rate_v2()
Just for cleaning up, introduce a new function get_sample_rate_v2()
for replacing two identical calls in set_sample_rate_v2().
No functional change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb')
-rw-r--r-- | sound/usb/clock.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/sound/usb/clock.c b/sound/usb/clock.c index 9e2703a25156..e3ccf3d81075 100644 --- a/sound/usb/clock.c +++ b/sound/usb/clock.c | |||
@@ -247,6 +247,27 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, | |||
247 | return 0; | 247 | return 0; |
248 | } | 248 | } |
249 | 249 | ||
250 | static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface, | ||
251 | int altsetting, int clock) | ||
252 | { | ||
253 | struct usb_device *dev = chip->dev; | ||
254 | unsigned char data[4]; | ||
255 | int err; | ||
256 | |||
257 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, | ||
258 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | ||
259 | UAC2_CS_CONTROL_SAM_FREQ << 8, | ||
260 | snd_usb_ctrl_intf(chip) | (clock << 8), | ||
261 | data, sizeof(data)); | ||
262 | if (err < 0) { | ||
263 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", | ||
264 | dev->devnum, iface, altsetting); | ||
265 | return 0; | ||
266 | } | ||
267 | |||
268 | return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); | ||
269 | } | ||
270 | |||
250 | static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, | 271 | static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, |
251 | struct usb_host_interface *alts, | 272 | struct usb_host_interface *alts, |
252 | struct audioformat *fmt, int rate) | 273 | struct audioformat *fmt, int rate) |
@@ -266,18 +287,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, | |||
266 | return -ENXIO; | 287 | return -ENXIO; |
267 | } | 288 | } |
268 | 289 | ||
269 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, | 290 | prev_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); |
270 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | ||
271 | UAC2_CS_CONTROL_SAM_FREQ << 8, | ||
272 | snd_usb_ctrl_intf(chip) | (clock << 8), | ||
273 | data, sizeof(data)); | ||
274 | if (err < 0) { | ||
275 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", | ||
276 | dev->devnum, iface, fmt->altsetting); | ||
277 | prev_rate = 0; | ||
278 | } else { | ||
279 | prev_rate = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); | ||
280 | } | ||
281 | 291 | ||
282 | data[0] = rate; | 292 | data[0] = rate; |
283 | data[1] = rate >> 8; | 293 | data[1] = rate >> 8; |
@@ -293,18 +303,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, | |||
293 | return err; | 303 | return err; |
294 | } | 304 | } |
295 | 305 | ||
296 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, | 306 | cur_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); |
297 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, | ||
298 | UAC2_CS_CONTROL_SAM_FREQ << 8, | ||
299 | snd_usb_ctrl_intf(chip) | (clock << 8), | ||
300 | data, sizeof(data)); | ||
301 | if (err < 0) { | ||
302 | snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", | ||
303 | dev->devnum, iface, fmt->altsetting); | ||
304 | cur_rate = 0; | ||
305 | } else { | ||
306 | cur_rate = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); | ||
307 | } | ||
308 | 307 | ||
309 | if (cur_rate != rate) { | 308 | if (cur_rate != rate) { |
310 | snd_printd(KERN_WARNING | 309 | snd_printd(KERN_WARNING |