tlv320aic3x.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * ALSA SoC TLV320AIC3X codec driver
  3. *
  4. * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
  5. * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.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 _AIC3X_H
  12. #define _AIC3X_H
  13. /* AIC3X register space */
  14. #define AIC3X_CACHEREGNUM 103
  15. /* Page select register */
  16. #define AIC3X_PAGE_SELECT 0
  17. /* Software reset register */
  18. #define AIC3X_RESET 1
  19. /* Codec Sample rate select register */
  20. #define AIC3X_SAMPLE_RATE_SEL_REG 2
  21. /* PLL progrramming register A */
  22. #define AIC3X_PLL_PROGA_REG 3
  23. /* PLL progrramming register B */
  24. #define AIC3X_PLL_PROGB_REG 4
  25. /* PLL progrramming register C */
  26. #define AIC3X_PLL_PROGC_REG 5
  27. /* PLL progrramming register D */
  28. #define AIC3X_PLL_PROGD_REG 6
  29. /* Codec datapath setup register */
  30. #define AIC3X_CODEC_DATAPATH_REG 7
  31. /* Audio serial data interface control register A */
  32. #define AIC3X_ASD_INTF_CTRLA 8
  33. /* Audio serial data interface control register B */
  34. #define AIC3X_ASD_INTF_CTRLB 9
  35. /* Audio serial data interface control register C */
  36. #define AIC3X_ASD_INTF_CTRLC 10
  37. /* Audio overflow status and PLL R value programming register */
  38. #define AIC3X_OVRF_STATUS_AND_PLLR_REG 11
  39. /* Audio codec digital filter control register */
  40. #define AIC3X_CODEC_DFILT_CTRL 12
  41. /* Headset/button press detection register */
  42. #define AIC3X_HEADSET_DETECT_CTRL_A 13
  43. #define AIC3X_HEADSET_DETECT_CTRL_B 14
  44. /* ADC PGA Gain control registers */
  45. #define LADC_VOL 15
  46. #define RADC_VOL 16
  47. /* MIC3 control registers */
  48. #define MIC3LR_2_LADC_CTRL 17
  49. #define MIC3LR_2_RADC_CTRL 18
  50. /* Line1 Input control registers */
  51. #define LINE1L_2_LADC_CTRL 19
  52. #define LINE1R_2_LADC_CTRL 21
  53. #define LINE1R_2_RADC_CTRL 22
  54. #define LINE1L_2_RADC_CTRL 24
  55. /* Line2 Input control registers */
  56. #define LINE2L_2_LADC_CTRL 20
  57. #define LINE2R_2_RADC_CTRL 23
  58. /* MICBIAS Control Register */
  59. #define MICBIAS_CTRL 25
  60. /* AGC Control Registers A, B, C */
  61. #define LAGC_CTRL_A 26
  62. #define LAGC_CTRL_B 27
  63. #define LAGC_CTRL_C 28
  64. #define RAGC_CTRL_A 29
  65. #define RAGC_CTRL_B 30
  66. #define RAGC_CTRL_C 31
  67. /* DAC Power and Left High Power Output control registers */
  68. #define DAC_PWR 37
  69. #define HPLCOM_CFG 37
  70. /* Right High Power Output control registers */
  71. #define HPRCOM_CFG 38
  72. /* DAC Output Switching control registers */
  73. #define DAC_LINE_MUX 41
  74. /* High Power Output Driver Pop Reduction registers */
  75. #define HPOUT_POP_REDUCTION 42
  76. /* DAC Digital control registers */
  77. #define LDAC_VOL 43
  78. #define RDAC_VOL 44
  79. /* High Power Output control registers */
  80. #define LINE2L_2_HPLOUT_VOL 45
  81. #define LINE2R_2_HPROUT_VOL 62
  82. #define PGAL_2_HPLOUT_VOL 46
  83. #define PGAL_2_HPROUT_VOL 60
  84. #define PGAR_2_HPLOUT_VOL 49
  85. #define PGAR_2_HPROUT_VOL 63
  86. #define DACL1_2_HPLOUT_VOL 47
  87. #define DACR1_2_HPROUT_VOL 64
  88. #define HPLOUT_CTRL 51
  89. #define HPROUT_CTRL 65
  90. /* High Power COM control registers */
  91. #define LINE2L_2_HPLCOM_VOL 52
  92. #define LINE2R_2_HPRCOM_VOL 69
  93. #define PGAL_2_HPLCOM_VOL 53
  94. #define PGAR_2_HPLCOM_VOL 56
  95. #define PGAL_2_HPRCOM_VOL 67
  96. #define PGAR_2_HPRCOM_VOL 70
  97. #define DACL1_2_HPLCOM_VOL 54
  98. #define DACR1_2_HPRCOM_VOL 71
  99. #define HPLCOM_CTRL 58
  100. #define HPRCOM_CTRL 72
  101. /* Mono Line Output Plus/Minus control registers */
  102. #define LINE2L_2_MONOLOPM_VOL 73
  103. #define LINE2R_2_MONOLOPM_VOL 76
  104. #define PGAL_2_MONOLOPM_VOL 74
  105. #define PGAR_2_MONOLOPM_VOL 77
  106. #define DACL1_2_MONOLOPM_VOL 75
  107. #define DACR1_2_MONOLOPM_VOL 78
  108. #define MONOLOPM_CTRL 79
  109. /* Line Output Plus/Minus control registers */
  110. #define LINE2L_2_LLOPM_VOL 80
  111. #define LINE2L_2_RLOPM_VOL 87
  112. #define LINE2R_2_LLOPM_VOL 83
  113. #define LINE2R_2_RLOPM_VOL 90
  114. #define PGAL_2_LLOPM_VOL 81
  115. #define PGAL_2_RLOPM_VOL 88
  116. #define PGAR_2_LLOPM_VOL 84
  117. #define PGAR_2_RLOPM_VOL 91
  118. #define DACL1_2_LLOPM_VOL 82
  119. #define DACL1_2_RLOPM_VOL 89
  120. #define DACR1_2_RLOPM_VOL 92
  121. #define DACR1_2_LLOPM_VOL 85
  122. #define LLOPM_CTRL 86
  123. #define RLOPM_CTRL 93
  124. /* GPIO/IRQ registers */
  125. #define AIC3X_STICKY_IRQ_FLAGS_REG 96
  126. #define AIC3X_RT_IRQ_FLAGS_REG 97
  127. #define AIC3X_GPIO1_REG 98
  128. #define AIC3X_GPIO2_REG 99
  129. #define AIC3X_GPIOA_REG 100
  130. #define AIC3X_GPIOB_REG 101
  131. /* Clock generation control register */
  132. #define AIC3X_CLKGEN_CTRL_REG 102
  133. /* Page select register bits */
  134. #define PAGE0_SELECT 0
  135. #define PAGE1_SELECT 1
  136. /* Audio serial data interface control register A bits */
  137. #define BIT_CLK_MASTER 0x80
  138. #define WORD_CLK_MASTER 0x40
  139. /* Codec Datapath setup register 7 */
  140. #define FSREF_44100 (1 << 7)
  141. #define FSREF_48000 (0 << 7)
  142. #define DUAL_RATE_MODE ((1 << 5) | (1 << 6))
  143. #define LDAC2LCH (0x1 << 3)
  144. #define RDAC2RCH (0x1 << 1)
  145. /* PLL registers bitfields */
  146. #define PLLP_SHIFT 0
  147. #define PLLQ_SHIFT 3
  148. #define PLLR_SHIFT 0
  149. #define PLLJ_SHIFT 2
  150. #define PLLD_MSB_SHIFT 0
  151. #define PLLD_LSB_SHIFT 2
  152. /* Clock generation register bits */
  153. #define CODEC_CLKIN_PLLDIV 0
  154. #define CODEC_CLKIN_CLKDIV 1
  155. #define PLL_CLKIN_SHIFT 4
  156. #define MCLK_SOURCE 0x0
  157. #define PLL_CLKDIV_SHIFT 0
  158. /* Software reset register bits */
  159. #define SOFT_RESET 0x80
  160. /* PLL progrramming register A bits */
  161. #define PLL_ENABLE 0x80
  162. /* Route bits */
  163. #define ROUTE_ON 0x80
  164. /* Mute bits */
  165. #define UNMUTE 0x08
  166. #define MUTE_ON 0x80
  167. /* Power bits */
  168. #define LADC_PWR_ON 0x04
  169. #define RADC_PWR_ON 0x04
  170. #define LDAC_PWR_ON 0x80
  171. #define RDAC_PWR_ON 0x40
  172. #define HPLOUT_PWR_ON 0x01
  173. #define HPROUT_PWR_ON 0x01
  174. #define HPLCOM_PWR_ON 0x01
  175. #define HPRCOM_PWR_ON 0x01
  176. #define MONOLOPM_PWR_ON 0x01
  177. #define LLOPM_PWR_ON 0x01
  178. #define RLOPM_PWR_ON 0x01
  179. #define INVERT_VOL(val) (0x7f - val)
  180. /* Default output volume (inverted) */
  181. #define DEFAULT_VOL INVERT_VOL(0x50)
  182. /* Default input volume */
  183. #define DEFAULT_GAIN 0x20
  184. /* GPIO API */
  185. enum {
  186. AIC3X_GPIO1_FUNC_DISABLED = 0,
  187. AIC3X_GPIO1_FUNC_AUDIO_WORDCLK_ADC = 1,
  188. AIC3X_GPIO1_FUNC_CLOCK_MUX = 2,
  189. AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV2 = 3,
  190. AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV4 = 4,
  191. AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV8 = 5,
  192. AIC3X_GPIO1_FUNC_SHORT_CIRCUIT_IRQ = 6,
  193. AIC3X_GPIO1_FUNC_AGC_NOISE_IRQ = 7,
  194. AIC3X_GPIO1_FUNC_INPUT = 8,
  195. AIC3X_GPIO1_FUNC_OUTPUT = 9,
  196. AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK = 10,
  197. AIC3X_GPIO1_FUNC_AUDIO_WORDCLK = 11,
  198. AIC3X_GPIO1_FUNC_BUTTON_IRQ = 12,
  199. AIC3X_GPIO1_FUNC_HEADSET_DETECT_IRQ = 13,
  200. AIC3X_GPIO1_FUNC_HEADSET_DETECT_OR_BUTTON_IRQ = 14,
  201. AIC3X_GPIO1_FUNC_ALL_IRQ = 16
  202. };
  203. enum {
  204. AIC3X_GPIO2_FUNC_DISABLED = 0,
  205. AIC3X_GPIO2_FUNC_HEADSET_DETECT_IRQ = 2,
  206. AIC3X_GPIO2_FUNC_INPUT = 3,
  207. AIC3X_GPIO2_FUNC_OUTPUT = 4,
  208. AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT = 5,
  209. AIC3X_GPIO2_FUNC_AUDIO_BITCLK = 8,
  210. AIC3X_GPIO2_FUNC_HEADSET_DETECT_OR_BUTTON_IRQ = 9,
  211. AIC3X_GPIO2_FUNC_ALL_IRQ = 10,
  212. AIC3X_GPIO2_FUNC_SHORT_CIRCUIT_OR_AGC_IRQ = 11,
  213. AIC3X_GPIO2_FUNC_HEADSET_OR_BUTTON_PRESS_OR_SHORT_CIRCUIT_IRQ = 12,
  214. AIC3X_GPIO2_FUNC_SHORT_CIRCUIT_IRQ = 13,
  215. AIC3X_GPIO2_FUNC_AGC_NOISE_IRQ = 14,
  216. AIC3X_GPIO2_FUNC_BUTTON_PRESS_IRQ = 15
  217. };
  218. void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state);
  219. int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio);
  220. /* headset detection / button API */
  221. /* The AIC3x supports detection of stereo headsets (GND + left + right signal)
  222. * and cellular headsets (GND + speaker output + microphone input).
  223. * It is recommended to enable MIC bias for this function to work properly.
  224. * For more information, please refer to the datasheet. */
  225. enum {
  226. AIC3X_HEADSET_DETECT_OFF = 0,
  227. AIC3X_HEADSET_DETECT_STEREO = 1,
  228. AIC3X_HEADSET_DETECT_CELLULAR = 2,
  229. AIC3X_HEADSET_DETECT_BOTH = 3
  230. };
  231. enum {
  232. AIC3X_HEADSET_DEBOUNCE_16MS = 0,
  233. AIC3X_HEADSET_DEBOUNCE_32MS = 1,
  234. AIC3X_HEADSET_DEBOUNCE_64MS = 2,
  235. AIC3X_HEADSET_DEBOUNCE_128MS = 3,
  236. AIC3X_HEADSET_DEBOUNCE_256MS = 4,
  237. AIC3X_HEADSET_DEBOUNCE_512MS = 5
  238. };
  239. enum {
  240. AIC3X_BUTTON_DEBOUNCE_0MS = 0,
  241. AIC3X_BUTTON_DEBOUNCE_8MS = 1,
  242. AIC3X_BUTTON_DEBOUNCE_16MS = 2,
  243. AIC3X_BUTTON_DEBOUNCE_32MS = 3
  244. };
  245. #define AIC3X_HEADSET_DETECT_ENABLED 0x80
  246. #define AIC3X_HEADSET_DETECT_SHIFT 5
  247. #define AIC3X_HEADSET_DETECT_MASK 3
  248. #define AIC3X_HEADSET_DEBOUNCE_SHIFT 2
  249. #define AIC3X_HEADSET_DEBOUNCE_MASK 7
  250. #define AIC3X_BUTTON_DEBOUNCE_SHIFT 0
  251. #define AIC3X_BUTTON_DEBOUNCE_MASK 3
  252. /* see the enums above for valid parameters to this function */
  253. void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect,
  254. int headset_debounce, int button_debounce);
  255. int aic3x_headset_detected(struct snd_soc_codec *codec);
  256. int aic3x_button_pressed(struct snd_soc_codec *codec);
  257. struct aic3x_setup_data {
  258. unsigned int gpio_func[2];
  259. };
  260. extern struct snd_soc_dai aic3x_dai;
  261. extern struct snd_soc_codec_device soc_codec_dev_aic3x;
  262. #endif /* _AIC3X_H */