aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2011-11-20 10:22:24 -0500
committerTakashi Iwai <tiwai@suse.de>2012-07-16 04:02:10 -0400
commitb5b9eb546762c4015c67c31364a6ec6f83fd2ada (patch)
tree51915b26a33c7bafb68b9759856129798a403c8a
parent1464189f8c2a5341722437ef916786afaf241c44 (diff)
ALSA: tlv: compute TLV_*_ITEM lengths automatically
Add helper macros with a little bit of preprocessor magic to automatically compute the length of a TLV item. This lets us avoid having to compute this by hand, and will allow to use items that do not use a fixed length. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--include/sound/tlv.h20
1 files changed, 12 insertions, 8 deletions
diff --git a/include/sound/tlv.h b/include/sound/tlv.h
index 7067e2dfb0b9..137d1654e8d6 100644
--- a/include/sound/tlv.h
+++ b/include/sound/tlv.h
@@ -38,21 +38,26 @@
38#define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */ 38#define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */
39#define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */ 39#define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */
40 40
41#define TLV_ITEM(type, ...) \
42 (type), TLV_LENGTH(__VA_ARGS__), __VA_ARGS__
43#define TLV_LENGTH(...) \
44 ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
45
41#define TLV_DB_SCALE_MASK 0xffff 46#define TLV_DB_SCALE_MASK 0xffff
42#define TLV_DB_SCALE_MUTE 0x10000 47#define TLV_DB_SCALE_MUTE 0x10000
43#define TLV_DB_SCALE_ITEM(min, step, mute) \ 48#define TLV_DB_SCALE_ITEM(min, step, mute) \
44 SNDRV_CTL_TLVT_DB_SCALE, 2 * sizeof(unsigned int), \ 49 TLV_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
45 (min), ((step) & TLV_DB_SCALE_MASK) | ((mute) ? TLV_DB_SCALE_MUTE : 0) 50 (min), \
51 ((step) & TLV_DB_SCALE_MASK) | \
52 ((mute) ? TLV_DB_SCALE_MUTE : 0))
46#define DECLARE_TLV_DB_SCALE(name, min, step, mute) \ 53#define DECLARE_TLV_DB_SCALE(name, min, step, mute) \
47 unsigned int name[] = { TLV_DB_SCALE_ITEM(min, step, mute) } 54 unsigned int name[] = { TLV_DB_SCALE_ITEM(min, step, mute) }
48 55
49/* dB scale specified with min/max values instead of step */ 56/* dB scale specified with min/max values instead of step */
50#define TLV_DB_MINMAX_ITEM(min_dB, max_dB) \ 57#define TLV_DB_MINMAX_ITEM(min_dB, max_dB) \
51 SNDRV_CTL_TLVT_DB_MINMAX, 2 * sizeof(unsigned int), \ 58 TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB))
52 (min_dB), (max_dB)
53#define TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ 59#define TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
54 SNDRV_CTL_TLVT_DB_MINMAX_MUTE, 2 * sizeof(unsigned int), \ 60 TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB))
55 (min_dB), (max_dB)
56#define DECLARE_TLV_DB_MINMAX(name, min_dB, max_dB) \ 61#define DECLARE_TLV_DB_MINMAX(name, min_dB, max_dB) \
57 unsigned int name[] = { TLV_DB_MINMAX_ITEM(min_dB, max_dB) } 62 unsigned int name[] = { TLV_DB_MINMAX_ITEM(min_dB, max_dB) }
58#define DECLARE_TLV_DB_MINMAX_MUTE(name, min_dB, max_dB) \ 63#define DECLARE_TLV_DB_MINMAX_MUTE(name, min_dB, max_dB) \
@@ -60,8 +65,7 @@
60 65
61/* linear volume between min_dB and max_dB (.01dB unit) */ 66/* linear volume between min_dB and max_dB (.01dB unit) */
62#define TLV_DB_LINEAR_ITEM(min_dB, max_dB) \ 67#define TLV_DB_LINEAR_ITEM(min_dB, max_dB) \
63 SNDRV_CTL_TLVT_DB_LINEAR, 2 * sizeof(unsigned int), \ 68 TLV_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB))
64 (min_dB), (max_dB)
65#define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB) \ 69#define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB) \
66 unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) } 70 unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) }
67 71