Meng Wang | 61af684 | 2018-09-10 17:47:55 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4 | */ |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/slab.h> |
| 7 | #include <linux/wait.h> |
| 8 | #include <linux/sched.h> |
| 9 | #include <linux/jiffies.h> |
| 10 | #include <linux/uaccess.h> |
| 11 | #include <linux/atomic.h> |
| 12 | #include <linux/wait.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 13 | #include <sound/asound.h> |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 14 | #include <dsp/msm-dts-srs-tm-config.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 15 | #include <dsp/apr_audio-v2.h> |
| 16 | #include <dsp/q6adm-v2.h> |
| 17 | #include <dsp/q6audio-v2.h> |
| 18 | #include <dsp/q6afe-v2.h> |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 19 | #include <dsp/q6core.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 20 | #include <dsp/audio_cal_utils.h> |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 21 | #include <dsp/q6common.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 22 | #include <ipc/apr.h> |
| 23 | #include "adsp_err.h" |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 24 | |
| 25 | #define TIMEOUT_MS 1000 |
| 26 | |
| 27 | #define RESET_COPP_ID 99 |
| 28 | #define INVALID_COPP_ID 0xFF |
| 29 | /* Used for inband payload copy, max size is 4k */ |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 30 | /* 3 is to account for module, instance & param ID in payload */ |
| 31 | #define ADM_GET_PARAMETER_LENGTH (4096 - APR_HDR_SIZE - 3 * sizeof(uint32_t)) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 32 | |
| 33 | #define ULL_SUPPORTED_BITS_PER_SAMPLE 16 |
| 34 | #define ULL_SUPPORTED_SAMPLE_RATE 48000 |
| 35 | |
| 36 | #ifndef CONFIG_DOLBY_DAP |
| 37 | #undef DOLBY_ADM_COPP_TOPOLOGY_ID |
| 38 | #define DOLBY_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFE |
| 39 | #endif |
| 40 | |
| 41 | #ifndef CONFIG_DOLBY_DS2 |
| 42 | #undef DS2_ADM_COPP_TOPOLOGY_ID |
| 43 | #define DS2_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFF |
| 44 | #endif |
| 45 | |
| 46 | /* ENUM for adm_status */ |
| 47 | enum adm_cal_status { |
| 48 | ADM_STATUS_CALIBRATION_REQUIRED = 0, |
| 49 | ADM_STATUS_MAX, |
| 50 | }; |
| 51 | |
| 52 | struct adm_copp { |
| 53 | |
| 54 | atomic_t id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 55 | atomic_t cnt[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 56 | atomic_t topology[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 57 | atomic_t mode[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 58 | atomic_t stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 59 | atomic_t rate[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 60 | atomic_t bit_width[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 61 | atomic_t channels[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 62 | atomic_t app_type[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 63 | atomic_t acdb_id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 64 | atomic_t session_type[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 65 | wait_queue_head_t wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 66 | wait_queue_head_t adm_delay_wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 67 | atomic_t adm_delay_stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 68 | uint32_t adm_delay[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 69 | unsigned long adm_status[AFE_MAX_PORTS][MAX_COPPS_PER_PORT]; |
| 70 | }; |
| 71 | |
| 72 | struct source_tracking_data { |
Banajit Goswami | 08bb736 | 2017-11-03 22:48:23 -0700 | [diff] [blame] | 73 | struct dma_buf *dma_buf; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 74 | struct param_outband memmap; |
| 75 | int apr_cmd_status; |
| 76 | }; |
| 77 | |
| 78 | struct adm_ctl { |
| 79 | void *apr; |
| 80 | |
| 81 | struct adm_copp copp; |
| 82 | |
| 83 | atomic_t matrix_map_stat; |
| 84 | wait_queue_head_t matrix_map_wait; |
| 85 | |
| 86 | atomic_t adm_stat; |
| 87 | wait_queue_head_t adm_wait; |
| 88 | |
| 89 | struct cal_type_data *cal_data[ADM_MAX_CAL_TYPES]; |
| 90 | |
| 91 | atomic_t mem_map_handles[ADM_MEM_MAP_INDEX_MAX]; |
| 92 | atomic_t mem_map_index; |
| 93 | |
| 94 | struct param_outband outband_memmap; |
| 95 | struct source_tracking_data sourceTrackingData; |
| 96 | |
| 97 | int set_custom_topology; |
| 98 | int ec_ref_rx; |
| 99 | int num_ec_ref_rx_chans; |
| 100 | int ec_ref_rx_bit_width; |
| 101 | int ec_ref_rx_sampling_rate; |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 102 | |
| 103 | int native_mode; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | static struct adm_ctl this_adm; |
| 107 | |
| 108 | struct adm_multi_ch_map { |
| 109 | bool set_channel_map; |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 110 | char channel_mapping[PCM_FORMAT_MAX_NUM_CHANNEL_V8]; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | #define ADM_MCH_MAP_IDX_PLAYBACK 0 |
| 114 | #define ADM_MCH_MAP_IDX_REC 1 |
| 115 | static struct adm_multi_ch_map multi_ch_maps[2] = { |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 116 | { false, |
| 117 | {0, 0, 0, 0, 0, 0, 0, 0, |
| 118 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 119 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 120 | 0, 0, 0, 0, 0, 0, 0, 0} |
| 121 | }, |
| 122 | { false, |
| 123 | {0, 0, 0, 0, 0, 0, 0, 0, |
| 124 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 125 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 126 | 0, 0, 0, 0, 0, 0, 0, 0} |
| 127 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | static int adm_get_parameters[MAX_COPPS_PER_PORT * ADM_GET_PARAMETER_LENGTH]; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 131 | static int adm_module_topo_list[MAX_COPPS_PER_PORT * |
| 132 | ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH]; |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 133 | static struct mutex dts_srs_lock; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 134 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 135 | void msm_dts_srs_acquire_lock(void) |
| 136 | { |
| 137 | mutex_lock(&dts_srs_lock); |
| 138 | } |
| 139 | |
| 140 | void msm_dts_srs_release_lock(void) |
| 141 | { |
| 142 | mutex_unlock(&dts_srs_lock); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * adm_validate_and_get_port_index - |
| 147 | * validate given port id |
| 148 | * |
| 149 | * @port_id: Port ID number |
| 150 | * |
| 151 | * Returns valid index on success or error on failure |
| 152 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 153 | int adm_validate_and_get_port_index(int port_id) |
| 154 | { |
| 155 | int index; |
| 156 | int ret; |
| 157 | |
| 158 | ret = q6audio_validate_port(port_id); |
| 159 | if (ret < 0) { |
| 160 | pr_err("%s: port validation failed id 0x%x ret %d\n", |
| 161 | __func__, port_id, ret); |
| 162 | return -EINVAL; |
| 163 | } |
| 164 | |
| 165 | index = afe_get_port_index(port_id); |
| 166 | if (index < 0 || index >= AFE_MAX_PORTS) { |
| 167 | pr_err("%s: Invalid port idx %d port_id 0x%x\n", |
| 168 | __func__, index, |
| 169 | port_id); |
| 170 | return -EINVAL; |
| 171 | } |
| 172 | pr_debug("%s: port_idx- %d\n", __func__, index); |
| 173 | return index; |
| 174 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 175 | EXPORT_SYMBOL(adm_validate_and_get_port_index); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 176 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 177 | /** |
| 178 | * adm_get_default_copp_idx - |
| 179 | * retrieve default copp_idx for given port |
| 180 | * |
| 181 | * @port_id: Port ID number |
| 182 | * |
| 183 | * Returns valid value on success or error on failure |
| 184 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 185 | int adm_get_default_copp_idx(int port_id) |
| 186 | { |
| 187 | int port_idx = adm_validate_and_get_port_index(port_id), idx; |
| 188 | |
| 189 | if (port_idx < 0) { |
| 190 | pr_err("%s: Invalid port id: 0x%x", __func__, port_id); |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | pr_debug("%s: port_idx:%d\n", __func__, port_idx); |
| 194 | for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) { |
| 195 | if (atomic_read(&this_adm.copp.id[port_idx][idx]) != |
| 196 | RESET_COPP_ID) |
| 197 | return idx; |
| 198 | } |
| 199 | return -EINVAL; |
| 200 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 201 | EXPORT_SYMBOL(adm_get_default_copp_idx); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 202 | |
| 203 | int adm_get_topology_for_port_from_copp_id(int port_id, int copp_id) |
| 204 | { |
| 205 | int port_idx = adm_validate_and_get_port_index(port_id), idx; |
| 206 | |
| 207 | if (port_idx < 0) { |
| 208 | pr_err("%s: Invalid port id: 0x%x", __func__, port_id); |
| 209 | return 0; |
| 210 | } |
| 211 | for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) |
| 212 | if (atomic_read(&this_adm.copp.id[port_idx][idx]) == copp_id) |
| 213 | return atomic_read(&this_adm.copp.topology[port_idx] |
| 214 | [idx]); |
| 215 | pr_err("%s: Invalid copp_id %d port_id 0x%x\n", |
| 216 | __func__, copp_id, port_id); |
| 217 | return 0; |
| 218 | } |
| 219 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 220 | /** |
| 221 | * adm_get_topology_for_port_copp_idx - |
| 222 | * retrieve topology of given port/copp_idx |
| 223 | * |
| 224 | * @port_id: Port ID number |
| 225 | * @copp_idx: copp index of ADM copp |
| 226 | * |
| 227 | * Returns valid value on success or 0 on failure |
| 228 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 229 | int adm_get_topology_for_port_copp_idx(int port_id, int copp_idx) |
| 230 | { |
| 231 | int port_idx = adm_validate_and_get_port_index(port_id); |
| 232 | |
| 233 | if (port_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 234 | pr_err("%s: Invalid port: 0x%x copp id: 0x%x", |
| 235 | __func__, port_id, copp_idx); |
| 236 | return 0; |
| 237 | } |
| 238 | return atomic_read(&this_adm.copp.topology[port_idx][copp_idx]); |
| 239 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 240 | EXPORT_SYMBOL(adm_get_topology_for_port_copp_idx); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 241 | |
| 242 | int adm_get_indexes_from_copp_id(int copp_id, int *copp_idx, int *port_idx) |
| 243 | { |
| 244 | int p_idx, c_idx; |
| 245 | |
| 246 | for (p_idx = 0; p_idx < AFE_MAX_PORTS; p_idx++) { |
| 247 | for (c_idx = 0; c_idx < MAX_COPPS_PER_PORT; c_idx++) { |
| 248 | if (atomic_read(&this_adm.copp.id[p_idx][c_idx]) |
| 249 | == copp_id) { |
| 250 | if (copp_idx != NULL) |
| 251 | *copp_idx = c_idx; |
| 252 | if (port_idx != NULL) |
| 253 | *port_idx = p_idx; |
| 254 | return 0; |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | return -EINVAL; |
| 259 | } |
| 260 | |
| 261 | static int adm_get_copp_id(int port_idx, int copp_idx) |
| 262 | { |
| 263 | pr_debug("%s: port_idx:%d copp_idx:%d\n", __func__, port_idx, copp_idx); |
| 264 | |
| 265 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 266 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 267 | return -EINVAL; |
| 268 | } |
| 269 | return atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 270 | } |
| 271 | |
| 272 | static int adm_get_idx_if_copp_exists(int port_idx, int topology, int mode, |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 273 | int rate, int bit_width, int app_type, |
| 274 | int session_type) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 275 | { |
| 276 | int idx; |
| 277 | |
| 278 | pr_debug("%s: port_idx-%d, topology-0x%x, mode-%d, rate-%d, bit_width-%d\n", |
| 279 | __func__, port_idx, topology, mode, rate, bit_width); |
| 280 | |
| 281 | for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) |
| 282 | if ((topology == |
| 283 | atomic_read(&this_adm.copp.topology[port_idx][idx])) && |
| 284 | (mode == atomic_read(&this_adm.copp.mode[port_idx][idx])) && |
| 285 | (rate == atomic_read(&this_adm.copp.rate[port_idx][idx])) && |
| 286 | (bit_width == |
| 287 | atomic_read(&this_adm.copp.bit_width[port_idx][idx])) && |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 288 | (session_type == |
| 289 | atomic_read( |
| 290 | &this_adm.copp.session_type[port_idx][idx])) && |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 291 | (app_type == |
| 292 | atomic_read(&this_adm.copp.app_type[port_idx][idx]))) |
| 293 | return idx; |
| 294 | return -EINVAL; |
| 295 | } |
| 296 | |
| 297 | static int adm_get_next_available_copp(int port_idx) |
| 298 | { |
| 299 | int idx; |
| 300 | |
| 301 | pr_debug("%s:\n", __func__); |
| 302 | for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) { |
| 303 | pr_debug("%s: copp_id:0x%x port_idx:%d idx:%d\n", __func__, |
| 304 | atomic_read(&this_adm.copp.id[port_idx][idx]), |
| 305 | port_idx, idx); |
| 306 | if (atomic_read(&this_adm.copp.id[port_idx][idx]) == |
| 307 | RESET_COPP_ID) |
| 308 | break; |
| 309 | } |
| 310 | return idx; |
| 311 | } |
| 312 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 313 | /** |
| 314 | * srs_trumedia_open - |
| 315 | * command to set SRS trumedia open |
| 316 | * |
| 317 | * @port_id: Port ID number |
| 318 | * @copp_idx: copp index of ADM copp |
| 319 | * @srs_tech_id: SRS tech index |
| 320 | * @srs_params: params pointer |
| 321 | * |
| 322 | * Returns 0 on success or error on failure |
| 323 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 324 | int srs_trumedia_open(int port_id, int copp_idx, __s32 srs_tech_id, |
| 325 | void *srs_params) |
| 326 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 327 | struct param_hdr_v3 param_hdr; |
| 328 | struct mem_mapping_hdr mem_hdr; |
| 329 | u32 total_param_size = 0; |
| 330 | bool outband = false; |
| 331 | int port_idx; |
| 332 | int ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 333 | |
| 334 | pr_debug("SRS - %s", __func__); |
| 335 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 336 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 337 | memset(&mem_hdr, 0, sizeof(mem_hdr)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 338 | port_id = afe_convert_virtual_to_portid(port_id); |
| 339 | port_idx = adm_validate_and_get_port_index(port_id); |
| 340 | if (port_idx < 0) { |
| 341 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 342 | return -EINVAL; |
| 343 | } |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 344 | |
| 345 | param_hdr.module_id = SRS_TRUMEDIA_MODULE_ID; |
| 346 | param_hdr.instance_id = INSTANCE_ID_0; |
| 347 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 348 | switch (srs_tech_id) { |
| 349 | case SRS_ID_GLOBAL: { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 350 | param_hdr.param_id = SRS_TRUMEDIA_PARAMS; |
| 351 | param_hdr.param_size = |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 352 | sizeof(struct srs_trumedia_params_GLOBAL); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 353 | break; |
| 354 | } |
| 355 | case SRS_ID_WOWHD: { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 356 | param_hdr.param_id = SRS_TRUMEDIA_PARAMS_WOWHD; |
| 357 | param_hdr.param_size = sizeof(struct srs_trumedia_params_WOWHD); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 358 | break; |
| 359 | } |
| 360 | case SRS_ID_CSHP: { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 361 | param_hdr.param_id = SRS_TRUMEDIA_PARAMS_CSHP; |
| 362 | param_hdr.param_size = sizeof(struct srs_trumedia_params_CSHP); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | case SRS_ID_HPF: { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 366 | param_hdr.param_id = SRS_TRUMEDIA_PARAMS_HPF; |
| 367 | param_hdr.param_size = sizeof(struct srs_trumedia_params_HPF); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 368 | break; |
| 369 | } |
| 370 | case SRS_ID_AEQ: { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 371 | u8 *update_params_ptr = (u8 *) this_adm.outband_memmap.kvaddr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 372 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 373 | outband = true; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 374 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 375 | if (update_params_ptr == NULL) { |
| 376 | pr_err("ADM_SRS_TRUMEDIA - %s: null memmap for AEQ params\n", |
| 377 | __func__); |
| 378 | ret = -EINVAL; |
| 379 | goto fail_cmd; |
| 380 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 381 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 382 | param_hdr.param_id = SRS_TRUMEDIA_PARAMS_AEQ; |
| 383 | param_hdr.param_size = sizeof(struct srs_trumedia_params_AEQ); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 384 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 385 | ret = q6common_pack_pp_params(update_params_ptr, ¶m_hdr, |
| 386 | srs_params, &total_param_size); |
| 387 | if (ret) { |
| 388 | pr_err("%s: Failed to pack param header and data, error %d\n", |
| 389 | __func__, ret); |
| 390 | goto fail_cmd; |
| 391 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 392 | break; |
| 393 | } |
| 394 | case SRS_ID_HL: { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 395 | param_hdr.param_id = SRS_TRUMEDIA_PARAMS_HL; |
| 396 | param_hdr.param_size = sizeof(struct srs_trumedia_params_HL); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 397 | break; |
| 398 | } |
| 399 | case SRS_ID_GEQ: { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 400 | param_hdr.param_id = SRS_TRUMEDIA_PARAMS_GEQ; |
| 401 | param_hdr.param_size = sizeof(struct srs_trumedia_params_GEQ); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 402 | break; |
| 403 | } |
| 404 | default: |
| 405 | goto fail_cmd; |
| 406 | } |
| 407 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 408 | if (outband && this_adm.outband_memmap.paddr) { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 409 | mem_hdr.data_payload_addr_lsw = |
| 410 | lower_32_bits(this_adm.outband_memmap.paddr); |
| 411 | mem_hdr.data_payload_addr_msw = |
| 412 | msm_audio_populate_upper_32_bits( |
| 413 | this_adm.outband_memmap.paddr); |
| 414 | mem_hdr.mem_map_handle = atomic_read( |
| 415 | &this_adm.mem_map_handles[ADM_SRS_TRUMEDIA]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 416 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 417 | ret = adm_set_pp_params(port_id, copp_idx, &mem_hdr, NULL, |
| 418 | total_param_size); |
| 419 | } else { |
| 420 | ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, |
| 421 | param_hdr, |
| 422 | (u8 *) srs_params); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 423 | } |
| 424 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 425 | if (ret < 0) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 426 | pr_err("SRS - %s: ADM enable for port %d failed\n", __func__, |
| 427 | port_id); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 428 | |
| 429 | fail_cmd: |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 430 | return ret; |
| 431 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 432 | EXPORT_SYMBOL(srs_trumedia_open); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 433 | |
| 434 | static int adm_populate_channel_weight(u16 *ptr, |
| 435 | struct msm_pcm_channel_mixer *ch_mixer, |
| 436 | int channel_index) |
| 437 | { |
| 438 | u16 i, j, start_index = 0; |
| 439 | |
| 440 | if (channel_index > ch_mixer->output_channel) { |
| 441 | pr_err("%s: channel index %d is larger than output_channel %d\n", |
| 442 | __func__, channel_index, ch_mixer->output_channel); |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | |
| 446 | for (i = 0; i < ch_mixer->output_channel; i++) { |
| 447 | pr_debug("%s: weight for output %d:", __func__, i); |
| 448 | for (j = 0; j < ADM_MAX_CHANNELS; j++) |
| 449 | pr_debug(" %d", |
| 450 | ch_mixer->channel_weight[i][j]); |
| 451 | pr_debug("\n"); |
| 452 | } |
| 453 | |
| 454 | for (i = 0; i < channel_index; ++i) |
| 455 | start_index += ch_mixer->input_channels[i]; |
| 456 | |
| 457 | for (i = 0; i < ch_mixer->output_channel; ++i) { |
| 458 | for (j = start_index; |
| 459 | j < start_index + |
| 460 | ch_mixer->input_channels[channel_index]; j++) { |
| 461 | *ptr = ch_mixer->channel_weight[i][j]; |
| 462 | pr_debug("%s: ptr[%d][%d] = %d\n", |
| 463 | __func__, i, j, *ptr); |
| 464 | ptr++; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * adm_programable_channel_mixer |
| 473 | * |
| 474 | * Receives port_id, copp_idx, session_id, session_type, ch_mixer |
| 475 | * and channel_index to send ADM command to mix COPP data. |
| 476 | * |
| 477 | * port_id - Passed value, port_id for which backend is wanted |
| 478 | * copp_idx - Passed value, copp_idx for which COPP is wanted |
| 479 | * session_id - Passed value, session_id for which session is needed |
| 480 | * session_type - Passed value, session_type for RX or TX |
| 481 | * ch_mixer - Passed value, ch_mixer for which channel mixer config is needed |
| 482 | * channel_index - Passed value, channel_index for which channel is needed |
| 483 | */ |
| 484 | int adm_programable_channel_mixer(int port_id, int copp_idx, int session_id, |
| 485 | int session_type, |
| 486 | struct msm_pcm_channel_mixer *ch_mixer, |
| 487 | int channel_index) |
| 488 | { |
| 489 | struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL; |
Vignesh Kulothungan | 2c6dccd | 2018-03-22 14:18:43 -0700 | [diff] [blame] | 490 | struct param_hdr_v1 data_v5; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 491 | int ret = 0, port_idx, sz = 0, param_size = 0; |
| 492 | u16 *adm_pspd_params; |
| 493 | u16 *ptr; |
| 494 | int index = 0; |
| 495 | |
| 496 | pr_debug("%s: port_id = %d\n", __func__, port_id); |
| 497 | port_id = afe_convert_virtual_to_portid(port_id); |
| 498 | port_idx = adm_validate_and_get_port_index(port_id); |
| 499 | if (port_idx < 0) { |
| 500 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 501 | return -EINVAL; |
| 502 | } |
| 503 | /* |
| 504 | * First 8 bytes are 4 bytes as rule number, 2 bytes as output |
| 505 | * channel and 2 bytes as input channel. |
| 506 | * 2 * ch_mixer->output_channel means output channel mapping. |
| 507 | * 2 * ch_mixer->input_channels[channel_index]) means input |
| 508 | * channel mapping. |
| 509 | * 2 * ch_mixer->input_channels[channel_index] * |
| 510 | * ch_mixer->output_channel) means the channel mixer weighting |
| 511 | * coefficients. |
| 512 | * param_size needs to be a multiple of 4 bytes. |
| 513 | */ |
| 514 | |
| 515 | param_size = 2 * (4 + ch_mixer->output_channel + |
| 516 | ch_mixer->input_channels[channel_index] + |
| 517 | ch_mixer->input_channels[channel_index] * |
| 518 | ch_mixer->output_channel); |
| 519 | roundup(param_size, 4); |
| 520 | |
| 521 | sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) + |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 522 | sizeof(struct default_chmixer_param_id_coeff) + |
Vignesh Kulothungan | 2c6dccd | 2018-03-22 14:18:43 -0700 | [diff] [blame] | 523 | sizeof(struct param_hdr_v1) + param_size; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 524 | pr_debug("%s: sz = %d\n", __func__, sz); |
| 525 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 526 | if (!adm_params) |
| 527 | return -ENOMEM; |
| 528 | |
| 529 | adm_params->payload_addr_lsw = 0; |
| 530 | adm_params->payload_addr_msw = 0; |
| 531 | adm_params->mem_map_handle = 0; |
| 532 | adm_params->direction = session_type; |
| 533 | adm_params->sessionid = session_id; |
| 534 | pr_debug("%s: copp_id = %d, session id %d\n", __func__, |
| 535 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]), |
| 536 | session_id); |
| 537 | adm_params->deviceid = atomic_read( |
| 538 | &this_adm.copp.id[port_idx][copp_idx]); |
| 539 | adm_params->reserved = 0; |
| 540 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 541 | /* |
| 542 | * This module is internal to ADSP and cannot be configured with |
| 543 | * an instance id |
| 544 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 545 | data_v5.module_id = MTMX_MODULE_ID_DEFAULT_CHMIXER; |
| 546 | data_v5.param_id = DEFAULT_CHMIXER_PARAM_ID_COEFF; |
| 547 | data_v5.reserved = 0; |
| 548 | data_v5.param_size = param_size; |
| 549 | adm_params->payload_size = |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 550 | sizeof(struct default_chmixer_param_id_coeff) + |
Vignesh Kulothungan | 2c6dccd | 2018-03-22 14:18:43 -0700 | [diff] [blame] | 551 | sizeof(struct param_hdr_v1) + data_v5.param_size; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 552 | adm_pspd_params = (u16 *)((u8 *)adm_params + |
| 553 | sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)); |
| 554 | memcpy(adm_pspd_params, &data_v5, sizeof(data_v5)); |
| 555 | |
| 556 | adm_pspd_params = (u16 *)((u8 *)adm_params + |
| 557 | sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) |
| 558 | + sizeof(data_v5)); |
| 559 | |
| 560 | adm_pspd_params[0] = ch_mixer->rule; |
| 561 | adm_pspd_params[2] = ch_mixer->output_channel; |
| 562 | adm_pspd_params[3] = ch_mixer->input_channels[channel_index]; |
| 563 | index = 4; |
| 564 | |
| 565 | if (ch_mixer->output_channel == 1) { |
| 566 | adm_pspd_params[index] = PCM_CHANNEL_FC; |
| 567 | } else if (ch_mixer->output_channel == 2) { |
| 568 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 569 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 570 | } else if (ch_mixer->output_channel == 3) { |
| 571 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 572 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 573 | adm_pspd_params[index + 2] = PCM_CHANNEL_FC; |
| 574 | } else if (ch_mixer->output_channel == 4) { |
| 575 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 576 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 577 | adm_pspd_params[index + 2] = PCM_CHANNEL_LS; |
| 578 | adm_pspd_params[index + 3] = PCM_CHANNEL_RS; |
| 579 | } else if (ch_mixer->output_channel == 5) { |
| 580 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 581 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 582 | adm_pspd_params[index + 2] = PCM_CHANNEL_FC; |
| 583 | adm_pspd_params[index + 3] = PCM_CHANNEL_LS; |
| 584 | adm_pspd_params[index + 4] = PCM_CHANNEL_RS; |
| 585 | } else if (ch_mixer->output_channel == 6) { |
| 586 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 587 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 588 | adm_pspd_params[index + 2] = PCM_CHANNEL_LFE; |
| 589 | adm_pspd_params[index + 3] = PCM_CHANNEL_FC; |
| 590 | adm_pspd_params[index + 4] = PCM_CHANNEL_LS; |
| 591 | adm_pspd_params[index + 5] = PCM_CHANNEL_RS; |
| 592 | } else if (ch_mixer->output_channel == 8) { |
| 593 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 594 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 595 | adm_pspd_params[index + 2] = PCM_CHANNEL_LFE; |
| 596 | adm_pspd_params[index + 3] = PCM_CHANNEL_FC; |
| 597 | adm_pspd_params[index + 4] = PCM_CHANNEL_LS; |
| 598 | adm_pspd_params[index + 5] = PCM_CHANNEL_RS; |
| 599 | adm_pspd_params[index + 6] = PCM_CHANNEL_LB; |
| 600 | adm_pspd_params[index + 7] = PCM_CHANNEL_RB; |
| 601 | } |
| 602 | |
| 603 | index = index + ch_mixer->output_channel; |
| 604 | if (ch_mixer->input_channels[channel_index] == 1) { |
| 605 | adm_pspd_params[index] = PCM_CHANNEL_FC; |
| 606 | } else if (ch_mixer->input_channels[channel_index] == 2) { |
| 607 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 608 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 609 | } else if (ch_mixer->input_channels[channel_index] == 3) { |
| 610 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 611 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 612 | adm_pspd_params[index + 2] = PCM_CHANNEL_FC; |
| 613 | } else if (ch_mixer->input_channels[channel_index] == 4) { |
| 614 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 615 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 616 | adm_pspd_params[index + 2] = PCM_CHANNEL_LS; |
| 617 | adm_pspd_params[index + 3] = PCM_CHANNEL_RS; |
| 618 | } else if (ch_mixer->input_channels[channel_index] == 5) { |
| 619 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 620 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 621 | adm_pspd_params[index + 2] = PCM_CHANNEL_FC; |
| 622 | adm_pspd_params[index + 3] = PCM_CHANNEL_LS; |
| 623 | adm_pspd_params[index + 4] = PCM_CHANNEL_RS; |
| 624 | } else if (ch_mixer->input_channels[channel_index] == 6) { |
| 625 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 626 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 627 | adm_pspd_params[index + 2] = PCM_CHANNEL_LFE; |
| 628 | adm_pspd_params[index + 3] = PCM_CHANNEL_FC; |
| 629 | adm_pspd_params[index + 4] = PCM_CHANNEL_LS; |
| 630 | adm_pspd_params[index + 5] = PCM_CHANNEL_RS; |
| 631 | } else if (ch_mixer->input_channels[channel_index] == 8) { |
| 632 | adm_pspd_params[index] = PCM_CHANNEL_FL; |
| 633 | adm_pspd_params[index + 1] = PCM_CHANNEL_FR; |
| 634 | adm_pspd_params[index + 2] = PCM_CHANNEL_LFE; |
| 635 | adm_pspd_params[index + 3] = PCM_CHANNEL_FC; |
| 636 | adm_pspd_params[index + 4] = PCM_CHANNEL_LS; |
| 637 | adm_pspd_params[index + 5] = PCM_CHANNEL_RS; |
| 638 | adm_pspd_params[index + 6] = PCM_CHANNEL_LB; |
| 639 | adm_pspd_params[index + 7] = PCM_CHANNEL_RB; |
| 640 | } |
| 641 | |
| 642 | index = index + ch_mixer->input_channels[channel_index]; |
| 643 | ret = adm_populate_channel_weight(&adm_pspd_params[index], |
| 644 | ch_mixer, channel_index); |
Meng Wang | d9fa69c | 2018-01-23 12:42:52 +0800 | [diff] [blame] | 645 | if (ret) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 646 | pr_err("%s: fail to get channel weight with error %d\n", |
| 647 | __func__, ret); |
| 648 | goto fail_cmd; |
| 649 | } |
| 650 | |
| 651 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 652 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 653 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 654 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 655 | adm_params->hdr.src_port = port_id; |
| 656 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 657 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 658 | adm_params->hdr.dest_port = |
| 659 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 660 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 661 | adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5; |
| 662 | adm_params->hdr.pkt_size = sz; |
| 663 | adm_params->payload_addr_lsw = 0; |
| 664 | adm_params->payload_addr_msw = 0; |
| 665 | adm_params->mem_map_handle = 0; |
| 666 | adm_params->reserved = 0; |
| 667 | |
| 668 | ptr = (u16 *)adm_params; |
| 669 | for (index = 0; index < (sz / 2); index++) |
| 670 | pr_debug("%s: adm_params[%d] = 0x%x\n", |
| 671 | __func__, index, (unsigned int)ptr[index]); |
| 672 | |
| 673 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], 0); |
| 674 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 675 | if (ret < 0) { |
| 676 | pr_err("%s: Set params failed port %d rc %d\n", __func__, |
| 677 | port_id, ret); |
| 678 | ret = -EINVAL; |
| 679 | goto fail_cmd; |
| 680 | } |
| 681 | |
| 682 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 683 | atomic_read( |
| 684 | &this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 685 | msecs_to_jiffies(TIMEOUT_MS)); |
| 686 | if (!ret) { |
| 687 | pr_err("%s: set params timed out port = %d\n", |
| 688 | __func__, port_id); |
| 689 | ret = -ETIMEDOUT; |
| 690 | goto fail_cmd; |
| 691 | } |
| 692 | ret = 0; |
| 693 | fail_cmd: |
| 694 | kfree(adm_params); |
| 695 | |
| 696 | return ret; |
| 697 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 698 | EXPORT_SYMBOL(adm_programable_channel_mixer); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 699 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 700 | /** |
| 701 | * adm_set_stereo_to_custom_stereo - |
| 702 | * command to update custom stereo |
| 703 | * |
| 704 | * @port_id: Port ID number |
| 705 | * @copp_idx: copp index of ADM copp |
| 706 | * @session_id: session id to be updated |
| 707 | * @params: params pointer |
| 708 | * @param_length: length of params |
| 709 | * |
| 710 | * Returns 0 on success or error on failure |
| 711 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 712 | int adm_set_stereo_to_custom_stereo(int port_id, int copp_idx, |
| 713 | unsigned int session_id, char *params, |
| 714 | uint32_t params_length) |
| 715 | { |
| 716 | struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL; |
| 717 | int sz, rc = 0, port_idx; |
| 718 | |
| 719 | pr_debug("%s:\n", __func__); |
| 720 | port_id = afe_convert_virtual_to_portid(port_id); |
| 721 | port_idx = adm_validate_and_get_port_index(port_id); |
| 722 | if (port_idx < 0) { |
| 723 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 724 | return -EINVAL; |
| 725 | } |
| 726 | |
| 727 | sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) + |
| 728 | params_length; |
| 729 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 730 | if (!adm_params) { |
| 731 | pr_err("%s, adm params memory alloc failed\n", __func__); |
| 732 | return -ENOMEM; |
| 733 | } |
| 734 | |
| 735 | memcpy(((u8 *)adm_params + |
| 736 | sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)), |
| 737 | params, params_length); |
| 738 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 739 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 740 | adm_params->hdr.pkt_size = sz; |
| 741 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 742 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 743 | adm_params->hdr.src_port = port_id; |
| 744 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 745 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 746 | adm_params->hdr.dest_port = 0; /* Ignored */; |
| 747 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 748 | adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5; |
| 749 | adm_params->payload_addr_lsw = 0; |
| 750 | adm_params->payload_addr_msw = 0; |
| 751 | adm_params->mem_map_handle = 0; |
| 752 | adm_params->payload_size = params_length; |
| 753 | /* direction RX as 0 */ |
| 754 | adm_params->direction = ADM_MATRIX_ID_AUDIO_RX; |
| 755 | /* session id for this cmd to be applied on */ |
| 756 | adm_params->sessionid = session_id; |
| 757 | adm_params->deviceid = |
| 758 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 759 | adm_params->reserved = 0; |
| 760 | pr_debug("%s: deviceid %d, session_id %d, src_port %d, dest_port %d\n", |
| 761 | __func__, adm_params->deviceid, adm_params->sessionid, |
| 762 | adm_params->hdr.src_port, adm_params->hdr.dest_port); |
| 763 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 764 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 765 | if (rc < 0) { |
| 766 | pr_err("%s: Set params failed port = 0x%x rc %d\n", |
| 767 | __func__, port_id, rc); |
| 768 | rc = -EINVAL; |
| 769 | goto set_stereo_to_custom_stereo_return; |
| 770 | } |
| 771 | /* Wait for the callback */ |
| 772 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 773 | atomic_read(&this_adm.copp.stat |
| 774 | [port_idx][copp_idx]) >= 0, |
| 775 | msecs_to_jiffies(TIMEOUT_MS)); |
| 776 | if (!rc) { |
| 777 | pr_err("%s: Set params timed out port = 0x%x\n", __func__, |
| 778 | port_id); |
| 779 | rc = -EINVAL; |
| 780 | goto set_stereo_to_custom_stereo_return; |
| 781 | } else if (atomic_read(&this_adm.copp.stat |
| 782 | [port_idx][copp_idx]) > 0) { |
| 783 | pr_err("%s: DSP returned error[%s]\n", __func__, |
| 784 | adsp_err_get_err_str(atomic_read( |
| 785 | &this_adm.copp.stat |
| 786 | [port_idx][copp_idx]))); |
| 787 | rc = adsp_err_get_lnx_err_code( |
| 788 | atomic_read(&this_adm.copp.stat |
| 789 | [port_idx][copp_idx])); |
| 790 | goto set_stereo_to_custom_stereo_return; |
| 791 | } |
| 792 | rc = 0; |
| 793 | set_stereo_to_custom_stereo_return: |
| 794 | kfree(adm_params); |
| 795 | return rc; |
| 796 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 797 | EXPORT_SYMBOL(adm_set_stereo_to_custom_stereo); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 798 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 799 | /* |
Bhalchandra Gajare | eed46bd | 2018-05-15 16:48:07 -0700 | [diff] [blame] | 800 | * adm_set_custom_chmix_cfg: |
| 801 | * Set the custom channel mixer configuration for ADM |
| 802 | * |
| 803 | * @port_id: Backend port id |
| 804 | * @copp_idx: ADM copp index |
| 805 | * @session_id: ID of the requesting session |
| 806 | * @params: Expected packaged params for channel mixer |
| 807 | * @params_length: Length of the params to be set |
| 808 | * @direction: RX or TX direction |
| 809 | * @stream_type: Audio or Listen stream type |
| 810 | */ |
| 811 | int adm_set_custom_chmix_cfg(int port_id, int copp_idx, |
| 812 | unsigned int session_id, char *params, |
| 813 | uint32_t params_length, int direction, |
| 814 | int stream_type) |
| 815 | { |
| 816 | struct adm_cmd_set_pspd_mtmx_strtr_params_v6 *adm_params = NULL; |
| 817 | int sz, rc = 0, port_idx; |
| 818 | |
| 819 | port_id = afe_convert_virtual_to_portid(port_id); |
| 820 | port_idx = adm_validate_and_get_port_index(port_id); |
| 821 | if (port_idx < 0) { |
| 822 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 823 | return -EINVAL; |
| 824 | } |
| 825 | |
| 826 | sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v6) + |
| 827 | params_length; |
| 828 | adm_params = kzalloc(sz, GFP_KERNEL); |
| 829 | if (!adm_params) { |
| 830 | pr_err("%s, adm params memory alloc failed\n", __func__); |
| 831 | return -ENOMEM; |
| 832 | } |
| 833 | |
| 834 | memcpy(((u8 *)adm_params + |
| 835 | sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v6)), |
| 836 | params, params_length); |
| 837 | adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 838 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 839 | adm_params->hdr.pkt_size = sz; |
| 840 | adm_params->hdr.src_svc = APR_SVC_ADM; |
| 841 | adm_params->hdr.src_domain = APR_DOMAIN_APPS; |
| 842 | adm_params->hdr.src_port = port_id; |
| 843 | adm_params->hdr.dest_svc = APR_SVC_ADM; |
| 844 | adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 845 | adm_params->hdr.dest_port = 0; /* Ignored */; |
| 846 | adm_params->hdr.token = port_idx << 16 | copp_idx; |
| 847 | adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V6; |
| 848 | adm_params->payload_addr_lsw = 0; |
| 849 | adm_params->payload_addr_msw = 0; |
| 850 | adm_params->mem_map_handle = 0; |
| 851 | adm_params->payload_size = params_length; |
| 852 | adm_params->direction = direction; |
| 853 | /* session id for this cmd to be applied on */ |
| 854 | adm_params->sessionid = session_id; |
| 855 | adm_params->deviceid = |
| 856 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 857 | /* connecting stream type i.e. lsm or asm */ |
| 858 | adm_params->stream_type = stream_type; |
| 859 | pr_debug("%s: deviceid %d, session_id %d, src_port %d, dest_port %d\n", |
| 860 | __func__, adm_params->deviceid, adm_params->sessionid, |
| 861 | adm_params->hdr.src_port, adm_params->hdr.dest_port); |
| 862 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 863 | rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); |
| 864 | if (rc < 0) { |
| 865 | pr_err("%s: Set params failed port = 0x%x rc %d\n", |
| 866 | __func__, port_id, rc); |
| 867 | rc = -EINVAL; |
| 868 | goto exit; |
| 869 | } |
| 870 | /* Wait for the callback */ |
| 871 | rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 872 | atomic_read(&this_adm.copp.stat |
| 873 | [port_idx][copp_idx]), |
| 874 | msecs_to_jiffies(TIMEOUT_MS)); |
| 875 | if (!rc) { |
| 876 | pr_err("%s: Set params timed out port = 0x%x\n", __func__, |
| 877 | port_id); |
| 878 | rc = -EINVAL; |
| 879 | goto exit; |
| 880 | } else if (atomic_read(&this_adm.copp.stat |
| 881 | [port_idx][copp_idx]) > 0) { |
| 882 | pr_err("%s: DSP returned error[%s]\n", __func__, |
| 883 | adsp_err_get_err_str(atomic_read( |
| 884 | &this_adm.copp.stat |
| 885 | [port_idx][copp_idx]))); |
| 886 | rc = adsp_err_get_lnx_err_code( |
| 887 | atomic_read(&this_adm.copp.stat |
| 888 | [port_idx][copp_idx])); |
| 889 | goto exit; |
| 890 | } |
| 891 | |
| 892 | rc = 0; |
| 893 | exit: |
| 894 | kfree(adm_params); |
| 895 | return rc; |
| 896 | } |
| 897 | EXPORT_SYMBOL(adm_set_custom_chmix_cfg); |
| 898 | |
| 899 | /* |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 900 | * With pre-packed data, only the opcode differes from V5 and V6. |
| 901 | * Use q6common_pack_pp_params to pack the data correctly. |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 902 | */ |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 903 | int adm_set_pp_params(int port_id, int copp_idx, |
| 904 | struct mem_mapping_hdr *mem_hdr, u8 *param_data, |
| 905 | u32 param_size) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 906 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 907 | struct adm_cmd_set_pp_params *adm_set_params = NULL; |
| 908 | int size = 0; |
| 909 | int port_idx = 0; |
| 910 | atomic_t *copp_stat = NULL; |
| 911 | int ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 912 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 913 | port_id = afe_convert_virtual_to_portid(port_id); |
| 914 | port_idx = adm_validate_and_get_port_index(port_id); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 915 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 916 | pr_err("%s: Invalid port_idx 0x%x\n", __func__, port_idx); |
| 917 | return -EINVAL; |
| 918 | } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 919 | pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 920 | return -EINVAL; |
| 921 | } |
| 922 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 923 | /* Only add params_size in inband case */ |
| 924 | size = sizeof(struct adm_cmd_set_pp_params); |
| 925 | if (param_data != NULL) |
| 926 | size += param_size; |
| 927 | adm_set_params = kzalloc(size, GFP_KERNEL); |
| 928 | if (!adm_set_params) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 929 | return -ENOMEM; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 930 | |
| 931 | adm_set_params->apr_hdr.hdr_field = |
| 932 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), |
| 933 | APR_PKT_VER); |
| 934 | adm_set_params->apr_hdr.pkt_size = size; |
| 935 | adm_set_params->apr_hdr.src_svc = APR_SVC_ADM; |
| 936 | adm_set_params->apr_hdr.src_domain = APR_DOMAIN_APPS; |
| 937 | adm_set_params->apr_hdr.src_port = port_id; |
| 938 | adm_set_params->apr_hdr.dest_svc = APR_SVC_ADM; |
| 939 | adm_set_params->apr_hdr.dest_domain = APR_DOMAIN_ADSP; |
| 940 | adm_set_params->apr_hdr.dest_port = |
| 941 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 942 | adm_set_params->apr_hdr.token = port_idx << 16 | copp_idx; |
| 943 | |
| 944 | if (q6common_is_instance_id_supported()) |
| 945 | adm_set_params->apr_hdr.opcode = ADM_CMD_SET_PP_PARAMS_V6; |
| 946 | else |
| 947 | adm_set_params->apr_hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; |
| 948 | |
| 949 | adm_set_params->payload_size = param_size; |
| 950 | |
| 951 | if (mem_hdr != NULL) { |
| 952 | /* Out of Band Case */ |
| 953 | adm_set_params->mem_hdr = *mem_hdr; |
| 954 | } else if (param_data != NULL) { |
| 955 | /* |
| 956 | * In band case. Parameter data must be pre-packed with its |
| 957 | * header before calling this function. Use |
| 958 | * q6common_pack_pp_params to pack parameter data and header |
| 959 | * correctly. |
| 960 | */ |
| 961 | memcpy(&adm_set_params->param_data, param_data, param_size); |
| 962 | } else { |
| 963 | pr_err("%s: Received NULL pointers for both memory header and param data\n", |
| 964 | __func__); |
| 965 | ret = -EINVAL; |
| 966 | goto done; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 967 | } |
| 968 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 969 | copp_stat = &this_adm.copp.stat[port_idx][copp_idx]; |
| 970 | atomic_set(copp_stat, -1); |
| 971 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) adm_set_params); |
| 972 | if (ret < 0) { |
| 973 | pr_err("%s: Set params APR send failed port = 0x%x ret %d\n", |
| 974 | __func__, port_id, ret); |
| 975 | goto done; |
| 976 | } |
| 977 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 978 | atomic_read(copp_stat) >= 0, |
| 979 | msecs_to_jiffies(TIMEOUT_MS)); |
| 980 | if (!ret) { |
| 981 | pr_err("%s: Set params timed out port = 0x%x\n", __func__, |
| 982 | port_id); |
| 983 | ret = -ETIMEDOUT; |
| 984 | goto done; |
| 985 | } |
| 986 | if (atomic_read(copp_stat) > 0) { |
| 987 | pr_err("%s: DSP returned error[%s]\n", __func__, |
| 988 | adsp_err_get_err_str(atomic_read(copp_stat))); |
| 989 | ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat)); |
| 990 | goto done; |
| 991 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 992 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 993 | ret = 0; |
| 994 | done: |
| 995 | kfree(adm_set_params); |
| 996 | return ret; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 997 | } |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 998 | EXPORT_SYMBOL(adm_set_pp_params); |
| 999 | |
| 1000 | int adm_pack_and_set_one_pp_param(int port_id, int copp_idx, |
| 1001 | struct param_hdr_v3 param_hdr, u8 *param_data) |
| 1002 | { |
| 1003 | u8 *packed_data = NULL; |
| 1004 | u32 total_size = 0; |
| 1005 | int ret = 0; |
| 1006 | |
| 1007 | total_size = sizeof(union param_hdrs) + param_hdr.param_size; |
| 1008 | packed_data = kzalloc(total_size, GFP_KERNEL); |
| 1009 | if (!packed_data) |
| 1010 | return -ENOMEM; |
| 1011 | |
| 1012 | ret = q6common_pack_pp_params(packed_data, ¶m_hdr, param_data, |
| 1013 | &total_size); |
| 1014 | if (ret) { |
| 1015 | pr_err("%s: Failed to pack parameter data, error %d\n", |
| 1016 | __func__, ret); |
| 1017 | goto done; |
| 1018 | } |
| 1019 | |
| 1020 | ret = adm_set_pp_params(port_id, copp_idx, NULL, packed_data, |
| 1021 | total_size); |
| 1022 | if (ret) |
| 1023 | pr_err("%s: Failed to set parameter data, error %d\n", __func__, |
| 1024 | ret); |
| 1025 | done: |
| 1026 | kfree(packed_data); |
| 1027 | return ret; |
| 1028 | } |
| 1029 | EXPORT_SYMBOL(adm_pack_and_set_one_pp_param); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1030 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1031 | /* |
| 1032 | * Only one parameter can be requested at a time. Therefore, packing and sending |
| 1033 | * the request can be handled locally. |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 1034 | */ |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1035 | int adm_get_pp_params(int port_id, int copp_idx, uint32_t client_id, |
| 1036 | struct mem_mapping_hdr *mem_hdr, |
| 1037 | struct param_hdr_v3 *param_hdr, u8 *returned_param_data) |
| 1038 | { |
| 1039 | struct adm_cmd_get_pp_params adm_get_params; |
| 1040 | int total_size = 0; |
| 1041 | int get_param_array_sz = ARRAY_SIZE(adm_get_parameters); |
| 1042 | int returned_param_size = 0; |
| 1043 | int returned_param_size_in_bytes = 0; |
| 1044 | int port_idx = 0; |
| 1045 | int idx = 0; |
| 1046 | atomic_t *copp_stat = NULL; |
| 1047 | int ret = 0; |
| 1048 | |
| 1049 | if (param_hdr == NULL) { |
| 1050 | pr_err("%s: Received NULL pointer for parameter header\n", |
| 1051 | __func__); |
| 1052 | return -EINVAL; |
| 1053 | } |
| 1054 | |
| 1055 | port_id = afe_convert_virtual_to_portid(port_id); |
| 1056 | port_idx = adm_validate_and_get_port_index(port_id); |
| 1057 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 1058 | pr_err("%s: Invalid port_idx 0x%x\n", __func__, port_idx); |
| 1059 | return -EINVAL; |
| 1060 | } |
| 1061 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 1062 | pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); |
| 1063 | return -EINVAL; |
| 1064 | } |
| 1065 | |
| 1066 | memset(&adm_get_params, 0, sizeof(adm_get_params)); |
| 1067 | |
| 1068 | if (mem_hdr != NULL) |
| 1069 | adm_get_params.mem_hdr = *mem_hdr; |
| 1070 | |
| 1071 | q6common_pack_pp_params((u8 *) &adm_get_params.param_hdr, param_hdr, |
| 1072 | NULL, &total_size); |
| 1073 | |
| 1074 | /* Pack APR header after filling body so total_size has correct value */ |
Vignesh Kulothungan | aadecdf | 2018-06-20 15:08:24 -0700 | [diff] [blame] | 1075 | adm_get_params.apr_hdr.hdr_field = |
| 1076 | APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), |
| 1077 | APR_PKT_VER); |
| 1078 | adm_get_params.apr_hdr.pkt_size = sizeof(adm_get_params); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1079 | adm_get_params.apr_hdr.src_svc = APR_SVC_ADM; |
| 1080 | adm_get_params.apr_hdr.src_domain = APR_DOMAIN_APPS; |
| 1081 | adm_get_params.apr_hdr.src_port = port_id; |
| 1082 | adm_get_params.apr_hdr.dest_svc = APR_SVC_ADM; |
| 1083 | adm_get_params.apr_hdr.dest_domain = APR_DOMAIN_ADSP; |
| 1084 | adm_get_params.apr_hdr.dest_port = |
| 1085 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 1086 | adm_get_params.apr_hdr.token = |
| 1087 | port_idx << 16 | client_id << 8 | copp_idx; |
| 1088 | |
| 1089 | if (q6common_is_instance_id_supported()) |
| 1090 | adm_get_params.apr_hdr.opcode = ADM_CMD_GET_PP_PARAMS_V6; |
| 1091 | else |
| 1092 | adm_get_params.apr_hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5; |
| 1093 | |
| 1094 | copp_stat = &this_adm.copp.stat[port_idx][copp_idx]; |
| 1095 | atomic_set(copp_stat, -1); |
Vignesh Kulothungan | aadecdf | 2018-06-20 15:08:24 -0700 | [diff] [blame] | 1096 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1097 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) &adm_get_params); |
Vidyakumar Athota | e427c41 | 2018-06-16 00:02:46 -0700 | [diff] [blame] | 1098 | if (ret < 0) { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1099 | pr_err("%s: Get params APR send failed port = 0x%x ret %d\n", |
| 1100 | __func__, port_id, ret); |
| 1101 | ret = -EINVAL; |
| 1102 | goto done; |
| 1103 | } |
| 1104 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 1105 | atomic_read(copp_stat) >= 0, |
| 1106 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1107 | if (!ret) { |
| 1108 | pr_err("%s: Get params timed out port = 0x%x\n", __func__, |
| 1109 | port_id); |
| 1110 | ret = -ETIMEDOUT; |
| 1111 | goto done; |
| 1112 | } |
| 1113 | if (atomic_read(copp_stat) > 0) { |
| 1114 | pr_err("%s: DSP returned error[%s]\n", __func__, |
| 1115 | adsp_err_get_err_str(atomic_read(copp_stat))); |
| 1116 | ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat)); |
| 1117 | goto done; |
| 1118 | } |
| 1119 | |
| 1120 | ret = 0; |
| 1121 | |
| 1122 | /* Copy data to caller if sent in band */ |
| 1123 | if (!returned_param_data) { |
| 1124 | pr_debug("%s: Received NULL pointer for param destination, not copying payload\n", |
| 1125 | __func__); |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | idx = ADM_GET_PARAMETER_LENGTH * copp_idx; |
| 1130 | returned_param_size = adm_get_parameters[idx]; |
| 1131 | if (returned_param_size < 0 || |
| 1132 | returned_param_size + idx + 1 > get_param_array_sz) { |
| 1133 | pr_err("%s: Invalid parameter size %d\n", __func__, |
| 1134 | returned_param_size); |
| 1135 | return -EINVAL; |
| 1136 | } |
| 1137 | |
| 1138 | returned_param_size_in_bytes = returned_param_size * sizeof(uint32_t); |
| 1139 | if (param_hdr->param_size < returned_param_size_in_bytes) { |
| 1140 | pr_err("%s: Provided buffer is not big enough, provided buffer size(%d) size needed(%d)\n", |
| 1141 | __func__, param_hdr->param_size, |
| 1142 | returned_param_size_in_bytes); |
| 1143 | return -EINVAL; |
| 1144 | } |
| 1145 | |
| 1146 | memcpy(returned_param_data, &adm_get_parameters[idx + 1], |
| 1147 | returned_param_size_in_bytes); |
| 1148 | done: |
| 1149 | return ret; |
| 1150 | } |
| 1151 | EXPORT_SYMBOL(adm_get_pp_params); |
| 1152 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1153 | int adm_get_pp_topo_module_list_v2(int port_id, int copp_idx, |
| 1154 | int32_t param_length, |
| 1155 | int32_t *returned_params) |
| 1156 | { |
| 1157 | struct adm_cmd_get_pp_topo_module_list adm_get_module_list; |
| 1158 | bool iid_supported = q6common_is_instance_id_supported(); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1159 | int *topo_list; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1160 | int num_modules = 0; |
| 1161 | int list_size = 0; |
| 1162 | int port_idx, idx; |
| 1163 | int i = 0; |
| 1164 | atomic_t *copp_stat = NULL; |
| 1165 | int ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1166 | |
| 1167 | pr_debug("%s : port_id %x", __func__, port_id); |
| 1168 | port_id = afe_convert_virtual_to_portid(port_id); |
| 1169 | port_idx = adm_validate_and_get_port_index(port_id); |
| 1170 | if (port_idx < 0) { |
| 1171 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 1172 | return -EINVAL; |
| 1173 | } |
| 1174 | |
| 1175 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 1176 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 1177 | return -EINVAL; |
| 1178 | } |
| 1179 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1180 | memset(&adm_get_module_list, 0, sizeof(adm_get_module_list)); |
| 1181 | |
| 1182 | adm_get_module_list.apr_hdr.pkt_size = sizeof(adm_get_module_list); |
| 1183 | adm_get_module_list.apr_hdr.src_svc = APR_SVC_ADM; |
| 1184 | adm_get_module_list.apr_hdr.src_domain = APR_DOMAIN_APPS; |
| 1185 | adm_get_module_list.apr_hdr.src_port = port_id; |
| 1186 | adm_get_module_list.apr_hdr.dest_svc = APR_SVC_ADM; |
| 1187 | adm_get_module_list.apr_hdr.dest_domain = APR_DOMAIN_ADSP; |
| 1188 | adm_get_module_list.apr_hdr.dest_port = |
| 1189 | atomic_read(&this_adm.copp.id[port_idx][copp_idx]); |
| 1190 | adm_get_module_list.apr_hdr.token = port_idx << 16 | copp_idx; |
| 1191 | /* |
| 1192 | * Out of band functionality is not currently utilized. |
| 1193 | * Assume in band. |
| 1194 | */ |
| 1195 | if (iid_supported) { |
| 1196 | adm_get_module_list.apr_hdr.opcode = |
| 1197 | ADM_CMD_GET_PP_TOPO_MODULE_LIST_V2; |
| 1198 | adm_get_module_list.param_max_size = param_length; |
| 1199 | } else { |
| 1200 | adm_get_module_list.apr_hdr.opcode = |
| 1201 | ADM_CMD_GET_PP_TOPO_MODULE_LIST; |
| 1202 | |
| 1203 | if (param_length > U16_MAX) { |
| 1204 | pr_err("%s: Invalid param length for V1 %d\n", __func__, |
| 1205 | param_length); |
| 1206 | return -EINVAL; |
| 1207 | } |
| 1208 | adm_get_module_list.param_max_size = param_length << 16; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1209 | } |
| 1210 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1211 | copp_stat = &this_adm.copp.stat[port_idx][copp_idx]; |
| 1212 | atomic_set(copp_stat, -1); |
| 1213 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) &adm_get_module_list); |
Vidyakumar Athota | e427c41 | 2018-06-16 00:02:46 -0700 | [diff] [blame] | 1214 | if (ret < 0) { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1215 | pr_err("%s: APR send pkt failed for port_id: 0x%x failed ret %d\n", |
| 1216 | __func__, port_id, ret); |
| 1217 | ret = -EINVAL; |
| 1218 | goto done; |
| 1219 | } |
| 1220 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 1221 | atomic_read(copp_stat) >= 0, |
| 1222 | msecs_to_jiffies(TIMEOUT_MS)); |
| 1223 | if (!ret) { |
| 1224 | pr_err("%s: Timeout for port_id: 0x%x\n", __func__, port_id); |
| 1225 | ret = -ETIMEDOUT; |
| 1226 | goto done; |
| 1227 | } |
| 1228 | if (atomic_read(copp_stat) > 0) { |
| 1229 | pr_err("%s: DSP returned error[%s]\n", __func__, |
| 1230 | adsp_err_get_err_str(atomic_read(copp_stat))); |
| 1231 | ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat)); |
| 1232 | goto done; |
| 1233 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1234 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1235 | ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1236 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1237 | if (returned_params) { |
| 1238 | /* |
| 1239 | * When processing ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST IID is |
| 1240 | * added since it is not present. Therefore, there is no need to |
| 1241 | * do anything different if IID is not supported here as it is |
| 1242 | * already taken care of. |
| 1243 | */ |
| 1244 | idx = ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH * copp_idx; |
| 1245 | num_modules = adm_module_topo_list[idx]; |
| 1246 | if (num_modules < 0 || num_modules > MAX_MODULES_IN_TOPO) { |
| 1247 | pr_err("%s: Invalid number of modules returned %d\n", |
| 1248 | __func__, num_modules); |
| 1249 | return -EINVAL; |
| 1250 | } |
| 1251 | |
| 1252 | list_size = num_modules * sizeof(struct module_instance_info); |
| 1253 | if (param_length < list_size) { |
| 1254 | pr_err("%s: Provided buffer not big enough to hold module-instance list, provided size %d, needed size %d\n", |
| 1255 | __func__, param_length, list_size); |
| 1256 | return -EINVAL; |
| 1257 | } |
| 1258 | |
| 1259 | topo_list = (int32_t *) (&adm_module_topo_list[idx]); |
| 1260 | memcpy(returned_params, topo_list, list_size); |
| 1261 | for (i = 1; i <= num_modules; i += 2) { |
| 1262 | pr_debug("module = 0x%x instance = 0x%x\n", |
| 1263 | returned_params[i], returned_params[i + 1]); |
| 1264 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1265 | } |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1266 | done: |
| 1267 | return ret; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1268 | } |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1269 | EXPORT_SYMBOL(adm_get_pp_topo_module_list_v2); |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 1270 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1271 | static void adm_callback_debug_print(struct apr_client_data *data) |
| 1272 | { |
| 1273 | uint32_t *payload; |
| 1274 | |
| 1275 | payload = data->payload; |
| 1276 | |
| 1277 | if (data->payload_size >= 8) |
| 1278 | pr_debug("%s: code = 0x%x PL#0[0x%x], PL#1[0x%x], size = %d\n", |
| 1279 | __func__, data->opcode, payload[0], payload[1], |
| 1280 | data->payload_size); |
| 1281 | else if (data->payload_size >= 4) |
| 1282 | pr_debug("%s: code = 0x%x PL#0[0x%x], size = %d\n", |
| 1283 | __func__, data->opcode, payload[0], |
| 1284 | data->payload_size); |
| 1285 | else |
| 1286 | pr_debug("%s: code = 0x%x, size = %d\n", |
| 1287 | __func__, data->opcode, data->payload_size); |
| 1288 | } |
| 1289 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 1290 | /** |
| 1291 | * adm_set_multi_ch_map - |
| 1292 | * Update multi channel map info |
| 1293 | * |
| 1294 | * @channel_map: pointer with channel map info |
| 1295 | * @path: direction or ADM path type |
| 1296 | * |
| 1297 | * Returns 0 on success or error on failure |
| 1298 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1299 | int adm_set_multi_ch_map(char *channel_map, int path) |
| 1300 | { |
| 1301 | int idx; |
| 1302 | |
| 1303 | if (path == ADM_PATH_PLAYBACK) { |
| 1304 | idx = ADM_MCH_MAP_IDX_PLAYBACK; |
| 1305 | } else if (path == ADM_PATH_LIVE_REC) { |
| 1306 | idx = ADM_MCH_MAP_IDX_REC; |
| 1307 | } else { |
| 1308 | pr_err("%s: invalid attempt to set path %d\n", __func__, path); |
| 1309 | return -EINVAL; |
| 1310 | } |
| 1311 | |
| 1312 | memcpy(multi_ch_maps[idx].channel_mapping, channel_map, |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 1313 | PCM_FORMAT_MAX_NUM_CHANNEL_V8); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1314 | multi_ch_maps[idx].set_channel_map = true; |
| 1315 | |
| 1316 | return 0; |
| 1317 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 1318 | EXPORT_SYMBOL(adm_set_multi_ch_map); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1319 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 1320 | /** |
| 1321 | * adm_get_multi_ch_map - |
| 1322 | * Retrieves multi channel map info |
| 1323 | * |
| 1324 | * @channel_map: pointer to be updated with channel map |
| 1325 | * @path: direction or ADM path type |
| 1326 | * |
| 1327 | * Returns 0 on success or error on failure |
| 1328 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1329 | int adm_get_multi_ch_map(char *channel_map, int path) |
| 1330 | { |
| 1331 | int idx; |
| 1332 | |
| 1333 | if (path == ADM_PATH_PLAYBACK) { |
| 1334 | idx = ADM_MCH_MAP_IDX_PLAYBACK; |
| 1335 | } else if (path == ADM_PATH_LIVE_REC) { |
| 1336 | idx = ADM_MCH_MAP_IDX_REC; |
| 1337 | } else { |
| 1338 | pr_err("%s: invalid attempt to get path %d\n", __func__, path); |
| 1339 | return -EINVAL; |
| 1340 | } |
| 1341 | |
| 1342 | if (multi_ch_maps[idx].set_channel_map) { |
| 1343 | memcpy(channel_map, multi_ch_maps[idx].channel_mapping, |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 1344 | PCM_FORMAT_MAX_NUM_CHANNEL_V8); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | return 0; |
| 1348 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 1349 | EXPORT_SYMBOL(adm_get_multi_ch_map); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1350 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1351 | static int adm_process_get_param_response(u32 opcode, u32 idx, u32 *payload, |
| 1352 | u32 payload_size) |
| 1353 | { |
| 1354 | struct adm_cmd_rsp_get_pp_params_v5 *v5_rsp = NULL; |
| 1355 | struct adm_cmd_rsp_get_pp_params_v6 *v6_rsp = NULL; |
| 1356 | u32 *param_data = NULL; |
| 1357 | int data_size = 0; |
| 1358 | int struct_size = 0; |
| 1359 | |
| 1360 | if (payload == NULL) { |
| 1361 | pr_err("%s: Payload is NULL\n", __func__); |
| 1362 | return -EINVAL; |
| 1363 | } |
| 1364 | |
| 1365 | switch (opcode) { |
| 1366 | case ADM_CMDRSP_GET_PP_PARAMS_V5: |
| 1367 | struct_size = sizeof(struct adm_cmd_rsp_get_pp_params_v5); |
| 1368 | v5_rsp = (struct adm_cmd_rsp_get_pp_params_v5 *) payload; |
| 1369 | data_size = v5_rsp->param_hdr.param_size; |
| 1370 | param_data = v5_rsp->param_data; |
| 1371 | break; |
| 1372 | case ADM_CMDRSP_GET_PP_PARAMS_V6: |
| 1373 | struct_size = sizeof(struct adm_cmd_rsp_get_pp_params_v6); |
| 1374 | v6_rsp = (struct adm_cmd_rsp_get_pp_params_v6 *) payload; |
| 1375 | data_size = v6_rsp->param_hdr.param_size; |
| 1376 | param_data = v6_rsp->param_data; |
| 1377 | break; |
| 1378 | default: |
| 1379 | pr_err("%s: Invalid opcode %d\n", __func__, opcode); |
| 1380 | return -EINVAL; |
| 1381 | } |
| 1382 | |
| 1383 | /* |
| 1384 | * Just store the returned parameter data, not the header. The calling |
| 1385 | * function is expected to know what it asked for. Therefore, there is |
| 1386 | * no difference between V5 and V6. |
| 1387 | */ |
| 1388 | if ((payload_size >= struct_size + data_size) && |
| 1389 | (ARRAY_SIZE(adm_get_parameters) > idx) && |
Karthikeyan Mani | 95be5b1 | 2018-11-09 14:57:32 -0800 | [diff] [blame] | 1390 | (ARRAY_SIZE(adm_get_parameters) > idx + 1 + data_size)) { |
Vignesh Kulothungan | aadecdf | 2018-06-20 15:08:24 -0700 | [diff] [blame] | 1391 | pr_debug("%s: Received parameter data in band\n", |
| 1392 | __func__); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1393 | /* |
| 1394 | * data_size is expressed in number of bytes, store in number of |
| 1395 | * ints |
| 1396 | */ |
| 1397 | adm_get_parameters[idx] = |
| 1398 | data_size / sizeof(*adm_get_parameters); |
| 1399 | pr_debug("%s: GET_PP PARAM: received parameter length: 0x%x\n", |
| 1400 | __func__, adm_get_parameters[idx]); |
| 1401 | /* store params after param_size */ |
| 1402 | memcpy(&adm_get_parameters[idx + 1], param_data, data_size); |
Vignesh Kulothungan | aadecdf | 2018-06-20 15:08:24 -0700 | [diff] [blame] | 1403 | } else if (payload_size == sizeof(uint32_t)) { |
| 1404 | adm_get_parameters[idx] = -1; |
| 1405 | pr_debug("%s: Out of band case, setting size to %d\n", |
| 1406 | __func__, adm_get_parameters[idx]); |
| 1407 | } else { |
| 1408 | pr_err("%s: Invalid parameter combination, payload_size %d, idx %d\n", |
| 1409 | __func__, payload_size, idx); |
| 1410 | return -EINVAL; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1411 | } |
Vignesh Kulothungan | aadecdf | 2018-06-20 15:08:24 -0700 | [diff] [blame] | 1412 | return 0; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | static int adm_process_get_topo_list_response(u32 opcode, int copp_idx, |
| 1416 | u32 num_modules, u32 *payload, |
| 1417 | u32 payload_size) |
| 1418 | { |
| 1419 | u32 *fill_list = NULL; |
| 1420 | int idx = 0; |
| 1421 | int i = 0; |
| 1422 | int j = 0; |
| 1423 | |
| 1424 | if (payload == NULL) { |
| 1425 | pr_err("%s: Payload is NULL\n", __func__); |
| 1426 | return -EINVAL; |
| 1427 | } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 1428 | pr_err("%s: Invalid COPP index %d\n", __func__, copp_idx); |
| 1429 | return -EINVAL; |
| 1430 | } |
| 1431 | |
| 1432 | idx = ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH * copp_idx; |
| 1433 | fill_list = adm_module_topo_list + idx; |
| 1434 | *fill_list++ = num_modules; |
| 1435 | for (i = 0; i < num_modules; i++) { |
| 1436 | if (j > payload_size / sizeof(u32)) { |
| 1437 | pr_err("%s: Invalid number of modules specified %d\n", |
| 1438 | __func__, num_modules); |
| 1439 | return -EINVAL; |
| 1440 | } |
| 1441 | |
| 1442 | /* store module ID */ |
| 1443 | *fill_list++ = payload[j]; |
| 1444 | j++; |
| 1445 | |
| 1446 | switch (opcode) { |
| 1447 | case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST_V2: |
| 1448 | /* store instance ID */ |
| 1449 | *fill_list++ = payload[j]; |
| 1450 | j++; |
| 1451 | break; |
| 1452 | case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST: |
| 1453 | /* Insert IID 0 when repacking */ |
| 1454 | *fill_list++ = INSTANCE_ID_0; |
| 1455 | break; |
| 1456 | default: |
| 1457 | pr_err("%s: Invalid opcode %d\n", __func__, opcode); |
| 1458 | return -EINVAL; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
Laxminath Kasam | 30ad751 | 2017-11-28 12:40:22 +0530 | [diff] [blame] | 1465 | static void adm_reset_data(void) |
| 1466 | { |
| 1467 | int i, j; |
| 1468 | |
| 1469 | apr_reset(this_adm.apr); |
| 1470 | for (i = 0; i < AFE_MAX_PORTS; i++) { |
| 1471 | for (j = 0; j < MAX_COPPS_PER_PORT; j++) { |
| 1472 | atomic_set(&this_adm.copp.id[i][j], |
| 1473 | RESET_COPP_ID); |
| 1474 | atomic_set(&this_adm.copp.cnt[i][j], 0); |
| 1475 | atomic_set( |
| 1476 | &this_adm.copp.topology[i][j], 0); |
| 1477 | atomic_set(&this_adm.copp.mode[i][j], |
| 1478 | 0); |
| 1479 | atomic_set(&this_adm.copp.stat[i][j], |
| 1480 | 0); |
| 1481 | atomic_set(&this_adm.copp.rate[i][j], |
| 1482 | 0); |
| 1483 | atomic_set( |
| 1484 | &this_adm.copp.channels[i][j], |
| 1485 | 0); |
| 1486 | atomic_set( |
| 1487 | &this_adm.copp.bit_width[i][j], 0); |
| 1488 | atomic_set( |
| 1489 | &this_adm.copp.app_type[i][j], 0); |
| 1490 | atomic_set( |
| 1491 | &this_adm.copp.acdb_id[i][j], 0); |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 1492 | atomic_set( |
| 1493 | &this_adm.copp.session_type[i][j], 0); |
Laxminath Kasam | 30ad751 | 2017-11-28 12:40:22 +0530 | [diff] [blame] | 1494 | this_adm.copp.adm_status[i][j] = |
| 1495 | ADM_STATUS_CALIBRATION_REQUIRED; |
| 1496 | } |
| 1497 | } |
| 1498 | this_adm.apr = NULL; |
| 1499 | cal_utils_clear_cal_block_q6maps(ADM_MAX_CAL_TYPES, |
| 1500 | this_adm.cal_data); |
| 1501 | mutex_lock(&this_adm.cal_data |
| 1502 | [ADM_CUSTOM_TOP_CAL]->lock); |
| 1503 | this_adm.set_custom_topology = 1; |
| 1504 | mutex_unlock(&this_adm.cal_data[ |
| 1505 | ADM_CUSTOM_TOP_CAL]->lock); |
| 1506 | rtac_clear_mapping(ADM_RTAC_CAL); |
| 1507 | /* |
| 1508 | * Free the ION memory and clear the map handles |
| 1509 | * for Source Tracking |
| 1510 | */ |
| 1511 | if (this_adm.sourceTrackingData.memmap.paddr != 0) { |
| 1512 | msm_audio_ion_free( |
| 1513 | this_adm.sourceTrackingData.dma_buf); |
| 1514 | this_adm.sourceTrackingData.dma_buf = NULL; |
| 1515 | this_adm.sourceTrackingData.memmap.size = 0; |
| 1516 | this_adm.sourceTrackingData.memmap.kvaddr = |
| 1517 | NULL; |
| 1518 | this_adm.sourceTrackingData.memmap.paddr = 0; |
| 1519 | this_adm.sourceTrackingData.apr_cmd_status = -1; |
| 1520 | atomic_set(&this_adm.mem_map_handles[ |
| 1521 | ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0); |
| 1522 | } |
| 1523 | } |
| 1524 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1525 | static int32_t adm_callback(struct apr_client_data *data, void *priv) |
| 1526 | { |
| 1527 | uint32_t *payload; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1528 | int port_idx, copp_idx, idx, client_id; |
| 1529 | int num_modules; |
| 1530 | int ret; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1531 | |
| 1532 | if (data == NULL) { |
| 1533 | pr_err("%s: data parameter is null\n", __func__); |
| 1534 | return -EINVAL; |
| 1535 | } |
| 1536 | |
| 1537 | payload = data->payload; |
| 1538 | |
| 1539 | if (data->opcode == RESET_EVENTS) { |
| 1540 | pr_debug("%s: Reset event is received: %d %d apr[%pK]\n", |
| 1541 | __func__, |
| 1542 | data->reset_event, data->reset_proc, this_adm.apr); |
Laxminath Kasam | 30ad751 | 2017-11-28 12:40:22 +0530 | [diff] [blame] | 1543 | if (this_adm.apr) |
| 1544 | adm_reset_data(); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | adm_callback_debug_print(data); |
| 1549 | if (data->payload_size) { |
| 1550 | copp_idx = (data->token) & 0XFF; |
| 1551 | port_idx = ((data->token) >> 16) & 0xFF; |
| 1552 | client_id = ((data->token) >> 8) & 0xFF; |
| 1553 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 1554 | pr_err("%s: Invalid port idx %d token %d\n", |
| 1555 | __func__, port_idx, data->token); |
| 1556 | return 0; |
| 1557 | } |
| 1558 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 1559 | pr_err("%s: Invalid copp idx %d token %d\n", |
| 1560 | __func__, copp_idx, data->token); |
| 1561 | return 0; |
| 1562 | } |
| 1563 | if (client_id < 0 || client_id >= ADM_CLIENT_ID_MAX) { |
| 1564 | pr_err("%s: Invalid client id %d\n", __func__, |
| 1565 | client_id); |
| 1566 | return 0; |
| 1567 | } |
| 1568 | if (data->opcode == APR_BASIC_RSP_RESULT) { |
| 1569 | pr_debug("%s: APR_BASIC_RSP_RESULT id 0x%x\n", |
| 1570 | __func__, payload[0]); |
| 1571 | if (payload[1] != 0) { |
| 1572 | pr_err("%s: cmd = 0x%x returned error = 0x%x\n", |
| 1573 | __func__, payload[0], payload[1]); |
| 1574 | } |
| 1575 | switch (payload[0]) { |
| 1576 | case ADM_CMD_SET_PP_PARAMS_V5: |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1577 | case ADM_CMD_SET_PP_PARAMS_V6: |
| 1578 | pr_debug("%s: ADM_CMD_SET_PP_PARAMS\n", |
| 1579 | __func__); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1580 | if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING) |
| 1581 | this_adm.sourceTrackingData. |
| 1582 | apr_cmd_status = payload[1]; |
| 1583 | else if (rtac_make_adm_callback(payload, |
| 1584 | data->payload_size)) |
| 1585 | break; |
| 1586 | /* |
| 1587 | * if soft volume is called and already |
| 1588 | * interrupted break out of the sequence here |
| 1589 | */ |
| 1590 | case ADM_CMD_DEVICE_OPEN_V5: |
| 1591 | case ADM_CMD_DEVICE_CLOSE_V5: |
| 1592 | case ADM_CMD_DEVICE_OPEN_V6: |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 1593 | case ADM_CMD_DEVICE_OPEN_V8: |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1594 | pr_debug("%s: Basic callback received, wake up.\n", |
| 1595 | __func__); |
| 1596 | atomic_set(&this_adm.copp.stat[port_idx] |
| 1597 | [copp_idx], payload[1]); |
| 1598 | wake_up( |
| 1599 | &this_adm.copp.wait[port_idx][copp_idx]); |
| 1600 | break; |
| 1601 | case ADM_CMD_ADD_TOPOLOGIES: |
| 1602 | pr_debug("%s: callback received, ADM_CMD_ADD_TOPOLOGIES.\n", |
| 1603 | __func__); |
| 1604 | atomic_set(&this_adm.adm_stat, payload[1]); |
| 1605 | wake_up(&this_adm.adm_wait); |
| 1606 | break; |
| 1607 | case ADM_CMD_MATRIX_MAP_ROUTINGS_V5: |
| 1608 | case ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5: |
| 1609 | pr_debug("%s: Basic callback received, wake up.\n", |
| 1610 | __func__); |
| 1611 | atomic_set(&this_adm.matrix_map_stat, |
| 1612 | payload[1]); |
| 1613 | wake_up(&this_adm.matrix_map_wait); |
| 1614 | break; |
| 1615 | case ADM_CMD_SHARED_MEM_UNMAP_REGIONS: |
| 1616 | pr_debug("%s: ADM_CMD_SHARED_MEM_UNMAP_REGIONS\n", |
| 1617 | __func__); |
| 1618 | atomic_set(&this_adm.adm_stat, payload[1]); |
| 1619 | wake_up(&this_adm.adm_wait); |
| 1620 | break; |
| 1621 | case ADM_CMD_SHARED_MEM_MAP_REGIONS: |
| 1622 | pr_debug("%s: ADM_CMD_SHARED_MEM_MAP_REGIONS\n", |
| 1623 | __func__); |
| 1624 | /* Should only come here if there is an APR */ |
| 1625 | /* error or malformed APR packet. Otherwise */ |
| 1626 | /* response will be returned as */ |
| 1627 | if (payload[1] != 0) { |
| 1628 | pr_err("%s: ADM map error, resuming\n", |
| 1629 | __func__); |
| 1630 | atomic_set(&this_adm.adm_stat, |
| 1631 | payload[1]); |
| 1632 | wake_up(&this_adm.adm_wait); |
| 1633 | } |
| 1634 | break; |
| 1635 | case ADM_CMD_GET_PP_PARAMS_V5: |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1636 | case ADM_CMD_GET_PP_PARAMS_V6: |
| 1637 | pr_debug("%s: ADM_CMD_GET_PP_PARAMS\n", |
| 1638 | __func__); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1639 | /* Should only come here if there is an APR */ |
| 1640 | /* error or malformed APR packet. Otherwise */ |
| 1641 | /* response will be returned as */ |
| 1642 | /* ADM_CMDRSP_GET_PP_PARAMS_V5 */ |
| 1643 | if (client_id == |
| 1644 | ADM_CLIENT_ID_SOURCE_TRACKING) { |
| 1645 | this_adm.sourceTrackingData. |
| 1646 | apr_cmd_status = payload[1]; |
| 1647 | if (payload[1] != 0) |
| 1648 | pr_err("%s: ADM get param error = %d\n", |
| 1649 | __func__, payload[1]); |
| 1650 | |
| 1651 | atomic_set(&this_adm.copp.stat |
| 1652 | [port_idx][copp_idx], |
| 1653 | payload[1]); |
| 1654 | wake_up(&this_adm.copp.wait |
| 1655 | [port_idx][copp_idx]); |
| 1656 | } else { |
| 1657 | if (payload[1] != 0) { |
| 1658 | pr_err("%s: ADM get param error = %d, resuming\n", |
| 1659 | __func__, payload[1]); |
| 1660 | |
| 1661 | rtac_make_adm_callback(payload, |
| 1662 | data->payload_size); |
| 1663 | } |
| 1664 | } |
| 1665 | break; |
| 1666 | case ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5: |
Bhalchandra Gajare | eed46bd | 2018-05-15 16:48:07 -0700 | [diff] [blame] | 1667 | case ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V6: |
| 1668 | pr_debug("%s:callback received PSPD MTMX, wake up\n", |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1669 | __func__); |
| 1670 | atomic_set(&this_adm.copp.stat[port_idx] |
| 1671 | [copp_idx], payload[1]); |
| 1672 | wake_up( |
| 1673 | &this_adm.copp.wait[port_idx][copp_idx]); |
| 1674 | break; |
| 1675 | case ADM_CMD_GET_PP_TOPO_MODULE_LIST: |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1676 | case ADM_CMD_GET_PP_TOPO_MODULE_LIST_V2: |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1677 | pr_debug("%s:ADM_CMD_GET_PP_TOPO_MODULE_LIST\n", |
| 1678 | __func__); |
| 1679 | if (payload[1] != 0) |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1680 | pr_err("%s: ADM get topo list error = %d\n", |
| 1681 | __func__, payload[1]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1682 | break; |
| 1683 | default: |
| 1684 | pr_err("%s: Unknown Cmd: 0x%x\n", __func__, |
| 1685 | payload[0]); |
| 1686 | break; |
| 1687 | } |
| 1688 | return 0; |
| 1689 | } |
| 1690 | |
| 1691 | switch (data->opcode) { |
| 1692 | case ADM_CMDRSP_DEVICE_OPEN_V5: |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 1693 | case ADM_CMDRSP_DEVICE_OPEN_V6: |
| 1694 | case ADM_CMDRSP_DEVICE_OPEN_V8: { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1695 | struct adm_cmd_rsp_device_open_v5 *open = |
| 1696 | (struct adm_cmd_rsp_device_open_v5 *)data->payload; |
| 1697 | |
| 1698 | if (open->copp_id == INVALID_COPP_ID) { |
| 1699 | pr_err("%s: invalid coppid rxed %d\n", |
| 1700 | __func__, open->copp_id); |
| 1701 | atomic_set(&this_adm.copp.stat[port_idx] |
| 1702 | [copp_idx], ADSP_EBADPARAM); |
| 1703 | wake_up( |
| 1704 | &this_adm.copp.wait[port_idx][copp_idx]); |
| 1705 | break; |
| 1706 | } |
| 1707 | atomic_set(&this_adm.copp.stat |
| 1708 | [port_idx][copp_idx], payload[0]); |
| 1709 | atomic_set(&this_adm.copp.id[port_idx][copp_idx], |
| 1710 | open->copp_id); |
| 1711 | pr_debug("%s: coppid rxed=%d\n", __func__, |
| 1712 | open->copp_id); |
| 1713 | wake_up(&this_adm.copp.wait[port_idx][copp_idx]); |
| 1714 | } |
| 1715 | break; |
| 1716 | case ADM_CMDRSP_GET_PP_PARAMS_V5: |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1717 | case ADM_CMDRSP_GET_PP_PARAMS_V6: |
| 1718 | pr_debug("%s: ADM_CMDRSP_GET_PP_PARAMS\n", __func__); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1719 | if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING) |
| 1720 | this_adm.sourceTrackingData.apr_cmd_status = |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1721 | payload[0]; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1722 | else if (rtac_make_adm_callback(payload, |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1723 | data->payload_size)) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1724 | break; |
| 1725 | |
| 1726 | idx = ADM_GET_PARAMETER_LENGTH * copp_idx; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1727 | if (payload[0] == 0 && data->payload_size > 0) { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1728 | ret = adm_process_get_param_response( |
| 1729 | data->opcode, idx, payload, |
| 1730 | data->payload_size); |
| 1731 | if (ret) |
| 1732 | pr_err("%s: Failed to process get param response, error %d\n", |
| 1733 | __func__, ret); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1734 | } else { |
| 1735 | adm_get_parameters[idx] = -1; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1736 | pr_err("%s: ADM_CMDRSP_GET_PP_PARAMS returned error 0x%x\n", |
| 1737 | __func__, payload[0]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1738 | } |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1739 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], |
| 1740 | payload[0]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1741 | wake_up(&this_adm.copp.wait[port_idx][copp_idx]); |
| 1742 | break; |
| 1743 | case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST: |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1744 | case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST_V2: |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1745 | pr_debug("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST\n", |
| 1746 | __func__); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1747 | num_modules = payload[1]; |
| 1748 | pr_debug("%s: Num modules %d\n", __func__, num_modules); |
| 1749 | if (payload[0]) { |
| 1750 | pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST, error = %d\n", |
| 1751 | __func__, payload[0]); |
| 1752 | } else if (num_modules > MAX_MODULES_IN_TOPO) { |
| 1753 | pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST invalid num modules received, num modules = %d\n", |
| 1754 | __func__, num_modules); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1755 | } else { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1756 | ret = adm_process_get_topo_list_response( |
| 1757 | data->opcode, copp_idx, num_modules, |
| 1758 | payload, data->payload_size); |
| 1759 | if (ret) |
| 1760 | pr_err("%s: Failed to process get topo modules list response, error %d\n", |
| 1761 | __func__, ret); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1762 | } |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 1763 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], |
| 1764 | payload[0]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1765 | wake_up(&this_adm.copp.wait[port_idx][copp_idx]); |
| 1766 | break; |
| 1767 | case ADM_CMDRSP_SHARED_MEM_MAP_REGIONS: |
| 1768 | pr_debug("%s: ADM_CMDRSP_SHARED_MEM_MAP_REGIONS\n", |
| 1769 | __func__); |
| 1770 | atomic_set(&this_adm.mem_map_handles[ |
| 1771 | atomic_read(&this_adm.mem_map_index)], |
| 1772 | *payload); |
| 1773 | atomic_set(&this_adm.adm_stat, 0); |
| 1774 | wake_up(&this_adm.adm_wait); |
| 1775 | break; |
| 1776 | default: |
| 1777 | pr_err("%s: Unknown cmd:0x%x\n", __func__, |
| 1778 | data->opcode); |
| 1779 | break; |
| 1780 | } |
| 1781 | } |
| 1782 | return 0; |
| 1783 | } |
| 1784 | |
| 1785 | static int adm_memory_map_regions(phys_addr_t *buf_add, uint32_t mempool_id, |
| 1786 | uint32_t *bufsz, uint32_t bufcnt) |
| 1787 | { |
| 1788 | struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL; |
| 1789 | struct avs_shared_map_region_payload *mregions = NULL; |
| 1790 | void *mmap_region_cmd = NULL; |
| 1791 | void *payload = NULL; |
| 1792 | int ret = 0; |
| 1793 | int i = 0; |
| 1794 | int cmd_size = 0; |
| 1795 | |
| 1796 | pr_debug("%s:\n", __func__); |
| 1797 | if (this_adm.apr == NULL) { |
| 1798 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 1799 | 0xFFFFFFFF, &this_adm); |
| 1800 | if (this_adm.apr == NULL) { |
| 1801 | pr_err("%s: Unable to register ADM\n", __func__); |
| 1802 | ret = -ENODEV; |
| 1803 | return ret; |
| 1804 | } |
| 1805 | rtac_set_adm_handle(this_adm.apr); |
| 1806 | } |
| 1807 | |
| 1808 | cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions) |
| 1809 | + sizeof(struct avs_shared_map_region_payload) |
| 1810 | * bufcnt; |
| 1811 | |
| 1812 | mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL); |
| 1813 | if (!mmap_region_cmd) |
| 1814 | return -ENOMEM; |
| 1815 | |
| 1816 | mmap_regions = (struct avs_cmd_shared_mem_map_regions *)mmap_region_cmd; |
| 1817 | mmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1818 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1819 | APR_PKT_VER); |
| 1820 | mmap_regions->hdr.pkt_size = cmd_size; |
| 1821 | mmap_regions->hdr.src_port = 0; |
| 1822 | |
| 1823 | mmap_regions->hdr.dest_port = 0; |
| 1824 | mmap_regions->hdr.token = 0; |
| 1825 | mmap_regions->hdr.opcode = ADM_CMD_SHARED_MEM_MAP_REGIONS; |
| 1826 | mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL & 0x00ff; |
| 1827 | mmap_regions->num_regions = bufcnt & 0x00ff; |
| 1828 | mmap_regions->property_flag = 0x00; |
| 1829 | |
| 1830 | pr_debug("%s: map_regions->num_regions = %d\n", __func__, |
| 1831 | mmap_regions->num_regions); |
| 1832 | payload = ((u8 *) mmap_region_cmd + |
| 1833 | sizeof(struct avs_cmd_shared_mem_map_regions)); |
| 1834 | mregions = (struct avs_shared_map_region_payload *)payload; |
| 1835 | |
| 1836 | for (i = 0; i < bufcnt; i++) { |
| 1837 | mregions->shm_addr_lsw = lower_32_bits(buf_add[i]); |
| 1838 | mregions->shm_addr_msw = |
| 1839 | msm_audio_populate_upper_32_bits(buf_add[i]); |
| 1840 | mregions->mem_size_bytes = bufsz[i]; |
| 1841 | ++mregions; |
| 1842 | } |
| 1843 | |
| 1844 | atomic_set(&this_adm.adm_stat, -1); |
| 1845 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) mmap_region_cmd); |
| 1846 | if (ret < 0) { |
| 1847 | pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__, |
| 1848 | mmap_regions->hdr.opcode, ret); |
| 1849 | ret = -EINVAL; |
| 1850 | goto fail_cmd; |
| 1851 | } |
| 1852 | |
| 1853 | ret = wait_event_timeout(this_adm.adm_wait, |
| 1854 | atomic_read(&this_adm.adm_stat) >= 0, |
| 1855 | 5 * HZ); |
| 1856 | if (!ret) { |
| 1857 | pr_err("%s: timeout. waited for memory_map\n", __func__); |
| 1858 | ret = -EINVAL; |
| 1859 | goto fail_cmd; |
| 1860 | } else if (atomic_read(&this_adm.adm_stat) > 0) { |
| 1861 | pr_err("%s: DSP returned error[%s]\n", |
| 1862 | __func__, adsp_err_get_err_str( |
| 1863 | atomic_read(&this_adm.adm_stat))); |
| 1864 | ret = adsp_err_get_lnx_err_code( |
| 1865 | atomic_read(&this_adm.adm_stat)); |
| 1866 | goto fail_cmd; |
| 1867 | } |
| 1868 | fail_cmd: |
| 1869 | kfree(mmap_region_cmd); |
| 1870 | return ret; |
| 1871 | } |
| 1872 | |
| 1873 | static int adm_memory_unmap_regions(void) |
| 1874 | { |
| 1875 | struct avs_cmd_shared_mem_unmap_regions unmap_regions; |
| 1876 | int ret = 0; |
| 1877 | |
| 1878 | pr_debug("%s:\n", __func__); |
| 1879 | if (this_adm.apr == NULL) { |
| 1880 | pr_err("%s: APR handle NULL\n", __func__); |
| 1881 | return -EINVAL; |
| 1882 | } |
| 1883 | |
| 1884 | unmap_regions.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1885 | APR_HDR_LEN(APR_HDR_SIZE), |
| 1886 | APR_PKT_VER); |
| 1887 | unmap_regions.hdr.pkt_size = sizeof(unmap_regions); |
| 1888 | unmap_regions.hdr.src_port = 0; |
| 1889 | unmap_regions.hdr.dest_port = 0; |
| 1890 | unmap_regions.hdr.token = 0; |
| 1891 | unmap_regions.hdr.opcode = ADM_CMD_SHARED_MEM_UNMAP_REGIONS; |
| 1892 | unmap_regions.mem_map_handle = atomic_read(&this_adm. |
| 1893 | mem_map_handles[atomic_read(&this_adm.mem_map_index)]); |
| 1894 | atomic_set(&this_adm.adm_stat, -1); |
| 1895 | ret = apr_send_pkt(this_adm.apr, (uint32_t *) &unmap_regions); |
| 1896 | if (ret < 0) { |
| 1897 | pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__, |
| 1898 | unmap_regions.hdr.opcode, ret); |
| 1899 | ret = -EINVAL; |
| 1900 | goto fail_cmd; |
| 1901 | } |
| 1902 | |
| 1903 | ret = wait_event_timeout(this_adm.adm_wait, |
| 1904 | atomic_read(&this_adm.adm_stat) >= 0, |
| 1905 | 5 * HZ); |
| 1906 | if (!ret) { |
| 1907 | pr_err("%s: timeout. waited for memory_unmap\n", |
| 1908 | __func__); |
| 1909 | ret = -EINVAL; |
| 1910 | goto fail_cmd; |
| 1911 | } else if (atomic_read(&this_adm.adm_stat) > 0) { |
| 1912 | pr_err("%s: DSP returned error[%s]\n", |
| 1913 | __func__, adsp_err_get_err_str( |
| 1914 | atomic_read(&this_adm.adm_stat))); |
| 1915 | ret = adsp_err_get_lnx_err_code( |
| 1916 | atomic_read(&this_adm.adm_stat)); |
| 1917 | goto fail_cmd; |
| 1918 | } else { |
| 1919 | pr_debug("%s: Unmap handle 0x%x succeeded\n", __func__, |
| 1920 | unmap_regions.mem_map_handle); |
| 1921 | } |
| 1922 | fail_cmd: |
| 1923 | return ret; |
| 1924 | } |
| 1925 | |
| 1926 | static int remap_cal_data(struct cal_block_data *cal_block, int cal_index) |
| 1927 | { |
| 1928 | int ret = 0; |
| 1929 | |
Banajit Goswami | 08bb736 | 2017-11-03 22:48:23 -0700 | [diff] [blame] | 1930 | if (cal_block->map_data.dma_buf == NULL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1931 | pr_err("%s: No ION allocation for cal index %d!\n", |
| 1932 | __func__, cal_index); |
| 1933 | ret = -EINVAL; |
| 1934 | goto done; |
| 1935 | } |
| 1936 | |
| 1937 | if ((cal_block->map_data.map_size > 0) && |
| 1938 | (cal_block->map_data.q6map_handle == 0)) { |
| 1939 | atomic_set(&this_adm.mem_map_index, cal_index); |
| 1940 | ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0, |
| 1941 | (uint32_t *)&cal_block->map_data.map_size, 1); |
| 1942 | if (ret < 0) { |
| 1943 | pr_err("%s: ADM mmap did not work! size = %zd ret %d\n", |
| 1944 | __func__, |
| 1945 | cal_block->map_data.map_size, ret); |
| 1946 | pr_debug("%s: ADM mmap did not work! addr = 0x%pK, size = %zd ret %d\n", |
| 1947 | __func__, |
| 1948 | &cal_block->cal_data.paddr, |
| 1949 | cal_block->map_data.map_size, ret); |
| 1950 | goto done; |
| 1951 | } |
| 1952 | cal_block->map_data.q6map_handle = atomic_read(&this_adm. |
| 1953 | mem_map_handles[cal_index]); |
| 1954 | } |
| 1955 | done: |
| 1956 | return ret; |
| 1957 | } |
| 1958 | |
| 1959 | static void send_adm_custom_topology(void) |
| 1960 | { |
| 1961 | struct cal_block_data *cal_block = NULL; |
| 1962 | struct cmd_set_topologies adm_top; |
| 1963 | int cal_index = ADM_CUSTOM_TOP_CAL; |
| 1964 | int result; |
| 1965 | |
| 1966 | if (this_adm.cal_data[cal_index] == NULL) |
| 1967 | goto done; |
| 1968 | |
| 1969 | mutex_lock(&this_adm.cal_data[cal_index]->lock); |
| 1970 | if (!this_adm.set_custom_topology) |
| 1971 | goto unlock; |
| 1972 | this_adm.set_custom_topology = 0; |
| 1973 | |
| 1974 | cal_block = cal_utils_get_only_cal_block(this_adm.cal_data[cal_index]); |
Vikram Panduranga | 770b838 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 1975 | if (cal_block == NULL || cal_utils_is_cal_stale(cal_block)) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1976 | goto unlock; |
| 1977 | |
| 1978 | pr_debug("%s: Sending cal_index %d\n", __func__, cal_index); |
| 1979 | |
| 1980 | result = remap_cal_data(cal_block, cal_index); |
| 1981 | if (result) { |
| 1982 | pr_err("%s: Remap_cal_data failed for cal %d!\n", |
| 1983 | __func__, cal_index); |
| 1984 | goto unlock; |
| 1985 | } |
| 1986 | atomic_set(&this_adm.mem_map_index, cal_index); |
| 1987 | atomic_set(&this_adm.mem_map_handles[cal_index], |
| 1988 | cal_block->map_data.q6map_handle); |
| 1989 | |
| 1990 | if (cal_block->cal_data.size == 0) { |
| 1991 | pr_debug("%s: No ADM cal to send\n", __func__); |
| 1992 | goto unlock; |
| 1993 | } |
| 1994 | |
| 1995 | adm_top.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 1996 | APR_HDR_LEN(20), APR_PKT_VER); |
| 1997 | adm_top.hdr.pkt_size = sizeof(adm_top); |
| 1998 | adm_top.hdr.src_svc = APR_SVC_ADM; |
| 1999 | adm_top.hdr.src_domain = APR_DOMAIN_APPS; |
| 2000 | adm_top.hdr.src_port = 0; |
| 2001 | adm_top.hdr.dest_svc = APR_SVC_ADM; |
| 2002 | adm_top.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 2003 | adm_top.hdr.dest_port = 0; |
| 2004 | adm_top.hdr.token = 0; |
| 2005 | adm_top.hdr.opcode = ADM_CMD_ADD_TOPOLOGIES; |
| 2006 | adm_top.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr); |
| 2007 | adm_top.payload_addr_msw = msm_audio_populate_upper_32_bits( |
| 2008 | cal_block->cal_data.paddr); |
| 2009 | adm_top.mem_map_handle = cal_block->map_data.q6map_handle; |
| 2010 | adm_top.payload_size = cal_block->cal_data.size; |
| 2011 | |
| 2012 | atomic_set(&this_adm.adm_stat, -1); |
| 2013 | pr_debug("%s: Sending ADM_CMD_ADD_TOPOLOGIES payload = 0x%pK, size = %d\n", |
| 2014 | __func__, &cal_block->cal_data.paddr, |
| 2015 | adm_top.payload_size); |
| 2016 | result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_top); |
| 2017 | if (result < 0) { |
| 2018 | pr_err("%s: Set topologies failed payload size = %zd result %d\n", |
| 2019 | __func__, cal_block->cal_data.size, result); |
| 2020 | goto unlock; |
| 2021 | } |
| 2022 | /* Wait for the callback */ |
| 2023 | result = wait_event_timeout(this_adm.adm_wait, |
| 2024 | atomic_read(&this_adm.adm_stat) >= 0, |
| 2025 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2026 | if (!result) { |
| 2027 | pr_err("%s: Set topologies timed out payload size = %zd\n", |
| 2028 | __func__, cal_block->cal_data.size); |
| 2029 | goto unlock; |
| 2030 | } else if (atomic_read(&this_adm.adm_stat) > 0) { |
| 2031 | pr_err("%s: DSP returned error[%s]\n", |
| 2032 | __func__, adsp_err_get_err_str( |
| 2033 | atomic_read(&this_adm.adm_stat))); |
| 2034 | result = adsp_err_get_lnx_err_code( |
| 2035 | atomic_read(&this_adm.adm_stat)); |
| 2036 | goto unlock; |
| 2037 | } |
| 2038 | unlock: |
| 2039 | mutex_unlock(&this_adm.cal_data[cal_index]->lock); |
| 2040 | done: |
| 2041 | return; |
| 2042 | } |
| 2043 | |
| 2044 | static int send_adm_cal_block(int port_id, int copp_idx, |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2045 | struct cal_block_data *cal_block, int perf_mode) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2046 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2047 | struct mem_mapping_hdr mem_hdr; |
| 2048 | int payload_size = 0; |
| 2049 | int port_idx = 0; |
| 2050 | int topology = 0; |
| 2051 | int result = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2052 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2053 | pr_debug("%s: Port id 0x%x,\n", __func__, port_id); |
| 2054 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2055 | if (!cal_block) { |
| 2056 | pr_debug("%s: No ADM cal to send for port_id = 0x%x!\n", |
| 2057 | __func__, port_id); |
| 2058 | result = -EINVAL; |
| 2059 | goto done; |
| 2060 | } |
| 2061 | if (cal_block->cal_data.size <= 0) { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2062 | pr_debug("%s: No ADM cal sent for port_id = 0x%x!\n", __func__, |
| 2063 | port_id); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2064 | result = -EINVAL; |
| 2065 | goto done; |
| 2066 | } |
| 2067 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2068 | memset(&mem_hdr, 0, sizeof(mem_hdr)); |
| 2069 | port_id = afe_convert_virtual_to_portid(port_id); |
| 2070 | port_idx = adm_validate_and_get_port_index(port_id); |
| 2071 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 2072 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 2073 | return -EINVAL; |
| 2074 | } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 2075 | pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); |
| 2076 | return -EINVAL; |
| 2077 | } |
| 2078 | |
| 2079 | topology = atomic_read(&this_adm.copp.topology[port_idx][copp_idx]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2080 | if (perf_mode == LEGACY_PCM_MODE && |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2081 | topology == DS2_ADM_COPP_TOPOLOGY_ID) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2082 | pr_err("%s: perf_mode %d, topology 0x%x\n", __func__, perf_mode, |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2083 | topology); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2084 | goto done; |
| 2085 | } |
| 2086 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2087 | mem_hdr.data_payload_addr_lsw = |
| 2088 | lower_32_bits(cal_block->cal_data.paddr); |
| 2089 | mem_hdr.data_payload_addr_msw = |
| 2090 | msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr); |
| 2091 | mem_hdr.mem_map_handle = cal_block->map_data.q6map_handle; |
| 2092 | payload_size = cal_block->cal_data.size; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2093 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2094 | adm_set_pp_params(port_id, copp_idx, &mem_hdr, NULL, payload_size); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2095 | |
| 2096 | done: |
| 2097 | return result; |
| 2098 | } |
| 2099 | |
| 2100 | static struct cal_block_data *adm_find_cal_by_path(int cal_index, int path) |
| 2101 | { |
| 2102 | struct list_head *ptr, *next; |
| 2103 | struct cal_block_data *cal_block = NULL; |
| 2104 | struct audio_cal_info_audproc *audproc_cal_info = NULL; |
| 2105 | struct audio_cal_info_audvol *audvol_cal_info = NULL; |
| 2106 | |
| 2107 | pr_debug("%s:\n", __func__); |
| 2108 | |
| 2109 | list_for_each_safe(ptr, next, |
| 2110 | &this_adm.cal_data[cal_index]->cal_blocks) { |
| 2111 | |
| 2112 | cal_block = list_entry(ptr, |
| 2113 | struct cal_block_data, list); |
| 2114 | |
Vikram Panduranga | 770b838 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 2115 | if (cal_utils_is_cal_stale(cal_block)) |
| 2116 | continue; |
| 2117 | |
Aditya Bavanari | 2a627ae | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2118 | if (cal_index == ADM_AUDPROC_CAL || |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 2119 | cal_index == ADM_LSM_AUDPROC_CAL || |
| 2120 | cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2121 | audproc_cal_info = cal_block->cal_info; |
| 2122 | if ((audproc_cal_info->path == path) && |
| 2123 | (cal_block->cal_data.size > 0)) |
| 2124 | return cal_block; |
| 2125 | } else if (cal_index == ADM_AUDVOL_CAL) { |
| 2126 | audvol_cal_info = cal_block->cal_info; |
| 2127 | if ((audvol_cal_info->path == path) && |
| 2128 | (cal_block->cal_data.size > 0)) |
| 2129 | return cal_block; |
| 2130 | } |
| 2131 | } |
| 2132 | pr_debug("%s: Can't find ADM cal for cal_index %d, path %d\n", |
| 2133 | __func__, cal_index, path); |
| 2134 | return NULL; |
| 2135 | } |
| 2136 | |
| 2137 | static struct cal_block_data *adm_find_cal_by_app_type(int cal_index, int path, |
| 2138 | int app_type) |
| 2139 | { |
| 2140 | struct list_head *ptr, *next; |
| 2141 | struct cal_block_data *cal_block = NULL; |
| 2142 | struct audio_cal_info_audproc *audproc_cal_info = NULL; |
| 2143 | struct audio_cal_info_audvol *audvol_cal_info = NULL; |
| 2144 | |
| 2145 | pr_debug("%s\n", __func__); |
| 2146 | |
| 2147 | list_for_each_safe(ptr, next, |
| 2148 | &this_adm.cal_data[cal_index]->cal_blocks) { |
| 2149 | |
| 2150 | cal_block = list_entry(ptr, |
| 2151 | struct cal_block_data, list); |
| 2152 | |
Vikram Panduranga | 770b838 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 2153 | if (cal_utils_is_cal_stale(cal_block)) |
| 2154 | continue; |
| 2155 | |
Aditya Bavanari | 2a627ae | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2156 | if (cal_index == ADM_AUDPROC_CAL || |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 2157 | cal_index == ADM_LSM_AUDPROC_CAL || |
| 2158 | cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2159 | audproc_cal_info = cal_block->cal_info; |
| 2160 | if ((audproc_cal_info->path == path) && |
| 2161 | (audproc_cal_info->app_type == app_type) && |
| 2162 | (cal_block->cal_data.size > 0)) |
| 2163 | return cal_block; |
| 2164 | } else if (cal_index == ADM_AUDVOL_CAL) { |
| 2165 | audvol_cal_info = cal_block->cal_info; |
| 2166 | if ((audvol_cal_info->path == path) && |
| 2167 | (audvol_cal_info->app_type == app_type) && |
| 2168 | (cal_block->cal_data.size > 0)) |
| 2169 | return cal_block; |
| 2170 | } |
| 2171 | } |
| 2172 | pr_debug("%s: Can't find ADM cali for cal_index %d, path %d, app %d, defaulting to search by path\n", |
| 2173 | __func__, cal_index, path, app_type); |
| 2174 | return adm_find_cal_by_path(cal_index, path); |
| 2175 | } |
| 2176 | |
| 2177 | |
| 2178 | static struct cal_block_data *adm_find_cal(int cal_index, int path, |
| 2179 | int app_type, int acdb_id, |
| 2180 | int sample_rate) |
| 2181 | { |
| 2182 | struct list_head *ptr, *next; |
| 2183 | struct cal_block_data *cal_block = NULL; |
| 2184 | struct audio_cal_info_audproc *audproc_cal_info = NULL; |
| 2185 | struct audio_cal_info_audvol *audvol_cal_info = NULL; |
| 2186 | |
| 2187 | pr_debug("%s:\n", __func__); |
| 2188 | |
| 2189 | list_for_each_safe(ptr, next, |
| 2190 | &this_adm.cal_data[cal_index]->cal_blocks) { |
| 2191 | |
| 2192 | cal_block = list_entry(ptr, |
| 2193 | struct cal_block_data, list); |
Vikram Panduranga | 770b838 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 2194 | if (cal_utils_is_cal_stale(cal_block)) |
| 2195 | continue; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2196 | |
Aditya Bavanari | 2a627ae | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2197 | if (cal_index == ADM_AUDPROC_CAL || |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 2198 | cal_index == ADM_LSM_AUDPROC_CAL || |
| 2199 | cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2200 | audproc_cal_info = cal_block->cal_info; |
| 2201 | if ((audproc_cal_info->path == path) && |
| 2202 | (audproc_cal_info->app_type == app_type) && |
| 2203 | (audproc_cal_info->acdb_id == acdb_id) && |
| 2204 | (audproc_cal_info->sample_rate == sample_rate) && |
| 2205 | (cal_block->cal_data.size > 0)) |
| 2206 | return cal_block; |
| 2207 | } else if (cal_index == ADM_AUDVOL_CAL) { |
| 2208 | audvol_cal_info = cal_block->cal_info; |
| 2209 | if ((audvol_cal_info->path == path) && |
| 2210 | (audvol_cal_info->app_type == app_type) && |
| 2211 | (audvol_cal_info->acdb_id == acdb_id) && |
| 2212 | (cal_block->cal_data.size > 0)) |
| 2213 | return cal_block; |
| 2214 | } |
| 2215 | } |
| 2216 | pr_debug("%s: Can't find ADM cal for cal_index %d, path %d, app %d, acdb_id %d sample_rate %d defaulting to search by app type\n", |
| 2217 | __func__, cal_index, path, app_type, acdb_id, sample_rate); |
| 2218 | return adm_find_cal_by_app_type(cal_index, path, app_type); |
| 2219 | } |
| 2220 | |
| 2221 | static int adm_remap_and_send_cal_block(int cal_index, int port_id, |
| 2222 | int copp_idx, struct cal_block_data *cal_block, int perf_mode, |
| 2223 | int app_type, int acdb_id, int sample_rate) |
| 2224 | { |
| 2225 | int ret = 0; |
| 2226 | |
| 2227 | pr_debug("%s: Sending cal_index cal %d\n", __func__, cal_index); |
| 2228 | ret = remap_cal_data(cal_block, cal_index); |
| 2229 | if (ret) { |
| 2230 | pr_err("%s: Remap_cal_data failed for cal %d!\n", |
| 2231 | __func__, cal_index); |
| 2232 | goto done; |
| 2233 | } |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 2234 | ret = send_adm_cal_block(port_id, copp_idx, cal_block, perf_mode); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2235 | if (ret < 0) |
| 2236 | pr_debug("%s: No cal sent for cal_index %d, port_id = 0x%x! ret %d sample_rate %d\n", |
| 2237 | __func__, cal_index, port_id, ret, sample_rate); |
| 2238 | done: |
| 2239 | return ret; |
| 2240 | } |
| 2241 | |
| 2242 | static void send_adm_cal_type(int cal_index, int path, int port_id, |
| 2243 | int copp_idx, int perf_mode, int app_type, |
| 2244 | int acdb_id, int sample_rate) |
| 2245 | { |
| 2246 | struct cal_block_data *cal_block = NULL; |
| 2247 | int ret; |
| 2248 | |
| 2249 | pr_debug("%s: cal index %d\n", __func__, cal_index); |
| 2250 | |
| 2251 | if (this_adm.cal_data[cal_index] == NULL) { |
| 2252 | pr_debug("%s: cal_index %d not allocated!\n", |
| 2253 | __func__, cal_index); |
| 2254 | goto done; |
| 2255 | } |
| 2256 | |
| 2257 | mutex_lock(&this_adm.cal_data[cal_index]->lock); |
| 2258 | cal_block = adm_find_cal(cal_index, path, app_type, acdb_id, |
| 2259 | sample_rate); |
| 2260 | if (cal_block == NULL) |
| 2261 | goto unlock; |
| 2262 | |
| 2263 | ret = adm_remap_and_send_cal_block(cal_index, port_id, copp_idx, |
| 2264 | cal_block, perf_mode, app_type, acdb_id, sample_rate); |
Vikram Panduranga | 770b838 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 2265 | |
| 2266 | cal_utils_mark_cal_used(cal_block); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2267 | unlock: |
| 2268 | mutex_unlock(&this_adm.cal_data[cal_index]->lock); |
| 2269 | done: |
| 2270 | return; |
| 2271 | } |
| 2272 | |
| 2273 | static int get_cal_path(int path) |
| 2274 | { |
| 2275 | if (path == 0x1) |
| 2276 | return RX_DEVICE; |
| 2277 | else |
| 2278 | return TX_DEVICE; |
| 2279 | } |
| 2280 | |
| 2281 | static void send_adm_cal(int port_id, int copp_idx, int path, int perf_mode, |
Aditya Bavanari | 5106b56 | 2018-01-08 13:16:32 +0530 | [diff] [blame] | 2282 | int app_type, int acdb_id, int sample_rate, |
| 2283 | int passthr_mode) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2284 | { |
| 2285 | pr_debug("%s: port id 0x%x copp_idx %d\n", __func__, port_id, copp_idx); |
| 2286 | |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 2287 | if (passthr_mode != LISTEN) { |
Aditya Bavanari | 2a627ae | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2288 | send_adm_cal_type(ADM_AUDPROC_CAL, path, port_id, copp_idx, |
| 2289 | perf_mode, app_type, acdb_id, sample_rate); |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 2290 | } else { |
Aditya Bavanari | 2a627ae | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 2291 | send_adm_cal_type(ADM_LSM_AUDPROC_CAL, path, port_id, copp_idx, |
| 2292 | perf_mode, app_type, acdb_id, sample_rate); |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 2293 | |
| 2294 | send_adm_cal_type(ADM_LSM_AUDPROC_PERSISTENT_CAL, path, |
| 2295 | port_id, copp_idx, perf_mode, app_type, |
| 2296 | acdb_id, sample_rate); |
| 2297 | } |
| 2298 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2299 | send_adm_cal_type(ADM_AUDVOL_CAL, path, port_id, copp_idx, perf_mode, |
| 2300 | app_type, acdb_id, sample_rate); |
| 2301 | } |
| 2302 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 2303 | /** |
| 2304 | * adm_connect_afe_port - |
| 2305 | * command to send ADM connect AFE port |
| 2306 | * |
| 2307 | * @mode: value of mode for ADM connect AFE |
| 2308 | * @session_id: session active to connect |
| 2309 | * @port_id: Port ID number |
| 2310 | * |
| 2311 | * Returns 0 on success or error on failure |
| 2312 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2313 | int adm_connect_afe_port(int mode, int session_id, int port_id) |
| 2314 | { |
| 2315 | struct adm_cmd_connect_afe_port_v5 cmd; |
| 2316 | int ret = 0; |
| 2317 | int port_idx, copp_idx = 0; |
| 2318 | |
| 2319 | pr_debug("%s: port_id: 0x%x session id:%d mode:%d\n", __func__, |
| 2320 | port_id, session_id, mode); |
| 2321 | |
| 2322 | port_id = afe_convert_virtual_to_portid(port_id); |
| 2323 | port_idx = adm_validate_and_get_port_index(port_id); |
| 2324 | if (port_idx < 0) { |
| 2325 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 2326 | return -EINVAL; |
| 2327 | } |
| 2328 | |
| 2329 | if (this_adm.apr == NULL) { |
| 2330 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 2331 | 0xFFFFFFFF, &this_adm); |
| 2332 | if (this_adm.apr == NULL) { |
| 2333 | pr_err("%s: Unable to register ADM\n", __func__); |
| 2334 | ret = -ENODEV; |
| 2335 | return ret; |
| 2336 | } |
| 2337 | rtac_set_adm_handle(this_adm.apr); |
| 2338 | } |
| 2339 | pr_debug("%s: Port ID 0x%x, index %d\n", __func__, port_id, port_idx); |
| 2340 | |
| 2341 | cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 2342 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 2343 | cmd.hdr.pkt_size = sizeof(cmd); |
| 2344 | cmd.hdr.src_svc = APR_SVC_ADM; |
| 2345 | cmd.hdr.src_domain = APR_DOMAIN_APPS; |
| 2346 | cmd.hdr.src_port = port_id; |
| 2347 | cmd.hdr.dest_svc = APR_SVC_ADM; |
| 2348 | cmd.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 2349 | cmd.hdr.dest_port = 0; /* Ignored */ |
| 2350 | cmd.hdr.token = port_idx << 16 | copp_idx; |
| 2351 | cmd.hdr.opcode = ADM_CMD_CONNECT_AFE_PORT_V5; |
| 2352 | |
| 2353 | cmd.mode = mode; |
| 2354 | cmd.session_id = session_id; |
| 2355 | cmd.afe_port_id = port_id; |
| 2356 | |
| 2357 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 2358 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&cmd); |
| 2359 | if (ret < 0) { |
| 2360 | pr_err("%s: ADM enable for port_id: 0x%x failed ret %d\n", |
| 2361 | __func__, port_id, ret); |
| 2362 | ret = -EINVAL; |
| 2363 | goto fail_cmd; |
| 2364 | } |
| 2365 | /* Wait for the callback with copp id */ |
| 2366 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 2367 | atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, |
| 2368 | msecs_to_jiffies(TIMEOUT_MS)); |
| 2369 | if (!ret) { |
| 2370 | pr_err("%s: ADM connect timedout for port_id: 0x%x\n", |
| 2371 | __func__, port_id); |
| 2372 | ret = -EINVAL; |
| 2373 | goto fail_cmd; |
| 2374 | } else if (atomic_read(&this_adm.copp.stat |
| 2375 | [port_idx][copp_idx]) > 0) { |
| 2376 | pr_err("%s: DSP returned error[%s]\n", |
| 2377 | __func__, adsp_err_get_err_str( |
| 2378 | atomic_read(&this_adm.copp.stat |
| 2379 | [port_idx][copp_idx]))); |
| 2380 | ret = adsp_err_get_lnx_err_code( |
| 2381 | atomic_read(&this_adm.copp.stat |
| 2382 | [port_idx][copp_idx])); |
| 2383 | goto fail_cmd; |
| 2384 | } |
| 2385 | atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]); |
| 2386 | return 0; |
| 2387 | |
| 2388 | fail_cmd: |
| 2389 | |
| 2390 | return ret; |
| 2391 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 2392 | EXPORT_SYMBOL(adm_connect_afe_port); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2393 | |
| 2394 | int adm_arrange_mch_map(struct adm_cmd_device_open_v5 *open, int path, |
| 2395 | int channel_mode) |
| 2396 | { |
| 2397 | int rc = 0, idx; |
| 2398 | |
Bhalchandra Gajare | eed46bd | 2018-05-15 16:48:07 -0700 | [diff] [blame] | 2399 | pr_debug("%s: channel mode %d", __func__, channel_mode); |
| 2400 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2401 | memset(open->dev_channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL); |
| 2402 | switch (path) { |
| 2403 | case ADM_PATH_PLAYBACK: |
| 2404 | idx = ADM_MCH_MAP_IDX_PLAYBACK; |
| 2405 | break; |
| 2406 | case ADM_PATH_LIVE_REC: |
| 2407 | case ADM_PATH_NONLIVE_REC: |
| 2408 | idx = ADM_MCH_MAP_IDX_REC; |
| 2409 | break; |
| 2410 | default: |
| 2411 | goto non_mch_path; |
| 2412 | }; |
| 2413 | if ((open->dev_num_channel > 2) && multi_ch_maps[idx].set_channel_map) { |
| 2414 | memcpy(open->dev_channel_mapping, |
| 2415 | multi_ch_maps[idx].channel_mapping, |
| 2416 | PCM_FORMAT_MAX_NUM_CHANNEL); |
| 2417 | } else { |
| 2418 | if (channel_mode == 1) { |
| 2419 | open->dev_channel_mapping[0] = PCM_CHANNEL_FC; |
| 2420 | } else if (channel_mode == 2) { |
| 2421 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2422 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2423 | } else if (channel_mode == 3) { |
| 2424 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2425 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2426 | open->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2427 | } else if (channel_mode == 4) { |
| 2428 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2429 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2430 | open->dev_channel_mapping[2] = PCM_CHANNEL_LS; |
| 2431 | open->dev_channel_mapping[3] = PCM_CHANNEL_RS; |
| 2432 | } else if (channel_mode == 5) { |
| 2433 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2434 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2435 | open->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2436 | open->dev_channel_mapping[3] = PCM_CHANNEL_LS; |
| 2437 | open->dev_channel_mapping[4] = PCM_CHANNEL_RS; |
| 2438 | } else if (channel_mode == 6) { |
| 2439 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2440 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2441 | open->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2442 | open->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2443 | open->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2444 | open->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2445 | } else if (channel_mode == 7) { |
| 2446 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2447 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2448 | open->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2449 | open->dev_channel_mapping[3] = PCM_CHANNEL_LFE; |
| 2450 | open->dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 2451 | open->dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| 2452 | open->dev_channel_mapping[6] = PCM_CHANNEL_CS; |
| 2453 | } else if (channel_mode == 8) { |
| 2454 | open->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2455 | open->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2456 | open->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2457 | open->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2458 | open->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2459 | open->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2460 | open->dev_channel_mapping[6] = PCM_CHANNEL_LB; |
| 2461 | open->dev_channel_mapping[7] = PCM_CHANNEL_RB; |
| 2462 | } else { |
| 2463 | pr_err("%s: invalid num_chan %d\n", __func__, |
| 2464 | channel_mode); |
| 2465 | rc = -EINVAL; |
| 2466 | goto inval_ch_mod; |
| 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | non_mch_path: |
| 2471 | inval_ch_mod: |
| 2472 | return rc; |
| 2473 | } |
| 2474 | |
| 2475 | int adm_arrange_mch_ep2_map(struct adm_cmd_device_open_v6 *open_v6, |
| 2476 | int channel_mode) |
| 2477 | { |
| 2478 | int rc = 0; |
| 2479 | |
| 2480 | memset(open_v6->dev_channel_mapping_eid2, 0, |
| 2481 | PCM_FORMAT_MAX_NUM_CHANNEL); |
| 2482 | |
| 2483 | if (channel_mode == 1) { |
| 2484 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FC; |
| 2485 | } else if (channel_mode == 2) { |
| 2486 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2487 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2488 | } else if (channel_mode == 3) { |
| 2489 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2490 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2491 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC; |
| 2492 | } else if (channel_mode == 4) { |
| 2493 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2494 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2495 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LS; |
| 2496 | open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_RS; |
| 2497 | } else if (channel_mode == 5) { |
| 2498 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2499 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2500 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC; |
| 2501 | open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_LS; |
| 2502 | open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_RS; |
| 2503 | } else if (channel_mode == 6) { |
| 2504 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2505 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2506 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE; |
| 2507 | open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC; |
| 2508 | open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS; |
| 2509 | open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS; |
| 2510 | } else if (channel_mode == 8) { |
| 2511 | open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL; |
| 2512 | open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR; |
| 2513 | open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE; |
| 2514 | open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC; |
| 2515 | open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS; |
| 2516 | open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS; |
| 2517 | open_v6->dev_channel_mapping_eid2[6] = PCM_CHANNEL_LB; |
| 2518 | open_v6->dev_channel_mapping_eid2[7] = PCM_CHANNEL_RB; |
| 2519 | } else { |
| 2520 | pr_err("%s: invalid num_chan %d\n", __func__, |
| 2521 | channel_mode); |
| 2522 | rc = -EINVAL; |
| 2523 | } |
| 2524 | |
| 2525 | return rc; |
| 2526 | } |
| 2527 | |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2528 | static int adm_arrange_mch_map_v8( |
| 2529 | struct adm_device_endpoint_payload *ep_payload, |
| 2530 | int path, |
| 2531 | int channel_mode) |
| 2532 | { |
| 2533 | int rc = 0, idx; |
| 2534 | |
| 2535 | memset(ep_payload->dev_channel_mapping, |
| 2536 | 0, PCM_FORMAT_MAX_NUM_CHANNEL_V8); |
| 2537 | switch (path) { |
| 2538 | case ADM_PATH_PLAYBACK: |
| 2539 | idx = ADM_MCH_MAP_IDX_PLAYBACK; |
| 2540 | break; |
| 2541 | case ADM_PATH_LIVE_REC: |
| 2542 | case ADM_PATH_NONLIVE_REC: |
| 2543 | idx = ADM_MCH_MAP_IDX_REC; |
| 2544 | break; |
| 2545 | default: |
| 2546 | goto non_mch_path; |
| 2547 | }; |
| 2548 | |
| 2549 | if ((ep_payload->dev_num_channel > 2) && |
| 2550 | multi_ch_maps[idx].set_channel_map) { |
| 2551 | memcpy(ep_payload->dev_channel_mapping, |
| 2552 | multi_ch_maps[idx].channel_mapping, |
| 2553 | PCM_FORMAT_MAX_NUM_CHANNEL_V8); |
| 2554 | } else { |
| 2555 | if (channel_mode == 1) { |
| 2556 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FC; |
| 2557 | } else if (channel_mode == 2) { |
| 2558 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2559 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2560 | } else if (channel_mode == 3) { |
| 2561 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2562 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2563 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2564 | } else if (channel_mode == 4) { |
| 2565 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2566 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2567 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LS; |
| 2568 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_RS; |
| 2569 | } else if (channel_mode == 5) { |
| 2570 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2571 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2572 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2573 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LS; |
| 2574 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_RS; |
| 2575 | } else if (channel_mode == 6) { |
| 2576 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2577 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2578 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2579 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2580 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2581 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2582 | } else if (channel_mode == 7) { |
| 2583 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2584 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2585 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2586 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LFE; |
| 2587 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 2588 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| 2589 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_CS; |
| 2590 | } else if (channel_mode == 8) { |
| 2591 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2592 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2593 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2594 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2595 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2596 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2597 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB; |
| 2598 | ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB; |
| 2599 | } else if (channel_mode == 10) { |
| 2600 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2601 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2602 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2603 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2604 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 2605 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| 2606 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS; |
| 2607 | ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS; |
| 2608 | ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL; |
| 2609 | ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR; |
| 2610 | } else if (channel_mode == 12) { |
| 2611 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2612 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2613 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2614 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2615 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 2616 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| 2617 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS; |
| 2618 | ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS; |
| 2619 | ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL; |
| 2620 | ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR; |
| 2621 | ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL; |
| 2622 | ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR; |
| 2623 | } else if (channel_mode == 16) { |
| 2624 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2625 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2626 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2627 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2628 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB; |
| 2629 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB; |
| 2630 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS; |
| 2631 | ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS; |
| 2632 | ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL; |
| 2633 | ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR; |
| 2634 | ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL; |
| 2635 | ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR; |
| 2636 | ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC; |
| 2637 | ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC; |
| 2638 | ep_payload->dev_channel_mapping[14] = PCM_CHANNEL_RLC; |
| 2639 | ep_payload->dev_channel_mapping[15] = PCM_CHANNEL_RRC; |
| 2640 | } else { |
| 2641 | pr_err("%s: invalid num_chan %d\n", __func__, |
| 2642 | channel_mode); |
| 2643 | rc = -EINVAL; |
| 2644 | goto inval_ch_mod; |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | non_mch_path: |
| 2649 | inval_ch_mod: |
| 2650 | return rc; |
| 2651 | } |
| 2652 | |
| 2653 | static int adm_arrange_mch_ep2_map_v8( |
| 2654 | struct adm_device_endpoint_payload *ep_payload, |
| 2655 | int channel_mode) |
| 2656 | { |
| 2657 | int rc = 0; |
| 2658 | |
| 2659 | memset(ep_payload->dev_channel_mapping, 0, |
| 2660 | PCM_FORMAT_MAX_NUM_CHANNEL_V8); |
| 2661 | |
| 2662 | if (channel_mode == 1) { |
| 2663 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FC; |
| 2664 | } else if (channel_mode == 2) { |
| 2665 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2666 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2667 | } else if (channel_mode == 3) { |
| 2668 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2669 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2670 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2671 | } else if (channel_mode == 4) { |
| 2672 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2673 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2674 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LS; |
| 2675 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_RS; |
| 2676 | } else if (channel_mode == 5) { |
| 2677 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2678 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2679 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC; |
| 2680 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LS; |
| 2681 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_RS; |
| 2682 | } else if (channel_mode == 6) { |
| 2683 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2684 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2685 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2686 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2687 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2688 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2689 | } else if (channel_mode == 8) { |
| 2690 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2691 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2692 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2693 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2694 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2695 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2696 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB; |
| 2697 | ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB; |
| 2698 | } else if (channel_mode == 10) { |
| 2699 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2700 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2701 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2702 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2703 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2704 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2705 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB; |
| 2706 | ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB; |
| 2707 | ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_CS; |
| 2708 | ep_payload->dev_channel_mapping[9] = PCM_CHANNELS; |
| 2709 | } else if (channel_mode == 12) { |
| 2710 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2711 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2712 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2713 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2714 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2715 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2716 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB; |
| 2717 | ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB; |
| 2718 | ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL; |
| 2719 | ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR; |
| 2720 | ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL; |
| 2721 | ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR; |
| 2722 | } else if (channel_mode == 16) { |
| 2723 | ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL; |
| 2724 | ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR; |
| 2725 | ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE; |
| 2726 | ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC; |
| 2727 | ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS; |
| 2728 | ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS; |
| 2729 | ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB; |
| 2730 | ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB; |
| 2731 | ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_CS; |
| 2732 | ep_payload->dev_channel_mapping[9] = PCM_CHANNELS; |
| 2733 | ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_CVH; |
| 2734 | ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_MS; |
| 2735 | ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC; |
| 2736 | ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC; |
| 2737 | ep_payload->dev_channel_mapping[14] = PCM_CHANNEL_RLC; |
| 2738 | ep_payload->dev_channel_mapping[15] = PCM_CHANNEL_RRC; |
| 2739 | } else { |
| 2740 | pr_err("%s: invalid num_chan %d\n", __func__, |
| 2741 | channel_mode); |
| 2742 | rc = -EINVAL; |
| 2743 | } |
| 2744 | |
| 2745 | return rc; |
| 2746 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 2747 | /** |
| 2748 | * adm_open - |
| 2749 | * command to send ADM open |
| 2750 | * |
| 2751 | * @port_id: port id number |
| 2752 | * @path: direction or ADM path type |
| 2753 | * @rate: sample rate of session |
| 2754 | * @channel_mode: number of channels set |
| 2755 | * @topology: topology active for this session |
| 2756 | * @perf_mode: performance mode like LL/ULL/.. |
| 2757 | * @bit_width: bit width to set for copp |
| 2758 | * @app_type: App type used for this session |
| 2759 | * @acdb_id: ACDB ID of this device |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 2760 | * @session_type: type of session |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 2761 | * |
| 2762 | * Returns 0 on success or error on failure |
| 2763 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2764 | int adm_open(int port_id, int path, int rate, int channel_mode, int topology, |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 2765 | int perf_mode, uint16_t bit_width, int app_type, int acdb_id, |
| 2766 | int session_type) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2767 | { |
| 2768 | struct adm_cmd_device_open_v5 open; |
| 2769 | struct adm_cmd_device_open_v6 open_v6; |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2770 | struct adm_cmd_device_open_v8 open_v8; |
| 2771 | struct adm_device_endpoint_payload ep1_payload; |
| 2772 | struct adm_device_endpoint_payload ep2_payload; |
| 2773 | int ep1_payload_size = 0; |
| 2774 | int ep2_payload_size = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2775 | int ret = 0; |
Asish Bhattacharya | 3450458 | 2017-08-08 12:55:01 +0530 | [diff] [blame] | 2776 | int port_idx, flags; |
| 2777 | int copp_idx = -1; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2778 | int tmp_port = q6audio_get_port_id(port_id); |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2779 | void *adm_params = NULL; |
| 2780 | int param_size; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2781 | |
| 2782 | pr_debug("%s:port %#x path:%d rate:%d mode:%d perf_mode:%d,topo_id %d\n", |
| 2783 | __func__, port_id, path, rate, channel_mode, perf_mode, |
| 2784 | topology); |
| 2785 | |
| 2786 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 2787 | port_idx = adm_validate_and_get_port_index(port_id); |
| 2788 | if (port_idx < 0) { |
| 2789 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 2790 | return -EINVAL; |
| 2791 | } |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2792 | if (channel_mode < 0 || channel_mode > 32) { |
| 2793 | pr_err("%s: Invalid channel number 0x%x\n", |
| 2794 | __func__, channel_mode); |
| 2795 | return -EINVAL; |
| 2796 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2797 | |
| 2798 | if (this_adm.apr == NULL) { |
| 2799 | this_adm.apr = apr_register("ADSP", "ADM", adm_callback, |
| 2800 | 0xFFFFFFFF, &this_adm); |
| 2801 | if (this_adm.apr == NULL) { |
| 2802 | pr_err("%s: Unable to register ADM\n", __func__); |
| 2803 | return -ENODEV; |
| 2804 | } |
| 2805 | rtac_set_adm_handle(this_adm.apr); |
| 2806 | } |
| 2807 | |
| 2808 | if (perf_mode == ULL_POST_PROCESSING_PCM_MODE) { |
| 2809 | flags = ADM_ULL_POST_PROCESSING_DEVICE_SESSION; |
| 2810 | if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) || |
| 2811 | (topology == DS2_ADM_COPP_TOPOLOGY_ID) || |
| 2812 | (topology == SRS_TRUMEDIA_TOPOLOGY_ID)) |
| 2813 | topology = DEFAULT_COPP_TOPOLOGY; |
| 2814 | } else if (perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) { |
| 2815 | flags = ADM_ULTRA_LOW_LATENCY_DEVICE_SESSION; |
| 2816 | topology = NULL_COPP_TOPOLOGY; |
| 2817 | rate = ULL_SUPPORTED_SAMPLE_RATE; |
| 2818 | bit_width = ULL_SUPPORTED_BITS_PER_SAMPLE; |
| 2819 | } else if (perf_mode == LOW_LATENCY_PCM_MODE) { |
| 2820 | flags = ADM_LOW_LATENCY_DEVICE_SESSION; |
| 2821 | if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) || |
| 2822 | (topology == DS2_ADM_COPP_TOPOLOGY_ID) || |
| 2823 | (topology == SRS_TRUMEDIA_TOPOLOGY_ID)) |
| 2824 | topology = DEFAULT_COPP_TOPOLOGY; |
| 2825 | } else { |
| 2826 | if ((path == ADM_PATH_COMPRESSED_RX) || |
| 2827 | (path == ADM_PATH_COMPRESSED_TX)) |
| 2828 | flags = 0; |
| 2829 | else |
| 2830 | flags = ADM_LEGACY_DEVICE_SESSION; |
| 2831 | } |
| 2832 | |
Laxminath Kasam | 8f7ccc2 | 2017-08-28 17:35:04 +0530 | [diff] [blame] | 2833 | if ((topology == VPM_TX_SM_ECNS_V2_COPP_TOPOLOGY) || |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2834 | (topology == VPM_TX_DM_FLUENCE_COPP_TOPOLOGY) || |
| 2835 | (topology == VPM_TX_DM_RFECNS_COPP_TOPOLOGY)) |
| 2836 | rate = 16000; |
| 2837 | |
kunleiz | c0cd19e | 2018-10-18 17:11:35 +0800 | [diff] [blame] | 2838 | if (topology == VPM_TX_VOICE_SMECNS_V2_COPP_TOPOLOGY) |
| 2839 | channel_mode = 1; |
| 2840 | |
Asish Bhattacharya | 3450458 | 2017-08-08 12:55:01 +0530 | [diff] [blame] | 2841 | /* |
| 2842 | * Routing driver reuses the same adm for streams with the same |
| 2843 | * app_type, sample_rate etc. |
| 2844 | * This isn't allowed for ULL streams as per the DSP interface |
| 2845 | */ |
| 2846 | if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) |
| 2847 | copp_idx = adm_get_idx_if_copp_exists(port_idx, topology, |
| 2848 | perf_mode, |
| 2849 | rate, bit_width, |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 2850 | app_type, session_type); |
Asish Bhattacharya | 3450458 | 2017-08-08 12:55:01 +0530 | [diff] [blame] | 2851 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2852 | if (copp_idx < 0) { |
| 2853 | copp_idx = adm_get_next_available_copp(port_idx); |
| 2854 | if (copp_idx >= MAX_COPPS_PER_PORT) { |
| 2855 | pr_err("%s: exceeded copp id %d\n", |
| 2856 | __func__, copp_idx); |
| 2857 | return -EINVAL; |
| 2858 | } |
| 2859 | atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0); |
| 2860 | atomic_set(&this_adm.copp.topology[port_idx][copp_idx], |
| 2861 | topology); |
| 2862 | atomic_set(&this_adm.copp.mode[port_idx][copp_idx], |
| 2863 | perf_mode); |
| 2864 | atomic_set(&this_adm.copp.rate[port_idx][copp_idx], |
| 2865 | rate); |
| 2866 | atomic_set(&this_adm.copp.channels[port_idx][copp_idx], |
| 2867 | channel_mode); |
| 2868 | atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx], |
| 2869 | bit_width); |
| 2870 | atomic_set(&this_adm.copp.app_type[port_idx][copp_idx], |
| 2871 | app_type); |
| 2872 | atomic_set(&this_adm.copp.acdb_id[port_idx][copp_idx], |
| 2873 | acdb_id); |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 2874 | atomic_set(&this_adm.copp.session_type[port_idx][copp_idx], |
| 2875 | session_type); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2876 | set_bit(ADM_STATUS_CALIBRATION_REQUIRED, |
| 2877 | (void *)&this_adm.copp.adm_status[port_idx][copp_idx]); |
| 2878 | if ((path != ADM_PATH_COMPRESSED_RX) && |
| 2879 | (path != ADM_PATH_COMPRESSED_TX)) |
| 2880 | send_adm_custom_topology(); |
| 2881 | } |
| 2882 | |
| 2883 | if (this_adm.copp.adm_delay[port_idx][copp_idx] && |
| 2884 | perf_mode == LEGACY_PCM_MODE) { |
| 2885 | atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], |
| 2886 | 1); |
| 2887 | this_adm.copp.adm_delay[port_idx][copp_idx] = 0; |
| 2888 | wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]); |
| 2889 | } |
| 2890 | |
| 2891 | /* Create a COPP if port id are not enabled */ |
| 2892 | if (atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]) == 0) { |
| 2893 | pr_debug("%s: open ADM: port_idx: %d, copp_idx: %d\n", __func__, |
| 2894 | port_idx, copp_idx); |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2895 | if ((topology == SRS_TRUMEDIA_TOPOLOGY_ID) && |
| 2896 | perf_mode == LEGACY_PCM_MODE) { |
| 2897 | int res; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2898 | |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2899 | atomic_set(&this_adm.mem_map_index, ADM_SRS_TRUMEDIA); |
| 2900 | msm_dts_srs_tm_ion_memmap(&this_adm.outband_memmap); |
| 2901 | res = adm_memory_map_regions( |
| 2902 | &this_adm.outband_memmap.paddr, 0, |
| 2903 | (uint32_t *)&this_adm.outband_memmap.size, 1); |
| 2904 | if (res < 0) { |
| 2905 | pr_err("%s: SRS adm_memory_map_regions failed! addr = 0x%pK, size = %d\n", |
| 2906 | __func__, |
| 2907 | (void *)this_adm.outband_memmap.paddr, |
| 2908 | (uint32_t)this_adm.outband_memmap.size); |
| 2909 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2910 | } |
| 2911 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2912 | |
Mangesh Kunchamwar | 9f295c7 | 2018-10-08 18:20:41 +0530 | [diff] [blame] | 2913 | if ((q6core_get_avcs_api_version_per_service( |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2914 | APRV2_IDS_SERVICE_ID_ADSP_ADM_V) >= |
Mangesh Kunchamwar | 9f295c7 | 2018-10-08 18:20:41 +0530 | [diff] [blame] | 2915 | ADSP_ADM_API_VERSION_V3) && |
| 2916 | q6core_use_Q6_32ch_support()) { |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2917 | memset(&open_v8, 0, sizeof(open_v8)); |
| 2918 | memset(&ep1_payload, 0, sizeof(ep1_payload)); |
| 2919 | memset(&ep2_payload, 0, sizeof(ep2_payload)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2920 | |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2921 | open_v8.hdr.hdr_field = APR_HDR_FIELD( |
| 2922 | APR_MSG_TYPE_SEQ_CMD, |
| 2923 | APR_HDR_LEN(APR_HDR_SIZE), |
| 2924 | APR_PKT_VER); |
| 2925 | open_v8.hdr.src_svc = APR_SVC_ADM; |
| 2926 | open_v8.hdr.src_domain = APR_DOMAIN_APPS; |
| 2927 | open_v8.hdr.src_port = tmp_port; |
| 2928 | open_v8.hdr.dest_svc = APR_SVC_ADM; |
| 2929 | open_v8.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 2930 | open_v8.hdr.dest_port = tmp_port; |
| 2931 | open_v8.hdr.token = port_idx << 16 | copp_idx; |
| 2932 | open_v8.hdr.opcode = ADM_CMD_DEVICE_OPEN_V8; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2933 | |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2934 | if (this_adm.native_mode != 0) { |
| 2935 | open_v8.flags = flags | |
| 2936 | (this_adm.native_mode << 11); |
| 2937 | this_adm.native_mode = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2938 | } else { |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2939 | open_v8.flags = flags; |
| 2940 | } |
| 2941 | open_v8.mode_of_operation = path; |
| 2942 | open_v8.endpoint_id_1 = tmp_port; |
| 2943 | open_v8.endpoint_id_2 = 0xFFFF; |
| 2944 | open_v8.endpoint_id_3 = 0xFFFF; |
| 2945 | |
Dieter Luecking | 4162083 | 2018-11-14 15:11:47 +0100 | [diff] [blame] | 2946 | if (this_adm.ec_ref_rx && (path != ADM_PATH_PLAYBACK)) { |
| 2947 | open_v8.endpoint_id_2 = this_adm.ec_ref_rx; |
| 2948 | this_adm.ec_ref_rx = -1; |
| 2949 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2950 | |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2951 | open_v8.topology_id = topology; |
| 2952 | open_v8.reserved = 0; |
| 2953 | |
| 2954 | /* variable endpoint payload */ |
| 2955 | ep1_payload.dev_num_channel = channel_mode & 0x00FF; |
| 2956 | ep1_payload.bit_width = bit_width; |
| 2957 | ep1_payload.sample_rate = rate; |
| 2958 | ret = adm_arrange_mch_map_v8(&ep1_payload, path, |
| 2959 | channel_mode); |
| 2960 | if (ret) |
| 2961 | return ret; |
| 2962 | |
| 2963 | pr_debug("%s: port_id=0x%x %x %x topology_id=0x%X flags %x ref_ch %x\n", |
| 2964 | __func__, open_v8.endpoint_id_1, |
| 2965 | open_v8.endpoint_id_2, |
| 2966 | open_v8.endpoint_id_3, |
| 2967 | open_v8.topology_id, |
| 2968 | open_v8.flags, |
| 2969 | this_adm.num_ec_ref_rx_chans); |
| 2970 | |
| 2971 | ep1_payload_size = 8 + |
| 2972 | roundup(ep1_payload.dev_num_channel, 4); |
| 2973 | param_size = sizeof(struct adm_cmd_device_open_v8) |
| 2974 | + ep1_payload_size; |
| 2975 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 2976 | |
Dieter Luecking | 27c5772 | 2018-10-05 16:45:41 +0200 | [diff] [blame] | 2977 | if ((this_adm.num_ec_ref_rx_chans != 0) |
| 2978 | && (path != ADM_PATH_PLAYBACK) |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2979 | && (open_v8.endpoint_id_2 != 0xFFFF)) { |
| 2980 | ep2_payload.dev_num_channel = |
| 2981 | this_adm.num_ec_ref_rx_chans; |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2982 | |
| 2983 | if (this_adm.ec_ref_rx_bit_width != 0) { |
| 2984 | ep2_payload.bit_width = |
| 2985 | this_adm.ec_ref_rx_bit_width; |
| 2986 | this_adm.ec_ref_rx_bit_width = 0; |
| 2987 | } else { |
| 2988 | ep2_payload.bit_width = bit_width; |
| 2989 | } |
| 2990 | |
| 2991 | if (this_adm.ec_ref_rx_sampling_rate != 0) { |
| 2992 | ep2_payload.sample_rate = |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 2993 | this_adm.ec_ref_rx_sampling_rate; |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 2994 | this_adm.ec_ref_rx_sampling_rate = 0; |
| 2995 | } else { |
| 2996 | ep2_payload.sample_rate = rate; |
| 2997 | } |
| 2998 | |
| 2999 | pr_debug("%s: adm open_v8 eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n", |
| 3000 | __func__, |
| 3001 | ep2_payload.dev_num_channel, |
| 3002 | ep2_payload.bit_width, |
| 3003 | ep2_payload.sample_rate); |
| 3004 | |
| 3005 | ret = adm_arrange_mch_ep2_map_v8(&ep2_payload, |
| 3006 | ep2_payload.dev_num_channel); |
| 3007 | |
| 3008 | if (ret) |
| 3009 | return ret; |
| 3010 | ep2_payload_size = 8 + |
| 3011 | roundup(ep2_payload.dev_num_channel, 4); |
| 3012 | param_size += ep2_payload_size; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3013 | } |
| 3014 | |
Dieter Luecking | 27c5772 | 2018-10-05 16:45:41 +0200 | [diff] [blame] | 3015 | open_v8.hdr.pkt_size = param_size; |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 3016 | adm_params = kzalloc(param_size, GFP_KERNEL); |
| 3017 | if (!adm_params) |
| 3018 | return -ENOMEM; |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 3019 | memcpy(adm_params, &open_v8, sizeof(open_v8)); |
| 3020 | memcpy(adm_params + sizeof(open_v8), |
| 3021 | (void *)&ep1_payload, |
| 3022 | ep1_payload_size); |
Dieter Luecking | 27c5772 | 2018-10-05 16:45:41 +0200 | [diff] [blame] | 3023 | |
| 3024 | if ((this_adm.num_ec_ref_rx_chans != 0) |
| 3025 | && (path != ADM_PATH_PLAYBACK) |
| 3026 | && (open_v8.endpoint_id_2 != 0xFFFF)) { |
Dieter Luecking | 4162083 | 2018-11-14 15:11:47 +0100 | [diff] [blame] | 3027 | this_adm.num_ec_ref_rx_chans = 0; |
Dieter Luecking | 27c5772 | 2018-10-05 16:45:41 +0200 | [diff] [blame] | 3028 | memcpy(adm_params + sizeof(open_v8) |
| 3029 | + ep1_payload_size, |
| 3030 | (void *)&ep2_payload, |
| 3031 | ep2_payload_size); |
| 3032 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3033 | |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 3034 | ret = apr_send_pkt(this_adm.apr, |
| 3035 | (uint32_t *)adm_params); |
| 3036 | if (ret < 0) { |
| 3037 | pr_err("%s: port_id: 0x%x for[0x%x] failed %d for open_v8\n", |
| 3038 | __func__, tmp_port, port_id, ret); |
| 3039 | return -EINVAL; |
| 3040 | } |
| 3041 | kfree(adm_params); |
| 3042 | } else { |
| 3043 | |
| 3044 | open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3045 | APR_HDR_LEN(APR_HDR_SIZE), |
| 3046 | APR_PKT_VER); |
| 3047 | open.hdr.pkt_size = sizeof(open); |
| 3048 | open.hdr.src_svc = APR_SVC_ADM; |
| 3049 | open.hdr.src_domain = APR_DOMAIN_APPS; |
| 3050 | open.hdr.src_port = tmp_port; |
| 3051 | open.hdr.dest_svc = APR_SVC_ADM; |
| 3052 | open.hdr.dest_domain = APR_DOMAIN_ADSP; |
| 3053 | open.hdr.dest_port = tmp_port; |
| 3054 | open.hdr.token = port_idx << 16 | copp_idx; |
| 3055 | open.hdr.opcode = ADM_CMD_DEVICE_OPEN_V5; |
| 3056 | open.flags = flags; |
| 3057 | open.mode_of_operation = path; |
| 3058 | open.endpoint_id_1 = tmp_port; |
| 3059 | open.endpoint_id_2 = 0xFFFF; |
| 3060 | |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 3061 | if (this_adm.ec_ref_rx && (path != 1) && |
| 3062 | (afe_get_port_type(tmp_port) == MSM_AFE_PORT_TYPE_TX)) { |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 3063 | open.endpoint_id_2 = this_adm.ec_ref_rx; |
| 3064 | this_adm.ec_ref_rx = -1; |
| 3065 | } |
| 3066 | |
| 3067 | open.topology_id = topology; |
| 3068 | |
| 3069 | open.dev_num_channel = channel_mode & 0x00FF; |
| 3070 | open.bit_width = bit_width; |
| 3071 | WARN_ON((perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) && |
| 3072 | (rate != ULL_SUPPORTED_SAMPLE_RATE)); |
| 3073 | open.sample_rate = rate; |
| 3074 | |
| 3075 | ret = adm_arrange_mch_map(&open, path, channel_mode); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3076 | |
| 3077 | if (ret) |
| 3078 | return ret; |
| 3079 | |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 3080 | pr_debug("%s: port_id=0x%x rate=%d topology_id=0x%X\n", |
| 3081 | __func__, open.endpoint_id_1, open.sample_rate, |
| 3082 | open.topology_id); |
| 3083 | |
| 3084 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3085 | |
| 3086 | if ((this_adm.num_ec_ref_rx_chans != 0) && |
| 3087 | (path != 1) && (open.endpoint_id_2 != 0xFFFF)) { |
| 3088 | memset(&open_v6, 0, |
| 3089 | sizeof(struct adm_cmd_device_open_v6)); |
| 3090 | memcpy(&open_v6, &open, |
| 3091 | sizeof(struct adm_cmd_device_open_v5)); |
| 3092 | open_v6.hdr.opcode = ADM_CMD_DEVICE_OPEN_V6; |
| 3093 | open_v6.hdr.pkt_size = sizeof(open_v6); |
| 3094 | open_v6.dev_num_channel_eid2 = |
| 3095 | this_adm.num_ec_ref_rx_chans; |
| 3096 | this_adm.num_ec_ref_rx_chans = 0; |
| 3097 | |
| 3098 | if (this_adm.ec_ref_rx_bit_width != 0) { |
| 3099 | open_v6.bit_width_eid2 = |
| 3100 | this_adm.ec_ref_rx_bit_width; |
| 3101 | this_adm.ec_ref_rx_bit_width = 0; |
| 3102 | } else { |
| 3103 | open_v6.bit_width_eid2 = bit_width; |
| 3104 | } |
| 3105 | |
| 3106 | if (this_adm.ec_ref_rx_sampling_rate != 0) { |
| 3107 | open_v6.sample_rate_eid2 = |
| 3108 | this_adm.ec_ref_rx_sampling_rate; |
| 3109 | this_adm.ec_ref_rx_sampling_rate = 0; |
| 3110 | } else { |
| 3111 | open_v6.sample_rate_eid2 = rate; |
| 3112 | } |
| 3113 | |
| 3114 | pr_debug("%s: eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n", |
| 3115 | __func__, open_v6.dev_num_channel_eid2, |
| 3116 | open_v6.bit_width_eid2, |
| 3117 | open_v6.sample_rate_eid2); |
| 3118 | |
| 3119 | ret = adm_arrange_mch_ep2_map(&open_v6, |
| 3120 | open_v6.dev_num_channel_eid2); |
| 3121 | |
| 3122 | if (ret) |
| 3123 | return ret; |
| 3124 | |
| 3125 | ret = apr_send_pkt(this_adm.apr, |
| 3126 | (uint32_t *)&open_v6); |
| 3127 | } else { |
| 3128 | ret = apr_send_pkt(this_adm.apr, |
| 3129 | (uint32_t *)&open); |
| 3130 | } |
| 3131 | if (ret < 0) { |
| 3132 | pr_err("%s: port_id: 0x%x for[0x%x] failed %d\n", |
| 3133 | __func__, tmp_port, port_id, ret); |
| 3134 | return -EINVAL; |
| 3135 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3136 | } |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 3137 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3138 | /* Wait for the callback with copp id */ |
| 3139 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 3140 | atomic_read(&this_adm.copp.stat |
| 3141 | [port_idx][copp_idx]) >= 0, |
| 3142 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3143 | if (!ret) { |
| 3144 | pr_err("%s: ADM open timedout for port_id: 0x%x for [0x%x]\n", |
| 3145 | __func__, tmp_port, port_id); |
| 3146 | return -EINVAL; |
| 3147 | } else if (atomic_read(&this_adm.copp.stat |
| 3148 | [port_idx][copp_idx]) > 0) { |
| 3149 | pr_err("%s: DSP returned error[%s]\n", |
| 3150 | __func__, adsp_err_get_err_str( |
| 3151 | atomic_read(&this_adm.copp.stat |
| 3152 | [port_idx][copp_idx]))); |
| 3153 | return adsp_err_get_lnx_err_code( |
| 3154 | atomic_read(&this_adm.copp.stat |
| 3155 | [port_idx][copp_idx])); |
| 3156 | } |
| 3157 | } |
| 3158 | atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]); |
| 3159 | return copp_idx; |
| 3160 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3161 | EXPORT_SYMBOL(adm_open); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3162 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3163 | /** |
| 3164 | * adm_copp_mfc_cfg - |
| 3165 | * command to send ADM MFC config |
| 3166 | * |
| 3167 | * @port_id: Port ID number |
| 3168 | * @copp_idx: copp index assigned |
| 3169 | * @dst_sample_rate: sink sample rate |
| 3170 | * |
| 3171 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3172 | void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate) |
| 3173 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 3174 | struct audproc_mfc_param_media_fmt mfc_cfg; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3175 | struct adm_cmd_device_open_v5 open; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 3176 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3177 | int port_idx; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3178 | int rc = 0; |
| 3179 | int i = 0; |
| 3180 | |
| 3181 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 3182 | port_idx = adm_validate_and_get_port_index(port_id); |
| 3183 | |
| 3184 | if (port_idx < 0) { |
| 3185 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 3186 | goto fail_cmd; |
| 3187 | } |
| 3188 | |
| 3189 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 3190 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 3191 | goto fail_cmd; |
| 3192 | } |
| 3193 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 3194 | memset(&mfc_cfg, 0, sizeof(mfc_cfg)); |
| 3195 | memset(&open, 0, sizeof(open)); |
| 3196 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3197 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 3198 | param_hdr.module_id = AUDPROC_MODULE_ID_MFC; |
| 3199 | param_hdr.instance_id = INSTANCE_ID_0; |
| 3200 | param_hdr.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT; |
| 3201 | param_hdr.param_size = sizeof(mfc_cfg); |
| 3202 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3203 | mfc_cfg.sampling_rate = dst_sample_rate; |
| 3204 | mfc_cfg.bits_per_sample = |
| 3205 | atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]); |
| 3206 | open.dev_num_channel = mfc_cfg.num_channels = |
| 3207 | atomic_read(&this_adm.copp.channels[port_idx][copp_idx]); |
| 3208 | |
| 3209 | rc = adm_arrange_mch_map(&open, ADM_PATH_PLAYBACK, |
| 3210 | mfc_cfg.num_channels); |
| 3211 | if (rc < 0) { |
| 3212 | pr_err("%s: unable to get channal map\n", __func__); |
| 3213 | goto fail_cmd; |
| 3214 | } |
| 3215 | |
| 3216 | for (i = 0; i < mfc_cfg.num_channels; i++) |
| 3217 | mfc_cfg.channel_type[i] = |
| 3218 | (uint16_t) open.dev_channel_mapping[i]; |
| 3219 | |
| 3220 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3221 | |
| 3222 | pr_debug("%s: mfc config: port_idx %d copp_idx %d copp SR %d copp BW %d copp chan %d o/p SR %d\n", |
| 3223 | __func__, port_idx, copp_idx, |
| 3224 | atomic_read(&this_adm.copp.rate[port_idx][copp_idx]), |
| 3225 | mfc_cfg.bits_per_sample, mfc_cfg.num_channels, |
| 3226 | mfc_cfg.sampling_rate); |
| 3227 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 3228 | rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 3229 | (uint8_t *) &mfc_cfg); |
| 3230 | if (rc) |
| 3231 | pr_err("%s: Failed to set media format configuration data, err %d\n", |
| 3232 | __func__, rc); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3233 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3234 | fail_cmd: |
| 3235 | return; |
| 3236 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3237 | EXPORT_SYMBOL(adm_copp_mfc_cfg); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3238 | |
| 3239 | static void route_set_opcode_matrix_id( |
| 3240 | struct adm_cmd_matrix_map_routings_v5 **route_addr, |
| 3241 | int path, uint32_t passthr_mode) |
| 3242 | { |
| 3243 | struct adm_cmd_matrix_map_routings_v5 *route = *route_addr; |
| 3244 | |
| 3245 | switch (path) { |
| 3246 | case ADM_PATH_PLAYBACK: |
| 3247 | route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5; |
| 3248 | route->matrix_id = ADM_MATRIX_ID_AUDIO_RX; |
| 3249 | break; |
| 3250 | case ADM_PATH_LIVE_REC: |
| 3251 | if (passthr_mode == LISTEN) { |
| 3252 | route->hdr.opcode = |
| 3253 | ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5; |
| 3254 | route->matrix_id = ADM_MATRIX_ID_LISTEN_TX; |
| 3255 | break; |
| 3256 | } |
| 3257 | /* fall through to set matrix id for non-listen case */ |
| 3258 | case ADM_PATH_NONLIVE_REC: |
| 3259 | route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5; |
| 3260 | route->matrix_id = ADM_MATRIX_ID_AUDIO_TX; |
| 3261 | break; |
| 3262 | case ADM_PATH_COMPRESSED_RX: |
| 3263 | route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5; |
| 3264 | route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_RX; |
| 3265 | break; |
| 3266 | case ADM_PATH_COMPRESSED_TX: |
| 3267 | route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5; |
| 3268 | route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_TX; |
| 3269 | break; |
| 3270 | default: |
| 3271 | pr_err("%s: Wrong path set[%d]\n", __func__, path); |
| 3272 | break; |
| 3273 | } |
| 3274 | pr_debug("%s: opcode 0x%x, matrix id %d\n", |
| 3275 | __func__, route->hdr.opcode, route->matrix_id); |
| 3276 | } |
| 3277 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3278 | /** |
| 3279 | * adm_matrix_map - |
| 3280 | * command to send ADM matrix map for ADM copp list |
| 3281 | * |
| 3282 | * @path: direction or ADM path type |
| 3283 | * @payload_map: have info of session id and associated copp_idx/num_copps |
| 3284 | * @perf_mode: performance mode like LL/ULL/.. |
| 3285 | * @passthr_mode: flag to indicate passthrough mode |
| 3286 | * |
| 3287 | * Returns 0 on success or error on failure |
| 3288 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3289 | int adm_matrix_map(int path, struct route_payload payload_map, int perf_mode, |
| 3290 | uint32_t passthr_mode) |
| 3291 | { |
| 3292 | struct adm_cmd_matrix_map_routings_v5 *route; |
| 3293 | struct adm_session_map_node_v5 *node; |
| 3294 | uint16_t *copps_list; |
| 3295 | int cmd_size = 0; |
| 3296 | int ret = 0, i = 0; |
| 3297 | void *payload = NULL; |
| 3298 | void *matrix_map = NULL; |
| 3299 | int port_idx, copp_idx; |
| 3300 | |
| 3301 | /* Assumes port_ids have already been validated during adm_open */ |
| 3302 | cmd_size = (sizeof(struct adm_cmd_matrix_map_routings_v5) + |
| 3303 | sizeof(struct adm_session_map_node_v5) + |
| 3304 | (sizeof(uint32_t) * payload_map.num_copps)); |
| 3305 | matrix_map = kzalloc(cmd_size, GFP_KERNEL); |
| 3306 | if (matrix_map == NULL) { |
| 3307 | pr_err("%s: Mem alloc failed\n", __func__); |
| 3308 | ret = -EINVAL; |
| 3309 | return ret; |
| 3310 | } |
| 3311 | route = (struct adm_cmd_matrix_map_routings_v5 *)matrix_map; |
| 3312 | |
| 3313 | route->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3314 | APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); |
| 3315 | route->hdr.pkt_size = cmd_size; |
| 3316 | route->hdr.src_svc = 0; |
| 3317 | route->hdr.src_domain = APR_DOMAIN_APPS; |
| 3318 | route->hdr.src_port = 0; /* Ignored */; |
| 3319 | route->hdr.dest_svc = APR_SVC_ADM; |
| 3320 | route->hdr.dest_domain = APR_DOMAIN_ADSP; |
| 3321 | route->hdr.dest_port = 0; /* Ignored */; |
| 3322 | route->hdr.token = 0; |
| 3323 | route->num_sessions = 1; |
| 3324 | route_set_opcode_matrix_id(&route, path, passthr_mode); |
| 3325 | |
| 3326 | payload = ((u8 *)matrix_map + |
| 3327 | sizeof(struct adm_cmd_matrix_map_routings_v5)); |
| 3328 | node = (struct adm_session_map_node_v5 *)payload; |
| 3329 | |
| 3330 | node->session_id = payload_map.session_id; |
| 3331 | node->num_copps = payload_map.num_copps; |
| 3332 | payload = (u8 *)node + sizeof(struct adm_session_map_node_v5); |
| 3333 | copps_list = (uint16_t *)payload; |
| 3334 | for (i = 0; i < payload_map.num_copps; i++) { |
| 3335 | port_idx = |
| 3336 | adm_validate_and_get_port_index(payload_map.port_id[i]); |
| 3337 | if (port_idx < 0) { |
| 3338 | pr_err("%s: Invalid port_id 0x%x\n", __func__, |
| 3339 | payload_map.port_id[i]); |
| 3340 | ret = -EINVAL; |
| 3341 | goto fail_cmd; |
| 3342 | } |
| 3343 | copp_idx = payload_map.copp_idx[i]; |
| 3344 | copps_list[i] = atomic_read(&this_adm.copp.id[port_idx] |
| 3345 | [copp_idx]); |
| 3346 | } |
| 3347 | atomic_set(&this_adm.matrix_map_stat, -1); |
| 3348 | |
| 3349 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)matrix_map); |
| 3350 | if (ret < 0) { |
| 3351 | pr_err("%s: routing for syream %d failed ret %d\n", |
| 3352 | __func__, payload_map.session_id, ret); |
| 3353 | ret = -EINVAL; |
| 3354 | goto fail_cmd; |
| 3355 | } |
| 3356 | ret = wait_event_timeout(this_adm.matrix_map_wait, |
| 3357 | atomic_read(&this_adm.matrix_map_stat) >= 0, |
| 3358 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3359 | if (!ret) { |
| 3360 | pr_err("%s: routing for syream %d failed\n", __func__, |
| 3361 | payload_map.session_id); |
| 3362 | ret = -EINVAL; |
| 3363 | goto fail_cmd; |
| 3364 | } else if (atomic_read(&this_adm.matrix_map_stat) > 0) { |
| 3365 | pr_err("%s: DSP returned error[%s]\n", __func__, |
| 3366 | adsp_err_get_err_str(atomic_read( |
| 3367 | &this_adm.matrix_map_stat))); |
| 3368 | ret = adsp_err_get_lnx_err_code( |
| 3369 | atomic_read(&this_adm.matrix_map_stat)); |
| 3370 | goto fail_cmd; |
| 3371 | } |
| 3372 | |
| 3373 | if ((perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) && |
| 3374 | (path != ADM_PATH_COMPRESSED_RX)) { |
| 3375 | for (i = 0; i < payload_map.num_copps; i++) { |
| 3376 | port_idx = afe_get_port_index(payload_map.port_id[i]); |
| 3377 | copp_idx = payload_map.copp_idx[i]; |
| 3378 | if (port_idx < 0 || copp_idx < 0 || |
| 3379 | (copp_idx > MAX_COPPS_PER_PORT - 1)) { |
| 3380 | pr_err("%s: Invalid idx port_idx %d copp_idx %d\n", |
| 3381 | __func__, port_idx, copp_idx); |
| 3382 | continue; |
| 3383 | } |
| 3384 | rtac_add_adm_device(payload_map.port_id[i], |
| 3385 | atomic_read(&this_adm.copp.id |
| 3386 | [port_idx][copp_idx]), |
| 3387 | get_cal_path(path), |
| 3388 | payload_map.session_id, |
| 3389 | payload_map.app_type[i], |
| 3390 | payload_map.acdb_dev_id[i]); |
| 3391 | |
| 3392 | if (!test_bit(ADM_STATUS_CALIBRATION_REQUIRED, |
| 3393 | (void *)&this_adm.copp.adm_status[port_idx] |
| 3394 | [copp_idx])) { |
| 3395 | pr_debug("%s: adm copp[0x%x][%d] already sent", |
| 3396 | __func__, port_idx, copp_idx); |
| 3397 | continue; |
| 3398 | } |
| 3399 | send_adm_cal(payload_map.port_id[i], copp_idx, |
| 3400 | get_cal_path(path), perf_mode, |
| 3401 | payload_map.app_type[i], |
| 3402 | payload_map.acdb_dev_id[i], |
Aditya Bavanari | 5106b56 | 2018-01-08 13:16:32 +0530 | [diff] [blame] | 3403 | payload_map.sample_rate[i], |
| 3404 | passthr_mode); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3405 | /* ADM COPP calibration is already sent */ |
| 3406 | clear_bit(ADM_STATUS_CALIBRATION_REQUIRED, |
| 3407 | (void *)&this_adm.copp. |
| 3408 | adm_status[port_idx][copp_idx]); |
| 3409 | pr_debug("%s: copp_id: %d\n", __func__, |
| 3410 | atomic_read(&this_adm.copp.id[port_idx] |
| 3411 | [copp_idx])); |
| 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | fail_cmd: |
| 3416 | kfree(matrix_map); |
| 3417 | return ret; |
| 3418 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3419 | EXPORT_SYMBOL(adm_matrix_map); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3420 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3421 | /** |
| 3422 | * adm_ec_ref_rx_id - |
| 3423 | * Update EC ref port ID |
| 3424 | * |
| 3425 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3426 | void adm_ec_ref_rx_id(int port_id) |
| 3427 | { |
| 3428 | this_adm.ec_ref_rx = port_id; |
| 3429 | pr_debug("%s: ec_ref_rx:%d\n", __func__, this_adm.ec_ref_rx); |
| 3430 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3431 | EXPORT_SYMBOL(adm_ec_ref_rx_id); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3432 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3433 | /** |
| 3434 | * adm_num_ec_ref_rx_chans - |
| 3435 | * Update EC ref number of channels |
| 3436 | * |
| 3437 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3438 | void adm_num_ec_ref_rx_chans(int num_chans) |
| 3439 | { |
| 3440 | this_adm.num_ec_ref_rx_chans = num_chans; |
| 3441 | pr_debug("%s: num_ec_ref_rx_chans:%d\n", |
| 3442 | __func__, this_adm.num_ec_ref_rx_chans); |
| 3443 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3444 | EXPORT_SYMBOL(adm_num_ec_ref_rx_chans); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3445 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3446 | /** |
| 3447 | * adm_ec_ref_rx_bit_width - |
| 3448 | * Update EC ref bit_width |
| 3449 | * |
| 3450 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3451 | void adm_ec_ref_rx_bit_width(int bit_width) |
| 3452 | { |
| 3453 | this_adm.ec_ref_rx_bit_width = bit_width; |
| 3454 | pr_debug("%s: ec_ref_rx_bit_width:%d\n", |
| 3455 | __func__, this_adm.ec_ref_rx_bit_width); |
| 3456 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3457 | EXPORT_SYMBOL(adm_ec_ref_rx_bit_width); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3458 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3459 | /** |
| 3460 | * adm_ec_ref_rx_sampling_rate - |
| 3461 | * Update EC ref sample rate |
| 3462 | * |
| 3463 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3464 | void adm_ec_ref_rx_sampling_rate(int sampling_rate) |
| 3465 | { |
| 3466 | this_adm.ec_ref_rx_sampling_rate = sampling_rate; |
| 3467 | pr_debug("%s: ec_ref_rx_sampling_rate:%d\n", |
| 3468 | __func__, this_adm.ec_ref_rx_sampling_rate); |
| 3469 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3470 | EXPORT_SYMBOL(adm_ec_ref_rx_sampling_rate); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3471 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3472 | /** |
Dieter Luecking | 50c5535 | 2018-09-28 14:29:17 +0200 | [diff] [blame] | 3473 | * adm_set_native_mode - |
| 3474 | * Set adm channel native mode. |
| 3475 | * If enabled matrix mixer will be |
| 3476 | * running in native mode for channel |
| 3477 | * configuration for this device session. |
| 3478 | * |
| 3479 | */ |
| 3480 | void adm_set_native_mode(int mode) |
| 3481 | { |
| 3482 | this_adm.native_mode = mode; |
| 3483 | pr_debug("%s: enable native_mode :%d\n", |
| 3484 | __func__, this_adm.native_mode); |
| 3485 | } |
| 3486 | EXPORT_SYMBOL(adm_set_native_mode); |
| 3487 | |
| 3488 | /** |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3489 | * adm_close - |
| 3490 | * command to close ADM copp |
| 3491 | * |
| 3492 | * @port_id: Port ID number |
| 3493 | * @perf_mode: performance mode like LL/ULL/.. |
| 3494 | * @copp_idx: copp index assigned |
| 3495 | * |
| 3496 | * Returns 0 on success or error on failure |
| 3497 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3498 | int adm_close(int port_id, int perf_mode, int copp_idx) |
| 3499 | { |
| 3500 | struct apr_hdr close; |
| 3501 | |
| 3502 | int ret = 0, port_idx; |
| 3503 | int copp_id = RESET_COPP_ID; |
| 3504 | |
| 3505 | pr_debug("%s: port_id=0x%x perf_mode: %d copp_idx: %d\n", __func__, |
| 3506 | port_id, perf_mode, copp_idx); |
| 3507 | |
| 3508 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 3509 | port_idx = adm_validate_and_get_port_index(port_id); |
| 3510 | if (port_idx < 0) { |
| 3511 | pr_err("%s: Invalid port_id 0x%x\n", |
| 3512 | __func__, port_id); |
| 3513 | return -EINVAL; |
| 3514 | } |
| 3515 | |
| 3516 | if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) { |
| 3517 | pr_err("%s: Invalid copp idx: %d\n", __func__, copp_idx); |
| 3518 | return -EINVAL; |
| 3519 | } |
| 3520 | |
| 3521 | if (this_adm.copp.adm_delay[port_idx][copp_idx] && perf_mode |
| 3522 | == LEGACY_PCM_MODE) { |
| 3523 | atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], |
| 3524 | 1); |
| 3525 | this_adm.copp.adm_delay[port_idx][copp_idx] = 0; |
| 3526 | wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]); |
| 3527 | } |
| 3528 | |
| 3529 | atomic_dec(&this_adm.copp.cnt[port_idx][copp_idx]); |
| 3530 | if (!(atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]))) { |
| 3531 | copp_id = adm_get_copp_id(port_idx, copp_idx); |
| 3532 | pr_debug("%s: Closing ADM port_idx:%d copp_idx:%d copp_id:0x%x\n", |
| 3533 | __func__, port_idx, copp_idx, copp_id); |
| 3534 | if ((!perf_mode) && (this_adm.outband_memmap.paddr != 0) && |
| 3535 | (atomic_read(&this_adm.copp.topology[port_idx][copp_idx]) == |
| 3536 | SRS_TRUMEDIA_TOPOLOGY_ID)) { |
| 3537 | atomic_set(&this_adm.mem_map_index, |
| 3538 | ADM_SRS_TRUMEDIA); |
| 3539 | ret = adm_memory_unmap_regions(); |
| 3540 | if (ret < 0) { |
| 3541 | pr_err("%s: adm mem unmmap err %d", |
| 3542 | __func__, ret); |
| 3543 | } else { |
| 3544 | atomic_set(&this_adm.mem_map_handles |
| 3545 | [ADM_SRS_TRUMEDIA], 0); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | |
| 3550 | if ((afe_get_port_type(port_id) == MSM_AFE_PORT_TYPE_TX) && |
| 3551 | this_adm.sourceTrackingData.memmap.paddr) { |
| 3552 | atomic_set(&this_adm.mem_map_index, |
| 3553 | ADM_MEM_MAP_INDEX_SOURCE_TRACKING); |
| 3554 | ret = adm_memory_unmap_regions(); |
| 3555 | if (ret < 0) { |
| 3556 | pr_err("%s: adm mem unmmap err %d", |
| 3557 | __func__, ret); |
| 3558 | } |
| 3559 | msm_audio_ion_free( |
Banajit Goswami | 08bb736 | 2017-11-03 22:48:23 -0700 | [diff] [blame] | 3560 | this_adm.sourceTrackingData.dma_buf); |
| 3561 | this_adm.sourceTrackingData.dma_buf = NULL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3562 | this_adm.sourceTrackingData.memmap.size = 0; |
| 3563 | this_adm.sourceTrackingData.memmap.kvaddr = NULL; |
| 3564 | this_adm.sourceTrackingData.memmap.paddr = 0; |
| 3565 | this_adm.sourceTrackingData.apr_cmd_status = -1; |
| 3566 | atomic_set(&this_adm.mem_map_handles[ |
| 3567 | ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0); |
| 3568 | } |
| 3569 | |
| 3570 | close.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, |
| 3571 | APR_HDR_LEN(APR_HDR_SIZE), |
| 3572 | APR_PKT_VER); |
| 3573 | close.pkt_size = sizeof(close); |
| 3574 | close.src_svc = APR_SVC_ADM; |
| 3575 | close.src_domain = APR_DOMAIN_APPS; |
| 3576 | close.src_port = port_id; |
| 3577 | close.dest_svc = APR_SVC_ADM; |
| 3578 | close.dest_domain = APR_DOMAIN_ADSP; |
| 3579 | close.dest_port = copp_id; |
| 3580 | close.token = port_idx << 16 | copp_idx; |
| 3581 | close.opcode = ADM_CMD_DEVICE_CLOSE_V5; |
| 3582 | |
| 3583 | atomic_set(&this_adm.copp.id[port_idx][copp_idx], |
| 3584 | RESET_COPP_ID); |
| 3585 | atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0); |
| 3586 | atomic_set(&this_adm.copp.topology[port_idx][copp_idx], 0); |
| 3587 | atomic_set(&this_adm.copp.mode[port_idx][copp_idx], 0); |
| 3588 | atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); |
| 3589 | atomic_set(&this_adm.copp.rate[port_idx][copp_idx], 0); |
| 3590 | atomic_set(&this_adm.copp.channels[port_idx][copp_idx], 0); |
| 3591 | atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx], 0); |
| 3592 | atomic_set(&this_adm.copp.app_type[port_idx][copp_idx], 0); |
Surendar Karka | e750751 | 2018-07-20 15:46:54 +0530 | [diff] [blame^] | 3593 | atomic_set(&this_adm.copp.session_type[port_idx][copp_idx], 0); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3594 | |
| 3595 | clear_bit(ADM_STATUS_CALIBRATION_REQUIRED, |
| 3596 | (void *)&this_adm.copp.adm_status[port_idx][copp_idx]); |
| 3597 | |
| 3598 | ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close); |
| 3599 | if (ret < 0) { |
| 3600 | pr_err("%s: ADM close failed %d\n", __func__, ret); |
| 3601 | return -EINVAL; |
| 3602 | } |
| 3603 | |
| 3604 | ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], |
| 3605 | atomic_read(&this_adm.copp.stat |
| 3606 | [port_idx][copp_idx]) >= 0, |
| 3607 | msecs_to_jiffies(TIMEOUT_MS)); |
| 3608 | if (!ret) { |
| 3609 | pr_err("%s: ADM cmd Route timedout for port 0x%x\n", |
| 3610 | __func__, port_id); |
| 3611 | return -EINVAL; |
| 3612 | } else if (atomic_read(&this_adm.copp.stat |
| 3613 | [port_idx][copp_idx]) > 0) { |
| 3614 | pr_err("%s: DSP returned error[%s]\n", |
| 3615 | __func__, adsp_err_get_err_str( |
| 3616 | atomic_read(&this_adm.copp.stat |
| 3617 | [port_idx][copp_idx]))); |
| 3618 | return adsp_err_get_lnx_err_code( |
| 3619 | atomic_read(&this_adm.copp.stat |
| 3620 | [port_idx][copp_idx])); |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) { |
| 3625 | pr_debug("%s: remove adm device from rtac\n", __func__); |
| 3626 | rtac_remove_adm_device(port_id, copp_id); |
| 3627 | } |
| 3628 | return 0; |
| 3629 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 3630 | EXPORT_SYMBOL(adm_close); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3631 | |
| 3632 | int send_rtac_audvol_cal(void) |
| 3633 | { |
| 3634 | int ret = 0; |
| 3635 | int ret2 = 0; |
| 3636 | int i = 0; |
| 3637 | int copp_idx, port_idx, acdb_id, app_id, path; |
| 3638 | struct cal_block_data *cal_block = NULL; |
| 3639 | struct audio_cal_info_audvol *audvol_cal_info = NULL; |
| 3640 | struct rtac_adm rtac_adm_data; |
| 3641 | |
| 3642 | mutex_lock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock); |
| 3643 | |
| 3644 | cal_block = cal_utils_get_only_cal_block( |
| 3645 | this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]); |
Vikram Panduranga | 770b838 | 2017-09-27 12:17:36 -0700 | [diff] [blame] | 3646 | if (cal_block == NULL || cal_utils_is_cal_stale(cal_block)) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3647 | pr_err("%s: can't find cal block!\n", __func__); |
| 3648 | goto unlock; |
| 3649 | } |
| 3650 | |
| 3651 | audvol_cal_info = cal_block->cal_info; |
| 3652 | if (audvol_cal_info == NULL) { |
| 3653 | pr_err("%s: audvol_cal_info is NULL!\n", __func__); |
| 3654 | goto unlock; |
| 3655 | } |
| 3656 | |
| 3657 | get_rtac_adm_data(&rtac_adm_data); |
| 3658 | for (; i < rtac_adm_data.num_of_dev; i++) { |
| 3659 | |
| 3660 | acdb_id = rtac_adm_data.device[i].acdb_dev_id; |
| 3661 | if (acdb_id == 0) |
| 3662 | acdb_id = audvol_cal_info->acdb_id; |
| 3663 | |
| 3664 | app_id = rtac_adm_data.device[i].app_type; |
| 3665 | if (app_id == 0) |
| 3666 | app_id = audvol_cal_info->app_type; |
| 3667 | |
| 3668 | path = afe_get_port_type(rtac_adm_data.device[i].afe_port); |
| 3669 | if ((acdb_id == audvol_cal_info->acdb_id) && |
| 3670 | (app_id == audvol_cal_info->app_type) && |
| 3671 | (path == audvol_cal_info->path)) { |
| 3672 | |
| 3673 | if (adm_get_indexes_from_copp_id(rtac_adm_data. |
| 3674 | device[i].copp, &copp_idx, &port_idx) != 0) { |
| 3675 | pr_debug("%s: Copp Id %d is not active\n", |
| 3676 | __func__, |
| 3677 | rtac_adm_data.device[i].copp); |
| 3678 | continue; |
| 3679 | } |
| 3680 | |
| 3681 | ret2 = adm_remap_and_send_cal_block(ADM_RTAC_AUDVOL_CAL, |
| 3682 | rtac_adm_data.device[i].afe_port, |
| 3683 | copp_idx, cal_block, |
| 3684 | atomic_read(&this_adm.copp. |
| 3685 | mode[port_idx][copp_idx]), |
| 3686 | audvol_cal_info->app_type, |
| 3687 | audvol_cal_info->acdb_id, |
| 3688 | atomic_read(&this_adm.copp. |
| 3689 | rate[port_idx][copp_idx])); |
| 3690 | if (ret2 < 0) { |
| 3691 | pr_debug("%s: remap and send failed for copp Id %d, acdb id %d, app type %d, path %d\n", |
| 3692 | __func__, rtac_adm_data.device[i].copp, |
| 3693 | audvol_cal_info->acdb_id, |
| 3694 | audvol_cal_info->app_type, |
| 3695 | audvol_cal_info->path); |
| 3696 | ret = ret2; |
| 3697 | } |
| 3698 | } |
| 3699 | } |
| 3700 | unlock: |
| 3701 | mutex_unlock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock); |
| 3702 | return ret; |
| 3703 | } |
| 3704 | |
| 3705 | int adm_map_rtac_block(struct rtac_cal_block_data *cal_block) |
| 3706 | { |
| 3707 | int result = 0; |
| 3708 | |
| 3709 | pr_debug("%s:\n", __func__); |
| 3710 | |
| 3711 | if (cal_block == NULL) { |
| 3712 | pr_err("%s: cal_block is NULL!\n", |
| 3713 | __func__); |
| 3714 | result = -EINVAL; |
| 3715 | goto done; |
| 3716 | } |
| 3717 | |
| 3718 | if (cal_block->cal_data.paddr == 0) { |
| 3719 | pr_debug("%s: No address to map!\n", |
| 3720 | __func__); |
| 3721 | result = -EINVAL; |
| 3722 | goto done; |
| 3723 | } |
| 3724 | |
| 3725 | if (cal_block->map_data.map_size == 0) { |
| 3726 | pr_debug("%s: map size is 0!\n", |
| 3727 | __func__); |
| 3728 | result = -EINVAL; |
| 3729 | goto done; |
| 3730 | } |
| 3731 | |
| 3732 | /* valid port ID needed for callback use primary I2S */ |
| 3733 | atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL); |
| 3734 | result = adm_memory_map_regions(&cal_block->cal_data.paddr, 0, |
| 3735 | &cal_block->map_data.map_size, 1); |
| 3736 | if (result < 0) { |
| 3737 | pr_err("%s: RTAC mmap did not work! size = %d result %d\n", |
| 3738 | __func__, |
| 3739 | cal_block->map_data.map_size, result); |
| 3740 | pr_debug("%s: RTAC mmap did not work! addr = 0x%pK, size = %d\n", |
| 3741 | __func__, |
| 3742 | &cal_block->cal_data.paddr, |
| 3743 | cal_block->map_data.map_size); |
| 3744 | goto done; |
| 3745 | } |
| 3746 | |
| 3747 | cal_block->map_data.map_handle = atomic_read( |
| 3748 | &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]); |
| 3749 | done: |
| 3750 | return result; |
| 3751 | } |
| 3752 | |
| 3753 | int adm_unmap_rtac_block(uint32_t *mem_map_handle) |
| 3754 | { |
| 3755 | int result = 0; |
| 3756 | |
| 3757 | pr_debug("%s:\n", __func__); |
| 3758 | |
| 3759 | if (mem_map_handle == NULL) { |
| 3760 | pr_debug("%s: Map handle is NULL, nothing to unmap\n", |
| 3761 | __func__); |
| 3762 | goto done; |
| 3763 | } |
| 3764 | |
| 3765 | if (*mem_map_handle == 0) { |
| 3766 | pr_debug("%s: Map handle is 0, nothing to unmap\n", |
| 3767 | __func__); |
| 3768 | goto done; |
| 3769 | } |
| 3770 | |
| 3771 | if (*mem_map_handle != atomic_read( |
| 3772 | &this_adm.mem_map_handles[ADM_RTAC_APR_CAL])) { |
| 3773 | pr_err("%s: Map handles do not match! Unmapping RTAC, RTAC map 0x%x, ADM map 0x%x\n", |
| 3774 | __func__, *mem_map_handle, atomic_read( |
| 3775 | &this_adm.mem_map_handles[ADM_RTAC_APR_CAL])); |
| 3776 | |
| 3777 | /* if mismatch use handle passed in to unmap */ |
| 3778 | atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL], |
| 3779 | *mem_map_handle); |
| 3780 | } |
| 3781 | |
| 3782 | /* valid port ID needed for callback use primary I2S */ |
| 3783 | atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL); |
| 3784 | result = adm_memory_unmap_regions(); |
| 3785 | if (result < 0) { |
| 3786 | pr_debug("%s: adm_memory_unmap_regions failed, error %d\n", |
| 3787 | __func__, result); |
| 3788 | } else { |
| 3789 | atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL], 0); |
| 3790 | *mem_map_handle = 0; |
| 3791 | } |
| 3792 | done: |
| 3793 | return result; |
| 3794 | } |
| 3795 | |
| 3796 | static int get_cal_type_index(int32_t cal_type) |
| 3797 | { |
| 3798 | int ret = -EINVAL; |
| 3799 | |
| 3800 | switch (cal_type) { |
| 3801 | case ADM_AUDPROC_CAL_TYPE: |
| 3802 | ret = ADM_AUDPROC_CAL; |
| 3803 | break; |
Aditya Bavanari | 2a627ae | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 3804 | case ADM_LSM_AUDPROC_CAL_TYPE: |
| 3805 | ret = ADM_LSM_AUDPROC_CAL; |
| 3806 | break; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3807 | case ADM_AUDVOL_CAL_TYPE: |
| 3808 | ret = ADM_AUDVOL_CAL; |
| 3809 | break; |
| 3810 | case ADM_CUST_TOPOLOGY_CAL_TYPE: |
| 3811 | ret = ADM_CUSTOM_TOP_CAL; |
| 3812 | break; |
| 3813 | case ADM_RTAC_INFO_CAL_TYPE: |
| 3814 | ret = ADM_RTAC_INFO_CAL; |
| 3815 | break; |
| 3816 | case ADM_RTAC_APR_CAL_TYPE: |
| 3817 | ret = ADM_RTAC_APR_CAL; |
| 3818 | break; |
| 3819 | case ADM_RTAC_AUDVOL_CAL_TYPE: |
| 3820 | ret = ADM_RTAC_AUDVOL_CAL; |
| 3821 | break; |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 3822 | case ADM_LSM_AUDPROC_PERSISTENT_CAL_TYPE: |
| 3823 | ret = ADM_LSM_AUDPROC_PERSISTENT_CAL; |
| 3824 | break; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3825 | default: |
| 3826 | pr_err("%s: invalid cal type %d!\n", __func__, cal_type); |
| 3827 | } |
| 3828 | return ret; |
| 3829 | } |
| 3830 | |
| 3831 | static int adm_alloc_cal(int32_t cal_type, size_t data_size, void *data) |
| 3832 | { |
| 3833 | int ret = 0; |
| 3834 | int cal_index; |
| 3835 | |
| 3836 | pr_debug("%s:\n", __func__); |
| 3837 | |
| 3838 | cal_index = get_cal_type_index(cal_type); |
| 3839 | if (cal_index < 0) { |
| 3840 | pr_err("%s: could not get cal index %d!\n", |
| 3841 | __func__, cal_index); |
| 3842 | ret = -EINVAL; |
| 3843 | goto done; |
| 3844 | } |
| 3845 | |
| 3846 | ret = cal_utils_alloc_cal(data_size, data, |
| 3847 | this_adm.cal_data[cal_index], 0, NULL); |
| 3848 | if (ret < 0) { |
| 3849 | pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n", |
| 3850 | __func__, ret, cal_type); |
| 3851 | ret = -EINVAL; |
| 3852 | goto done; |
| 3853 | } |
| 3854 | done: |
| 3855 | return ret; |
| 3856 | } |
| 3857 | |
| 3858 | static int adm_dealloc_cal(int32_t cal_type, size_t data_size, void *data) |
| 3859 | { |
| 3860 | int ret = 0; |
| 3861 | int cal_index; |
| 3862 | |
| 3863 | pr_debug("%s:\n", __func__); |
| 3864 | |
| 3865 | cal_index = get_cal_type_index(cal_type); |
| 3866 | if (cal_index < 0) { |
| 3867 | pr_err("%s: could not get cal index %d!\n", |
| 3868 | __func__, cal_index); |
| 3869 | ret = -EINVAL; |
| 3870 | goto done; |
| 3871 | } |
| 3872 | |
| 3873 | ret = cal_utils_dealloc_cal(data_size, data, |
| 3874 | this_adm.cal_data[cal_index]); |
| 3875 | if (ret < 0) { |
| 3876 | pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n", |
| 3877 | __func__, ret, cal_type); |
| 3878 | ret = -EINVAL; |
| 3879 | goto done; |
| 3880 | } |
| 3881 | done: |
| 3882 | return ret; |
| 3883 | } |
| 3884 | |
| 3885 | static int adm_set_cal(int32_t cal_type, size_t data_size, void *data) |
| 3886 | { |
| 3887 | int ret = 0; |
| 3888 | int cal_index; |
| 3889 | |
| 3890 | pr_debug("%s:\n", __func__); |
| 3891 | |
| 3892 | cal_index = get_cal_type_index(cal_type); |
| 3893 | if (cal_index < 0) { |
| 3894 | pr_err("%s: could not get cal index %d!\n", |
| 3895 | __func__, cal_index); |
| 3896 | ret = -EINVAL; |
| 3897 | goto done; |
| 3898 | } |
| 3899 | |
| 3900 | ret = cal_utils_set_cal(data_size, data, |
| 3901 | this_adm.cal_data[cal_index], 0, NULL); |
| 3902 | if (ret < 0) { |
| 3903 | pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n", |
| 3904 | __func__, ret, cal_type); |
| 3905 | ret = -EINVAL; |
| 3906 | goto done; |
| 3907 | } |
| 3908 | |
| 3909 | if (cal_index == ADM_CUSTOM_TOP_CAL) { |
| 3910 | mutex_lock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock); |
| 3911 | this_adm.set_custom_topology = 1; |
| 3912 | mutex_unlock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock); |
| 3913 | } else if (cal_index == ADM_RTAC_AUDVOL_CAL) { |
| 3914 | send_rtac_audvol_cal(); |
| 3915 | } |
| 3916 | done: |
| 3917 | return ret; |
| 3918 | } |
| 3919 | |
| 3920 | static int adm_map_cal_data(int32_t cal_type, |
| 3921 | struct cal_block_data *cal_block) |
| 3922 | { |
| 3923 | int ret = 0; |
| 3924 | int cal_index; |
| 3925 | |
| 3926 | pr_debug("%s:\n", __func__); |
| 3927 | |
| 3928 | cal_index = get_cal_type_index(cal_type); |
| 3929 | if (cal_index < 0) { |
| 3930 | pr_err("%s: could not get cal index %d!\n", |
| 3931 | __func__, cal_index); |
| 3932 | ret = -EINVAL; |
| 3933 | goto done; |
| 3934 | } |
| 3935 | |
| 3936 | atomic_set(&this_adm.mem_map_index, cal_index); |
| 3937 | ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0, |
| 3938 | (uint32_t *)&cal_block->map_data.map_size, 1); |
| 3939 | if (ret < 0) { |
| 3940 | pr_err("%s: map did not work! cal_type %i ret %d\n", |
| 3941 | __func__, cal_index, ret); |
| 3942 | ret = -ENODEV; |
| 3943 | goto done; |
| 3944 | } |
| 3945 | cal_block->map_data.q6map_handle = atomic_read(&this_adm. |
| 3946 | mem_map_handles[cal_index]); |
| 3947 | done: |
| 3948 | return ret; |
| 3949 | } |
| 3950 | |
| 3951 | static int adm_unmap_cal_data(int32_t cal_type, |
| 3952 | struct cal_block_data *cal_block) |
| 3953 | { |
| 3954 | int ret = 0; |
| 3955 | int cal_index; |
| 3956 | |
| 3957 | pr_debug("%s:\n", __func__); |
| 3958 | |
| 3959 | cal_index = get_cal_type_index(cal_type); |
| 3960 | if (cal_index < 0) { |
| 3961 | pr_err("%s: could not get cal index %d!\n", |
| 3962 | __func__, cal_index); |
| 3963 | ret = -EINVAL; |
| 3964 | goto done; |
| 3965 | } |
| 3966 | |
| 3967 | if (cal_block == NULL) { |
| 3968 | pr_err("%s: Cal block is NULL!\n", |
| 3969 | __func__); |
| 3970 | goto done; |
| 3971 | } |
| 3972 | |
| 3973 | if (cal_block->map_data.q6map_handle == 0) { |
| 3974 | pr_err("%s: Map handle is NULL, nothing to unmap\n", |
| 3975 | __func__); |
| 3976 | goto done; |
| 3977 | } |
| 3978 | |
| 3979 | atomic_set(&this_adm.mem_map_handles[cal_index], |
| 3980 | cal_block->map_data.q6map_handle); |
| 3981 | atomic_set(&this_adm.mem_map_index, cal_index); |
| 3982 | ret = adm_memory_unmap_regions(); |
| 3983 | if (ret < 0) { |
| 3984 | pr_err("%s: unmap did not work! cal_type %i ret %d\n", |
| 3985 | __func__, cal_index, ret); |
| 3986 | ret = -ENODEV; |
| 3987 | goto done; |
| 3988 | } |
| 3989 | cal_block->map_data.q6map_handle = 0; |
| 3990 | done: |
| 3991 | return ret; |
| 3992 | } |
| 3993 | |
| 3994 | static void adm_delete_cal_data(void) |
| 3995 | { |
| 3996 | pr_debug("%s:\n", __func__); |
| 3997 | |
| 3998 | cal_utils_destroy_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data); |
| 3999 | } |
| 4000 | |
| 4001 | static int adm_init_cal_data(void) |
| 4002 | { |
| 4003 | int ret = 0; |
| 4004 | struct cal_type_info cal_type_info[] = { |
| 4005 | {{ADM_CUST_TOPOLOGY_CAL_TYPE, |
| 4006 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 4007 | adm_set_cal, NULL, NULL} }, |
| 4008 | {adm_map_cal_data, adm_unmap_cal_data, |
| 4009 | cal_utils_match_buf_num} }, |
| 4010 | |
| 4011 | {{ADM_AUDPROC_CAL_TYPE, |
| 4012 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 4013 | adm_set_cal, NULL, NULL} }, |
| 4014 | {adm_map_cal_data, adm_unmap_cal_data, |
| 4015 | cal_utils_match_buf_num} }, |
| 4016 | |
Aditya Bavanari | 2a627ae | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 4017 | {{ADM_LSM_AUDPROC_CAL_TYPE, |
| 4018 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 4019 | adm_set_cal, NULL, NULL} }, |
| 4020 | {adm_map_cal_data, adm_unmap_cal_data, |
| 4021 | cal_utils_match_buf_num} }, |
| 4022 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4023 | {{ADM_AUDVOL_CAL_TYPE, |
| 4024 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 4025 | adm_set_cal, NULL, NULL} }, |
| 4026 | {adm_map_cal_data, adm_unmap_cal_data, |
| 4027 | cal_utils_match_buf_num} }, |
| 4028 | |
| 4029 | {{ADM_RTAC_INFO_CAL_TYPE, |
| 4030 | {NULL, NULL, NULL, NULL, NULL, NULL} }, |
| 4031 | {NULL, NULL, cal_utils_match_buf_num} }, |
| 4032 | |
| 4033 | {{ADM_RTAC_APR_CAL_TYPE, |
| 4034 | {NULL, NULL, NULL, NULL, NULL, NULL} }, |
| 4035 | {NULL, NULL, cal_utils_match_buf_num} }, |
| 4036 | |
| 4037 | {{SRS_TRUMEDIA_CAL_TYPE, |
| 4038 | {NULL, NULL, NULL, NULL, NULL, NULL} }, |
| 4039 | {NULL, NULL, cal_utils_match_buf_num} }, |
| 4040 | |
| 4041 | {{ADM_RTAC_AUDVOL_CAL_TYPE, |
| 4042 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 4043 | adm_set_cal, NULL, NULL} }, |
| 4044 | {adm_map_cal_data, adm_unmap_cal_data, |
| 4045 | cal_utils_match_buf_num} }, |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 4046 | |
| 4047 | {{ADM_LSM_AUDPROC_PERSISTENT_CAL_TYPE, |
| 4048 | {adm_alloc_cal, adm_dealloc_cal, NULL, |
| 4049 | adm_set_cal, NULL, NULL} }, |
| 4050 | {adm_map_cal_data, adm_unmap_cal_data, |
| 4051 | cal_utils_match_buf_num} }, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4052 | }; |
| 4053 | pr_debug("%s:\n", __func__); |
| 4054 | |
| 4055 | ret = cal_utils_create_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data, |
| 4056 | cal_type_info); |
| 4057 | if (ret < 0) { |
| 4058 | pr_err("%s: could not create cal type! ret %d\n", |
| 4059 | __func__, ret); |
| 4060 | ret = -EINVAL; |
| 4061 | goto err; |
| 4062 | } |
| 4063 | |
| 4064 | return ret; |
| 4065 | err: |
| 4066 | adm_delete_cal_data(); |
| 4067 | return ret; |
| 4068 | } |
| 4069 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4070 | /** |
| 4071 | * adm_set_volume - |
| 4072 | * command to set volume on ADM copp |
| 4073 | * |
| 4074 | * @port_id: Port ID number |
| 4075 | * @copp_idx: copp index assigned |
| 4076 | * @volume: gain value to set |
| 4077 | * |
| 4078 | * Returns 0 on success or error on failure |
| 4079 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4080 | int adm_set_volume(int port_id, int copp_idx, int volume) |
| 4081 | { |
| 4082 | struct audproc_volume_ctrl_master_gain audproc_vol; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4083 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4084 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4085 | |
| 4086 | pr_debug("%s: port_id %d, volume %d\n", __func__, port_id, volume); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4087 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4088 | memset(&audproc_vol, 0, sizeof(audproc_vol)); |
| 4089 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4090 | param_hdr.module_id = AUDPROC_MODULE_ID_VOL_CTRL; |
| 4091 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4092 | param_hdr.param_id = AUDPROC_PARAM_ID_VOL_CTRL_MASTER_GAIN; |
| 4093 | param_hdr.param_size = sizeof(audproc_vol); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4094 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4095 | audproc_vol.master_gain = volume; |
| 4096 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4097 | rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4098 | (uint8_t *) &audproc_vol); |
| 4099 | if (rc) |
| 4100 | pr_err("%s: Failed to set volume, err %d\n", __func__, rc); |
| 4101 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4102 | return rc; |
| 4103 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4104 | EXPORT_SYMBOL(adm_set_volume); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4105 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4106 | /** |
| 4107 | * adm_set_softvolume - |
| 4108 | * command to set softvolume |
| 4109 | * |
| 4110 | * @port_id: Port ID number |
| 4111 | * @copp_idx: copp index assigned |
| 4112 | * @softvol_param: Params to set for softvolume |
| 4113 | * |
| 4114 | * Returns 0 on success or error on failure |
| 4115 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4116 | int adm_set_softvolume(int port_id, int copp_idx, |
| 4117 | struct audproc_softvolume_params *softvol_param) |
| 4118 | { |
| 4119 | struct audproc_soft_step_volume_params audproc_softvol; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4120 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4121 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4122 | |
| 4123 | pr_debug("%s: period %d step %d curve %d\n", __func__, |
| 4124 | softvol_param->period, softvol_param->step, |
| 4125 | softvol_param->rampingcurve); |
| 4126 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4127 | memset(&audproc_softvol, 0, sizeof(audproc_softvol)); |
| 4128 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4129 | param_hdr.module_id = AUDPROC_MODULE_ID_VOL_CTRL; |
| 4130 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4131 | param_hdr.param_id = AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS; |
| 4132 | param_hdr.param_size = sizeof(audproc_softvol); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4133 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4134 | audproc_softvol.period = softvol_param->period; |
| 4135 | audproc_softvol.step = softvol_param->step; |
| 4136 | audproc_softvol.ramping_curve = softvol_param->rampingcurve; |
| 4137 | |
| 4138 | pr_debug("%s: period %d, step %d, curve %d\n", __func__, |
| 4139 | audproc_softvol.period, audproc_softvol.step, |
| 4140 | audproc_softvol.ramping_curve); |
| 4141 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4142 | rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4143 | (uint8_t *) &audproc_softvol); |
| 4144 | if (rc) |
| 4145 | pr_err("%s: Failed to set soft volume, err %d\n", __func__, rc); |
| 4146 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4147 | return rc; |
| 4148 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4149 | EXPORT_SYMBOL(adm_set_softvolume); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4150 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4151 | /** |
| 4152 | * adm_set_mic_gain - |
| 4153 | * command to set MIC gain |
| 4154 | * |
| 4155 | * @port_id: Port ID number |
| 4156 | * @copp_idx: copp index assigned |
| 4157 | * @volume: gain value to set |
| 4158 | * |
| 4159 | * Returns 0 on success or error on failure |
| 4160 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4161 | int adm_set_mic_gain(int port_id, int copp_idx, int volume) |
| 4162 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4163 | struct admx_mic_gain mic_gain_params; |
| 4164 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4165 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4166 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4167 | pr_debug("%s: Setting mic gain to %d at port_id 0x%x\n", __func__, |
| 4168 | volume, port_id); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4169 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4170 | memset(&mic_gain_params, 0, sizeof(mic_gain_params)); |
| 4171 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4172 | param_hdr.module_id = ADM_MODULE_IDX_MIC_GAIN_CTRL; |
| 4173 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4174 | param_hdr.param_id = ADM_PARAM_IDX_MIC_GAIN; |
| 4175 | param_hdr.param_size = sizeof(mic_gain_params); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4176 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4177 | mic_gain_params.tx_mic_gain = volume; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4178 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4179 | rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4180 | (uint8_t *) &mic_gain_params); |
| 4181 | if (rc) |
| 4182 | pr_err("%s: Failed to set mic gain, err %d\n", __func__, rc); |
| 4183 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4184 | return rc; |
| 4185 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4186 | EXPORT_SYMBOL(adm_set_mic_gain); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4187 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4188 | /** |
| 4189 | * adm_send_set_multichannel_ec_primary_mic_ch - |
| 4190 | * command to set multi-ch EC primary mic |
| 4191 | * |
| 4192 | * @port_id: Port ID number |
| 4193 | * @copp_idx: copp index assigned |
| 4194 | * @primary_mic_ch: channel number of primary mic |
| 4195 | * |
| 4196 | * Returns 0 on success or error on failure |
| 4197 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4198 | int adm_send_set_multichannel_ec_primary_mic_ch(int port_id, int copp_idx, |
| 4199 | int primary_mic_ch) |
| 4200 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4201 | struct admx_sec_primary_mic_ch sec_primary_ch_params; |
| 4202 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4203 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4204 | |
| 4205 | pr_debug("%s port_id 0x%x, copp_idx 0x%x, primary_mic_ch %d\n", |
| 4206 | __func__, port_id, copp_idx, primary_mic_ch); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4207 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4208 | memset(&sec_primary_ch_params, 0, sizeof(sec_primary_ch_params)); |
| 4209 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4210 | param_hdr.module_id = AUDPROC_MODULE_ID_VOICE_TX_SECNS; |
| 4211 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4212 | param_hdr.param_id = AUDPROC_PARAM_IDX_SEC_PRIMARY_MIC_CH; |
| 4213 | param_hdr.param_size = sizeof(sec_primary_ch_params); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4214 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4215 | sec_primary_ch_params.version = 0; |
| 4216 | sec_primary_ch_params.sec_primary_mic_ch = primary_mic_ch; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4217 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4218 | rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4219 | (uint8_t *) &sec_primary_ch_params); |
| 4220 | if (rc) |
| 4221 | pr_err("%s: Failed to set primary mic chanel, err %d\n", |
| 4222 | __func__, rc); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4223 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4224 | return rc; |
| 4225 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4226 | EXPORT_SYMBOL(adm_send_set_multichannel_ec_primary_mic_ch); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4227 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4228 | /** |
| 4229 | * adm_param_enable - |
| 4230 | * command to send params to ADM for given module |
| 4231 | * |
| 4232 | * @port_id: Port ID number |
| 4233 | * @copp_idx: copp index assigned |
| 4234 | * @module_id: ADM module |
| 4235 | * @enable: flag to enable or disable module |
| 4236 | * |
| 4237 | * Returns 0 on success or error on failure |
| 4238 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4239 | int adm_param_enable(int port_id, int copp_idx, int module_id, int enable) |
| 4240 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4241 | struct module_instance_info mod_inst_info; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4242 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4243 | memset(&mod_inst_info, 0, sizeof(mod_inst_info)); |
| 4244 | mod_inst_info.module_id = module_id; |
| 4245 | mod_inst_info.instance_id = INSTANCE_ID_0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4246 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4247 | return adm_param_enable_v2(port_id, copp_idx, mod_inst_info, enable); |
| 4248 | } |
Vidyakumar Athota | 98464a2 | 2018-03-15 20:39:37 -0700 | [diff] [blame] | 4249 | EXPORT_SYMBOL(adm_param_enable); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4250 | |
| 4251 | /** |
| 4252 | * adm_param_enable_v2 - |
| 4253 | * command to send params to ADM for given module |
| 4254 | * |
| 4255 | * @port_id: Port ID number |
| 4256 | * @copp_idx: copp index assigned |
| 4257 | * @mod_inst_info: module and instance ID info |
| 4258 | * @enable: flag to enable or disable module |
| 4259 | * |
| 4260 | * Returns 0 on success or error on failure |
| 4261 | */ |
| 4262 | int adm_param_enable_v2(int port_id, int copp_idx, |
| 4263 | struct module_instance_info mod_inst_info, int enable) |
| 4264 | { |
| 4265 | uint32_t enable_param; |
| 4266 | struct param_hdr_v3 param_hdr; |
| 4267 | int rc = 0; |
| 4268 | |
| 4269 | if (enable < 0 || enable > 1) { |
| 4270 | pr_err("%s: Invalid value for enable %d\n", __func__, enable); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4271 | return -EINVAL; |
| 4272 | } |
| 4273 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4274 | pr_debug("%s port_id %d, module_id 0x%x, instance_id 0x%x, enable %d\n", |
| 4275 | __func__, port_id, mod_inst_info.module_id, |
| 4276 | mod_inst_info.instance_id, enable); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4277 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4278 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4279 | param_hdr.module_id = mod_inst_info.module_id; |
| 4280 | param_hdr.instance_id = mod_inst_info.instance_id; |
| 4281 | param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE; |
| 4282 | param_hdr.param_size = sizeof(enable_param); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4283 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4284 | enable_param = enable; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4285 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4286 | rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4287 | (uint8_t *) &enable_param); |
| 4288 | if (rc) |
| 4289 | pr_err("%s: Failed to set enable of module(%d) instance(%d) to %d, err %d\n", |
| 4290 | __func__, mod_inst_info.module_id, |
| 4291 | mod_inst_info.instance_id, enable, rc); |
| 4292 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4293 | return rc; |
| 4294 | |
| 4295 | } |
Vidyakumar Athota | 98464a2 | 2018-03-15 20:39:37 -0700 | [diff] [blame] | 4296 | EXPORT_SYMBOL(adm_param_enable_v2); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4297 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4298 | /** |
| 4299 | * adm_send_calibration - |
| 4300 | * send ADM calibration to DSP |
| 4301 | * |
| 4302 | * @port_id: Port ID number |
| 4303 | * @copp_idx: copp index assigned |
| 4304 | * @path: direction or ADM path type |
| 4305 | * @perf_mode: performance mode like LL/ULL/.. |
| 4306 | * @cal_type: calibration type to use |
| 4307 | * @params: pointer with cal data |
| 4308 | * @size: cal size |
| 4309 | * |
| 4310 | * Returns 0 on success or error on failure |
| 4311 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4312 | int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode, |
| 4313 | int cal_type, char *params, int size) |
| 4314 | { |
| 4315 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4316 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4317 | |
| 4318 | pr_debug("%s:port_id %d, path %d, perf_mode %d, cal_type %d, size %d\n", |
| 4319 | __func__, port_id, path, perf_mode, cal_type, size); |
| 4320 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4321 | /* Maps audio_dev_ctrl path definition to ACDB definition */ |
| 4322 | if (get_cal_path(path) != RX_DEVICE) { |
| 4323 | pr_err("%s: acdb_path %d\n", __func__, path); |
| 4324 | rc = -EINVAL; |
| 4325 | goto end; |
| 4326 | } |
| 4327 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4328 | rc = adm_set_pp_params(port_id, copp_idx, NULL, (u8 *) params, size); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4329 | |
| 4330 | end: |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4331 | return rc; |
| 4332 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4333 | EXPORT_SYMBOL(adm_send_calibration); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4334 | |
| 4335 | /* |
| 4336 | * adm_update_wait_parameters must be called with routing driver locks. |
| 4337 | * adm_reset_wait_parameters must be called with routing driver locks. |
| 4338 | * set and reset parmeters are separated to make sure it is always called |
| 4339 | * under routing driver lock. |
| 4340 | * adm_wait_timeout is to block until timeout or interrupted. Timeout is |
| 4341 | * not a an error. |
| 4342 | */ |
| 4343 | int adm_set_wait_parameters(int port_id, int copp_idx) |
| 4344 | { |
| 4345 | |
| 4346 | int ret = 0, port_idx; |
| 4347 | |
| 4348 | pr_debug("%s: port_id 0x%x, copp_idx %d\n", __func__, port_id, |
| 4349 | copp_idx); |
| 4350 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4351 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4352 | if (port_idx < 0) { |
| 4353 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 4354 | ret = -EINVAL; |
| 4355 | goto end; |
| 4356 | } |
| 4357 | |
| 4358 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4359 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4360 | return -EINVAL; |
| 4361 | } |
| 4362 | |
| 4363 | this_adm.copp.adm_delay[port_idx][copp_idx] = 1; |
| 4364 | atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 0); |
| 4365 | |
| 4366 | end: |
| 4367 | return ret; |
| 4368 | |
| 4369 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4370 | EXPORT_SYMBOL(adm_set_wait_parameters); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4371 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4372 | /** |
| 4373 | * adm_reset_wait_parameters - |
| 4374 | * reset wait parameters or ADM delay value |
| 4375 | * |
| 4376 | * @port_id: Port ID number |
| 4377 | * @copp_idx: copp index assigned |
| 4378 | * |
| 4379 | * Returns 0 on success or error on failure |
| 4380 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4381 | int adm_reset_wait_parameters(int port_id, int copp_idx) |
| 4382 | { |
| 4383 | int ret = 0, port_idx; |
| 4384 | |
| 4385 | pr_debug("%s: port_id 0x%x copp_idx %d\n", __func__, port_id, |
| 4386 | copp_idx); |
| 4387 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4388 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4389 | if (port_idx < 0) { |
| 4390 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 4391 | ret = -EINVAL; |
| 4392 | goto end; |
| 4393 | } |
| 4394 | |
| 4395 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4396 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4397 | return -EINVAL; |
| 4398 | } |
| 4399 | |
| 4400 | atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 1); |
| 4401 | this_adm.copp.adm_delay[port_idx][copp_idx] = 0; |
| 4402 | |
| 4403 | end: |
| 4404 | return ret; |
| 4405 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4406 | EXPORT_SYMBOL(adm_reset_wait_parameters); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4407 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4408 | /** |
| 4409 | * adm_wait_timeout - |
| 4410 | * ADM wait command after command send to DSP |
| 4411 | * |
| 4412 | * @port_id: Port ID number |
| 4413 | * @copp_idx: copp index assigned |
| 4414 | * @wait_time: value in ms for command timeout |
| 4415 | * |
| 4416 | * Returns 0 on success or error on failure |
| 4417 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4418 | int adm_wait_timeout(int port_id, int copp_idx, int wait_time) |
| 4419 | { |
| 4420 | int ret = 0, port_idx; |
| 4421 | |
| 4422 | pr_debug("%s: port_id 0x%x, copp_idx %d, wait_time %d\n", __func__, |
| 4423 | port_id, copp_idx, wait_time); |
| 4424 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4425 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4426 | if (port_idx < 0) { |
| 4427 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
| 4428 | ret = -EINVAL; |
| 4429 | goto end; |
| 4430 | } |
| 4431 | |
| 4432 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4433 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4434 | return -EINVAL; |
| 4435 | } |
| 4436 | |
| 4437 | ret = wait_event_timeout( |
| 4438 | this_adm.copp.adm_delay_wait[port_idx][copp_idx], |
| 4439 | atomic_read(&this_adm.copp.adm_delay_stat[port_idx][copp_idx]), |
| 4440 | msecs_to_jiffies(wait_time)); |
| 4441 | pr_debug("%s: return %d\n", __func__, ret); |
| 4442 | if (ret != 0) |
| 4443 | ret = -EINTR; |
| 4444 | end: |
| 4445 | pr_debug("%s: return %d--\n", __func__, ret); |
| 4446 | return ret; |
| 4447 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4448 | EXPORT_SYMBOL(adm_wait_timeout); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4449 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4450 | /** |
| 4451 | * adm_store_cal_data - |
| 4452 | * Retrieve calibration data for ADM copp device |
| 4453 | * |
| 4454 | * @port_id: Port ID number |
| 4455 | * @copp_idx: copp index assigned |
| 4456 | * @path: direction or copp type |
| 4457 | * @perf_mode: performance mode like LL/ULL/.. |
| 4458 | * @cal_index: calibration index to use |
| 4459 | * @params: pointer to store cal data |
| 4460 | * @size: pointer to fill with cal size |
| 4461 | * |
| 4462 | * Returns 0 on success or error on failure |
| 4463 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4464 | int adm_store_cal_data(int port_id, int copp_idx, int path, int perf_mode, |
| 4465 | int cal_index, char *params, int *size) |
| 4466 | { |
| 4467 | int rc = 0; |
| 4468 | struct cal_block_data *cal_block = NULL; |
| 4469 | int app_type, acdb_id, port_idx, sample_rate; |
| 4470 | |
| 4471 | if (this_adm.cal_data[cal_index] == NULL) { |
| 4472 | pr_debug("%s: cal_index %d not allocated!\n", |
| 4473 | __func__, cal_index); |
| 4474 | goto end; |
| 4475 | } |
| 4476 | |
| 4477 | if (get_cal_path(path) != RX_DEVICE) { |
| 4478 | pr_debug("%s: Invalid path to store calibration %d\n", |
| 4479 | __func__, path); |
| 4480 | rc = -EINVAL; |
| 4481 | goto end; |
| 4482 | } |
| 4483 | |
| 4484 | port_id = afe_convert_virtual_to_portid(port_id); |
| 4485 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4486 | if (port_idx < 0) { |
| 4487 | pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); |
| 4488 | rc = -EINVAL; |
| 4489 | goto end; |
| 4490 | } |
| 4491 | |
| 4492 | if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4493 | pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); |
| 4494 | return -EINVAL; |
| 4495 | } |
| 4496 | |
| 4497 | acdb_id = atomic_read(&this_adm.copp.acdb_id[port_idx][copp_idx]); |
| 4498 | app_type = atomic_read(&this_adm.copp.app_type[port_idx][copp_idx]); |
| 4499 | sample_rate = atomic_read(&this_adm.copp.rate[port_idx][copp_idx]); |
| 4500 | |
| 4501 | mutex_lock(&this_adm.cal_data[cal_index]->lock); |
| 4502 | cal_block = adm_find_cal(cal_index, get_cal_path(path), app_type, |
| 4503 | acdb_id, sample_rate); |
| 4504 | if (cal_block == NULL) |
| 4505 | goto unlock; |
| 4506 | |
| 4507 | if (cal_block->cal_data.size <= 0) { |
| 4508 | pr_debug("%s: No ADM cal send for port_id = 0x%x!\n", |
| 4509 | __func__, port_id); |
| 4510 | rc = -EINVAL; |
| 4511 | goto unlock; |
| 4512 | } |
| 4513 | |
Aditya Bavanari | 2a627ae | 2017-11-21 20:24:53 +0530 | [diff] [blame] | 4514 | if (cal_index == ADM_AUDPROC_CAL || cal_index == ADM_LSM_AUDPROC_CAL) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4515 | if (cal_block->cal_data.size > AUD_PROC_BLOCK_SIZE) { |
| 4516 | pr_err("%s:audproc:invalid size exp/actual[%zd, %d]\n", |
| 4517 | __func__, cal_block->cal_data.size, *size); |
| 4518 | rc = -ENOMEM; |
| 4519 | goto unlock; |
| 4520 | } |
Bhalchandra Gajare | bbb6414 | 2018-05-10 14:16:49 -0700 | [diff] [blame] | 4521 | } else if (cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) { |
| 4522 | if (cal_block->cal_data.size > AUD_PROC_PERSIST_BLOCK_SIZE) { |
| 4523 | pr_err("%s:persist invalid size exp/actual[%zd, %d]\n", |
| 4524 | __func__, cal_block->cal_data.size, *size); |
| 4525 | rc = -ENOMEM; |
| 4526 | goto unlock; |
| 4527 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4528 | } else if (cal_index == ADM_AUDVOL_CAL) { |
| 4529 | if (cal_block->cal_data.size > AUD_VOL_BLOCK_SIZE) { |
| 4530 | pr_err("%s:aud_vol:invalid size exp/actual[%zd, %d]\n", |
| 4531 | __func__, cal_block->cal_data.size, *size); |
| 4532 | rc = -ENOMEM; |
| 4533 | goto unlock; |
| 4534 | } |
| 4535 | } else { |
| 4536 | pr_debug("%s: Not valid calibration for dolby topolgy\n", |
| 4537 | __func__); |
| 4538 | rc = -EINVAL; |
| 4539 | goto unlock; |
| 4540 | } |
| 4541 | memcpy(params, cal_block->cal_data.kvaddr, cal_block->cal_data.size); |
| 4542 | *size = cal_block->cal_data.size; |
| 4543 | |
| 4544 | pr_debug("%s:port_id %d, copp_idx %d, path %d", |
| 4545 | __func__, port_id, copp_idx, path); |
| 4546 | pr_debug("perf_mode %d, cal_type %d, size %d\n", |
| 4547 | perf_mode, cal_index, *size); |
| 4548 | |
| 4549 | unlock: |
| 4550 | mutex_unlock(&this_adm.cal_data[cal_index]->lock); |
| 4551 | end: |
| 4552 | return rc; |
| 4553 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4554 | EXPORT_SYMBOL(adm_store_cal_data); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4555 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4556 | /** |
| 4557 | * adm_send_compressed_device_mute - |
| 4558 | * command to send mute for compressed device |
| 4559 | * |
| 4560 | * @port_id: Port ID number |
| 4561 | * @copp_idx: copp index assigned |
| 4562 | * @mute_on: flag to indicate mute or unmute |
| 4563 | * |
| 4564 | * Returns 0 on success or error on failure |
| 4565 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4566 | int adm_send_compressed_device_mute(int port_id, int copp_idx, bool mute_on) |
| 4567 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4568 | u32 mute_param = mute_on ? 1 : 0; |
| 4569 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4570 | int ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4571 | |
| 4572 | pr_debug("%s port_id: 0x%x, copp_idx %d, mute_on: %d\n", |
| 4573 | __func__, port_id, copp_idx, mute_on); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4574 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4575 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4576 | param_hdr.module_id = AUDPROC_MODULE_ID_COMPRESSED_MUTE; |
| 4577 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4578 | param_hdr.param_id = AUDPROC_PARAM_ID_COMPRESSED_MUTE; |
| 4579 | param_hdr.param_size = sizeof(mute_param); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4580 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4581 | ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4582 | (uint8_t *) &mute_param); |
| 4583 | if (ret) |
| 4584 | pr_err("%s: Failed to set mute, err %d\n", __func__, ret); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4585 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4586 | return ret; |
| 4587 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4588 | EXPORT_SYMBOL(adm_send_compressed_device_mute); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4589 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4590 | /** |
| 4591 | * adm_send_compressed_device_latency - |
| 4592 | * command to send latency for compressed device |
| 4593 | * |
| 4594 | * @port_id: Port ID number |
| 4595 | * @copp_idx: copp index assigned |
| 4596 | * @latency: latency value to pass |
| 4597 | * |
| 4598 | * Returns 0 on success or error on failure |
| 4599 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4600 | int adm_send_compressed_device_latency(int port_id, int copp_idx, int latency) |
| 4601 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4602 | u32 latency_param; |
| 4603 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4604 | int ret = 0; |
| 4605 | |
| 4606 | pr_debug("%s port_id: 0x%x, copp_idx %d latency: %d\n", __func__, |
| 4607 | port_id, copp_idx, latency); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4608 | |
| 4609 | if (latency < 0) { |
| 4610 | pr_err("%s: Invalid value for latency %d", __func__, latency); |
| 4611 | return -EINVAL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4612 | } |
| 4613 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4614 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4615 | param_hdr.module_id = AUDPROC_MODULE_ID_COMPRESSED_LATENCY; |
| 4616 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4617 | param_hdr.param_id = AUDPROC_PARAM_ID_COMPRESSED_LATENCY; |
| 4618 | param_hdr.param_size = sizeof(latency_param); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4619 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4620 | latency_param = latency; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4621 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4622 | ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4623 | (uint8_t *) &latency_param); |
| 4624 | if (ret) |
| 4625 | pr_err("%s: Failed to set latency, err %d\n", __func__, ret); |
| 4626 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4627 | return ret; |
| 4628 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4629 | EXPORT_SYMBOL(adm_send_compressed_device_latency); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4630 | |
| 4631 | /** |
| 4632 | * adm_swap_speaker_channels |
| 4633 | * |
| 4634 | * Receives port_id, copp_idx, sample rate, spk_swap and |
| 4635 | * send MFC command to swap speaker channel. |
| 4636 | * Return zero on success. On failure returns nonzero. |
| 4637 | * |
| 4638 | * port_id - Passed value, port_id for which channels swap is wanted |
| 4639 | * copp_idx - Passed value, copp_idx for which channels swap is wanted |
| 4640 | * sample_rate - Passed value, sample rate used by app type config |
| 4641 | * spk_swap - Passed value, spk_swap for check if swap flag is set |
| 4642 | */ |
| 4643 | int adm_swap_speaker_channels(int port_id, int copp_idx, |
| 4644 | int sample_rate, bool spk_swap) |
| 4645 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4646 | struct audproc_mfc_param_media_fmt mfc_cfg; |
| 4647 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4648 | uint16_t num_channels; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4649 | int port_idx = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4650 | int ret = 0; |
| 4651 | |
| 4652 | pr_debug("%s: Enter, port_id %d, copp_idx %d\n", |
| 4653 | __func__, port_id, copp_idx); |
| 4654 | port_id = q6audio_convert_virtual_to_portid(port_id); |
| 4655 | port_idx = adm_validate_and_get_port_index(port_id); |
| 4656 | if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { |
| 4657 | pr_err("%s: Invalid port_id %#x\n", __func__, port_id); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4658 | return -EINVAL; |
| 4659 | } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { |
| 4660 | pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); |
| 4661 | return -EINVAL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4662 | } |
| 4663 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4664 | num_channels = atomic_read(&this_adm.copp.channels[port_idx][copp_idx]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4665 | if (num_channels != 2) { |
| 4666 | pr_debug("%s: Invalid number of channels: %d\n", |
| 4667 | __func__, num_channels); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4668 | return -EINVAL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | memset(&mfc_cfg, 0, sizeof(mfc_cfg)); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4672 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4673 | |
| 4674 | param_hdr.module_id = AUDPROC_MODULE_ID_MFC; |
| 4675 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4676 | param_hdr.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT; |
| 4677 | param_hdr.param_size = sizeof(mfc_cfg); |
| 4678 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4679 | mfc_cfg.sampling_rate = sample_rate; |
| 4680 | mfc_cfg.bits_per_sample = |
| 4681 | atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]); |
| 4682 | mfc_cfg.num_channels = num_channels; |
| 4683 | |
| 4684 | /* Currently applying speaker swap for only 2 channel use case */ |
| 4685 | if (spk_swap) { |
| 4686 | mfc_cfg.channel_type[0] = |
| 4687 | (uint16_t) PCM_CHANNEL_FR; |
| 4688 | mfc_cfg.channel_type[1] = |
| 4689 | (uint16_t) PCM_CHANNEL_FL; |
| 4690 | } else { |
| 4691 | mfc_cfg.channel_type[0] = |
| 4692 | (uint16_t) PCM_CHANNEL_FL; |
| 4693 | mfc_cfg.channel_type[1] = |
| 4694 | (uint16_t) PCM_CHANNEL_FR; |
| 4695 | } |
| 4696 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4697 | ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4698 | (u8 *) &mfc_cfg); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4699 | if (ret < 0) { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4700 | pr_err("%s: Failed to set swap speaker channels on port[0x%x] failed %d\n", |
| 4701 | __func__, port_id, ret); |
| 4702 | return ret; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | pr_debug("%s: mfc_cfg Set params returned success", __func__); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4706 | return 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4707 | } |
| 4708 | EXPORT_SYMBOL(adm_swap_speaker_channels); |
| 4709 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4710 | /** |
| 4711 | * adm_set_sound_focus - |
| 4712 | * Update sound focus info |
| 4713 | * |
| 4714 | * @port_id: Port ID number |
| 4715 | * @copp_idx: copp index assigned |
| 4716 | * @soundFocusData: sound focus data to pass |
| 4717 | * |
| 4718 | * Returns 0 on success or error on failure |
| 4719 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4720 | int adm_set_sound_focus(int port_id, int copp_idx, |
| 4721 | struct sound_focus_param soundFocusData) |
| 4722 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4723 | struct adm_param_fluence_soundfocus_t soundfocus_params; |
| 4724 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4725 | int ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4726 | int i; |
| 4727 | |
| 4728 | pr_debug("%s: Enter, port_id %d, copp_idx %d\n", |
| 4729 | __func__, port_id, copp_idx); |
| 4730 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4731 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
Vignesh Kulothungan | 6f75e7b | 2018-06-21 18:05:44 -0700 | [diff] [blame] | 4732 | param_hdr.module_id = VOICEPROC_MODULE_ID_FLUENCE_PRO_VC_TX; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4733 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4734 | param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS; |
| 4735 | param_hdr.param_size = sizeof(soundfocus_params); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4736 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4737 | memset(&(soundfocus_params), 0xFF, sizeof(soundfocus_params)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4738 | for (i = 0; i < MAX_SECTORS; i++) { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4739 | soundfocus_params.start_angles[i] = |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4740 | soundFocusData.start_angle[i]; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4741 | soundfocus_params.enables[i] = soundFocusData.enable[i]; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4742 | pr_debug("%s: start_angle[%d] = %d\n", |
| 4743 | __func__, i, soundFocusData.start_angle[i]); |
| 4744 | pr_debug("%s: enable[%d] = %d\n", |
| 4745 | __func__, i, soundFocusData.enable[i]); |
| 4746 | } |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4747 | soundfocus_params.gain_step = soundFocusData.gain_step; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4748 | pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step); |
| 4749 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4750 | soundfocus_params.reserved = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4751 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4752 | ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 4753 | (uint8_t *) &soundfocus_params); |
| 4754 | if (ret) |
| 4755 | pr_err("%s: Failed to set sound focus params, err %d\n", |
| 4756 | __func__, ret); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4757 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4758 | pr_debug("%s: Exit, ret=%d\n", __func__, ret); |
| 4759 | |
| 4760 | return ret; |
| 4761 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4762 | EXPORT_SYMBOL(adm_set_sound_focus); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4763 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4764 | /** |
| 4765 | * adm_get_sound_focus - |
| 4766 | * Retrieve sound focus info |
| 4767 | * |
| 4768 | * @port_id: Port ID number |
| 4769 | * @copp_idx: copp index assigned |
| 4770 | * @soundFocusData: pointer for sound focus data to be updated with |
| 4771 | * |
| 4772 | * Returns 0 on success or error on failure |
| 4773 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4774 | int adm_get_sound_focus(int port_id, int copp_idx, |
| 4775 | struct sound_focus_param *soundFocusData) |
| 4776 | { |
| 4777 | int ret = 0, i; |
| 4778 | char *params_value; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4779 | uint32_t max_param_size = 0; |
| 4780 | struct adm_param_fluence_soundfocus_t *soundfocus_params = NULL; |
| 4781 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4782 | |
| 4783 | pr_debug("%s: Enter, port_id %d, copp_idx %d\n", |
| 4784 | __func__, port_id, copp_idx); |
| 4785 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4786 | max_param_size = sizeof(struct adm_param_fluence_soundfocus_t) + |
| 4787 | sizeof(union param_hdrs); |
| 4788 | params_value = kzalloc(max_param_size, GFP_KERNEL); |
| 4789 | if (!params_value) |
| 4790 | return -ENOMEM; |
| 4791 | |
| 4792 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
Vignesh Kulothungan | 6f75e7b | 2018-06-21 18:05:44 -0700 | [diff] [blame] | 4793 | param_hdr.module_id = VOICEPROC_MODULE_ID_FLUENCE_PRO_VC_TX; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4794 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4795 | param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS; |
| 4796 | param_hdr.param_size = max_param_size; |
| 4797 | ret = adm_get_pp_params(port_id, copp_idx, |
| 4798 | ADM_CLIENT_ID_SOURCE_TRACKING, NULL, ¶m_hdr, |
| 4799 | params_value); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4800 | if (ret) { |
| 4801 | pr_err("%s: get parameters failed ret:%d\n", __func__, ret); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4802 | ret = -EINVAL; |
| 4803 | goto done; |
| 4804 | } |
| 4805 | |
| 4806 | if (this_adm.sourceTrackingData.apr_cmd_status != 0) { |
| 4807 | pr_err("%s - get params returned error [%s]\n", |
| 4808 | __func__, adsp_err_get_err_str( |
| 4809 | this_adm.sourceTrackingData.apr_cmd_status)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4810 | ret = adsp_err_get_lnx_err_code( |
| 4811 | this_adm.sourceTrackingData.apr_cmd_status); |
| 4812 | goto done; |
| 4813 | } |
| 4814 | |
| 4815 | soundfocus_params = (struct adm_param_fluence_soundfocus_t *) |
| 4816 | params_value; |
| 4817 | for (i = 0; i < MAX_SECTORS; i++) { |
| 4818 | soundFocusData->start_angle[i] = |
| 4819 | soundfocus_params->start_angles[i]; |
| 4820 | soundFocusData->enable[i] = soundfocus_params->enables[i]; |
| 4821 | pr_debug("%s: start_angle[%d] = %d\n", |
| 4822 | __func__, i, soundFocusData->start_angle[i]); |
| 4823 | pr_debug("%s: enable[%d] = %d\n", |
| 4824 | __func__, i, soundFocusData->enable[i]); |
| 4825 | } |
| 4826 | soundFocusData->gain_step = soundfocus_params->gain_step; |
| 4827 | pr_debug("%s: gain_step = %d\n", __func__, soundFocusData->gain_step); |
| 4828 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4829 | done: |
| 4830 | pr_debug("%s: Exit, ret = %d\n", __func__, ret); |
| 4831 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4832 | kfree(params_value); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4833 | return ret; |
| 4834 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4835 | EXPORT_SYMBOL(adm_get_sound_focus); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4836 | |
| 4837 | static int adm_source_tracking_alloc_map_memory(void) |
| 4838 | { |
| 4839 | int ret; |
| 4840 | |
| 4841 | pr_debug("%s: Enter\n", __func__); |
| 4842 | |
Banajit Goswami | 08bb736 | 2017-11-03 22:48:23 -0700 | [diff] [blame] | 4843 | ret = msm_audio_ion_alloc(&this_adm.sourceTrackingData.dma_buf, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4844 | AUD_PROC_BLOCK_SIZE, |
| 4845 | &this_adm.sourceTrackingData.memmap.paddr, |
| 4846 | &this_adm.sourceTrackingData.memmap.size, |
| 4847 | &this_adm.sourceTrackingData.memmap.kvaddr); |
| 4848 | if (ret) { |
| 4849 | pr_err("%s: failed to allocate memory\n", __func__); |
| 4850 | |
| 4851 | ret = -EINVAL; |
| 4852 | goto done; |
| 4853 | } |
| 4854 | |
| 4855 | atomic_set(&this_adm.mem_map_index, ADM_MEM_MAP_INDEX_SOURCE_TRACKING); |
| 4856 | ret = adm_memory_map_regions(&this_adm.sourceTrackingData.memmap.paddr, |
| 4857 | 0, |
| 4858 | (uint32_t *)&this_adm.sourceTrackingData.memmap.size, |
| 4859 | 1); |
| 4860 | if (ret < 0) { |
| 4861 | pr_err("%s: failed to map memory, paddr = 0x%pK, size = %d\n", |
| 4862 | __func__, |
| 4863 | (void *)this_adm.sourceTrackingData.memmap.paddr, |
| 4864 | (uint32_t)this_adm.sourceTrackingData.memmap.size); |
| 4865 | |
Banajit Goswami | 08bb736 | 2017-11-03 22:48:23 -0700 | [diff] [blame] | 4866 | msm_audio_ion_free(this_adm.sourceTrackingData.dma_buf); |
| 4867 | this_adm.sourceTrackingData.dma_buf = NULL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4868 | this_adm.sourceTrackingData.memmap.size = 0; |
| 4869 | this_adm.sourceTrackingData.memmap.kvaddr = NULL; |
| 4870 | this_adm.sourceTrackingData.memmap.paddr = 0; |
| 4871 | this_adm.sourceTrackingData.apr_cmd_status = -1; |
| 4872 | atomic_set(&this_adm.mem_map_handles |
| 4873 | [ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0); |
| 4874 | |
| 4875 | ret = -EINVAL; |
| 4876 | goto done; |
| 4877 | } |
| 4878 | ret = 0; |
| 4879 | pr_debug("%s: paddr = 0x%pK, size = %d, mem_map_handle = 0x%x\n", |
| 4880 | __func__, (void *)this_adm.sourceTrackingData.memmap.paddr, |
| 4881 | (uint32_t)this_adm.sourceTrackingData.memmap.size, |
| 4882 | atomic_read(&this_adm.mem_map_handles |
| 4883 | [ADM_MEM_MAP_INDEX_SOURCE_TRACKING])); |
| 4884 | |
| 4885 | done: |
| 4886 | pr_debug("%s: Exit, ret = %d\n", __func__, ret); |
| 4887 | |
| 4888 | return ret; |
| 4889 | } |
| 4890 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 4891 | /** |
| 4892 | * adm_get_source_tracking - |
| 4893 | * Retrieve source tracking info |
| 4894 | * |
| 4895 | * @port_id: Port ID number |
| 4896 | * @copp_idx: copp index assigned |
| 4897 | * @sourceTrackingData: pointer for source track data to be updated with |
| 4898 | * |
| 4899 | * Returns 0 on success or error on failure |
| 4900 | */ |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4901 | int adm_get_source_tracking(int port_id, int copp_idx, |
| 4902 | struct source_tracking_param *sourceTrackingData) |
| 4903 | { |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4904 | struct adm_param_fluence_sourcetracking_t *source_tracking_params = |
| 4905 | NULL; |
| 4906 | struct mem_mapping_hdr mem_hdr; |
| 4907 | struct param_hdr_v3 param_hdr; |
| 4908 | int i = 0; |
| 4909 | int ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4910 | |
| 4911 | pr_debug("%s: Enter, port_id %d, copp_idx %d\n", |
| 4912 | __func__, port_id, copp_idx); |
| 4913 | |
| 4914 | if (!this_adm.sourceTrackingData.memmap.paddr) { |
| 4915 | /* Allocate and map shared memory for out of band usage */ |
| 4916 | ret = adm_source_tracking_alloc_map_memory(); |
| 4917 | if (ret != 0) { |
| 4918 | ret = -EINVAL; |
| 4919 | goto done; |
| 4920 | } |
| 4921 | } |
| 4922 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4923 | memset(&mem_hdr, 0, sizeof(mem_hdr)); |
| 4924 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 4925 | mem_hdr.data_payload_addr_lsw = |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4926 | lower_32_bits(this_adm.sourceTrackingData.memmap.paddr); |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4927 | mem_hdr.data_payload_addr_msw = msm_audio_populate_upper_32_bits( |
| 4928 | this_adm.sourceTrackingData.memmap.paddr); |
| 4929 | mem_hdr.mem_map_handle = atomic_read( |
| 4930 | &this_adm.mem_map_handles[ADM_MEM_MAP_INDEX_SOURCE_TRACKING]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4931 | |
Vignesh Kulothungan | 6f75e7b | 2018-06-21 18:05:44 -0700 | [diff] [blame] | 4932 | param_hdr.module_id = VOICEPROC_MODULE_ID_FLUENCE_PRO_VC_TX; |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4933 | param_hdr.instance_id = INSTANCE_ID_0; |
| 4934 | param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOURCETRACKING; |
| 4935 | /* |
| 4936 | * This size should be the max size of the calibration data + header. |
| 4937 | * Use the union size to ensure max size is used. |
| 4938 | */ |
| 4939 | param_hdr.param_size = |
| 4940 | sizeof(struct adm_param_fluence_sourcetracking_t) + |
| 4941 | sizeof(union param_hdrs); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4942 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4943 | /* |
| 4944 | * Retrieving parameters out of band, so no need to provide a buffer for |
| 4945 | * the returned parameter data as it will be at the memory location |
| 4946 | * provided. |
| 4947 | */ |
| 4948 | ret = adm_get_pp_params(port_id, copp_idx, |
| 4949 | ADM_CLIENT_ID_SOURCE_TRACKING, &mem_hdr, |
| 4950 | ¶m_hdr, NULL); |
| 4951 | if (ret) { |
| 4952 | pr_err("%s: Failed to get params, error %d\n", __func__, ret); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4953 | goto done; |
| 4954 | } |
| 4955 | |
| 4956 | if (this_adm.sourceTrackingData.apr_cmd_status != 0) { |
| 4957 | pr_err("%s - get params returned error [%s]\n", |
| 4958 | __func__, adsp_err_get_err_str( |
| 4959 | this_adm.sourceTrackingData.apr_cmd_status)); |
| 4960 | |
| 4961 | ret = adsp_err_get_lnx_err_code( |
| 4962 | this_adm.sourceTrackingData.apr_cmd_status); |
| 4963 | goto done; |
| 4964 | } |
| 4965 | |
Vignesh Kulothungan | 60cc035 | 2018-01-29 16:21:22 -0800 | [diff] [blame] | 4966 | /* How do we know what the param data was retrieved with for hdr size */ |
| 4967 | source_tracking_params = |
| 4968 | (struct adm_param_fluence_sourcetracking_t |
| 4969 | *) (this_adm.sourceTrackingData.memmap.kvaddr + |
| 4970 | sizeof(struct param_hdr_v1)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4971 | for (i = 0; i < MAX_SECTORS; i++) { |
| 4972 | sourceTrackingData->vad[i] = source_tracking_params->vad[i]; |
| 4973 | pr_debug("%s: vad[%d] = %d\n", |
| 4974 | __func__, i, sourceTrackingData->vad[i]); |
| 4975 | } |
| 4976 | sourceTrackingData->doa_speech = source_tracking_params->doa_speech; |
| 4977 | pr_debug("%s: doa_speech = %d\n", |
| 4978 | __func__, sourceTrackingData->doa_speech); |
| 4979 | |
| 4980 | for (i = 0; i < MAX_NOISE_SOURCE_INDICATORS; i++) { |
| 4981 | sourceTrackingData->doa_noise[i] = |
| 4982 | source_tracking_params->doa_noise[i]; |
| 4983 | pr_debug("%s: doa_noise[%d] = %d\n", |
| 4984 | __func__, i, sourceTrackingData->doa_noise[i]); |
| 4985 | } |
| 4986 | for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) { |
| 4987 | sourceTrackingData->polar_activity[i] = |
| 4988 | source_tracking_params->polar_activity[i]; |
| 4989 | pr_debug("%s: polar_activity[%d] = %d\n", |
| 4990 | __func__, i, sourceTrackingData->polar_activity[i]); |
| 4991 | } |
| 4992 | |
| 4993 | ret = 0; |
| 4994 | |
| 4995 | done: |
| 4996 | pr_debug("%s: Exit, ret=%d\n", __func__, ret); |
| 4997 | |
| 4998 | return ret; |
| 4999 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 5000 | EXPORT_SYMBOL(adm_get_source_tracking); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5001 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 5002 | int __init adm_init(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5003 | { |
| 5004 | int i = 0, j; |
| 5005 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5006 | this_adm.ec_ref_rx = -1; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5007 | init_waitqueue_head(&this_adm.matrix_map_wait); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5008 | init_waitqueue_head(&this_adm.adm_wait); |
| 5009 | |
| 5010 | for (i = 0; i < AFE_MAX_PORTS; i++) { |
| 5011 | for (j = 0; j < MAX_COPPS_PER_PORT; j++) { |
| 5012 | atomic_set(&this_adm.copp.id[i][j], RESET_COPP_ID); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5013 | init_waitqueue_head(&this_adm.copp.wait[i][j]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5014 | init_waitqueue_head( |
| 5015 | &this_adm.copp.adm_delay_wait[i][j]); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | if (adm_init_cal_data()) |
| 5020 | pr_err("%s: could not init cal data!\n", __func__); |
| 5021 | |
Banajit Goswami | 08bb736 | 2017-11-03 22:48:23 -0700 | [diff] [blame] | 5022 | this_adm.sourceTrackingData.dma_buf = NULL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5023 | this_adm.sourceTrackingData.memmap.size = 0; |
| 5024 | this_adm.sourceTrackingData.memmap.kvaddr = NULL; |
| 5025 | this_adm.sourceTrackingData.memmap.paddr = 0; |
| 5026 | this_adm.sourceTrackingData.apr_cmd_status = -1; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5027 | |
| 5028 | return 0; |
| 5029 | } |
| 5030 | |
Asish Bhattacharya | 5faacb3 | 2017-12-04 17:23:15 +0530 | [diff] [blame] | 5031 | void adm_exit(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5032 | { |
Laxminath Kasam | 30ad751 | 2017-11-28 12:40:22 +0530 | [diff] [blame] | 5033 | if (this_adm.apr) |
| 5034 | adm_reset_data(); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 5035 | adm_delete_cal_data(); |
| 5036 | } |