tlv.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __UAPI_SOUND_TLV_H
  13. #define __UAPI_SOUND_TLV_H
  14. #define SNDRV_CTL_TLVT_CONTAINER 0 /* one level down - group of TLVs */
  15. #define SNDRV_CTL_TLVT_DB_SCALE 1 /* dB scale */
  16. #define SNDRV_CTL_TLVT_DB_LINEAR 2 /* linear volume */
  17. #define SNDRV_CTL_TLVT_DB_RANGE 3 /* dB range container */
  18. #define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */
  19. #define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */
  20. /*
  21. * channel-mapping TLV items
  22. * TLV length must match with num_channels
  23. */
  24. #define SNDRV_CTL_TLVT_CHMAP_FIXED 0x101 /* fixed channel position */
  25. #define SNDRV_CTL_TLVT_CHMAP_VAR 0x102 /* channels freely swappable */
  26. #define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103 /* pair-wise swappable */
  27. /*
  28. * TLV structure is right behind the struct snd_ctl_tlv:
  29. * unsigned int type - see SNDRV_CTL_TLVT_*
  30. * unsigned int length
  31. * .... data aligned to sizeof(unsigned int), use
  32. * block_length = (length + (sizeof(unsigned int) - 1)) &
  33. * ~(sizeof(unsigned int) - 1)) ....
  34. */
  35. #define SNDRV_CTL_TLVD_ITEM(type, ...) \
  36. (type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__
  37. #define SNDRV_CTL_TLVD_LENGTH(...) \
  38. ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
  39. #define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \
  40. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__)
  41. #define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \
  42. unsigned int name[] = { \
  43. SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \
  44. }
  45. #define SNDRV_CTL_TLVD_DB_SCALE_MASK 0xffff
  46. #define SNDRV_CTL_TLVD_DB_SCALE_MUTE 0x10000
  47. #define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
  48. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \
  49. (min), \
  50. ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \
  51. ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0))
  52. #define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \
  53. unsigned int name[] = { \
  54. SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \
  55. }
  56. /* dB scale specified with min/max values instead of step */
  57. #define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
  58. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB))
  59. #define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
  60. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB))
  61. #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \
  62. unsigned int name[] = { \
  63. SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \
  64. }
  65. #define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \
  66. unsigned int name[] = { \
  67. SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \
  68. }
  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. /* dB range container:
  77. * Items in dB range container must be ordered by their values and by their
  78. * dB values. This implies that larger values must correspond with larger
  79. * dB values (which is also required for all other mixer controls).
  80. */
  81. /* Each item is: <min> <max> <TLV> */
  82. #define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \
  83. SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
  84. #define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \
  85. unsigned int name[] = { \
  86. SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \
  87. }
  88. #define SNDRV_CTL_TLVD_DB_GAIN_MUTE -9999999
  89. #endif