alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Mack <zonque@gmail.com>
To: alsa-devel@alsa-project.org
Cc: gdiffey@gmail.com, tiwai@suse.de, clemens@ladisch.de,
	linuxaudio@showlabor.de, Daniel Mack <zonque@gmail.com>,
	blablack@gmail.com
Subject: [PATCH 5/6] ALSA: snd-usb: add support for implicit feedback
Date: Fri, 23 Dec 2011 17:15:46 +0100	[thread overview]
Message-ID: <1324656947-23169-6-git-send-email-zonque@gmail.com> (raw)
In-Reply-To: <1324656947-23169-1-git-send-email-zonque@gmail.com>

Implicit feedback is a streaming mode that does not rely on dedicated
sync endpoints but uses the information provided by record streams to
clock output streams. Now that the streaming logic is decoupled from the
PCM streams, this is easy to implement.

Signed-off-by: Daniel Mack <zonque@gmail.com>
---
 sound/usb/pcm.c |   37 ++++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 271579c..69cc912 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -300,7 +300,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
 	struct usb_interface *iface;
 	unsigned int ep, attr;
 	int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
-	int err;
+	int err, implicit_fb = 0;
 
 	iface = usb_ifnum_to_if(dev, fmt->iface);
 	if (WARN_ON(!iface))
@@ -325,25 +325,34 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
 	 * assume it as adaptive-out or sync-in.
 	 */
 	attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE;
-	if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) ||
-	     (! is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) &&
-	    altsd->bNumEndpoints >= 2) {
-		switch (subs->stream->chip->usb_id) {
-		case USB_ID(0x0763, 0x2080): /* M-Audio FastTrack Ultra */
-		case USB_ID(0x0763, 0x2081):
+
+	switch (subs->stream->chip->usb_id) {
+	case USB_ID(0x0763, 0x2080): /* M-Audio FastTrack Ultra */
+	case USB_ID(0x0763, 0x2081):
+		if (is_playback) {
+			implicit_fb = 1;
 			ep = 0x81;
 			iface = usb_ifnum_to_if(dev, 2);
+
+			if (!iface || iface->num_altsetting == 0)
+				return -EINVAL;
+
 			alts = &iface->altsetting[1];
 			goto add_sync_ep;
 		}
+	}
 
+	if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) ||
+	     (!is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) &&
+	    altsd->bNumEndpoints >= 2) {
 		/* check sync-pipe endpoint */
 		/* ... and check descriptor size before accessing bSynchAddress
 		   because there is a version of the SB Audigy 2 NX firmware lacking
 		   the audio fields in the endpoint descriptors */
 		if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 0x01 ||
 		    (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
-		     get_endpoint(alts, 1)->bSynchAddress != 0)) {
+		     get_endpoint(alts, 1)->bSynchAddress != 0 &&
+		     !implicit_fb)) {
 			snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n",
 				   dev->devnum, fmt->iface, fmt->altsetting);
 			return -EINVAL;
@@ -351,16 +360,22 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
 		ep = get_endpoint(alts, 1)->bEndpointAddress;
 		if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
 		    (( is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) ||
-		     (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)))) {
+		     (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)) ||
+		     ( is_playback && !implicit_fb))) {
 			snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n",
 				   dev->devnum, fmt->iface, fmt->altsetting);
 			return -EINVAL;
 		}
+
+		implicit_fb = (get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_USAGE_MASK)
+				== USB_ENDPOINT_USAGE_IMPLICIT_FB;
+
 add_sync_ep:
 		subs->sync_endpoint = snd_usb_add_endpoint(subs->stream->chip,
 							   alts, ep, !subs->direction,
-							   SND_USB_ENDPOINT_TYPE_SYNC);
-
+							   implicit_fb ?
+								SND_USB_ENDPOINT_TYPE_DATA :
+								SND_USB_ENDPOINT_TYPE_SYNC);
 		if (!subs->sync_endpoint)
 			return -EINVAL;
 
-- 
1.7.7.4

  parent reply	other threads:[~2011-12-23 16:16 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-23 16:15 [PATCH 0/6] snd-usb endpoint rework, version 6 Daniel Mack
2011-12-23 16:15 ` [PATCH 1/6] ALSA: snd-usb: add snd_usb_audio-wide mutex Daniel Mack
2011-12-23 16:15 ` [PATCH 2/6] ALSA: snd-usb: implement new endpoint streaming model Daniel Mack
2011-12-23 16:15 ` [PATCH 3/6] ALSA: snd-usb: switch over to new endpoint streaming logic Daniel Mack
2011-12-23 16:15 ` [PATCH 4/6] ALSA: snd-usb: remove old " Daniel Mack
2011-12-23 16:15 ` Daniel Mack [this message]
2011-12-23 16:15 ` [PATCH 6/6] ALSA: snd-usb: add some documentation Daniel Mack
2011-12-30 13:56 ` [PATCH 0/6] snd-usb endpoint rework, version 6 Daniel Mack
2011-12-30 15:22   ` Felix Homann
     [not found]   ` <CAFz=ag6XNJSXvYQnAEbx=M+zXVH7sEw=_CJQKx63MmdQBWFuwA@mail.gmail.com>
2011-12-30 15:24     ` Daniel Mack
     [not found]       ` <CACckToWP-C5H2xhvdJ5ykNf4BcuNCa4cMyFh2hppcwW0u33fQQ@mail.gmail.com>
     [not found]         ` <4EFE6E52.4050503@gmail.com>
2011-12-31  4:35           ` Grant Diffey
2011-12-31  8:04             ` Grant Diffey
2011-12-31 14:23   ` Felix Homann
2011-12-31 15:02     ` Aurélien Leblond
2011-12-31 15:39       ` Felix Homann
     [not found]   ` <CAFz=ag7_qzPJq44havp=EbFVKud5VvKaOLJk0i0dM43X3urp9Q@mail.gmail.com>
2012-01-01 17:09     ` Felix Homann
2012-01-16 20:26       ` Grant Diffey
2012-01-16 20:27         ` Grant Diffey
2012-04-09 19:21         ` Daniel Mack
2012-04-10 15:35           ` Grant Diffey
2012-04-10 18:52           ` Felix Homann
2012-04-11 15:08             ` Daniel Mack
2012-04-12  9:05               ` Felix Homann
2012-04-12 11:45                 ` Daniel Mack
2012-04-10 15:40       ` Grant Diffey
  -- strict thread matches above, loose matches on Subject: below --
2012-04-12 11:51 [PATCH 0/6] snd-usb endpoint rework, version 7 Daniel Mack
2012-04-12 11:51 ` [PATCH 5/6] ALSA: snd-usb: add support for implicit feedback Daniel Mack

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=1324656947-23169-6-git-send-email-zonque@gmail.com \
    --to=zonque@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=blablack@gmail.com \
    --cc=clemens@ladisch.de \
    --cc=gdiffey@gmail.com \
    --cc=linuxaudio@showlabor.de \
    --cc=tiwai@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).