2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
13 #ifndef __UAPI_SOUND_TLV_H
14 #define __UAPI_SOUND_TLV_H
16 #define SNDRV_CTL_TLVT_CONTAINER 0 /* one level down - group of TLVs */
17 #define SNDRV_CTL_TLVT_DB_SCALE 1 /* dB scale */
18 #define SNDRV_CTL_TLVT_DB_LINEAR 2 /* linear volume */
19 #define SNDRV_CTL_TLVT_DB_RANGE 3 /* dB range container */
20 #define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */
21 #define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */
24 * channel-mapping TLV items
25 * TLV length must match with num_channels
27 #define SNDRV_CTL_TLVT_CHMAP_FIXED 0x101 /* fixed channel position */
28 #define SNDRV_CTL_TLVT_CHMAP_VAR 0x102 /* channels freely swappable */
29 #define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103 /* pair-wise swappable */
32 * TLV structure is right behind the struct snd_ctl_tlv:
33 * unsigned int type - see SNDRV_CTL_TLVT_*
35 * .... data aligned to sizeof(unsigned int), use
36 * block_length = (length + (sizeof(unsigned int) - 1)) &
37 * ~(sizeof(unsigned int) - 1)) ....
39 #define TLV_ITEM(type, ...) \
40 (type), TLV_LENGTH(__VA_ARGS__), __VA_ARGS__
41 #define TLV_LENGTH(...) \
42 ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
44 #define TLV_CONTAINER_ITEM(...) \
45 TLV_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__)
46 #define DECLARE_TLV_CONTAINER(name, ...) \
47 unsigned int name[] = { TLV_CONTAINER_ITEM(__VA_ARGS__) }
49 #define TLV_DB_SCALE_MASK 0xffff
50 #define TLV_DB_SCALE_MUTE 0x10000
51 #define TLV_DB_SCALE_ITEM(min, step, mute) \
52 TLV_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
54 ((step) & TLV_DB_SCALE_MASK) | \
55 ((mute) ? TLV_DB_SCALE_MUTE : 0))
56 #define DECLARE_TLV_DB_SCALE(name, min, step, mute) \
57 unsigned int name[] = { TLV_DB_SCALE_ITEM(min, step, mute) }
59 /* dB scale specified with min/max values instead of step */
60 #define TLV_DB_MINMAX_ITEM(min_dB, max_dB) \
61 TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB))
62 #define TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
63 TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB))
64 #define DECLARE_TLV_DB_MINMAX(name, min_dB, max_dB) \
65 unsigned int name[] = { TLV_DB_MINMAX_ITEM(min_dB, max_dB) }
66 #define DECLARE_TLV_DB_MINMAX_MUTE(name, min_dB, max_dB) \
67 unsigned int name[] = { TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) }
69 /* linear volume between min_dB and max_dB (.01dB unit) */
70 #define TLV_DB_LINEAR_ITEM(min_dB, max_dB) \
71 TLV_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB))
72 #define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB) \
73 unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) }
75 /* dB range container:
76 * Items in dB range container must be ordered by their values and by their
77 * dB values. This implies that larger values must correspond with larger
78 * dB values (which is also required for all other mixer controls).
80 /* Each item is: <min> <max> <TLV> */
81 #define TLV_DB_RANGE_ITEM(...) \
82 TLV_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
83 #define DECLARE_TLV_DB_RANGE(name, ...) \
84 unsigned int name[] = { TLV_DB_RANGE_ITEM(__VA_ARGS__) }
85 /* The below assumes that each item TLV is 4 words like DB_SCALE or LINEAR */
86 #define TLV_DB_RANGE_HEAD(num) \
87 SNDRV_CTL_TLVT_DB_RANGE, 6 * (num) * sizeof(unsigned int)
89 #define TLV_DB_GAIN_MUTE -9999999