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