tlv.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #define SNDRV_CTL_TLVT_FCP_CHANNEL_LABELS 0x110 /* channel labels */
  18. /*
  19. * TLV structure is right behind the struct snd_ctl_tlv:
  20. * unsigned int type - see SNDRV_CTL_TLVT_*
  21. * unsigned int length
  22. * .... data aligned to sizeof(unsigned int), use
  23. * block_length = (length + (sizeof(unsigned int) - 1)) &
  24. * ~(sizeof(unsigned int) - 1)) ....
  25. */
  26. #define SNDRV_CTL_TLVD_ITEM(type, ...) \
  27. (type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__
  28. #define SNDRV_CTL_TLVD_LENGTH(...) \
  29. ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
  30. /* Accessor offsets for TLV data items */
  31. #define SNDRV_CTL_TLVO_TYPE 0
  32. #define SNDRV_CTL_TLVO_LEN 1
  33. #define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \
  34. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__)
  35. #define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \
  36. unsigned int name[] = { \
  37. SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \
  38. }
  39. #define SNDRV_CTL_TLVD_DB_SCALE_MASK 0xffff
  40. #define SNDRV_CTL_TLVD_DB_SCALE_MUTE 0x10000
  41. #define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
  42. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
  43. (min), \
  44. ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \
  45. ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0))
  46. #define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \
  47. unsigned int name[] = { \
  48. SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
  49. }
  50. /* Accessor offsets for min, mute and step items in dB scale type TLV */
  51. #define SNDRV_CTL_TLVO_DB_SCALE_MIN 2
  52. #define SNDRV_CTL_TLVO_DB_SCALE_MUTE_AND_STEP 3
  53. /* dB scale specified with min/max values instead of step */
  54. #define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
  55. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB))
  56. #define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
  57. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB))
  58. #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \
  59. unsigned int name[] = { \
  60. SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
  61. }
  62. #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \
  63. unsigned int name[] = { \
  64. SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
  65. }
  66. /* Accessor offsets for min, max items in db-minmax types of TLV. */
  67. #define SNDRV_CTL_TLVO_DB_MINMAX_MIN 2
  68. #define SNDRV_CTL_TLVO_DB_MINMAX_MAX 3
  69. /* linear volume between min_dB and max_dB (.01dB unit) */
  70. #define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
  71. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB))
  72. #define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \
  73. unsigned int name[] = { \
  74. SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
  75. }
  76. /* Accessor offsets for min, max items in db-linear type of TLV. */
  77. #define SNDRV_CTL_TLVO_DB_LINEAR_MIN 2
  78. #define SNDRV_CTL_TLVO_DB_LINEAR_MAX 3
  79. /* dB range container:
  80. * Items in dB range container must be ordered by their values and by their
  81. * dB values. This implies that larger values must correspond with larger
  82. * dB values (which is also required for all other mixer controls).
  83. */
  84. /* Each item is: <min> <max> <TLV> */
  85. #define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \
  86. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
  87. #define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \
  88. unsigned int name[] = { \
  89. SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \
  90. }
  91. #define SNDRV_CTL_TLVD_DB_GAIN_MUTE -9999999
  92. #endif