ALSA: usbaudio: Expose usb device supported sample rates
Rahul Mittal [Mon, 3 Jun 2013 15:29:03 +0000 (20:29 +0530)]
Add alsa control for exposing sample rate range
supported by the usb audio device

Bug 1274264
Bug 1240790

Change-Id: I6b0c43416ad61009cd287f948210aca29b62c3fc
Signed-off-by: Rahul Mittal <rmittal@nvidia.com>
Reviewed-on: http://git-master/r/235030
(cherry picked from commit 3ee6a261731ca9d07e54c47923d338ca193dfed4)
Reviewed-on: http://git-master/r/236563
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Ravindra Lokhande <rlokhande@nvidia.com>
Reviewed-by: Sumit Bhattacharya <sumitb@nvidia.com>
Reviewed-by: Scott Peterson <speterson@nvidia.com>
GVS: Gerrit_Virtual_Submit

sound/usb/stream.c

index 7db2f89..44a5ff3 100644 (file)
@@ -461,6 +461,35 @@ static struct uac2_output_terminal_descriptor *
        return NULL;
 }
 
+static int usb_device_sample_rate_info(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 2;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = 192000;
+       return 0;
+}
+
+static int usb_device_sample_rate_get(struct snd_kcontrol *kcontrol,
+               struct snd_ctl_elem_value *ucontrol)
+{
+       struct audioformat *fp = snd_kcontrol_chip(kcontrol);
+
+       ucontrol->value.integer.value[0] = fp->rate_min;
+       ucontrol->value.integer.value[1] = fp->rate_max;
+
+       return 0;
+}
+
+struct snd_kcontrol_new usb_device_sample_rate_control = {
+       .access = SNDRV_CTL_ELEM_ACCESS_READ,
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "USB Device Sample Rate",
+       .info = usb_device_sample_rate_info,
+       .get = usb_device_sample_rate_get,
+};
+
 int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
 {
        struct usb_device *dev;
@@ -697,6 +726,11 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
                snd_usb_init_pitch(chip, iface_no, alts, fp);
                snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max);
        }
+
+       /* Add usb device sample rate control */
+       snd_ctl_add(chip->card,
+               snd_ctl_new1(&usb_device_sample_rate_control, fp));
+
        return 0;
 }