[alsa-devel] [PATCH v4] ALSA: usb: Work around CM6631 sample rate change bug

Torstein Hegge hegge at resisty.net
Sun Mar 24 21:46:56 CET 2013


On Fri, Mar 22, 2013 at 16:32:19 +0100, Clemens Ladisch wrote:
> Torstein Hegge wrote:
> > +	if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
> > +				   USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
> > +				   UAC2_CS_CONTROL_SAM_FREQ << 8,
> > +				   snd_usb_ctrl_intf(chip) | (clock << 8),
> > +				   data, sizeof(data))) < 0) {
> > +		snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n",
> > +			   dev->devnum, iface, fmt->altsetting);
> > +		return err;
> > +	}
> 
> This code requires that all devices allow reading the sample rate.
> 
> When you cannot read the current rate, just assume it needs to be set.

Good point, read failure shouldn't have to be fatal, or cause
set_sample_rate_v2() to return before actually setting the sample rate. But
set_sample_rate_v2() already depends on being able to read the sample rate, and
will propagate errors back to snd_usb_pcm_prepare(), even if the returned rate
isn't used for anything except for a snd_printd.

On the other hand, set_sample_rate_v1() does
        return 0; /* some devices don't support reading */
when it fails to read the current rate.

Both the existing sample rate read and the sample rate read added by this patch
could be replaced by

        err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
                              UAC2_CS_CONTROL_SAM_FREQ << 8,
                              snd_usb_ctrl_intf(chip) | (clock << 8), 
                              data, sizeof(data));
        }
        if (err < 0) {
                snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n",
                           dev->devnum, iface, fmt->altsetting);
                cur_rate = 0;
        } else {
                cur_rate = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
        }


Torstein


More information about the Alsa-devel mailing list