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