wm8904.h 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. /****************************************************************************
  2. * drivers/audio/wm8904.h
  3. *
  4. * Copyright (C) 2014 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Reference:
  8. * "WM8904 Ultra Low Power CODEC for Portable Audio Applications, Pre-
  9. * Production", September 2012, Rev 3.3, Wolfson Microelectronics
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. * 3. Neither the name NuttX nor the names of its contributors may be
  22. * used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  28. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  29. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  30. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  32. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  33. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ****************************************************************************/
  39. #ifndef __DRIVERS_AUDIO_WM8904_H
  40. #define __DRIVERS_AUDIO_WM8904_H
  41. /****************************************************************************
  42. * Included Files
  43. ****************************************************************************/
  44. #include <nuttx/config.h>
  45. #include <nuttx/compiler.h>
  46. #include <pthread.h>
  47. #include <mqueue.h>
  48. #include <nuttx/wqueue.h>
  49. #include <nuttx/fs/ioctl.h>
  50. #ifdef CONFIG_AUDIO
  51. /****************************************************************************
  52. * Pre-processor Definitions
  53. ****************************************************************************/
  54. /* So far, I have not been able to get FLL lock interrupts. Worse, I have
  55. * been able to get the FLL to claim that it is locked at all even when
  56. * polling. What am I doing wrong?
  57. *
  58. * Hmmm.. seems unnecessary anyway
  59. */
  60. #undef WM8904_USE_FFLOCK_INT
  61. #undef WM8904_USE_FFLOCK_POLL
  62. /* Registers Addresses ******************************************************/
  63. #define WM8904_SWRST 0x00 /* SW Reset and ID */
  64. #define WM8904_ID 0x00 /* SW Reset and ID */
  65. #define WM8904_BIAS_CTRL 0x04 /* Bias Control */
  66. #define WM8904_VMID_CTRL 0x05 /* VMID Control */
  67. #define WM8904_MIC_BIAS_CTRL0 0x06 /* Mic Bias Control 0 */
  68. #define WM8904_MIC_BIAS_CTRL1 0x07 /* Mic Bias Control 1 */
  69. #define WM8904_ANALOG_ADC 0x0a /* Analogue ADC */
  70. #define WM8904_PM0 0x0c /* Power Management 0 */
  71. #define WM8904_PM2 0x0e /* Power Management 2 */
  72. #define WM8904_PM3 0x0f /* Power Management 3 */
  73. #define WM8904_PM6 0x12 /* Power Management 6 */
  74. #define WM8904_CLKRATE0 0x14 /* Clock Rates 0 */
  75. #define WM8904_CLKRATE1 0x15 /* Clock Rates 1 */
  76. #define WM8904_CLKRATE2 0x16 /* Clock Rates 2 */
  77. #define WM8904_AIF0 0x18 /* Audio Interface 0 */
  78. #define WM8904_AIF1 0x19 /* Audio Interface 1 */
  79. #define WM8904_AIF2 0x1a /* Audio Interface 2 */
  80. #define WM8904_AIF3 0x1b /* Audio Interface 3 */
  81. #define WM8904_DAC_VOL_LEFT 0x1e /* DAC Digital Volume Left */
  82. #define WM8904_DAC_VOL_RIGHT 0x1f /* DAC Digital Volume Right */
  83. #define WM8904_DAC_DIGI0 0x20 /* DAC Digital 0 */
  84. #define WM8904_DAC_DIGI1 0x21 /* DAC Digital 1 */
  85. #define WM8904_ADC_VOL_LEFT 0x24 /* ADC Digital Volume Left */
  86. #define WM8904_ADC_VOL_RIGHT 0x25 /* ADC Digital Volume Right */
  87. #define WM8904_ADC_DIGI 0x26 /* ADC Digital */
  88. #define WM8904_MIC_DIGI 0x27 /* Digital Microphone */
  89. #define WM8904_DRC0 0x28 /* DRC 0 */
  90. #define WM8904_DRC1 0x29 /* DRC 1 */
  91. #define WM8904_DRC2 0x2a /* DRC 2 */
  92. #define WM8904_DRC3 0x2b /* DRC 3 */
  93. #define WM8904_ANA_LEFT_IN0 0x2c /* Analogue Left Input 0 */
  94. #define WM8904_ANA_RIGHT_IN0 0x2d /* Analogue Right Input 0 */
  95. #define WM8904_ANA_LEFT_IN1 0x2e /* Analogue Left Input 1 */
  96. #define WM8904_ANA_RIGHT_IN1 0x2f /* Analogue Right Input 1 */
  97. #define WM8904_ANA_LEFT_OUT1 0x39 /* Analogue OUT1 Left */
  98. #define WM8904_ANA_RIGHT_OUT1 0x3a /* Analogue OUT1 Right */
  99. #define WM8904_ANA_LEFT_OUT2 0x3b /* Analogue OUT2 Left */
  100. #define WM8904_ANA_RIGHT_OUT2 0x3c /* Analogue OUT2 Right */
  101. #define WM8904_ANA_OUT12_ZC 0x3d /* Analogue OUT12 ZC */
  102. #define WM8904_DC_SERVO0 0x43 /* DC Servo 0 */
  103. #define WM8904_DC_SERVO1 0x44 /* DC Servo 1 */
  104. #define WM8904_DC_SERVO2 0x45 /* DC Servo 2 */
  105. #define WM8904_DC_SERVO4 0x47 /* DC Servo 4 */
  106. #define WM8904_DC_SERVO5 0x48 /* DC Servo 5 */
  107. #define WM8904_DC_SERVO6 0x49 /* DC Servo 6 */
  108. #define WM8904_DC_SERVO7 0x4a /* DC Servo 7 */
  109. #define WM8904_DC_SERVO8 0x4b /* DC Servo 8 */
  110. #define WM8904_DC_SERVO9 0x4c /* DC Servo 9 */
  111. #define WM8904_DC_SERVO_RDBACK 0x4d /* DC Servo Readback 0 */
  112. #define WM8904_ANA_HP0 0x5a /* Analogue HP 0 */
  113. #define WM8904_ANA_LINEOUT0 0x5e /* Analogue Lineout 0 */
  114. #define WM8904_CHG_PUMP0 0x62 /* Charge Pump 0 */
  115. #define WM8904_CLASS_W0 0x68 /* Class W 0 */
  116. #define WM8904_WR_SEQ0 0x6c /* Write Sequencer 0 */
  117. #define WM8904_WR_SEQ1 0x6d /* Write Sequencer 1 */
  118. #define WM8904_WR_SEQ2 0x6e /* Write Sequencer 2 */
  119. #define WM8904_WR_SEQ3 0x6f /* Write Sequencer 3 */
  120. #define WM8904_WR_SEQ4 0x70 /* Write Sequencer 4 */
  121. #define WM8904_FLL_CTRL1 0x74 /* FLL Control 1 */
  122. #define WM8904_FLL_CTRL2 0x75 /* FLL Control 2 */
  123. #define WM8904_FLL_CTRL3 0x76 /* FLL Control 3 */
  124. #define WM8904_FLL_CTRL4 0x77 /* FLL Control 4 */
  125. #define WM8904_FLL_CTRL5 0x78 /* FLL Control 5 */
  126. #define WM8904_GPIO_CTRL1 0x79 /* GPIO Control 1 */
  127. #define WM8904_GPIO_CTRL2 0x7a /* GPIO Control 2 */
  128. #define WM8904_GPIO_CTRL3 0x7b /* GPIO Control 3 */
  129. #define WM8904_GPIO_CTRL4 0x7c /* GPIO Control 4 */
  130. #define WM8904_DIGI_PULLS 0x7e /* Digital Pulls */
  131. #define WM8904_INT_STATUS 0x7f /* Interrupt Status */
  132. #define WM8904_INT_MASK 0x80 /* Interrupt Status Mask */
  133. #define WM8904_INT_POL 0x81 /* Interrupt Polarity */
  134. #define WM8904_INT_DEBOUNCE 0x82 /* Interrupt Debounce */
  135. #define WM8904_EQ1 0x86 /* EQ1 */
  136. #define WM8904_EQ2 0x87 /* EQ2 */
  137. #define WM8904_EQ3 0x88 /* EQ3 */
  138. #define WM8904_EQ4 0x89 /* EQ4 */
  139. #define WM8904_EQ5 0x8a /* EQ5 */
  140. #define WM8904_EQ6 0x8b /* EQ6 */
  141. #define WM8904_EQ7 0x8c /* EQ7 */
  142. #define WM8904_EQ8 0x8d /* EQ8 */
  143. #define WM8904_EQ9 0x8e /* EQ9 */
  144. #define WM8904_EQ10 0x8f /* EQ10 */
  145. #define WM8904_EQ11 0x90 /* EQ11 */
  146. #define WM8904_EQ12 0x91 /* EQ12 */
  147. #define WM8904_EQ13 0x92 /* EQ13 */
  148. #define WM8904_EQ14 0x93 /* EQ14 */
  149. #define WM8904_EQ15 0x94 /* EQ15 */
  150. #define WM8904_EQ16 0x95 /* EQ16 */
  151. #define WM8904_EQ17 0x96 /* EQ17 */
  152. #define WM8904_EQ18 0x97 /* EQ18 */
  153. #define WM8904_EQ19 0x98 /* EQ19 */
  154. #define WM8904_EQ20 0x99 /* EQ20 */
  155. #define WM8904_EQ21 0x9a /* EQ21 */
  156. #define WM8904_EQ22 0x9b /* EQ22 */
  157. #define WM8904_EQ23 0x9c /* EQ23 */
  158. #define WM8904_EQ24 0x9d /* EQ24 */
  159. #define WM8904_CTRLIF_TEST_1 0xa1 /* Control Interface Test 1 */
  160. #define WM8904_ADC_TEST 0xc6 /* ADC Test */
  161. #define WM8904_ANA_OUT_BIAS_0 0xCC /* Analogue Output Bias 0 */
  162. #define WM8904_FLL_NCO_TEST0 0xf7 /* FLL NCO Test 0 */
  163. #define WM8904_FLL_NCO_TEST1 0xf8 /* FLL NCO Test 1 */
  164. #define WM8904_DUMMY 0xff /* Dummy register address */
  165. /* Register Default Values **************************************************/
  166. /* Registers have some undocumented bits set on power up. These probably
  167. * should be retained on writes (?).
  168. */
  169. #define WM8904_SWRST_DEFAULT 0x8904
  170. #define WM8904_ID_DEFAULT 0x0018
  171. #define WM8904_BIAS_CTRL_DEFAULT 0x0000
  172. #define WM8904_VMID_CTRL_DEFAULT 0x0000
  173. #define WM8904_MIC_BIAS_CTRL0_DEFAULT 0x0000
  174. #define WM8904_MIC_BIAS_CTRL1_DEFAULT 0x0000
  175. #define WM8904_ANALOG_ADC_DEFAULT 0x0001
  176. #define WM8904_PM0_DEFAULT 0x0000
  177. #define WM8904_PM2_DEFAULT 0x0000
  178. #define WM8904_PM3_DEFAULT 0x0000
  179. #define WM8904_PM6_DEFAULT 0x0000
  180. #define WM8904_CLKRATE0_DEFAULT 0x8c5e
  181. #define WM8904_CLKRATE1_DEFAULT 0x0c05
  182. #define WM8904_CLKRATE2_DEFAULT 0x0000
  183. #define WM8904_AIF0_DEFAULT 0x0050
  184. #define WM8904_AIF1_DEFAULT 0x000a
  185. #define WM8904_AIF2_DEFAULT 0x00e4
  186. #define WM8904_AIF3_DEFAULT 0x0040
  187. #define WM8904_DAC_VOL_LEFT_DEFAULT 0x00c0
  188. #define WM8904_DAC_VOL_RIGHT_DEFAULT 0x00c0
  189. #define WM8904_DAC_DIGI0_DEFAULT 0x0000
  190. #define WM8904_DAC_DIGI1_DEFAULT 0x0004
  191. #define WM8904_ADC_VOL_LEFT_DEFAULT 0x00c0
  192. #define WM8904_ADC_VOL_RIGHT_DEFAULT 0x00c0
  193. #define WM8904_ADC_DIGI_DEFAULT 0x0010
  194. #define WM8904_MIC_DIGI_DEFAULT 0x0000
  195. #define WM8904_DRC0_DEFAULT 0x01af
  196. #define WM8904_DRC1_DEFAULT 0x3248
  197. #define WM8904_DRC2_DEFAULT 0x0000
  198. #define WM8904_DRC3_DEFAULT 0x0000
  199. #define WM8904_ANA_LEFT_IN0_DEFAULT 0x0085
  200. #define WM8904_ANA_RIGHT_IN0_DEFAULT 0x0085
  201. #define WM8904_ANA_LEFT_IN1_DEFAULT 0x0044
  202. #define WM8904_ANA_RIGHT_IN1_DEFAULT 0x0044
  203. #define WM8904_ANA_LEFT_OUT1_DEFAULT 0x002d
  204. #define WM8904_ANA_RIGHT_OUT1_DEFAULT 0x002d
  205. #define WM8904_ANA_LEFT_OUT2_DEFAULT 0x0039
  206. #define WM8904_ANA_RIGHT_OUT2_DEFAULT 0x0039
  207. #define WM8904_ANA_OUT12_ZC_DEFAULT 0x0000
  208. #define WM8904_DC_SERVO0_DEFAULT 0x0000
  209. #define WM8904_DC_SERVO2_DEFAULT 0xaaaa
  210. #define WM8904_DC_SERVO4_DEFAULT 0xaaaa
  211. #define WM8904_DC_SERVO5_DEFAULT 0xaaaa
  212. #define WM8904_DC_SERVO6_DEFAULT 0x0000
  213. #define WM8904_DC_SERVO7_DEFAULT 0x0000
  214. #define WM8904_DC_SERVO8_DEFAULT 0x0000
  215. #define WM8904_DC_SERVO9_DEFAULT 0x0000
  216. #define WM8904_DC_SERVO_RDBACK_DEFAULT 0x0000
  217. #define WM8904_ANA_HP0_DEFAULT 0x0000
  218. #define WM8904_ANA_LINEOUT0_DEFAULT 0x0000
  219. #define WM8904_CHG_PUMP0_DEFAULT 0x0000
  220. #define WM8904_CLASS_W0_DEFAULT 0x0000
  221. #define WM8904_WR_SEQ0_DEFAULT 0x0000
  222. #define WM8904_WR_SEQ1_DEFAULT 0x0000
  223. #define WM8904_WR_SEQ2_DEFAULT 0x0000
  224. #define WM8904_WR_SEQ3_DEFAULT 0x0000
  225. #define WM8904_WR_SEQ4_DEFAULT 0x0000
  226. #define WM8904_FLL_CTRL1_DEFAULT 0x0000
  227. #define WM8904_FLL_CTRL2_DEFAULT 0x0007
  228. #define WM8904_FLL_CTRL3_DEFAULT 0x0000
  229. #define WM8904_FLL_CTRL4_DEFAULT 0x2ee0
  230. #define WM8904_FLL_CTRL5_DEFAULT 0x0004
  231. #define WM8904_GPIO_CTRL1_DEFAULT 0x0014
  232. #define WM8904_GPIO_CTRL2_DEFAULT 0x0010
  233. #define WM8904_GPIO_CTRL3_DEFAULT 0x0010
  234. #define WM8904_GPIO_CTRL4_DEFAULT 0x0000
  235. #define WM8904_DIGI_PULLS_DEFAULT 0x0000
  236. #define WM8904_INT_MASK_DEFAULT 0xffff
  237. #define WM8904_INT_POL_DEFAULT 0x0000
  238. #define WM8904_INT_DEBOUNCE_DEFAULT 0x0000
  239. #define WM8904_EQ1_DEFAULT 0x0000
  240. #define WM8904_EQ2_DEFAULT 0x000c
  241. #define WM8904_EQ3_DEFAULT 0x000c
  242. #define WM8904_EQ4_DEFAULT 0x000c
  243. #define WM8904_EQ5_DEFAULT 0x000c
  244. #define WM8904_EQ6_DEFAULT 0x000c
  245. #define WM8904_EQ7_DEFAULT 0x0fca
  246. #define WM8904_EQ8_DEFAULT 0x0400
  247. #define WM8904_EQ9_DEFAULT 0x00d8
  248. #define WM8904_EQ10_DEFAULT 0x1eb5
  249. #define WM8904_EQ11_DEFAULT 0xf145
  250. #define WM8904_EQ12_DEFAULT 0x0b75
  251. #define WM8904_EQ13_DEFAULT 0x01c5
  252. #define WM8904_EQ14_DEFAULT 0x1c54
  253. #define WM8904_EQ15_DEFAULT 0xf373
  254. #define WM8904_EQ16_DEFAULT 0x0a54
  255. #define WM8904_EQ17_DEFAULT 0x0558
  256. #define WM8904_EQ18_DEFAULT 0x168e
  257. #define WM8904_EQ19_DEFAULT 0xf829
  258. #define WM8904_EQ20_DEFAULT 0x07ad
  259. #define WM8904_EQ21_DEFAULT 0x1103
  260. #define WM8904_EQ22_DEFAULT 0x0564
  261. #define WM8904_EQ23_DEFAULT 0x0559
  262. #define WM8904_EQ24_DEFAULT 0x4000
  263. #define WM8904_CTRLIF_TEST_1_DEFAULT 0x0000
  264. #define WM8904_FLL_NCO_TEST0_DEFAULT 0x0000
  265. #define WM8904_ANA_OUT_BIAS_0_DEFAULT 0x0000
  266. #define WM8904_ADC_TEST_DEFAULT 0x0000
  267. #define WM8904_FLL_NCO_TEST1_DEFAULT 0x0019
  268. /* Register Bit Definitions *************************************************/
  269. /* 0x00 SW Reset and ID */
  270. #define WM8904_SW_RST_DEV_ID1 0x8904
  271. /* 0x04 Bias Control */
  272. #define WM8904_ISEL_SHIFT (2) /* Bits 2-3: Master Bias Control */
  273. #define WM8904_ISEL_MASK (3 << WM8904_ISEL_SHIFT)
  274. # define WM8904_ISEL_LOW (0 << WM8904_ISEL_SHIFT) /* Low power bias */
  275. # define WM8904_ISEL_HIGH (2 << WM8904_ISEL_SHIFT) /* High performance bias */
  276. #define WM8904_BIAS_ENA (1 << 0) /* Bit 0: Normal bias current generator */
  277. /* 0x05 VMID Control */
  278. #define WM8904_VMID_BUF_ENA (1 << 6) /* Bit 6: Enable VMID buffer to unused I/O */
  279. #define WM8904_VMID_RES_SHIFT (1) /* Bits 1-2: VMID divider enable and select */
  280. #define WM8904_VMID_RES_MASK (3 << WM8904_VMID_RES_SHIFT)
  281. # define WM8904_VMID_RES_OFF (0 << WM8904_VMID_RES_SHIFT) /* VMID disabled */
  282. # define WM8904_VMID_RES_NORMAL (1 << WM8904_VMID_RES_SHIFT) /* 2 x 50k divider */
  283. # define WM8904_VMID_RES_STANDBY (2 << WM8904_VMID_RES_SHIFT) /* 2 x 250k divider */
  284. # define WM8904_VMID_RES_FASTSTART (3 << WM8904_VMID_RES_SHIFT) /* 2 x 5k divider */
  285. #define WM8904_VMID_ENA (1 << 0) /* Bit 0: VMID buffer enable */
  286. /* 0x06 Mic Bias Control 0 */
  287. #define WM8904_MICDET_THR_SHIFT (4) /* Bits 4-6: MICBIAS current detect threshold */
  288. #define WM8904_MICDET_THR_MASK (7 << WM8904_MICDET_THR_SHIFT)
  289. # define WM8904_MICDET_THR(n) ((uint16_t)(n) << WM8904_MICDET_THR_SHIFT)
  290. #define WM8904_MICSHORT_THR_SHIFT (2) /* Bits 2-3: MICBIAS short circuit threshold */
  291. #define WM8904_MICSHORT_THR_MASK (3 << WM8904_MICSHORT_THR_SHIFT)
  292. #define WM8904_MICSHORT_THR(n) ((uint16_t)(n) << WM8904_MICSHORT_THR_SHIFT)
  293. #define WM8904_MICDET_ENA (1 << 1) /* Bit 1: MICBIAS current/short circuit detect enable */
  294. #define WM8904_MICBIAS_ENA (1 << 0) /* Bit 0: MICBIAS enable */
  295. /* 0x07 Mic Bias Control 1 */
  296. #define WM8904_MICBIAS_SEL_MASK (0x0007) /* Bits 0-2: Selects MICBIAS voltage */
  297. /* 0x0a Analogue ADC */
  298. #define WM8904_ADC_OSR128 (1 << 0) /* Bit 0: ADC Oversampling Ratio */
  299. /* 0x0c Power Management 0 */
  300. #define WM8904_INL_ENA (1 << 1) /* Bit 1: Left input PGA enable */
  301. #define WM8904_INR_ENA (1 << 0) /* Bit 0: Right input PGA enable */
  302. /* 0x0e Power Management 2 */
  303. #define WM8904_HPL_PGA_ENA (1 << 1) /* Bit 1: Left headphone output enable */
  304. #define WM8904_HPR_PGA_ENA (1 << 0) /* Bit 0: Right headphone output enable */
  305. /* 0x0f Power Management 3 */
  306. #define WM8904_LINEOUTL_PGA_ENA (1 << 1) /* Bit 1: Left line output enable */
  307. #define WM8904_LINEOUTR_PGA_ENA (1 << 0) /* Bit 0: Right line output enable */
  308. /* 0x12 Power Management 6 */
  309. #define WM8904_DACL_ENA (1 << 3) /* Bit 3: Left DAC enable */
  310. #define WM8904_DACR_ENA (1 << 2) /* Bit 2: Right DAC enable */
  311. #define WM8904_ADCL_ENA (1 << 1) /* Bit 1: Left ADC enable */
  312. #define WM8904_ADCR_ENA (1 << 0) /* Bit 0: Right ADC enable */
  313. /* 0x14 Clock Rates 0 */
  314. #define WM8904_TOCLK_RATE_DIV16 (1 << 14) /* Bit 14: TOCLK Rate Divider (/16) */
  315. #define WM8904_TOCLK_RATE_X4 (1 << 13) /* Bit 13: TOCLK Rate Multiplier */
  316. #define WM8904_MCLK_DIV (1 << 0) /* Bit 0: Enables divide by 2 on MCLK */
  317. # define WM8904_MCLK_DIV1 (0) /* 0: SYSCLK = MCLK */
  318. # define WM8904_MCLK_DIV2 (1 << 0) /* 1: SYSCLK = MCLK/2*/
  319. /* 0x15 Clock Rates 1 */
  320. #define WM8904_CLK_SYS_RATE_SHIFT (10) /* Bits 10-13: Selects the SYSCLK / fs ratio */
  321. #define WM8904_CLK_SYS_RATE_MASK (15 << WM8904_CLK_SYS_RATE_SHIFT)
  322. # define WM8904_CLK_SYS_RATE_DIV64 (0 << WM8904_CLK_SYS_RATE_SHIFT)
  323. # define WM8904_CLK_SYS_RATE_DIV128 (1 << WM8904_CLK_SYS_RATE_SHIFT)
  324. # define WM8904_CLK_SYS_RATE_DIV192 (2 << WM8904_CLK_SYS_RATE_SHIFT)
  325. # define WM8904_CLK_SYS_RATE_DIV256 (3 << WM8904_CLK_SYS_RATE_SHIFT)
  326. # define WM8904_CLK_SYS_RATE_DIV384 (4 << WM8904_CLK_SYS_RATE_SHIFT)
  327. # define WM8904_CLK_SYS_RATE_DIV512 (5 << WM8904_CLK_SYS_RATE_SHIFT)
  328. # define WM8904_CLK_SYS_RATE_DIV768 (6 << WM8904_CLK_SYS_RATE_SHIFT)
  329. # define WM8904_CLK_SYS_RATE_DIV1024 (7 << WM8904_CLK_SYS_RATE_SHIFT)
  330. # define WM8904_CLK_SYS_RATE_DIV1408 (8 << WM8904_CLK_SYS_RATE_SHIFT)
  331. # define WM8904_CLK_SYS_RATE_DIV1536 (9 << WM8904_CLK_SYS_RATE_SHIFT)
  332. #define WM8904_SAMPLE_RATE_SHIFT (0) /* Bits 0-2: Selects the Sample Rate (fs) */
  333. #define WM8904_SAMPLE_RATE_MASK (3 << WM8904_SAMPLE_RATE_SHIFT)
  334. # define WM8904_SAMPLE_RATE_8KHZ (0 << WM8904_SAMPLE_RATE_SHIFT) /* 8kHz */
  335. # define WM8904_SAMPLE_RATE_12KHZ (1 << WM8904_SAMPLE_RATE_SHIFT) /* 11.025kHz, 12kHz */
  336. # define WM8904_SAMPLE_RATE_16KHZ (2 << WM8904_SAMPLE_RATE_SHIFT) /* 16kHz */
  337. # define WM8904_SAMPLE_RATE_24KHZ (3 << WM8904_SAMPLE_RATE_SHIFT) /* 22.05kHz, 24kHz */
  338. # define WM8904_SAMPLE_RATE_32KHZ (4 << WM8904_SAMPLE_RATE_SHIFT) /* 32kHz */
  339. # define WM8904_SAMPLE_RATE_48KHZ (5 << WM8904_SAMPLE_RATE_SHIFT) /* 44.1kHz, 48kHz */
  340. /* 0x16 Clock Rates 2 */
  341. #define WM8904_MCLK_INV (1 << 15) /* Bit 15: MCLK invert */
  342. #define WM8904_SYSCLK_SRC (1 << 14) /* Bit 14: SYSCLK source select */
  343. # define WM8904_SYSCLK_SRCMCLK (0) /* 0: MCLK */
  344. # define WM8904_SYSCLK_SRCFLL (1 << 14) /* 1: FLL Output */
  345. #define WM8904_TOCLK_RATE (1 << 12) /* Bit 12: TOCLK rate divider (/2) */
  346. #define WM8904_OPCLK_ENA (1 << 3) /* Bit 3: GPIO clock output enable */
  347. #define WM8904_CLK_SYS_ENA (1 << 2) /* Bit 2: System clock enable */
  348. #define WM8904_CLK_DSP_ENA (1 << 1) /* Bit 1: DSP clock enable */
  349. #define WM8904_TOCLK_ENA (1 << 0) /* Bit 0: Zero cross timeout enable */
  350. /* 0x18 Audio Interface 0 */
  351. #define WM8904_DACL_DATINV (1 << 12) /* Bit 12: Left DAC invert */
  352. #define WM8904_DACR_DATINV (1 << 11) /* Bit 11: Right DAC invert */
  353. #define WM8904_DAC_BOOST_SHIFT (9) /* Bits 9-10: DAC digital input volume boost */
  354. #define WM8904_DAC_BOOST_MASK (3 << WM8904_DAC_BOOST_SHIFT)
  355. # define WM8904_DAC_BOOST_0DB (0 << WM8904_DAC_BOOST_SHIFT)
  356. # define WM8904_DAC_BOOST_6DB (1 << WM8904_DAC_BOOST_SHIFT)
  357. # define WM8904_DAC_BOOST_12DB (2 << WM8904_DAC_BOOST_SHIFT)
  358. #define WM8904_LOOPBACK (1 << 8) /* Bit 8: Digital loopback function */
  359. #define WM8904_AIFADCL_SRC (1 << 7) /* Bit 7: Left digital audio channel source */
  360. #define WM8904_AIFADCR_SRC (1 << 6) /* Bit 6: Right digital audio channel source */
  361. #define WM8904_AIFDACL_SRC (1 << 5) /* Bit 5: Left DAC data source select */
  362. #define WM8904_AIFDACR_SRC (1 << 4) /* Bit 4: Right DAC data source select */
  363. #define WM8904_ADC_COMP (1 << 3) /* Bit 3: ADC companding enable */
  364. #define WM8904_ADC_COMPMODE (1 << 2) /* Bit 2: ADC companding type */
  365. #define WM8904_DAC_COMP (1 << 1) /* Bit 1: DAC companding enable */
  366. #define WM8904_DAC_COMPMODE (1 << 0) /* Bit 0: DAC companding type */
  367. /* 0x19 Audio Interface 1 */
  368. #define WM8904_AIFDAC_TDM (1 << 13) /* Bit 13: DAC TDM enable */
  369. #define WM8904_AIFDAC_TDM_CHAN (1 << 12) /* Bit 12: DACDAT TDM channel select */
  370. #define WM8904_AIFADC_TDM (1 << 11) /* Bit 11: ADC TDM enable */
  371. #define WM8904_AIFADC_TDM_CHAN (1 << 10) /* Bit 10: ADCDAT TDM channel select */
  372. #define WM8904_AIF_TRIS (1 << 8) /* Bit 8: Audio interface tristate */
  373. #define WM8904_AIF_BCLK_INV (1 << 7) /* Bit 7: BCLK invert */
  374. #define WM8904_BCLK_DIR (1 << 6) /* Bit 6: Audio interface BCLK direction */
  375. #define WM8904_AIF_LRCLK_INV (1 << 4) /* Bit 4: LRC polarity/DSP mode A-B select */
  376. #define WM8904_AIF_WL_SHIFT (2) /* Bits 2-3: Digital audio interface word length */
  377. #define WM8904_AIF_WL_MASK (3 << WM8904_AIF_WL_SHIFT)
  378. # define WM8904_AIF_WL_16BITS (0 << WM8904_AIF_WL_SHIFT)
  379. # define WM8904_AIF_WL_20BITS (1 << WM8904_AIF_WL_SHIFT)
  380. # define WM8904_AIF_WL_24BITS (2 << WM8904_AIF_WL_SHIFT)
  381. # define WM8904_AIF_WL_32BITS (3 << WM8904_AIF_WL_SHIFT)
  382. #define WM8904_AIF_FMT_SHIFT (0) /* Bits 0-1: Digital audio interface format */
  383. #define WM8904_AIF_FMT_MASK (3 << WM8904_AIF_FMT_SHIFT)
  384. # define WM8904_AIF_FMT_RJUST (0 << WM8904_AIF_FMT_SHIFT) /* Right Justified */
  385. # define WM8904_AIF_FMT_LJUST (1 << WM8904_AIF_FMT_SHIFT) /* Left Justified */
  386. # define WM8904_AIF_FMT_I2S (2 << WM8904_AIF_FMT_SHIFT) /* I2S */
  387. # define WM8904_AIF_FMT_DSP (3 << WM8904_AIF_FMT_SHIFT) /* DSP */
  388. /* 0x1a Audio Interface 2 */
  389. #define WM8904_OPCLK_DIV_SHIFT (8) /* Bits 8-11: GPIO Output Clock Divider */
  390. #define WM8904_OPCLK_DIV_MASK (15 << WM8904_OPCLK_DIV_SHIFT)
  391. # define WM8904_OPCLK_DIV1 (0 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK */
  392. # define WM8904_OPCLK_DIV2 (1 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK / 2 */
  393. # define WM8904_OPCLK_DIV3 (2 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK / 3 */
  394. # define WM8904_OPCLK_DIV4 (3 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK / 4 */
  395. # define WM8904_OPCLK_DIV5p5 (4 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK / 5.5 */
  396. # define WM8904_OPCLK_DIV6 (5 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK / 6 */
  397. # define WM8904_OPCLK_DIV8 (6 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK / 8 */
  398. # define WM8904_OPCLK_DIV12 (7 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK / 12 */
  399. # define WM8904_OPCLK_DIV16 (8 << WM8904_OPCLK_DIV_SHIFT) /* SYSCLK / 16 */
  400. #define WM8904_BCLK_DIV_SHIFT (0) /* Bits 0-4: BCLK Frequency (Master Mode) */
  401. #define WM8904_BCLK_DIV_MASK (31 << WM8904_BCLK_DIV_SHIFT)
  402. # define WM8904_BCLK_DIV(n) ((uint16_t)(n) << WM8904_BCLK_DIV_SHIFT)
  403. # define WM8904_BCLK_DIV1 (0 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK */
  404. # define WM8904_BCLK_DIV1p5 (1 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 1.5 */
  405. # define WM8904_BCLK_DIV2 (2 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 2 */
  406. # define WM8904_BCLK_DIV3 (3 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 3 */
  407. # define WM8904_BCLK_DIV4 (4 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 4 */
  408. # define WM8904_BCLK_DIV5 (5 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 5 */
  409. # define WM8904_BCLK_DIV5p5 (6 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 5.5 */
  410. # define WM8904_BCLK_DIV6 (7 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 6 */
  411. # define WM8904_BCLK_DIV8 (8 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 8 */
  412. # define WM8904_BCLK_DIV10 (9 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 10 */
  413. # define WM8904_BCLK_DIV11 (10 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 11 */
  414. # define WM8904_BCLK_DIV12 (11 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 12 */
  415. # define WM8904_BCLK_DIV16 (12 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 16 */
  416. # define WM8904_BCLK_DIV20 (13 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 20 */
  417. # define WM8904_BCLK_DIV22 (14 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 22 */
  418. # define WM8904_BCLK_DIV24 (15 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 24 */
  419. # define WM8904_BCLK_DIV25 (16 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 25 */
  420. # define WM8904_BCLK_DIV30 (17 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 30 */
  421. # define WM8904_BCLK_DIV32 (18 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 32 */
  422. # define WM8904_BCLK_DIV44 (19 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 44 */
  423. # define WM8904_BCLK_DIV48 (20 << WM8904_BCLK_DIV_SHIFT) /* SYSCLK / 48 */
  424. /* 0x1b Audio Interface 3 */
  425. #define WM8904_LRCLK_DIR (1 << 11) /* Bit 11: Audio interface LRC direction */
  426. #define WM8904_LRCLK_RATE_SHIFT (0) /* Bits 0-10: LRC rate (master mode) */
  427. #define WM8904_LRCLK_RATE_MASK (0x7ff << WM8904_LRCLK_RATE_SHIFT)
  428. # define WM8904_LRCLK_RATE(n) ((uint16_t)(n) << WM8904_LRCLK_RATE_SHIFT)
  429. /* 0x1e DAC Digital Volume Left */
  430. /* 0x1f DAC Digital Volume Right */
  431. #define WM8904_DAC_VU (1 << 8) /* Bit 8: DAC volume update */
  432. #define WM8904_DAC_VOL_SHIFT (0) /* Bits 0-7: DAC digital volume */
  433. #define WM8904_DAC_VOL_MASK (0xff << WM8904_DAC_VOL_SHIFT)
  434. # define WM8904_DAC_VOL(n) ((uint16_t)(n) << WM8904_DAC_VOL_SHIFT)
  435. /* 0x20 DAC Digital 0 */
  436. #define WM8904_ADCL_DAC_SVOL_SHIFT (8) /* Bits 8-11: Left digital sidetone volume */
  437. #define WM8904_ADCL_DAC_SVOL_MASK (15 << WM8904_ADCL_DAC_SVOL_SHIFT)
  438. # define WM8904_ADCL_DAC_SVOL(n) ((uint16_t)(n) << WM8904_ADCL_DAC_SVOL_SHIFT)
  439. #define WM8904_ADCR_DAC_SVOL_SHIFT (4) /* Bits 4-7: Right digital sidetone volume*/
  440. #define WM8904_ADCR_DAC_SVOL_MASK (15 << WM8904_ADCR_DAC_SVOL_SHIFT)
  441. # define WM8904_ADCR_DAC_SVOL(n) ((uint16_t)(n) << WM8904_ADCR_DAC_SVOL_SHIFT)
  442. #define WM8904_ADC_TO_DACL_SHIFT (2) /* Bits 2-3: Left DAC digital sidetone source */
  443. #define WM8904_ADC_TO_DACL_MASK (3 << WM8904_ADC_TO_DACL_SHIFT)
  444. # define WM8904_ADC_TO_DACL_NONE (0 << WM8904_ADC_TO_DACL_SHIFT) /* No sidetone */
  445. # define WM8904_ADC_TO_DACL_LEFT (1 << WM8904_ADC_TO_DACL_SHIFT) /* Left ADC */
  446. # define WM8904_ADC_TO_DACL_RIGHT (2 << WM8904_ADC_TO_DACL_SHIFT) /* Right ADC */
  447. #define WM8904_ADC_TO_DACR_SHIFT (0) /* Bits 0-1: Right DAC digital sidetone source */
  448. #define WM8904_ADC_TO_DACR_MASK (3 << WM8904_ADC_TO_DACR_SHIFT)
  449. # define WM8904_ADC_TO_DACR_NONE (0 << WM8904_ADC_TO_DACR_SHIFT) /* No sidetone */
  450. # define WM8904_ADC_TO_DACR_LEFT (1 << WM8904_ADC_TO_DACR_SHIFT) /* Left ADC */
  451. # define WM8904_ADC_TO_DACR_RIGHT (2 << WM8904_ADC_TO_DACR_SHIFT) /* Right ADC */
  452. /* 0x21 DAC Digital 1 */
  453. #define WM8904_DAC_MONO (1 << 12) /* Bit 12: DAC mono mix */
  454. #define WM8904_DAC_SB_FILT (1 << 11) /* Bit 11: Selects DAC filter characteristics */
  455. #define WM8904_DAC_MUTERATE (1 << 10) /* Bit 10: DAC soft mute ramp rate */
  456. #define WM8904_DAC_UNMUTE_RAMP (1 << 9) /* Bit 9: DAC soft mute mode */
  457. #define WM8904_DAC_OSR128 (1 << 6) /* Bit 6: DAC oversample rate select */
  458. #define WM8904_DAC_MUTE (1 << 3) /* Bit 3: DAC soft mute control */
  459. #define WM8904_DEEMPH_SHIFT (1) /* Bits 1-2: DAC de-emphasis control */
  460. #define WM8904_DEEMPH_MASK (3 << WM8904_DEEMPH_SHIFT)
  461. # define WM8904_DEEMPH_NONE (0 << WM8904_DEEMPH_SHIFT) /* No de-emphasis */
  462. # define WM8904_DEEMPH_32KHZ (1 << WM8904_DEEMPH_SHIFT) /* 32kHz sample rate */
  463. # define WM8904_DEEMPH_44p1KHZ (2 << WM8904_DEEMPH_SHIFT) /* 44.1kHz sample rate */
  464. # define WM8904_DEEMPH_48KHZ (3 << WM8904_DEEMPH_SHIFT) /* 48kHz sample rate */
  465. /* 0x24 ADC Digital Volume Left */
  466. /* 0x25 ADC Digital Volume Right */
  467. #define WM8904_ADC_VU (1 << 8) /* Bit 8: ADC Volume Update */
  468. #define WM8904_ADC_VOL_SHIFT (0) /* Bits 0-7: ADC Digital Volume */
  469. #define WM8904_ADC_VOL_MASK (0xff << WM8904_ADC_VOL_SHIFT)
  470. # define WM8904_ADC_VOL(n) ((uint16_t)(n) << WM8904_ADC_VOL_SHIFT)
  471. /* 0x26 ADC Digital */
  472. #define WM8904_ADC_HPF_CUT_SHIFT (5) /* Bits 5-6: ADC digital high pass filter cut-off */
  473. #define WM8904_ADC_HPF_CUT_MASK (3 << WM8904_ADC_HPF_CUT_SHIFT)
  474. # define WM8904_ADC_HPF_CUT_HIFI (0 << WM8904_ADC_HPF_CUT_SHIFT) /* Hi-fi mode */
  475. # define WM8904_ADC_HPF_CUT_VOICE1 (1 << WM8904_ADC_HPF_CUT_SHIFT) /* Voice mode 1 */
  476. # define WM8904_ADC_HPF_CUT_VOICE2 (2 << WM8904_ADC_HPF_CUT_SHIFT) /* Voice mode 2 */
  477. # define WM8904_ADC_HPF_CUT_VOICE3 (3 << WM8904_ADC_HPF_CUT_SHIFT) /* Voice mode 3 */
  478. #define WM8904_ADC_HPF (1 << 4) /* Bit 4: ADC digital high pass filter enable */
  479. #define WM8904_ADCL_DATINV (1 << 1) /* Bit 1: Left ADC invert */
  480. #define WM8904_ADCR_DATINV (1 << 0) /* Bit 0: Right ADC invert */
  481. /* 0x27 Digital Microphone */
  482. #define WM8904_DMIC_ENA (1 << 12) /* Bit 12: Enables digital microphone mode */
  483. #define WM8904_DMIC_SRC (1 << 11) /* Bit 11: Selects digital microphone data input */
  484. /* 0x28 DRC 0 */
  485. #define WM8904_DRC_ENA (1 << 15) /* Bit 15: DRC enable */
  486. #define WM8904_DRC_DAC_PATH (1 << 14) /* Bit 14: DRC path select */
  487. #define WM8904_DRC_GS_HYST_LVL_SHIFT (11) /* Bits 11-12: Gain smoothing hysteresis threshold */
  488. #define WM8904_DRC_GS_HYST_LVL_MASK (3 << WM8904_DRC_GS_HYST_LVL_SHIFT)
  489. # define WM8904_DRC_GS_HYST_LVL(n) ((uint16_t)(n) << WM8904_DRC_GS_HYST_LVL_SHIFT)
  490. # define WM8904_DRC_GS_HYST_LOW (0 << WM8904_DRC_GS_HYST_LVL_SHIFT) /* Low */
  491. # define WM8904_DRC_GS_HYST_MEDIUM (1 << WM8904_DRC_GS_HYST_LVL_SHIFT) /* Medium */
  492. # define WM8904_DRC_GS_HYST_HIGH (2 << WM8904_DRC_GS_HYST_LVL_SHIFT) /* High */
  493. #define WM8904_DRC_STARTUP_GAIN_SHIFT (6) /* Bits 6-10: Initial gain at DRC startup */
  494. #define WM8904_DRC_STARTUP_GAIN_MASK (31 << WM8904_DRC_STARTUP_GAIN_SHIFT)
  495. # define WM8904_DRC_STARTUP_GAIN(n) ((uint16_t)(n) << WM8904_DRC_STARTUP_GAIN_SHIFT)
  496. #define WM8904_DRC_FF_DELAY (1 << 5) /* Bit 5: Feed-forward delay for anti-clip feature */
  497. #define WM8904_DRC_GS_ENA (1 << 3) /* Bit 3: Gain smoothing enable */
  498. #define WM8904_DRC_QR (1 << 2) /* Bit 2: Quick release enable */
  499. #define WM8904_DRC_ANTICLIP (1 << 1) /* Bit 1: Anti-clip enable */
  500. #define WM8904_DRC_GS_HYST (1 << 0) /* Bit 0: Gain smoothing hysteresis enable */
  501. /* 0x29 DRC 1 */
  502. #define WM8904_DRC_ATK_SHIFT (12) /* Bits 13-15: Gain attack rate (seconds/6dB) */
  503. #define WM8904_DRC_ATK_MASK (15 << WM8904_DRC_ATK_SHIFT)
  504. # define WM8904_DRC_ATK(n) ((uint16_t)(n) << WM8904_DRC_ATK_SHIFT)
  505. #define WM8904_DRC_DCY_SHIFT (8) /* Bits 8-11: Gain decay rate (seconds/6dB) */
  506. #define WM8904_DRC_DCY_MASK (15 << WM8904_DRC_DCY_SHIFT)
  507. # define WM8904_DRC_DCY(n) ((uint16_t)(n) << WM8904_DRC_DCY_SHIFT)
  508. #define WM8904_DRC_QR_THR_SHIFT (6) /* Bits 6-7: Quick release crest factor threshold */
  509. #define WM8904_DRC_QR_THR_MASK (3 << WM8904_DRC_QR_THR_SHIFT)
  510. # define WM8904_DRC_QR_THR(n) ((uint16_t)(n) << WM8904_DRC_QR_THR_SHIFT)
  511. #define WM8904_DRC_QR_DCY_SHIFT (4) /* Bits 4-5: Quick release decay rate (seconds/6dB)*/
  512. #define WM8904_DRC_QR_DCY_MASK (3 << WM8904_DRC_QR_DCY_SHIFT)
  513. # define WM8904_DRC_QR_DCY(n) ((uint16_t)(n) << WM8904_DRC_QR_DCY_SHIFT)
  514. #define WM8904_DRC_MINGAIN_SHIFT (2) /* Bits 2-3: Minimum gain the DRC can use to attenuate audio*/
  515. #define WM8904_DRC_MINGAIN_MASK (3 << WM8904_DRC_MINGAIN_SHIFT)
  516. # define WM8904_DRC_MINGAIN(n) ((uint16_t)(n) << WM8904_DRC_MINGAIN_SHIFT)
  517. #define WM8904_DRC_MAXGAIN_SHIFT (0) /* Bits 0-1: Maximum gain the DRC can use to boost audio*/
  518. #define WM8904_DRC_MAXGAIN_MASK (3 << WM8904_DRC_MAXGAIN_SHIFT)
  519. # define WM8904_DRC_MAXGAIN(n) ((uint16_t)(n) << WM8904_DRC_MAXGAIN_SHIFT)
  520. /* 0x2a DRC 2 */
  521. #define WM8904_DRC_HI_COMP_SHIFT (3) /* Bits 3-5: Compressor slope (upper region) */
  522. #define WM8904_DRC_HI_COMP_MASK (7 << WM8904_DRC_HI_COMP_SHIFT)
  523. # define WM8904_DRC_HI_COMP_DIV1 (0 << WM8904_DRC_HI_COMP_SHIFT) /* 1 (no compression) */
  524. # define WM8904_DRC_HI_COMP_DIV2 (1 << WM8904_DRC_HI_COMP_SHIFT) /* 1/2 */
  525. # define WM8904_DRC_HI_COMP_DIV4 (2 << WM8904_DRC_HI_COMP_SHIFT) /* 1/4 */
  526. # define WM8904_DRC_HI_COMP_DIV8 (3 << WM8904_DRC_HI_COMP_SHIFT) /* 1/8 */
  527. # define WM8904_DRC_HI_COMP_DIV16 (4 << WM8904_DRC_HI_COMP_SHIFT) /* 1/16 */
  528. # define WM8904_DRC_HI_COMP_ZERO (5 << WM8904_DRC_HI_COMP_SHIFT) /* 0 */
  529. #define WM8904_DRC_LO_COMP_SHIFT (0) /* Bits 0-2: Compressor slope (lower region)*/
  530. #define WM8904_DRC_LO_COMP_MASK (7 << WM8904_DRC_LO_COMP_SHIFT)
  531. # define WM8904_DRC_LO_COMP(n) ((uint16_t)(n) << WM8904_DRC_LO_COMP_SHIFT)
  532. # define WM8904_DRC_LO_COMP_DIV1 (0 << WM8904_DRC_HI_COMP_SHIFT) /* 1 (no compression) */
  533. # define WM8904_DRC_LO_COMP_DIV2 (1 << WM8904_DRC_HI_COMP_SHIFT) /* 1/2 */
  534. # define WM8904_DRC_LO_COMP_DIV4 (2 << WM8904_DRC_HI_COMP_SHIFT) /* 1/4 */
  535. # define WM8904_DRC_LO_COMP_DIV8 (3 << WM8904_DRC_HI_COMP_SHIFT) /* 1/8 */
  536. # define WM8904_DRC_LO_COMP_DIV16 (4 << WM8904_DRC_HI_COMP_SHIFT) /* 1/16 */
  537. # define WM8904_DRC_LO_COMP_ZERO (5 << WM8904_DRC_HI_COMP_SHIFT) /* 0 */
  538. /* 0x2b DRC 3 */
  539. #define WM8904_DRC_KNEE_IP_SHIFT (5) /* Bits 5-10: Input signal at the compressor knee*/
  540. #define WM8904_DRC_KNEE_IP_MASK (0X3f << WM8904_DRC_KNEE_IP_SHIFT)
  541. # define WM8904_DRC_KNEE_IP(n) ((uint16_t)(n) << WM8904_DRC_KNEE_IP_SHIFT)
  542. #define WM8904_DRC_KNEE_OP_SHIFT (0) /* Bits 0-4: Output signal at the compressor knee */
  543. #define WM8904_DRC_KNEE_OP_MASK (0x1f << WM8904_DRC_KNEE_OP_SHIFT)
  544. # define WM8904_DRC_KNEE_OP(n) ((uint16_t)(n) << WM8904_DRC_KNEE_OP_SHIFT)
  545. /* 0x2c Analogue Left Input 0 */
  546. /* 0x2d Analogue Right Input 0 */
  547. #define WM8904_INMUTE (1 << 7) /* Bit 7: Input PGA mute */
  548. #define WM8904_IN_VOL_SHIFT (0) /* Bits 0-4: Input PGA volume */
  549. #define WM8904_IN_VOL_MASK (31 << WM8904_IN_VOL_SHIFT)
  550. # define WM8904_IN_VOL(n) ((uint16_t)(n) << WM8904_IN_VOL_SHIFT)
  551. /* 0x2e Analogue Left Input 1 */
  552. /* 0x2f Analogue Right Input 1 */
  553. #define WM8904_IN_CM_ENA (1 << 6) /* Bit 6: Input PGA common mode rejection enable */
  554. #define WM8904_IP_SEL_N_SHIFT (4) /* Bits 4-5: Select pin for inverting input */
  555. #define WM8904_IP_SEL_N_MASK (3 << WM8904_IP_SEL_N_SHIFT)
  556. # define WM8904_IP_SEL_N_IN1L (0 << WM8904_IP_SEL_N_SHIFT)
  557. # define WM8904_IP_SEL_N_IN2L (1 << WM8904_IP_SEL_N_SHIFT)
  558. # define WM8904_IP_SEL_N_IN3L (2 << WM8904_IP_SEL_N_SHIFT)
  559. #define WM8904_IP_SEL_P_SHIFT (2) /* Bits 2-3: Select pin for non-inverting input */
  560. #define WM8904_IP_SEL_P_MASK (3 << WM8904_IP_SEL_P_SHIFT)
  561. # define WM8904_IP_SEL_P(n) ((uint16_t)(n) << WM8904_IP_SEL_P_SHIFT)
  562. # define WM8904_IP_SEL_P_IN1L (0 << WM8904_IP_SEL_P_SHIFT)
  563. # define WM8904_IP_SEL_P_IN2L (1 << WM8904_IP_SEL_P_SHIFT)
  564. # define WM8904_IP_SEL_P_IN3L (2 << WM8904_IP_SEL_P_SHIFT)
  565. #define WM8904_MODE_SHIFT (0) /* Bits 0-1: Sets mode for analog input */
  566. #define WM8904_MODE_MASK (23<< WM8904_MODE_SHIFT)
  567. # define WM8904_MODE(n) ((uint16_t)(n) << WM8904_MODE_SHIFT)
  568. # define WM8904_MODE_SINGLE (0 << WM8904_MODE_SHIFT) /* Single-Ended */
  569. # define WM8904_MODE_DIFFLINE (1 << WM8904_MODE_SHIFT) /* Differential Line */
  570. # define WM8904_MODE_DIFFMIC (2 << WM8904_MODE_SHIFT) /* Differential MIC */
  571. /* 0x39 Analogue OUT1 Left */
  572. /* 0x3a Analogue OUT1 Right */
  573. #define WM8904_HPOUT_MUTE (1 << 8) /* Bit 8: Headphone output mute */
  574. #define WM8904_HPOUT_VU (1 << 7) /* Bit 7: Headphone output volume update */
  575. #define WM8904_HPOUTZC (1 << 6) /* Bit 6: Headphone output zero cross enable */
  576. #define WM8904_HPOUT_VOL_SHIFT (0) /* Bits 0-5: Headphone output volume */
  577. #define WM8904_HPOUT_VOL_MASK (0x3f << WM8904_HPOUT_VOL_SHIFT)
  578. # define WM8904_HPOUT_VOL(n) ((uint16_t)(n) << WM8904_HPOUT_VOL_SHIFT)
  579. /* 0x3b Analogue OUT2 Left */
  580. /* 0x3c Analogue OUT2 Right */
  581. #define WM8904_LINEOUT_MUTE (1 << 8) /* Bit 8: Headphone output mute */
  582. #define WM8904_LINEOUT_VU (1 << 7) /* Bit 7: Headphone output volume update */
  583. #define WM8904_LINEOUTZC (1 << 6) /* Bit 6: Headphone output zero cross enable */
  584. #define WM8904_LINEOUT_VOL_SHIFT (0) /* Bits 0-5: Headphone output volume */
  585. #define WM8904_LINEOUT_VOL_MASK (0x3f << WM8904_LINEOUT_VOL_SHIFT)
  586. # define WM8904_LINEOUT_VOL(n) ((uint16_t)(n) << WM8904_LINEOUT_VOL_SHIFT)
  587. /* 0x3d Analogue OUT12 ZC */
  588. #define WM8904_HPL_BYP_ENA (1 << 3) /* Bit 3: Selects input for left headphone output MUX */
  589. #define WM8904_HPR_BYP_ENA (1 << 2) /* Bit 2: Selects input for right headphone output MUX */
  590. #define WM8904_LINEOUTL_BYP_ENA (1 << 1) /* Bit 1: Selects input for left line output MUX */
  591. #define WM8904_LINEOUTR_BYP_ENA (1 << 0) /* Bit 0: Selects input for right line output MUX */
  592. /* 0x43 DC Servo 0 */
  593. #define WM8904_DCS_ENA_CHAN_3 (1 << 3) /* Bit 3: DC servo enable for LINEOUTR */
  594. #define WM8904_DCS_ENA_CHAN_2 (1 << 2) /* Bit 2: DC servo enable for LINEOUTL */
  595. #define WM8904_DCS_ENA_CHAN_1 (1 << 1) /* Bit 1: DC servo enable for HPOUTR */
  596. #define WM8904_DCS_ENA_CHAN_0 (1 << 0) /* Bit 0: DC servo enable for HPOUTL */
  597. /* 0x44 DC Servo 1 */
  598. #define WM8904_DCS_TRIG_SINGLE_3 (1 << 15) /* Bit 15: Single DC offset correction for LINEOUTR */
  599. #define WM8904_DCS_TRIG_SINGLE_2 (1 << 14) /* Bit 14: Single DC offset correction for LINEOUTL */
  600. #define WM8904_DCS_TRIG_SINGLE_1 (1 << 13) /* Bit 13: Single DC offset correction for HPOUTR */
  601. #define WM8904_DCS_TRIG_SINGLE_0 (1 << 12) /* Bit 12: Single DC offset correction for HPOUTL */
  602. #define WM8904_DCS_TRIG_SERIES_3 (1 << 11) /* Bit 11: Series of DC offset corrections for LINEOUTR */
  603. #define WM8904_DCS_TRIG_SERIES_2 (1 << 10) /* Bit 10: Series of DC offset corrections for LINEOUTL */
  604. #define WM8904_DCS_TRIG_SERIES_1 (1 << 9) /* Bit 9: Series of DC offset corrections for HPOUTR */
  605. #define WM8904_DCS_TRIG_SERIES_0 (1 << 8) /* Bit 8: Series of DC offset corrections for HPOUTL */
  606. #define WM8904_DCS_TRIG_STARTUP_3 (1 << 7) /* Bit 7: Start-up DC Servo mode for LINEOUTR */
  607. #define WM8904_DCS_TRIG_STARTUP_2 (1 << 6) /* Bit 6: Start-up DC Servo mode for LINEOUTL */
  608. #define WM8904_DCS_TRIG_STARTUP_1 (1 << 5) /* Bit 5: Start-up DC Servo mode for HPOUTR */
  609. #define WM8904_DCS_TRIG_STARTUP_0 (1 << 4) /* Bit 4: Start-up DC Servo mode for HPOUTL */
  610. #define WM8904_DCS_TRIG_DAC_WR_3 (1 << 3) /* Bit 3: DAC write DC Servo mode for LINEOUTR */
  611. #define WM8904_DCS_TRIG_DAC_WR_2 (1 << 2) /* Bit 2: DAC write DC Servo mode for LINEOUTL */
  612. #define WM8904_DCS_TRIG_DAC_WR_1 (1 << 1) /* Bit 1: DAC write DC Servo mode for HPOUTR */
  613. #define WM8904_DCS_TRIG_DAC_WR_0 (1 << 0) /* Bit 0: DAC write DC Servo mode for HPOUTL */
  614. /* 0x45 DC Servo 2 */
  615. #define WM8904_DCS_TIMER_PERIOD_23_SHIFT (8) /* Bits 8-11: LINEOUTL/LINEOUTR update period */
  616. #define WM8904_DCS_TIMER_PERIOD_23_MASK (15 << WM8904_DCS_TIMER_PERIOD_23_SHIFT)
  617. # define WM8904_DCS_TIMER_PERIOD_23(n) ((uint16_t)(n) << WM8904_DCS_TIMER_PERIOD_23_SHIFT)
  618. #define WM8904_DCS_TIMER_PERIOD_01_SHIFT (0) /* Bits 0-3: HPOUTL/HPOUTR update period */
  619. #define WM8904_DCS_TIMER_PERIOD_01_MASK (15 << WM8904_DCS_TIMER_PERIOD_01_SHIFT)
  620. # define WM8904_DCS_TIMER_PERIOD_01(n) ((uint16_t)(n) << WM8904_DCS_TIMER_PERIOD_01_SHIFT)
  621. /* 0x47 DC Servo 4 */
  622. #define WM8904_DCS_SERIES_NO_23_MASK (0x007f) /* Bits 0-6: Number updates to perform in series for LINEOUTL/R */
  623. /* 0x48 DC Servo 5 */
  624. #define WM8904_DCS_SERIES_NO_01_MASK (0x007f) /* Bits 0-6: Number updates to perform in series for HPOUTL/R */
  625. /* 0x49 DC Servo 6 */
  626. #define WM8904_DCS_DAC_WR_VAL_3_MASK (0x00ff) /* Bits 0-7: DC Offset value for LINEOUTR */
  627. /* 0x4a DC Servo 7 */
  628. #define WM8904_DCS_DAC_WR_VAL_2_MASK (0x00ff) /* Bits 0-7: DC Offset value for LINEOUTL */
  629. /* 0x4b DC Servo 8 */
  630. #define WM8904_DCS_DAC_WR_VAL_1_MASK (0x00ff) /* Bits 0-7: DC Offset value for HPOUTR */
  631. /* 0x4c DC Servo 9 */
  632. #define WM8904_DCS_DAC_WR_VAL_0_MASK (0x00ff) /* Bits 0-7: DC Offset value for HPOUTL */
  633. /* 0x4d DC Servo Readback 0 */
  634. #define WM8904_DCS_CAL_COMPLETE_SHIFT (8) /* Bits 8-11: DC servo complete status */
  635. #define WM8904_DCS_CAL_COMPLETE_MASK (15 << WM8904_DCS_CAL_COMPLETE_SHIFT)
  636. # define WM8904_DCS_CAL_COMPLETE_LINEOUTR (8 << WM8904_DCS_CAL_COMPLETE_SHIFT)
  637. # define WM8904_DCS_CAL_COMPLETE_LINEOUTL (4 << WM8904_DCS_CAL_COMPLETE_SHIFT)
  638. # define WM8904_DCS_CAL_COMPLETE_HPOUTR (2 << WM8904_DCS_CAL_COMPLETE_SHIFT)
  639. # define WM8904_DCS_CAL_COMPLETE_HPOUTL (1 << WM8904_DCS_CAL_COMPLETE_SHIFT)
  640. #define WM8904_DCS_DAC_WR_COMPLETE_SHIFT (4) /* Bits 4-7: DC servo DAC write status */
  641. #define WM8904_DCS_DAC_WR_COMPLETE_MASK (15 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  642. # define WM8904_DCS_DAC_WR_COMPLETE_LINEOUTR (8 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  643. # define WM8904_DCS_DAC_WR_COMPLETE_LINEOUTL (4 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  644. # define WM8904_DCS_DAC_WR_COMPLETE_HPOUTR (2 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  645. # define WM8904_DCS_DAC_WR_COMPLETE_HPOUTL (1 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  646. #define WM8904_DCS_STARTUP_COMPLETE_SHIFT (0) /* Bits 0-3: DC servo start-up status */
  647. #define WM8904_DCS_STARTUP_COMPLETE_MASK (15 << WM8904_DCS_STARTUP_COMPLETE_SHIFT)
  648. # define WM8904_DCS_STARTUP_COMPLETE(n) ((uint16_t)(n) << WM8904_DCS_STARTUP_COMPLETE_SHIFT)
  649. # define WM8904_DCS_STARTUP_COMPLETE_LINEOUTR (8 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  650. # define WM8904_DCS_STARTUP_COMPLETE_LINEOUTL (4 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  651. # define WM8904_DCS_STARTUP_COMPLETE_HPOUTR (2 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  652. # define WM8904_DCS_STARTUP_COMPLETE_HPOUTL (1 << WM8904_DCS_DAC_WR_COMPLETE_SHIFT)
  653. /* 0x5a Analogue HP 0 */
  654. #define WM8904_HPL_RMV_SHORT (1 << 7) /* Bit 7: Removes HPOUTL short */
  655. #define WM8904_HPL_ENA_OUTP (1 << 6) /* Bit 6: Enables HPOUTL output stage */
  656. #define WM8904_HPL_ENA_DLY (1 << 5) /* Bit 5: Enables HPOUTL intermediate stage */
  657. #define WM8904_HPL_ENA (1 << 4) /* Bit 4: Enables HPOUTL input stage */
  658. #define WM8904_HPR_RMV_SHORT (1 << 3) /* Bit 3: Removes HPOUTR short */
  659. #define WM8904_HPR_ENA_OUTP (1 << 2) /* Bit 2: Enables HPOUTR output stage */
  660. #define WM8904_HPR_ENA_DLY (1 << 1) /* Bit 1: Enables HPOUTR intermediate stage */
  661. #define WM8904_HPR_ENA (1 << 0) /* Bit 0: Enables HPOUTR input stage */
  662. /* 0x5e Analogue Lineout 0 */
  663. #define WM8904_LINEOUTL_RMV_SHORT (1 << 7) /* Bit 7: Removes LINEOUTL short */
  664. #define WM8904_LINEOUTL_ENA_OUTP (1 << 6) /* Bit 6: Enables LINEOUTL output stage */
  665. #define WM8904_LINEOUTL_ENA_DLY (1 << 5) /* Bit 5: Enables LINEOUTL intermediate stage */
  666. #define WM8904_LINEOUTL_ENA (1 << 4) /* Bit 4: Enables LINEOUTL input stage */
  667. #define WM8904_LINEOUTR_RMV_SHORT (1 << 3) /* Bit 3: Removes LINEOUTR short */
  668. #define WM8904_LINEOUTR_ENA_OUTP (1 << 2) /* Bit 2: Enables LINEOUTR output stage */
  669. #define WM8904_LINEOUTR_ENA_DLY (1 << 1) /* Bit 1: Enables LINEOUTR intermediate stage */
  670. #define WM8904_LINEOUTR_ENA (1 << 0) /* Bit 0: Enables LINEOUTR input stage */
  671. /* 0x62 Charge Pump 0 */
  672. #define WM8904_CP_ENA (1 << 0) /* Bit 0: Enable charge-pump digits */
  673. /* 0x68 Class W 0 */
  674. #define WM8904_CP_DYN_PWR (1 << 0) /* Bit 0: Enable dynamic charge pump power control */
  675. /* 0x6c Write Sequencer 0 */
  676. #define WM8904_WSEQ_ENA (1 << 8) /* Bit 8: Write sequencer enable */
  677. #define WM8904_WSEQ_WRITE_INDEX_SHIFT (0) /* Bits 0-4: Sequence write index */
  678. #define WM8904_WSEQ_WRITE_INDEX_MASK (31 << WM8904_WSEQ_WRITE_INDEX_SHIFT)
  679. # define WM8904_WSEQ_WRITE_INDEX(n) ((uint16_t)(n) << WM8904_WSEQ_WRITE_INDEX_SHIFT)
  680. /* 0x6d Write Sequencer 1 */
  681. #define WM8904_WSEQ_DATA_WIDTH_SHIFT (12) /* Bits 12-14: Width of data block in sequence step */
  682. #define WM8904_WSEQ_DATA_WIDTH_MASK (7 << WM8904_WSEQ_DATA_WIDTH_SHIFT)
  683. # define WM8904_WSEQ_DATA_WIDTH(n) ((uint16_t)((n)-1) << WM8904_WSEQ_DATA_WIDTH_SHIFT)
  684. #define WM8904_WSEQ_DATA_START_SHIFT (8) /* Bits 8-11: LSB bit of data block in sequence step */
  685. #define WM8904_WSEQ_DATA_START_MASK (15 << WM8904_WSEQ_DATA_START_SHIFT)
  686. # define WM8904_WSEQ_DATA_START(n) ((uint16_t)(n) << WM8904_WSEQ_DATA_START_SHIFT)
  687. #define WM8904_WSEQ_ADDR_SHIFT (0) /* Bits 0-7: Control Register be written in sequence step */
  688. #define WM8904_WSEQ_ADDR_MASK (0xff << WM8904_WSEQ_ADDR_SHIFT)
  689. # define WM8904_WSEQ_ADDR(n) ((uint16_t)(n) << WM8904_WSEQ_ADDR_SHIFT)
  690. /* 0x6e Write Sequencer 2 */
  691. #define WM8904_WSEQ_EOS (1 << 14) /* Bit 14: End of sequence flag */
  692. #define WM8904_WSEQ_DELAY_SHIFT (8) /* Bits 8-11: Time delay after executing this step */
  693. #define WM8904_WSEQ_DELAY_MASK (15 << WM8904_WSEQ_DELAY_SHIFT)
  694. # define WM8904_WSEQ_DELAY(n) ((uint16_t)(n) << WM8904_WSEQ_DELAY_SHIFT)
  695. #define WM8904_WSEQ_DATA_SHIFT (0) /* Bits 0-7: Data to be written in this sequence step */
  696. #define WM8904_WSEQ_DATA_MASK (0xff << WM8904_WSEQ_DATA_SHIFT)
  697. # define WM8904_WSEQ_DATA(n) ((uint16_t)(n) << WM8904_WSEQ_DATA_SHIFT)
  698. /* 0x6f Write Sequencer 3 */
  699. #define WM8904_WSEQ_ABORT (1 << 9) /* Bit 9: Aborts the current sequence */
  700. #define WM8904_WSEQ_START (1 << 8) /* Bit 8: Starts the write sequencer */
  701. #define WM8904_WSEQ_START_INDEX_SHIFT (0) /* Bits 0-5: Sequence start index */
  702. #define WM8904_WSEQ_START_INDEX_MASK (63 << WM8904_WSEQ_START_INDEX_SHIFT)
  703. # define WM8904_WSEQ_START_INDEX(n) ((uint16_t)(n) << WM8904_WSEQ_START_INDEX_SHIFT)
  704. /* 0x70 Write Sequencer 4 */
  705. #define WM8904_WSEQ_CURRENT_INDEX_SHIFT (4) /* Bits 4-9: Sequence current index */
  706. #define WM8904_WSEQ_CURRENT_INDEX_MASK (63 << WM8904_WSEQ_CURRENT_INDEX_SHIFT)
  707. #define WM8904_WSEQ_BUSY (1 << 0) /* Bit 0: Sequencer busy flag */
  708. /* 0x74 FLL Control 1 */
  709. #define WM8904_FLL_FRACN_ENA (1 << 2) /* Bit 2: FLL fractional enable */
  710. #define WM8904_FLL_OSC_ENA (1 << 1) /* Bit 1: FLL oscillator enable */
  711. #define WM8904_FLL_ENA (1 << 0) /* Bit 0: FLL enable */
  712. /* 0x75 FLL Control 2 */
  713. #define WM8904_FLL_OUTDIV_SHIFT (8) /* Bits 8-13: FLL FOUT clock divider */
  714. #define WM8904_FLL_OUTDIV_MASK (63 << WM8904_FLL_OUTDIV_SHIFT)
  715. # define WM8904_FLL_OUTDIV(n) ((uint16_t)((n)-1) << WM8904_FLL_OUTDIV_SHIFT)
  716. #define WM8904_FLL_CTRL_RATE_SHIFT (4) /* Bits 4-6: Frequency of the FLL control block */
  717. #define WM8904_FLL_CTRL_RATE_MASK (7 << WM8904_FLL_CTRL_RATE_SHIFT)
  718. # define WM8904_FLL_CTRL_RATE(n) ((uint16_t)((n)-1) << WM8904_FLL_CTRL_RATE_SHIFT)
  719. #define WM8904_FLL_FRATIO_SHIFT (0) /* Bits 0-2: FVCO clock divider */
  720. #define WM8904_FLL_FRATIO_MASK (7 << WM8904_FLL_FRATIO_SHIFT)
  721. # define WM8904_FLL_FRATIO(n) ((uint32_t)(n) << WM8904_FLL_FRATIO_SHIFT)
  722. # define WM8904_FLL_FRATIO_DIV1 (0 << WM8904_FLL_FRATIO_SHIFT) /* Divide by 1 */
  723. # define WM8904_FLL_FRATIO_DIV2 (1 << WM8904_FLL_FRATIO_SHIFT) /* Divide by 2 */
  724. # define WM8904_FLL_FRATIO_DIV4 (2 << WM8904_FLL_FRATIO_SHIFT) /* Divide by 4 */
  725. # define WM8904_FLL_FRATIO_DIV8 (3 << WM8904_FLL_FRATIO_SHIFT) /* Divide by 8 */
  726. # define WM8904_FLL_FRATIO_DIV16 (4 << WM8904_FLL_FRATIO_SHIFT) /* Divide by 16 */
  727. /* 0x76 FLL Control 3, Bits 0-15=Fractional multiply for FREF */
  728. /* 0x77 FLL Control 4 */
  729. #define WM8904_FLL_N_SHIFT (5) /* Bits 5-14: Integer multiply for FREF */
  730. #define WM8904_FLL_N_MASK (0x3ff << WM8904_FLL_N_SHIFT)
  731. # define WM8904_FLL_N(n) ((uint16_t)(n) << WM8904_FLL_N_SHIFT)
  732. #define WM8904_FLL_GAIN_SHIFT (0) /* Bits 0-3: FLL Gain applied to error */
  733. #define WM8904_FLL_GAIN_MASK (15 << WM8904_FLL_GAIN_SHIFT)
  734. # define WM8904_FLL_GAIN_X1 (0 << WM8904_FLL_GAIN_SHIFT)
  735. # define WM8904_FLL_GAIN_X2 (1 << WM8904_FLL_GAIN_SHIFT)
  736. # define WM8904_FLL_GAIN_X4 (2 << WM8904_FLL_GAIN_SHIFT)
  737. # define WM8904_FLL_GAIN_X8 (3 << WM8904_FLL_GAIN_SHIFT)
  738. # define WM8904_FLL_GAIN_X16 (4 << WM8904_FLL_GAIN_SHIFT)
  739. # define WM8904_FLL_GAIN_X32 (5 << WM8904_FLL_GAIN_SHIFT)
  740. # define WM8904_FLL_GAIN_X64 (6 << WM8904_FLL_GAIN_SHIFT)
  741. # define WM8904_FLL_GAIN_X128 (7 << WM8904_FLL_GAIN_SHIFT)
  742. # define WM8904_FLL_GAIN_X256 (8 << WM8904_FLL_GAIN_SHIFT)
  743. /* 0x78 FLL Control 5 */
  744. #define WM8904_FLL_CLK_REF_DIV_SHIFT (3) /* Bits 3-4: FLL clock reference divider */
  745. #define WM8904_FLL_CLK_REF_DIV_MASK (3 << WM8904_FLL_CLK_REF_DIV_SHIFT)
  746. # define WM8904_FLL_CLK_REF_DIV1 (0 << WM8904_FLL_CLK_REF_DIV_SHIFT) /* MCLK / 1 */
  747. # define WM8904_FLL_CLK_REF_DIV2 (1 << WM8904_FLL_CLK_REF_DIV_SHIFT) /* MCLK / 2 */
  748. # define WM8904_FLL_CLK_REF_DIV4 (2 << WM8904_FLL_CLK_REF_DIV_SHIFT) /* MCLK / 4 */
  749. # define WM8904_FLL_CLK_REF_DIV8 (3 << WM8904_FLL_CLK_REF_DIV_SHIFT) /* MCLK / 8 */
  750. #define WM8904_FLL_CLK_REF_SRC_SHIFT (0) /* Bits 0-2: FLL clock source */
  751. #define WM8904_FLL_CLK_REF_SRC_MASK (3 << WM8904_FLL_CLK_REF_SRC_SHIFT)
  752. # define WM8904_FLL_CLK_REF_SRC_MCLK (0 << WM8904_FLL_CLK_REF_SRC_SHIFT)
  753. # define WM8904_FLL_CLK_REF_SRC_BCLK (1 << WM8904_FLL_CLK_REF_SRC_SHIFT)
  754. # define WM8904_FLL_CLK_REF_SRC_LRCLK (2 << WM8904_FLL_CLK_REF_SRC_SHIFT)
  755. /* 0x79 GPIO Control 1 */
  756. #define WM8904_GPIO1_PU (1 << 5) /* Bit 5: GPIO1 pull-up resistor enable */
  757. #define WM8904_GPIO1_PD (1 << 4) /* Bit 4: GPIO1 pull-down resistor enable */
  758. #define WM8904_GPIO1_SEL_SHIFT (0) /* Bits 0-3: */
  759. #define WM8904_GPIO1_SEL_MASK (15 << WM8904_GPIO1_SEL_SHIFT)
  760. # define WM8904_GPIO1_SEL_INPUT (0 << WM8904_GPIO1_SEL_SHIFT) /* Input pin */
  761. # define WM8904_GPIO1_SEL_CLKOUT (1 << WM8904_GPIO1_SEL_SHIFT) /* Clock output (f=SYSCLK/OPCLKDIV) */
  762. # define WM8904_GPIO1_SEL_ZERO (2 << WM8904_GPIO1_SEL_SHIFT) /* Logic '0' */
  763. # define WM8904_GPIO1_SEL_ONE (3 << WM8904_GPIO1_SEL_SHIFT) /* Logic '1' */
  764. # define WM8904_GPIO1_SEL_IRQ (4 << WM8904_GPIO1_SEL_SHIFT) /* IRQ */
  765. # define WM8904_GPIO1_SEL_FLLLOCK (5 << WM8904_GPIO1_SEL_SHIFT) /* FLL Lock */
  766. # define WM8904_GPIO1_SEL_MICDET (6 << WM8904_GPIO1_SEL_SHIFT) /* Mic Detect */
  767. # define WM8904_GPIO1_SEL_MICSHORT (7 << WM8904_GPIO1_SEL_SHIFT) /* Mic Short */
  768. # define WM8904_GPIO1_SEL_DMICOUT (8 << WM8904_GPIO1_SEL_SHIFT) /* DMIC clock out */
  769. # define WM8904_GPIO1_SEL_FLLOUT (9 << WM8904_GPIO1_SEL_SHIFT) /* FLL Clock Output */
  770. /* 0x7a GPIO Control 2 */
  771. #define WM8904_GPIO2_PU (1 << 5) /* Bit 5: GPIO2 pull-up resistor enable */
  772. #define WM8904_GPIO2_PD (1 << 4) /* Bit 4: GPIO2 pull-down resistor enable */
  773. #define WM8904_GPIO2_SEL_SHIFT (0) /* Bits 0-3: */
  774. #define WM8904_GPIO2_SEL_MASK (15 << WM8904_GPIO2_SEL_SHIFT)
  775. # define WM8904_GPIO2_SEL_INPUT (0 << WM8904_GPIO2_SEL_SHIFT) /* Input pin */
  776. # define WM8904_GPIO2_SEL_CLKOUT (1 << WM8904_GPIO2_SEL_SHIFT) /* Clock output (f=SYSCLK/OPCLKDIV) */
  777. # define WM8904_GPIO2_SEL_ZERO (2 << WM8904_GPIO2_SEL_SHIFT) /* Logic '0' */
  778. # define WM8904_GPIO2_SEL_ONE (3 << WM8904_GPIO2_SEL_SHIFT) /* Logic '1' */
  779. # define WM8904_GPIO2_SEL_IRQ (4 << WM8904_GPIO2_SEL_SHIFT) /* IRQ */
  780. # define WM8904_GPIO2_SEL_FLLLOCK (5 << WM8904_GPIO2_SEL_SHIFT) /* FLL Lock */
  781. # define WM8904_GPIO2_SEL_MICDET (6 << WM8904_GPIO2_SEL_SHIFT) /* Mic Detect */
  782. # define WM8904_GPIO2_SEL_MICSHORT (7 << WM8904_GPIO2_SEL_SHIFT) /* Mic Short */
  783. # define WM8904_GPIO2_SEL_DMICOUT (8 << WM8904_GPIO2_SEL_SHIFT) /* DMIC clock out */
  784. # define WM8904_GPIO2_SEL_FLLOUT (9 << WM8904_GPIO2_SEL_SHIFT) /* FLL Clock Output */
  785. /* 0x7b GPIO Control 3 */
  786. #define WM8904_GPIO3_PU (1 << 5) /* Bit 5: GPIO3 pull-up resistor enable */
  787. #define WM8904_GPIO3_PD (1 << 4) /* Bit 4: GPIO3 pull-down resistor enable */
  788. #define WM8904_GPIO3_SEL_SHIFT (0) /* Bits 0-3: */
  789. #define WM8904_GPIO3_SEL_MASK (15 << WM8904_GPIO3_SEL_SHIFT)
  790. # define WM8904_GPIO3_SEL_INPUT (0 << WM8904_GPIO3_SEL_SHIFT) /* Input pin */
  791. # define WM8904_GPIO3_SEL_CLKOUT (1 << WM8904_GPIO3_SEL_SHIFT) /* Clock output (f=SYSCLK/OPCLKDIV) */
  792. # define WM8904_GPIO3_SEL_ZERO (2 << WM8904_GPIO3_SEL_SHIFT) /* Logic '0' */
  793. # define WM8904_GPIO3_SEL_ONE (3 << WM8904_GPIO3_SEL_SHIFT) /* Logic '1' */
  794. # define WM8904_GPIO3_SEL_IRQ (4 << WM8904_GPIO3_SEL_SHIFT) /* IRQ */
  795. # define WM8904_GPIO3_SEL_FLLLOCK (5 << WM8904_GPIO3_SEL_SHIFT) /* FLL Lock */
  796. # define WM8904_GPIO3_SEL_MICDET (6 << WM8904_GPIO3_SEL_SHIFT) /* Mic Detect */
  797. # define WM8904_GPIO3_SEL_MICSHORT (7 << WM8904_GPIO3_SEL_SHIFT) /* Mic Short */
  798. # define WM8904_GPIO3_SEL_DMICOUT (8 << WM8904_GPIO3_SEL_SHIFT) /* DMIC clock out */
  799. # define WM8904_GPIO3_SEL_FLLOUT (9 << WM8904_GPIO3_SEL_SHIFT) /* FLL Clock Output */
  800. /* 0x7c GPIO Control 4 */
  801. #define WM8904_GPI7_ENA (1 << 9) /* Bit 9: GPI7 input enable */
  802. #define WM8904_GPI8_ENA (1 << 8) /* Bit 8: GPI8 input enable */
  803. #define WM8904_GPIO_BCLK_MODE_ENA (1 << 7) /* Bit 7: Selects BCLK/GPIO4 pin function */
  804. #define WM8904_GPIO_BCLK_SEL_SHIFT (0) /* Bits 0-3: GPIO_BCLK function select */
  805. #define WM8904_GPIO_BCLK_SEL_MASK (15 << WM8904_GPIO_BCLK_SEL_SHIFT)
  806. # define WM8904_GPIO_BCLK_SEL_INPUT (0 << WM8904_GPIO_BCLK_SEL_SHIFT) /* Input pin */
  807. # define WM8904_GPIO_BCLK_SEL_CLKOUT (1 << WM8904_GPIO_BCLK_SEL_SHIFT) /* Clock output (f=SYSCLK/OPCLKDIV) */
  808. # define WM8904_GPIO_BCLK_SEL_ZERO (2 << WM8904_GPIO_BCLK_SEL_SHIFT) /* Logic '0' */
  809. # define WM8904_GPIO_BCLK_SEL_ONE (3 << WM8904_GPIO_BCLK_SEL_SHIFT) /* Logic '1' */
  810. # define WM8904_GPIO_BCLK_SEL_IRQ (4 << WM8904_GPIO_BCLK_SEL_SHIFT) /* IRQ */
  811. # define WM8904_GPIO_BCLK_SEL_FLLLOCK (5 << WM8904_GPIO_BCLK_SEL_SHIFT) /* FLL Lock */
  812. # define WM8904_GPIO_BCLK_SEL_MICDET (6 << WM8904_GPIO_BCLK_SEL_SHIFT) /* Mic Detect */
  813. # define WM8904_GPIO_BCLK_SEL_MICSHORT (7 << WM8904_GPIO_BCLK_SEL_SHIFT) /* Mic Short */
  814. # define WM8904_GPIO_BCLK_SEL_DMICOUT (8 << WM8904_GPIO_BCLK_SEL_SHIFT) /* DMIC clock out */
  815. # define WM8904_GPIO_BCLK_SEL_FLLOUT (9 << WM8904_GPIO_BCLK_SEL_SHIFT) /* FLL Clock Output */
  816. /* 0x7e Digital Pulls */
  817. #define WM8904_MCLK_PU (1 << 7) /* Bit 7: MCLK pull-up resistor enable */
  818. #define WM8904_MCLK_PD (1 << 6) /* Bit 6: MCLK pull-down resistor enable */
  819. #define WM8904_DACDAT_PU (1 << 5) /* Bit 5: DACDAT pull-up resistor enable */
  820. #define WM8904_DACDAT_PD (1 << 4) /* Bit 4: DACDAT pull-down resistor enable */
  821. #define WM8904_LRCLK_PU (1 << 3) /* Bit 3: LRCLK pull-up resistor enable */
  822. #define WM8904_LRCLK_PD (1 << 2) /* Bit 2: LRCLK pull-down resistor enable */
  823. #define WM8904_BCLK_PU (1 << 1) /* Bit 1: BCLK pull-up resistor enable */
  824. #define WM8904_BCLK_PD (1 << 0) /* Bit 0: BCLK pull-down resistor enable */
  825. /* Common interrupt bits */
  826. /* 0x7f Interrupt Status */
  827. /* 0x80 Interrupt Status Mask */
  828. /* 0x81 Interrupt Polarity */
  829. /* 0x82 Interrupt Debounce */
  830. #define WM8904_GPIO_BCLK_INT (1 << 9) /* Bit 9: GPIO4 interrupt */
  831. #define WM8904_WSEQ_INT (1 << 8) /* Bit 8: Write Sequence interrupt */
  832. #define WM8904_GPIO3_INT (1 << 7) /* Bit 7: GPIO3 interrupt */
  833. #define WM8904_GPIO2_INT (1 << 6) /* Bit 6: GPIO2 interrupt */
  834. #define WM8904_GPIO1_INT (1 << 5) /* Bit 5: GPIO1 interrupt */
  835. #define WM8904_GPI8_INT (1 << 4) /* Bit 4: GPI8 interrupt */
  836. #define WM8904_GPI7_INT (1 << 3) /* Bit 3: GPI7 interrupt */
  837. #define WM8904_FLL_LOCK_INT (1 << 2) /* Bit 2: FLL Lock interrupt */
  838. #define WM8904_MIC_SHRT_INT (1 << 1) /* Bit 1: MICBIAS short circuit interrupt */
  839. #define WM8904_MIC_DET_INT (1 << 0) /* Bit 0: MICBIAS short circuit interrupt */
  840. #define WM8904_ALL_INTS (0x03ff)
  841. /* 0x7f Interrupt Status (only) */
  842. #define WM8904_IRQ (1 << 10) /* Bit 10: Logical OR of all other interrupt flags */
  843. /* 0x86 EQ1 */
  844. #define WM8904_EQ_ENA (1 << 0) /* Bit 0: EQ enable */
  845. /* 0x87-0x8b EQ2-EQ6: 5 bit equalizer value */
  846. /* 0x8c-0x9d EQ7-EQ24: 16-bit equalizer value */
  847. /* 0xa1 Control Interface Test 1 */
  848. #define WM8904_USER_KEY 0x0002
  849. /* 0xc6 ADC Test */
  850. #define WM8904_ADC_128_OSR_TST_MODE (1 << 2) /* Bit 2: ADC bias control (1) */
  851. #define WM8904_ADC_BIASX1P5 (1 << 0) /* Bit 0: ADC bias control (2) */
  852. /* 0xcc Analogue Output Bias 0 */
  853. #define WM8904_ANA_OUT_BIAS_SHIFT (4) /* Bits 4-6: */
  854. #define WM8904_ANA_OUT_BIAS_MASK (7 << WM8904_ANA_OUT_BIAS_SHIFT)
  855. # define WM8904_ANA_OUT_BIAS(n) ((uint16_t)(n) << WM8904_ANA_OUT_BIAS_SHIFT)
  856. /* 0xf7 FLL NCO Test 0 */
  857. #define WM8904_FLL_FRC_NCO (1 << 0) /* Bit 0: FLL Forced control select */
  858. /* 0xf8 FLL NCO Test 1 */
  859. #define WM8904FLL_FRC_NCO_SHIFT (0) /* Bits 0-5: FLL forced oscillator value */
  860. #define WM8904FLL_FRC_NCO_MASK (0x3f << WM8904FLL_FRC_NCO_SHIFT)
  861. # define WM8904FLL_FRC_NCO_VAL(n) ((uint16_t)(n) << WM8904FLL_FRC_NCO_SHIFT)
  862. /* FLL Configuration *********************************************************/
  863. /* Default FLL configuration */
  864. #define WM8904_DEFAULT_SAMPRATE 11025 /* Initial sample rate */
  865. #define WM8904_DEFAULT_NCHANNELS 1 /* Initial number of channels */
  866. #define WM8904_DEFAULT_BPSAMP 16 /* Initial bits per sample */
  867. #define WM8904_NFLLRATIO_DIV1 0 /* Values of the FLL_RATIO field */
  868. #define WM8904_NFLLRATIO_DIV2 1
  869. #define WM8904_NFLLRATIO_DIV4 2
  870. #define WM8904_NFLLRATIO_DIV8 3
  871. #define WM8904_NFLLRATIO_DIV16 4
  872. #define WM8904_NFLLRATIO 5 /* Number of FLL_RATIO values */
  873. #define WM8904_MINOUTDIV 4 /* Minimum FLL_OUTDIV divider */
  874. #define WM8904_MAXOUTDIV 64 /* Maximum FLL_OUTDIV divider */
  875. #define WM8904_BCLK_MAXDIV 20 /* Maximum BCLK divider */
  876. #define WM8904_FVCO_MIN 90000000 /* Minimum value of Fvco */
  877. #define WM8904_FVCO_MAX 100000000 /* Maximum value of Fvco */
  878. #define WM8904_FRAMELEN8 14 /* Bits per frame for 8-bit data */
  879. #define WM8904_FRAMELEN16 32 /* Bits per frame for 16-bit data */
  880. /* Commonly defined and redefined macros */
  881. #ifndef MIN
  882. # define MIN(a,b) (((a) < (b)) ? (a) : (b))
  883. #endif
  884. #ifndef MAX
  885. # define MAX(a,b) (((a) > (b)) ? (a) : (b))
  886. #endif
  887. /****************************************************************************
  888. * Public Types
  889. ****************************************************************************/
  890. struct wm8904_dev_s
  891. {
  892. /* We are an audio lower half driver (We are also the upper "half" of
  893. * the WM8904 driver with respect to the board lower half driver).
  894. *
  895. * Terminology: Our "lower" half audio instances will be called dev for the
  896. * publicly visible version and "priv" for the version that only this driver
  897. * knows. From the point of view of this driver, it is the board lower
  898. * "half" that is referred to as "lower".
  899. */
  900. struct audio_lowerhalf_s dev; /* WM8904 audio lower half (this device) */
  901. /* Our specific driver data goes here */
  902. const FAR struct wm8904_lower_s *lower; /* Pointer to the board lower functions */
  903. FAR struct i2c_master_s *i2c; /* I2C driver to use */
  904. FAR struct i2s_dev_s *i2s; /* I2S driver to use */
  905. struct dq_queue_s pendq; /* Queue of pending buffers to be sent */
  906. struct dq_queue_s doneq; /* Queue of sent buffers to be returned */
  907. mqd_t mq; /* Message queue for receiving messages */
  908. char mqname[16]; /* Our message queue name */
  909. pthread_t threadid; /* ID of our thread */
  910. uint32_t bitrate; /* Actual programmed bit rate */
  911. sem_t pendsem; /* Protect pendq */
  912. #ifdef WM8904_USE_FFLOCK_INT
  913. struct work_s work; /* Interrupt work */
  914. #endif
  915. uint16_t samprate; /* Configured samprate (samples/sec) */
  916. #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
  917. #ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
  918. uint16_t balance; /* Current balance level (b16) */
  919. #endif /* CONFIG_AUDIO_EXCLUDE_BALANCE */
  920. uint8_t volume; /* Current volume level {0..63} */
  921. #endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */
  922. uint8_t nchannels; /* Number of channels (1 or 2) */
  923. uint8_t bpsamp; /* Bits per sample (8 or 16) */
  924. volatile uint8_t inflight; /* Number of audio buffers in-flight */
  925. #ifdef WM8904_USE_FFLOCK_INT
  926. volatile bool locked; /* FLL is locked */
  927. #endif
  928. bool running; /* True: Worker thread is running */
  929. bool paused; /* True: Playing is paused */
  930. bool mute; /* True: Output is muted */
  931. #ifndef CONFIG_AUDIO_EXCLUDE_STOP
  932. bool terminating; /* True: Stop requested */
  933. #endif
  934. bool reserved; /* True: Device is reserved */
  935. volatile int result; /* The result of the last transfer */
  936. };
  937. /****************************************************************************
  938. * Public Data
  939. ****************************************************************************/
  940. #ifdef CONFIG_WM8904_CLKDEBUG
  941. extern const uint8_t g_sysclk_scaleb1[WM8904_BCLK_MAXDIV+1];
  942. extern const uint8_t g_fllratio[WM8904_NFLLRATIO];
  943. #endif
  944. /****************************************************************************
  945. * Public Function Prototypes
  946. ****************************************************************************/
  947. /****************************************************************************
  948. * Name: wm8904_readreg
  949. *
  950. * Description:
  951. * Read the specified 16-bit register from the WM8904 device.
  952. *
  953. ****************************************************************************/
  954. #if defined(CONFIG_WM8904_REGDUMP) || defined(CONFIG_WM8904_CLKDEBUG)
  955. struct wm8904_dev_s;
  956. uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr);
  957. #endif
  958. #endif /* CONFIG_AUDIO */
  959. #endif /* __DRIVERS_AUDIO_WM8904_H */