blob: be0e9988b8f7e921955d683b73d93226391bb2ed [file] [log] [blame]
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301/*
kunleiz5574e742019-04-12 11:28:19 +08002 * Copyright (c) 2013-2017, 2019 The Linux Foundation. All rights reserved.
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303 *
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>
Laxminath Kasam605b42f2017-08-01 22:02:15 +053018#include <dsp/apr_audio-v2.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053019#include <sound/lsm_params.h>
Laxminath Kasam605b42f2017-08-01 22:02:15 +053020#include <ipc/apr.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053021
22#define MAX_NUM_CONFIDENCE 20
23
24#define ADM_LSM_PORT_ID 0xADCB
25
26#define LSM_MAX_NUM_CHANNELS 8
27
28typedef void (*lsm_app_cb)(uint32_t opcode, uint32_t token,
kunleiz5574e742019-04-12 11:28:19 +080029 uint32_t *payload, uint16_t client_size, void *priv);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053030
31struct 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
41struct snd_lsm_event_status_v2 {
42 uint16_t status;
43 uint16_t payload_size;
44 uint8_t confidence_value[0];
45};
46
47struct 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
56struct lsm_hw_params {
57 u16 sample_rate;
58 u16 sample_size;
59 u32 buf_sz;
60 u32 period_count;
61 u16 num_chs;
62};
63
64struct 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;
87 struct lsm_hw_params hw_params;
88 bool use_topology;
89 int session_state;
90 bool poll_enable;
91 int perf_mode;
92 uint32_t event_mode;
93};
94
95struct 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
102struct lsm_stream_cmd_open_tx_v2 {
103 struct apr_hdr hdr;
104 uint32_t topology_id;
105} __packed;
106
107struct 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
115struct lsm_param_size_reserved {
116 uint16_t param_size;
117 uint16_t reserved;
118} __packed;
119
120union lsm_param_size {
121 uint32_t param_size;
122 struct lsm_param_size_reserved sr;
123} __packed;
124
125struct lsm_param_payload_common {
126 uint32_t module_id;
127 uint32_t param_id;
128 union lsm_param_size p_size;
129} __packed;
130
131struct 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
138struct 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
146struct 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;
152
153struct lsm_param_fwk_mode_cfg {
154 struct lsm_param_payload_common common;
155 uint32_t minor_version;
156 uint32_t mode;
157} __packed;
158
159struct 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
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 */
173struct lsm_param_min_confidence_levels {
174 struct lsm_param_payload_common common;
175 uint8_t num_confidence_levels;
176} __packed;
177
178struct 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
185struct lsm_cmd_set_params {
186 struct apr_hdr msg_hdr;
187 struct lsm_set_params_hdr param_hdr;
188} __packed;
189
190struct 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
196struct lsm_cmd_set_params_opmode {
197 struct apr_hdr msg_hdr;
198 struct lsm_set_params_hdr params_hdr;
199 struct lsm_param_op_mode op_mode;
200} __packed;
201
202struct 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
208struct 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;
212} __packed;
213
214struct 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
221struct 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
227struct 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
234struct 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
240struct 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
248struct lsm_lab_enable {
249 struct lsm_param_payload_common common;
250 uint16_t enable;
251 uint16_t reserved;
252} __packed;
253
254struct 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
260struct 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
267struct 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
273struct 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
281struct 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
294struct 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
300struct 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
307struct lsm_client *q6lsm_client_alloc(lsm_app_cb cb, void *priv);
308void q6lsm_client_free(struct lsm_client *client);
309int q6lsm_open(struct lsm_client *client, uint16_t app_id);
310int q6lsm_start(struct lsm_client *client, bool wait);
311int q6lsm_stop(struct lsm_client *client, bool wait);
312int q6lsm_snd_model_buf_alloc(struct lsm_client *client, size_t len,
313 bool allocate_module_data);
314int q6lsm_snd_model_buf_free(struct lsm_client *client);
315int q6lsm_close(struct lsm_client *client);
316int q6lsm_register_sound_model(struct lsm_client *client,
317 enum lsm_detection_mode mode,
318 bool detectfailure);
319int q6lsm_set_data(struct lsm_client *client,
320 enum lsm_detection_mode mode,
321 bool detectfailure);
322int q6lsm_deregister_sound_model(struct lsm_client *client);
323void set_lsm_port(int lsm_port);
324int get_lsm_port(void);
325int q6lsm_lab_control(struct lsm_client *client, u32 enable);
326int q6lsm_stop_lab(struct lsm_client *client);
327int q6lsm_read(struct lsm_client *client, struct lsm_cmd_read *read);
328int q6lsm_lab_buffer_alloc(struct lsm_client *client, bool alloc);
329int q6lsm_set_one_param(struct lsm_client *client,
330 struct lsm_params_info *p_info, void *data,
331 uint32_t param_type);
332void q6lsm_sm_set_param_data(struct lsm_client *client,
333 struct lsm_params_info *p_info,
334 size_t *offset);
335int q6lsm_set_port_connected(struct lsm_client *client);
336int q6lsm_set_fwk_mode_cfg(struct lsm_client *client, uint32_t event_mode);
337int q6lsm_set_media_fmt_params(struct lsm_client *client);
338#endif /* __Q6LSM_H__ */