rt711.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * rt711.h -- RT711 ALSA SoC audio driver header
  4. *
  5. * Copyright(c) 2019 Realtek Semiconductor Corp.
  6. */
  7. #ifndef __RT711_H__
  8. #define __RT711_H__
  9. extern const struct dev_pm_ops rt711_runtime_pm;
  10. struct rt711_priv {
  11. struct regmap *regmap;
  12. struct regmap *sdw_regmap;
  13. struct snd_soc_component *component;
  14. struct sdw_slave *slave;
  15. enum sdw_slave_status status;
  16. struct sdw_bus_params params;
  17. bool hw_init;
  18. bool first_hw_init;
  19. struct snd_soc_jack *hs_jack;
  20. struct delayed_work jack_detect_work;
  21. struct delayed_work jack_btn_check_work;
  22. struct work_struct calibration_work;
  23. struct mutex calibrate_mutex; /* for headset calibration */
  24. int jack_type, jd_src;
  25. };
  26. struct sdw_stream_data {
  27. struct sdw_stream_runtime *sdw_stream;
  28. };
  29. /* NID */
  30. #define RT711_AUDIO_FUNCTION_GROUP 0x01
  31. #define RT711_DAC_OUT2 0x03
  32. #define RT711_ADC_IN1 0x09
  33. #define RT711_ADC_IN2 0x08
  34. #define RT711_DMIC1 0x12
  35. #define RT711_DMIC2 0x13
  36. #define RT711_MIC2 0x19
  37. #define RT711_LINE1 0x1a
  38. #define RT711_LINE2 0x1b
  39. #define RT711_BEEP 0x1d
  40. #define RT711_VENDOR_REG 0x20
  41. #define RT711_HP_OUT 0x21
  42. #define RT711_MIXER_IN1 0x22
  43. #define RT711_MIXER_IN2 0x23
  44. #define RT711_INLINE_CMD 0x55
  45. #define RT711_VENDOR_CALI 0x58
  46. #define RT711_VENDOR_IMS_DRE 0x5b
  47. /* Index (NID:20h) */
  48. #define RT711_DAC_DC_CALI_CTL1 0x00
  49. #define RT711_JD_CTL2 0x09
  50. #define RT711_CC_DET1 0x11
  51. #define RT711_PARA_VERB_CTL 0x1a
  52. #define RT711_COMBO_JACK_AUTO_CTL1 0x45
  53. #define RT711_COMBO_JACK_AUTO_CTL2 0x46
  54. #define RT711_INLINE_CMD_CTL 0x48
  55. #define RT711_DIGITAL_MISC_CTRL4 0x4a
  56. #define RT711_VREFOUT_CTL 0x6b
  57. #define RT711_FSM_CTL 0x6f
  58. #define RT711_IRQ_FLAG_TABLE1 0x80
  59. #define RT711_IRQ_FLAG_TABLE2 0x81
  60. #define RT711_IRQ_FLAG_TABLE3 0x82
  61. #define RT711_TX_RX_MUX_CTL 0x91
  62. /* Index (NID:5bh) */
  63. #define RT711_IMS_DIGITAL_CTL1 0x00
  64. #define RT711_HP_IMS_RESULT_L 0x20
  65. #define RT711_HP_IMS_RESULT_R 0x21
  66. /* Verb */
  67. #define RT711_VERB_SET_CONNECT_SEL 0x3100
  68. #define RT711_VERB_SET_EAPD_BTLENABLE 0x3c00
  69. #define RT711_VERB_GET_CONNECT_SEL 0xb100
  70. #define RT711_VERB_SET_POWER_STATE 0x3500
  71. #define RT711_VERB_SET_CHANNEL_STREAMID 0x3600
  72. #define RT711_VERB_SET_PIN_WIDGET_CONTROL 0x3700
  73. #define RT711_VERB_SET_UNSOLICITED_ENABLE 0x3800
  74. #define RT711_SET_AMP_GAIN_MUTE_H 0x7300
  75. #define RT711_SET_AMP_GAIN_MUTE_L 0x8380
  76. #define RT711_VERB_GET_POWER_STATE 0xb500
  77. #define RT711_VERB_GET_CHANNEL_STREAMID 0xb600
  78. #define RT711_VERB_GET_PIN_SENSE 0xb900
  79. #define RT711_FUNC_RESET 0xff01
  80. #define RT711_READ_HDA_3 0x2012
  81. #define RT711_READ_HDA_2 0x2013
  82. #define RT711_READ_HDA_1 0x2014
  83. #define RT711_READ_HDA_0 0x2015
  84. #define RT711_PRIV_INDEX_W_H 0x7500
  85. #define RT711_PRIV_INDEX_W_L 0x8580
  86. #define RT711_PRIV_DATA_W_H 0x7400
  87. #define RT711_PRIV_DATA_W_L 0x8480
  88. #define RT711_PRIV_INDEX_R_H 0x9d00
  89. #define RT711_PRIV_INDEX_R_L 0xad80
  90. #define RT711_PRIV_DATA_R_H 0x9c00
  91. #define RT711_PRIV_DATA_R_L 0xac80
  92. #define RT711_DAC_FORMAT_H 0x7203
  93. #define RT711_DAC_FORMAT_L 0x8283
  94. #define RT711_ADC1_FORMAT_H 0x7209
  95. #define RT711_ADC1_FORMAT_L 0x8289
  96. #define RT711_ADC2_FORMAT_H 0x7208
  97. #define RT711_ADC2_FORMAT_L 0x8288
  98. #define RT711_SET_AUDIO_POWER_STATE\
  99. (RT711_VERB_SET_POWER_STATE | RT711_AUDIO_FUNCTION_GROUP)
  100. #define RT711_GET_AUDIO_POWER_STATE\
  101. (RT711_VERB_GET_POWER_STATE | RT711_AUDIO_FUNCTION_GROUP)
  102. #define RT711_SET_PIN_DMIC1\
  103. (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_DMIC1)
  104. #define RT711_SET_PIN_DMIC2\
  105. (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_DMIC2)
  106. #define RT711_SET_PIN_HP\
  107. (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_HP_OUT)
  108. #define RT711_SET_PIN_MIC2\
  109. (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_MIC2)
  110. #define RT711_SET_PIN_LINE1\
  111. (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_LINE1)
  112. #define RT711_SET_PIN_LINE2\
  113. (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_LINE2)
  114. #define RT711_SET_MIC2_UNSOLICITED_ENABLE\
  115. (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_MIC2)
  116. #define RT711_SET_HP_UNSOLICITED_ENABLE\
  117. (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_HP_OUT)
  118. #define RT711_SET_INLINE_UNSOLICITED_ENABLE\
  119. (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_INLINE_CMD)
  120. #define RT711_SET_STREAMID_DAC2\
  121. (RT711_VERB_SET_CHANNEL_STREAMID | RT711_DAC_OUT2)
  122. #define RT711_SET_STREAMID_ADC1\
  123. (RT711_VERB_SET_CHANNEL_STREAMID | RT711_ADC_IN1)
  124. #define RT711_SET_STREAMID_ADC2\
  125. (RT711_VERB_SET_CHANNEL_STREAMID | RT711_ADC_IN2)
  126. #define RT711_GET_STREAMID_DAC2\
  127. (RT711_VERB_GET_CHANNEL_STREAMID | RT711_DAC_OUT2)
  128. #define RT711_GET_STREAMID_ADC1\
  129. (RT711_VERB_GET_CHANNEL_STREAMID | RT711_ADC_IN1)
  130. #define RT711_GET_STREAMID_ADC2\
  131. (RT711_VERB_GET_CHANNEL_STREAMID | RT711_ADC_IN2)
  132. #define RT711_SET_GAIN_DAC2_L\
  133. (RT711_SET_AMP_GAIN_MUTE_L | RT711_DAC_OUT2)
  134. #define RT711_SET_GAIN_DAC2_H\
  135. (RT711_SET_AMP_GAIN_MUTE_H | RT711_DAC_OUT2)
  136. #define RT711_SET_GAIN_ADC1_L\
  137. (RT711_SET_AMP_GAIN_MUTE_L | RT711_ADC_IN1)
  138. #define RT711_SET_GAIN_ADC1_H\
  139. (RT711_SET_AMP_GAIN_MUTE_H | RT711_ADC_IN1)
  140. #define RT711_SET_GAIN_ADC2_L\
  141. (RT711_SET_AMP_GAIN_MUTE_L | RT711_ADC_IN2)
  142. #define RT711_SET_GAIN_ADC2_H\
  143. (RT711_SET_AMP_GAIN_MUTE_H | RT711_ADC_IN2)
  144. #define RT711_SET_GAIN_AMIC_L\
  145. (RT711_SET_AMP_GAIN_MUTE_L | RT711_MIC2)
  146. #define RT711_SET_GAIN_AMIC_H\
  147. (RT711_SET_AMP_GAIN_MUTE_H | RT711_MIC2)
  148. #define RT711_SET_GAIN_DMIC1_L\
  149. (RT711_SET_AMP_GAIN_MUTE_L | RT711_DMIC1)
  150. #define RT711_SET_GAIN_DMIC1_H\
  151. (RT711_SET_AMP_GAIN_MUTE_H | RT711_DMIC1)
  152. #define RT711_SET_GAIN_DMIC2_L\
  153. (RT711_SET_AMP_GAIN_MUTE_L | RT711_DMIC2)
  154. #define RT711_SET_GAIN_DMIC2_H\
  155. (RT711_SET_AMP_GAIN_MUTE_H | RT711_DMIC2)
  156. #define RT711_SET_GAIN_HP_L\
  157. (RT711_SET_AMP_GAIN_MUTE_L | RT711_HP_OUT)
  158. #define RT711_SET_GAIN_HP_H\
  159. (RT711_SET_AMP_GAIN_MUTE_H | RT711_HP_OUT)
  160. /* DAC DC offset calibration control-1 (0x00)(NID:20h) */
  161. #define RT711_DAC_DC_CALI_TRIGGER (0x1 << 15)
  162. /* jack detect control 2 (0x09)(NID:20h) */
  163. #define RT711_JD2_2PORT_200K_DECODE_HP (0x1 << 13)
  164. #define RT711_HP_JD_SEL_JD1 (0x0 << 1)
  165. #define RT711_HP_JD_SEL_JD2 (0x1 << 1)
  166. /* CC DET1 (0x11)(NID:20h) */
  167. #define RT711_HP_JD_FINAL_RESULT_CTL_JD12 (0x1 << 10)
  168. #define RT711_HP_JD_FINAL_RESULT_CTL_CCDET (0x0 << 10)
  169. /* Parameter & Verb control (0x1a)(NID:20h) */
  170. #define RT711_HIDDEN_REG_SW_RESET (0x1 << 14)
  171. /* combo jack auto switch control 2 (0x46)(NID:20h) */
  172. #define RT711_COMBOJACK_AUTO_DET_STATUS (0x1 << 11)
  173. #define RT711_COMBOJACK_AUTO_DET_TRS (0x1 << 10)
  174. #define RT711_COMBOJACK_AUTO_DET_CTIA (0x1 << 9)
  175. #define RT711_COMBOJACK_AUTO_DET_OMTP (0x1 << 8)
  176. /* FSM control (0x6f)(NID:20h) */
  177. #define RT711_CALI_CTL (0x0 << 0)
  178. #define RT711_COMBOJACK_CTL (0x1 << 0)
  179. #define RT711_IMS_CTL (0x2 << 0)
  180. #define RT711_DEPOP_CTL (0x3 << 0)
  181. /* Impedance Sense Digital Control 1 (0x00)(NID:5bh) */
  182. #define RT711_TRIGGER_IMS (0x1 << 15)
  183. #define RT711_IMS_EN (0x1 << 6)
  184. #define RT711_EAPD_HIGH 0x2
  185. #define RT711_EAPD_LOW 0x0
  186. #define RT711_MUTE_SFT 7
  187. /* set input/output mapping to payload[14][15] separately */
  188. #define RT711_DIR_IN_SFT 6
  189. #define RT711_DIR_OUT_SFT 7
  190. enum {
  191. RT711_AIF1,
  192. RT711_AIF2,
  193. RT711_AIFS,
  194. };
  195. enum rt711_jd_src {
  196. RT711_JD_NULL,
  197. RT711_JD1,
  198. RT711_JD2
  199. };
  200. int rt711_io_init(struct device *dev, struct sdw_slave *slave);
  201. int rt711_init(struct device *dev, struct regmap *sdw_regmap,
  202. struct regmap *regmap, struct sdw_slave *slave);
  203. int rt711_jack_detect(struct rt711_priv *rt711, bool *hp, bool *mic);
  204. int rt711_clock_config(struct device *dev);
  205. #endif /* __RT711_H__ */