tlv320dac.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #ifndef _DEV_TLV320DAC_H_
  2. #define _DEV_TLV320DAC_H_
  3. /*!
  4. * Copyright (C) 2007 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file tlv320dac.h
  36. * \brief TLV320AIC23B driver.
  37. *
  38. * \verbatim
  39. *
  40. * $Log$
  41. * Revision 1.2 2009/01/17 11:26:47 haraldkipp
  42. * Getting rid of two remaining BSD types in favor of stdint.
  43. * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
  44. *
  45. * Revision 1.1 2008/10/05 16:51:46 haraldkipp
  46. * Added suport for the TLV320 audio DAC.
  47. *
  48. *
  49. * \endverbatim
  50. */
  51. /*! \name Left Line Input Channel Volume Control Register */
  52. /*@{*/
  53. #define DAC_LLI_VOL 0x00 /*!< \brief Register address. */
  54. #define DAC_LLI_VOL_LRS 0x0100 /*!< \brief Left/right simultaneous volume/mute update. */
  55. #define DAC_LLI_VOL_LIM 0x0080 /*!< \brief Mute. */
  56. #define DAC_LLI_VOL_LIV 0x001F /*!< \brief Volume control mask.
  57. *
  58. * From 0x00 (-34.5dB) to 0x1F (+12dB) in 1.5dB steps.
  59. */
  60. #define DAC_LLI_VOL_LIV_LSB 0 /*!< \brief Volume control LSB. */
  61. /*@}*/
  62. /*! \name Right Line Input Channel Volume Control Register */
  63. /*@{*/
  64. #define DAC_RLI_VOL 0x01 /*!< \brief Register address. */
  65. #define DAC_RLI_VOL_RLS 0x0100 /*!< \brief Right/left simultaneous volume/mute update. */
  66. #define DAC_RLI_VOL_RIM 0x0080 /*!< \brief Mute. */
  67. #define DAC_RLI_VOL_RIV 0x001F /*!< \brief Volume control mask.
  68. *
  69. * From 0x00 (-34.5dB) to 0x1F (+12dB) in 1.5dB steps.
  70. */
  71. #define DAC_RLI_VOL_RIV_LSB 0 /*!< \brief Volume control LSB. */
  72. /*@}*/
  73. /*! \name Left Channel Headphone Volume Control */
  74. /*@{*/
  75. #define DAC_LHP_VOL 0x02 /*!< \brief Register address. */
  76. #define DAC_LHP_VOL_LRS 0x0100 /*!< \brief Left/right simultaneous volume/mute update. */
  77. #define DAC_LHP_VOL_LZC 0x0080 /*!< \brief Zero cross detect. */
  78. #define DAC_LHP_VOL_LHV 0x007F /*!< \brief Volume control mask.
  79. *
  80. * From 0x30 (-73dB, mute) to 0x3F (+6dB).
  81. */
  82. #define DAC_LHP_VOL_LHV_LSB 0 /*!< \brief Volume control LSB. */
  83. /*@}*/
  84. /*! \name Right Channel Headphone Volume Control */
  85. /*@{*/
  86. #define DAC_RHP_VOL 0x03 /*!< \brief Register address. */
  87. #define DAC_RHP_VOL_RLS 0x0100 /*!< \brief Right/left simultaneous volume/mute update. */
  88. #define DAC_RHP_VOL_LZC 0x0080 /*!< \brief Zero cross detect. */
  89. #define DAC_RHP_VOL_LHV 0x007F /*!< \brief Volume control mask.
  90. *
  91. * From 0x30 (-73dB, mute) to 0x3F (+6dB).
  92. */
  93. #define DAC_RHP_VOL_LHV_LSB 0 /*!< \brief Volume control LSB. */
  94. /*@}*/
  95. /*! \name Analog Audio Path Control */
  96. /*@{*/
  97. #define DAC_ANA_PATH 0x04 /*!< \brief Register address. */
  98. #define DAC_ANA_PATH_STA 0x01C0 /*!< \brief Side tone mask. */
  99. #define DAC_ANA_PATH_STA_LSB 6 /*!< \brief Side tone LSB. */
  100. #define DAC_ANA_PATH_STA_0DB 0x0100 /*!< \brief Added side tone of 0dB. */
  101. #define DAC_ANA_PATH_STA_M6DB 0x0000 /*!< \brief Added side tone of -6dB. */
  102. #define DAC_ANA_PATH_STA_M9DB 0x0040 /*!< \brief Added side tone of -9dB. */
  103. #define DAC_ANA_PATH_STA_M12DB 0x0080 /*!< \brief Added side tone of -12dB. */
  104. #define DAC_ANA_PATH_STA_M18DB 0x00C0 /*!< \brief Added side tone of -18dB. */
  105. #define DAC_ANA_PATH_STE 0x0020 /*!< \brief Side tone enable. */
  106. #define DAC_ANA_PATH_DAC 0x0010 /*!< \brief DAC select. */
  107. #define DAC_ANA_PATH_BYP 0x0008 /*!< \brief Bypass. */
  108. #define DAC_ANA_PATH_INSEL 0x0004 /*!< \brief ADC microphone input. */
  109. #define DAC_ANA_PATH_MICM 0x0002 /*!< \brief Microphone mute. */
  110. #define DAC_ANA_PATH_MICB 0x0001 /*!< \brief Microphone boost. */
  111. /*@}*/
  112. /*! \name Digital Audio Path Control */
  113. /*@{*/
  114. #define DAC_DIG_PATH 0x05 /*!< \brief Register address. */
  115. #define DAC_DIG_PATH_DACM 0x0008 /*!< \brief DAC soft mute. */
  116. #define DAC_DIG_PATH_DEEMP 0x0006 /*!< \brief De-emphases control mask. */
  117. #define DAC_DIG_PATH_DEEMP_LSB 1 /*!< \brief De-emphases control LSB. */
  118. #define DAC_DIG_PATH_DEEMP_NONE 0x0000 /*!< \brief De-emphases disabled. */
  119. #define DAC_DIG_PATH_DEEMP_32KHZ 0x0002 /*!< \brief De-emphases 32 kHz. */
  120. #define DAC_DIG_PATH_DEEMP_44_1KHZ 0x0004 /*!< \brief De-emphases 44.1 kHz. */
  121. #define DAC_DIG_PATH_DEEMP_48KHZ 0x0006 /*!< \brief De-emphases 48 kHz. */
  122. #define DAC_DIG_PATH_ADCHP 0x0001 /*!< \brief ADC high-pass filter. */
  123. /*@}*/
  124. /*! \name Digital Audio Path Control */
  125. /*@{*/
  126. #define DAC_PWRDN 0x06 /*!< \brief Register address. */
  127. #define DAC_PWRDN_OFF 0x0080 /*!< \brief Device power off. */
  128. #define DAC_PWRDN_CLK 0x0040 /*!< \brief Clock off. */
  129. #define DAC_PWRDN_OSC 0x0020 /*!< \brief Oscillator off. */
  130. #define DAC_PWRDN_OUT 0x0010 /*!< \brief Outputs off. */
  131. #define DAC_PWRDN_DAC 0x0008 /*!< \brief DAC off. */
  132. #define DAC_PWRDN_ADC 0x0004 /*!< \brief ADC off. */
  133. #define DAC_PWRDN_MIC 0x0002 /*!< \brief Microphone input off. */
  134. #define DAC_PWRDN_LINE 0x0001 /*!< \brief Line input off. */
  135. /*@}*/
  136. /*! \name Digital Audio Interface Format */
  137. /*@{*/
  138. #define DAC_DAI_FMT 0x07 /*!< \brief Register address. */
  139. #define DAC_DAI_FMT_MS 0x0040 /*!< \brief Maser mode. */
  140. #define DAC_DAI_FMT_LRSWAP 0x0020 /*!< \brief DAC left/right swap. */
  141. #define DAC_DAI_FMT_LRP 0x0010 /*!< \brief DAC left/right phase. */
  142. #define DAC_DAI_FMT_IWL 0x000C /*!< \brief Input bit length mask. */
  143. #define DAC_DAI_FMT_IWL_LSB 2 /*!< \brief Input bit length LSB. */
  144. #define DAC_DAI_FMT_IWL_16 0x0000 /*!< \brief 16 bit input length. */
  145. #define DAC_DAI_FMT_IWL_20 0x0004 /*!< \brief 20 bit input length. */
  146. #define DAC_DAI_FMT_IWL_24 0x0008 /*!< \brief 24 bit input length. */
  147. #define DAC_DAI_FMT_IWL_32 0x000C /*!< \brief 32 bit input length. */
  148. #define DAC_DAI_FMT_FOR 0x0003 /*!< \brief Data format mask. */
  149. #define DAC_DAI_FMT_FOR_LSB 0 /*!< \brief Data format LSB. */
  150. #define DAC_DAI_FMT_FOR_RA 0x0000 /*!< \brief MSB first, right aligned. */
  151. #define DAC_DAI_FMT_FOR_LA 0x0001 /*!< \brief MSB first, left aligned. */
  152. #define DAC_DAI_FMT_FOR_I2S 0x0002 /*!< \brief I2S format, MSB first, left – 1 aligned. */
  153. #define DAC_DAI_FMT_FOR_DSP 0x0003 /*!< \brief DSP format, frame sync followed by two data words. */
  154. /*@}*/
  155. /*! \name Sample Rate Control */
  156. /*@{*/
  157. #define DAC_SRATE 0x08 /*!< \brief Register address. */
  158. #define DAC_SRATE_CLKOUT 0x0080 /*!< \brief Clock output divider. */
  159. #define DAC_SRATE_CLKIN 0x0040 /*!< \brief Clock input divider. */
  160. #define DAC_SRATE_SR 0x003C /*!< \brief Sampling rate mask. */
  161. #define DAC_SRATE_SR_LSB 2 /*!< \brief Sampling rate LSB. */
  162. #define DAC_SRATE_BOSR 0x0002 /*!< \brief Base oversampling rate.
  163. *
  164. * USB mode : 0=250 fs, 1=272 fs
  165. * Normal mode: 0=256 fs, 1=384 fs
  166. */
  167. #define DAC_SRATE_USB 0x0001 /*!< \brief USB clock mode. */
  168. /*@}*/
  169. /*! \name Digital Interface Activation */
  170. /*@{*/
  171. #define DAC_DI_ACT 0x09 /*!< \brief Register address. */
  172. #define DAC_DI_ACT_ACT 0x0001 /*!< \brief Interface active. */
  173. /*@}*/
  174. /*! \name Reset Register */
  175. /*@{*/
  176. #define DAC_RESET 0x0F /*!< \brief Register address.
  177. *
  178. * Writing zero to this register triggers reset.
  179. */
  180. /*@}*/
  181. #define DAC_MAX_VOLUME 6
  182. #define DAC_MIN_VOLUME -73
  183. extern int Tlv320DacInit(unsigned int rate);
  184. extern int Tlv320DacWrite(void *buf, int len);
  185. extern int Tlv320DacFlush(void);
  186. extern u_char Tlv320DacReadReg(unsigned int reg);
  187. extern void Tlv320DacWriteReg(unsigned int reg, unsigned int val);
  188. extern int Tlv320DacSetVolume(int left, int right);
  189. extern int Tlv320DacSetRate(unsigned int rate);
  190. extern int Tlv320SwitchMode(void);
  191. #endif