tlv.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \
  41. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__)
  42. #define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \
  43. unsigned int name[] = { \
  44. SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \
  45. }
  46. #define SNDRV_CTL_TLVD_DB_SCALE_MASK 0xffff
  47. #define SNDRV_CTL_TLVD_DB_SCALE_MUTE 0x10000
  48. #define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
  49. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
  50. (min), \
  51. ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \
  52. ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0))
  53. #define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \
  54. unsigned int name[] = { \
  55. SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
  56. }
  57. /* dB scale specified with min/max values instead of step */
  58. #define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
  59. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB))
  60. #define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
  61. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB))
  62. #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \
  63. unsigned int name[] = { \
  64. SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
  65. }
  66. #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \
  67. unsigned int name[] = { \
  68. SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
  69. }
  70. /* linear volume between min_dB and max_dB (.01dB unit) */
  71. #define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
  72. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB))
  73. #define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \
  74. unsigned int name[] = { \
  75. SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \
  76. }
  77. /* dB range container:
  78. * Items in dB range container must be ordered by their values and by their
  79. * dB values. This implies that larger values must correspond with larger
  80. * dB values (which is also required for all other mixer controls).
  81. */
  82. /* Each item is: <min> <max> <TLV> */
  83. #define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \
  84. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
  85. #define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \
  86. unsigned int name[] = { \
  87. SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \
  88. }
  89. #define SNDRV_CTL_TLVD_DB_GAIN_MUTE -9999999
  90. #endif