2 * Copyright (c) 2013-2017, 2019 Linux Foundation. All rights reserved.
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.
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.
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>
22 #define MAX_NUM_CONFIDENCE 20
24 #define ADM_LSM_PORT_ID 0xADCB
26 #define LSM_MAX_NUM_CHANNELS 8
28 typedef void (*lsm_app_cb)(uint32_t opcode, uint32_t token,
29 uint32_t *payload, uint16_t client_size, void *priv);
31 struct lsm_sound_model {
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;
41 struct snd_lsm_event_status_v2 {
43 uint16_t payload_size;
44 uint8_t confidence_value[0];
47 struct lsm_lab_buffer {
51 struct ion_handle *handle;
52 struct ion_client *client;
53 uint32_t mem_map_handle;
56 struct lsm_hw_params {
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;
76 uint16_t connect_to_port;
77 uint8_t num_confidence_levels;
78 uint8_t *confidence_levels;
81 dma_addr_t lsm_cal_phy_addr;
82 uint32_t lsm_cal_size;
86 struct lsm_lab_buffer *lab_buffer;
87 struct lsm_hw_params hw_params;
95 struct lsm_stream_cmd_open_tx {
99 uint32_t sampling_rate;
102 struct lsm_stream_cmd_open_tx_v2 {
104 uint32_t topology_id;
107 struct lsm_custom_topologies {
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;
115 struct lsm_session_cmd_set_params_v2 {
116 struct apr_hdr apr_hdr;
117 uint32_t payload_size;
118 struct mem_mapping_hdr mem_hdr;
122 struct lsm_session_cmd_set_params_v3 {
123 struct apr_hdr apr_hdr;
124 struct mem_mapping_hdr mem_hdr;
125 uint32_t payload_size;
129 struct lsm_param_op_mode {
130 uint32_t minor_version;
135 struct lsm_param_connect_to_port {
136 uint32_t minor_version;
137 /* AFE port id that receives voice wake up data */
142 struct lsm_param_poll_enable {
143 uint32_t minor_version;
144 /* indicates to voice wakeup that HW MAD/SW polling is enabled or not */
145 uint32_t polling_enable;
148 struct lsm_param_fwk_mode_cfg {
149 uint32_t minor_version;
153 struct lsm_param_media_fmt {
154 uint32_t minor_version;
155 uint32_t sample_rate;
156 uint16_t num_channels;
158 uint8_t channel_mapping[LSM_MAX_NUM_CHANNELS];
161 struct lsm_param_confidence_levels {
162 uint8_t num_confidence_levels;
163 uint8_t confidence_levels[0];
166 struct lsm_param_epd_thres {
167 uint32_t minor_version;
172 struct lsm_param_gain {
173 uint32_t minor_version;
178 struct lsm_cmd_reg_snd_model {
181 uint32_t model_addr_lsw;
182 uint32_t model_addr_msw;
183 uint32_t mem_map_handle;
186 struct lsm_param_lab_enable {
191 struct lsm_param_lab_config {
192 uint32_t minor_version;
193 uint32_t wake_up_latency_ms;
196 struct lsm_cmd_read {
198 uint32_t buf_addr_lsw;
199 uint32_t buf_addr_msw;
200 uint32_t mem_map_handle;
204 struct lsm_cmd_read_done {
207 uint32_t buf_addr_lsw;
208 uint32_t buf_addr_msw;
209 uint32_t mem_map_handle;
212 uint32_t timestamp_lsw;
213 uint32_t timestamp_msw;
217 struct lsm_client *q6lsm_client_alloc(lsm_app_cb cb, void *priv);
218 void q6lsm_client_free(struct lsm_client *client);
219 int q6lsm_open(struct lsm_client *client, uint16_t app_id);
220 int q6lsm_start(struct lsm_client *client, bool wait);
221 int q6lsm_stop(struct lsm_client *client, bool wait);
222 int q6lsm_snd_model_buf_alloc(struct lsm_client *client, size_t len,
223 bool allocate_module_data);
224 int q6lsm_snd_model_buf_free(struct lsm_client *client);
225 int q6lsm_close(struct lsm_client *client);
226 int q6lsm_register_sound_model(struct lsm_client *client,
227 enum lsm_detection_mode mode,
229 int q6lsm_set_data(struct lsm_client *client,
230 enum lsm_detection_mode mode,
232 int q6lsm_deregister_sound_model(struct lsm_client *client);
233 void set_lsm_port(int);
234 int get_lsm_port(void);
235 int q6lsm_lab_control(struct lsm_client *client, u32 enable);
236 int q6lsm_stop_lab(struct lsm_client *client);
237 int q6lsm_read(struct lsm_client *client, struct lsm_cmd_read *read);
238 int q6lsm_lab_buffer_alloc(struct lsm_client *client, bool alloc);
239 int q6lsm_set_one_param(struct lsm_client *client,
240 struct lsm_params_info *p_info, void *data,
241 uint32_t param_type);
242 void q6lsm_sm_set_param_data(struct lsm_client *client,
243 struct lsm_params_info *p_info,
245 int q6lsm_set_port_connected(struct lsm_client *client);
246 int q6lsm_set_fwk_mode_cfg(struct lsm_client *client, uint32_t event_mode);
247 int q6lsm_set_media_fmt_params(struct lsm_client *client);
248 #endif /* __Q6LSM_H__ */