• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _LSM_PARAMS_H__
2 #define _LSM_PARAMS_H__
3 
4 #define LSM_POLLING_ENABLE_SUPPORT
5 #define LSM_EVENT_TIMESTAMP_MODE_SUPPORT
6 
7 #include <linux/types.h>
8 #include <sound/asound.h>
9 
10 #define SNDRV_LSM_VERSION SNDRV_PROTOCOL_VERSION(0, 3, 1)
11 
12 #define LSM_MAX_STAGES_PER_SESSION 2
13 #define LSM_STAGE_INDEX_FIRST 0
14 
15 #define LSM_OUT_FORMAT_PCM (0)
16 #define LSM_OUT_FORMAT_ADPCM (1 << 0)
17 
18 #define LSM_OUT_DATA_RAW (0)
19 #define LSM_OUT_DATA_PACKED (1)
20 
21 #define LSM_OUT_DATA_EVENTS_DISABLED (0)
22 #define LSM_OUT_DATA_EVENTS_ENABLED (1)
23 
24 #define LSM_OUT_TRANSFER_MODE_RT (0)
25 #define LSM_OUT_TRANSFER_MODE_FTRT (1)
26 
27 #define LSM_ENDPOINT_DETECT_THRESHOLD (0)
28 #define LSM_OPERATION_MODE (1)
29 #define LSM_GAIN (2)
30 #define LSM_MIN_CONFIDENCE_LEVELS (3)
31 #define LSM_REG_SND_MODEL (4)
32 #define LSM_DEREG_SND_MODEL (5)
33 #define LSM_CUSTOM_PARAMS (6)
34 #define LSM_POLLING_ENABLE (7)
35 #define LSM_DET_EVENT_TYPE (8)
36 #define LSM_LAB_CONTROL (9)
37 #define LSM_GET_CUSTOM_PARAMS (10)
38 #define LSM_PARAMS_MAX (LSM_GET_CUSTOM_PARAMS + 1)
39 
40 #define LSM_EVENT_NON_TIME_STAMP_MODE (0)
41 #define LSM_EVENT_TIME_STAMP_MODE (1)
42 
43 #define LSM_DET_EVENT_TYPE_LEGACY (0)
44 #define LSM_DET_EVENT_TYPE_GENERIC (1)
45 
46 /* Valid sample rates for input hw_params */
47 #define LSM_INPUT_SAMPLE_RATE_16K 16000
48 #define LSM_INPUT_SAMPLE_RATE_48K 48000
49 
50 /* Valid bit-widths for input hw_params */
51 #define LSM_INPUT_BIT_WIDTH_16	16
52 #define LSM_INPUT_BIT_WIDTH_24	24
53 
54 /* Min and Max channels for input hw_params */
55 #define LSM_INPUT_NUM_CHANNELS_MIN	1
56 #define LSM_INPUT_NUM_CHANNELS_MAX	9
57 
58 enum lsm_app_id {
59 	LSM_VOICE_WAKEUP_APP_ID = 1,
60 	LSM_VOICE_WAKEUP_APP_ID_V2 = 2,
61 };
62 
63 enum lsm_detection_mode {
64 	LSM_MODE_KEYWORD_ONLY_DETECTION = 1,
65 	LSM_MODE_USER_KEYWORD_DETECTION
66 };
67 
68 enum lsm_vw_status {
69 	LSM_VOICE_WAKEUP_STATUS_RUNNING = 1,
70 	LSM_VOICE_WAKEUP_STATUS_DETECTED,
71 	LSM_VOICE_WAKEUP_STATUS_END_SPEECH,
72 	LSM_VOICE_WAKEUP_STATUS_REJECTED
73 };
74 
75 /*
76  * Data for LSM_ENDPOINT_DETECT_THRESHOLD param_type
77  * @epd_begin: Begin threshold
78  * @epd_end: End threshold
79  */
80 struct snd_lsm_ep_det_thres {
81 	__u32 epd_begin;
82 	__u32 epd_end;
83 };
84 
85 /*
86  * Data for LSM_OPERATION_MODE param_type
87  * @mode: The detection mode to be used
88  * @detect_failure: Setting to enable failure detections.
89  */
90 struct snd_lsm_detect_mode {
91 	enum lsm_detection_mode mode;
92 	bool detect_failure;
93 };
94 
95 /*
96  * Data for LSM_GAIN param_type
97  * @gain: The gain to be applied on LSM
98  */
99 struct snd_lsm_gain {
100 	__u16 gain;
101 };
102 
103 /*
104  * Data for LSM_POLLING_ENABLE param_type
105  * @poll_en: Polling enable or disable
106  */
107 struct snd_lsm_poll_enable {
108 	bool poll_en;
109 };
110 
111 /*
112  * Data for LSM_DET_EVENT_TYPE param_type
113  * @event_type: LSM_DET_EVENT_TYPE_LEGACY or LSM_DET_EVENT_TYPE_GENERIC
114  * @mode: Type of information in detection event payload
115  */
116 struct snd_lsm_det_event_type {
117 	__u32 event_type;
118 	__u32 mode;
119 };
120 
121 struct snd_lsm_sound_model_v2 {
122 	__u8 *data;
123 	__u8 *confidence_level;
124 	__u32 data_size;
125 	enum lsm_detection_mode detection_mode;
126 	__u8 num_confidence_levels;
127 	bool detect_failure;
128 };
129 
130 struct snd_lsm_session_data {
131 	enum lsm_app_id app_id;
132 };
133 
134 /*
135  * Stage info for multi-stage session
136  * @app_type: acdb app_type to be used to map topology/cal for the stage
137  * @lpi_enable: low power island mode applicable for the stage
138  */
139 struct snd_lsm_stage_info {
140 	__u32 app_type;
141 	__u32 lpi_enable;
142 };
143 
144 /*
145  * Session info for multi-stage session
146  * @app_id: VoiceWakeup engine id, this is now used to just validate input arg
147  * @num_stages: number of detection stages to be used
148  * @stage_info: stage info for each of the stage being used, ordered by index
149  */
150 struct snd_lsm_session_data_v2 {
151 	enum lsm_app_id app_id;
152 	__u32 num_stages;
153 	struct snd_lsm_stage_info stage_info[LSM_MAX_STAGES_PER_SESSION];
154 };
155 
156 /*
157  * Data for LSM_LAB_CONTROL param_type
158  * @enable: lab enable or disable
159  */
160 struct snd_lsm_lab_control {
161 	__u32 enable;
162 };
163 
164 struct snd_lsm_event_status {
165 	__u16 status;
166 	__u16 payload_size;
167 	__u8 payload[0];
168 };
169 
170 struct snd_lsm_event_status_v3 {
171 	__u32 timestamp_lsw;
172 	__u32 timestamp_msw;
173 	__u16 status;
174 	__u16 payload_size;
175 	__u8 payload[0];
176 };
177 
178 struct snd_lsm_detection_params {
179 	__u8 *conf_level;
180 	enum lsm_detection_mode detect_mode;
181 	__u8 num_confidence_levels;
182 	bool detect_failure;
183 	bool poll_enable;
184 };
185 
186 /*
187  * Param info for each parameter type
188  * @module_id: Module to which parameter is to be set
189  * @param_id: Parameter that is to be set
190  * @param_size: size (in number of bytes) for the data
191  *		in param_data.
192  *		For confidence levels, this is num_conf_levels
193  *		For REG_SND_MODEL, this is size of sound model
194  *		For CUSTOM_PARAMS, this is size of the entire blob of data
195  * @param_data: Data for the parameter.
196  *		For some param_types this is a structure defined, ex: LSM_GAIN
197  *		For CONFIDENCE_LEVELS, this is array of confidence levels
198  *		For REG_SND_MODEL, this is the sound model data
199  *		For CUSTOM_PARAMS, this is the blob of custom data.
200  * @param_type: Parameter type as defined in values upto LSM_PARAMS_MAX
201  */
202 struct lsm_params_info {
203 	__u32 module_id;
204 	__u32 param_id;
205 	__u32 param_size;
206 	__u8 *param_data;
207 	uint32_t param_type;
208 };
209 
210 /*
211  * Param info(version 2) for each parameter type
212  *
213  * Existing member variables:
214  * @module_id: Module to which parameter is to be set
215  * @param_id: Parameter that is to be set
216  * @param_size: size (in number of bytes) for the data
217  *		in param_data.
218  *		For confidence levels, this is num_conf_levels
219  *		For REG_SND_MODEL, this is size of sound model
220  *		For CUSTOM_PARAMS, this is size of the entire blob of data
221  * @param_data: Data for the parameter.
222  *		For some param_types this is a structure defined, ex: LSM_GAIN
223  *		For CONFIDENCE_LEVELS, this is array of confidence levels
224  *		For REG_SND_MODEL, this is the sound model data
225  *		For CUSTOM_PARAMS, this is the blob of custom data.
226  * @param_type: Parameter type as defined in values upto LSM_PARAMS_MAX
227  *
228  * Member variables applicable only to V2:
229  * @instance_id: instance id of the param to which parameter is to be set
230  * @stage_idx: detection stage for which the param is applicable
231  */
232 struct lsm_params_info_v2 {
233 	__u32 module_id;
234 	__u32 param_id;
235 	__u32 param_size;
236 	__u8 *param_data;
237 	uint32_t param_type;
238 	__u16 instance_id;
239 	__u16 stage_idx;
240 };
241 
242 /*
243  * Data passed to the SET_PARAM_V2 IOCTL
244  * @num_params: Number of params that are to be set
245  *		should not be greater than LSM_PARAMS_MAX
246  * @params: Points to an array of lsm_params_info
247  *	    Each entry points to one parameter to set
248  * @data_size: size (in bytes) for params
249  *	       should be equal to
250  *	       num_params * sizeof(struct lsm_parms_info)
251  */
252 struct snd_lsm_module_params {
253 	__u8 *params;
254 	__u32 num_params;
255 	__u32 data_size;
256 };
257 
258 /*
259  * Data passed to LSM_OUT_FORMAT_CFG IOCTL
260  * @format: The media format enum
261  * @packing: indicates the packing method used for data path
262  * @events: indicates whether data path events need to be enabled
263  * @transfer_mode: indicates whether FTRT mode or RT mode.
264  */
265 struct snd_lsm_output_format_cfg {
266 	__u8 format;
267 	__u8 packing;
268 	__u8 events;
269 	__u8 mode;
270 };
271 
272 /*
273  * Data passed to SNDRV_LSM_SET_INPUT_HW_PARAMS ioctl
274  *
275  * @sample_rate: Sample rate of input to lsm.
276  *		 valid values are 16000 and 48000
277  * @bit_width: Bit width of audio samples input to lsm.
278  *	       valid values are 16 and 24
279  * @num_channels: Number of channels input to lsm.
280  *		  valid values are range from 1 to 16
281  */
282 struct snd_lsm_input_hw_params {
283 	__u32 sample_rate;
284 	__u16 bit_width;
285 	__u16 num_channels;
286 } __attribute__((packed));
287 
288 /*
289  * Param get info  for each parameter type
290  * add "for SNDRV_LSM_GET_MODULE_PARAMS ioctl"
291  * Existing member variables:
292  * @module_id: Module to which parameter is to be set
293  * @instance_id: instance id of the param to which parameter is to be set
294  * @param_id: Parameter that is to be set
295  * @param_size: size of requested param
296  * @param_type: Parameter type as defined in values upto LSM_PARAMS_MAX
297  * @stage_idx: detection stage for which the param is applicable
298  * @payload: memory where requested param info will be populated
299  */
300 struct lsm_params_get_info {
301 	__u32 module_id;
302 	__u16 instance_id;
303 	__u16 reserved;
304 	__u32 param_id;
305 	__u32 param_size;
306 	uint32_t param_type;
307 	__u16 stage_idx;
308 	__u8 payload[0];
309 } __attribute__((packed));
310 
311 #define SNDRV_LSM_DEREG_SND_MODEL _IOW('U', 0x01, int)
312 #define SNDRV_LSM_EVENT_STATUS	_IOW('U', 0x02, struct snd_lsm_event_status)
313 #define SNDRV_LSM_ABORT_EVENT	_IOW('U', 0x03, int)
314 #define SNDRV_LSM_START		_IOW('U', 0x04, int)
315 #define SNDRV_LSM_STOP		_IOW('U', 0x05, int)
316 #define SNDRV_LSM_SET_SESSION_DATA _IOW('U', 0x06, struct snd_lsm_session_data)
317 #define SNDRV_LSM_REG_SND_MODEL_V2 _IOW('U', 0x07,\
318 					struct snd_lsm_sound_model_v2)
319 #define SNDRV_LSM_LAB_CONTROL	_IOW('U', 0x08, uint32_t)
320 #define SNDRV_LSM_STOP_LAB	_IO('U', 0x09)
321 #define SNDRV_LSM_SET_PARAMS	_IOW('U', 0x0A, \
322 					struct snd_lsm_detection_params)
323 #define SNDRV_LSM_SET_MODULE_PARAMS	_IOW('U', 0x0B, \
324 					struct snd_lsm_module_params)
325 #define SNDRV_LSM_OUT_FORMAT_CFG _IOW('U', 0x0C, \
326 				      struct snd_lsm_output_format_cfg)
327 #define SNDRV_LSM_SET_PORT	_IO('U', 0x0D)
328 #define SNDRV_LSM_SET_FWK_MODE_CONFIG	_IOW('U', 0x0E, uint32_t)
329 #define SNDRV_LSM_EVENT_STATUS_V3	_IOW('U', 0x0F, \
330 					struct snd_lsm_event_status_v3)
331 #define SNDRV_LSM_GENERIC_DET_EVENT	_IOW('U', 0x10, struct snd_lsm_event_status)
332 #define SNDRV_LSM_SET_INPUT_HW_PARAMS	_IOW('U', 0x11,	\
333 					     struct snd_lsm_input_hw_params)
334 #define SNDRV_LSM_SET_SESSION_DATA_V2 _IOW('U', 0x12, \
335 					struct snd_lsm_session_data_v2)
336 #define SNDRV_LSM_SET_MODULE_PARAMS_V2 _IOW('U', 0x13, \
337 					struct snd_lsm_module_params)
338 #define SNDRV_LSM_GET_MODULE_PARAMS _IOWR('U', 0x14, \
339 					struct lsm_params_get_info)
340 #endif
341