tlv320aic3x.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. /* Class-D speaker driver on tlv320aic3007 */
  110. #define CLASSD_CTRL 73
  111. /* Line Output Plus/Minus control registers */
  112. #define LINE2L_2_LLOPM_VOL 80
  113. #define LINE2L_2_RLOPM_VOL 87
  114. #define LINE2R_2_LLOPM_VOL 83
  115. #define LINE2R_2_RLOPM_VOL 90
  116. #define PGAL_2_LLOPM_VOL 81
  117. #define PGAL_2_RLOPM_VOL 88
  118. #define PGAR_2_LLOPM_VOL 84
  119. #define PGAR_2_RLOPM_VOL 91
  120. #define DACL1_2_LLOPM_VOL 82
  121. #define DACL1_2_RLOPM_VOL 89
  122. #define DACR1_2_RLOPM_VOL 92
  123. #define DACR1_2_LLOPM_VOL 85
  124. #define LLOPM_CTRL 86
  125. #define RLOPM_CTRL 93
  126. /* GPIO/IRQ registers */
  127. #define AIC3X_STICKY_IRQ_FLAGS_REG 96
  128. #define AIC3X_RT_IRQ_FLAGS_REG 97
  129. #define AIC3X_GPIO1_REG 98
  130. #define AIC3X_GPIO2_REG 99
  131. #define AIC3X_GPIOA_REG 100
  132. #define AIC3X_GPIOB_REG 101
  133. /* Clock generation control register */
  134. #define AIC3X_CLKGEN_CTRL_REG 102
  135. /* Page select register bits */
  136. #define PAGE0_SELECT 0
  137. #define PAGE1_SELECT 1
  138. /* Audio serial data interface control register A bits */
  139. #define BIT_CLK_MASTER 0x80
  140. #define WORD_CLK_MASTER 0x40
  141. /* Codec Datapath setup register 7 */
  142. #define FSREF_44100 (1 << 7)
  143. #define FSREF_48000 (0 << 7)
  144. #define DUAL_RATE_MODE ((1 << 5) | (1 << 6))
  145. #define LDAC2LCH (0x1 << 3)
  146. #define RDAC2RCH (0x1 << 1)
  147. /* PLL registers bitfields */
  148. #define PLLP_SHIFT 0
  149. #define PLLQ_SHIFT 3
  150. #define PLLR_SHIFT 0
  151. #define PLLJ_SHIFT 2
  152. #define PLLD_MSB_SHIFT 0
  153. #define PLLD_LSB_SHIFT 2
  154. /* Clock generation register bits */
  155. #define CODEC_CLKIN_PLLDIV 0
  156. #define CODEC_CLKIN_CLKDIV 1
  157. #define PLL_CLKIN_SHIFT 4
  158. #define MCLK_SOURCE 0x0
  159. #define PLL_CLKDIV_SHIFT 0
  160. /* Software reset register bits */
  161. #define SOFT_RESET 0x80
  162. /* PLL progrramming register A bits */
  163. #define PLL_ENABLE 0x80
  164. /* Route bits */
  165. #define ROUTE_ON 0x80
  166. /* Mute bits */
  167. #define UNMUTE 0x08
  168. #define MUTE_ON 0x80
  169. /* Power bits */
  170. #define LADC_PWR_ON 0x04
  171. #define RADC_PWR_ON 0x04
  172. #define LDAC_PWR_ON 0x80
  173. #define RDAC_PWR_ON 0x40
  174. #define HPLOUT_PWR_ON 0x01
  175. #define HPROUT_PWR_ON 0x01
  176. #define HPLCOM_PWR_ON 0x01
  177. #define HPRCOM_PWR_ON 0x01
  178. #define MONOLOPM_PWR_ON 0x01
  179. #define LLOPM_PWR_ON 0x01
  180. #define RLOPM_PWR_ON 0x01
  181. #define INVERT_VOL(val) (0x7f - val)
  182. /* Default output volume (inverted) */
  183. #define DEFAULT_VOL INVERT_VOL(0x50)
  184. /* Default input volume */
  185. #define DEFAULT_GAIN 0x20
  186. void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state);
  187. int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio);
  188. /* headset detection / button API */
  189. /* The AIC3x supports detection of stereo headsets (GND + left + right signal)
  190. * and cellular headsets (GND + speaker output + microphone input).
  191. * It is recommended to enable MIC bias for this function to work properly.
  192. * For more information, please refer to the datasheet. */
  193. enum {
  194. AIC3X_HEADSET_DETECT_OFF = 0,
  195. AIC3X_HEADSET_DETECT_STEREO = 1,
  196. AIC3X_HEADSET_DETECT_CELLULAR = 2,
  197. AIC3X_HEADSET_DETECT_BOTH = 3
  198. };
  199. enum {
  200. AIC3X_HEADSET_DEBOUNCE_16MS = 0,
  201. AIC3X_HEADSET_DEBOUNCE_32MS = 1,
  202. AIC3X_HEADSET_DEBOUNCE_64MS = 2,
  203. AIC3X_HEADSET_DEBOUNCE_128MS = 3,
  204. AIC3X_HEADSET_DEBOUNCE_256MS = 4,
  205. AIC3X_HEADSET_DEBOUNCE_512MS = 5
  206. };
  207. enum {
  208. AIC3X_BUTTON_DEBOUNCE_0MS = 0,
  209. AIC3X_BUTTON_DEBOUNCE_8MS = 1,
  210. AIC3X_BUTTON_DEBOUNCE_16MS = 2,
  211. AIC3X_BUTTON_DEBOUNCE_32MS = 3
  212. };
  213. #define AIC3X_HEADSET_DETECT_ENABLED 0x80
  214. #define AIC3X_HEADSET_DETECT_SHIFT 5
  215. #define AIC3X_HEADSET_DETECT_MASK 3
  216. #define AIC3X_HEADSET_DEBOUNCE_SHIFT 2
  217. #define AIC3X_HEADSET_DEBOUNCE_MASK 7
  218. #define AIC3X_BUTTON_DEBOUNCE_SHIFT 0
  219. #define AIC3X_BUTTON_DEBOUNCE_MASK 3
  220. /* see the enums above for valid parameters to this function */
  221. void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect,
  222. int headset_debounce, int button_debounce);
  223. int aic3x_headset_detected(struct snd_soc_codec *codec);
  224. int aic3x_button_pressed(struct snd_soc_codec *codec);
  225. #endif /* _AIC3X_H */