xref: /openbmc/linux/include/uapi/sound/tlv.h (revision 8bd1369b)
1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2 /*
3  *   This program is free software; you can redistribute it and/or modify
4  *   it under the terms of the GNU General Public License as published by
5  *   the Free Software Foundation; either version 2 of the License, or
6  *   (at your option) any later version.
7  *
8  *   This program is distributed in the hope that it will be useful,
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *   GNU General Public License for more details.
12  */
13 
14 #ifndef __UAPI_SOUND_TLV_H
15 #define __UAPI_SOUND_TLV_H
16 
17 #define SNDRV_CTL_TLVT_CONTAINER 0	/* one level down - group of TLVs */
18 #define SNDRV_CTL_TLVT_DB_SCALE	1       /* dB scale */
19 #define SNDRV_CTL_TLVT_DB_LINEAR 2	/* linear volume */
20 #define SNDRV_CTL_TLVT_DB_RANGE 3	/* dB range container */
21 #define SNDRV_CTL_TLVT_DB_MINMAX 4	/* dB scale with min/max */
22 #define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5	/* dB scale with min/max with mute */
23 
24 /*
25  * channel-mapping TLV items
26  *  TLV length must match with num_channels
27  */
28 #define SNDRV_CTL_TLVT_CHMAP_FIXED	0x101	/* fixed channel position */
29 #define SNDRV_CTL_TLVT_CHMAP_VAR	0x102	/* channels freely swappable */
30 #define SNDRV_CTL_TLVT_CHMAP_PAIRED	0x103	/* pair-wise swappable */
31 
32 /*
33  * TLV structure is right behind the struct snd_ctl_tlv:
34  *   unsigned int type  	- see SNDRV_CTL_TLVT_*
35  *   unsigned int length
36  *   .... data aligned to sizeof(unsigned int), use
37  *        block_length = (length + (sizeof(unsigned int) - 1)) &
38  *                       ~(sizeof(unsigned int) - 1)) ....
39  */
40 #define SNDRV_CTL_TLVD_ITEM(type, ...) \
41 	(type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__
42 #define SNDRV_CTL_TLVD_LENGTH(...) \
43 	((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
44 
45 /* Accessor offsets for TLV data items */
46 #define SNDRV_CTL_TLVO_TYPE		0
47 #define SNDRV_CTL_TLVO_LEN		1
48 
49 #define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \
50 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__)
51 #define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \
52 	unsigned int name[] = { \
53 		SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \
54 	}
55 
56 #define SNDRV_CTL_TLVD_DB_SCALE_MASK	0xffff
57 #define SNDRV_CTL_TLVD_DB_SCALE_MUTE	0x10000
58 #define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
59 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
60 			    (min), \
61 			    ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \
62 			     ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0))
63 #define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \
64 	unsigned int name[] = { \
65 		SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
66 	}
67 
68 /* Accessor offsets for min, mute and step items in dB scale type TLV */
69 #define SNDRV_CTL_TLVO_DB_SCALE_MIN		2
70 #define SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP	3
71 
72 /* dB scale specified with min/max values instead of step */
73 #define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
74 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB))
75 #define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
76 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB))
77 #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \
78 	unsigned int name[] = { \
79 		SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
80 	}
81 #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \
82 	unsigned int name[] = { \
83 		SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
84 	}
85 
86 /* Accessor offsets for min, max items in db-minmax types of TLV. */
87 #define SNDRV_CTL_TLVO_DB_MINMAX_MIN	2
88 #define SNDRV_CTL_TLVO_DB_MINMAX_MAX	3
89 
90 /* linear volume between min_dB and max_dB (.01dB unit) */
91 #define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
92 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB))
93 #define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \
94 	unsigned int name[] = { \
95 		SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
96 	}
97 
98 /* Accessor offsets for min, max items in db-linear type of TLV. */
99 #define SNDRV_CTL_TLVO_DB_LINEAR_MIN	2
100 #define SNDRV_CTL_TLVO_DB_LINEAR_MAX	3
101 
102 /* dB range container:
103  * Items in dB range container must be ordered by their values and by their
104  * dB values. This implies that larger values must correspond with larger
105  * dB values (which is also required for all other mixer controls).
106  */
107 /* Each item is: <min> <max> <TLV> */
108 #define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \
109 	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
110 #define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \
111 	unsigned int name[] = { \
112 		SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \
113 	}
114 
115 #define SNDRV_CTL_TLVD_DB_GAIN_MUTE	-9999999
116 
117 #endif
118