Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 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 | |
| 14 | #ifndef __CPE_CORE_H__ |
| 15 | #define __CPE_CORE_H__ |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/wait.h> |
| 19 | #include <linux/dma-mapping.h> |
| 20 | #include <sound/lsm_params.h> |
| 21 | |
| 22 | enum { |
| 23 | CMD_INIT_STATE = 0, |
| 24 | CMD_SENT, |
| 25 | CMD_RESP_RCVD, |
| 26 | }; |
| 27 | |
| 28 | enum wcd_cpe_event { |
| 29 | WCD_CPE_PRE_ENABLE = 1, |
| 30 | WCD_CPE_POST_ENABLE, |
| 31 | WCD_CPE_PRE_DISABLE, |
| 32 | WCD_CPE_POST_DISABLE, |
| 33 | }; |
| 34 | |
| 35 | struct wcd_cpe_afe_port_cfg { |
| 36 | u8 port_id; |
| 37 | u16 bit_width; |
| 38 | u16 num_channels; |
| 39 | u32 sample_rate; |
| 40 | }; |
| 41 | |
| 42 | struct lsm_out_fmt_cfg { |
| 43 | u8 format; |
| 44 | u8 pack_mode; |
| 45 | u8 data_path_events; |
| 46 | u8 transfer_mode; |
| 47 | }; |
| 48 | |
| 49 | struct lsm_hw_params { |
| 50 | u32 sample_rate; |
| 51 | u16 num_chs; |
| 52 | u16 bit_width; |
| 53 | }; |
| 54 | |
| 55 | struct cpe_lsm_session { |
| 56 | /* sound model related */ |
| 57 | void *snd_model_data; |
| 58 | u8 *conf_levels; |
| 59 | void *cmi_reg_handle; |
| 60 | |
| 61 | /* Clients private data */ |
| 62 | void *priv_d; |
| 63 | |
| 64 | void (*event_cb)(void *priv_data, |
| 65 | u8 detect_status, |
| 66 | u8 size, u8 *payload); |
| 67 | |
| 68 | struct completion cmd_comp; |
| 69 | struct wcd_cpe_afe_port_cfg afe_port_cfg; |
| 70 | struct wcd_cpe_afe_port_cfg afe_out_port_cfg; |
| 71 | struct mutex lsm_lock; |
| 72 | |
| 73 | u32 snd_model_size; |
| 74 | u32 lsm_mem_handle; |
| 75 | u16 cmd_err_code; |
| 76 | u8 id; |
| 77 | u8 num_confidence_levels; |
| 78 | u16 afe_out_port_id; |
| 79 | struct task_struct *lsm_lab_thread; |
| 80 | bool started; |
| 81 | |
| 82 | u32 lab_enable; |
| 83 | struct lsm_out_fmt_cfg out_fmt_cfg; |
| 84 | |
| 85 | bool is_topology_used; |
| 86 | }; |
| 87 | |
| 88 | struct wcd_cpe_afe_ops { |
| 89 | int (*afe_set_params)(void *core_handle, |
| 90 | struct wcd_cpe_afe_port_cfg *cfg, |
| 91 | bool afe_mad_ctl); |
| 92 | |
| 93 | int (*afe_port_start)(void *core_handle, |
| 94 | struct wcd_cpe_afe_port_cfg *cfg); |
| 95 | |
| 96 | int (*afe_port_stop)(void *core_handle, |
| 97 | struct wcd_cpe_afe_port_cfg *cfg); |
| 98 | |
| 99 | int (*afe_port_suspend)(void *core_handle, |
| 100 | struct wcd_cpe_afe_port_cfg *cfg); |
| 101 | |
| 102 | int (*afe_port_resume)(void *core_handle, |
| 103 | struct wcd_cpe_afe_port_cfg *cfg); |
| 104 | |
| 105 | int (*afe_port_cmd_cfg)(void *core_handle, |
| 106 | struct wcd_cpe_afe_port_cfg *cfg); |
| 107 | }; |
| 108 | |
| 109 | struct wcd_cpe_lsm_ops { |
| 110 | |
| 111 | struct cpe_lsm_session *(*lsm_alloc_session) |
| 112 | (void *core_handle, void *lsm_priv_d, |
| 113 | void (*event_cb)(void *priv_data, |
| 114 | u8 detect_status, |
| 115 | u8 size, u8 *payload)); |
| 116 | |
| 117 | int (*lsm_dealloc_session) |
| 118 | (void *core_handle, struct cpe_lsm_session *); |
| 119 | |
| 120 | int (*lsm_open_tx)(void *core_handle, |
| 121 | struct cpe_lsm_session *, u16, u16); |
| 122 | |
| 123 | int (*lsm_close_tx)(void *core_handle, |
| 124 | struct cpe_lsm_session *); |
| 125 | |
| 126 | int (*lsm_shmem_alloc)(void *core_handle, |
| 127 | struct cpe_lsm_session *, u32 size); |
| 128 | |
| 129 | int (*lsm_shmem_dealloc)(void *core_handle, |
| 130 | struct cpe_lsm_session *); |
| 131 | |
| 132 | int (*lsm_register_snd_model)(void *core_handle, |
| 133 | struct cpe_lsm_session *, |
| 134 | enum lsm_detection_mode, bool); |
| 135 | |
| 136 | int (*lsm_deregister_snd_model)(void *core_handle, |
| 137 | struct cpe_lsm_session *); |
| 138 | |
| 139 | int (*lsm_get_afe_out_port_id)(void *core_handle, |
| 140 | struct cpe_lsm_session *session); |
| 141 | |
| 142 | int (*lsm_start)(void *core_handle, |
| 143 | struct cpe_lsm_session *); |
| 144 | |
| 145 | int (*lsm_stop)(void *core_handle, |
| 146 | struct cpe_lsm_session *); |
| 147 | |
| 148 | int (*lsm_lab_control)(void *core_handle, |
| 149 | struct cpe_lsm_session *session, |
| 150 | bool enable); |
| 151 | |
| 152 | int (*lab_ch_setup)(void *core_handle, |
| 153 | struct cpe_lsm_session *session, |
| 154 | enum wcd_cpe_event event); |
| 155 | |
| 156 | int (*lsm_set_data)(void *core_handle, |
| 157 | struct cpe_lsm_session *session, |
| 158 | enum lsm_detection_mode detect_mode, |
| 159 | bool detect_failure); |
| 160 | int (*lsm_set_fmt_cfg)(void *core_handle, |
| 161 | struct cpe_lsm_session *session); |
| 162 | int (*lsm_set_one_param)(void *core_handle, |
| 163 | struct cpe_lsm_session *session, |
| 164 | struct lsm_params_info *p_info, |
| 165 | void *data, uint32_t param_type); |
| 166 | void (*lsm_get_snd_model_offset) |
| 167 | (void *core_handle, struct cpe_lsm_session *, |
| 168 | size_t *offset); |
| 169 | int (*lsm_set_media_fmt_params)(void *core_handle, |
| 170 | struct cpe_lsm_session *session, |
| 171 | struct lsm_hw_params *param); |
| 172 | int (*lsm_set_port)(void *core_handle, |
| 173 | struct cpe_lsm_session *session, void *data); |
| 174 | }; |
| 175 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 176 | #if IS_ENABLED(CONFIG_SND_SOC_WCD_CPE) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 177 | int wcd_cpe_get_lsm_ops(struct wcd_cpe_lsm_ops *lsm_ops); |
| 178 | int wcd_cpe_get_afe_ops(struct wcd_cpe_afe_ops *afe_ops); |
| 179 | void *wcd_cpe_get_core_handle(struct snd_soc_codec *codec); |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 180 | #else /* CONFIG_SND_SOC_WCD_CPE */ |
| 181 | static inline int wcd_cpe_get_lsm_ops(struct wcd_cpe_lsm_ops *lsm_ops) |
| 182 | { |
| 183 | return 0; |
| 184 | } |
| 185 | static inline int wcd_cpe_get_afe_ops(struct wcd_cpe_afe_ops *afe_ops) |
| 186 | { |
| 187 | return 0; |
| 188 | } |
| 189 | static inline void *wcd_cpe_get_core_handle(struct snd_soc_codec *codec) |
| 190 | { |
| 191 | return NULL; |
| 192 | } |
| 193 | #endif /* CONFIG_SND_SOC_WCD_CPE */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 194 | #endif |