alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Mack <daniel@caiaq.de>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, gregkh@suse.de, clemens@ladisch.de
Subject: [PATCH 1/9] ALSA: usb-audio: UAC2: clean up parsing of bmaControls
Date: Mon, 31 May 2010 13:35:36 +0200	[thread overview]
Message-ID: <1275305744-6590-1-git-send-email-daniel@caiaq.de> (raw)

Introduce two new static inline functions for a more readable parsing
of UAC2 bmaControls.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
---
 include/linux/usb/audio-v2.h |   10 ++++++++++
 sound/usb/mixer.c            |    8 ++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/linux/usb/audio-v2.h b/include/linux/usb/audio-v2.h
index 92f1d99..8f91be3 100644
--- a/include/linux/usb/audio-v2.h
+++ b/include/linux/usb/audio-v2.h
@@ -18,6 +18,16 @@
 /* v1.0 and v2.0 of this standard have many things in common. For the rest
  * of the definitions, please refer to audio.h */
 
+static inline bool uac2_control_is_readable(u32 bmControls, u8 control)
+{
+	return (bmControls >> (control * 2)) & 0x1;
+}
+
+static inline bool uac2_control_is_writeable(u32 bmControls, u8 control)
+{
+	return (bmControls >> (control * 2)) & 0x2;
+}
+
 /* 4.7.2.1 Clock Source Descriptor */
 
 struct uac_clock_source_descriptor {
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 03ce971..43d6417 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1188,9 +1188,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
 
 			for (j = 0; j < channels; j++) {
 				unsigned int mask = snd_usb_combine_bytes(bmaControls + csize * (j+1), csize);
-				if (mask & (1 << (i * 2))) {
+				if (uac2_control_is_readable(mask, i)) {
 					ch_bits |= (1 << j);
-					if (~mask & (1 << ((i * 2) + 1)))
+					if (!uac2_control_is_writeable(mask, i))
 						ch_read_only |= (1 << j);
 				}
 			}
@@ -1198,9 +1198,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
 			/* FIXME: the whole unit is read-only if any of the channels is marked read-only */
 			if (ch_bits & 1) /* the first channel must be set (for ease of programming) */
 				build_feature_ctl(state, _ftr, ch_bits, i, &iterm, unitid, !!ch_read_only);
-			if (master_bits & (1 << i * 2))
+			if (uac2_control_is_readable(master_bits, i))
 				build_feature_ctl(state, _ftr, 0, i, &iterm, unitid,
-						  ~master_bits & (1 << ((i * 2) + 1)));
+						  !uac2_control_is_writeable(master_bits, i));
 		}
 	}
 
-- 
1.7.1

             reply	other threads:[~2010-05-31 11:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-31 11:35 Daniel Mack [this message]
2010-05-31 11:35 ` [PATCH 2/9] ALSA: usb-audio: support partially write-protected UAC2 controls Daniel Mack
2010-05-31 11:35 ` [PATCH 3/9] include/linux/usb/audio-v2.h: add more UAC2 details Daniel Mack
2010-05-31 11:35 ` [PATCH 4/9] ALSA: usb-audio: fix selector unit string index accessor Daniel Mack
2010-05-31 11:35 ` [PATCH 5/9] ALSA: usb-audio: parse clock topology of UAC2 devices Daniel Mack
2010-05-31 12:51   ` Daniel Mack
2010-05-31 11:35 ` [PATCH 6/9] ALSA: usb-audio: unify constants from specification Daniel Mack
2010-05-31 11:35 ` [PATCH 7/9] ALSA: usb-audio: add UAC2 sepecific Feature Unit controls Daniel Mack
2010-05-31 11:35 ` [PATCH 8/9] ALSA: usb-audio: clean up find_audio_control_unit() Daniel Mack
2010-05-31 11:35 ` [PATCH 9/9] ALSA: usb-audio: export UAC2 clock selectors as mixer controls Daniel Mack
2010-05-31 16:35 ` [PATCH 1/9] ALSA: usb-audio: UAC2: clean up parsing of bmaControls Takashi Iwai
2010-05-31 16:47   ` Daniel Mack
2010-05-31 20:35     ` Takashi Iwai

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=1275305744-6590-1-git-send-email-daniel@caiaq.de \
    --to=daniel@caiaq.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=gregkh@suse.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).