Commit dcbe7bcf authored by Daniel Mack's avatar Daniel Mack Committed by Takashi Iwai

ALSA: usb-audio: UAC2: clean up parsing of bmaControls

Introduce two new static inline functions for a more readable parsing
of UAC2 bmaControls.
Signed-off-by: default avatarDaniel Mack <daniel@caiaq.de>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 67a3e12b
...@@ -18,6 +18,16 @@ ...@@ -18,6 +18,16 @@
/* v1.0 and v2.0 of this standard have many things in common. For the rest /* v1.0 and v2.0 of this standard have many things in common. For the rest
* of the definitions, please refer to audio.h */ * 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 */ /* 4.7.2.1 Clock Source Descriptor */
struct uac_clock_source_descriptor { struct uac_clock_source_descriptor {
......
...@@ -1188,9 +1188,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void ...@@ -1188,9 +1188,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
for (j = 0; j < channels; j++) { for (j = 0; j < channels; j++) {
unsigned int mask = snd_usb_combine_bytes(bmaControls + csize * (j+1), csize); 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); ch_bits |= (1 << j);
if (~mask & (1 << ((i * 2) + 1))) if (!uac2_control_is_writeable(mask, i))
ch_read_only |= (1 << j); ch_read_only |= (1 << j);
} }
} }
...@@ -1198,9 +1198,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void ...@@ -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 */ /* 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) */ 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); 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, build_feature_ctl(state, _ftr, 0, i, &iterm, unitid,
~master_bits & (1 << ((i * 2) + 1))); !uac2_control_is_writeable(master_bits, i));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment