blob: cbf83e7a7e914a116809c38f719f49741a0e4c22 [file] [log] [blame]
Banajit Goswami0530e2f2016-12-09 21:34:37 -08001/*
2 * Copyright (c) 2014-2016, 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
14#ifndef __CPE_CMI_H__
15#define __CPE_CMI_H__
16
17#include <linux/types.h>
18
19#define CPE_AFE_PORT_1_TX 1
20#define CPE_AFE_PORT_3_TX 3
21#define CPE_AFE_PORT_ID_2_OUT 0x02
22#define CMI_INBAND_MESSAGE_SIZE 127
23
24/*
25 * Multiple mad types can be supported at once.
26 * these values can be OR'ed to form the set of
27 * supported mad types
28 */
29#define MAD_TYPE_AUDIO (1 << 0)
30#define MAD_TYPE_BEACON (1 << 1)
31#define MAD_TYPE_ULTRASND (1 << 2)
32
33/* Core service command opcodes */
34#define CPE_CORE_SVC_CMD_SHARED_MEM_ALLOC (0x3001)
35#define CPE_CORE_SVC_CMDRSP_SHARED_MEM_ALLOC (0x3002)
36#define CPE_CORE_SVC_CMD_SHARED_MEM_DEALLOC (0x3003)
37#define CPE_CORE_SVC_CMD_DRAM_ACCESS_REQ (0x3004)
38#define CPE_CORE_SVC_EVENT_SYSTEM_BOOT (0x3005)
39/* core service command opcodes for WCD9335 */
40#define CPE_CORE_SVC_CMD_CFG_CLK_PLAN (0x3006)
41#define CPE_CORE_SVC_CMD_CLK_FREQ_REQUEST (0x3007)
42
43#define CPE_BOOT_SUCCESS 0x00
44#define CPE_BOOT_FAILED 0x01
45
46#define CPE_CORE_VERSION_SYSTEM_BOOT_EVENT 0x01
47
48/* LSM Service command opcodes */
49#define CPE_LSM_SESSION_CMD_OPEN_TX (0x2000)
50#define CPE_LSM_SESSION_CMD_SET_PARAMS (0x2001)
51#define CPE_LSM_SESSION_CMD_REGISTER_SOUND_MODEL (0x2002)
52#define CPE_LSM_SESSION_CMD_DEREGISTER_SOUND_MODEL (0x2003)
53#define CPE_LSM_SESSION_CMD_START (0x2004)
54#define CPE_LSM_SESSION_CMD_STOP (0x2005)
55#define CPE_LSM_SESSION_EVENT_DETECTION_STATUS_V2 (0x2006)
56#define CPE_LSM_SESSION_CMD_CLOSE_TX (0x2007)
57#define CPE_LSM_SESSION_CMD_SHARED_MEM_ALLOC (0x2008)
58#define CPE_LSM_SESSION_CMDRSP_SHARED_MEM_ALLOC (0x2009)
59#define CPE_LSM_SESSION_CMD_SHARED_MEM_DEALLOC (0x200A)
60#define CPE_LSM_SESSION_CMD_TX_BUFF_OUTPUT_CONFIG (0x200f)
61#define CPE_LSM_SESSION_CMD_OPEN_TX_V2 (0x200D)
62#define CPE_LSM_SESSION_CMD_SET_PARAMS_V2 (0x200E)
63
64/* LSM Service module and param IDs */
65#define CPE_LSM_MODULE_ID_VOICE_WAKEUP (0x00012C00)
66#define CPE_LSM_MODULE_ID_VOICE_WAKEUP_V2 (0x00012C0D)
67#define CPE_LSM_MODULE_FRAMEWORK (0x00012C0E)
68
69#define CPE_LSM_PARAM_ID_ENDPOINT_DETECT_THRESHOLD (0x00012C01)
70#define CPE_LSM_PARAM_ID_OPERATION_MODE (0x00012C02)
71#define CPE_LSM_PARAM_ID_GAIN (0x00012C03)
72#define CPE_LSM_PARAM_ID_CONNECT_TO_PORT (0x00012C04)
73#define CPE_LSM_PARAM_ID_MIN_CONFIDENCE_LEVELS (0x00012C07)
74
75/* LSM LAB command opcodes */
76#define CPE_LSM_SESSION_CMD_EOB 0x0000200B
77#define CPE_LSM_MODULE_ID_LAB 0x00012C08
78/* used for enable/disable lab*/
79#define CPE_LSM_PARAM_ID_LAB_ENABLE 0x00012C09
80/* used for T in LAB config DSP internal buffer*/
81#define CPE_LSM_PARAM_ID_LAB_CONFIG 0x00012C0A
82#define CPE_LSM_PARAM_ID_REGISTER_SOUND_MODEL (0x00012C14)
83#define CPE_LSM_PARAM_ID_DEREGISTER_SOUND_MODEL (0x00012C15)
84#define CPE_LSM_PARAM_ID_MEDIA_FMT (0x00012C1E)
85
86/* AFE Service command opcodes */
87#define CPE_AFE_PORT_CMD_START (0x1001)
88#define CPE_AFE_PORT_CMD_STOP (0x1002)
89#define CPE_AFE_PORT_CMD_SUSPEND (0x1003)
90#define CPE_AFE_PORT_CMD_RESUME (0x1004)
91#define CPE_AFE_PORT_CMD_SHARED_MEM_ALLOC (0x1005)
92#define CPE_AFE_PORT_CMDRSP_SHARED_MEM_ALLOC (0x1006)
93#define CPE_AFE_PORT_CMD_SHARED_MEM_DEALLOC (0x1007)
94#define CPE_AFE_PORT_CMD_GENERIC_CONFIG (0x1008)
95#define CPE_AFE_SVC_CMD_LAB_MODE (0x1009)
96
97/* AFE Service module and param IDs */
98#define CPE_AFE_CMD_SET_PARAM (0x1000)
99#define CPE_AFE_MODULE_ID_SW_MAD (0x0001022D)
100#define CPE_AFE_PARAM_ID_SW_MAD_CFG (0x0001022E)
101#define CPE_AFE_PARAM_ID_SVM_MODEL (0x0001022F)
102
103#define CPE_AFE_MODULE_HW_MAD (0x00010230)
104#define CPE_AFE_PARAM_ID_HW_MAD_CTL (0x00010232)
105#define CPE_AFE_PARAM_ID_HW_MAD_CFG (0x00010231)
106
107#define CPE_AFE_MODULE_AUDIO_DEV_INTERFACE (0x0001020C)
108#define CPE_AFE_PARAM_ID_GENERIC_PORT_CONFIG (0x00010253)
109
110#define CPE_CMI_BASIC_RSP_OPCODE (0x0001)
111#define CPE_HDR_MAX_PLD_SIZE (0x7F)
112
113#define CMI_OBM_FLAG_IN_BAND 0
114#define CMI_OBM_FLAG_OUT_BAND 1
115
116#define CMI_SHMEM_ALLOC_FAILED 0xff
117
118/*
119 * Future Service ID's can be added one line
120 * before the CMI_CPE_SERVICE_ID_MAX
121 */
122enum {
123 CMI_CPE_SERVICE_ID_MIN = 0,
124 CMI_CPE_CORE_SERVICE_ID,
125 CMI_CPE_AFE_SERVICE_ID,
126 CMI_CPE_LSM_SERVICE_ID,
127 CMI_CPE_SERVICE_ID_MAX,
128};
129
130#define CPE_LSM_SESSION_ID_MAX 2
131
132#define IS_VALID_SESSION_ID(s_id) \
133 (s_id <= CPE_LSM_SESSION_ID_MAX)
134
135#define IS_VALID_SERVICE_ID(s_id) \
136 (s_id > CMI_CPE_SERVICE_ID_MIN && \
137 s_id < CMI_CPE_SERVICE_ID_MAX)
138
139#define IS_VALID_PLD_SIZE(p_size) \
140 (p_size <= CPE_HDR_MAX_PLD_SIZE)
141
142#define CMI_HDR_SET_OPCODE(hdr, cmd) (hdr->opcode = cmd)
143
144
145#define CMI_HDR_SET(hdr_info, mask, shift, value) \
146 (hdr_info = (((hdr_info) & ~(mask)) | \
147 ((value << shift) & mask)))
148
149#define SVC_ID_SHIFT 4
150#define SVC_ID_MASK (0x07 << SVC_ID_SHIFT)
151
152#define SESSION_ID_SHIFT 0
153#define SESSION_ID_MASK (0x0F << SESSION_ID_SHIFT)
154
155#define PAYLD_SIZE_SHIFT 0
156#define PAYLD_SIZE_MASK (0x7F << PAYLD_SIZE_SHIFT)
157
158#define OBM_FLAG_SHIFT 7
159#define OBM_FLAG_MASK (1 << OBM_FLAG_SHIFT)
160
161#define VERSION_SHIFT 7
162#define VERSION_MASK (1 << VERSION_SHIFT)
163
164#define CMI_HDR_SET_SERVICE(hdr, s_id) \
165 CMI_HDR_SET(hdr->hdr_info, SVC_ID_MASK,\
166 SVC_ID_SHIFT, s_id)
167#define CMI_HDR_GET_SERVICE(hdr) \
168 ((hdr->hdr_info >> SVC_ID_SHIFT) & \
169 (SVC_ID_MASK >> SVC_ID_SHIFT))
170
171
172#define CMI_HDR_SET_SESSION(hdr, s_id) \
173 CMI_HDR_SET(hdr->hdr_info, SESSION_ID_MASK,\
174 SESSION_ID_SHIFT, s_id)
175
176#define CMI_HDR_GET_SESSION_ID(hdr) \
177 ((hdr->hdr_info >> SESSION_ID_SHIFT) & \
178 (SESSION_ID_MASK >> SESSION_ID_SHIFT))
179
180#define CMI_GET_HEADER(msg) ((struct cmi_hdr *)(msg))
181#define CMI_GET_PAYLOAD(msg) ((void *)(CMI_GET_HEADER(msg) + 1))
182#define CMI_GET_OPCODE(msg) (CMI_GET_HEADER(msg)->opcode)
183
184#define CMI_HDR_SET_VERSION(hdr, ver) \
185 CMI_HDR_SET(hdr->hdr_info, VERSION_MASK, \
186 VERSION_SHIFT, ver)
187
188#define CMI_HDR_SET_PAYLOAD_SIZE(hdr, p_size) \
189 CMI_HDR_SET(hdr->pld_info, PAYLD_SIZE_MASK, \
190 PAYLD_SIZE_SHIFT, p_size)
191
192#define CMI_HDR_GET_PAYLOAD_SIZE(hdr) \
193 ((hdr->pld_info >> PAYLD_SIZE_SHIFT) & \
194 (PAYLD_SIZE_MASK >> PAYLD_SIZE_SHIFT))
195
196#define CMI_HDR_SET_OBM(hdr, obm_flag) \
197 CMI_HDR_SET(hdr->pld_info, OBM_FLAG_MASK, \
198 OBM_FLAG_SHIFT, obm_flag)
199
200#define CMI_HDR_GET_OBM_FLAG(hdr) \
201 ((hdr->pld_info >> OBM_FLAG_SHIFT) & \
202 (OBM_FLAG_MASK >> OBM_FLAG_SHIFT))
203
204struct cmi_hdr {
205 /*
206 * bits 0:3 is session id
207 * bits 4:6 is service id
208 * bit 7 is the version flag
209 */
210 u8 hdr_info;
211
212 /*
213 * bits 0:6 is payload size in case of in-band message
214 * bits 0:6 is size (OBM message size)
215 * bit 7 is the OBM flag
216 */
217 u8 pld_info;
218
219 /* 16 bit command opcode */
220 u16 opcode;
221} __packed;
222
223union cpe_addr {
224 u64 msw_lsw;
225 void *kvaddr;
226} __packed;
227
228struct cmi_obm {
229 u32 version;
230 u32 size;
231 union cpe_addr data_ptr;
232 u32 mem_handle;
233} __packed;
234
235struct cmi_obm_msg {
236 struct cmi_hdr hdr;
237 struct cmi_obm pld;
238} __packed;
239
240struct cmi_core_svc_event_system_boot {
241 u8 status;
242 u8 version;
243 u16 sfr_buff_size;
244 u32 sfr_buff_address;
245} __packed;
246
247struct cmi_core_svc_cmd_shared_mem_alloc {
248 u32 size;
249} __packed;
250
251struct cmi_core_svc_cmdrsp_shared_mem_alloc {
252 u32 addr;
253} __packed;
254
255struct cmi_core_svc_cmd_clk_freq_request {
256 u32 clk_freq;
257} __packed;
258
259struct cmi_msg_transport {
260 u32 size;
261 u32 addr;
262} __packed;
263
264struct cmi_basic_rsp_result {
265 u8 status;
266} __packed;
267
268struct cpe_lsm_cmd_open_tx {
269 struct cmi_hdr hdr;
270 u16 app_id;
271 u16 reserved;
272 u32 sampling_rate;
273} __packed;
274
275struct cpe_lsm_cmd_open_tx_v2 {
276 struct cmi_hdr hdr;
277 u32 topology_id;
278} __packed;
279
280struct cpe_cmd_shmem_alloc {
281 struct cmi_hdr hdr;
282 u32 size;
283} __packed;
284
285struct cpe_cmdrsp_shmem_alloc {
286 struct cmi_hdr hdr;
287 u32 addr;
288} __packed;
289
290struct cpe_cmd_shmem_dealloc {
291 struct cmi_hdr hdr;
292 u32 addr;
293} __packed;
294
295struct cpe_lsm_event_detect_v2 {
296 struct cmi_hdr hdr;
297 u8 detection_status;
298 u8 size;
299 u8 payload[0];
300} __packed;
301
302struct cpe_lsm_psize_res {
303 u16 param_size;
304 u16 reserved;
305} __packed;
306
307union cpe_lsm_param_size {
308 u32 param_size;
309 struct cpe_lsm_psize_res sr;
310} __packed;
311
312struct cpe_param_data {
313 u32 module_id;
314 u32 param_id;
315 union cpe_lsm_param_size p_size;
316} __packed;
317
318struct cpe_lsm_param_epd_thres {
319 struct cmi_hdr hdr;
320 struct cpe_param_data param;
321 u32 minor_version;
322 u32 epd_begin;
323 u32 epd_end;
324} __packed;
325
326struct cpe_lsm_param_gain {
327 struct cmi_hdr hdr;
328 struct cpe_param_data param;
329 u32 minor_version;
330 u16 gain;
331 u16 reserved;
332} __packed;
333
334struct cpe_afe_hw_mad_ctrl {
335 struct cpe_param_data param;
336 u32 minor_version;
337 u16 mad_type;
338 u16 mad_enable;
339} __packed;
340
341struct cpe_afe_port_cfg {
342 struct cpe_param_data param;
343 u32 minor_version;
344 u16 bit_width;
345 u16 num_channels;
346 u32 sample_rate;
347} __packed;
348
349struct cpe_afe_cmd_port_cfg {
350 struct cmi_hdr hdr;
351 u8 bit_width;
352 u8 num_channels;
353 u16 buffer_size;
354 u32 sample_rate;
355} __packed;
356
357struct cpe_afe_params {
358 struct cmi_hdr hdr;
359 struct cpe_afe_hw_mad_ctrl hw_mad_ctrl;
360 struct cpe_afe_port_cfg port_cfg;
361} __packed;
362
363struct cpe_afe_svc_cmd_mode {
364 struct cmi_hdr hdr;
365 u8 mode;
366} __packed;
367
368struct cpe_lsm_param_opmode {
369 struct cmi_hdr hdr;
370 struct cpe_param_data param;
371 u32 minor_version;
372 u16 mode;
373 u16 reserved;
374} __packed;
375
376struct cpe_lsm_param_connectport {
377 struct cmi_hdr hdr;
378 struct cpe_param_data param;
379 u32 minor_version;
380 u16 afe_port_id;
381 u16 reserved;
382} __packed;
383
384/*
385 * This cannot be sent to CPE as is,
386 * need to append the conf_levels dynamically
387 */
388struct cpe_lsm_conf_level {
389 struct cmi_hdr hdr;
390 struct cpe_param_data param;
391 u8 num_active_models;
392} __packed;
393
394struct cpe_lsm_output_format_cfg {
395 struct cmi_hdr hdr;
396 u8 format;
397 u8 packing;
398 u8 data_path_events;
399} __packed;
400
401struct cpe_lsm_lab_enable {
402 struct cpe_param_data param;
403 u16 enable;
404 u16 reserved;
405} __packed;
406
407struct cpe_lsm_control_lab {
408 struct cmi_hdr hdr;
409 struct cpe_lsm_lab_enable lab_enable;
410} __packed;
411
412struct cpe_lsm_lab_config {
413 struct cpe_param_data param;
414 u32 minor_ver;
415 u32 latency;
416} __packed;
417
418struct cpe_lsm_lab_latency_config {
419 struct cmi_hdr hdr;
420 struct cpe_lsm_lab_config latency_cfg;
421} __packed;
422
423struct cpe_lsm_media_fmt_param {
424 struct cmi_hdr hdr;
425 struct cpe_param_data param;
426 u32 minor_version;
427 u32 sample_rate;
428 u16 num_channels;
429 u16 bit_width;
430} __packed;
431
432
433#define CPE_PARAM_LSM_LAB_LATENCY_SIZE (\
434 sizeof(struct cpe_lsm_lab_latency_config) - \
435 sizeof(struct cmi_hdr))
436#define PARAM_SIZE_LSM_LATENCY_SIZE (\
437 sizeof(struct cpe_lsm_lab_config) - \
438 sizeof(struct cpe_param_data))
439#define CPE_PARAM_SIZE_LSM_LAB_CONTROL (\
440 sizeof(struct cpe_lsm_control_lab) - \
441 sizeof(struct cmi_hdr))
442#define PARAM_SIZE_LSM_CONTROL_SIZE (sizeof(struct cpe_lsm_lab_enable) - \
443 sizeof(struct cpe_param_data))
444#define PARAM_SIZE_AFE_HW_MAD_CTRL (sizeof(struct cpe_afe_hw_mad_ctrl) - \
445 sizeof(struct cpe_param_data))
446#define PARAM_SIZE_AFE_PORT_CFG (sizeof(struct cpe_afe_port_cfg) - \
447 sizeof(struct cpe_param_data))
448#define CPE_AFE_PARAM_PAYLOAD_SIZE (sizeof(struct cpe_afe_params) - \
449 sizeof(struct cmi_hdr))
450
451#define OPEN_CMD_PAYLOAD_SIZE (sizeof(struct cpe_lsm_cmd_open_tx) - \
452 sizeof(struct cmi_hdr))
453#define OPEN_V2_CMD_PAYLOAD_SIZE (sizeof(struct cpe_lsm_cmd_open_tx_v2) - \
454 sizeof(struct cmi_hdr))
455#define SHMEM_ALLOC_CMD_PLD_SIZE (sizeof(struct cpe_cmd_shmem_alloc) - \
456 sizeof(struct cmi_hdr))
457
458#define SHMEM_DEALLOC_CMD_PLD_SIZE (sizeof(struct cpe_cmd_shmem_dealloc) - \
459 sizeof(struct cmi_hdr))
460#define OUT_FMT_CFG_CMD_PAYLOAD_SIZE ( \
461 sizeof(struct cpe_lsm_output_format_cfg) - \
462 sizeof(struct cmi_hdr))
463
464#define CPE_AFE_CMD_PORT_CFG_PAYLOAD_SIZE \
465 (sizeof(struct cpe_afe_cmd_port_cfg) - \
466 sizeof(struct cmi_hdr))
467
468#define CPE_AFE_CMD_MODE_PAYLOAD_SIZE \
469 (sizeof(struct cpe_afe_svc_cmd_mode) - \
470 sizeof(struct cmi_hdr))
471#define CPE_CMD_EPD_THRES_PLD_SIZE (sizeof(struct cpe_lsm_param_epd_thres) - \
472 sizeof(struct cmi_hdr))
473#define CPE_EPD_THRES_PARAM_SIZE ((CPE_CMD_EPD_THRES_PLD_SIZE) - \
474 sizeof(struct cpe_param_data))
475#define CPE_CMD_OPMODE_PLD_SIZE (sizeof(struct cpe_lsm_param_opmode) - \
476 sizeof(struct cmi_hdr))
477#define CPE_OPMODE_PARAM_SIZE ((CPE_CMD_OPMODE_PLD_SIZE) -\
478 sizeof(struct cpe_param_data))
479#define CPE_CMD_CONNECTPORT_PLD_SIZE \
480 (sizeof(struct cpe_lsm_param_connectport) - \
481 sizeof(struct cmi_hdr))
482#define CPE_CONNECTPORT_PARAM_SIZE ((CPE_CMD_CONNECTPORT_PLD_SIZE) - \
483 sizeof(struct cpe_param_data))
484#define CPE_CMD_GAIN_PLD_SIZE (sizeof(struct cpe_lsm_param_gain) - \
485 sizeof(struct cmi_hdr))
486#define CPE_GAIN_PARAM_SIZE ((CPE_CMD_GAIN_PLD_SIZE) - \
487 sizeof(struct cpe_param_data))
488#define CPE_MEDIA_FMT_PLD_SIZE (sizeof(struct cpe_lsm_media_fmt_param) - \
489 sizeof(struct cmi_hdr))
490#define CPE_MEDIA_FMT_PARAM_SIZE ((CPE_MEDIA_FMT_PLD_SIZE) - \
491 sizeof(struct cpe_param_data))
492#endif /* __CPE_CMI_H__ */