q6afe-v2.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __Q6AFE_V2_H__
  13. #define __Q6AFE_V2_H__
  14. #include <sound/apr_audio-v2.h>
  15. #define IN 0x000
  16. #define OUT 0x001
  17. #define MSM_AFE_MONO 0
  18. #define MSM_AFE_CH_STEREO 1
  19. #define MSM_AFE_MONO_RIGHT 1
  20. #define MSM_AFE_MONO_LEFT 2
  21. #define MSM_AFE_STEREO 3
  22. #define MSM_AFE_4CHANNELS 4
  23. #define MSM_AFE_6CHANNELS 6
  24. #define MSM_AFE_8CHANNELS 8
  25. #define MSM_AFE_I2S_FORMAT_LPCM 0
  26. #define MSM_AFE_I2S_FORMAT_COMPR 1
  27. #define MSM_AFE_I2S_FORMAT_IEC60958_LPCM 2
  28. #define MSM_AFE_I2S_FORMAT_IEC60958_COMPR 3
  29. #define MSM_AFE_PORT_TYPE_RX 0
  30. #define MSM_AFE_PORT_TYPE_TX 1
  31. #define RT_PROXY_DAI_001_RX 0xE0
  32. #define RT_PROXY_DAI_001_TX 0xF0
  33. #define RT_PROXY_DAI_002_RX 0xF1
  34. #define RT_PROXY_DAI_002_TX 0xE1
  35. #define VIRTUAL_ID_TO_PORTID(val) ((val & 0xF) | 0x2000)
  36. enum {
  37. IDX_PRIMARY_I2S_RX = 0,
  38. IDX_PRIMARY_I2S_TX = 1,
  39. IDX_AFE_PORT_ID_PRIMARY_PCM_RX = 2,
  40. IDX_AFE_PORT_ID_PRIMARY_PCM_TX = 3,
  41. IDX_SECONDARY_I2S_RX = 4,
  42. IDX_SECONDARY_I2S_TX = 5,
  43. IDX_MI2S_RX = 6,
  44. IDX_MI2S_TX = 7,
  45. IDX_HDMI_RX = 8,
  46. IDX_RSVD_2 = 9,
  47. IDX_RSVD_3 = 10,
  48. IDX_DIGI_MIC_TX = 11,
  49. IDX_VOICE_RECORD_RX = 12,
  50. IDX_VOICE_RECORD_TX = 13,
  51. IDX_VOICE_PLAYBACK_TX = 14,
  52. IDX_SLIMBUS_0_RX = 15,
  53. IDX_SLIMBUS_0_TX = 16,
  54. IDX_SLIMBUS_1_RX = 17,
  55. IDX_SLIMBUS_1_TX = 18,
  56. IDX_SLIMBUS_2_RX = 19,
  57. IDX_SLIMBUS_2_TX = 20,
  58. IDX_SLIMBUS_3_RX = 21,
  59. IDX_SLIMBUS_3_TX = 22,
  60. IDX_SLIMBUS_4_RX = 23,
  61. IDX_SLIMBUS_4_TX = 24,
  62. IDX_SLIMBUS_5_RX = 25,
  63. IDX_SLIMBUS_5_TX = 26,
  64. IDX_INT_BT_SCO_RX = 27,
  65. IDX_INT_BT_SCO_TX = 28,
  66. IDX_INT_BT_A2DP_RX = 29,
  67. IDX_INT_FM_RX = 30,
  68. IDX_INT_FM_TX = 31,
  69. IDX_RT_PROXY_PORT_001_RX = 32,
  70. IDX_RT_PROXY_PORT_001_TX = 33,
  71. IDX_AFE_PORT_ID_QUATERNARY_MI2S_RX = 34,
  72. IDX_AFE_PORT_ID_QUATERNARY_MI2S_TX = 35,
  73. IDX_AFE_PORT_ID_SECONDARY_MI2S_RX = 36,
  74. IDX_AFE_PORT_ID_SECONDARY_MI2S_TX = 37,
  75. IDX_AFE_PORT_ID_TERTIARY_MI2S_RX = 38,
  76. IDX_AFE_PORT_ID_TERTIARY_MI2S_TX = 39,
  77. IDX_AFE_PORT_ID_PRIMARY_MI2S_RX = 40,
  78. IDX_AFE_PORT_ID_PRIMARY_MI2S_TX = 41,
  79. IDX_AFE_PORT_ID_SECONDARY_PCM_RX = 42,
  80. IDX_AFE_PORT_ID_SECONDARY_PCM_TX = 43,
  81. IDX_VOICE2_PLAYBACK_TX = 44,
  82. IDX_GLOBAL_CFG,
  83. AFE_MAX_PORTS
  84. };
  85. enum afe_mad_type {
  86. MAD_HW_NONE = 0x00,
  87. MAD_HW_AUDIO = 0x01,
  88. MAD_HW_BEACON = 0x02,
  89. MAD_HW_ULTRASOUND = 0x04,
  90. MAD_SW_AUDIO = 0x05,
  91. };
  92. struct afe_audio_buffer {
  93. dma_addr_t phys;
  94. void *data;
  95. uint32_t used;
  96. uint32_t size;/* size of buffer */
  97. uint32_t actual_size; /* actual number of bytes read by DSP */
  98. struct ion_handle *handle;
  99. struct ion_client *client;
  100. };
  101. struct afe_audio_port_data {
  102. struct afe_audio_buffer *buf;
  103. uint32_t max_buf_cnt;
  104. uint32_t dsp_buf;
  105. uint32_t cpu_buf;
  106. struct list_head mem_map_handle;
  107. uint32_t tmp_hdl;
  108. /* read or write locks */
  109. struct mutex lock;
  110. spinlock_t dsp_lock;
  111. };
  112. struct afe_audio_client {
  113. atomic_t cmd_state;
  114. /* Relative or absolute TS */
  115. uint32_t time_flag;
  116. void *priv;
  117. uint64_t time_stamp;
  118. struct mutex cmd_lock;
  119. /* idx:1 out port, 0: in port*/
  120. struct afe_audio_port_data port[2];
  121. wait_queue_head_t cmd_wait;
  122. uint32_t mem_map_handle;
  123. };
  124. struct aanc_data {
  125. bool aanc_active;
  126. uint16_t aanc_rx_port;
  127. uint16_t aanc_tx_port;
  128. uint32_t aanc_rx_port_sample_rate;
  129. uint32_t aanc_tx_port_sample_rate;
  130. };
  131. int afe_open(u16 port_id, union afe_port_config *afe_config, int rate);
  132. int afe_close(int port_id);
  133. int afe_loopback(u16 enable, u16 rx_port, u16 tx_port);
  134. int afe_sidetone(u16 tx_port_id, u16 rx_port_id, u16 enable, uint16_t gain);
  135. int afe_loopback_gain(u16 port_id, u16 volume);
  136. int afe_validate_port(u16 port_id);
  137. int afe_get_port_index(u16 port_id);
  138. int afe_start_pseudo_port(u16 port_id);
  139. int afe_stop_pseudo_port(u16 port_id);
  140. uint32_t afe_req_mmap_handle(struct afe_audio_client *ac);
  141. int afe_unmap_cal_blocks(void);
  142. int afe_memory_map(u32 dma_addr_p, u32 dma_buf_sz, struct afe_audio_client *ac);
  143. int afe_cmd_memory_map(u32 dma_addr_p, u32 dma_buf_sz);
  144. int afe_cmd_memory_map_nowait(int port_id, u32 dma_addr_p, u32 dma_buf_sz);
  145. int afe_cmd_memory_unmap(u32 dma_addr_p);
  146. int afe_cmd_memory_unmap_nowait(u32 dma_addr_p);
  147. void afe_set_dtmf_gen_rx_portid(u16 rx_port_id, int set);
  148. int afe_dtmf_generate_rx(int64_t duration_in_ms,
  149. uint16_t high_freq,
  150. uint16_t low_freq, uint16_t gain);
  151. int afe_register_get_events(u16 port_id,
  152. void (*cb) (uint32_t opcode,
  153. uint32_t token, uint32_t *payload, void *priv),
  154. void *private_data);
  155. int afe_unregister_get_events(u16 port_id);
  156. int afe_rt_proxy_port_write(u32 buf_addr_p, u32 mem_map_handle, int bytes);
  157. int afe_rt_proxy_port_read(u32 buf_addr_p, u32 mem_map_handle, int bytes);
  158. int afe_port_start(u16 port_id, union afe_port_config *afe_config,
  159. u32 rate);
  160. int afe_spk_prot_feed_back_cfg(int src_port, int dst_port,
  161. int l_ch, int r_ch, u32 enable);
  162. int afe_spk_prot_get_calib_data(struct afe_spkr_prot_get_vi_calib *calib);
  163. int afe_port_stop_nowait(int port_id);
  164. int afe_apply_gain(u16 port_id, u16 gain);
  165. int afe_q6_interface_prepare(void);
  166. int afe_get_port_type(u16 port_id);
  167. int q6afe_audio_client_buf_alloc_contiguous(unsigned int dir,
  168. struct afe_audio_client *ac,
  169. unsigned int bufsz,
  170. unsigned int bufcnt);
  171. struct afe_audio_client *q6afe_audio_client_alloc(void *priv);
  172. int q6afe_audio_client_buf_free_contiguous(unsigned int dir,
  173. struct afe_audio_client *ac);
  174. void q6afe_audio_client_free(struct afe_audio_client *ac);
  175. /* if port_id is virtual, convert to physical..
  176. * if port_id is already physical, return physical
  177. */
  178. int afe_convert_virtual_to_portid(u16 port_id);
  179. int afe_pseudo_port_start_nowait(u16 port_id);
  180. int afe_pseudo_port_stop_nowait(u16 port_id);
  181. int afe_set_lpass_clock(u16 port_id, struct afe_clk_cfg *cfg);
  182. int afe_set_lpass_internal_digital_codec_clock(u16 port_id,
  183. struct afe_digital_clk_cfg *cfg);
  184. int q6afe_check_osr_clk_freq(u32 freq);
  185. int afe_turn_onoff_hw_mad(u16 mad_type, u16 mad_enable);
  186. int afe_port_set_mad_type(u16 port_id, enum afe_mad_type mad_type);
  187. enum afe_mad_type afe_port_get_mad_type(u16 port_id);
  188. int afe_set_config(enum afe_config_type config_type, void *config_data,
  189. int arg);
  190. void afe_clear_config(enum afe_config_type config);
  191. bool afe_has_config(enum afe_config_type config);
  192. void afe_set_aanc_info(struct aanc_data *aanc_info);
  193. #ifdef CONFIG_SND_SOC_MAXIM_DSM
  194. int32_t dsm_open(void *data);
  195. #endif /* CONFIG_SND_SOC_MAXIM_DSM */
  196. #endif /* __Q6AFE_V2_H__ */