audio.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2011-2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /*!
  31. * @file audio.h
  32. * @brief Common herder file for audio drivers
  33. *
  34. * @ingroup diag_audio
  35. */
  36. #ifndef __AUDIO_H
  37. #define __AUDIO_H
  38. #include "i2c/imx_i2c.h"
  39. /*
  40. * This macro is for test purpose only, do not define it unless you know what you are doing.
  41. */
  42. //#define ESAI_AC97_SUPPORT
  43. #define AUDIO_RECORD_BUF_LEN 0x100000
  44. //! @brief AUDIO bus types
  45. typedef enum {
  46. AUDIO_BUS_TYPE_SSI,
  47. AUDIO_BUS_TYPE_ESAI,
  48. AUDIO_BUS_TYPE_SPDIF,
  49. } audio_bus_type_e;
  50. //! @brief Audio bus modes
  51. typedef enum {
  52. AUDIO_BUS_MODE_SLAVE = 0,
  53. AUDIO_BUS_MODE_MASTER = 1,
  54. AUDIO_BUS_MODE_EITHER = 2, //the audio controller or codec can be configured as Master or Slave
  55. } audio_bus_mode_e;
  56. //! @brief Audio bus protocals
  57. typedef enum {
  58. AUDIO_BUS_PROTOCOL_NORMAL,
  59. AUDIO_BUS_PROTOCOL_NETWORK,
  60. AUDIO_BUS_PROTOCOL_I2S,
  61. AUDIO_BUS_PROTOCOL_LEFT_ALIGNED,
  62. AUDIO_BUS_PROTOCOL_AC97,
  63. } audio_bus_protocol_e;
  64. //! @brief Trasmit directions
  65. typedef enum {
  66. AUDIO_TRANS_DIR_TX = 0,
  67. AUDIO_TRANS_DIR_RX = 1,
  68. AUDIO_TRANS_DIR_TXRX = 2,
  69. } audio_trans_dir_e;
  70. //! @brief Sample rates
  71. typedef enum {
  72. SAMPLERATE_8KHz = 8000,
  73. SAMPLERATE_16KHz = 16000,
  74. SAMPLERATE_32KHz = 32000,
  75. SAMPLERATE_44_1KHz = 44100,
  76. SAMPLERATE_48KHz = 48000,
  77. } audio_samplerate_e;
  78. //! @brief Word length
  79. typedef enum {
  80. WL_8 = 8,
  81. WL_16 = 16,
  82. WL_20 = 20,
  83. WL_24 = 24,
  84. WL_32 = 32,
  85. } audio_word_length_e;
  86. //! @brief Parameters dedicated with PCM data
  87. typedef struct {
  88. audio_samplerate_e sample_rate;
  89. uint32_t channel_number;
  90. audio_word_length_e word_length;
  91. } audio_pcm_para_t, *audio_pcm_para_p;
  92. //! @brief Data structure for PCM file
  93. typedef struct {
  94. const char *name;
  95. audio_pcm_para_p para; //!< The PCM data's parameters
  96. uint8_t *buf; //!< Pointer to the buffer where the PCM data located
  97. uint32_t size; //!< Buffer size fot the PCD data
  98. } audio_pcm_t, *audio_pcm_p;
  99. //! @brief Parameters dedicated with audio device(controller or codec)
  100. typedef struct {
  101. audio_bus_mode_e bus_mode; //!< Bus mode
  102. audio_bus_protocol_e bus_protocol; //!< Protocal
  103. audio_trans_dir_e trans_dir; //!< Direction
  104. audio_samplerate_e sample_rate; //!< Sample rate
  105. audio_word_length_e word_length; //!< Word length
  106. uint32_t channel_number; //!< Channel number
  107. } audio_dev_para_t, *audio_dev_para_p;
  108. //! @brief Operations for audio device(controller or codec)
  109. typedef struct {
  110. int32_t (*init) (void *priv); //!< Initialize routine
  111. int32_t (*deinit) (void *priv); //!< De-initialize routine
  112. int32_t (*config) (void *priv, audio_dev_para_p para); //!< Configuration routine
  113. int32_t (*ioctl) (void *priv, uint32_t cmd, void *para); //!< IO control routine
  114. int32_t (*write) (void *priv, uint8_t * buf, uint32_t byte2write, uint32_t * bytewrittern); //!< Write routine
  115. int32_t (*read) (void *priv, uint8_t * buf, uint32_t byte2read, uint32_t * byteread); //!< Read routine
  116. } audio_dev_ops_t, *audio_dev_ops_p;
  117. //! brief Data structure for audio codec
  118. typedef struct {
  119. const char *name;
  120. const i2c_device_info_t * device; //!< Pointer to I2C device info.
  121. audio_bus_type_e bus_type; //The bus type(ssi, esai or spdif) the codec supports
  122. audio_bus_mode_e bus_mode; //the bus mode(master, slave or both)the codec supports
  123. audio_dev_ops_p ops; //!< Operations
  124. } audio_codec_t, *audio_codec_p;
  125. //! brief Data structure for audio controller
  126. typedef struct {
  127. const char *name;
  128. uint32_t instance; // the io base address of the controller
  129. audio_bus_type_e bus_type; //The bus type(ssi, esai or spdif) the controller supports
  130. audio_bus_mode_e bus_mode; //the bus mode(master, slave or both)the controller supports
  131. uint32_t irq; //the irq number
  132. uint32_t sdma_ch; //Will be used for SDMA
  133. audio_dev_ops_p ops;
  134. } audio_ctrl_t, *audio_ctrl_p;
  135. //! @brief Audio card structure
  136. typedef struct {
  137. const char *name;
  138. audio_codec_p codec; //!< Audio codec
  139. audio_ctrl_p ctrl; //!< Audio controller
  140. audio_dev_ops_p ops; //!< Operations
  141. } audio_card_t, *audio_card_p;
  142. #endif