Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 1 | /* |
Revathi Uddaraju | 1803e36 | 2016-10-19 14:12:00 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved. |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 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 | |
| 16 | #include <linux/list.h> |
| 17 | #include <linux/msm_ion.h> |
| 18 | #include <sound/apr_audio-v2.h> |
| 19 | #include <sound/lsm_params.h> |
| 20 | #include <linux/qdsp6v2/apr.h> |
| 21 | |
| 22 | #define MAX_NUM_CONFIDENCE 20 |
| 23 | |
Revathi Uddaraju | 1803e36 | 2016-10-19 14:12:00 +0530 | [diff] [blame] | 24 | #define ADM_LSM_PORT_ID 0xADCB |
| 25 | |
Chaithanya Krishna Bacharaju | 8a87c69 | 2016-07-21 11:08:56 +0530 | [diff] [blame] | 26 | #define LSM_MAX_NUM_CHANNELS 8 |
| 27 | |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 28 | typedef void (*lsm_app_cb)(uint32_t opcode, uint32_t token, |
| 29 | uint32_t *payload, void *priv); |
| 30 | |
| 31 | struct lsm_sound_model { |
| 32 | dma_addr_t phys; |
| 33 | void *data; |
| 34 | size_t size; /* size of buffer */ |
| 35 | uint32_t actual_size; /* actual number of bytes read by DSP */ |
| 36 | struct ion_handle *handle; |
| 37 | struct ion_client *client; |
| 38 | uint32_t mem_map_handle; |
| 39 | }; |
| 40 | |
| 41 | struct snd_lsm_event_status_v2 { |
| 42 | uint16_t status; |
| 43 | uint16_t payload_size; |
| 44 | uint8_t confidence_value[0]; |
| 45 | }; |
| 46 | |
| 47 | struct lsm_lab_buffer { |
| 48 | dma_addr_t phys; |
| 49 | void *data; |
| 50 | size_t size; |
| 51 | struct ion_handle *handle; |
| 52 | struct ion_client *client; |
| 53 | uint32_t mem_map_handle; |
| 54 | }; |
| 55 | |
Chaithanya Krishna Bacharaju | 8a87c69 | 2016-07-21 11:08:56 +0530 | [diff] [blame] | 56 | struct lsm_hw_params { |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 57 | u16 sample_rate; |
| 58 | u16 sample_size; |
| 59 | u32 buf_sz; |
| 60 | u32 period_count; |
Chaithanya Krishna Bacharaju | 8a87c69 | 2016-07-21 11:08:56 +0530 | [diff] [blame] | 61 | u16 num_chs; |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | struct lsm_client { |
| 65 | int session; |
| 66 | lsm_app_cb cb; |
| 67 | atomic_t cmd_state; |
| 68 | void *priv; |
| 69 | struct apr_svc *apr; |
| 70 | struct apr_svc *mmap_apr; |
| 71 | struct mutex cmd_lock; |
| 72 | struct lsm_sound_model sound_model; |
| 73 | wait_queue_head_t cmd_wait; |
| 74 | uint32_t cmd_err_code; |
| 75 | uint16_t mode; |
| 76 | uint16_t connect_to_port; |
| 77 | uint8_t num_confidence_levels; |
| 78 | uint8_t *confidence_levels; |
| 79 | bool opened; |
| 80 | bool started; |
| 81 | dma_addr_t lsm_cal_phy_addr; |
| 82 | uint32_t lsm_cal_size; |
| 83 | uint32_t app_id; |
| 84 | bool lab_enable; |
| 85 | bool lab_started; |
| 86 | struct lsm_lab_buffer *lab_buffer; |
Chaithanya Krishna Bacharaju | 8a87c69 | 2016-07-21 11:08:56 +0530 | [diff] [blame] | 87 | struct lsm_hw_params hw_params; |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 88 | bool use_topology; |
Revathi Uddaraju | 1803e36 | 2016-10-19 14:12:00 +0530 | [diff] [blame] | 89 | int session_state; |
| 90 | bool poll_enable; |
| 91 | int perf_mode; |
Chaithanya Krishna Bacharaju | 997bb56 | 2016-07-21 10:08:32 +0530 | [diff] [blame] | 92 | uint32_t event_mode; |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | struct lsm_stream_cmd_open_tx { |
| 96 | struct apr_hdr hdr; |
| 97 | uint16_t app_id; |
| 98 | uint16_t reserved; |
| 99 | uint32_t sampling_rate; |
| 100 | } __packed; |
| 101 | |
| 102 | struct lsm_stream_cmd_open_tx_v2 { |
| 103 | struct apr_hdr hdr; |
| 104 | uint32_t topology_id; |
| 105 | } __packed; |
| 106 | |
| 107 | struct lsm_custom_topologies { |
| 108 | struct apr_hdr hdr; |
| 109 | uint32_t data_payload_addr_lsw; |
| 110 | uint32_t data_payload_addr_msw; |
| 111 | uint32_t mem_map_handle; |
| 112 | uint32_t buffer_size; |
| 113 | } __packed; |
| 114 | |
| 115 | struct lsm_param_size_reserved { |
| 116 | uint16_t param_size; |
| 117 | uint16_t reserved; |
| 118 | } __packed; |
| 119 | |
| 120 | union lsm_param_size { |
| 121 | uint32_t param_size; |
| 122 | struct lsm_param_size_reserved sr; |
| 123 | } __packed; |
| 124 | |
| 125 | struct lsm_param_payload_common { |
| 126 | uint32_t module_id; |
| 127 | uint32_t param_id; |
| 128 | union lsm_param_size p_size; |
| 129 | } __packed; |
| 130 | |
| 131 | struct lsm_param_op_mode { |
| 132 | struct lsm_param_payload_common common; |
| 133 | uint32_t minor_version; |
| 134 | uint16_t mode; |
| 135 | uint16_t reserved; |
| 136 | } __packed; |
| 137 | |
| 138 | struct lsm_param_connect_to_port { |
| 139 | struct lsm_param_payload_common common; |
| 140 | uint32_t minor_version; |
| 141 | /* AFE port id that receives voice wake up data */ |
| 142 | uint16_t port_id; |
| 143 | uint16_t reserved; |
| 144 | } __packed; |
| 145 | |
Revathi Uddaraju | 1803e36 | 2016-10-19 14:12:00 +0530 | [diff] [blame] | 146 | struct lsm_param_poll_enable { |
| 147 | struct lsm_param_payload_common common; |
| 148 | uint32_t minor_version; |
| 149 | /* indicates to voice wakeup that HW MAD/SW polling is enabled or not */ |
| 150 | uint32_t polling_enable; |
| 151 | } __packed; |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 152 | |
Chaithanya Krishna Bacharaju | 997bb56 | 2016-07-21 10:08:32 +0530 | [diff] [blame] | 153 | struct lsm_param_fwk_mode_cfg { |
| 154 | struct lsm_param_payload_common common; |
| 155 | uint32_t minor_version; |
| 156 | uint32_t mode; |
| 157 | } __packed; |
| 158 | |
Chaithanya Krishna Bacharaju | 8a87c69 | 2016-07-21 11:08:56 +0530 | [diff] [blame] | 159 | struct lsm_param_media_fmt { |
| 160 | struct lsm_param_payload_common common; |
| 161 | uint32_t minor_version; |
| 162 | uint32_t sample_rate; |
| 163 | uint16_t num_channels; |
| 164 | uint16_t bit_width; |
| 165 | uint8_t channel_mapping[LSM_MAX_NUM_CHANNELS]; |
| 166 | } __packed; |
| 167 | |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 168 | /* |
| 169 | * This param cannot be sent in this format. |
| 170 | * The actual number of confidence level values |
| 171 | * need to appended to this param payload. |
| 172 | */ |
| 173 | struct lsm_param_min_confidence_levels { |
| 174 | struct lsm_param_payload_common common; |
| 175 | uint8_t num_confidence_levels; |
| 176 | } __packed; |
| 177 | |
| 178 | struct lsm_set_params_hdr { |
| 179 | uint32_t data_payload_size; |
| 180 | uint32_t data_payload_addr_lsw; |
| 181 | uint32_t data_payload_addr_msw; |
| 182 | uint32_t mem_map_handle; |
| 183 | } __packed; |
| 184 | |
| 185 | struct lsm_cmd_set_params { |
| 186 | struct apr_hdr msg_hdr; |
| 187 | struct lsm_set_params_hdr param_hdr; |
| 188 | } __packed; |
| 189 | |
| 190 | struct lsm_cmd_set_params_conf { |
| 191 | struct apr_hdr msg_hdr; |
| 192 | struct lsm_set_params_hdr params_hdr; |
| 193 | struct lsm_param_min_confidence_levels conf_payload; |
| 194 | } __packed; |
| 195 | |
Revathi Uddaraju | 1803e36 | 2016-10-19 14:12:00 +0530 | [diff] [blame] | 196 | struct lsm_cmd_set_params_opmode { |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 197 | struct apr_hdr msg_hdr; |
| 198 | struct lsm_set_params_hdr params_hdr; |
Revathi Uddaraju | 1803e36 | 2016-10-19 14:12:00 +0530 | [diff] [blame] | 199 | struct lsm_param_op_mode op_mode; |
| 200 | } __packed; |
| 201 | |
| 202 | struct lsm_cmd_set_connectport { |
| 203 | struct apr_hdr msg_hdr; |
| 204 | struct lsm_set_params_hdr params_hdr; |
| 205 | struct lsm_param_connect_to_port connect_to_port; |
| 206 | } __packed; |
| 207 | |
| 208 | struct lsm_cmd_poll_enable { |
| 209 | struct apr_hdr msg_hdr; |
| 210 | struct lsm_set_params_hdr params_hdr; |
| 211 | struct lsm_param_poll_enable poll_enable; |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 212 | } __packed; |
| 213 | |
| 214 | struct lsm_param_epd_thres { |
| 215 | struct lsm_param_payload_common common; |
| 216 | uint32_t minor_version; |
| 217 | uint32_t epd_begin; |
| 218 | uint32_t epd_end; |
| 219 | } __packed; |
| 220 | |
| 221 | struct lsm_cmd_set_epd_threshold { |
| 222 | struct apr_hdr msg_hdr; |
| 223 | struct lsm_set_params_hdr param_hdr; |
| 224 | struct lsm_param_epd_thres epd_thres; |
| 225 | } __packed; |
| 226 | |
| 227 | struct lsm_param_gain { |
| 228 | struct lsm_param_payload_common common; |
| 229 | uint32_t minor_version; |
| 230 | uint16_t gain; |
| 231 | uint16_t reserved; |
| 232 | } __packed; |
| 233 | |
| 234 | struct lsm_cmd_set_gain { |
| 235 | struct apr_hdr msg_hdr; |
| 236 | struct lsm_set_params_hdr param_hdr; |
| 237 | struct lsm_param_gain lsm_gain; |
| 238 | } __packed; |
| 239 | |
| 240 | struct lsm_cmd_reg_snd_model { |
| 241 | struct apr_hdr hdr; |
| 242 | uint32_t model_size; |
| 243 | uint32_t model_addr_lsw; |
| 244 | uint32_t model_addr_msw; |
| 245 | uint32_t mem_map_handle; |
| 246 | } __packed; |
| 247 | |
| 248 | struct lsm_lab_enable { |
| 249 | struct lsm_param_payload_common common; |
| 250 | uint16_t enable; |
| 251 | uint16_t reserved; |
| 252 | } __packed; |
| 253 | |
| 254 | struct lsm_params_lab_enable { |
| 255 | struct apr_hdr msg_hdr; |
| 256 | struct lsm_set_params_hdr params_hdr; |
| 257 | struct lsm_lab_enable lab_enable; |
| 258 | } __packed; |
| 259 | |
| 260 | struct lsm_lab_config { |
| 261 | struct lsm_param_payload_common common; |
| 262 | uint32_t minor_version; |
| 263 | uint32_t wake_up_latency_ms; |
| 264 | } __packed; |
| 265 | |
| 266 | |
| 267 | struct lsm_params_lab_config { |
| 268 | struct apr_hdr msg_hdr; |
| 269 | struct lsm_set_params_hdr params_hdr; |
| 270 | struct lsm_lab_config lab_config; |
| 271 | } __packed; |
| 272 | |
| 273 | struct lsm_cmd_read { |
| 274 | struct apr_hdr hdr; |
| 275 | uint32_t buf_addr_lsw; |
| 276 | uint32_t buf_addr_msw; |
| 277 | uint32_t mem_map_handle; |
| 278 | uint32_t buf_size; |
| 279 | } __packed; |
| 280 | |
| 281 | struct lsm_cmd_read_done { |
| 282 | struct apr_hdr hdr; |
| 283 | uint32_t status; |
| 284 | uint32_t buf_addr_lsw; |
| 285 | uint32_t buf_addr_msw; |
| 286 | uint32_t mem_map_handle; |
| 287 | uint32_t total_size; |
| 288 | uint32_t offset; |
| 289 | uint32_t timestamp_lsw; |
| 290 | uint32_t timestamp_msw; |
| 291 | uint32_t flags; |
| 292 | } __packed; |
| 293 | |
Chaithanya Krishna Bacharaju | 997bb56 | 2016-07-21 10:08:32 +0530 | [diff] [blame] | 294 | struct lsm_cmd_set_fwk_mode_cfg { |
| 295 | struct apr_hdr msg_hdr; |
| 296 | struct lsm_set_params_hdr params_hdr; |
| 297 | struct lsm_param_fwk_mode_cfg fwk_mode_cfg; |
| 298 | } __packed; |
| 299 | |
Chaithanya Krishna Bacharaju | 8a87c69 | 2016-07-21 11:08:56 +0530 | [diff] [blame] | 300 | struct lsm_cmd_set_media_fmt { |
| 301 | struct apr_hdr msg_hdr; |
| 302 | struct lsm_set_params_hdr params_hdr; |
| 303 | struct lsm_param_media_fmt media_fmt; |
| 304 | } __packed; |
| 305 | |
| 306 | |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 307 | struct lsm_client *q6lsm_client_alloc(lsm_app_cb cb, void *priv); |
| 308 | void q6lsm_client_free(struct lsm_client *client); |
| 309 | int q6lsm_open(struct lsm_client *client, uint16_t app_id); |
| 310 | int q6lsm_start(struct lsm_client *client, bool wait); |
| 311 | int q6lsm_stop(struct lsm_client *client, bool wait); |
| 312 | int q6lsm_snd_model_buf_alloc(struct lsm_client *client, size_t len, |
| 313 | bool allocate_module_data); |
| 314 | int q6lsm_snd_model_buf_free(struct lsm_client *client); |
| 315 | int q6lsm_close(struct lsm_client *client); |
| 316 | int q6lsm_register_sound_model(struct lsm_client *client, |
| 317 | enum lsm_detection_mode mode, |
| 318 | bool detectfailure); |
| 319 | int q6lsm_set_data(struct lsm_client *client, |
| 320 | enum lsm_detection_mode mode, |
| 321 | bool detectfailure); |
| 322 | int q6lsm_deregister_sound_model(struct lsm_client *client); |
| 323 | void set_lsm_port(int lsm_port); |
| 324 | int get_lsm_port(void); |
| 325 | int q6lsm_lab_control(struct lsm_client *client, u32 enable); |
| 326 | int q6lsm_stop_lab(struct lsm_client *client); |
| 327 | int q6lsm_read(struct lsm_client *client, struct lsm_cmd_read *read); |
| 328 | int q6lsm_lab_buffer_alloc(struct lsm_client *client, bool alloc); |
| 329 | int q6lsm_set_one_param(struct lsm_client *client, |
| 330 | struct lsm_params_info *p_info, void *data, |
Chaithanya Krishna Bacharaju | 3f13407 | 2016-02-29 14:13:02 +0530 | [diff] [blame] | 331 | uint32_t param_type); |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 332 | void q6lsm_sm_set_param_data(struct lsm_client *client, |
| 333 | struct lsm_params_info *p_info, |
| 334 | size_t *offset); |
Revathi Uddaraju | 1803e36 | 2016-10-19 14:12:00 +0530 | [diff] [blame] | 335 | int q6lsm_set_port_connected(struct lsm_client *client); |
Chaithanya Krishna Bacharaju | 997bb56 | 2016-07-21 10:08:32 +0530 | [diff] [blame] | 336 | int q6lsm_set_fwk_mode_cfg(struct lsm_client *client, uint32_t event_mode); |
Chaithanya Krishna Bacharaju | 8a87c69 | 2016-07-21 11:08:56 +0530 | [diff] [blame] | 337 | int q6lsm_set_media_fmt_params(struct lsm_client *client); |
Banajit Goswami | 0530e2f | 2016-12-09 21:34:37 -0800 | [diff] [blame] | 338 | #endif /* __Q6LSM_H__ */ |