2 * Copyright (c) 2014-2016, 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.
17 #include <linux/types.h>
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
25 * Multiple mad types can be supported at once.
26 * these values can be OR'ed to form the set of
29 #define MAD_TYPE_AUDIO (1 << 0)
30 #define MAD_TYPE_BEACON (1 << 1)
31 #define MAD_TYPE_ULTRASND (1 << 2)
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)
43 #define CPE_BOOT_SUCCESS 0x00
44 #define CPE_BOOT_FAILED 0x01
46 #define CPE_CORE_VERSION_SYSTEM_BOOT_EVENT 0x01
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)
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)
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)
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)
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)
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)
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)
107 #define CPE_AFE_MODULE_AUDIO_DEV_INTERFACE (0x0001020C)
108 #define CPE_AFE_PARAM_ID_GENERIC_PORT_CONFIG (0x00010253)
110 #define CPE_CMI_BASIC_RSP_OPCODE (0x0001)
111 #define CPE_HDR_MAX_PLD_SIZE (0x7F)
113 #define CMI_OBM_FLAG_IN_BAND 0
114 #define CMI_OBM_FLAG_OUT_BAND 1
116 #define CMI_SHMEM_ALLOC_FAILED 0xff
119 * Future Service ID's can be added one line
120 * before the CMI_CPE_SERVICE_ID_MAX
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,
130 #define CPE_LSM_SESSION_ID_MAX 2
132 #define IS_VALID_SESSION_ID(s_id) \
133 (s_id <= CPE_LSM_SESSION_ID_MAX)
135 #define IS_VALID_SERVICE_ID(s_id) \
136 (s_id > CMI_CPE_SERVICE_ID_MIN && \
137 s_id < CMI_CPE_SERVICE_ID_MAX)
139 #define IS_VALID_PLD_SIZE(p_size) \
140 (p_size <= CPE_HDR_MAX_PLD_SIZE)
142 #define CMI_HDR_SET_OPCODE(hdr, cmd) (hdr->opcode = cmd)
145 #define CMI_HDR_SET(hdr_info, mask, shift, value) \
146 (hdr_info = (((hdr_info) & ~(mask)) | \
147 ((value << shift) & mask)))
149 #define SVC_ID_SHIFT 4
150 #define SVC_ID_MASK (0x07 << SVC_ID_SHIFT)
152 #define SESSION_ID_SHIFT 0
153 #define SESSION_ID_MASK (0x0F << SESSION_ID_SHIFT)
155 #define PAYLD_SIZE_SHIFT 0
156 #define PAYLD_SIZE_MASK (0x7F << PAYLD_SIZE_SHIFT)
158 #define OBM_FLAG_SHIFT 7
159 #define OBM_FLAG_MASK (1 << OBM_FLAG_SHIFT)
161 #define VERSION_SHIFT 7
162 #define VERSION_MASK (1 << VERSION_SHIFT)
164 #define CMI_HDR_SET_SERVICE(hdr, s_id) \
165 CMI_HDR_SET(hdr->hdr_info, SVC_ID_MASK,\
167 #define CMI_HDR_GET_SERVICE(hdr) \
168 ((hdr->hdr_info >> SVC_ID_SHIFT) & \
169 (SVC_ID_MASK >> SVC_ID_SHIFT))
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)
176 #define CMI_HDR_GET_SESSION_ID(hdr) \
177 ((hdr->hdr_info >> SESSION_ID_SHIFT) & \
178 (SESSION_ID_MASK >> SESSION_ID_SHIFT))
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)
184 #define CMI_HDR_SET_VERSION(hdr, ver) \
185 CMI_HDR_SET(hdr->hdr_info, VERSION_MASK, \
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)
192 #define CMI_HDR_GET_PAYLOAD_SIZE(hdr) \
193 ((hdr->pld_info >> PAYLD_SIZE_SHIFT) & \
194 (PAYLD_SIZE_MASK >> PAYLD_SIZE_SHIFT))
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)
200 #define CMI_HDR_GET_OBM_FLAG(hdr) \
201 ((hdr->pld_info >> OBM_FLAG_SHIFT) & \
202 (OBM_FLAG_MASK >> OBM_FLAG_SHIFT))
206 * bits 0:3 is session id
207 * bits 4:6 is service id
208 * bit 7 is the version flag
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
219 /* 16 bit command opcode */
231 union cpe_addr data_ptr;
240 struct cmi_core_svc_event_system_boot {
244 u32 sfr_buff_address;
247 struct cmi_core_svc_cmd_shared_mem_alloc {
251 struct cmi_core_svc_cmdrsp_shared_mem_alloc {
255 struct cmi_core_svc_cmd_clk_freq_request {
259 struct cmi_msg_transport {
264 struct cmi_basic_rsp_result {
268 struct cpe_lsm_cmd_open_tx {
275 struct cpe_lsm_cmd_open_tx_v2 {
280 struct cpe_cmd_shmem_alloc {
285 struct cpe_cmdrsp_shmem_alloc {
290 struct cpe_cmd_shmem_dealloc {
295 struct cpe_lsm_event_detect_v2 {
302 struct cpe_lsm_psize_res {
307 union cpe_lsm_param_size {
309 struct cpe_lsm_psize_res sr;
312 struct cpe_param_data {
315 union cpe_lsm_param_size p_size;
318 struct cpe_lsm_param_epd_thres {
320 struct cpe_param_data param;
326 struct cpe_lsm_param_gain {
328 struct cpe_param_data param;
334 struct cpe_afe_hw_mad_ctrl {
335 struct cpe_param_data param;
341 struct cpe_afe_port_cfg {
342 struct cpe_param_data param;
349 struct cpe_afe_cmd_port_cfg {
357 struct cpe_afe_params {
359 struct cpe_afe_hw_mad_ctrl hw_mad_ctrl;
360 struct cpe_afe_port_cfg port_cfg;
363 struct cpe_afe_svc_cmd_mode {
368 struct cpe_lsm_param_opmode {
370 struct cpe_param_data param;
376 struct cpe_lsm_param_connectport {
378 struct cpe_param_data param;
385 * This cannot be sent to CPE as is,
386 * need to append the conf_levels dynamically
388 struct cpe_lsm_conf_level {
390 struct cpe_param_data param;
391 u8 num_active_models;
394 struct cpe_lsm_output_format_cfg {
401 struct cpe_lsm_lab_enable {
402 struct cpe_param_data param;
407 struct cpe_lsm_control_lab {
409 struct cpe_lsm_lab_enable lab_enable;
412 struct cpe_lsm_lab_config {
413 struct cpe_param_data param;
418 struct cpe_lsm_lab_latency_config {
420 struct cpe_lsm_lab_config latency_cfg;
423 struct cpe_lsm_media_fmt_param {
425 struct cpe_param_data param;
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))
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))
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))
464 #define CPE_AFE_CMD_PORT_CFG_PAYLOAD_SIZE \
465 (sizeof(struct cpe_afe_cmd_port_cfg) - \
466 sizeof(struct cmi_hdr))
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__ */