rt274.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * rt274.h -- RT274 ALSA SoC audio driver
  4. *
  5. * Copyright 2016 Realtek Microelectronics
  6. * Author: Bard Liao <[email protected]>
  7. */
  8. #ifndef __RT274_H__
  9. #define __RT274_H__
  10. #define VERB_CMD(V, N, D) ((N << 20) | (V << 8) | D)
  11. #define RT274_AUDIO_FUNCTION_GROUP 0x01
  12. #define RT274_DAC_OUT0 0x02
  13. #define RT274_DAC_OUT1 0x03
  14. #define RT274_ADC_IN2 0x08
  15. #define RT274_ADC_IN1 0x09
  16. #define RT274_DIG_CVT 0x0a
  17. #define RT274_DMIC1 0x12
  18. #define RT274_DMIC2 0x13
  19. #define RT274_MIC 0x19
  20. #define RT274_LINE1 0x1a
  21. #define RT274_LINE2 0x1b
  22. #define RT274_LINE3 0x16
  23. #define RT274_SPDIF 0x1e
  24. #define RT274_VENDOR_REGISTERS 0x20
  25. #define RT274_HP_OUT 0x21
  26. #define RT274_MIXER_IN1 0x22
  27. #define RT274_MIXER_IN2 0x23
  28. #define RT274_INLINE_CMD 0x55
  29. #define RT274_SET_PIN_SFT 6
  30. #define RT274_SET_PIN_ENABLE 0x40
  31. #define RT274_SET_PIN_DISABLE 0
  32. #define RT274_SET_EAPD_HIGH 0x2
  33. #define RT274_SET_EAPD_LOW 0
  34. #define RT274_MUTE_SFT 7
  35. /* Verb commands */
  36. #define RT274_RESET\
  37. VERB_CMD(AC_VERB_SET_CODEC_RESET, RT274_AUDIO_FUNCTION_GROUP, 0)
  38. #define RT274_GET_PARAM(NID, PARAM) VERB_CMD(AC_VERB_PARAMETERS, NID, PARAM)
  39. #define RT274_SET_POWER(NID) VERB_CMD(AC_VERB_SET_POWER_STATE, NID, 0)
  40. #define RT274_SET_AUDIO_POWER RT274_SET_POWER(RT274_AUDIO_FUNCTION_GROUP)
  41. #define RT274_SET_HPO_POWER RT274_SET_POWER(RT274_HP_OUT)
  42. #define RT274_SET_DMIC1_POWER RT274_SET_POWER(RT274_DMIC1)
  43. #define RT274_LOUT_MUX\
  44. VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_LINE3, 0)
  45. #define RT274_HPO_MUX\
  46. VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_HP_OUT, 0)
  47. #define RT274_ADC0_MUX\
  48. VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_MIXER_IN1, 0)
  49. #define RT274_ADC1_MUX\
  50. VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_MIXER_IN2, 0)
  51. #define RT274_SET_MIC\
  52. VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_MIC, 0)
  53. #define RT274_SET_PIN_LOUT3\
  54. VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_LINE3, 0)
  55. #define RT274_SET_PIN_HPO\
  56. VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_HP_OUT, 0)
  57. #define RT274_SET_PIN_DMIC1\
  58. VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_DMIC1, 0)
  59. #define RT274_SET_PIN_SPDIF\
  60. VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_SPDIF, 0)
  61. #define RT274_SET_PIN_DIG_CVT\
  62. VERB_CMD(AC_VERB_SET_DIGI_CONVERT_1, RT274_DIG_CVT, 0)
  63. #define RT274_SET_AMP_GAIN_HPO\
  64. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0)
  65. #define RT274_SET_AMP_GAIN_ADC_IN1\
  66. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0)
  67. #define RT274_SET_AMP_GAIN_ADC_IN2\
  68. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN2, 0)
  69. #define RT274_GET_HP_SENSE\
  70. VERB_CMD(AC_VERB_GET_PIN_SENSE, RT274_HP_OUT, 0)
  71. #define RT274_GET_MIC_SENSE\
  72. VERB_CMD(AC_VERB_GET_PIN_SENSE, RT274_MIC, 0)
  73. #define RT274_SET_DMIC2_DEFAULT\
  74. VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT274_DMIC2, 0)
  75. #define RT274_SET_SPDIF_DEFAULT\
  76. VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT274_SPDIF, 0)
  77. #define RT274_DAC0L_GAIN\
  78. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT0, 0xa000)
  79. #define RT274_DAC0R_GAIN\
  80. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT0, 0x9000)
  81. #define RT274_DAC1L_GAIN\
  82. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT1, 0xa000)
  83. #define RT274_DAC1R_GAIN\
  84. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT1, 0x9000)
  85. #define RT274_ADCL_GAIN\
  86. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0x6000)
  87. #define RT274_ADCR_GAIN\
  88. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0x5000)
  89. #define RT274_MIC_GAIN\
  90. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_MIC, 0x7000)
  91. #define RT274_LOUTL_GAIN\
  92. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_LINE3, 0xa000)
  93. #define RT274_LOUTR_GAIN\
  94. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_LINE3, 0x9000)
  95. #define RT274_HPOL_GAIN\
  96. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0xa000)
  97. #define RT274_HPOR_GAIN\
  98. VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0x9000)
  99. #define RT274_DAC_FORMAT\
  100. VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT274_DAC_OUT0, 0)
  101. #define RT274_ADC_FORMAT\
  102. VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT274_ADC_IN1, 0)
  103. #define RT274_COEF_INDEX\
  104. VERB_CMD(AC_VERB_SET_COEF_INDEX, RT274_VENDOR_REGISTERS, 0)
  105. #define RT274_PROC_COEF\
  106. VERB_CMD(AC_VERB_SET_PROC_COEF, RT274_VENDOR_REGISTERS, 0)
  107. #define RT274_UNSOLICITED_INLINE_CMD\
  108. VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_INLINE_CMD, 0)
  109. #define RT274_UNSOLICITED_HP_OUT\
  110. VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_HP_OUT, 0)
  111. #define RT274_UNSOLICITED_MIC\
  112. VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_MIC, 0)
  113. #define RT274_COEF58_INDEX\
  114. VERB_CMD(AC_VERB_SET_COEF_INDEX, 0x58, 0)
  115. #define RT274_COEF58_COEF\
  116. VERB_CMD(AC_VERB_SET_PROC_COEF, 0x58, 0)
  117. #define RT274_COEF5b_INDEX\
  118. VERB_CMD(AC_VERB_SET_COEF_INDEX, 0x5b, 0)
  119. #define RT274_COEF5b_COEF\
  120. VERB_CMD(AC_VERB_SET_PROC_COEF, 0x5b, 0)
  121. #define RT274_SET_STREAMID_DAC0\
  122. VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_DAC_OUT0, 0)
  123. #define RT274_SET_STREAMID_DAC1\
  124. VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_DAC_OUT1, 0)
  125. #define RT274_SET_STREAMID_ADC1\
  126. VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_ADC_IN1, 0)
  127. #define RT274_SET_STREAMID_ADC2\
  128. VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_ADC_IN2, 0)
  129. /* Index registers */
  130. #define RT274_EAPD_GPIO_IRQ_CTRL 0x10
  131. #define RT274_PAD_CTRL12 0x35
  132. #define RT274_I2S_CTRL1 0x63
  133. #define RT274_I2S_CTRL2 0x64
  134. #define RT274_MCLK_CTRL 0x71
  135. #define RT274_CLK_CTRL 0x72
  136. #define RT274_PLL2_CTRL 0x7b
  137. /* EAPD GPIO IRQ control (Index 0x10) */
  138. #define RT274_IRQ_DIS (0x0 << 13)
  139. #define RT274_IRQ_EN (0x1 << 13)
  140. #define RT274_IRQ_CLR (0x1 << 12)
  141. #define RT274_GPI2_SEL_MASK (0x3 << 7)
  142. #define RT274_GPI2_SEL_GPIO2 (0x0 << 7)
  143. #define RT274_GPI2_SEL_I2S (0x1 << 7)
  144. #define RT274_GPI2_SEL_DMIC_CLK (0x2 << 7)
  145. #define RT274_GPI2_SEL_CBJ (0x3 << 7)
  146. /* Front I2S_Interface control 1 (Index 0x63) */
  147. #define RT274_I2S_MODE_MASK (0x1 << 11)
  148. #define RT274_I2S_MODE_S (0x0 << 11)
  149. #define RT274_I2S_MODE_M (0x1 << 11)
  150. #define RT274_TDM_DIS (0x0 << 10)
  151. #define RT274_TDM_EN (0x1 << 10)
  152. #define RT274_TDM_CH_NUM (0x1 << 7)
  153. #define RT274_TDM_2CH (0x0 << 7)
  154. #define RT274_TDM_4CH (0x1 << 7)
  155. #define RT274_I2S_FMT_MASK (0x3 << 8)
  156. #define RT274_I2S_FMT_I2S (0x0 << 8)
  157. #define RT274_I2S_FMT_LJ (0x1 << 8)
  158. #define RT274_I2S_FMT_PCMA (0x2 << 8)
  159. #define RT274_I2S_FMT_PCMB (0x3 << 8)
  160. /* MCLK clock domain control (Index 0x71) */
  161. #define RT274_MCLK_MODE_MASK (0x1 << 14)
  162. #define RT274_MCLK_MODE_DIS (0x0 << 14)
  163. #define RT274_MCLK_MODE_EN (0x1 << 14)
  164. /* Clock control (Index 0x72) */
  165. #define RT274_CLK_SRC_MASK (0x7 << 3)
  166. #define RT274_CLK_SRC_MCLK (0x0 << 3)
  167. #define RT274_CLK_SRC_PLL2 (0x3 << 3)
  168. /* PLL2 control (Index 0x7b) */
  169. #define RT274_PLL2_SRC_MASK (0x1 << 13)
  170. #define RT274_PLL2_SRC_MCLK (0x0 << 13)
  171. #define RT274_PLL2_SRC_BCLK (0x1 << 13)
  172. /* HP-OUT (0x21) */
  173. #define RT274_M_HP_MUX_SFT 14
  174. #define RT274_HP_SEL_MASK 0x1
  175. #define RT274_HP_SEL_SFT 0
  176. #define RT274_HP_SEL_F 0
  177. #define RT274_HP_SEL_S 1
  178. /* ADC (0x22) (0x23) */
  179. #define RT274_ADC_SEL_MASK 0x7
  180. #define RT274_ADC_SEL_SFT 0
  181. #define RT274_ADC_SEL_MIC 0
  182. #define RT274_ADC_SEL_LINE1 1
  183. #define RT274_ADC_SEL_LINE2 2
  184. #define RT274_ADC_SEL_DMIC 3
  185. #define RT274_SCLK_S_MCLK 0
  186. #define RT274_SCLK_S_PLL1 1
  187. #define RT274_SCLK_S_PLL2 2
  188. #define RT274_PLL2_S_MCLK 0
  189. #define RT274_PLL2_S_BCLK 1
  190. enum {
  191. RT274_AIF1,
  192. RT274_AIFS,
  193. };
  194. #endif /* __RT274_H__ */