tlv.h 4.0 KB

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