nau8825.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * NAU8825 ALSA SoC audio driver
  3. *
  4. * Copyright 2015 Google Inc.
  5. * Author: Anatol Pomozov <anatol.pomozov@chrominium.org>
  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 __NAU8825_H__
  12. #define __NAU8825_H__
  13. #define NAU8825_REG_RESET 0x00
  14. #define NAU8825_REG_ENA_CTRL 0x01
  15. #define NAU8825_REG_CLK_DIVIDER 0x03
  16. #define NAU8825_REG_FLL1 0x04
  17. #define NAU8825_REG_FLL2 0x05
  18. #define NAU8825_REG_FLL3 0x06
  19. #define NAU8825_REG_FLL4 0x07
  20. #define NAU8825_REG_FLL5 0x08
  21. #define NAU8825_REG_FLL6 0x09
  22. #define NAU8825_REG_FLL_VCO_RSV 0x0a
  23. #define NAU8825_REG_HSD_CTRL 0x0c
  24. #define NAU8825_REG_JACK_DET_CTRL 0x0d
  25. #define NAU8825_REG_INTERRUPT_MASK 0x0f
  26. #define NAU8825_REG_IRQ_STATUS 0x10
  27. #define NAU8825_REG_INT_CLR_KEY_STATUS 0x11
  28. #define NAU8825_REG_INTERRUPT_DIS_CTRL 0x12
  29. #define NAU8825_REG_SAR_CTRL 0x13
  30. #define NAU8825_REG_KEYDET_CTRL 0x14
  31. #define NAU8825_REG_VDET_THRESHOLD_1 0x15
  32. #define NAU8825_REG_VDET_THRESHOLD_2 0x16
  33. #define NAU8825_REG_VDET_THRESHOLD_3 0x17
  34. #define NAU8825_REG_VDET_THRESHOLD_4 0x18
  35. #define NAU8825_REG_GPIO34_CTRL 0x19
  36. #define NAU8825_REG_GPIO12_CTRL 0x1a
  37. #define NAU8825_REG_TDM_CTRL 0x1b
  38. #define NAU8825_REG_I2S_PCM_CTRL1 0x1c
  39. #define NAU8825_REG_I2S_PCM_CTRL2 0x1d
  40. #define NAU8825_REG_LEFT_TIME_SLOT 0x1e
  41. #define NAU8825_REG_RIGHT_TIME_SLOT 0x1f
  42. #define NAU8825_REG_BIQ_CTRL 0x20
  43. #define NAU8825_REG_BIQ_COF1 0x21
  44. #define NAU8825_REG_BIQ_COF2 0x22
  45. #define NAU8825_REG_BIQ_COF3 0x23
  46. #define NAU8825_REG_BIQ_COF4 0x24
  47. #define NAU8825_REG_BIQ_COF5 0x25
  48. #define NAU8825_REG_BIQ_COF6 0x26
  49. #define NAU8825_REG_BIQ_COF7 0x27
  50. #define NAU8825_REG_BIQ_COF8 0x28
  51. #define NAU8825_REG_BIQ_COF9 0x29
  52. #define NAU8825_REG_BIQ_COF10 0x2a
  53. #define NAU8825_REG_ADC_RATE 0x2b
  54. #define NAU8825_REG_DAC_CTRL1 0x2c
  55. #define NAU8825_REG_DAC_CTRL2 0x2d
  56. #define NAU8825_REG_DAC_DGAIN_CTRL 0x2f
  57. #define NAU8825_REG_ADC_DGAIN_CTRL 0x30
  58. #define NAU8825_REG_MUTE_CTRL 0x31
  59. #define NAU8825_REG_HSVOL_CTRL 0x32
  60. #define NAU8825_REG_DACL_CTRL 0x33
  61. #define NAU8825_REG_DACR_CTRL 0x34
  62. #define NAU8825_REG_ADC_DRC_KNEE_IP12 0x38
  63. #define NAU8825_REG_ADC_DRC_KNEE_IP34 0x39
  64. #define NAU8825_REG_ADC_DRC_SLOPES 0x3a
  65. #define NAU8825_REG_ADC_DRC_ATKDCY 0x3b
  66. #define NAU8825_REG_DAC_DRC_KNEE_IP12 0x45
  67. #define NAU8825_REG_DAC_DRC_KNEE_IP34 0x46
  68. #define NAU8825_REG_DAC_DRC_SLOPES 0x47
  69. #define NAU8825_REG_DAC_DRC_ATKDCY 0x48
  70. #define NAU8825_REG_IMM_MODE_CTRL 0x4c
  71. #define NAU8825_REG_IMM_RMS_L 0x4d
  72. #define NAU8825_REG_IMM_RMS_R 0x4e
  73. #define NAU8825_REG_CLASSG_CTRL 0x50
  74. #define NAU8825_REG_OPT_EFUSE_CTRL 0x51
  75. #define NAU8825_REG_MISC_CTRL 0x55
  76. #define NAU8825_REG_I2C_DEVICE_ID 0x58
  77. #define NAU8825_REG_SARDOUT_RAM_STATUS 0x59
  78. #define NAU8825_REG_BIAS_ADJ 0x66
  79. #define NAU8825_REG_TRIM_SETTINGS 0x68
  80. #define NAU8825_REG_ANALOG_CONTROL_1 0x69
  81. #define NAU8825_REG_ANALOG_CONTROL_2 0x6a
  82. #define NAU8825_REG_ANALOG_ADC_1 0x71
  83. #define NAU8825_REG_ANALOG_ADC_2 0x72
  84. #define NAU8825_REG_RDAC 0x73
  85. #define NAU8825_REG_MIC_BIAS 0x74
  86. #define NAU8825_REG_BOOST 0x76
  87. #define NAU8825_REG_FEPGA 0x77
  88. #define NAU8825_REG_POWER_UP_CONTROL 0x7f
  89. #define NAU8825_REG_CHARGE_PUMP 0x80
  90. #define NAU8825_REG_CHARGE_PUMP_INPUT_READ 0x81
  91. #define NAU8825_REG_GENERAL_STATUS 0x82
  92. #define NAU8825_REG_MAX NAU8825_REG_GENERAL_STATUS
  93. /* ENA_CTRL (0x1) */
  94. #define NAU8825_ENABLE_DACR_SFT 10
  95. #define NAU8825_ENABLE_DACR (1 << NAU8825_ENABLE_DACR_SFT)
  96. #define NAU8825_ENABLE_DACL_SFT 9
  97. #define NAU8825_ENABLE_ADC_SFT 8
  98. #define NAU8825_ENABLE_SAR_SFT 1
  99. /* CLK_DIVIDER (0x3) */
  100. #define NAU8825_CLK_SRC_SFT 15
  101. #define NAU8825_CLK_SRC_MASK (1 << NAU8825_CLK_SRC_SFT)
  102. #define NAU8825_CLK_SRC_VCO (1 << NAU8825_CLK_SRC_SFT)
  103. #define NAU8825_CLK_SRC_MCLK (0 << NAU8825_CLK_SRC_SFT)
  104. #define NAU8825_CLK_MCLK_SRC_MASK (0xf << 0)
  105. /* FLL1 (0x04) */
  106. #define NAU8825_FLL_RATIO_MASK (0x7f << 0)
  107. /* FLL3 (0x06) */
  108. #define NAU8825_FLL_INTEGER_MASK (0x3ff << 0)
  109. /* FLL4 (0x07) */
  110. #define NAU8825_FLL_REF_DIV_SFT 10
  111. #define NAU8825_FLL_REF_DIV_MASK (0x3 << NAU8825_FLL_REF_DIV_SFT)
  112. /* FLL5 (0x08) */
  113. #define NAU8825_FLL_FILTER_SW_MASK (0x1 << 14)
  114. /* FLL6 (0x9) */
  115. #define NAU8825_DCO_EN_MASK (0x1 << 15)
  116. #define NAU8825_DCO_EN (0x1 << 15)
  117. #define NAU8825_DCO_DIS (0x0 << 15)
  118. #define NAU8825_SDM_EN_MASK (0x1 << 14)
  119. #define NAU8825_SDM_EN (0x1 << 14)
  120. #define NAU8825_SDM_DIS (0x0 << 14)
  121. /* HSD_CTRL (0xc) */
  122. #define NAU8825_HSD_AUTO_MODE (1 << 6)
  123. /* 0 - short to GND, 1 - open */
  124. #define NAU8825_SPKR_DWN1R (1 << 1)
  125. #define NAU8825_SPKR_DWN1L (1 << 0)
  126. /* JACK_DET_CTRL (0xd) */
  127. #define NAU8825_JACK_DET_RESTART (1 << 9)
  128. #define NAU8825_JACK_INSERT_DEBOUNCE_SFT 5
  129. #define NAU8825_JACK_INSERT_DEBOUNCE_MASK (0x7 << NAU8825_JACK_INSERT_DEBOUNCE_SFT)
  130. #define NAU8825_JACK_EJECT_DEBOUNCE_SFT 2
  131. #define NAU8825_JACK_EJECT_DEBOUNCE_MASK (0x7 << NAU8825_JACK_EJECT_DEBOUNCE_SFT)
  132. #define NAU8825_JACK_POLARITY (1 << 1) /* 0 - active low, 1 - active high */
  133. /* INTERRUPT_MASK (0xf) */
  134. #define NAU8825_IRQ_OUTPUT_EN (1 << 11)
  135. #define NAU8825_IRQ_HEADSET_COMPLETE_EN (1 << 10)
  136. #define NAU8825_IRQ_KEY_RELEASE_EN (1 << 7)
  137. #define NAU8825_IRQ_KEY_SHORT_PRESS_EN (1 << 5)
  138. #define NAU8825_IRQ_EJECT_EN (1 << 2)
  139. /* IRQ_STATUS (0x10) */
  140. #define NAU8825_HEADSET_COMPLETION_IRQ (1 << 10)
  141. #define NAU8825_SHORT_CIRCUIT_IRQ (1 << 9)
  142. #define NAU8825_IMPEDANCE_MEAS_IRQ (1 << 8)
  143. #define NAU8825_KEY_IRQ_MASK (0x7 << 5)
  144. #define NAU8825_KEY_RELEASE_IRQ (1 << 7)
  145. #define NAU8825_KEY_LONG_PRESS_IRQ (1 << 6)
  146. #define NAU8825_KEY_SHORT_PRESS_IRQ (1 << 5)
  147. #define NAU8825_MIC_DETECTION_IRQ (1 << 4)
  148. #define NAU8825_JACK_EJECTION_IRQ_MASK (3 << 2)
  149. #define NAU8825_JACK_EJECTION_DETECTED (1 << 2)
  150. #define NAU8825_JACK_INSERTION_IRQ_MASK (3 << 0)
  151. #define NAU8825_JACK_INSERTION_DETECTED (1 << 0)
  152. /* INTERRUPT_DIS_CTRL (0x12) */
  153. #define NAU8825_IRQ_HEADSET_COMPLETE_DIS (1 << 10)
  154. #define NAU8825_IRQ_KEY_RELEASE_DIS (1 << 7)
  155. #define NAU8825_IRQ_KEY_SHORT_PRESS_DIS (1 << 5)
  156. #define NAU8825_IRQ_EJECT_DIS (1 << 2)
  157. /* SAR_CTRL (0x13) */
  158. #define NAU8825_SAR_ADC_EN_SFT 12
  159. #define NAU8825_SAR_ADC_EN (1 << NAU8825_SAR_ADC_EN_SFT)
  160. #define NAU8825_SAR_INPUT_MASK (1 << 11)
  161. #define NAU8825_SAR_INPUT_JKSLV (1 << 11)
  162. #define NAU8825_SAR_INPUT_JKR2 (0 << 11)
  163. #define NAU8825_SAR_TRACKING_GAIN_SFT 8
  164. #define NAU8825_SAR_TRACKING_GAIN_MASK (0x7 << NAU8825_SAR_TRACKING_GAIN_SFT)
  165. #define NAU8825_SAR_COMPARE_TIME_SFT 2
  166. #define NAU8825_SAR_COMPARE_TIME_MASK (3 << 2)
  167. #define NAU8825_SAR_SAMPLING_TIME_SFT 0
  168. #define NAU8825_SAR_SAMPLING_TIME_MASK (3 << 0)
  169. /* KEYDET_CTRL (0x14) */
  170. #define NAU8825_KEYDET_SHORTKEY_DEBOUNCE_SFT 12
  171. #define NAU8825_KEYDET_SHORTKEY_DEBOUNCE_MASK (0x3 << NAU8825_KEYDET_SHORTKEY_DEBOUNCE_SFT)
  172. #define NAU8825_KEYDET_LEVELS_NR_SFT 8
  173. #define NAU8825_KEYDET_LEVELS_NR_MASK (0x7 << 8)
  174. #define NAU8825_KEYDET_HYSTERESIS_SFT 0
  175. #define NAU8825_KEYDET_HYSTERESIS_MASK 0xf
  176. /* GPIO12_CTRL (0x1a) */
  177. #define NAU8825_JKDET_PULL_UP (1 << 11) /* 0 - pull down, 1 - pull up */
  178. #define NAU8825_JKDET_PULL_EN (1 << 9) /* 0 - enable pull, 1 - disable */
  179. #define NAU8825_JKDET_OUTPUT_EN (1 << 8) /* 0 - enable input, 1 - enable output */
  180. /* I2S_PCM_CTRL1 (0x1c) */
  181. #define NAU8825_I2S_BP_SFT 7
  182. #define NAU8825_I2S_BP_MASK (1 << NAU8825_I2S_BP_SFT)
  183. #define NAU8825_I2S_BP_INV (1 << NAU8825_I2S_BP_SFT)
  184. #define NAU8825_I2S_PCMB_SFT 6
  185. #define NAU8825_I2S_PCMB_MASK (1 << NAU8825_I2S_PCMB_SFT)
  186. #define NAU8825_I2S_PCMB_EN (1 << NAU8825_I2S_PCMB_SFT)
  187. #define NAU8825_I2S_DL_SFT 2
  188. #define NAU8825_I2S_DL_MASK (0x3 << NAU8825_I2S_DL_SFT)
  189. #define NAU8825_I2S_DL_16 (0 << NAU8825_I2S_DL_SFT)
  190. #define NAU8825_I2S_DL_20 (1 << NAU8825_I2S_DL_SFT)
  191. #define NAU8825_I2S_DL_24 (2 << NAU8825_I2S_DL_SFT)
  192. #define NAU8825_I2S_DL_32 (3 << NAU8825_I2S_DL_SFT)
  193. #define NAU8825_I2S_DF_SFT 0
  194. #define NAU8825_I2S_DF_MASK (0x3 << NAU8825_I2S_DF_SFT)
  195. #define NAU8825_I2S_DF_RIGTH (0 << NAU8825_I2S_DF_SFT)
  196. #define NAU8825_I2S_DF_LEFT (1 << NAU8825_I2S_DF_SFT)
  197. #define NAU8825_I2S_DF_I2S (2 << NAU8825_I2S_DF_SFT)
  198. #define NAU8825_I2S_DF_PCM_AB (3 << NAU8825_I2S_DF_SFT)
  199. /* I2S_PCM_CTRL2 (0x1d) */
  200. #define NAU8825_I2S_TRISTATE (1 << 15) /* 0 - normal mode, 1 - Hi-Z output */
  201. #define NAU8825_I2S_MS_SFT 3
  202. #define NAU8825_I2S_MS_MASK (1 << NAU8825_I2S_MS_SFT)
  203. #define NAU8825_I2S_MS_MASTER (1 << NAU8825_I2S_MS_SFT)
  204. #define NAU8825_I2S_MS_SLAVE (0 << NAU8825_I2S_MS_SFT)
  205. /* ADC_RATE (0x2b) */
  206. #define NAU8825_ADC_SYNC_DOWN_SFT 0
  207. #define NAU8825_ADC_SYNC_DOWN_MASK 0x3
  208. #define NAU8825_ADC_SYNC_DOWN_32 0
  209. #define NAU8825_ADC_SYNC_DOWN_64 1
  210. #define NAU8825_ADC_SYNC_DOWN_128 2
  211. #define NAU8825_ADC_SYNC_DOWN_256 3
  212. /* DAC_CTRL1 (0x2c) */
  213. #define NAU8825_DAC_CLIP_OFF (1 << 7)
  214. #define NAU8825_DAC_OVERSAMPLE_SFT 0
  215. #define NAU8825_DAC_OVERSAMPLE_MASK 0x7
  216. #define NAU8825_DAC_OVERSAMPLE_64 0
  217. #define NAU8825_DAC_OVERSAMPLE_256 1
  218. #define NAU8825_DAC_OVERSAMPLE_128 2
  219. #define NAU8825_DAC_OVERSAMPLE_32 4
  220. /* MUTE_CTRL (0x31) */
  221. #define NAU8825_DAC_ZERO_CROSSING_EN (1 << 9)
  222. #define NAU8825_DAC_SOFT_MUTE (1 << 9)
  223. /* HSVOL_CTRL (0x32) */
  224. #define NAU8825_HP_MUTE (1 << 15)
  225. /* DACL_CTRL (0x33) */
  226. #define NAU8825_DACL_CH_SEL_SFT 9
  227. /* DACR_CTRL (0x34) */
  228. #define NAU8825_DACR_CH_SEL_SFT 9
  229. /* I2C_DEVICE_ID (0x58) */
  230. #define NAU8825_GPIO2JD1 (1 << 7)
  231. #define NAU8825_SOFTWARE_ID_MASK 0x3
  232. #define NAU8825_SOFTWARE_ID_NAU8825 0x0
  233. /* BIAS_ADJ (0x66) */
  234. #define NAU8825_BIAS_VMID (1 << 6)
  235. #define NAU8825_BIAS_VMID_SEL_SFT 4
  236. #define NAU8825_BIAS_VMID_SEL_MASK (3 << NAU8825_BIAS_VMID_SEL_SFT)
  237. /* ANALOG_CONTROL_2 (0x6a) */
  238. #define NAU8825_HP_NON_CLASSG_CURRENT_2xADJ (1 << 12)
  239. #define NAU8825_DAC_CAPACITOR_MSB (1 << 1)
  240. #define NAU8825_DAC_CAPACITOR_LSB (1 << 0)
  241. /* ANALOG_ADC_2 (0x72) */
  242. #define NAU8825_ADC_VREFSEL_MASK (0x3 << 8)
  243. #define NAU8825_ADC_VREFSEL_ANALOG (0 << 8)
  244. #define NAU8825_ADC_VREFSEL_VMID (1 << 8)
  245. #define NAU8825_ADC_VREFSEL_VMID_PLUS_0_5DB (2 << 8)
  246. #define NAU8825_ADC_VREFSEL_VMID_PLUS_1DB (3 << 8)
  247. #define NAU8825_POWERUP_ADCL (1 << 6)
  248. /* MIC_BIAS (0x74) */
  249. #define NAU8825_MICBIAS_JKSLV (1 << 14)
  250. #define NAU8825_MICBIAS_JKR2 (1 << 12)
  251. #define NAU8825_MICBIAS_POWERUP_SFT 8
  252. #define NAU8825_MICBIAS_VOLTAGE_SFT 0
  253. #define NAU8825_MICBIAS_VOLTAGE_MASK 0x7
  254. /* BOOST (0x76) */
  255. #define NAU8825_PRECHARGE_DIS (1 << 13)
  256. #define NAU8825_GLOBAL_BIAS_EN (1 << 12)
  257. #define NAU8825_HP_BOOST_G_DIS (1 << 8)
  258. #define NAU8825_SHORT_SHUTDOWN_EN (1 << 6)
  259. /* POWER_UP_CONTROL (0x7f) */
  260. #define NAU8825_POWERUP_INTEGR_R (1 << 5)
  261. #define NAU8825_POWERUP_INTEGR_L (1 << 4)
  262. #define NAU8825_POWERUP_DRV_IN_R (1 << 3)
  263. #define NAU8825_POWERUP_DRV_IN_L (1 << 2)
  264. #define NAU8825_POWERUP_HP_DRV_R (1 << 1)
  265. #define NAU8825_POWERUP_HP_DRV_L (1 << 0)
  266. /* CHARGE_PUMP (0x80) */
  267. #define NAU8825_JAMNODCLOW (1 << 10)
  268. #define NAU8825_POWER_DOWN_DACR (1 << 9)
  269. #define NAU8825_POWER_DOWN_DACL (1 << 8)
  270. #define NAU8825_CHANRGE_PUMP_EN (1 << 5)
  271. /* System Clock Source */
  272. enum {
  273. NAU8825_CLK_MCLK = 0,
  274. NAU8825_CLK_INTERNAL,
  275. };
  276. struct nau8825 {
  277. struct device *dev;
  278. struct regmap *regmap;
  279. struct snd_soc_dapm_context *dapm;
  280. struct snd_soc_jack *jack;
  281. struct clk *mclk;
  282. int irq;
  283. int mclk_freq; /* 0 - mclk is disabled */
  284. int button_pressed;
  285. int micbias_voltage;
  286. int vref_impedance;
  287. bool jkdet_enable;
  288. bool jkdet_pull_enable;
  289. bool jkdet_pull_up;
  290. int jkdet_polarity;
  291. int sar_threshold_num;
  292. int sar_threshold[8];
  293. int sar_hysteresis;
  294. int sar_voltage;
  295. int sar_compare_time;
  296. int sar_sampling_time;
  297. int key_debounce;
  298. int jack_insert_debounce;
  299. int jack_eject_debounce;
  300. };
  301. int nau8825_enable_jack_detect(struct snd_soc_codec *codec,
  302. struct snd_soc_jack *jack);
  303. #endif /* __NAU8825_H__ */