tegra210_mbdrc.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * tegra210_mbdrc.h - Definitions for Tegra210 MBDRC driver
  4. *
  5. * Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
  6. *
  7. */
  8. #ifndef __TEGRA210_MBDRC_H__
  9. #define __TEGRA210_MBDRC_H__
  10. #include <linux/platform_device.h>
  11. #include <sound/soc.h>
  12. /* Register offsets from TEGRA210_MBDRC*_BASE */
  13. #define TEGRA210_MBDRC_SOFT_RESET 0x4
  14. #define TEGRA210_MBDRC_CG 0x8
  15. #define TEGRA210_MBDRC_STATUS 0xc
  16. #define TEGRA210_MBDRC_CFG 0x28
  17. #define TEGRA210_MBDRC_CHANNEL_MASK 0x2c
  18. #define TEGRA210_MBDRC_MASTER_VOL 0x30
  19. #define TEGRA210_MBDRC_FAST_FACTOR 0x34
  20. #define TEGRA210_MBDRC_FILTER_COUNT 3
  21. #define TEGRA210_MBDRC_FILTER_PARAM_STRIDE 0x4
  22. #define TEGRA210_MBDRC_IIR_CFG 0x38
  23. #define TEGRA210_MBDRC_IN_ATTACK 0x44
  24. #define TEGRA210_MBDRC_IN_RELEASE 0x50
  25. #define TEGRA210_MBDRC_FAST_ATTACK 0x5c
  26. #define TEGRA210_MBDRC_IN_THRESHOLD 0x68
  27. #define TEGRA210_MBDRC_OUT_THRESHOLD 0x74
  28. #define TEGRA210_MBDRC_RATIO_1ST 0x80
  29. #define TEGRA210_MBDRC_RATIO_2ND 0x8c
  30. #define TEGRA210_MBDRC_RATIO_3RD 0x98
  31. #define TEGRA210_MBDRC_RATIO_4TH 0xa4
  32. #define TEGRA210_MBDRC_RATIO_5TH 0xb0
  33. #define TEGRA210_MBDRC_MAKEUP_GAIN 0xbc
  34. #define TEGRA210_MBDRC_INIT_GAIN 0xc8
  35. #define TEGRA210_MBDRC_GAIN_ATTACK 0xd4
  36. #define TEGRA210_MBDRC_GAIN_RELEASE 0xe0
  37. #define TEGRA210_MBDRC_FAST_RELEASE 0xec
  38. #define TEGRA210_MBDRC_CFG_RAM_CTRL 0xf8
  39. #define TEGRA210_MBDRC_CFG_RAM_DATA 0x104
  40. #define TEGRA210_MBDRC_MAX_REG (TEGRA210_MBDRC_CFG_RAM_DATA + \
  41. (TEGRA210_MBDRC_FILTER_PARAM_STRIDE * \
  42. (TEGRA210_MBDRC_FILTER_COUNT - 1)))
  43. /* Fields for TEGRA210_MBDRC_CFG */
  44. #define TEGRA210_MBDRC_CFG_RMS_OFFSET_SHIFT 16
  45. #define TEGRA210_MBDRC_CFG_RMS_OFFSET_MASK (0x1ff << TEGRA210_MBDRC_CFG_RMS_OFFSET_SHIFT)
  46. #define TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT 14
  47. #define TEGRA210_MBDRC_CFG_PEAK_RMS_MASK (0x1 << TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT)
  48. #define TEGRA210_MBDRC_CFG_PEAK (1 << TEGRA210_MBDRC_CFG_PEAK_RMS_SHIFT)
  49. #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT 13
  50. #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_MASK (0x1 << TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT)
  51. #define TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_FLEX (1 << TEGRA210_MBDRC_CFG_FILTER_STRUCTURE_SHIFT)
  52. #define TEGRA210_MBDRC_CFG_SHIFT_CTRL_SHIFT 8
  53. #define TEGRA210_MBDRC_CFG_SHIFT_CTRL_MASK (0x1f << TEGRA210_MBDRC_CFG_SHIFT_CTRL_SHIFT)
  54. #define TEGRA210_MBDRC_CFG_FRAME_SIZE_SHIFT 4
  55. #define TEGRA210_MBDRC_CFG_FRAME_SIZE_MASK (0xf << TEGRA210_MBDRC_CFG_FRAME_SIZE_SHIFT)
  56. #define TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT 0
  57. #define TEGRA210_MBDRC_CFG_MBDRC_MODE_MASK (0x3 << TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT)
  58. #define TEGRA210_MBDRC_CFG_MBDRC_MODE_BYPASS (0 << TEGRA210_MBDRC_CFG_MBDRC_MODE_SHIFT)
  59. /* Fields for TEGRA210_MBDRC_CHANNEL_MASK */
  60. #define TEGRA210_MBDRC_CHANNEL_MASK_SHIFT 0
  61. #define TEGRA210_MBDRC_CHANNEL_MASK_MASK (0xff << TEGRA210_MBDRC_CHANNEL_MASK_SHIFT)
  62. /* Fields for TEGRA210_MBDRC_MASTER_VOL */
  63. #define TEGRA210_MBDRC_MASTER_VOL_SHIFT 23
  64. #define TEGRA210_MBDRC_MASTER_VOL_MIN -256
  65. #define TEGRA210_MBDRC_MASTER_VOL_MAX 256
  66. /* Fields for TEGRA210_MBDRC_FAST_FACTOR */
  67. #define TEGRA210_MBDRC_FAST_FACTOR_RELEASE_SHIFT 16
  68. #define TEGRA210_MBDRC_FAST_FACTOR_RELEASE_MASK (0xffff << TEGRA210_MBDRC_FAST_FACTOR_RELEASE_SHIFT)
  69. #define TEGRA210_MBDRC_FAST_FACTOR_ATTACK_SHIFT 0
  70. #define TEGRA210_MBDRC_FAST_FACTOR_ATTACK_MASK (0xffff << TEGRA210_MBDRC_FAST_FACTOR_ATTACK_SHIFT)
  71. /* Fields for TEGRA210_MBDRC_IIR_CFG */
  72. #define TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_SHIFT 0
  73. #define TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_MASK (0xf << TEGRA210_MBDRC_IIR_CFG_NUM_STAGES_SHIFT)
  74. /* Fields for TEGRA210_MBDRC_IN_ATTACK */
  75. #define TEGRA210_MBDRC_IN_ATTACK_TC_SHIFT 0
  76. #define TEGRA210_MBDRC_IN_ATTACK_TC_MASK (0xffffffff << TEGRA210_MBDRC_IN_ATTACK_TC_SHIFT)
  77. /* Fields for TEGRA210_MBDRC_IN_RELEASE */
  78. #define TEGRA210_MBDRC_IN_RELEASE_TC_SHIFT 0
  79. #define TEGRA210_MBDRC_IN_RELEASE_TC_MASK (0xffffffff << TEGRA210_MBDRC_IN_RELEASE_TC_SHIFT)
  80. /* Fields for TEGRA210_MBDRC_FAST_ATTACK */
  81. #define TEGRA210_MBDRC_FAST_ATTACK_TC_SHIFT 0
  82. #define TEGRA210_MBDRC_FAST_ATTACK_TC_MASK (0xffffffff << TEGRA210_MBDRC_FAST_ATTACK_TC_SHIFT)
  83. /* Fields for TEGRA210_MBDRC_IN_THRESHOLD / TEGRA210_MBDRC_OUT_THRESHOLD */
  84. #define TEGRA210_MBDRC_THRESH_4TH_SHIFT 24
  85. #define TEGRA210_MBDRC_THRESH_4TH_MASK (0xff << TEGRA210_MBDRC_THRESH_4TH_SHIFT)
  86. #define TEGRA210_MBDRC_THRESH_3RD_SHIFT 16
  87. #define TEGRA210_MBDRC_THRESH_3RD_MASK (0xff << TEGRA210_MBDRC_THRESH_3RD_SHIFT)
  88. #define TEGRA210_MBDRC_THRESH_2ND_SHIFT 8
  89. #define TEGRA210_MBDRC_THRESH_2ND_MASK (0xff << TEGRA210_MBDRC_THRESH_2ND_SHIFT)
  90. #define TEGRA210_MBDRC_THRESH_1ST_SHIFT 0
  91. #define TEGRA210_MBDRC_THRESH_1ST_MASK (0xff << TEGRA210_MBDRC_THRESH_1ST_SHIFT)
  92. /* Fields for TEGRA210_MBDRC_RATIO_1ST */
  93. #define TEGRA210_MBDRC_RATIO_1ST_SHIFT 0
  94. #define TEGRA210_MBDRC_RATIO_1ST_MASK (0xffff << TEGRA210_MBDRC_RATIO_1ST_SHIFT)
  95. /* Fields for TEGRA210_MBDRC_RATIO_2ND */
  96. #define TEGRA210_MBDRC_RATIO_2ND_SHIFT 0
  97. #define TEGRA210_MBDRC_RATIO_2ND_MASK (0xffff << TEGRA210_MBDRC_RATIO_2ND_SHIFT)
  98. /* Fields for TEGRA210_MBDRC_RATIO_3RD */
  99. #define TEGRA210_MBDRC_RATIO_3RD_SHIFT 0
  100. #define TEGRA210_MBDRC_RATIO_3RD_MASK (0xffff << TEGRA210_MBDRC_RATIO_3RD_SHIFT)
  101. /* Fields for TEGRA210_MBDRC_RATIO_4TH */
  102. #define TEGRA210_MBDRC_RATIO_4TH_SHIFT 0
  103. #define TEGRA210_MBDRC_RATIO_4TH_MASK (0xffff << TEGRA210_MBDRC_RATIO_4TH_SHIFT)
  104. /* Fields for TEGRA210_MBDRC_RATIO_5TH */
  105. #define TEGRA210_MBDRC_RATIO_5TH_SHIFT 0
  106. #define TEGRA210_MBDRC_RATIO_5TH_MASK (0xffff << TEGRA210_MBDRC_RATIO_5TH_SHIFT)
  107. /* Fields for TEGRA210_MBDRC_MAKEUP_GAIN */
  108. #define TEGRA210_MBDRC_MAKEUP_GAIN_SHIFT 0
  109. #define TEGRA210_MBDRC_MAKEUP_GAIN_MASK (0x3f << TEGRA210_MBDRC_MAKEUP_GAIN_SHIFT)
  110. /* Fields for TEGRA210_MBDRC_INIT_GAIN */
  111. #define TEGRA210_MBDRC_INIT_GAIN_SHIFT 0
  112. #define TEGRA210_MBDRC_INIT_GAIN_MASK (0xffffffff << TEGRA210_MBDRC_INIT_GAIN_SHIFT)
  113. /* Fields for TEGRA210_MBDRC_GAIN_ATTACK */
  114. #define TEGRA210_MBDRC_GAIN_ATTACK_SHIFT 0
  115. #define TEGRA210_MBDRC_GAIN_ATTACK_MASK (0xffffffff << TEGRA210_MBDRC_GAIN_ATTACK_SHIFT)
  116. /* Fields for TEGRA210_MBDRC_GAIN_RELEASE */
  117. #define TEGRA210_MBDRC_GAIN_RELEASE_SHIFT 0
  118. #define TEGRA210_MBDRC_GAIN_RELEASE_MASK (0xffffffff << TEGRA210_MBDRC_GAIN_RELEASE_SHIFT)
  119. /* Fields for TEGRA210_MBDRC_FAST_RELEASE */
  120. #define TEGRA210_MBDRC_FAST_RELEASE_SHIFT 0
  121. #define TEGRA210_MBDRC_FAST_RELEASE_MASK (0xffffffff << TEGRA210_MBDRC_FAST_RELEASE_SHIFT)
  122. #define TEGRA210_MBDRC_RAM_CTRL_RW_READ 0
  123. #define TEGRA210_MBDRC_RAM_CTRL_RW_WRITE (1 << 14)
  124. #define TEGRA210_MBDRC_RAM_CTRL_ADDR_INIT_EN (1 << 13)
  125. #define TEGRA210_MBDRC_RAM_CTRL_SEQ_ACCESS_EN (1 << 12)
  126. #define TEGRA210_MBDRC_RAM_CTRL_RAM_ADDR_MASK 0x1ff
  127. /*
  128. * Order and size of each structure element for following structures should not
  129. * be altered size order of elements and their size are based on PEQ co-eff ram
  130. * and shift ram layout.
  131. */
  132. #define TEGRA210_MBDRC_THRESHOLD_NUM 4
  133. #define TEGRA210_MBDRC_RATIO_NUM (TEGRA210_MBDRC_THRESHOLD_NUM + 1)
  134. #define TEGRA210_MBDRC_MAX_BIQUAD_STAGES 8
  135. /* Order of these enums are same as the order of band specific hw registers */
  136. enum {
  137. MBDRC_LOW_BAND,
  138. MBDRC_MID_BAND,
  139. MBDRC_HIGH_BAND,
  140. MBDRC_NUM_BAND,
  141. };
  142. struct tegra210_mbdrc_band_params {
  143. u32 band;
  144. u32 iir_stages;
  145. u32 in_attack_tc;
  146. u32 in_release_tc;
  147. u32 fast_attack_tc;
  148. u32 in_threshold[TEGRA210_MBDRC_THRESHOLD_NUM];
  149. u32 out_threshold[TEGRA210_MBDRC_THRESHOLD_NUM];
  150. u32 ratio[TEGRA210_MBDRC_RATIO_NUM];
  151. u32 makeup_gain;
  152. u32 gain_init;
  153. u32 gain_attack_tc;
  154. u32 gain_release_tc;
  155. u32 fast_release_tc;
  156. /* For biquad_params[][5] order of coeff is b0, b1, a0, a1, a2 */
  157. u32 biquad_params[TEGRA210_MBDRC_MAX_BIQUAD_STAGES * 5];
  158. };
  159. struct tegra210_mbdrc_config {
  160. unsigned int mode;
  161. unsigned int rms_off;
  162. unsigned int peak_rms_mode;
  163. unsigned int fliter_structure;
  164. unsigned int shift_ctrl;
  165. unsigned int frame_size;
  166. unsigned int channel_mask;
  167. unsigned int fa_factor; /* Fast attack factor */
  168. unsigned int fr_factor; /* Fast release factor */
  169. struct tegra210_mbdrc_band_params band_params[MBDRC_NUM_BAND];
  170. };
  171. int tegra210_mbdrc_regmap_init(struct platform_device *pdev);
  172. int tegra210_mbdrc_component_init(struct snd_soc_component *cmpnt);
  173. int tegra210_mbdrc_hw_params(struct snd_soc_component *cmpnt);
  174. #endif