cpe_cmi.h 13 KB

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