rt5514.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * rt5514.h -- RT5514 ALSA SoC audio driver
  3. *
  4. * Copyright 2015 Realtek Microelectronics
  5. * Author: Oder Chiou <oder_chiou@realtek.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef __RT5514_H__
  12. #define __RT5514_H__
  13. #include <linux/clk.h>
  14. #define RT5514_DEVICE_ID 0x10ec5514
  15. #define RT5514_RESET 0x2000
  16. #define RT5514_PWR_ANA1 0x2004
  17. #define RT5514_PWR_ANA2 0x2008
  18. #define RT5514_I2S_CTRL1 0x2010
  19. #define RT5514_I2S_CTRL2 0x2014
  20. #define RT5514_VAD_CTRL6 0x2030
  21. #define RT5514_EXT_VAD_CTRL 0x206c
  22. #define RT5514_DIG_IO_CTRL 0x2070
  23. #define RT5514_PAD_CTRL1 0x2080
  24. #define RT5514_DMIC_DATA_CTRL 0x20a0
  25. #define RT5514_DIG_SOURCE_CTRL 0x20a4
  26. #define RT5514_SRC_CTRL 0x20ac
  27. #define RT5514_DOWNFILTER2_CTRL1 0x20d0
  28. #define RT5514_PLL_SOURCE_CTRL 0x2100
  29. #define RT5514_CLK_CTRL1 0x2104
  30. #define RT5514_CLK_CTRL2 0x2108
  31. #define RT5514_PLL3_CALIB_CTRL1 0x2110
  32. #define RT5514_PLL3_CALIB_CTRL5 0x2124
  33. #define RT5514_DELAY_BUF_CTRL1 0x2140
  34. #define RT5514_DELAY_BUF_CTRL3 0x2148
  35. #define RT5514_DOWNFILTER0_CTRL1 0x2190
  36. #define RT5514_DOWNFILTER0_CTRL2 0x2194
  37. #define RT5514_DOWNFILTER0_CTRL3 0x2198
  38. #define RT5514_DOWNFILTER1_CTRL1 0x21a0
  39. #define RT5514_DOWNFILTER1_CTRL2 0x21a4
  40. #define RT5514_DOWNFILTER1_CTRL3 0x21a8
  41. #define RT5514_ANA_CTRL_LDO10 0x2200
  42. #define RT5514_ANA_CTRL_LDO18_16 0x2204
  43. #define RT5514_ANA_CTRL_ADC12 0x2210
  44. #define RT5514_ANA_CTRL_ADC21 0x2214
  45. #define RT5514_ANA_CTRL_ADC22 0x2218
  46. #define RT5514_ANA_CTRL_ADC23 0x221c
  47. #define RT5514_ANA_CTRL_MICBST 0x2220
  48. #define RT5514_ANA_CTRL_ADCFED 0x2224
  49. #define RT5514_ANA_CTRL_INBUF 0x2228
  50. #define RT5514_ANA_CTRL_VREF 0x222c
  51. #define RT5514_ANA_CTRL_PLL3 0x2240
  52. #define RT5514_ANA_CTRL_PLL1_1 0x2260
  53. #define RT5514_ANA_CTRL_PLL1_2 0x2264
  54. #define RT5514_DMIC_LP_CTRL 0x2e00
  55. #define RT5514_MISC_CTRL_DSP 0x2e04
  56. #define RT5514_DSP_CTRL1 0x2f00
  57. #define RT5514_DSP_CTRL3 0x2f08
  58. #define RT5514_DSP_CTRL4 0x2f10
  59. #define RT5514_VENDOR_ID1 0x2ff0
  60. #define RT5514_VENDOR_ID2 0x2ff4
  61. #define RT5514_DSP_MAPPING 0x18000000
  62. /* RT5514_PWR_ANA1 (0x2004) */
  63. #define RT5514_POW_LDO18_IN (0x1 << 5)
  64. #define RT5514_POW_LDO18_IN_BIT 5
  65. #define RT5514_POW_LDO18_ADC (0x1 << 4)
  66. #define RT5514_POW_LDO18_ADC_BIT 4
  67. #define RT5514_POW_LDO21 (0x1 << 3)
  68. #define RT5514_POW_LDO21_BIT 3
  69. #define RT5514_POW_BG_LDO18_IN (0x1 << 2)
  70. #define RT5514_POW_BG_LDO18_IN_BIT 2
  71. #define RT5514_POW_BG_LDO21 (0x1 << 1)
  72. #define RT5514_POW_BG_LDO21_BIT 1
  73. /* RT5514_PWR_ANA2 (0x2008) */
  74. #define RT5514_POW_PLL1 (0x1 << 18)
  75. #define RT5514_POW_PLL1_BIT 18
  76. #define RT5514_POW_PLL1_LDO (0x1 << 16)
  77. #define RT5514_POW_PLL1_LDO_BIT 16
  78. #define RT5514_POW_BG_MBIAS (0x1 << 15)
  79. #define RT5514_POW_BG_MBIAS_BIT 15
  80. #define RT5514_POW_MBIAS (0x1 << 14)
  81. #define RT5514_POW_MBIAS_BIT 14
  82. #define RT5514_POW_VREF2 (0x1 << 13)
  83. #define RT5514_POW_VREF2_BIT 13
  84. #define RT5514_POW_VREF1 (0x1 << 12)
  85. #define RT5514_POW_VREF1_BIT 12
  86. #define RT5514_POWR_LDO16 (0x1 << 11)
  87. #define RT5514_POWR_LDO16_BIT 11
  88. #define RT5514_POWL_LDO16 (0x1 << 10)
  89. #define RT5514_POWL_LDO16_BIT 10
  90. #define RT5514_POW_ADC2 (0x1 << 9)
  91. #define RT5514_POW_ADC2_BIT 9
  92. #define RT5514_POW_INPUT_BUF (0x1 << 8)
  93. #define RT5514_POW_INPUT_BUF_BIT 8
  94. #define RT5514_POW_ADC1_R (0x1 << 7)
  95. #define RT5514_POW_ADC1_R_BIT 7
  96. #define RT5514_POW_ADC1_L (0x1 << 6)
  97. #define RT5514_POW_ADC1_L_BIT 6
  98. #define RT5514_POW2_BSTR (0x1 << 5)
  99. #define RT5514_POW2_BSTR_BIT 5
  100. #define RT5514_POW2_BSTL (0x1 << 4)
  101. #define RT5514_POW2_BSTL_BIT 4
  102. #define RT5514_POW_BSTR (0x1 << 3)
  103. #define RT5514_POW_BSTR_BIT 3
  104. #define RT5514_POW_BSTL (0x1 << 2)
  105. #define RT5514_POW_BSTL_BIT 2
  106. #define RT5514_POW_ADCFEDR (0x1 << 1)
  107. #define RT5514_POW_ADCFEDR_BIT 1
  108. #define RT5514_POW_ADCFEDL (0x1 << 0)
  109. #define RT5514_POW_ADCFEDL_BIT 0
  110. /* RT5514_I2S_CTRL1 (0x2010) */
  111. #define RT5514_TDM_MODE (0x1 << 28)
  112. #define RT5514_TDM_MODE_SFT 28
  113. #define RT5514_I2S_LR_MASK (0x1 << 26)
  114. #define RT5514_I2S_LR_SFT 26
  115. #define RT5514_I2S_LR_NOR (0x0 << 26)
  116. #define RT5514_I2S_LR_INV (0x1 << 26)
  117. #define RT5514_I2S_BP_MASK (0x1 << 25)
  118. #define RT5514_I2S_BP_SFT 25
  119. #define RT5514_I2S_BP_NOR (0x0 << 25)
  120. #define RT5514_I2S_BP_INV (0x1 << 25)
  121. #define RT5514_I2S_DF_MASK (0x7 << 16)
  122. #define RT5514_I2S_DF_SFT 16
  123. #define RT5514_I2S_DF_I2S (0x0 << 16)
  124. #define RT5514_I2S_DF_LEFT (0x1 << 16)
  125. #define RT5514_I2S_DF_PCM_A (0x2 << 16)
  126. #define RT5514_I2S_DF_PCM_B (0x3 << 16)
  127. #define RT5514_TDMSLOT_SEL_RX_MASK (0x3 << 10)
  128. #define RT5514_TDMSLOT_SEL_RX_SFT 10
  129. #define RT5514_TDMSLOT_SEL_RX_4CH (0x1 << 10)
  130. #define RT5514_CH_LEN_RX_MASK (0x3 << 8)
  131. #define RT5514_CH_LEN_RX_SFT 8
  132. #define RT5514_CH_LEN_RX_16 (0x0 << 8)
  133. #define RT5514_CH_LEN_RX_20 (0x1 << 8)
  134. #define RT5514_CH_LEN_RX_24 (0x2 << 8)
  135. #define RT5514_CH_LEN_RX_32 (0x3 << 8)
  136. #define RT5514_TDMSLOT_SEL_TX_MASK (0x3 << 6)
  137. #define RT5514_TDMSLOT_SEL_TX_SFT 6
  138. #define RT5514_TDMSLOT_SEL_TX_4CH (0x1 << 6)
  139. #define RT5514_CH_LEN_TX_MASK (0x3 << 4)
  140. #define RT5514_CH_LEN_TX_SFT 4
  141. #define RT5514_CH_LEN_TX_16 (0x0 << 4)
  142. #define RT5514_CH_LEN_TX_20 (0x1 << 4)
  143. #define RT5514_CH_LEN_TX_24 (0x2 << 4)
  144. #define RT5514_CH_LEN_TX_32 (0x3 << 4)
  145. #define RT5514_I2S_DL_MASK (0x3 << 0)
  146. #define RT5514_I2S_DL_SFT 0
  147. #define RT5514_I2S_DL_16 (0x0 << 0)
  148. #define RT5514_I2S_DL_20 (0x1 << 0)
  149. #define RT5514_I2S_DL_24 (0x2 << 0)
  150. #define RT5514_I2S_DL_8 (0x3 << 0)
  151. /* RT5514_DIG_SOURCE_CTRL (0x20a4) */
  152. #define RT5514_AD1_DMIC_INPUT_SEL (0x1 << 1)
  153. #define RT5514_AD1_DMIC_INPUT_SEL_SFT 1
  154. #define RT5514_AD0_DMIC_INPUT_SEL (0x1 << 0)
  155. #define RT5514_AD0_DMIC_INPUT_SEL_SFT 0
  156. /* RT5514_PLL_SOURCE_CTRL (0x2100) */
  157. #define RT5514_PLL_1_SEL_MASK (0x7 << 12)
  158. #define RT5514_PLL_1_SEL_SFT 12
  159. #define RT5514_PLL_1_SEL_SCLK (0x3 << 12)
  160. #define RT5514_PLL_1_SEL_MCLK (0x4 << 12)
  161. /* RT5514_CLK_CTRL1 (0x2104) */
  162. #define RT5514_CLK_AD_ANA1_EN (0x1 << 31)
  163. #define RT5514_CLK_AD_ANA1_EN_BIT 31
  164. #define RT5514_CLK_AD1_EN (0x1 << 24)
  165. #define RT5514_CLK_AD1_EN_BIT 24
  166. #define RT5514_CLK_AD0_EN (0x1 << 23)
  167. #define RT5514_CLK_AD0_EN_BIT 23
  168. #define RT5514_CLK_DMIC_OUT_SEL_MASK (0x7 << 8)
  169. #define RT5514_CLK_DMIC_OUT_SEL_SFT 8
  170. /* RT5514_CLK_CTRL2 (0x2108) */
  171. #define RT5514_CLK_SYS_DIV_OUT_MASK (0x7 << 8)
  172. #define RT5514_CLK_SYS_DIV_OUT_SFT 8
  173. #define RT5514_SEL_ADC_OSR_MASK (0x7 << 4)
  174. #define RT5514_SEL_ADC_OSR_SFT 4
  175. #define RT5514_CLK_SYS_PRE_SEL_MASK (0x3 << 0)
  176. #define RT5514_CLK_SYS_PRE_SEL_SFT 0
  177. #define RT5514_CLK_SYS_PRE_SEL_MCLK (0x2 << 0)
  178. #define RT5514_CLK_SYS_PRE_SEL_PLL (0x3 << 0)
  179. /* RT5514_DOWNFILTER_CTRL (0x2190 0x2194 0x21a0 0x21a4) */
  180. #define RT5514_AD_DMIC_MIX (0x1 << 11)
  181. #define RT5514_AD_DMIC_MIX_BIT 11
  182. #define RT5514_AD_AD_MIX (0x1 << 10)
  183. #define RT5514_AD_AD_MIX_BIT 10
  184. #define RT5514_AD_AD_MUTE (0x1 << 7)
  185. #define RT5514_AD_AD_MUTE_BIT 7
  186. #define RT5514_AD_GAIN_MASK (0x3f << 1)
  187. #define RT5514_AD_GAIN_SFT 1
  188. /* RT5514_ANA_CTRL_MICBST (0x2220) */
  189. #define RT5514_SEL_BSTL_MASK (0xf << 4)
  190. #define RT5514_SEL_BSTL_SFT 4
  191. #define RT5514_SEL_BSTR_MASK (0xf << 0)
  192. #define RT5514_SEL_BSTR_SFT 0
  193. /* RT5514_ANA_CTRL_PLL1_1 (0x2260) */
  194. #define RT5514_PLL_K_MAX 0x1f
  195. #define RT5514_PLL_K_MASK (RT5514_PLL_K_MAX << 16)
  196. #define RT5514_PLL_K_SFT 16
  197. #define RT5514_PLL_N_MAX 0x1ff
  198. #define RT5514_PLL_N_MASK (RT5514_PLL_N_MAX << 7)
  199. #define RT5514_PLL_N_SFT 4
  200. #define RT5514_PLL_M_MAX 0xf
  201. #define RT5514_PLL_M_MASK (RT5514_PLL_M_MAX << 0)
  202. #define RT5514_PLL_M_SFT 0
  203. /* RT5514_ANA_CTRL_PLL1_2 (0x2264) */
  204. #define RT5514_PLL_M_BP (0x1 << 2)
  205. #define RT5514_PLL_M_BP_SFT 2
  206. #define RT5514_PLL_K_BP (0x1 << 1)
  207. #define RT5514_PLL_K_BP_SFT 1
  208. #define RT5514_EN_LDO_PLL1 (0x1 << 0)
  209. #define RT5514_EN_LDO_PLL1_BIT 0
  210. #define RT5514_PLL_INP_MAX 40000000
  211. #define RT5514_PLL_INP_MIN 256000
  212. #define RT5514_FIRMWARE1 "/*(DEBLOBBED)*/"
  213. #define RT5514_FIRMWARE2 "/*(DEBLOBBED)*/"
  214. /* System Clock Source */
  215. enum {
  216. RT5514_SCLK_S_MCLK,
  217. RT5514_SCLK_S_PLL1,
  218. };
  219. /* PLL1 Source */
  220. enum {
  221. RT5514_PLL1_S_MCLK,
  222. RT5514_PLL1_S_BCLK,
  223. };
  224. struct rt5514_priv {
  225. struct snd_soc_codec *codec;
  226. struct regmap *i2c_regmap, *regmap;
  227. struct clk *mclk;
  228. int sysclk;
  229. int sysclk_src;
  230. int lrck;
  231. int bclk;
  232. int pll_src;
  233. int pll_in;
  234. int pll_out;
  235. int dsp_enabled;
  236. };
  237. #endif /* __RT5514_H__ */