cpe_core.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2013-2018, 2020 The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __CPE_CORE_H__
  6. #define __CPE_CORE_H__
  7. #include <linux/types.h>
  8. #include <linux/wait.h>
  9. #include <linux/dma-mapping.h>
  10. #include <audio/sound/lsm_params.h>
  11. enum {
  12. CMD_INIT_STATE = 0,
  13. CMD_SENT,
  14. CMD_RESP_RCVD,
  15. };
  16. enum wcd_cpe_event {
  17. WCD_CPE_PRE_ENABLE = 1,
  18. WCD_CPE_POST_ENABLE,
  19. WCD_CPE_PRE_DISABLE,
  20. WCD_CPE_POST_DISABLE,
  21. };
  22. struct wcd_cpe_afe_port_cfg {
  23. u8 port_id;
  24. u16 bit_width;
  25. u16 num_channels;
  26. u32 sample_rate;
  27. };
  28. struct lsm_out_fmt_cfg {
  29. u8 format;
  30. u8 pack_mode;
  31. u8 data_path_events;
  32. u8 transfer_mode;
  33. };
  34. struct lsm_hw_params {
  35. u32 sample_rate;
  36. u16 num_chs;
  37. u16 bit_width;
  38. };
  39. struct cpe_lsm_session {
  40. /* sound model related */
  41. void *snd_model_data;
  42. u8 *conf_levels;
  43. void *cmi_reg_handle;
  44. /* Clients private data */
  45. void *priv_d;
  46. void (*event_cb)(void *priv_data,
  47. u8 detect_status,
  48. u8 size, u8 *payload);
  49. struct completion cmd_comp;
  50. struct wcd_cpe_afe_port_cfg afe_port_cfg;
  51. struct wcd_cpe_afe_port_cfg afe_out_port_cfg;
  52. struct mutex lsm_lock;
  53. u32 snd_model_size;
  54. u32 lsm_mem_handle;
  55. u16 cmd_err_code;
  56. u8 id;
  57. u8 num_confidence_levels;
  58. u16 afe_out_port_id;
  59. struct task_struct *lsm_lab_thread;
  60. bool started;
  61. u32 lab_enable;
  62. struct lsm_out_fmt_cfg out_fmt_cfg;
  63. bool is_topology_used;
  64. };
  65. struct wcd_cpe_afe_ops {
  66. int (*afe_set_params)(void *core_handle,
  67. struct wcd_cpe_afe_port_cfg *cfg,
  68. bool afe_mad_ctl);
  69. int (*afe_port_start)(void *core_handle,
  70. struct wcd_cpe_afe_port_cfg *cfg);
  71. int (*afe_port_stop)(void *core_handle,
  72. struct wcd_cpe_afe_port_cfg *cfg);
  73. int (*afe_port_suspend)(void *core_handle,
  74. struct wcd_cpe_afe_port_cfg *cfg);
  75. int (*afe_port_resume)(void *core_handle,
  76. struct wcd_cpe_afe_port_cfg *cfg);
  77. int (*afe_port_cmd_cfg)(void *core_handle,
  78. struct wcd_cpe_afe_port_cfg *cfg);
  79. };
  80. struct wcd_cpe_lsm_ops {
  81. struct cpe_lsm_session *(*lsm_alloc_session)
  82. (void *core_handle, void *lsm_priv_d,
  83. void (*event_cb)(void *priv_data,
  84. u8 detect_status,
  85. u8 size, u8 *payload));
  86. int (*lsm_dealloc_session)
  87. (void *core_handle, struct cpe_lsm_session *session);
  88. int (*lsm_open_tx)(void *core_handle,
  89. struct cpe_lsm_session *session, u16 app_id,
  90. u16 sample_rate);
  91. int (*lsm_close_tx)(void *core_handle,
  92. struct cpe_lsm_session *session);
  93. int (*lsm_shmem_alloc)(void *core_handle,
  94. struct cpe_lsm_session *session, u32 size);
  95. int (*lsm_shmem_dealloc)(void *core_handle,
  96. struct cpe_lsm_session *session);
  97. int (*lsm_register_snd_model)(void *core_handle,
  98. struct cpe_lsm_session *session,
  99. enum lsm_detection_mode,
  100. bool detect_failure);
  101. int (*lsm_deregister_snd_model)(void *core_handle,
  102. struct cpe_lsm_session *session);
  103. int (*lsm_get_afe_out_port_id)(void *core_handle,
  104. struct cpe_lsm_session *session);
  105. int (*lsm_start)(void *core_handle,
  106. struct cpe_lsm_session *session);
  107. int (*lsm_stop)(void *core_handle,
  108. struct cpe_lsm_session *session);
  109. int (*lsm_lab_control)(void *core_handle,
  110. struct cpe_lsm_session *session,
  111. bool enable);
  112. int (*lab_ch_setup)(void *core_handle,
  113. struct cpe_lsm_session *session,
  114. enum wcd_cpe_event event);
  115. int (*lsm_set_data)(void *core_handle,
  116. struct cpe_lsm_session *session,
  117. enum lsm_detection_mode detect_mode,
  118. bool detect_failure);
  119. int (*lsm_set_fmt_cfg)(void *core_handle,
  120. struct cpe_lsm_session *session);
  121. int (*lsm_set_one_param)(void *core_handle,
  122. struct cpe_lsm_session *session,
  123. struct lsm_params_info *p_info,
  124. void *data, uint32_t param_type);
  125. void (*lsm_get_snd_model_offset)
  126. (void *core_handle, struct cpe_lsm_session *session,
  127. size_t *offset);
  128. int (*lsm_set_media_fmt_params)(void *core_handle,
  129. struct cpe_lsm_session *session,
  130. struct lsm_hw_params *param);
  131. int (*lsm_set_port)(void *core_handle,
  132. struct cpe_lsm_session *session, void *data);
  133. };
  134. #if IS_ENABLED(CONFIG_SND_SOC_WCD_CPE)
  135. int wcd_cpe_get_lsm_ops(struct wcd_cpe_lsm_ops *lsm_ops);
  136. int wcd_cpe_get_afe_ops(struct wcd_cpe_afe_ops *afe_ops);
  137. void *wcd_cpe_get_core_handle(struct snd_soc_component *component);
  138. #else /* CONFIG_SND_SOC_WCD_CPE */
  139. static inline int wcd_cpe_get_lsm_ops(struct wcd_cpe_lsm_ops *lsm_ops)
  140. {
  141. return 0;
  142. }
  143. static inline int wcd_cpe_get_afe_ops(struct wcd_cpe_afe_ops *afe_ops)
  144. {
  145. return 0;
  146. }
  147. static inline void *wcd_cpe_get_core_handle(struct snd_soc_component *component)
  148. {
  149. return NULL;
  150. }
  151. #endif /* CONFIG_SND_SOC_WCD_CPE */
  152. #endif