cpe_core.h 4.4 KB

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