tlv.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef __UAPI_SOUND_TLV_H
  14. #define __UAPI_SOUND_TLV_H
  15. #define SNDRV_CTL_TLVT_CONTAINER 0 /* one level down - group of TLVs */
  16. #define SNDRV_CTL_TLVT_DB_SCALE 1 /* dB scale */
  17. #define SNDRV_CTL_TLVT_DB_LINEAR 2 /* linear volume */
  18. #define SNDRV_CTL_TLVT_DB_RANGE 3 /* dB range container */
  19. #define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */
  20. #define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */
  21. /*
  22. * channel-mapping TLV items
  23. * TLV length must match with num_channels
  24. */
  25. #define SNDRV_CTL_TLVT_CHMAP_FIXED 0x101 /* fixed channel position */
  26. #define SNDRV_CTL_TLVT_CHMAP_VAR 0x102 /* channels freely swappable */
  27. #define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103 /* pair-wise swappable */
  28. /*
  29. * TLV structure is right behind the struct snd_ctl_tlv:
  30. * unsigned int type - see SNDRV_CTL_TLVT_*
  31. * unsigned int length
  32. * .... data aligned to sizeof(unsigned int), use
  33. * block_length = (length + (sizeof(unsigned int) - 1)) &
  34. * ~(sizeof(unsigned int) - 1)) ....
  35. */
  36. #define SNDRV_CTL_TLVD_ITEM(type, ...) \
  37. (type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__
  38. #define SNDRV_CTL_TLVD_LENGTH(...) \
  39. ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
  40. /* Accessor offsets for TLV data items */
  41. #define SNDRV_CTL_TLVO_TYPE 0
  42. #define SNDRV_CTL_TLVO_LEN 1
  43. #define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \
  44. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__)
  45. #define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \
  46. unsigned int name[] = { \
  47. SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \
  48. }
  49. #define SNDRV_CTL_TLVD_DB_SCALE_MASK 0xffff
  50. #define SNDRV_CTL_TLVD_DB_SCALE_MUTE 0x10000
  51. #define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
  52. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
  53. (min), \
  54. ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \
  55. ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0))
  56. #define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \
  57. unsigned int name[] = { \
  58. SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
  59. }
  60. /* Accessor offsets for min, mute and step items in dB scale type TLV */
  61. #define SNDRV_CTL_TLVO_DB_SCALE_MIN 2
  62. #define SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP 3
  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. /* Accessor offsets for min, max items in db-minmax types of TLV. */
  77. #define SNDRV_CTL_TLVO_DB_MINMAX_MIN 2
  78. #define SNDRV_CTL_TLVO_DB_MINMAX_MAX 3
  79. /* linear volume between min_dB and max_dB (.01dB unit) */
  80. #define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
  81. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB))
  82. #define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \
  83. unsigned int name[] = { \
  84. SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
  85. }
  86. /* Accessor offsets for min, max items in db-linear type of TLV. */
  87. #define SNDRV_CTL_TLVO_DB_LINEAR_MIN 2
  88. #define SNDRV_CTL_TLVO_DB_LINEAR_MAX 3
  89. /* dB range container:
  90. * Items in dB range container must be ordered by their values and by their
  91. * dB values. This implies that larger values must correspond with larger
  92. * dB values (which is also required for all other mixer controls).
  93. */
  94. /* Each item is: <min> <max> <TLV> */
  95. #define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \
  96. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
  97. #define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \
  98. unsigned int name[] = { \
  99. SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \
  100. }
  101. #define SNDRV_CTL_TLVD_DB_GAIN_MUTE -9999999
  102. #endif