q6lsm.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef __Q6LSM_H__
  14. #define __Q6LSM_H__
  15. #include <linux/list.h>
  16. #include <linux/msm_ion.h>
  17. #include <dsp/apr_audio-v2.h>
  18. #include <sound/lsm_params.h>
  19. #include <ipc/apr.h>
  20. #define MAX_NUM_CONFIDENCE 20
  21. #define ADM_LSM_PORT_ID 0xADCB
  22. #define LSM_MAX_NUM_CHANNELS 8
  23. #define LSM_V3P0_MAX_NUM_CHANNELS 9
  24. typedef void (*lsm_app_cb)(uint32_t opcode, uint32_t token,
  25. uint32_t *payload, void *priv);
  26. struct lsm_sound_model {
  27. dma_addr_t phys;
  28. void *data;
  29. size_t size; /* size of buffer */
  30. uint32_t actual_size; /* actual number of bytes read by DSP */
  31. struct dma_buf *dma_buf;
  32. uint32_t mem_map_handle;
  33. };
  34. struct snd_lsm_event_status_v2 {
  35. uint16_t status;
  36. uint16_t payload_size;
  37. uint8_t confidence_value[0];
  38. };
  39. struct lsm_lab_buffer {
  40. dma_addr_t phys;
  41. void *data;
  42. size_t size;
  43. struct dma_buf *dma_buf;
  44. uint32_t mem_map_handle;
  45. };
  46. struct lsm_hw_params {
  47. u16 sample_rate;
  48. u16 sample_size;
  49. u32 buf_sz;
  50. u32 period_count;
  51. u16 num_chs;
  52. };
  53. struct lsm_client {
  54. int session;
  55. lsm_app_cb cb;
  56. atomic_t cmd_state;
  57. void *priv;
  58. struct apr_svc *apr;
  59. struct apr_svc *mmap_apr;
  60. struct mutex cmd_lock;
  61. struct lsm_sound_model sound_model;
  62. wait_queue_head_t cmd_wait;
  63. uint32_t cmd_err_code;
  64. uint16_t mode;
  65. uint16_t connect_to_port;
  66. uint8_t num_confidence_levels;
  67. uint8_t *confidence_levels;
  68. bool opened;
  69. bool started;
  70. dma_addr_t lsm_cal_phy_addr;
  71. uint32_t lsm_cal_size;
  72. uint32_t app_id;
  73. bool lab_enable;
  74. bool lab_started;
  75. struct lsm_lab_buffer *lab_buffer;
  76. struct lsm_hw_params out_hw_params;
  77. struct lsm_hw_params in_hw_params;
  78. bool use_topology;
  79. int session_state;
  80. bool poll_enable;
  81. int perf_mode;
  82. uint32_t event_mode;
  83. uint32_t event_type;
  84. };
  85. struct lsm_stream_cmd_open_tx {
  86. struct apr_hdr hdr;
  87. uint16_t app_id;
  88. uint16_t reserved;
  89. uint32_t sampling_rate;
  90. } __packed;
  91. struct lsm_stream_cmd_open_tx_v2 {
  92. struct apr_hdr hdr;
  93. uint32_t topology_id;
  94. } __packed;
  95. struct lsm_custom_topologies {
  96. struct apr_hdr hdr;
  97. uint32_t data_payload_addr_lsw;
  98. uint32_t data_payload_addr_msw;
  99. uint32_t mem_map_handle;
  100. uint32_t buffer_size;
  101. } __packed;
  102. struct lsm_session_cmd_set_params_v2 {
  103. struct apr_hdr apr_hdr;
  104. uint32_t payload_size;
  105. struct mem_mapping_hdr mem_hdr;
  106. u32 param_data[0];
  107. } __packed;
  108. struct lsm_session_cmd_set_params_v3 {
  109. struct apr_hdr apr_hdr;
  110. struct mem_mapping_hdr mem_hdr;
  111. uint32_t payload_size;
  112. u32 param_data[0];
  113. } __packed;
  114. struct lsm_param_op_mode {
  115. uint32_t minor_version;
  116. uint16_t mode;
  117. uint16_t reserved;
  118. } __packed;
  119. struct lsm_param_connect_to_port {
  120. uint32_t minor_version;
  121. /* AFE port id that receives voice wake up data */
  122. uint16_t port_id;
  123. uint16_t reserved;
  124. } __packed;
  125. struct lsm_param_poll_enable {
  126. uint32_t minor_version;
  127. /* indicates to voice wakeup that HW MAD/SW polling is enabled or not */
  128. uint32_t polling_enable;
  129. } __packed;
  130. struct lsm_param_fwk_mode_cfg {
  131. uint32_t minor_version;
  132. uint32_t mode;
  133. } __packed;
  134. struct lsm_param_media_fmt {
  135. uint32_t minor_version;
  136. uint32_t sample_rate;
  137. uint16_t num_channels;
  138. uint16_t bit_width;
  139. uint8_t channel_mapping[LSM_MAX_NUM_CHANNELS];
  140. } __packed;
  141. struct lsm_param_media_fmt_v2 {
  142. uint32_t minor_version;
  143. uint32_t sample_rate;
  144. uint16_t bit_width;
  145. uint16_t num_channels;
  146. uint8_t channel_mapping[0];
  147. } __packed;
  148. struct lsm_param_confidence_levels {
  149. uint8_t num_confidence_levels;
  150. uint8_t confidence_levels[0];
  151. } __packed;
  152. struct lsm_param_epd_thres {
  153. uint32_t minor_version;
  154. uint32_t epd_begin;
  155. uint32_t epd_end;
  156. } __packed;
  157. struct lsm_param_gain {
  158. uint32_t minor_version;
  159. uint16_t gain;
  160. uint16_t reserved;
  161. } __packed;
  162. struct lsm_cmd_reg_snd_model {
  163. struct apr_hdr hdr;
  164. uint32_t model_size;
  165. uint32_t model_addr_lsw;
  166. uint32_t model_addr_msw;
  167. uint32_t mem_map_handle;
  168. } __packed;
  169. struct lsm_param_lab_enable {
  170. uint16_t enable;
  171. uint16_t reserved;
  172. } __packed;
  173. struct lsm_param_lab_config {
  174. uint32_t minor_version;
  175. uint32_t wake_up_latency_ms;
  176. } __packed;
  177. struct lsm_param_lab_out_ch_cfg {
  178. uint32_t minor_version;
  179. uint32_t num_channels;
  180. uint8_t channel_indices[0];
  181. } __packed;
  182. struct lsm_cmd_read {
  183. struct apr_hdr hdr;
  184. uint32_t buf_addr_lsw;
  185. uint32_t buf_addr_msw;
  186. uint32_t mem_map_handle;
  187. uint32_t buf_size;
  188. } __packed;
  189. struct lsm_cmd_read_done {
  190. struct apr_hdr hdr;
  191. uint32_t status;
  192. uint32_t buf_addr_lsw;
  193. uint32_t buf_addr_msw;
  194. uint32_t mem_map_handle;
  195. uint32_t total_size;
  196. uint32_t offset;
  197. uint32_t timestamp_lsw;
  198. uint32_t timestamp_msw;
  199. uint32_t flags;
  200. } __packed;
  201. struct lsm_param_det_event_type {
  202. uint32_t minor_version;
  203. uint32_t event_type;
  204. uint32_t mode;
  205. } __packed;
  206. struct lsm_client *q6lsm_client_alloc(lsm_app_cb cb, void *priv);
  207. void q6lsm_client_free(struct lsm_client *client);
  208. int q6lsm_open(struct lsm_client *client, uint16_t app_id);
  209. int q6lsm_start(struct lsm_client *client, bool wait);
  210. int q6lsm_stop(struct lsm_client *client, bool wait);
  211. int q6lsm_snd_model_buf_alloc(struct lsm_client *client, size_t len,
  212. bool allocate_module_data);
  213. int q6lsm_snd_model_buf_free(struct lsm_client *client);
  214. int q6lsm_close(struct lsm_client *client);
  215. int q6lsm_register_sound_model(struct lsm_client *client,
  216. enum lsm_detection_mode mode,
  217. bool detectfailure);
  218. int q6lsm_set_data(struct lsm_client *client,
  219. enum lsm_detection_mode mode,
  220. bool detectfailure);
  221. int q6lsm_deregister_sound_model(struct lsm_client *client);
  222. void set_lsm_port(int lsm_port);
  223. int get_lsm_port(void);
  224. int q6lsm_lab_control(struct lsm_client *client, u32 enable);
  225. int q6lsm_stop_lab(struct lsm_client *client);
  226. int q6lsm_read(struct lsm_client *client, struct lsm_cmd_read *read);
  227. int q6lsm_lab_buffer_alloc(struct lsm_client *client, bool alloc);
  228. int q6lsm_set_one_param(struct lsm_client *client,
  229. struct lsm_params_info *p_info, void *data,
  230. uint32_t param_type);
  231. void q6lsm_sm_set_param_data(struct lsm_client *client,
  232. struct lsm_params_info *p_info,
  233. size_t *offset);
  234. int q6lsm_set_port_connected(struct lsm_client *client);
  235. int q6lsm_set_fwk_mode_cfg(struct lsm_client *client, uint32_t event_mode);
  236. int q6lsm_set_media_fmt_params(struct lsm_client *client);
  237. int q6lsm_set_media_fmt_v2_params(struct lsm_client *client);
  238. int q6lsm_lab_out_ch_cfg(struct lsm_client *client, u8 *ch_map);
  239. #endif /* __Q6LSM_H__ */