18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *   This program is free software; you can redistribute it and/or modify
48c2ecf20Sopenharmony_ci *   it under the terms of the GNU General Public License as published by
58c2ecf20Sopenharmony_ci *   the Free Software Foundation; either version 2 of the License, or
68c2ecf20Sopenharmony_ci *   (at your option) any later version.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *   This program is distributed in the hope that it will be useful,
98c2ecf20Sopenharmony_ci *   but WITHOUT ANY WARRANTY; without even the implied warranty of
108c2ecf20Sopenharmony_ci *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
118c2ecf20Sopenharmony_ci *   GNU General Public License for more details.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef __UAPI_SOUND_TLV_H
158c2ecf20Sopenharmony_ci#define __UAPI_SOUND_TLV_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_CONTAINER 0	/* one level down - group of TLVs */
188c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_DB_SCALE	1       /* dB scale */
198c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_DB_LINEAR 2	/* linear volume */
208c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_DB_RANGE 3	/* dB range container */
218c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_DB_MINMAX 4	/* dB scale with min/max */
228c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5	/* dB scale with min/max with mute */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * channel-mapping TLV items
268c2ecf20Sopenharmony_ci *  TLV length must match with num_channels
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_CHMAP_FIXED	0x101	/* fixed channel position */
298c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_CHMAP_VAR	0x102	/* channels freely swappable */
308c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVT_CHMAP_PAIRED	0x103	/* pair-wise swappable */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/*
338c2ecf20Sopenharmony_ci * TLV structure is right behind the struct snd_ctl_tlv:
348c2ecf20Sopenharmony_ci *   unsigned int type  	- see SNDRV_CTL_TLVT_*
358c2ecf20Sopenharmony_ci *   unsigned int length
368c2ecf20Sopenharmony_ci *   .... data aligned to sizeof(unsigned int), use
378c2ecf20Sopenharmony_ci *        block_length = (length + (sizeof(unsigned int) - 1)) &
388c2ecf20Sopenharmony_ci *                       ~(sizeof(unsigned int) - 1)) ....
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_ITEM(type, ...) \
418c2ecf20Sopenharmony_ci	(type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__
428c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_LENGTH(...) \
438c2ecf20Sopenharmony_ci	((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* Accessor offsets for TLV data items */
468c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVO_TYPE		0
478c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVO_LEN		1
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \
508c2ecf20Sopenharmony_ci	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__)
518c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \
528c2ecf20Sopenharmony_ci	unsigned int name[] = { \
538c2ecf20Sopenharmony_ci		SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DB_SCALE_MASK	0xffff
578c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DB_SCALE_MUTE	0x10000
588c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
598c2ecf20Sopenharmony_ci	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
608c2ecf20Sopenharmony_ci			    (min), \
618c2ecf20Sopenharmony_ci			    ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \
628c2ecf20Sopenharmony_ci			     ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0))
638c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \
648c2ecf20Sopenharmony_ci	unsigned int name[] = { \
658c2ecf20Sopenharmony_ci		SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
668c2ecf20Sopenharmony_ci	}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* Accessor offsets for min, mute and step items in dB scale type TLV */
698c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVO_DB_SCALE_MIN		2
708c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP	3
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* dB scale specified with min/max values instead of step */
738c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
748c2ecf20Sopenharmony_ci	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB))
758c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
768c2ecf20Sopenharmony_ci	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB))
778c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \
788c2ecf20Sopenharmony_ci	unsigned int name[] = { \
798c2ecf20Sopenharmony_ci		SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
808c2ecf20Sopenharmony_ci	}
818c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \
828c2ecf20Sopenharmony_ci	unsigned int name[] = { \
838c2ecf20Sopenharmony_ci		SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
848c2ecf20Sopenharmony_ci	}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/* Accessor offsets for min, max items in db-minmax types of TLV. */
878c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVO_DB_MINMAX_MIN	2
888c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVO_DB_MINMAX_MAX	3
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* linear volume between min_dB and max_dB (.01dB unit) */
918c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
928c2ecf20Sopenharmony_ci	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB))
938c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \
948c2ecf20Sopenharmony_ci	unsigned int name[] = { \
958c2ecf20Sopenharmony_ci		SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
968c2ecf20Sopenharmony_ci	}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* Accessor offsets for min, max items in db-linear type of TLV. */
998c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVO_DB_LINEAR_MIN	2
1008c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVO_DB_LINEAR_MAX	3
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/* dB range container:
1038c2ecf20Sopenharmony_ci * Items in dB range container must be ordered by their values and by their
1048c2ecf20Sopenharmony_ci * dB values. This implies that larger values must correspond with larger
1058c2ecf20Sopenharmony_ci * dB values (which is also required for all other mixer controls).
1068c2ecf20Sopenharmony_ci */
1078c2ecf20Sopenharmony_ci/* Each item is: <min> <max> <TLV> */
1088c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \
1098c2ecf20Sopenharmony_ci	SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
1108c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \
1118c2ecf20Sopenharmony_ci	unsigned int name[] = { \
1128c2ecf20Sopenharmony_ci		SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \
1138c2ecf20Sopenharmony_ci	}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#define SNDRV_CTL_TLVD_DB_GAIN_MUTE	-9999999
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#endif
118