rt715.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * rt715.h -- RT715 ALSA SoC audio driver header
  4. *
  5. * Copyright(c) 2019 Realtek Semiconductor Corp.
  6. */
  7. #ifndef __RT715_H__
  8. #define __RT715_H__
  9. #include <linux/regulator/consumer.h>
  10. struct rt715_priv {
  11. struct regmap *regmap;
  12. struct regmap *sdw_regmap;
  13. struct snd_soc_codec *codec;
  14. struct sdw_slave *slave;
  15. int dbg_nid;
  16. int dbg_vid;
  17. int dbg_payload;
  18. enum sdw_slave_status status;
  19. struct sdw_bus_params params;
  20. bool hw_init;
  21. bool first_hw_init;
  22. };
  23. struct sdw_stream_data {
  24. struct sdw_stream_runtime *sdw_stream;
  25. };
  26. /* NID */
  27. #define RT715_AUDIO_FUNCTION_GROUP 0x01
  28. #define RT715_MIC_ADC 0x07
  29. #define RT715_LINE_ADC 0x08
  30. #define RT715_MIX_ADC 0x09
  31. #define RT715_DMIC1 0x12
  32. #define RT715_DMIC2 0x13
  33. #define RT715_MIC1 0x18
  34. #define RT715_MIC2 0x19
  35. #define RT715_LINE1 0x1a
  36. #define RT715_LINE2 0x1b
  37. #define RT715_DMIC3 0x1d
  38. #define RT715_DMIC4 0x29
  39. #define RT715_VENDOR_REGISTERS 0x20
  40. #define RT715_MUX_IN1 0x22
  41. #define RT715_MUX_IN2 0x23
  42. #define RT715_MUX_IN3 0x24
  43. #define RT715_MUX_IN4 0x25
  44. #define RT715_MIX_ADC2 0x27
  45. #define RT715_INLINE_CMD 0x55
  46. /* Index (NID:20h) */
  47. #define RT715_SDW_INPUT_SEL 0x39
  48. #define RT715_EXT_DMIC_CLK_CTRL2 0x54
  49. /* Verb */
  50. #define RT715_VERB_SET_CONNECT_SEL 0x3100
  51. #define RT715_VERB_GET_CONNECT_SEL 0xb100
  52. #define RT715_VERB_SET_EAPD_BTLENABLE 0x3c00
  53. #define RT715_VERB_SET_POWER_STATE 0x3500
  54. #define RT715_VERB_SET_CHANNEL_STREAMID 0x3600
  55. #define RT715_VERB_SET_PIN_WIDGET_CONTROL 0x3700
  56. #define RT715_VERB_SET_CONFIG_DEFAULT1 0x4c00
  57. #define RT715_VERB_SET_CONFIG_DEFAULT2 0x4d00
  58. #define RT715_VERB_SET_CONFIG_DEFAULT3 0x4e00
  59. #define RT715_VERB_SET_CONFIG_DEFAULT4 0x4f00
  60. #define RT715_VERB_SET_UNSOLICITED_ENABLE 0x3800
  61. #define RT715_SET_AMP_GAIN_MUTE_H 0x7300
  62. #define RT715_SET_AMP_GAIN_MUTE_L 0x8380
  63. #define RT715_READ_HDA_3 0x2012
  64. #define RT715_READ_HDA_2 0x2013
  65. #define RT715_READ_HDA_1 0x2014
  66. #define RT715_READ_HDA_0 0x2015
  67. #define RT715_PRIV_INDEX_W_H 0x7520
  68. #define RT715_PRIV_INDEX_W_L 0x85a0
  69. #define RT715_PRIV_DATA_W_H 0x7420
  70. #define RT715_PRIV_DATA_W_L 0x84a0
  71. #define RT715_PRIV_INDEX_R_H 0x9d20
  72. #define RT715_PRIV_INDEX_R_L 0xada0
  73. #define RT715_PRIV_DATA_R_H 0x9c20
  74. #define RT715_PRIV_DATA_R_L 0xaca0
  75. #define RT715_MIC_ADC_FORMAT_H 0x7207
  76. #define RT715_MIC_ADC_FORMAT_L 0x8287
  77. #define RT715_MIC_LINE_FORMAT_H 0x7208
  78. #define RT715_MIC_LINE_FORMAT_L 0x8288
  79. #define RT715_MIX_ADC_FORMAT_H 0x7209
  80. #define RT715_MIX_ADC_FORMAT_L 0x8289
  81. #define RT715_MIX_ADC2_FORMAT_H 0x7227
  82. #define RT715_MIX_ADC2_FORMAT_L 0x82a7
  83. #define RT715_FUNC_RESET 0xff01
  84. #define RT715_SET_AUDIO_POWER_STATE\
  85. (RT715_VERB_SET_POWER_STATE | RT715_AUDIO_FUNCTION_GROUP)
  86. #define RT715_SET_PIN_DMIC1\
  87. (RT715_VERB_SET_PIN_WIDGET_CONTROL | RT715_DMIC1)
  88. #define RT715_SET_PIN_DMIC2\
  89. (RT715_VERB_SET_PIN_WIDGET_CONTROL | RT715_DMIC2)
  90. #define RT715_SET_PIN_DMIC3\
  91. (RT715_VERB_SET_PIN_WIDGET_CONTROL | RT715_DMIC3)
  92. #define RT715_SET_PIN_DMIC4\
  93. (RT715_VERB_SET_PIN_WIDGET_CONTROL | RT715_DMIC4)
  94. #define RT715_SET_PIN_MIC1\
  95. (RT715_VERB_SET_PIN_WIDGET_CONTROL | RT715_MIC1)
  96. #define RT715_SET_PIN_MIC2\
  97. (RT715_VERB_SET_PIN_WIDGET_CONTROL | RT715_MIC2)
  98. #define RT715_SET_PIN_LINE1\
  99. (RT715_VERB_SET_PIN_WIDGET_CONTROL | RT715_LINE1)
  100. #define RT715_SET_PIN_LINE2\
  101. (RT715_VERB_SET_PIN_WIDGET_CONTROL | RT715_LINE2)
  102. #define RT715_SET_MIC1_UNSOLICITED_ENABLE\
  103. (RT715_VERB_SET_UNSOLICITED_ENABLE | RT715_MIC1)
  104. #define RT715_SET_MIC2_UNSOLICITED_ENABLE\
  105. (RT715_VERB_SET_UNSOLICITED_ENABLE | RT715_MIC2)
  106. #define RT715_SET_STREAMID_MIC_ADC\
  107. (RT715_VERB_SET_CHANNEL_STREAMID | RT715_MIC_ADC)
  108. #define RT715_SET_STREAMID_LINE_ADC\
  109. (RT715_VERB_SET_CHANNEL_STREAMID | RT715_LINE_ADC)
  110. #define RT715_SET_STREAMID_MIX_ADC\
  111. (RT715_VERB_SET_CHANNEL_STREAMID | RT715_MIX_ADC)
  112. #define RT715_SET_STREAMID_MIX_ADC2\
  113. (RT715_VERB_SET_CHANNEL_STREAMID | RT715_MIX_ADC2)
  114. #define RT715_SET_GAIN_MIC_ADC_L\
  115. (RT715_SET_AMP_GAIN_MUTE_L | RT715_MIC_ADC)
  116. #define RT715_SET_GAIN_MIC_ADC_H\
  117. (RT715_SET_AMP_GAIN_MUTE_H | RT715_MIC_ADC)
  118. #define RT715_SET_GAIN_LINE_ADC_L\
  119. (RT715_SET_AMP_GAIN_MUTE_L | RT715_LINE_ADC)
  120. #define RT715_SET_GAIN_LINE_ADC_H\
  121. (RT715_SET_AMP_GAIN_MUTE_H | RT715_LINE_ADC)
  122. #define RT715_SET_GAIN_MIX_ADC_L\
  123. (RT715_SET_AMP_GAIN_MUTE_L | RT715_MIX_ADC)
  124. #define RT715_SET_GAIN_MIX_ADC_H\
  125. (RT715_SET_AMP_GAIN_MUTE_H | RT715_MIX_ADC)
  126. #define RT715_SET_GAIN_MIX_ADC2_L\
  127. (RT715_SET_AMP_GAIN_MUTE_L | RT715_MIX_ADC2)
  128. #define RT715_SET_GAIN_MIX_ADC2_H\
  129. (RT715_SET_AMP_GAIN_MUTE_H | RT715_MIX_ADC2)
  130. #define RT715_SET_GAIN_DMIC1_L\
  131. (RT715_SET_AMP_GAIN_MUTE_L | RT715_DMIC1)
  132. #define RT715_SET_GAIN_DMIC1_H\
  133. (RT715_SET_AMP_GAIN_MUTE_H | RT715_DMIC1)
  134. #define RT715_SET_GAIN_DMIC2_L\
  135. (RT715_SET_AMP_GAIN_MUTE_L | RT715_DMIC2)
  136. #define RT715_SET_GAIN_DMIC2_H\
  137. (RT715_SET_AMP_GAIN_MUTE_H | RT715_DMIC2)
  138. #define RT715_SET_GAIN_DMIC3_L\
  139. (RT715_SET_AMP_GAIN_MUTE_L | RT715_DMIC3)
  140. #define RT715_SET_GAIN_DMIC3_H\
  141. (RT715_SET_AMP_GAIN_MUTE_H | RT715_DMIC3)
  142. #define RT715_SET_GAIN_DMIC4_L\
  143. (RT715_SET_AMP_GAIN_MUTE_L | RT715_DMIC4)
  144. #define RT715_SET_GAIN_DMIC4_H\
  145. (RT715_SET_AMP_GAIN_MUTE_H | RT715_DMIC4)
  146. #define RT715_SET_GAIN_MIC1_L\
  147. (RT715_SET_AMP_GAIN_MUTE_L | RT715_MIC1)
  148. #define RT715_SET_GAIN_MIC1_H\
  149. (RT715_SET_AMP_GAIN_MUTE_H | RT715_MIC1)
  150. #define RT715_SET_GAIN_MIC2_L\
  151. (RT715_SET_AMP_GAIN_MUTE_L | RT715_MIC2)
  152. #define RT715_SET_GAIN_MIC2_H\
  153. (RT715_SET_AMP_GAIN_MUTE_H | RT715_MIC2)
  154. #define RT715_SET_GAIN_LINE1_L\
  155. (RT715_SET_AMP_GAIN_MUTE_L | RT715_LINE1)
  156. #define RT715_SET_GAIN_LINE1_H\
  157. (RT715_SET_AMP_GAIN_MUTE_H | RT715_LINE1)
  158. #define RT715_SET_GAIN_LINE2_L\
  159. (RT715_SET_AMP_GAIN_MUTE_L | RT715_LINE2)
  160. #define RT715_SET_GAIN_LINE2_H\
  161. (RT715_SET_AMP_GAIN_MUTE_H | RT715_LINE2)
  162. #define RT715_SET_DMIC1_CONFIG_DEFAULT1\
  163. (RT715_VERB_SET_CONFIG_DEFAULT1 | RT715_DMIC1)
  164. #define RT715_SET_DMIC2_CONFIG_DEFAULT1\
  165. (RT715_VERB_SET_CONFIG_DEFAULT1 | RT715_DMIC2)
  166. #define RT715_SET_DMIC1_CONFIG_DEFAULT2\
  167. (RT715_VERB_SET_CONFIG_DEFAULT2 | RT715_DMIC1)
  168. #define RT715_SET_DMIC2_CONFIG_DEFAULT2\
  169. (RT715_VERB_SET_CONFIG_DEFAULT2 | RT715_DMIC2)
  170. #define RT715_SET_DMIC1_CONFIG_DEFAULT3\
  171. (RT715_VERB_SET_CONFIG_DEFAULT3 | RT715_DMIC1)
  172. #define RT715_SET_DMIC2_CONFIG_DEFAULT3\
  173. (RT715_VERB_SET_CONFIG_DEFAULT3 | RT715_DMIC2)
  174. #define RT715_SET_DMIC1_CONFIG_DEFAULT4\
  175. (RT715_VERB_SET_CONFIG_DEFAULT4 | RT715_DMIC1)
  176. #define RT715_SET_DMIC2_CONFIG_DEFAULT4\
  177. (RT715_VERB_SET_CONFIG_DEFAULT4 | RT715_DMIC2)
  178. #define RT715_SET_DMIC3_CONFIG_DEFAULT1\
  179. (RT715_VERB_SET_CONFIG_DEFAULT1 | RT715_DMIC3)
  180. #define RT715_SET_DMIC4_CONFIG_DEFAULT1\
  181. (RT715_VERB_SET_CONFIG_DEFAULT1 | RT715_DMIC4)
  182. #define RT715_SET_DMIC3_CONFIG_DEFAULT2\
  183. (RT715_VERB_SET_CONFIG_DEFAULT2 | RT715_DMIC3)
  184. #define RT715_SET_DMIC4_CONFIG_DEFAULT2\
  185. (RT715_VERB_SET_CONFIG_DEFAULT2 | RT715_DMIC4)
  186. #define RT715_SET_DMIC3_CONFIG_DEFAULT3\
  187. (RT715_VERB_SET_CONFIG_DEFAULT3 | RT715_DMIC3)
  188. #define RT715_SET_DMIC4_CONFIG_DEFAULT3\
  189. (RT715_VERB_SET_CONFIG_DEFAULT3 | RT715_DMIC4)
  190. #define RT715_SET_DMIC3_CONFIG_DEFAULT4\
  191. (RT715_VERB_SET_CONFIG_DEFAULT4 | RT715_DMIC3)
  192. #define RT715_SET_DMIC4_CONFIG_DEFAULT4\
  193. (RT715_VERB_SET_CONFIG_DEFAULT4 | RT715_DMIC4)
  194. #define RT715_MUTE_SFT 7
  195. #define RT715_DIR_IN_SFT 6
  196. #define RT715_DIR_OUT_SFT 7
  197. enum {
  198. RT715_AIF1,
  199. RT715_AIF2,
  200. RT715_AIFS,
  201. };
  202. #define RT715_POWER_UP_DELAY_MS 400
  203. int rt715_io_init(struct device *dev, struct sdw_slave *slave);
  204. int rt715_init(struct device *dev, struct regmap *sdw_regmap,
  205. struct regmap *regmap, struct sdw_slave *slave);
  206. int hda_to_sdw(unsigned int nid, unsigned int verb, unsigned int payload,
  207. unsigned int *sdw_addr_h, unsigned int *sdw_data_h,
  208. unsigned int *sdw_addr_l, unsigned int *sdw_data_l);
  209. int rt715_clock_config(struct device *dev);
  210. #endif /* __RT715_H__ */