msm_audio_mvs.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /* Copyright (c) 2010-2011, 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. */
  13. #ifndef __MSM_AUDIO_MVS_H
  14. #define __MSM_AUDIO_MVS_H
  15. #include <linux/msm_audio.h>
  16. #include <linux/wakelock.h>
  17. #include <linux/pm_qos.h>
  18. #include <mach/msm_rpcrouter.h>
  19. #include <mach/debug_mm.h>
  20. #include <linux/slab.h>
  21. #define AUDIO_GET_MVS_CONFIG _IOW(AUDIO_IOCTL_MAGIC, \
  22. (AUDIO_MAX_COMMON_IOCTL_NUM + 0), unsigned)
  23. #define AUDIO_SET_MVS_CONFIG _IOR(AUDIO_IOCTL_MAGIC, \
  24. (AUDIO_MAX_COMMON_IOCTL_NUM + 1), unsigned)
  25. #define AUDIO_SET_SCR_CONFIG _IOR(AUDIO_IOCTL_MAGIC, \
  26. (AUDIO_MAX_COMMON_IOCTL_NUM + 2), unsigned)
  27. #define AUDIO_SET_DTX_CONFIG _IOR(AUDIO_IOCTL_MAGIC, \
  28. (AUDIO_MAX_COMMON_IOCTL_NUM + 3), unsigned)
  29. /* MVS modes */
  30. #define MVS_MODE_LINEAR_PCM 9
  31. #define MVS_PROG 0x30000014
  32. #define MVS_VERS 0x00030001
  33. #define MVS_CLIENT_ID_VOIP 0x00000003 /* MVS_CLIENT_VOIP */
  34. #define MVS_ACQUIRE_PROC 4
  35. #define MVS_ENABLE_PROC 5
  36. #define MVS_RELEASE_PROC 6
  37. #define MVS_SET_PCM_MODE_PROC 9
  38. #define MVS_EVENT_CB_TYPE_PROC 1
  39. #define MVS_PACKET_UL_FN_TYPE_PROC 2
  40. #define MVS_PACKET_DL_FN_TYPE_PROC 3
  41. #define MVS_CB_FUNC_ID 0xAAAABBBB
  42. #define MVS_UL_CB_FUNC_ID 0xBBBBCCCC
  43. #define MVS_DL_CB_FUNC_ID 0xCCCCDDDD
  44. /* MVS frame modes */
  45. #define MVS_FRAME_MODE_PCM_UL 13
  46. #define MVS_FRAME_MODE_PCM_DL 14
  47. /* MVS context */
  48. #define MVS_PKT_CONTEXT_ISR 0x00000001
  49. /* Max voc packet size */
  50. #define MVS_MAX_VOC_PKT_SIZE 320
  51. #define VOIP_MAX_Q_LEN 20
  52. #define MVS_MAX_Q_LEN 8
  53. #define RPC_TYPE_REQUEST 0
  54. #define RPC_TYPE_REPLY 1
  55. #define RPC_STATUS_FAILURE 0
  56. #define RPC_STATUS_SUCCESS 1
  57. #define RPC_STATUS_REJECT 1
  58. #define RPC_COMMON_HDR_SZ (sizeof(uint32_t) * 2)
  59. #define RPC_REQUEST_HDR_SZ (sizeof(struct rpc_request_hdr))
  60. #define RPC_REPLY_HDR_SZ (sizeof(uint32_t) * 3)
  61. enum audio_mvs_state_type { AUDIO_MVS_CLOSED, AUDIO_MVS_OPENED,
  62. AUDIO_MVS_PREPARING, AUDIO_MVS_ACQUIRE, AUDIO_MVS_ENABLED,
  63. AUDIO_MVS_CLOSING
  64. };
  65. enum audio_mvs_event_type { AUDIO_MVS_COMMAND, AUDIO_MVS_MODE,
  66. AUDIO_MVS_NOTIFY
  67. };
  68. enum audio_mvs_cmd_status_type { AUDIO_MVS_CMD_FAILURE, AUDIO_MVS_CMD_BUSY,
  69. AUDIO_MVS_CMD_SUCCESS
  70. };
  71. enum audio_mvs_mode_status_type { AUDIO_MVS_MODE_NOT_AVAIL,
  72. AUDIO_MVS_MODE_INIT, AUDIO_MVS_MODE_READY
  73. };
  74. enum audio_mvs_pkt_status_type { AUDIO_MVS_PKT_NORMAL, AUDIO_MVS_PKT_FAST,
  75. AUDIO_MVS_PKT_SLOW
  76. };
  77. struct rpc_audio_mvs_acquire_args {
  78. uint32_t client_id;
  79. uint32_t cb_func_id;
  80. };
  81. struct audio_mvs_acquire_msg {
  82. struct rpc_request_hdr rpc_hdr;
  83. struct rpc_audio_mvs_acquire_args acquire_args;
  84. };
  85. struct rpc_audio_mvs_enable_args {
  86. uint32_t client_id;
  87. uint32_t mode;
  88. uint32_t ul_cb_func_id;
  89. uint32_t dl_cb_func_id;
  90. uint32_t context;
  91. };
  92. struct audio_mvs_enable_msg {
  93. struct rpc_request_hdr rpc_hdr;
  94. struct rpc_audio_mvs_enable_args enable_args;
  95. };
  96. struct audio_mvs_release_msg {
  97. struct rpc_request_hdr rpc_hdr;
  98. uint32_t client_id;
  99. };
  100. struct audio_mvs_set_pcm_mode_msg {
  101. struct rpc_request_hdr rpc_hdr;
  102. uint32_t pcm_mode;
  103. };
  104. struct audio_mvs_set_pcmwb_mode_msg {
  105. struct rpc_request_hdr rpc_hdr;
  106. uint32_t pcmwb_mode;
  107. };
  108. struct audio_mvs_buffer {
  109. uint8_t *voc_pkt;
  110. uint32_t len;
  111. };
  112. union audio_mvs_event_data {
  113. struct mvs_ev_command_type {
  114. uint32_t event;
  115. uint32_t client_id;
  116. uint32_t cmd_status;
  117. } mvs_ev_command_type;
  118. struct mvs_ev_mode_type {
  119. uint32_t event;
  120. uint32_t client_id;
  121. uint32_t mode_status;
  122. uint32_t mode;
  123. } mvs_ev_mode_type;
  124. struct mvs_ev_notify_type {
  125. uint32_t event;
  126. uint32_t client_id;
  127. uint32_t buf_dir;
  128. uint32_t max_frames;
  129. } mvs_ev_notify_type;
  130. };
  131. struct audio_mvs_cb_func_args {
  132. uint32_t cb_func_id;
  133. uint32_t valid_ptr;
  134. uint32_t event;
  135. union audio_mvs_event_data event_data;
  136. };
  137. struct audio_mvs_frame_info_hdr {
  138. uint32_t frame_mode;
  139. uint32_t mvs_mode;
  140. uint32_t buf_free_cnt;
  141. };
  142. struct audio_mvs_ul_cb_func_args {
  143. uint32_t cb_func_id;
  144. uint32_t pkt_len;
  145. uint32_t voc_pkt[MVS_MAX_VOC_PKT_SIZE / 4];
  146. uint32_t valid_ptr;
  147. uint32_t frame_mode;
  148. uint32_t frame_mode_ignore;
  149. struct audio_mvs_frame_info_hdr frame_info_hdr;
  150. uint32_t pcm_frame;
  151. uint32_t pcm_mode;
  152. uint32_t pkt_len_ignore;
  153. };
  154. struct audio_mvs_ul_reply {
  155. struct rpc_reply_hdr reply_hdr;
  156. uint32_t valid_pkt_status_ptr;
  157. uint32_t pkt_status;
  158. };
  159. struct audio_mvs_dl_cb_func_args {
  160. uint32_t cb_func_id;
  161. uint32_t valid_ptr;
  162. uint32_t frame_mode;
  163. uint32_t frame_mode_ignore;
  164. struct audio_mvs_frame_info_hdr frame_info_hdr;
  165. uint32_t pcm_frame;
  166. uint32_t pcm_mode;
  167. };
  168. struct audio_mvs_dl_reply {
  169. struct rpc_reply_hdr reply_hdr;
  170. uint32_t voc_pkt[MVS_MAX_VOC_PKT_SIZE / 4];
  171. uint32_t valid_frame_info_ptr;
  172. uint32_t frame_mode;
  173. uint32_t frame_mode_again;
  174. struct audio_mvs_frame_info_hdr frame_info_hdr;
  175. uint32_t pcm_frame;
  176. uint32_t pcm_mode;
  177. uint32_t valid_pkt_status_ptr;
  178. uint32_t pkt_status;
  179. };
  180. struct audio_mvs_info_type {
  181. enum audio_mvs_state_type state;
  182. uint32_t frame_mode;
  183. uint32_t mvs_mode;
  184. uint32_t buf_free_cnt;
  185. uint32_t pcm_frame;
  186. uint32_t pcm_mode;
  187. uint32_t out_sample_rate;
  188. uint32_t out_channel_mode;
  189. uint32_t out_weight;
  190. uint32_t out_buffer_size;
  191. int dl_play;
  192. struct msm_rpc_endpoint *rpc_endpt;
  193. uint32_t rpc_prog;
  194. uint32_t rpc_ver;
  195. uint32_t rpc_status;
  196. unsigned int pcm_size;
  197. unsigned int pcm_count;
  198. unsigned int pcm_playback_irq_pos; /* IRQ position */
  199. unsigned int pcm_playback_buf_pos; /* position in buffer */
  200. unsigned int pcm_capture_size;
  201. unsigned int pcm_capture_count;
  202. unsigned int pcm_capture_irq_pos; /* IRQ position */
  203. unsigned int pcm_capture_buf_pos; /* position in buffer */
  204. uint32_t samp_rate;
  205. uint32_t channel_mode;
  206. uint8_t *mem_chunk;
  207. struct snd_pcm_substream *playback_substream;
  208. struct snd_pcm_substream *capture_substream;
  209. struct audio_mvs_buffer in[MVS_MAX_Q_LEN];
  210. uint32_t in_read;
  211. uint32_t in_write;
  212. struct audio_mvs_buffer out[MVS_MAX_Q_LEN];
  213. uint32_t out_read;
  214. uint32_t out_write;
  215. struct task_struct *task;
  216. wait_queue_head_t wait;
  217. wait_queue_head_t prepare_wait;
  218. wait_queue_head_t out_wait;
  219. wait_queue_head_t in_wait;
  220. struct mutex lock;
  221. struct mutex prepare_lock;
  222. struct mutex in_lock;
  223. struct mutex out_lock;
  224. struct wake_lock suspend_lock;
  225. struct pm_qos_request pm_qos_req;
  226. struct timer_list timer;
  227. unsigned long expiry;
  228. int ack_dl_count;
  229. int ack_ul_count;
  230. int prepare_ack;
  231. int playback_start;
  232. int capture_start;
  233. unsigned long expiry_delta;
  234. int mvs_enable;
  235. int playback_enable;
  236. int capture_enable;
  237. int instance;
  238. };
  239. struct audio_voip_info_type {
  240. enum audio_mvs_state_type state;
  241. enum audio_mvs_state_type playback_state;
  242. enum audio_mvs_state_type capture_state;
  243. unsigned int pcm_playback_size;
  244. unsigned int pcm_count;
  245. unsigned int pcm_playback_irq_pos; /* IRQ position */
  246. unsigned int pcm_playback_buf_pos; /* position in buffer */
  247. unsigned int pcm_capture_size;
  248. unsigned int pcm_capture_count;
  249. unsigned int pcm_capture_irq_pos; /* IRQ position */
  250. unsigned int pcm_capture_buf_pos; /* position in buffer */
  251. struct snd_pcm_substream *playback_substream;
  252. struct snd_pcm_substream *capture_substream;
  253. struct audio_mvs_buffer in[VOIP_MAX_Q_LEN];
  254. uint32_t in_read;
  255. uint32_t in_write;
  256. struct audio_mvs_buffer out[VOIP_MAX_Q_LEN];
  257. uint32_t out_read;
  258. uint32_t out_write;
  259. wait_queue_head_t out_wait;
  260. wait_queue_head_t in_wait;
  261. struct mutex lock;
  262. struct mutex prepare_lock;
  263. struct wake_lock suspend_lock;
  264. struct pm_qos_request pm_qos_req;
  265. int playback_start;
  266. int capture_start;
  267. int instance;
  268. };
  269. enum msm_audio_pcm_frame_type {
  270. MVS_AMR_SPEECH_GOOD, /* Good speech frame */
  271. MVS_AMR_SPEECH_DEGRADED, /* Speech degraded */
  272. MVS_AMR_ONSET, /* onset */
  273. MVS_AMR_SPEECH_BAD, /* Corrupt speech frame (bad CRC) */
  274. MVS_AMR_SID_FIRST, /* First silence descriptor */
  275. MVS_AMR_SID_UPDATE, /* Comfort noise frame */
  276. MVS_AMR_SID_BAD, /* Corrupt SID frame (bad CRC) */
  277. MVS_AMR_NO_DATA, /* Nothing to transmit */
  278. MVS_AMR_SPEECH_LOST, /* downlink speech lost */
  279. };
  280. enum msm_audio_dtx_mode_type { MVS_DTX_OFF, MVS_DTX_ON
  281. };
  282. struct msm_audio_mvs_config {
  283. uint32_t mvs_mode;
  284. uint32_t bit_rate;
  285. };
  286. extern struct snd_soc_dai_driver msm_mvs_dais[2];
  287. extern struct snd_soc_codec_device soc_codec_dev_msm_mvs;
  288. extern struct snd_soc_platform_driver msm_mvs_soc_platform;
  289. extern struct snd_soc_platform_driver msm_voip_soc_platform;
  290. #endif /* __MSM_AUDIO_MVS_H */