cpe_cmi.h 12 KB

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