Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Torstein Hegge <hegge@resisty.net>
To: Eldad Zack <eldad@fogrefinery.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	alsa-devel@alsa-project.org, Daniel Mack <zonque@gmail.com>,
	Clemens Ladisch <clemens@ladisch.de>
Subject: Re: [PATCH 10/10] ALSA: usb-audio: UAC2: support read-only freq control
Date: Mon, 1 Apr 2013 10:17:21 +0200	[thread overview]
Message-ID: <20130401081721.GI18838@pvv.ntnu.no> (raw)
In-Reply-To: <1364745152-1762-11-git-send-email-eldad@fogrefinery.com>

On Sun, Mar 31, 2013 at 17:52:32 +0200, Eldad Zack wrote:
> Some clocks might be read-only, e.g., external clocks (see also
> UAC2 4.7.2.1).
> 
> In this case, setting the sample frequency will always fail
> (even if the rate is equal to the current clock rate),
> therefore do not write, but read the value and compare to the
> requested rate.
> 
> If it doesn't match, return -ENXIO since the clock is invalid for
> this configuration.

I think could be more readable if it was built on top of [1]. Then it
could check the target rate against the prev_rate reported by the device
and return before the sample rate set, something like:

diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index 9e2703a..395327c 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -254,18 +254,14 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
 	struct usb_device *dev = chip->dev;
 	unsigned char data[4];
 	int err, cur_rate, prev_rate;
-	int clock = snd_usb_clock_find_source(chip, fmt->clock);
+	int clock;
+	bool writeable;
+	struct uac_clock_source_descriptor *cs_desc;
 
+	clock = snd_usb_clock_find_source(chip, fmt->clock, true);
 	if (clock < 0)
 		return clock;
 
-	if (!uac_clock_source_is_valid(chip, clock)) {
-		/* TODO: should we try to find valid clock setups by ourself? */
-		snd_printk(KERN_ERR "%d:%d:%d: clock source %d is not valid, cannot use\n",
-			   dev->devnum, iface, fmt->altsetting, clock);
-		return -ENXIO;
-	}
-
 	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,
@@ -279,6 +275,20 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
 		prev_rate = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
 	}
 
+	cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, clock);
+	writeable = uac2_control_is_writeable(cs_desc->bmControls, UAC2_CS_CONTROL_SAM_FREQ - 1);
+	if (!writeable) {
+		if (prev_rate != rate) {
+			snd_printk(KERN_WARNING
+				"%d:%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
+				dev->devnum, iface, fmt->altsetting, rate, crate);
+			return -ENXIO;
+		}
+		else {
+			return 0;
+		}
+	}
+
 	data[0] = rate;
 	data[1] = rate >> 8;
 	data[2] = rate >> 16;

+ the other changes from the rest of your patch series.

[1] http://thread.gmane.org/gmane.linux.alsa.devel/106773

> +		err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
> +					   USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
> +					   UAC2_CS_CONTROL_SAM_FREQ << 8,
> +					   snd_usb_ctrl_intf(chip) | (clock << 8),
> +					   &data, sizeof(data));

Is the indentation here intentional?

> -	if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
> +	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(rate))) < 0) {
> +				   &data, sizeof(rate));

Same formatting comment as above.

> +	if (crate != rate) {
> +		if (!writeable) {
> +			snd_printk(KERN_WARNING "%d:%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
> +				dev->devnum, iface, fmt->altsetting, rate, crate);
> +			return -ENXIO;
> +		}
>  		snd_printd(KERN_WARNING "current rate %d is different from the runtime rate %d\n", crate, rate);
> +	}

This bit didn't read very well on a narrow terminal.


Torstein

  reply	other threads:[~2013-04-01  8:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-31 15:52 [PATCH 00/10] UAC2: Automatic clock switching Eldad Zack
2013-03-31 15:52 ` [PATCH 01/10] ALSA: usb-audio: convert list_for_each to entry variant Eldad Zack
2013-03-31 15:52 ` [PATCH 02/10] ALSA: usb-audio: neaten MODULE_DEVICE_TABLE placement Eldad Zack
2013-03-31 15:52 ` [PATCH 03/10] ALSA: usb-audio: neaten EXPORT_SYMBOLS placement Eldad Zack
2013-03-31 15:52 ` [PATCH 04/10] ALSA: usb-audio: spelling correction Eldad Zack
2013-03-31 15:52 ` [PATCH 05/10] ALSA: usb-audio: use endianness macros Eldad Zack
2013-03-31 16:06   ` Clemens Ladisch
2013-03-31 17:15     ` Eldad Zack
2013-03-31 17:30       ` Clemens Ladisch
2013-04-05 18:36         ` Eldad Zack
2013-03-31 15:52 ` [PATCH 06/10] ALSA: usb-audio: UAC2: do clock validity check earlier Eldad Zack
2013-04-01  8:16   ` Torstein Hegge
2013-04-01 22:36     ` Eldad Zack
2013-04-02  8:38   ` Takashi Iwai
2013-03-31 15:52 ` [PATCH 07/10] ALSA: usb-audio: UAC2: try to find and switch to valid clock Eldad Zack
2013-04-02  8:46   ` Takashi Iwai
2013-04-02 20:20     ` Eldad Zack
2013-03-31 15:52 ` [PATCH 08/10] ALSA: usb-audio: UAC2: auto clock selection module param Eldad Zack
2013-04-02  8:51   ` Takashi Iwai
2013-04-02 20:27     ` Eldad Zack
2013-03-31 15:52 ` [PATCH 09/10] ALSA: usb-audio: show err in set_sample_rate_v2 debug Eldad Zack
2013-03-31 15:52 ` [PATCH 10/10] ALSA: usb-audio: UAC2: support read-only freq control Eldad Zack
2013-04-01  8:17   ` Torstein Hegge [this message]
2013-04-01 22:45     ` Eldad Zack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130401081721.GI18838@pvv.ntnu.no \
    --to=hegge@resisty.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=eldad@fogrefinery.com \
    --cc=tiwai@suse.de \
    --cc=zonque@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox