da7213.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /*
  2. * da7213.h - DA7213 ASoC Codec Driver
  3. *
  4. * Copyright (c) 2013 Dialog Semiconductor
  5. *
  6. * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef _DA7213_H
  13. #define _DA7213_H
  14. #include <linux/clk.h>
  15. #include <linux/regmap.h>
  16. #include <sound/da7213.h>
  17. /*
  18. * Registers
  19. */
  20. /* Status Registers */
  21. #define DA7213_STATUS1 0x02
  22. #define DA7213_PLL_STATUS 0x03
  23. #define DA7213_AUX_L_GAIN_STATUS 0x04
  24. #define DA7213_AUX_R_GAIN_STATUS 0x05
  25. #define DA7213_MIC_1_GAIN_STATUS 0x06
  26. #define DA7213_MIC_2_GAIN_STATUS 0x07
  27. #define DA7213_MIXIN_L_GAIN_STATUS 0x08
  28. #define DA7213_MIXIN_R_GAIN_STATUS 0x09
  29. #define DA7213_ADC_L_GAIN_STATUS 0x0A
  30. #define DA7213_ADC_R_GAIN_STATUS 0x0B
  31. #define DA7213_DAC_L_GAIN_STATUS 0x0C
  32. #define DA7213_DAC_R_GAIN_STATUS 0x0D
  33. #define DA7213_HP_L_GAIN_STATUS 0x0E
  34. #define DA7213_HP_R_GAIN_STATUS 0x0F
  35. #define DA7213_LINE_GAIN_STATUS 0x10
  36. /* System Initialisation Registers */
  37. #define DA7213_DIG_ROUTING_DAI 0x21
  38. #define DA7213_SR 0x22
  39. #define DA7213_REFERENCES 0x23
  40. #define DA7213_PLL_FRAC_TOP 0x24
  41. #define DA7213_PLL_FRAC_BOT 0x25
  42. #define DA7213_PLL_INTEGER 0x26
  43. #define DA7213_PLL_CTRL 0x27
  44. #define DA7213_DAI_CLK_MODE 0x28
  45. #define DA7213_DAI_CTRL 0x29
  46. #define DA7213_DIG_ROUTING_DAC 0x2A
  47. #define DA7213_ALC_CTRL1 0x2B
  48. /* Input - Gain, Select and Filter Registers */
  49. #define DA7213_AUX_L_GAIN 0x30
  50. #define DA7213_AUX_R_GAIN 0x31
  51. #define DA7213_MIXIN_L_SELECT 0x32
  52. #define DA7213_MIXIN_R_SELECT 0x33
  53. #define DA7213_MIXIN_L_GAIN 0x34
  54. #define DA7213_MIXIN_R_GAIN 0x35
  55. #define DA7213_ADC_L_GAIN 0x36
  56. #define DA7213_ADC_R_GAIN 0x37
  57. #define DA7213_ADC_FILTERS1 0x38
  58. #define DA7213_MIC_1_GAIN 0x39
  59. #define DA7213_MIC_2_GAIN 0x3A
  60. /* Output - Gain, Select and Filter Registers */
  61. #define DA7213_DAC_FILTERS5 0x40
  62. #define DA7213_DAC_FILTERS2 0x41
  63. #define DA7213_DAC_FILTERS3 0x42
  64. #define DA7213_DAC_FILTERS4 0x43
  65. #define DA7213_DAC_FILTERS1 0x44
  66. #define DA7213_DAC_L_GAIN 0x45
  67. #define DA7213_DAC_R_GAIN 0x46
  68. #define DA7213_CP_CTRL 0x47
  69. #define DA7213_HP_L_GAIN 0x48
  70. #define DA7213_HP_R_GAIN 0x49
  71. #define DA7213_LINE_GAIN 0x4A
  72. #define DA7213_MIXOUT_L_SELECT 0x4B
  73. #define DA7213_MIXOUT_R_SELECT 0x4C
  74. /* System Controller Registers */
  75. #define DA7213_SYSTEM_MODES_INPUT 0x50
  76. #define DA7213_SYSTEM_MODES_OUTPUT 0x51
  77. /* Control Registers */
  78. #define DA7213_AUX_L_CTRL 0x60
  79. #define DA7213_AUX_R_CTRL 0x61
  80. #define DA7213_MICBIAS_CTRL 0x62
  81. #define DA7213_MIC_1_CTRL 0x63
  82. #define DA7213_MIC_2_CTRL 0x64
  83. #define DA7213_MIXIN_L_CTRL 0x65
  84. #define DA7213_MIXIN_R_CTRL 0x66
  85. #define DA7213_ADC_L_CTRL 0x67
  86. #define DA7213_ADC_R_CTRL 0x68
  87. #define DA7213_DAC_L_CTRL 0x69
  88. #define DA7213_DAC_R_CTRL 0x6A
  89. #define DA7213_HP_L_CTRL 0x6B
  90. #define DA7213_HP_R_CTRL 0x6C
  91. #define DA7213_LINE_CTRL 0x6D
  92. #define DA7213_MIXOUT_L_CTRL 0x6E
  93. #define DA7213_MIXOUT_R_CTRL 0x6F
  94. /* Configuration Registers */
  95. #define DA7213_LDO_CTRL 0x90
  96. #define DA7213_IO_CTRL 0x91
  97. #define DA7213_GAIN_RAMP_CTRL 0x92
  98. #define DA7213_MIC_CONFIG 0x93
  99. #define DA7213_PC_COUNT 0x94
  100. #define DA7213_CP_VOL_THRESHOLD1 0x95
  101. #define DA7213_CP_DELAY 0x96
  102. #define DA7213_CP_DETECTOR 0x97
  103. #define DA7213_DAI_OFFSET 0x98
  104. #define DA7213_DIG_CTRL 0x99
  105. #define DA7213_ALC_CTRL2 0x9A
  106. #define DA7213_ALC_CTRL3 0x9B
  107. #define DA7213_ALC_NOISE 0x9C
  108. #define DA7213_ALC_TARGET_MIN 0x9D
  109. #define DA7213_ALC_TARGET_MAX 0x9E
  110. #define DA7213_ALC_GAIN_LIMITS 0x9F
  111. #define DA7213_ALC_ANA_GAIN_LIMITS 0xA0
  112. #define DA7213_ALC_ANTICLIP_CTRL 0xA1
  113. #define DA7213_ALC_ANTICLIP_LEVEL 0xA2
  114. #define DA7213_ALC_OFFSET_AUTO_M_L 0xA3
  115. #define DA7213_ALC_OFFSET_AUTO_U_L 0xA4
  116. #define DA7213_ALC_OFFSET_MAN_M_L 0xA6
  117. #define DA7213_ALC_OFFSET_MAN_U_L 0xA7
  118. #define DA7213_ALC_OFFSET_AUTO_M_R 0xA8
  119. #define DA7213_ALC_OFFSET_AUTO_U_R 0xA9
  120. #define DA7213_ALC_OFFSET_MAN_M_R 0xAB
  121. #define DA7213_ALC_OFFSET_MAN_U_R 0xAC
  122. #define DA7213_ALC_CIC_OP_LVL_CTRL 0xAD
  123. #define DA7213_ALC_CIC_OP_LVL_DATA 0xAE
  124. #define DA7213_DAC_NG_SETUP_TIME 0xAF
  125. #define DA7213_DAC_NG_OFF_THRESHOLD 0xB0
  126. #define DA7213_DAC_NG_ON_THRESHOLD 0xB1
  127. #define DA7213_DAC_NG_CTRL 0xB2
  128. /*
  129. * Bit fields
  130. */
  131. /* DA7213_PLL_STATUS = 0x03 */
  132. #define DA7219_PLL_SRM_LOCK (0x1 << 1)
  133. /* DA7213_SR = 0x22 */
  134. #define DA7213_SR_8000 (0x1 << 0)
  135. #define DA7213_SR_11025 (0x2 << 0)
  136. #define DA7213_SR_12000 (0x3 << 0)
  137. #define DA7213_SR_16000 (0x5 << 0)
  138. #define DA7213_SR_22050 (0x6 << 0)
  139. #define DA7213_SR_24000 (0x7 << 0)
  140. #define DA7213_SR_32000 (0x9 << 0)
  141. #define DA7213_SR_44100 (0xA << 0)
  142. #define DA7213_SR_48000 (0xB << 0)
  143. #define DA7213_SR_88200 (0xE << 0)
  144. #define DA7213_SR_96000 (0xF << 0)
  145. /* DA7213_REFERENCES = 0x23 */
  146. #define DA7213_BIAS_EN (0x1 << 3)
  147. #define DA7213_VMID_EN (0x1 << 7)
  148. /* DA7213_PLL_CTRL = 0x27 */
  149. #define DA7213_PLL_INDIV_5_TO_9_MHZ (0x0 << 2)
  150. #define DA7213_PLL_INDIV_9_TO_18_MHZ (0x1 << 2)
  151. #define DA7213_PLL_INDIV_18_TO_36_MHZ (0x2 << 2)
  152. #define DA7213_PLL_INDIV_36_TO_54_MHZ (0x3 << 2)
  153. #define DA7213_PLL_INDIV_MASK (0x3 << 2)
  154. #define DA7213_PLL_MCLK_SQR_EN (0x1 << 4)
  155. #define DA7213_PLL_32K_MODE (0x1 << 5)
  156. #define DA7213_PLL_SRM_EN (0x1 << 6)
  157. #define DA7213_PLL_EN (0x1 << 7)
  158. #define DA7213_PLL_MODE_MASK (0x7 << 5)
  159. /* DA7213_DAI_CLK_MODE = 0x28 */
  160. #define DA7213_DAI_BCLKS_PER_WCLK_32 (0x0 << 0)
  161. #define DA7213_DAI_BCLKS_PER_WCLK_64 (0x1 << 0)
  162. #define DA7213_DAI_BCLKS_PER_WCLK_128 (0x2 << 0)
  163. #define DA7213_DAI_BCLKS_PER_WCLK_256 (0x3 << 0)
  164. #define DA7213_DAI_BCLKS_PER_WCLK_MASK (0x3 << 0)
  165. #define DA7213_DAI_CLK_POL_INV (0x1 << 2)
  166. #define DA7213_DAI_WCLK_POL_INV (0x1 << 3)
  167. #define DA7213_DAI_CLK_EN_MASK (0x1 << 7)
  168. /* DA7213_DAI_CTRL = 0x29 */
  169. #define DA7213_DAI_FORMAT_I2S_MODE (0x0 << 0)
  170. #define DA7213_DAI_FORMAT_LEFT_J (0x1 << 0)
  171. #define DA7213_DAI_FORMAT_RIGHT_J (0x2 << 0)
  172. #define DA7213_DAI_FORMAT_MASK (0x3 << 0)
  173. #define DA7213_DAI_WORD_LENGTH_S16_LE (0x0 << 2)
  174. #define DA7213_DAI_WORD_LENGTH_S20_LE (0x1 << 2)
  175. #define DA7213_DAI_WORD_LENGTH_S24_LE (0x2 << 2)
  176. #define DA7213_DAI_WORD_LENGTH_S32_LE (0x3 << 2)
  177. #define DA7213_DAI_WORD_LENGTH_MASK (0x3 << 2)
  178. #define DA7213_DAI_EN_SHIFT 7
  179. /* DA7213_DIG_ROUTING_DAI = 0x21 */
  180. #define DA7213_DAI_L_SRC_SHIFT 0
  181. #define DA7213_DAI_R_SRC_SHIFT 4
  182. #define DA7213_DAI_SRC_MAX 4
  183. /* DA7213_DIG_ROUTING_DAC = 0x2A */
  184. #define DA7213_DAC_L_SRC_SHIFT 0
  185. #define DA7213_DAC_L_MONO_SHIFT 3
  186. #define DA7213_DAC_R_SRC_SHIFT 4
  187. #define DA7213_DAC_R_MONO_SHIFT 7
  188. #define DA7213_DAC_SRC_MAX 4
  189. #define DA7213_DAC_MONO_MAX 0x1
  190. /* DA7213_ALC_CTRL1 = 0x2B */
  191. #define DA7213_ALC_OFFSET_EN_SHIFT 0
  192. #define DA7213_ALC_OFFSET_EN_MAX 0x1
  193. #define DA7213_ALC_OFFSET_EN (0x1 << 0)
  194. #define DA7213_ALC_SYNC_MODE (0x1 << 1)
  195. #define DA7213_ALC_CALIB_MODE_MAN (0x1 << 2)
  196. #define DA7213_ALC_L_EN_SHIFT 3
  197. #define DA7213_ALC_AUTO_CALIB_EN (0x1 << 4)
  198. #define DA7213_ALC_CALIB_OVERFLOW (0x1 << 5)
  199. #define DA7213_ALC_R_EN_SHIFT 7
  200. #define DA7213_ALC_EN_MAX 0x1
  201. /* DA7213_AUX_L/R_GAIN = 0x30/0x31 */
  202. #define DA7213_AUX_AMP_GAIN_SHIFT 0
  203. #define DA7213_AUX_AMP_GAIN_MAX 0x3F
  204. /* DA7213_MIXIN_L/R_SELECT = 0x32/0x33 */
  205. #define DA7213_DMIC_EN_SHIFT 7
  206. #define DA7213_DMIC_EN_MAX 0x1
  207. /* DA7213_MIXIN_L_SELECT = 0x32 */
  208. #define DA7213_MIXIN_L_MIX_SELECT_AUX_L_SHIFT 0
  209. #define DA7213_MIXIN_L_MIX_SELECT_MIC_1_SHIFT 1
  210. #define DA7213_MIXIN_L_MIX_SELECT_MIC_1 (0x1 << 1)
  211. #define DA7213_MIXIN_L_MIX_SELECT_MIC_2_SHIFT 2
  212. #define DA7213_MIXIN_L_MIX_SELECT_MIC_2 (0x1 << 2)
  213. #define DA7213_MIXIN_L_MIX_SELECT_MIXIN_R_SHIFT 3
  214. #define DA7213_MIXIN_L_MIX_SELECT_MAX 0x1
  215. /* DA7213_MIXIN_R_SELECT = 0x33 */
  216. #define DA7213_MIXIN_R_MIX_SELECT_AUX_R_SHIFT 0
  217. #define DA7213_MIXIN_R_MIX_SELECT_MIC_2_SHIFT 1
  218. #define DA7213_MIXIN_R_MIX_SELECT_MIC_2 (0x1 << 1)
  219. #define DA7213_MIXIN_R_MIX_SELECT_MIC_1_SHIFT 2
  220. #define DA7213_MIXIN_R_MIX_SELECT_MIC_1 (0x1 << 2)
  221. #define DA7213_MIXIN_R_MIX_SELECT_MIXIN_L_SHIFT 3
  222. #define DA7213_MIXIN_R_MIX_SELECT_MAX 0x1
  223. #define DA7213_MIC_BIAS_OUTPUT_SELECT_2 (0x1 << 6)
  224. /* DA7213_MIXIN_L/R_GAIN = 0x34/0x35 */
  225. #define DA7213_MIXIN_AMP_GAIN_SHIFT 0
  226. #define DA7213_MIXIN_AMP_GAIN_MAX 0xF
  227. /* DA7213_ADC_L/R_GAIN = 0x36/0x37 */
  228. #define DA7213_ADC_AMP_GAIN_SHIFT 0
  229. #define DA7213_ADC_AMP_GAIN_MAX 0x7F
  230. /* DA7213_ADC/DAC_FILTERS1 = 0x38/0x44 */
  231. #define DA7213_VOICE_HPF_CORNER_SHIFT 0
  232. #define DA7213_VOICE_HPF_CORNER_MAX 8
  233. #define DA7213_VOICE_EN_SHIFT 3
  234. #define DA7213_VOICE_EN_MAX 0x1
  235. #define DA7213_AUDIO_HPF_CORNER_SHIFT 4
  236. #define DA7213_AUDIO_HPF_CORNER_MAX 4
  237. #define DA7213_HPF_EN_SHIFT 7
  238. #define DA7213_HPF_EN_MAX 0x1
  239. /* DA7213_MIC_1/2_GAIN = 0x39/0x3A */
  240. #define DA7213_MIC_AMP_GAIN_SHIFT 0
  241. #define DA7213_MIC_AMP_GAIN_MAX 0x7
  242. /* DA7213_DAC_FILTERS5 = 0x40 */
  243. #define DA7213_DAC_SOFTMUTE_EN_SHIFT 7
  244. #define DA7213_DAC_SOFTMUTE_EN_MAX 0x1
  245. #define DA7213_DAC_SOFTMUTE_RATE_SHIFT 4
  246. #define DA7213_DAC_SOFTMUTE_RATE_MAX 7
  247. /* DA7213_DAC_FILTERS2/3/4 = 0x41/0x42/0x43 */
  248. #define DA7213_DAC_EQ_BAND_MAX 0xF
  249. /* DA7213_DAC_FILTERS2 = 0x41 */
  250. #define DA7213_DAC_EQ_BAND1_SHIFT 0
  251. #define DA7213_DAC_EQ_BAND2_SHIFT 4
  252. /* DA7213_DAC_FILTERS2 = 0x42 */
  253. #define DA7213_DAC_EQ_BAND3_SHIFT 0
  254. #define DA7213_DAC_EQ_BAND4_SHIFT 4
  255. /* DA7213_DAC_FILTERS4 = 0x43 */
  256. #define DA7213_DAC_EQ_BAND5_SHIFT 0
  257. #define DA7213_DAC_EQ_EN_SHIFT 7
  258. #define DA7213_DAC_EQ_EN_MAX 0x1
  259. /* DA7213_DAC_L/R_GAIN = 0x45/0x46 */
  260. #define DA7213_DAC_AMP_GAIN_SHIFT 0
  261. #define DA7213_DAC_AMP_GAIN_MAX 0x7F
  262. /* DA7213_HP_L/R_GAIN = 0x45/0x46 */
  263. #define DA7213_HP_AMP_GAIN_SHIFT 0
  264. #define DA7213_HP_AMP_GAIN_MAX 0x3F
  265. /* DA7213_CP_CTRL = 0x47 */
  266. #define DA7213_CP_EN_SHIFT 7
  267. /* DA7213_LINE_GAIN = 0x4A */
  268. #define DA7213_LINE_AMP_GAIN_SHIFT 0
  269. #define DA7213_LINE_AMP_GAIN_MAX 0x3F
  270. /* DA7213_MIXOUT_L_SELECT = 0x4B */
  271. #define DA7213_MIXOUT_L_MIX_SELECT_AUX_L_SHIFT 0
  272. #define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_SHIFT 1
  273. #define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_SHIFT 2
  274. #define DA7213_MIXOUT_L_MIX_SELECT_DAC_L_SHIFT 3
  275. #define DA7213_MIXOUT_L_MIX_SELECT_AUX_L_INVERTED_SHIFT 4
  276. #define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_INVERTED_SHIFT 5
  277. #define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_INVERTED_SHIFT 6
  278. #define DA7213_MIXOUT_L_MIX_SELECT_MAX 0x1
  279. /* DA7213_MIXOUT_R_SELECT = 0x4C */
  280. #define DA7213_MIXOUT_R_MIX_SELECT_AUX_R_SHIFT 0
  281. #define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_SHIFT 1
  282. #define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_SHIFT 2
  283. #define DA7213_MIXOUT_R_MIX_SELECT_DAC_R_SHIFT 3
  284. #define DA7213_MIXOUT_R_MIX_SELECT_AUX_R_INVERTED_SHIFT 4
  285. #define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_INVERTED_SHIFT 5
  286. #define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_INVERTED_SHIFT 6
  287. #define DA7213_MIXOUT_R_MIX_SELECT_MAX 0x1
  288. /*
  289. * DA7213_AUX_L/R_CTRL = 0x60/0x61,
  290. * DA7213_MIC_1/2_CTRL = 0x63/0x64,
  291. * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
  292. * DA7213_ADC_L/R_CTRL = 0x65/0x66,
  293. * DA7213_DAC_L/R_CTRL = 0x69/0x6A,
  294. * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
  295. * DA7213_LINE_CTRL = 0x6D
  296. */
  297. #define DA7213_MUTE_EN_SHIFT 6
  298. #define DA7213_MUTE_EN_MAX 0x1
  299. #define DA7213_MUTE_EN (0x1 << 6)
  300. /*
  301. * DA7213_AUX_L/R_CTRL = 0x60/0x61,
  302. * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
  303. * DA7213_ADC_L/R_CTRL = 0x65/0x66,
  304. * DA7213_DAC_L/R_CTRL = 0x69/0x6A,
  305. * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
  306. * DA7213_LINE_CTRL = 0x6D
  307. */
  308. #define DA7213_GAIN_RAMP_EN_SHIFT 5
  309. #define DA7213_GAIN_RAMP_EN_MAX 0x1
  310. #define DA7213_GAIN_RAMP_EN (0x1 << 5)
  311. /*
  312. * DA7213_AUX_L/R_CTRL = 0x60/0x61,
  313. * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
  314. * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
  315. * DA7213_LINE_CTRL = 0x6D
  316. */
  317. #define DA7213_ZC_EN_SHIFT 4
  318. #define DA7213_ZC_EN_MAX 0x1
  319. /*
  320. * DA7213_AUX_L/R_CTRL = 0x60/0x61,
  321. * DA7213_MIC_1/2_CTRL = 0x63/0x64,
  322. * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
  323. * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
  324. * DA7213_MIXOUT_L/R_CTRL = 0x6E/0x6F,
  325. * DA7213_LINE_CTRL = 0x6D
  326. */
  327. #define DA7213_AMP_EN_SHIFT 7
  328. /* DA7213_MIC_1/2_CTRL = 0x63/0x64 */
  329. #define DA7213_MIC_AMP_IN_SEL_SHIFT 2
  330. #define DA7213_MIC_AMP_IN_SEL_MAX 3
  331. /* DA7213_MICBIAS_CTRL = 0x62 */
  332. #define DA7213_MICBIAS1_LEVEL_SHIFT 0
  333. #define DA7213_MICBIAS1_LEVEL_MASK (0x3 << 0)
  334. #define DA7213_MICBIAS1_EN_SHIFT 3
  335. #define DA7213_MICBIAS2_LEVEL_SHIFT 4
  336. #define DA7213_MICBIAS2_LEVEL_MASK (0x3 << 4)
  337. #define DA7213_MICBIAS2_EN_SHIFT 7
  338. /* DA7213_MIXIN_L/R_CTRL = 0x65/0x66 */
  339. #define DA7213_MIXIN_MIX_EN (0x1 << 3)
  340. /* DA7213_ADC_L/R_CTRL = 0x67/0x68 */
  341. #define DA7213_ADC_EN_SHIFT 7
  342. #define DA7213_ADC_EN (0x1 << 7)
  343. /* DA7213_DAC_L/R_CTRL = 0x69/0x6A*/
  344. #define DA7213_DAC_EN_SHIFT 7
  345. /* DA7213_HP_L/R_CTRL = 0x6B/0x6C */
  346. #define DA7213_HP_AMP_OE (0x1 << 3)
  347. /* DA7213_LINE_CTRL = 0x6D */
  348. #define DA7213_LINE_AMP_OE (0x1 << 3)
  349. /* DA7213_MIXOUT_L/R_CTRL = 0x6E/0x6F */
  350. #define DA7213_MIXOUT_MIX_EN (0x1 << 3)
  351. /* DA7213_GAIN_RAMP_CTRL = 0x92 */
  352. #define DA7213_GAIN_RAMP_RATE_SHIFT 0
  353. #define DA7213_GAIN_RAMP_RATE_MAX 4
  354. /* DA7213_MIC_CONFIG = 0x93 */
  355. #define DA7213_DMIC_DATA_SEL_SHIFT 0
  356. #define DA7213_DMIC_DATA_SEL_MASK (0x1 << 0)
  357. #define DA7213_DMIC_SAMPLEPHASE_SHIFT 1
  358. #define DA7213_DMIC_SAMPLEPHASE_MASK (0x1 << 1)
  359. #define DA7213_DMIC_CLK_RATE_SHIFT 2
  360. #define DA7213_DMIC_CLK_RATE_MASK (0x1 << 2)
  361. /* DA7213_PC_COUNT = 0x94 */
  362. #define DA7213_PC_FREERUN_MASK (0x1 << 0)
  363. /* DA7213_DIG_CTRL = 0x99 */
  364. #define DA7213_DAC_L_INV_SHIFT 3
  365. #define DA7213_DAC_R_INV_SHIFT 7
  366. #define DA7213_DAC_INV_MAX 0x1
  367. /* DA7213_ALC_CTRL2 = 0x9A */
  368. #define DA7213_ALC_ATTACK_SHIFT 0
  369. #define DA7213_ALC_ATTACK_MAX 13
  370. #define DA7213_ALC_RELEASE_SHIFT 4
  371. #define DA7213_ALC_RELEASE_MAX 11
  372. /* DA7213_ALC_CTRL3 = 0x9B */
  373. #define DA7213_ALC_HOLD_SHIFT 0
  374. #define DA7213_ALC_HOLD_MAX 16
  375. #define DA7213_ALC_INTEG_ATTACK_SHIFT 4
  376. #define DA7213_ALC_INTEG_RELEASE_SHIFT 6
  377. #define DA7213_ALC_INTEG_MAX 4
  378. /*
  379. * DA7213_ALC_NOISE = 0x9C,
  380. * DA7213_ALC_TARGET_MIN/MAX = 0x9D/0x9E
  381. */
  382. #define DA7213_ALC_THRESHOLD_SHIFT 0
  383. #define DA7213_ALC_THRESHOLD_MAX 0x3F
  384. /* DA7213_ALC_GAIN_LIMITS = 0x9F */
  385. #define DA7213_ALC_ATTEN_MAX_SHIFT 0
  386. #define DA7213_ALC_GAIN_MAX_SHIFT 4
  387. #define DA7213_ALC_ATTEN_GAIN_MAX_MAX 0xF
  388. /* DA7213_ALC_ANA_GAIN_LIMITS = 0xA0 */
  389. #define DA7213_ALC_ANA_GAIN_MIN_SHIFT 0
  390. #define DA7213_ALC_ANA_GAIN_MAX_SHIFT 4
  391. #define DA7213_ALC_ANA_GAIN_MAX 0x7
  392. /* DA7213_ALC_ANTICLIP_CTRL = 0xA1 */
  393. #define DA7213_ALC_ANTICLIP_EN_SHIFT 7
  394. #define DA7213_ALC_ANTICLIP_EN_MAX 0x1
  395. /* DA7213_ALC_ANTICLIP_LEVEL = 0xA2 */
  396. #define DA7213_ALC_ANTICLIP_LEVEL_SHIFT 0
  397. #define DA7213_ALC_ANTICLIP_LEVEL_MAX 0x7F
  398. /* DA7213_ALC_CIC_OP_LVL_CTRL = 0xAD */
  399. #define DA7213_ALC_DATA_MIDDLE (0x2 << 0)
  400. #define DA7213_ALC_DATA_TOP (0x3 << 0)
  401. #define DA7213_ALC_CIC_OP_CHANNEL_LEFT (0x0 << 7)
  402. #define DA7213_ALC_CIC_OP_CHANNEL_RIGHT (0x1 << 7)
  403. /* DA7213_DAC_NG_SETUP_TIME = 0xAF */
  404. #define DA7213_DAC_NG_SETUP_TIME_SHIFT 0
  405. #define DA7213_DAC_NG_SETUP_TIME_MAX 4
  406. #define DA7213_DAC_NG_RAMPUP_RATE_SHIFT 2
  407. #define DA7213_DAC_NG_RAMPDN_RATE_SHIFT 3
  408. #define DA7213_DAC_NG_RAMP_RATE_MAX 2
  409. /* DA7213_DAC_NG_OFF/ON_THRESH = 0xB0/0xB1 */
  410. #define DA7213_DAC_NG_THRESHOLD_SHIFT 0
  411. #define DA7213_DAC_NG_THRESHOLD_MAX 0x7
  412. /* DA7213_DAC_NG_CTRL = 0xB2 */
  413. #define DA7213_DAC_NG_EN_SHIFT 7
  414. #define DA7213_DAC_NG_EN_MAX 0x1
  415. /*
  416. * General defines
  417. */
  418. /* Register inversion */
  419. #define DA7213_NO_INVERT 0
  420. #define DA7213_INVERT 1
  421. /* Byte related defines */
  422. #define DA7213_BYTE_SHIFT 8
  423. #define DA7213_BYTE_MASK 0xFF
  424. /* ALC related */
  425. #define DA7213_ALC_OFFSET_15_8 0x00FF00
  426. #define DA7213_ALC_OFFSET_19_16 0x0F0000
  427. #define DA7213_ALC_AVG_ITERATIONS 5
  428. /* PLL related */
  429. #define DA7213_PLL_FREQ_OUT_90316800 90316800
  430. #define DA7213_PLL_FREQ_OUT_98304000 98304000
  431. #define DA7213_PLL_FREQ_OUT_94310400 94310400
  432. #define DA7213_PLL_INDIV_5_TO_9_MHZ_VAL 2
  433. #define DA7213_PLL_INDIV_9_TO_18_MHZ_VAL 4
  434. #define DA7213_PLL_INDIV_18_TO_36_MHZ_VAL 8
  435. #define DA7213_PLL_INDIV_36_TO_54_MHZ_VAL 16
  436. #define DA7213_SRM_CHECK_RETRIES 8
  437. enum da7213_clk_src {
  438. DA7213_CLKSRC_MCLK = 0,
  439. DA7213_CLKSRC_MCLK_SQR,
  440. };
  441. enum da7213_sys_clk {
  442. DA7213_SYSCLK_MCLK = 0,
  443. DA7213_SYSCLK_PLL,
  444. DA7213_SYSCLK_PLL_SRM,
  445. DA7213_SYSCLK_PLL_32KHZ
  446. };
  447. /* Codec private data */
  448. struct da7213_priv {
  449. struct regmap *regmap;
  450. struct clk *mclk;
  451. unsigned int mclk_rate;
  452. int clk_src;
  453. bool master;
  454. bool alc_calib_auto;
  455. bool alc_en;
  456. struct da7213_platform_data *pdata;
  457. };
  458. #endif /* _DA7213_H */