xref: /linux/include/uapi/sound/tlv.h (revision f3a8b6645dc2e60d11f20c1c23afd964ff4e55ae)
1 /*
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.
6  *
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.
11  */
12 
13 #ifndef __UAPI_SOUND_TLV_H
14 #define __UAPI_SOUND_TLV_H
15 
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 */
22 
23 /*
24  * channel-mapping TLV items
25  *  TLV length must match with num_channels
26  */
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 */
30 
31 /*
32  * TLV structure is right behind the struct snd_ctl_tlv:
33  *   unsigned int type  	- see SNDRV_CTL_TLVT_*
34  *   unsigned int length
35  *   .... data aligned to sizeof(unsigned int), use
36  *        block_length = (length + (sizeof(unsigned int) - 1)) &
37  *                       ~(sizeof(unsigned int) - 1)) ....
38  */
39 #define SNDRV_CTL_TLVD_ITEM(type, ...) \
40 	(type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__
41 #define SNDRV_CTL_TLVD_LENGTH(...) \
42 	((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
43 
44 #define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \
45 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__)
46 #define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \
47 	unsigned int name[] = { \
48 		SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \
49 	}
50 
51 #define SNDRV_CTL_TLVD_DB_SCALE_MASK	0xffff
52 #define SNDRV_CTL_TLVD_DB_SCALE_MUTE	0x10000
53 #define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
54 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
55 			    (min), \
56 			    ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \
57 			     ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0))
58 #define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \
59 	unsigned int name[] = { \
60 		SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
61 	}
62 
63 /* dB scale specified with min/max values instead of step */
64 #define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
65 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB))
66 #define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
67 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB))
68 #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \
69 	unsigned int name[] = { \
70 		SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
71 	}
72 #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \
73 	unsigned int name[] = { \
74 		SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
75 	}
76 
77 /* linear volume between min_dB and max_dB (.01dB unit) */
78 #define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
79 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB))
80 #define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \
81 	unsigned int name[] = { \
82 		SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
83 	}
84 
85 /* dB range container:
86  * Items in dB range container must be ordered by their values and by their
87  * dB values. This implies that larger values must correspond with larger
88  * dB values (which is also required for all other mixer controls).
89  */
90 /* Each item is: <min> <max> <TLV> */
91 #define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \
92 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
93 #define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \
94 	unsigned int name[] = { \
95 		SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \
96 	}
97 
98 #define SNDRV_CTL_TLVD_DB_GAIN_MUTE	-9999999
99 
100 #endif
101