cpe_core.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2013-2017, 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 <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 *);
  88. int (*lsm_open_tx)(void *core_handle,
  89. struct cpe_lsm_session *, u16, u16);
  90. int (*lsm_close_tx)(void *core_handle,
  91. struct cpe_lsm_session *);
  92. int (*lsm_shmem_alloc)(void *core_handle,
  93. struct cpe_lsm_session *, u32 size);
  94. int (*lsm_shmem_dealloc)(void *core_handle,
  95. struct cpe_lsm_session *);
  96. int (*lsm_register_snd_model)(void *core_handle,
  97. struct cpe_lsm_session *,
  98. enum lsm_detection_mode, bool);
  99. int (*lsm_deregister_snd_model)(void *core_handle,
  100. struct cpe_lsm_session *);
  101. int (*lsm_get_afe_out_port_id)(void *core_handle,
  102. struct cpe_lsm_session *session);
  103. int (*lsm_start)(void *core_handle,
  104. struct cpe_lsm_session *);
  105. int (*lsm_stop)(void *core_handle,
  106. struct cpe_lsm_session *);
  107. int (*lsm_lab_control)(void *core_handle,
  108. struct cpe_lsm_session *session,
  109. bool enable);
  110. int (*lab_ch_setup)(void *core_handle,
  111. struct cpe_lsm_session *session,
  112. enum wcd_cpe_event event);
  113. int (*lsm_set_data)(void *core_handle,
  114. struct cpe_lsm_session *session,
  115. enum lsm_detection_mode detect_mode,
  116. bool detect_failure);
  117. int (*lsm_set_fmt_cfg)(void *core_handle,
  118. struct cpe_lsm_session *session);
  119. int (*lsm_set_one_param)(void *core_handle,
  120. struct cpe_lsm_session *session,
  121. struct lsm_params_info *p_info,
  122. void *data, uint32_t param_type);
  123. void (*lsm_get_snd_model_offset)
  124. (void *core_handle, struct cpe_lsm_session *,
  125. size_t *offset);
  126. int (*lsm_set_media_fmt_params)(void *core_handle,
  127. struct cpe_lsm_session *session,
  128. struct lsm_hw_params *param);
  129. int (*lsm_set_port)(void *core_handle,
  130. struct cpe_lsm_session *session, void *data);
  131. };
  132. #if IS_ENABLED(CONFIG_SND_SOC_WCD_CPE)
  133. int wcd_cpe_get_lsm_ops(struct wcd_cpe_lsm_ops *lsm_ops);
  134. int wcd_cpe_get_afe_ops(struct wcd_cpe_afe_ops *afe_ops);
  135. void *wcd_cpe_get_core_handle(struct snd_soc_codec *codec);
  136. #else /* CONFIG_SND_SOC_WCD_CPE */
  137. static inline int wcd_cpe_get_lsm_ops(struct wcd_cpe_lsm_ops *lsm_ops)
  138. {
  139. return 0;
  140. }
  141. static inline int wcd_cpe_get_afe_ops(struct wcd_cpe_afe_ops *afe_ops)
  142. {
  143. return 0;
  144. }
  145. static inline void *wcd_cpe_get_core_handle(struct snd_soc_codec *codec)
  146. {
  147. return NULL;
  148. }
  149. #endif /* CONFIG_SND_SOC_WCD_CPE */
  150. #endif