blob: 78ce2b88ac2100c5fe98a895081decafde7a867e [file] [log] [blame]
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
2 *
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
2147 if (cal_index == ADM_AUDPROC_CAL) {
2148 audproc_cal_info = cal_block->cal_info;
2149 if ((audproc_cal_info->path == path) &&
2150 (cal_block->cal_data.size > 0))
2151 return cal_block;
2152 } else if (cal_index == ADM_AUDVOL_CAL) {
2153 audvol_cal_info = cal_block->cal_info;
2154 if ((audvol_cal_info->path == path) &&
2155 (cal_block->cal_data.size > 0))
2156 return cal_block;
2157 }
2158 }
2159 pr_debug("%s: Can't find ADM cal for cal_index %d, path %d\n",
2160 __func__, cal_index, path);
2161 return NULL;
2162}
2163
2164static struct cal_block_data *adm_find_cal_by_app_type(int cal_index, int path,
2165 int app_type)
2166{
2167 struct list_head *ptr, *next;
2168 struct cal_block_data *cal_block = NULL;
2169 struct audio_cal_info_audproc *audproc_cal_info = NULL;
2170 struct audio_cal_info_audvol *audvol_cal_info = NULL;
2171
2172 pr_debug("%s\n", __func__);
2173
2174 list_for_each_safe(ptr, next,
2175 &this_adm.cal_data[cal_index]->cal_blocks) {
2176
2177 cal_block = list_entry(ptr,
2178 struct cal_block_data, list);
2179
2180 if (cal_index == ADM_AUDPROC_CAL) {
2181 audproc_cal_info = cal_block->cal_info;
2182 if ((audproc_cal_info->path == path) &&
2183 (audproc_cal_info->app_type == app_type) &&
2184 (cal_block->cal_data.size > 0))
2185 return cal_block;
2186 } else if (cal_index == ADM_AUDVOL_CAL) {
2187 audvol_cal_info = cal_block->cal_info;
2188 if ((audvol_cal_info->path == path) &&
2189 (audvol_cal_info->app_type == app_type) &&
2190 (cal_block->cal_data.size > 0))
2191 return cal_block;
2192 }
2193 }
2194 pr_debug("%s: Can't find ADM cali for cal_index %d, path %d, app %d, defaulting to search by path\n",
2195 __func__, cal_index, path, app_type);
2196 return adm_find_cal_by_path(cal_index, path);
2197}
2198
2199
2200static struct cal_block_data *adm_find_cal(int cal_index, int path,
2201 int app_type, int acdb_id,
2202 int sample_rate)
2203{
2204 struct list_head *ptr, *next;
2205 struct cal_block_data *cal_block = NULL;
2206 struct audio_cal_info_audproc *audproc_cal_info = NULL;
2207 struct audio_cal_info_audvol *audvol_cal_info = NULL;
2208
2209 pr_debug("%s:\n", __func__);
2210
2211 list_for_each_safe(ptr, next,
2212 &this_adm.cal_data[cal_index]->cal_blocks) {
2213
2214 cal_block = list_entry(ptr,
2215 struct cal_block_data, list);
2216
2217 if (cal_index == ADM_AUDPROC_CAL) {
2218 audproc_cal_info = cal_block->cal_info;
2219 if ((audproc_cal_info->path == path) &&
2220 (audproc_cal_info->app_type == app_type) &&
2221 (audproc_cal_info->acdb_id == acdb_id) &&
2222 (audproc_cal_info->sample_rate == sample_rate) &&
2223 (cal_block->cal_data.size > 0))
2224 return cal_block;
2225 } else if (cal_index == ADM_AUDVOL_CAL) {
2226 audvol_cal_info = cal_block->cal_info;
2227 if ((audvol_cal_info->path == path) &&
2228 (audvol_cal_info->app_type == app_type) &&
2229 (audvol_cal_info->acdb_id == acdb_id) &&
2230 (cal_block->cal_data.size > 0))
2231 return cal_block;
2232 }
2233 }
2234 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",
2235 __func__, cal_index, path, app_type, acdb_id, sample_rate);
2236 return adm_find_cal_by_app_type(cal_index, path, app_type);
2237}
2238
2239static int adm_remap_and_send_cal_block(int cal_index, int port_id,
2240 int copp_idx, struct cal_block_data *cal_block, int perf_mode,
2241 int app_type, int acdb_id, int sample_rate)
2242{
2243 int ret = 0;
2244
2245 pr_debug("%s: Sending cal_index cal %d\n", __func__, cal_index);
2246 ret = remap_cal_data(cal_block, cal_index);
2247 if (ret) {
2248 pr_err("%s: Remap_cal_data failed for cal %d!\n",
2249 __func__, cal_index);
2250 goto done;
2251 }
2252 ret = send_adm_cal_block(port_id, copp_idx, cal_block, perf_mode,
2253 app_type, acdb_id, sample_rate);
2254 if (ret < 0)
2255 pr_debug("%s: No cal sent for cal_index %d, port_id = 0x%x! ret %d sample_rate %d\n",
2256 __func__, cal_index, port_id, ret, sample_rate);
2257done:
2258 return ret;
2259}
2260
2261static void send_adm_cal_type(int cal_index, int path, int port_id,
2262 int copp_idx, int perf_mode, int app_type,
2263 int acdb_id, int sample_rate)
2264{
2265 struct cal_block_data *cal_block = NULL;
2266 int ret;
2267
2268 pr_debug("%s: cal index %d\n", __func__, cal_index);
2269
2270 if (this_adm.cal_data[cal_index] == NULL) {
2271 pr_debug("%s: cal_index %d not allocated!\n",
2272 __func__, cal_index);
2273 goto done;
2274 }
2275
2276 mutex_lock(&this_adm.cal_data[cal_index]->lock);
2277 cal_block = adm_find_cal(cal_index, path, app_type, acdb_id,
2278 sample_rate);
2279 if (cal_block == NULL)
2280 goto unlock;
2281
2282 ret = adm_remap_and_send_cal_block(cal_index, port_id, copp_idx,
2283 cal_block, perf_mode, app_type, acdb_id, sample_rate);
2284unlock:
2285 mutex_unlock(&this_adm.cal_data[cal_index]->lock);
2286done:
2287 return;
2288}
2289
2290static int get_cal_path(int path)
2291{
2292 if (path == 0x1)
2293 return RX_DEVICE;
2294 else
2295 return TX_DEVICE;
2296}
2297
2298static void send_adm_cal(int port_id, int copp_idx, int path, int perf_mode,
2299 int app_type, int acdb_id, int sample_rate)
2300{
2301 pr_debug("%s: port id 0x%x copp_idx %d\n", __func__, port_id, copp_idx);
2302
2303 send_adm_cal_type(ADM_AUDPROC_CAL, path, port_id, copp_idx, perf_mode,
2304 app_type, acdb_id, sample_rate);
2305 send_adm_cal_type(ADM_AUDVOL_CAL, path, port_id, copp_idx, perf_mode,
2306 app_type, acdb_id, sample_rate);
2307}
2308
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302309/**
2310 * adm_connect_afe_port -
2311 * command to send ADM connect AFE port
2312 *
2313 * @mode: value of mode for ADM connect AFE
2314 * @session_id: session active to connect
2315 * @port_id: Port ID number
2316 *
2317 * Returns 0 on success or error on failure
2318 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302319int adm_connect_afe_port(int mode, int session_id, int port_id)
2320{
2321 struct adm_cmd_connect_afe_port_v5 cmd;
2322 int ret = 0;
2323 int port_idx, copp_idx = 0;
2324
2325 pr_debug("%s: port_id: 0x%x session id:%d mode:%d\n", __func__,
2326 port_id, session_id, mode);
2327
2328 port_id = afe_convert_virtual_to_portid(port_id);
2329 port_idx = adm_validate_and_get_port_index(port_id);
2330 if (port_idx < 0) {
2331 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
2332 return -EINVAL;
2333 }
2334
2335 if (this_adm.apr == NULL) {
2336 this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
2337 0xFFFFFFFF, &this_adm);
2338 if (this_adm.apr == NULL) {
2339 pr_err("%s: Unable to register ADM\n", __func__);
2340 ret = -ENODEV;
2341 return ret;
2342 }
2343 rtac_set_adm_handle(this_adm.apr);
2344 }
2345 pr_debug("%s: Port ID 0x%x, index %d\n", __func__, port_id, port_idx);
2346
2347 cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2348 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
2349 cmd.hdr.pkt_size = sizeof(cmd);
2350 cmd.hdr.src_svc = APR_SVC_ADM;
2351 cmd.hdr.src_domain = APR_DOMAIN_APPS;
2352 cmd.hdr.src_port = port_id;
2353 cmd.hdr.dest_svc = APR_SVC_ADM;
2354 cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
2355 cmd.hdr.dest_port = 0; /* Ignored */
2356 cmd.hdr.token = port_idx << 16 | copp_idx;
2357 cmd.hdr.opcode = ADM_CMD_CONNECT_AFE_PORT_V5;
2358
2359 cmd.mode = mode;
2360 cmd.session_id = session_id;
2361 cmd.afe_port_id = port_id;
2362
2363 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2364 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&cmd);
2365 if (ret < 0) {
2366 pr_err("%s: ADM enable for port_id: 0x%x failed ret %d\n",
2367 __func__, port_id, ret);
2368 ret = -EINVAL;
2369 goto fail_cmd;
2370 }
2371 /* Wait for the callback with copp id */
2372 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2373 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
2374 msecs_to_jiffies(TIMEOUT_MS));
2375 if (!ret) {
2376 pr_err("%s: ADM connect timedout for port_id: 0x%x\n",
2377 __func__, port_id);
2378 ret = -EINVAL;
2379 goto fail_cmd;
2380 } else if (atomic_read(&this_adm.copp.stat
2381 [port_idx][copp_idx]) > 0) {
2382 pr_err("%s: DSP returned error[%s]\n",
2383 __func__, adsp_err_get_err_str(
2384 atomic_read(&this_adm.copp.stat
2385 [port_idx][copp_idx])));
2386 ret = adsp_err_get_lnx_err_code(
2387 atomic_read(&this_adm.copp.stat
2388 [port_idx][copp_idx]));
2389 goto fail_cmd;
2390 }
2391 atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]);
2392 return 0;
2393
2394fail_cmd:
2395
2396 return ret;
2397}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302398EXPORT_SYMBOL(adm_connect_afe_port);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302399
2400int adm_arrange_mch_map(struct adm_cmd_device_open_v5 *open, int path,
2401 int channel_mode)
2402{
2403 int rc = 0, idx;
2404
2405 memset(open->dev_channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2406 switch (path) {
2407 case ADM_PATH_PLAYBACK:
2408 idx = ADM_MCH_MAP_IDX_PLAYBACK;
2409 break;
2410 case ADM_PATH_LIVE_REC:
2411 case ADM_PATH_NONLIVE_REC:
2412 idx = ADM_MCH_MAP_IDX_REC;
2413 break;
2414 default:
2415 goto non_mch_path;
2416 };
2417 if ((open->dev_num_channel > 2) && multi_ch_maps[idx].set_channel_map) {
2418 memcpy(open->dev_channel_mapping,
2419 multi_ch_maps[idx].channel_mapping,
2420 PCM_FORMAT_MAX_NUM_CHANNEL);
2421 } else {
2422 if (channel_mode == 1) {
2423 open->dev_channel_mapping[0] = PCM_CHANNEL_FC;
2424 } else if (channel_mode == 2) {
2425 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2426 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2427 } else if (channel_mode == 3) {
2428 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2429 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2430 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2431 } else if (channel_mode == 4) {
2432 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2433 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2434 open->dev_channel_mapping[2] = PCM_CHANNEL_LS;
2435 open->dev_channel_mapping[3] = PCM_CHANNEL_RS;
2436 } else if (channel_mode == 5) {
2437 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2438 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2439 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2440 open->dev_channel_mapping[3] = PCM_CHANNEL_LS;
2441 open->dev_channel_mapping[4] = PCM_CHANNEL_RS;
2442 } else if (channel_mode == 6) {
2443 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2444 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2445 open->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2446 open->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2447 open->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2448 open->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2449 } else if (channel_mode == 7) {
2450 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2451 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2452 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2453 open->dev_channel_mapping[3] = PCM_CHANNEL_LFE;
2454 open->dev_channel_mapping[4] = PCM_CHANNEL_LB;
2455 open->dev_channel_mapping[5] = PCM_CHANNEL_RB;
2456 open->dev_channel_mapping[6] = PCM_CHANNEL_CS;
2457 } else if (channel_mode == 8) {
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_LFE;
2461 open->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2462 open->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2463 open->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2464 open->dev_channel_mapping[6] = PCM_CHANNEL_LB;
2465 open->dev_channel_mapping[7] = PCM_CHANNEL_RB;
2466 } else {
2467 pr_err("%s: invalid num_chan %d\n", __func__,
2468 channel_mode);
2469 rc = -EINVAL;
2470 goto inval_ch_mod;
2471 }
2472 }
2473
2474non_mch_path:
2475inval_ch_mod:
2476 return rc;
2477}
2478
2479int adm_arrange_mch_ep2_map(struct adm_cmd_device_open_v6 *open_v6,
2480 int channel_mode)
2481{
2482 int rc = 0;
2483
2484 memset(open_v6->dev_channel_mapping_eid2, 0,
2485 PCM_FORMAT_MAX_NUM_CHANNEL);
2486
2487 if (channel_mode == 1) {
2488 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FC;
2489 } else if (channel_mode == 2) {
2490 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2491 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2492 } else if (channel_mode == 3) {
2493 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2494 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2495 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC;
2496 } else if (channel_mode == 4) {
2497 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2498 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2499 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LS;
2500 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_RS;
2501 } else if (channel_mode == 5) {
2502 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2503 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2504 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC;
2505 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_LS;
2506 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_RS;
2507 } else if (channel_mode == 6) {
2508 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2509 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2510 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE;
2511 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC;
2512 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS;
2513 open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS;
2514 } else if (channel_mode == 8) {
2515 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2516 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2517 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE;
2518 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC;
2519 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS;
2520 open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS;
2521 open_v6->dev_channel_mapping_eid2[6] = PCM_CHANNEL_LB;
2522 open_v6->dev_channel_mapping_eid2[7] = PCM_CHANNEL_RB;
2523 } else {
2524 pr_err("%s: invalid num_chan %d\n", __func__,
2525 channel_mode);
2526 rc = -EINVAL;
2527 }
2528
2529 return rc;
2530}
2531
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302532/**
2533 * adm_open -
2534 * command to send ADM open
2535 *
2536 * @port_id: port id number
2537 * @path: direction or ADM path type
2538 * @rate: sample rate of session
2539 * @channel_mode: number of channels set
2540 * @topology: topology active for this session
2541 * @perf_mode: performance mode like LL/ULL/..
2542 * @bit_width: bit width to set for copp
2543 * @app_type: App type used for this session
2544 * @acdb_id: ACDB ID of this device
2545 *
2546 * Returns 0 on success or error on failure
2547 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302548int adm_open(int port_id, int path, int rate, int channel_mode, int topology,
2549 int perf_mode, uint16_t bit_width, int app_type, int acdb_id)
2550{
2551 struct adm_cmd_device_open_v5 open;
2552 struct adm_cmd_device_open_v6 open_v6;
2553 int ret = 0;
Asish Bhattacharya34504582017-08-08 12:55:01 +05302554 int port_idx, flags;
2555 int copp_idx = -1;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302556 int tmp_port = q6audio_get_port_id(port_id);
2557
2558 pr_debug("%s:port %#x path:%d rate:%d mode:%d perf_mode:%d,topo_id %d\n",
2559 __func__, port_id, path, rate, channel_mode, perf_mode,
2560 topology);
2561
2562 port_id = q6audio_convert_virtual_to_portid(port_id);
2563 port_idx = adm_validate_and_get_port_index(port_id);
2564 if (port_idx < 0) {
2565 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
2566 return -EINVAL;
2567 }
2568
2569 if (this_adm.apr == NULL) {
2570 this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
2571 0xFFFFFFFF, &this_adm);
2572 if (this_adm.apr == NULL) {
2573 pr_err("%s: Unable to register ADM\n", __func__);
2574 return -ENODEV;
2575 }
2576 rtac_set_adm_handle(this_adm.apr);
2577 }
2578
2579 if (perf_mode == ULL_POST_PROCESSING_PCM_MODE) {
2580 flags = ADM_ULL_POST_PROCESSING_DEVICE_SESSION;
2581 if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) ||
2582 (topology == DS2_ADM_COPP_TOPOLOGY_ID) ||
2583 (topology == SRS_TRUMEDIA_TOPOLOGY_ID))
2584 topology = DEFAULT_COPP_TOPOLOGY;
2585 } else if (perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) {
2586 flags = ADM_ULTRA_LOW_LATENCY_DEVICE_SESSION;
2587 topology = NULL_COPP_TOPOLOGY;
2588 rate = ULL_SUPPORTED_SAMPLE_RATE;
2589 bit_width = ULL_SUPPORTED_BITS_PER_SAMPLE;
2590 } else if (perf_mode == LOW_LATENCY_PCM_MODE) {
2591 flags = ADM_LOW_LATENCY_DEVICE_SESSION;
2592 if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) ||
2593 (topology == DS2_ADM_COPP_TOPOLOGY_ID) ||
2594 (topology == SRS_TRUMEDIA_TOPOLOGY_ID))
2595 topology = DEFAULT_COPP_TOPOLOGY;
2596 } else {
2597 if ((path == ADM_PATH_COMPRESSED_RX) ||
2598 (path == ADM_PATH_COMPRESSED_TX))
2599 flags = 0;
2600 else
2601 flags = ADM_LEGACY_DEVICE_SESSION;
2602 }
2603
Laxminath Kasam8f7ccc22017-08-28 17:35:04 +05302604 if ((topology == VPM_TX_SM_ECNS_V2_COPP_TOPOLOGY) ||
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302605 (topology == VPM_TX_DM_FLUENCE_COPP_TOPOLOGY) ||
2606 (topology == VPM_TX_DM_RFECNS_COPP_TOPOLOGY))
2607 rate = 16000;
2608
Asish Bhattacharya34504582017-08-08 12:55:01 +05302609 /*
2610 * Routing driver reuses the same adm for streams with the same
2611 * app_type, sample_rate etc.
2612 * This isn't allowed for ULL streams as per the DSP interface
2613 */
2614 if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE)
2615 copp_idx = adm_get_idx_if_copp_exists(port_idx, topology,
2616 perf_mode,
2617 rate, bit_width,
2618 app_type);
2619
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302620 if (copp_idx < 0) {
2621 copp_idx = adm_get_next_available_copp(port_idx);
2622 if (copp_idx >= MAX_COPPS_PER_PORT) {
2623 pr_err("%s: exceeded copp id %d\n",
2624 __func__, copp_idx);
2625 return -EINVAL;
2626 }
2627 atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0);
2628 atomic_set(&this_adm.copp.topology[port_idx][copp_idx],
2629 topology);
2630 atomic_set(&this_adm.copp.mode[port_idx][copp_idx],
2631 perf_mode);
2632 atomic_set(&this_adm.copp.rate[port_idx][copp_idx],
2633 rate);
2634 atomic_set(&this_adm.copp.channels[port_idx][copp_idx],
2635 channel_mode);
2636 atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx],
2637 bit_width);
2638 atomic_set(&this_adm.copp.app_type[port_idx][copp_idx],
2639 app_type);
2640 atomic_set(&this_adm.copp.acdb_id[port_idx][copp_idx],
2641 acdb_id);
2642 set_bit(ADM_STATUS_CALIBRATION_REQUIRED,
2643 (void *)&this_adm.copp.adm_status[port_idx][copp_idx]);
2644 if ((path != ADM_PATH_COMPRESSED_RX) &&
2645 (path != ADM_PATH_COMPRESSED_TX))
2646 send_adm_custom_topology();
2647 }
2648
2649 if (this_adm.copp.adm_delay[port_idx][copp_idx] &&
2650 perf_mode == LEGACY_PCM_MODE) {
2651 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx],
2652 1);
2653 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
2654 wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]);
2655 }
2656
2657 /* Create a COPP if port id are not enabled */
2658 if (atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]) == 0) {
2659 pr_debug("%s: open ADM: port_idx: %d, copp_idx: %d\n", __func__,
2660 port_idx, copp_idx);
2661 if ((topology == SRS_TRUMEDIA_TOPOLOGY_ID) &&
2662 perf_mode == LEGACY_PCM_MODE) {
2663 int res;
2664
2665 atomic_set(&this_adm.mem_map_index, ADM_SRS_TRUMEDIA);
2666 msm_dts_srs_tm_ion_memmap(&this_adm.outband_memmap);
2667 res = adm_memory_map_regions(&this_adm.outband_memmap.paddr, 0,
2668 (uint32_t *)&this_adm.outband_memmap.size, 1);
2669 if (res < 0) {
2670 pr_err("%s: SRS adm_memory_map_regions failed ! addr = 0x%pK, size = %d\n",
2671 __func__, (void *)this_adm.outband_memmap.paddr,
2672 (uint32_t)this_adm.outband_memmap.size);
2673 }
2674 }
2675 open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2676 APR_HDR_LEN(APR_HDR_SIZE),
2677 APR_PKT_VER);
2678 open.hdr.pkt_size = sizeof(open);
2679 open.hdr.src_svc = APR_SVC_ADM;
2680 open.hdr.src_domain = APR_DOMAIN_APPS;
2681 open.hdr.src_port = tmp_port;
2682 open.hdr.dest_svc = APR_SVC_ADM;
2683 open.hdr.dest_domain = APR_DOMAIN_ADSP;
2684 open.hdr.dest_port = tmp_port;
2685 open.hdr.token = port_idx << 16 | copp_idx;
2686 open.hdr.opcode = ADM_CMD_DEVICE_OPEN_V5;
2687 open.flags = flags;
2688 open.mode_of_operation = path;
2689 open.endpoint_id_1 = tmp_port;
2690 open.endpoint_id_2 = 0xFFFF;
2691
2692 if (this_adm.ec_ref_rx && (path != 1)) {
2693 open.endpoint_id_2 = this_adm.ec_ref_rx;
2694 this_adm.ec_ref_rx = -1;
2695 }
2696
2697 open.topology_id = topology;
2698
2699 open.dev_num_channel = channel_mode & 0x00FF;
2700 open.bit_width = bit_width;
2701 WARN_ON((perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) &&
2702 (rate != ULL_SUPPORTED_SAMPLE_RATE));
2703 open.sample_rate = rate;
2704
2705 ret = adm_arrange_mch_map(&open, path, channel_mode);
2706
2707 if (ret)
2708 return ret;
2709
2710 pr_debug("%s: port_id=0x%x rate=%d topology_id=0x%X\n",
2711 __func__, open.endpoint_id_1, open.sample_rate,
2712 open.topology_id);
2713
2714 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2715
2716 if ((this_adm.num_ec_ref_rx_chans != 0) && (path != 1) &&
2717 (open.endpoint_id_2 != 0xFFFF)) {
2718 memset(&open_v6, 0,
2719 sizeof(struct adm_cmd_device_open_v6));
2720 memcpy(&open_v6, &open,
2721 sizeof(struct adm_cmd_device_open_v5));
2722 open_v6.hdr.opcode = ADM_CMD_DEVICE_OPEN_V6;
2723 open_v6.hdr.pkt_size = sizeof(open_v6);
2724 open_v6.dev_num_channel_eid2 =
2725 this_adm.num_ec_ref_rx_chans;
2726 this_adm.num_ec_ref_rx_chans = 0;
2727
2728 if (this_adm.ec_ref_rx_bit_width != 0) {
2729 open_v6.bit_width_eid2 =
2730 this_adm.ec_ref_rx_bit_width;
2731 this_adm.ec_ref_rx_bit_width = 0;
2732 } else {
2733 open_v6.bit_width_eid2 = bit_width;
2734 }
2735
2736 if (this_adm.ec_ref_rx_sampling_rate != 0) {
2737 open_v6.sample_rate_eid2 =
2738 this_adm.ec_ref_rx_sampling_rate;
2739 this_adm.ec_ref_rx_sampling_rate = 0;
2740 } else {
2741 open_v6.sample_rate_eid2 = rate;
2742 }
2743
2744 pr_debug("%s: eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n",
2745 __func__, open_v6.dev_num_channel_eid2,
2746 open_v6.bit_width_eid2,
2747 open_v6.sample_rate_eid2);
2748
2749 ret = adm_arrange_mch_ep2_map(&open_v6,
2750 open_v6.dev_num_channel_eid2);
2751
2752 if (ret)
2753 return ret;
2754
2755 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open_v6);
2756 } else {
2757 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open);
2758 }
2759 if (ret < 0) {
2760 pr_err("%s: port_id: 0x%x for[0x%x] failed %d\n",
2761 __func__, tmp_port, port_id, ret);
2762 return -EINVAL;
2763 }
2764 /* Wait for the callback with copp id */
2765 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2766 atomic_read(&this_adm.copp.stat
2767 [port_idx][copp_idx]) >= 0,
2768 msecs_to_jiffies(TIMEOUT_MS));
2769 if (!ret) {
2770 pr_err("%s: ADM open timedout for port_id: 0x%x for [0x%x]\n",
2771 __func__, tmp_port, port_id);
2772 return -EINVAL;
2773 } else if (atomic_read(&this_adm.copp.stat
2774 [port_idx][copp_idx]) > 0) {
2775 pr_err("%s: DSP returned error[%s]\n",
2776 __func__, adsp_err_get_err_str(
2777 atomic_read(&this_adm.copp.stat
2778 [port_idx][copp_idx])));
2779 return adsp_err_get_lnx_err_code(
2780 atomic_read(&this_adm.copp.stat
2781 [port_idx][copp_idx]));
2782 }
2783 }
2784 atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]);
2785 return copp_idx;
2786}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302787EXPORT_SYMBOL(adm_open);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302788
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302789/**
2790 * adm_copp_mfc_cfg -
2791 * command to send ADM MFC config
2792 *
2793 * @port_id: Port ID number
2794 * @copp_idx: copp index assigned
2795 * @dst_sample_rate: sink sample rate
2796 *
2797 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302798void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate)
2799{
2800 struct audproc_mfc_output_media_fmt mfc_cfg;
2801 struct adm_cmd_device_open_v5 open;
2802 int port_idx;
2803 int sz = 0;
2804 int rc = 0;
2805 int i = 0;
2806
2807 port_id = q6audio_convert_virtual_to_portid(port_id);
2808 port_idx = adm_validate_and_get_port_index(port_id);
2809
2810 if (port_idx < 0) {
2811 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
2812 goto fail_cmd;
2813 }
2814
2815 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
2816 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
2817 goto fail_cmd;
2818 }
2819
2820 sz = sizeof(struct audproc_mfc_output_media_fmt);
2821
2822 mfc_cfg.params.hdr.hdr_field =
2823 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2824 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
2825 mfc_cfg.params.hdr.pkt_size = sz;
2826 mfc_cfg.params.hdr.src_svc = APR_SVC_ADM;
2827 mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS;
2828 mfc_cfg.params.hdr.src_port = port_id;
2829 mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM;
2830 mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP;
2831 mfc_cfg.params.hdr.dest_port =
2832 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
2833 mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx;
2834 mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
2835 mfc_cfg.params.payload_addr_lsw = 0;
2836 mfc_cfg.params.payload_addr_msw = 0;
2837 mfc_cfg.params.mem_map_handle = 0;
2838 mfc_cfg.params.payload_size = sizeof(mfc_cfg) -
2839 sizeof(mfc_cfg.params);
2840 mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC;
2841 mfc_cfg.data.param_id =
2842 AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
2843 mfc_cfg.data.param_size = mfc_cfg.params.payload_size -
2844 sizeof(mfc_cfg.data);
2845 mfc_cfg.data.reserved = 0;
2846 mfc_cfg.sampling_rate = dst_sample_rate;
2847 mfc_cfg.bits_per_sample =
2848 atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]);
2849 open.dev_num_channel = mfc_cfg.num_channels =
2850 atomic_read(&this_adm.copp.channels[port_idx][copp_idx]);
2851
2852 rc = adm_arrange_mch_map(&open, ADM_PATH_PLAYBACK,
2853 mfc_cfg.num_channels);
2854 if (rc < 0) {
2855 pr_err("%s: unable to get channal map\n", __func__);
2856 goto fail_cmd;
2857 }
2858
2859 for (i = 0; i < mfc_cfg.num_channels; i++)
2860 mfc_cfg.channel_type[i] =
2861 (uint16_t) open.dev_channel_mapping[i];
2862
2863 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2864
2865 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",
2866 __func__, port_idx, copp_idx,
2867 atomic_read(&this_adm.copp.rate[port_idx][copp_idx]),
2868 mfc_cfg.bits_per_sample, mfc_cfg.num_channels,
2869 mfc_cfg.sampling_rate);
2870
2871 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg);
2872
2873 if (rc < 0) {
2874 pr_err("%s: port_id: for[0x%x] failed %d\n",
2875 __func__, port_id, rc);
2876 goto fail_cmd;
2877 }
2878 /* Wait for the callback with copp id */
2879 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2880 atomic_read(&this_adm.copp.stat
2881 [port_idx][copp_idx]) >= 0,
2882 msecs_to_jiffies(TIMEOUT_MS));
2883 if (!rc) {
2884 pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n",
2885 __func__, port_id);
2886 goto fail_cmd;
2887 } else if (atomic_read(&this_adm.copp.stat
2888 [port_idx][copp_idx]) > 0) {
2889 pr_err("%s: DSP returned error[%s]\n",
2890 __func__, adsp_err_get_err_str(
2891 atomic_read(&this_adm.copp.stat
2892 [port_idx][copp_idx])));
2893 goto fail_cmd;
2894 }
2895 rc = 0;
2896fail_cmd:
2897 return;
2898}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302899EXPORT_SYMBOL(adm_copp_mfc_cfg);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302900
2901static void route_set_opcode_matrix_id(
2902 struct adm_cmd_matrix_map_routings_v5 **route_addr,
2903 int path, uint32_t passthr_mode)
2904{
2905 struct adm_cmd_matrix_map_routings_v5 *route = *route_addr;
2906
2907 switch (path) {
2908 case ADM_PATH_PLAYBACK:
2909 route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5;
2910 route->matrix_id = ADM_MATRIX_ID_AUDIO_RX;
2911 break;
2912 case ADM_PATH_LIVE_REC:
2913 if (passthr_mode == LISTEN) {
2914 route->hdr.opcode =
2915 ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
2916 route->matrix_id = ADM_MATRIX_ID_LISTEN_TX;
2917 break;
2918 }
2919 /* fall through to set matrix id for non-listen case */
2920 case ADM_PATH_NONLIVE_REC:
2921 route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5;
2922 route->matrix_id = ADM_MATRIX_ID_AUDIO_TX;
2923 break;
2924 case ADM_PATH_COMPRESSED_RX:
2925 route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
2926 route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_RX;
2927 break;
2928 case ADM_PATH_COMPRESSED_TX:
2929 route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
2930 route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_TX;
2931 break;
2932 default:
2933 pr_err("%s: Wrong path set[%d]\n", __func__, path);
2934 break;
2935 }
2936 pr_debug("%s: opcode 0x%x, matrix id %d\n",
2937 __func__, route->hdr.opcode, route->matrix_id);
2938}
2939
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302940/**
2941 * adm_matrix_map -
2942 * command to send ADM matrix map for ADM copp list
2943 *
2944 * @path: direction or ADM path type
2945 * @payload_map: have info of session id and associated copp_idx/num_copps
2946 * @perf_mode: performance mode like LL/ULL/..
2947 * @passthr_mode: flag to indicate passthrough mode
2948 *
2949 * Returns 0 on success or error on failure
2950 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302951int adm_matrix_map(int path, struct route_payload payload_map, int perf_mode,
2952 uint32_t passthr_mode)
2953{
2954 struct adm_cmd_matrix_map_routings_v5 *route;
2955 struct adm_session_map_node_v5 *node;
2956 uint16_t *copps_list;
2957 int cmd_size = 0;
2958 int ret = 0, i = 0;
2959 void *payload = NULL;
2960 void *matrix_map = NULL;
2961 int port_idx, copp_idx;
2962
2963 /* Assumes port_ids have already been validated during adm_open */
2964 cmd_size = (sizeof(struct adm_cmd_matrix_map_routings_v5) +
2965 sizeof(struct adm_session_map_node_v5) +
2966 (sizeof(uint32_t) * payload_map.num_copps));
2967 matrix_map = kzalloc(cmd_size, GFP_KERNEL);
2968 if (matrix_map == NULL) {
2969 pr_err("%s: Mem alloc failed\n", __func__);
2970 ret = -EINVAL;
2971 return ret;
2972 }
2973 route = (struct adm_cmd_matrix_map_routings_v5 *)matrix_map;
2974
2975 route->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2976 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
2977 route->hdr.pkt_size = cmd_size;
2978 route->hdr.src_svc = 0;
2979 route->hdr.src_domain = APR_DOMAIN_APPS;
2980 route->hdr.src_port = 0; /* Ignored */;
2981 route->hdr.dest_svc = APR_SVC_ADM;
2982 route->hdr.dest_domain = APR_DOMAIN_ADSP;
2983 route->hdr.dest_port = 0; /* Ignored */;
2984 route->hdr.token = 0;
2985 route->num_sessions = 1;
2986 route_set_opcode_matrix_id(&route, path, passthr_mode);
2987
2988 payload = ((u8 *)matrix_map +
2989 sizeof(struct adm_cmd_matrix_map_routings_v5));
2990 node = (struct adm_session_map_node_v5 *)payload;
2991
2992 node->session_id = payload_map.session_id;
2993 node->num_copps = payload_map.num_copps;
2994 payload = (u8 *)node + sizeof(struct adm_session_map_node_v5);
2995 copps_list = (uint16_t *)payload;
2996 for (i = 0; i < payload_map.num_copps; i++) {
2997 port_idx =
2998 adm_validate_and_get_port_index(payload_map.port_id[i]);
2999 if (port_idx < 0) {
3000 pr_err("%s: Invalid port_id 0x%x\n", __func__,
3001 payload_map.port_id[i]);
3002 ret = -EINVAL;
3003 goto fail_cmd;
3004 }
3005 copp_idx = payload_map.copp_idx[i];
3006 copps_list[i] = atomic_read(&this_adm.copp.id[port_idx]
3007 [copp_idx]);
3008 }
3009 atomic_set(&this_adm.matrix_map_stat, -1);
3010
3011 ret = apr_send_pkt(this_adm.apr, (uint32_t *)matrix_map);
3012 if (ret < 0) {
3013 pr_err("%s: routing for syream %d failed ret %d\n",
3014 __func__, payload_map.session_id, ret);
3015 ret = -EINVAL;
3016 goto fail_cmd;
3017 }
3018 ret = wait_event_timeout(this_adm.matrix_map_wait,
3019 atomic_read(&this_adm.matrix_map_stat) >= 0,
3020 msecs_to_jiffies(TIMEOUT_MS));
3021 if (!ret) {
3022 pr_err("%s: routing for syream %d failed\n", __func__,
3023 payload_map.session_id);
3024 ret = -EINVAL;
3025 goto fail_cmd;
3026 } else if (atomic_read(&this_adm.matrix_map_stat) > 0) {
3027 pr_err("%s: DSP returned error[%s]\n", __func__,
3028 adsp_err_get_err_str(atomic_read(
3029 &this_adm.matrix_map_stat)));
3030 ret = adsp_err_get_lnx_err_code(
3031 atomic_read(&this_adm.matrix_map_stat));
3032 goto fail_cmd;
3033 }
3034
3035 if ((perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) &&
3036 (path != ADM_PATH_COMPRESSED_RX)) {
3037 for (i = 0; i < payload_map.num_copps; i++) {
3038 port_idx = afe_get_port_index(payload_map.port_id[i]);
3039 copp_idx = payload_map.copp_idx[i];
3040 if (port_idx < 0 || copp_idx < 0 ||
3041 (copp_idx > MAX_COPPS_PER_PORT - 1)) {
3042 pr_err("%s: Invalid idx port_idx %d copp_idx %d\n",
3043 __func__, port_idx, copp_idx);
3044 continue;
3045 }
3046 rtac_add_adm_device(payload_map.port_id[i],
3047 atomic_read(&this_adm.copp.id
3048 [port_idx][copp_idx]),
3049 get_cal_path(path),
3050 payload_map.session_id,
3051 payload_map.app_type[i],
3052 payload_map.acdb_dev_id[i]);
3053
3054 if (!test_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3055 (void *)&this_adm.copp.adm_status[port_idx]
3056 [copp_idx])) {
3057 pr_debug("%s: adm copp[0x%x][%d] already sent",
3058 __func__, port_idx, copp_idx);
3059 continue;
3060 }
3061 send_adm_cal(payload_map.port_id[i], copp_idx,
3062 get_cal_path(path), perf_mode,
3063 payload_map.app_type[i],
3064 payload_map.acdb_dev_id[i],
3065 payload_map.sample_rate[i]);
3066 /* ADM COPP calibration is already sent */
3067 clear_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3068 (void *)&this_adm.copp.
3069 adm_status[port_idx][copp_idx]);
3070 pr_debug("%s: copp_id: %d\n", __func__,
3071 atomic_read(&this_adm.copp.id[port_idx]
3072 [copp_idx]));
3073 }
3074 }
3075
3076fail_cmd:
3077 kfree(matrix_map);
3078 return ret;
3079}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303080EXPORT_SYMBOL(adm_matrix_map);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303081
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303082/**
3083 * adm_ec_ref_rx_id -
3084 * Update EC ref port ID
3085 *
3086 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303087void adm_ec_ref_rx_id(int port_id)
3088{
3089 this_adm.ec_ref_rx = port_id;
3090 pr_debug("%s: ec_ref_rx:%d\n", __func__, this_adm.ec_ref_rx);
3091}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303092EXPORT_SYMBOL(adm_ec_ref_rx_id);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303093
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303094/**
3095 * adm_num_ec_ref_rx_chans -
3096 * Update EC ref number of channels
3097 *
3098 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303099void adm_num_ec_ref_rx_chans(int num_chans)
3100{
3101 this_adm.num_ec_ref_rx_chans = num_chans;
3102 pr_debug("%s: num_ec_ref_rx_chans:%d\n",
3103 __func__, this_adm.num_ec_ref_rx_chans);
3104}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303105EXPORT_SYMBOL(adm_num_ec_ref_rx_chans);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303106
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303107/**
3108 * adm_ec_ref_rx_bit_width -
3109 * Update EC ref bit_width
3110 *
3111 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303112void adm_ec_ref_rx_bit_width(int bit_width)
3113{
3114 this_adm.ec_ref_rx_bit_width = bit_width;
3115 pr_debug("%s: ec_ref_rx_bit_width:%d\n",
3116 __func__, this_adm.ec_ref_rx_bit_width);
3117}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303118EXPORT_SYMBOL(adm_ec_ref_rx_bit_width);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303119
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303120/**
3121 * adm_ec_ref_rx_sampling_rate -
3122 * Update EC ref sample rate
3123 *
3124 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303125void adm_ec_ref_rx_sampling_rate(int sampling_rate)
3126{
3127 this_adm.ec_ref_rx_sampling_rate = sampling_rate;
3128 pr_debug("%s: ec_ref_rx_sampling_rate:%d\n",
3129 __func__, this_adm.ec_ref_rx_sampling_rate);
3130}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303131EXPORT_SYMBOL(adm_ec_ref_rx_sampling_rate);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303132
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303133/**
3134 * adm_close -
3135 * command to close ADM copp
3136 *
3137 * @port_id: Port ID number
3138 * @perf_mode: performance mode like LL/ULL/..
3139 * @copp_idx: copp index assigned
3140 *
3141 * Returns 0 on success or error on failure
3142 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303143int adm_close(int port_id, int perf_mode, int copp_idx)
3144{
3145 struct apr_hdr close;
3146
3147 int ret = 0, port_idx;
3148 int copp_id = RESET_COPP_ID;
3149
3150 pr_debug("%s: port_id=0x%x perf_mode: %d copp_idx: %d\n", __func__,
3151 port_id, perf_mode, copp_idx);
3152
3153 port_id = q6audio_convert_virtual_to_portid(port_id);
3154 port_idx = adm_validate_and_get_port_index(port_id);
3155 if (port_idx < 0) {
3156 pr_err("%s: Invalid port_id 0x%x\n",
3157 __func__, port_id);
3158 return -EINVAL;
3159 }
3160
3161 if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) {
3162 pr_err("%s: Invalid copp idx: %d\n", __func__, copp_idx);
3163 return -EINVAL;
3164 }
3165
3166 if (this_adm.copp.adm_delay[port_idx][copp_idx] && perf_mode
3167 == LEGACY_PCM_MODE) {
3168 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx],
3169 1);
3170 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
3171 wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]);
3172 }
3173
3174 atomic_dec(&this_adm.copp.cnt[port_idx][copp_idx]);
3175 if (!(atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]))) {
3176 copp_id = adm_get_copp_id(port_idx, copp_idx);
3177 pr_debug("%s: Closing ADM port_idx:%d copp_idx:%d copp_id:0x%x\n",
3178 __func__, port_idx, copp_idx, copp_id);
3179 if ((!perf_mode) && (this_adm.outband_memmap.paddr != 0) &&
3180 (atomic_read(&this_adm.copp.topology[port_idx][copp_idx]) ==
3181 SRS_TRUMEDIA_TOPOLOGY_ID)) {
3182 atomic_set(&this_adm.mem_map_index,
3183 ADM_SRS_TRUMEDIA);
3184 ret = adm_memory_unmap_regions();
3185 if (ret < 0) {
3186 pr_err("%s: adm mem unmmap err %d",
3187 __func__, ret);
3188 } else {
3189 atomic_set(&this_adm.mem_map_handles
3190 [ADM_SRS_TRUMEDIA], 0);
3191 }
3192 }
3193
3194
3195 if ((afe_get_port_type(port_id) == MSM_AFE_PORT_TYPE_TX) &&
3196 this_adm.sourceTrackingData.memmap.paddr) {
3197 atomic_set(&this_adm.mem_map_index,
3198 ADM_MEM_MAP_INDEX_SOURCE_TRACKING);
3199 ret = adm_memory_unmap_regions();
3200 if (ret < 0) {
3201 pr_err("%s: adm mem unmmap err %d",
3202 __func__, ret);
3203 }
3204 msm_audio_ion_free(
3205 this_adm.sourceTrackingData.ion_client,
3206 this_adm.sourceTrackingData.ion_handle);
3207 this_adm.sourceTrackingData.ion_client = NULL;
3208 this_adm.sourceTrackingData.ion_handle = NULL;
3209 this_adm.sourceTrackingData.memmap.size = 0;
3210 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
3211 this_adm.sourceTrackingData.memmap.paddr = 0;
3212 this_adm.sourceTrackingData.apr_cmd_status = -1;
3213 atomic_set(&this_adm.mem_map_handles[
3214 ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
3215 }
3216
3217 close.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3218 APR_HDR_LEN(APR_HDR_SIZE),
3219 APR_PKT_VER);
3220 close.pkt_size = sizeof(close);
3221 close.src_svc = APR_SVC_ADM;
3222 close.src_domain = APR_DOMAIN_APPS;
3223 close.src_port = port_id;
3224 close.dest_svc = APR_SVC_ADM;
3225 close.dest_domain = APR_DOMAIN_ADSP;
3226 close.dest_port = copp_id;
3227 close.token = port_idx << 16 | copp_idx;
3228 close.opcode = ADM_CMD_DEVICE_CLOSE_V5;
3229
3230 atomic_set(&this_adm.copp.id[port_idx][copp_idx],
3231 RESET_COPP_ID);
3232 atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0);
3233 atomic_set(&this_adm.copp.topology[port_idx][copp_idx], 0);
3234 atomic_set(&this_adm.copp.mode[port_idx][copp_idx], 0);
3235 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3236 atomic_set(&this_adm.copp.rate[port_idx][copp_idx], 0);
3237 atomic_set(&this_adm.copp.channels[port_idx][copp_idx], 0);
3238 atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx], 0);
3239 atomic_set(&this_adm.copp.app_type[port_idx][copp_idx], 0);
3240
3241 clear_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3242 (void *)&this_adm.copp.adm_status[port_idx][copp_idx]);
3243
3244 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close);
3245 if (ret < 0) {
3246 pr_err("%s: ADM close failed %d\n", __func__, ret);
3247 return -EINVAL;
3248 }
3249
3250 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3251 atomic_read(&this_adm.copp.stat
3252 [port_idx][copp_idx]) >= 0,
3253 msecs_to_jiffies(TIMEOUT_MS));
3254 if (!ret) {
3255 pr_err("%s: ADM cmd Route timedout for port 0x%x\n",
3256 __func__, port_id);
3257 return -EINVAL;
3258 } else if (atomic_read(&this_adm.copp.stat
3259 [port_idx][copp_idx]) > 0) {
3260 pr_err("%s: DSP returned error[%s]\n",
3261 __func__, adsp_err_get_err_str(
3262 atomic_read(&this_adm.copp.stat
3263 [port_idx][copp_idx])));
3264 return adsp_err_get_lnx_err_code(
3265 atomic_read(&this_adm.copp.stat
3266 [port_idx][copp_idx]));
3267 }
3268 }
3269
3270 if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) {
3271 pr_debug("%s: remove adm device from rtac\n", __func__);
3272 rtac_remove_adm_device(port_id, copp_id);
3273 }
3274 return 0;
3275}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303276EXPORT_SYMBOL(adm_close);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303277
3278int send_rtac_audvol_cal(void)
3279{
3280 int ret = 0;
3281 int ret2 = 0;
3282 int i = 0;
3283 int copp_idx, port_idx, acdb_id, app_id, path;
3284 struct cal_block_data *cal_block = NULL;
3285 struct audio_cal_info_audvol *audvol_cal_info = NULL;
3286 struct rtac_adm rtac_adm_data;
3287
3288 mutex_lock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock);
3289
3290 cal_block = cal_utils_get_only_cal_block(
3291 this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]);
3292 if (cal_block == NULL) {
3293 pr_err("%s: can't find cal block!\n", __func__);
3294 goto unlock;
3295 }
3296
3297 audvol_cal_info = cal_block->cal_info;
3298 if (audvol_cal_info == NULL) {
3299 pr_err("%s: audvol_cal_info is NULL!\n", __func__);
3300 goto unlock;
3301 }
3302
3303 get_rtac_adm_data(&rtac_adm_data);
3304 for (; i < rtac_adm_data.num_of_dev; i++) {
3305
3306 acdb_id = rtac_adm_data.device[i].acdb_dev_id;
3307 if (acdb_id == 0)
3308 acdb_id = audvol_cal_info->acdb_id;
3309
3310 app_id = rtac_adm_data.device[i].app_type;
3311 if (app_id == 0)
3312 app_id = audvol_cal_info->app_type;
3313
3314 path = afe_get_port_type(rtac_adm_data.device[i].afe_port);
3315 if ((acdb_id == audvol_cal_info->acdb_id) &&
3316 (app_id == audvol_cal_info->app_type) &&
3317 (path == audvol_cal_info->path)) {
3318
3319 if (adm_get_indexes_from_copp_id(rtac_adm_data.
3320 device[i].copp, &copp_idx, &port_idx) != 0) {
3321 pr_debug("%s: Copp Id %d is not active\n",
3322 __func__,
3323 rtac_adm_data.device[i].copp);
3324 continue;
3325 }
3326
3327 ret2 = adm_remap_and_send_cal_block(ADM_RTAC_AUDVOL_CAL,
3328 rtac_adm_data.device[i].afe_port,
3329 copp_idx, cal_block,
3330 atomic_read(&this_adm.copp.
3331 mode[port_idx][copp_idx]),
3332 audvol_cal_info->app_type,
3333 audvol_cal_info->acdb_id,
3334 atomic_read(&this_adm.copp.
3335 rate[port_idx][copp_idx]));
3336 if (ret2 < 0) {
3337 pr_debug("%s: remap and send failed for copp Id %d, acdb id %d, app type %d, path %d\n",
3338 __func__, rtac_adm_data.device[i].copp,
3339 audvol_cal_info->acdb_id,
3340 audvol_cal_info->app_type,
3341 audvol_cal_info->path);
3342 ret = ret2;
3343 }
3344 }
3345 }
3346unlock:
3347 mutex_unlock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock);
3348 return ret;
3349}
3350
3351int adm_map_rtac_block(struct rtac_cal_block_data *cal_block)
3352{
3353 int result = 0;
3354
3355 pr_debug("%s:\n", __func__);
3356
3357 if (cal_block == NULL) {
3358 pr_err("%s: cal_block is NULL!\n",
3359 __func__);
3360 result = -EINVAL;
3361 goto done;
3362 }
3363
3364 if (cal_block->cal_data.paddr == 0) {
3365 pr_debug("%s: No address to map!\n",
3366 __func__);
3367 result = -EINVAL;
3368 goto done;
3369 }
3370
3371 if (cal_block->map_data.map_size == 0) {
3372 pr_debug("%s: map size is 0!\n",
3373 __func__);
3374 result = -EINVAL;
3375 goto done;
3376 }
3377
3378 /* valid port ID needed for callback use primary I2S */
3379 atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL);
3380 result = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
3381 &cal_block->map_data.map_size, 1);
3382 if (result < 0) {
3383 pr_err("%s: RTAC mmap did not work! size = %d result %d\n",
3384 __func__,
3385 cal_block->map_data.map_size, result);
3386 pr_debug("%s: RTAC mmap did not work! addr = 0x%pK, size = %d\n",
3387 __func__,
3388 &cal_block->cal_data.paddr,
3389 cal_block->map_data.map_size);
3390 goto done;
3391 }
3392
3393 cal_block->map_data.map_handle = atomic_read(
3394 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]);
3395done:
3396 return result;
3397}
3398
3399int adm_unmap_rtac_block(uint32_t *mem_map_handle)
3400{
3401 int result = 0;
3402
3403 pr_debug("%s:\n", __func__);
3404
3405 if (mem_map_handle == NULL) {
3406 pr_debug("%s: Map handle is NULL, nothing to unmap\n",
3407 __func__);
3408 goto done;
3409 }
3410
3411 if (*mem_map_handle == 0) {
3412 pr_debug("%s: Map handle is 0, nothing to unmap\n",
3413 __func__);
3414 goto done;
3415 }
3416
3417 if (*mem_map_handle != atomic_read(
3418 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL])) {
3419 pr_err("%s: Map handles do not match! Unmapping RTAC, RTAC map 0x%x, ADM map 0x%x\n",
3420 __func__, *mem_map_handle, atomic_read(
3421 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]));
3422
3423 /* if mismatch use handle passed in to unmap */
3424 atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL],
3425 *mem_map_handle);
3426 }
3427
3428 /* valid port ID needed for callback use primary I2S */
3429 atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL);
3430 result = adm_memory_unmap_regions();
3431 if (result < 0) {
3432 pr_debug("%s: adm_memory_unmap_regions failed, error %d\n",
3433 __func__, result);
3434 } else {
3435 atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL], 0);
3436 *mem_map_handle = 0;
3437 }
3438done:
3439 return result;
3440}
3441
3442static int get_cal_type_index(int32_t cal_type)
3443{
3444 int ret = -EINVAL;
3445
3446 switch (cal_type) {
3447 case ADM_AUDPROC_CAL_TYPE:
3448 ret = ADM_AUDPROC_CAL;
3449 break;
3450 case ADM_AUDVOL_CAL_TYPE:
3451 ret = ADM_AUDVOL_CAL;
3452 break;
3453 case ADM_CUST_TOPOLOGY_CAL_TYPE:
3454 ret = ADM_CUSTOM_TOP_CAL;
3455 break;
3456 case ADM_RTAC_INFO_CAL_TYPE:
3457 ret = ADM_RTAC_INFO_CAL;
3458 break;
3459 case ADM_RTAC_APR_CAL_TYPE:
3460 ret = ADM_RTAC_APR_CAL;
3461 break;
3462 case ADM_RTAC_AUDVOL_CAL_TYPE:
3463 ret = ADM_RTAC_AUDVOL_CAL;
3464 break;
3465 default:
3466 pr_err("%s: invalid cal type %d!\n", __func__, cal_type);
3467 }
3468 return ret;
3469}
3470
3471static int adm_alloc_cal(int32_t cal_type, size_t data_size, void *data)
3472{
3473 int ret = 0;
3474 int cal_index;
3475
3476 pr_debug("%s:\n", __func__);
3477
3478 cal_index = get_cal_type_index(cal_type);
3479 if (cal_index < 0) {
3480 pr_err("%s: could not get cal index %d!\n",
3481 __func__, cal_index);
3482 ret = -EINVAL;
3483 goto done;
3484 }
3485
3486 ret = cal_utils_alloc_cal(data_size, data,
3487 this_adm.cal_data[cal_index], 0, NULL);
3488 if (ret < 0) {
3489 pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
3490 __func__, ret, cal_type);
3491 ret = -EINVAL;
3492 goto done;
3493 }
3494done:
3495 return ret;
3496}
3497
3498static int adm_dealloc_cal(int32_t cal_type, size_t data_size, void *data)
3499{
3500 int ret = 0;
3501 int cal_index;
3502
3503 pr_debug("%s:\n", __func__);
3504
3505 cal_index = get_cal_type_index(cal_type);
3506 if (cal_index < 0) {
3507 pr_err("%s: could not get cal index %d!\n",
3508 __func__, cal_index);
3509 ret = -EINVAL;
3510 goto done;
3511 }
3512
3513 ret = cal_utils_dealloc_cal(data_size, data,
3514 this_adm.cal_data[cal_index]);
3515 if (ret < 0) {
3516 pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
3517 __func__, ret, cal_type);
3518 ret = -EINVAL;
3519 goto done;
3520 }
3521done:
3522 return ret;
3523}
3524
3525static int adm_set_cal(int32_t cal_type, size_t data_size, void *data)
3526{
3527 int ret = 0;
3528 int cal_index;
3529
3530 pr_debug("%s:\n", __func__);
3531
3532 cal_index = get_cal_type_index(cal_type);
3533 if (cal_index < 0) {
3534 pr_err("%s: could not get cal index %d!\n",
3535 __func__, cal_index);
3536 ret = -EINVAL;
3537 goto done;
3538 }
3539
3540 ret = cal_utils_set_cal(data_size, data,
3541 this_adm.cal_data[cal_index], 0, NULL);
3542 if (ret < 0) {
3543 pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
3544 __func__, ret, cal_type);
3545 ret = -EINVAL;
3546 goto done;
3547 }
3548
3549 if (cal_index == ADM_CUSTOM_TOP_CAL) {
3550 mutex_lock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock);
3551 this_adm.set_custom_topology = 1;
3552 mutex_unlock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock);
3553 } else if (cal_index == ADM_RTAC_AUDVOL_CAL) {
3554 send_rtac_audvol_cal();
3555 }
3556done:
3557 return ret;
3558}
3559
3560static int adm_map_cal_data(int32_t cal_type,
3561 struct cal_block_data *cal_block)
3562{
3563 int ret = 0;
3564 int cal_index;
3565
3566 pr_debug("%s:\n", __func__);
3567
3568 cal_index = get_cal_type_index(cal_type);
3569 if (cal_index < 0) {
3570 pr_err("%s: could not get cal index %d!\n",
3571 __func__, cal_index);
3572 ret = -EINVAL;
3573 goto done;
3574 }
3575
3576 atomic_set(&this_adm.mem_map_index, cal_index);
3577 ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
3578 (uint32_t *)&cal_block->map_data.map_size, 1);
3579 if (ret < 0) {
3580 pr_err("%s: map did not work! cal_type %i ret %d\n",
3581 __func__, cal_index, ret);
3582 ret = -ENODEV;
3583 goto done;
3584 }
3585 cal_block->map_data.q6map_handle = atomic_read(&this_adm.
3586 mem_map_handles[cal_index]);
3587done:
3588 return ret;
3589}
3590
3591static int adm_unmap_cal_data(int32_t cal_type,
3592 struct cal_block_data *cal_block)
3593{
3594 int ret = 0;
3595 int cal_index;
3596
3597 pr_debug("%s:\n", __func__);
3598
3599 cal_index = get_cal_type_index(cal_type);
3600 if (cal_index < 0) {
3601 pr_err("%s: could not get cal index %d!\n",
3602 __func__, cal_index);
3603 ret = -EINVAL;
3604 goto done;
3605 }
3606
3607 if (cal_block == NULL) {
3608 pr_err("%s: Cal block is NULL!\n",
3609 __func__);
3610 goto done;
3611 }
3612
3613 if (cal_block->map_data.q6map_handle == 0) {
3614 pr_err("%s: Map handle is NULL, nothing to unmap\n",
3615 __func__);
3616 goto done;
3617 }
3618
3619 atomic_set(&this_adm.mem_map_handles[cal_index],
3620 cal_block->map_data.q6map_handle);
3621 atomic_set(&this_adm.mem_map_index, cal_index);
3622 ret = adm_memory_unmap_regions();
3623 if (ret < 0) {
3624 pr_err("%s: unmap did not work! cal_type %i ret %d\n",
3625 __func__, cal_index, ret);
3626 ret = -ENODEV;
3627 goto done;
3628 }
3629 cal_block->map_data.q6map_handle = 0;
3630done:
3631 return ret;
3632}
3633
3634static void adm_delete_cal_data(void)
3635{
3636 pr_debug("%s:\n", __func__);
3637
3638 cal_utils_destroy_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data);
3639}
3640
3641static int adm_init_cal_data(void)
3642{
3643 int ret = 0;
3644 struct cal_type_info cal_type_info[] = {
3645 {{ADM_CUST_TOPOLOGY_CAL_TYPE,
3646 {adm_alloc_cal, adm_dealloc_cal, NULL,
3647 adm_set_cal, NULL, NULL} },
3648 {adm_map_cal_data, adm_unmap_cal_data,
3649 cal_utils_match_buf_num} },
3650
3651 {{ADM_AUDPROC_CAL_TYPE,
3652 {adm_alloc_cal, adm_dealloc_cal, NULL,
3653 adm_set_cal, NULL, NULL} },
3654 {adm_map_cal_data, adm_unmap_cal_data,
3655 cal_utils_match_buf_num} },
3656
3657 {{ADM_AUDVOL_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_RTAC_INFO_CAL_TYPE,
3664 {NULL, NULL, NULL, NULL, NULL, NULL} },
3665 {NULL, NULL, cal_utils_match_buf_num} },
3666
3667 {{ADM_RTAC_APR_CAL_TYPE,
3668 {NULL, NULL, NULL, NULL, NULL, NULL} },
3669 {NULL, NULL, cal_utils_match_buf_num} },
3670
3671 {{SRS_TRUMEDIA_CAL_TYPE,
3672 {NULL, NULL, NULL, NULL, NULL, NULL} },
3673 {NULL, NULL, cal_utils_match_buf_num} },
3674
3675 {{ADM_RTAC_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 pr_debug("%s:\n", __func__);
3682
3683 ret = cal_utils_create_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data,
3684 cal_type_info);
3685 if (ret < 0) {
3686 pr_err("%s: could not create cal type! ret %d\n",
3687 __func__, ret);
3688 ret = -EINVAL;
3689 goto err;
3690 }
3691
3692 return ret;
3693err:
3694 adm_delete_cal_data();
3695 return ret;
3696}
3697
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303698/**
3699 * adm_set_volume -
3700 * command to set volume on ADM copp
3701 *
3702 * @port_id: Port ID number
3703 * @copp_idx: copp index assigned
3704 * @volume: gain value to set
3705 *
3706 * Returns 0 on success or error on failure
3707 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303708int adm_set_volume(int port_id, int copp_idx, int volume)
3709{
3710 struct audproc_volume_ctrl_master_gain audproc_vol;
3711 int sz = 0;
3712 int rc = 0;
3713 int port_idx;
3714
3715 pr_debug("%s: port_id %d, volume %d\n", __func__, port_id, volume);
3716 port_id = afe_convert_virtual_to_portid(port_id);
3717 port_idx = adm_validate_and_get_port_index(port_id);
3718 if (port_idx < 0) {
3719 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
3720 rc = -EINVAL;
3721 goto fail_cmd;
3722 }
3723
3724 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
3725 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
3726 return -EINVAL;
3727 }
3728
3729 sz = sizeof(struct audproc_volume_ctrl_master_gain);
3730 audproc_vol.params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3731 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
3732 audproc_vol.params.hdr.pkt_size = sz;
3733 audproc_vol.params.hdr.src_svc = APR_SVC_ADM;
3734 audproc_vol.params.hdr.src_domain = APR_DOMAIN_APPS;
3735 audproc_vol.params.hdr.src_port = port_id;
3736 audproc_vol.params.hdr.dest_svc = APR_SVC_ADM;
3737 audproc_vol.params.hdr.dest_domain = APR_DOMAIN_ADSP;
3738 audproc_vol.params.hdr.dest_port =
3739 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
3740 audproc_vol.params.hdr.token = port_idx << 16 | copp_idx;
3741 audproc_vol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
3742 audproc_vol.params.payload_addr_lsw = 0;
3743 audproc_vol.params.payload_addr_msw = 0;
3744 audproc_vol.params.mem_map_handle = 0;
3745 audproc_vol.params.payload_size = sizeof(audproc_vol) -
3746 sizeof(audproc_vol.params);
3747 audproc_vol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL;
3748 audproc_vol.data.param_id = AUDPROC_PARAM_ID_VOL_CTRL_MASTER_GAIN;
3749 audproc_vol.data.param_size = audproc_vol.params.payload_size -
3750 sizeof(audproc_vol.data);
3751 audproc_vol.data.reserved = 0;
3752 audproc_vol.master_gain = volume;
3753
3754 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3755 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_vol);
3756 if (rc < 0) {
3757 pr_err("%s: Set params failed port = %#x\n",
3758 __func__, port_id);
3759 rc = -EINVAL;
3760 goto fail_cmd;
3761 }
3762 /* Wait for the callback */
3763 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3764 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
3765 msecs_to_jiffies(TIMEOUT_MS));
3766 if (!rc) {
3767 pr_err("%s: Vol cntrl Set params timed out port = %#x\n",
3768 __func__, port_id);
3769 rc = -EINVAL;
3770 goto fail_cmd;
3771 } else if (atomic_read(&this_adm.copp.stat
3772 [port_idx][copp_idx]) > 0) {
3773 pr_err("%s: DSP returned error[%s]\n",
3774 __func__, adsp_err_get_err_str(
3775 atomic_read(&this_adm.copp.stat
3776 [port_idx][copp_idx])));
3777 rc = adsp_err_get_lnx_err_code(
3778 atomic_read(&this_adm.copp.stat
3779 [port_idx][copp_idx]));
3780 goto fail_cmd;
3781 }
3782 rc = 0;
3783fail_cmd:
3784 return rc;
3785}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303786EXPORT_SYMBOL(adm_set_volume);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303787
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303788/**
3789 * adm_set_softvolume -
3790 * command to set softvolume
3791 *
3792 * @port_id: Port ID number
3793 * @copp_idx: copp index assigned
3794 * @softvol_param: Params to set for softvolume
3795 *
3796 * Returns 0 on success or error on failure
3797 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303798int adm_set_softvolume(int port_id, int copp_idx,
3799 struct audproc_softvolume_params *softvol_param)
3800{
3801 struct audproc_soft_step_volume_params audproc_softvol;
3802 int sz = 0;
3803 int rc = 0;
3804 int port_idx;
3805
3806 pr_debug("%s: period %d step %d curve %d\n", __func__,
3807 softvol_param->period, softvol_param->step,
3808 softvol_param->rampingcurve);
3809
3810 port_id = afe_convert_virtual_to_portid(port_id);
3811 port_idx = adm_validate_and_get_port_index(port_id);
3812 if (port_idx < 0) {
3813 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
3814 rc = -EINVAL;
3815 goto fail_cmd;
3816 }
3817
3818 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
3819 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
3820 return -EINVAL;
3821 }
3822
3823 sz = sizeof(struct audproc_soft_step_volume_params);
3824
3825 audproc_softvol.params.hdr.hdr_field =
3826 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3827 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
3828 audproc_softvol.params.hdr.pkt_size = sz;
3829 audproc_softvol.params.hdr.src_svc = APR_SVC_ADM;
3830 audproc_softvol.params.hdr.src_domain = APR_DOMAIN_APPS;
3831 audproc_softvol.params.hdr.src_port = port_id;
3832 audproc_softvol.params.hdr.dest_svc = APR_SVC_ADM;
3833 audproc_softvol.params.hdr.dest_domain = APR_DOMAIN_ADSP;
3834 audproc_softvol.params.hdr.dest_port =
3835 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
3836 audproc_softvol.params.hdr.token = port_idx << 16 | copp_idx;
3837 audproc_softvol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
3838 audproc_softvol.params.payload_addr_lsw = 0;
3839 audproc_softvol.params.payload_addr_msw = 0;
3840 audproc_softvol.params.mem_map_handle = 0;
3841 audproc_softvol.params.payload_size = sizeof(audproc_softvol) -
3842 sizeof(audproc_softvol.params);
3843 audproc_softvol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL;
3844 audproc_softvol.data.param_id =
3845 AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS;
3846 audproc_softvol.data.param_size = audproc_softvol.params.payload_size -
3847 sizeof(audproc_softvol.data);
3848 audproc_softvol.data.reserved = 0;
3849 audproc_softvol.period = softvol_param->period;
3850 audproc_softvol.step = softvol_param->step;
3851 audproc_softvol.ramping_curve = softvol_param->rampingcurve;
3852
3853 pr_debug("%s: period %d, step %d, curve %d\n", __func__,
3854 audproc_softvol.period, audproc_softvol.step,
3855 audproc_softvol.ramping_curve);
3856
3857 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3858 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_softvol);
3859 if (rc < 0) {
3860 pr_err("%s: Set params failed port = %#x\n",
3861 __func__, port_id);
3862 rc = -EINVAL;
3863 goto fail_cmd;
3864 }
3865 /* Wait for the callback */
3866 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3867 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
3868 msecs_to_jiffies(TIMEOUT_MS));
3869 if (!rc) {
3870 pr_err("%s: Soft volume Set params timed out port = %#x\n",
3871 __func__, port_id);
3872 rc = -EINVAL;
3873 goto fail_cmd;
3874 } else if (atomic_read(&this_adm.copp.stat
3875 [port_idx][copp_idx]) > 0) {
3876 pr_err("%s: DSP returned error[%s]\n",
3877 __func__, adsp_err_get_err_str(
3878 atomic_read(&this_adm.copp.stat
3879 [port_idx][copp_idx])));
3880 rc = adsp_err_get_lnx_err_code(
3881 atomic_read(&this_adm.copp.stat
3882 [port_idx][copp_idx]));
3883 goto fail_cmd;
3884 }
3885 rc = 0;
3886fail_cmd:
3887 return rc;
3888}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303889EXPORT_SYMBOL(adm_set_softvolume);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303890
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303891/**
3892 * adm_set_mic_gain -
3893 * command to set MIC gain
3894 *
3895 * @port_id: Port ID number
3896 * @copp_idx: copp index assigned
3897 * @volume: gain value to set
3898 *
3899 * Returns 0 on success or error on failure
3900 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303901int adm_set_mic_gain(int port_id, int copp_idx, int volume)
3902{
3903 struct adm_set_mic_gain_params mic_gain_params;
3904 int rc = 0;
3905 int sz, port_idx;
3906
3907 pr_debug("%s:\n", __func__);
3908 port_id = afe_convert_virtual_to_portid(port_id);
3909 port_idx = adm_validate_and_get_port_index(port_id);
3910 if (port_idx < 0) {
3911 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
3912 return -EINVAL;
3913 }
3914
3915 sz = sizeof(struct adm_set_mic_gain_params);
3916
3917 mic_gain_params.params.hdr.hdr_field =
3918 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3919 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
3920 mic_gain_params.params.hdr.pkt_size = sz;
3921 mic_gain_params.params.hdr.src_svc = APR_SVC_ADM;
3922 mic_gain_params.params.hdr.src_domain = APR_DOMAIN_APPS;
3923 mic_gain_params.params.hdr.src_port = port_id;
3924 mic_gain_params.params.hdr.dest_svc = APR_SVC_ADM;
3925 mic_gain_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
3926 mic_gain_params.params.hdr.dest_port =
3927 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
3928 mic_gain_params.params.hdr.token = port_idx << 16 | copp_idx;
3929 mic_gain_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
3930 mic_gain_params.params.payload_addr_lsw = 0;
3931 mic_gain_params.params.payload_addr_msw = 0;
3932 mic_gain_params.params.mem_map_handle = 0;
3933 mic_gain_params.params.payload_size =
3934 sizeof(struct adm_param_data_v5) +
3935 sizeof(struct admx_mic_gain);
3936 mic_gain_params.data.module_id = ADM_MODULE_IDX_MIC_GAIN_CTRL;
3937 mic_gain_params.data.param_id = ADM_PARAM_IDX_MIC_GAIN;
3938 mic_gain_params.data.param_size =
3939 sizeof(struct admx_mic_gain);
3940 mic_gain_params.data.reserved = 0;
3941 mic_gain_params.mic_gain_data.tx_mic_gain = volume;
3942 mic_gain_params.mic_gain_data.reserved = 0;
3943 pr_debug("%s: Mic Gain set to %d at port_id 0x%x\n",
3944 __func__, volume, port_id);
3945
3946 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3947 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mic_gain_params);
3948 if (rc < 0) {
3949 pr_err("%s: Set params failed port = %#x\n",
3950 __func__, port_id);
3951 rc = -EINVAL;
3952 goto fail_cmd;
3953 }
3954 /* Wait for the callback */
3955 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3956 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
3957 msecs_to_jiffies(TIMEOUT_MS));
3958 if (!rc) {
3959 pr_err("%s: Mic Gain Set params timed out port = %#x\n",
3960 __func__, port_id);
3961 rc = -EINVAL;
3962 goto fail_cmd;
3963 } else if (atomic_read(&this_adm.copp.stat
3964 [port_idx][copp_idx]) > 0) {
3965 pr_err("%s: DSP returned error[%s]\n",
3966 __func__, adsp_err_get_err_str(
3967 atomic_read(&this_adm.copp.stat
3968 [port_idx][copp_idx])));
3969 rc = adsp_err_get_lnx_err_code(
3970 atomic_read(&this_adm.copp.stat
3971 [port_idx][copp_idx]));
3972 goto fail_cmd;
3973 }
3974 rc = 0;
3975fail_cmd:
3976 return rc;
3977}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303978EXPORT_SYMBOL(adm_set_mic_gain);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303979
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303980/**
3981 * adm_send_set_multichannel_ec_primary_mic_ch -
3982 * command to set multi-ch EC primary mic
3983 *
3984 * @port_id: Port ID number
3985 * @copp_idx: copp index assigned
3986 * @primary_mic_ch: channel number of primary mic
3987 *
3988 * Returns 0 on success or error on failure
3989 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303990int adm_send_set_multichannel_ec_primary_mic_ch(int port_id, int copp_idx,
3991 int primary_mic_ch)
3992{
3993 struct adm_set_sec_primary_ch_params sec_primary_ch_params;
3994 int rc = 0;
3995 int sz, port_idx;
3996
3997 pr_debug("%s port_id 0x%x, copp_idx 0x%x, primary_mic_ch %d\n",
3998 __func__, port_id, copp_idx, primary_mic_ch);
3999 port_id = afe_convert_virtual_to_portid(port_id);
4000 port_idx = adm_validate_and_get_port_index(port_id);
4001 if (port_idx < 0) {
4002 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
4003 return -EINVAL;
4004 }
4005
4006 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4007 pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx);
4008 return -EINVAL;
4009 }
4010
4011 sz = sizeof(struct adm_set_sec_primary_ch_params);
4012
4013 sec_primary_ch_params.params.hdr.hdr_field =
4014 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4015 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4016 sec_primary_ch_params.params.hdr.pkt_size = sz;
4017 sec_primary_ch_params.params.hdr.src_svc = APR_SVC_ADM;
4018 sec_primary_ch_params.params.hdr.src_domain = APR_DOMAIN_APPS;
4019 sec_primary_ch_params.params.hdr.src_port = port_id;
4020 sec_primary_ch_params.params.hdr.dest_svc = APR_SVC_ADM;
4021 sec_primary_ch_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4022 sec_primary_ch_params.params.hdr.dest_port =
4023 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4024 sec_primary_ch_params.params.hdr.token = port_idx << 16 | copp_idx;
4025 sec_primary_ch_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4026 sec_primary_ch_params.params.payload_addr_lsw = 0;
4027 sec_primary_ch_params.params.payload_addr_msw = 0;
4028 sec_primary_ch_params.params.mem_map_handle = 0;
4029 sec_primary_ch_params.params.payload_size =
4030 sizeof(struct adm_param_data_v5) +
4031 sizeof(struct admx_sec_primary_mic_ch);
4032 sec_primary_ch_params.data.module_id =
4033 AUDPROC_MODULE_ID_VOICE_TX_SECNS;
4034 sec_primary_ch_params.data.param_id =
4035 AUDPROC_PARAM_IDX_SEC_PRIMARY_MIC_CH;
4036 sec_primary_ch_params.data.param_size =
4037 sizeof(struct admx_sec_primary_mic_ch);
4038 sec_primary_ch_params.data.reserved = 0;
4039 sec_primary_ch_params.sec_primary_mic_ch_data.version = 0;
4040 sec_primary_ch_params.sec_primary_mic_ch_data.reserved = 0;
4041 sec_primary_ch_params.sec_primary_mic_ch_data.sec_primary_mic_ch =
4042 primary_mic_ch;
4043 sec_primary_ch_params.sec_primary_mic_ch_data.reserved1 = 0;
4044
4045 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4046 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&sec_primary_ch_params);
4047 if (rc < 0) {
4048 pr_err("%s: Set params failed port = %#x\n",
4049 __func__, port_id);
4050 rc = -EINVAL;
4051 goto fail_cmd;
4052 }
4053 /* Wait for the callback */
4054 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4055 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4056 msecs_to_jiffies(TIMEOUT_MS));
4057 if (!rc) {
4058 pr_err("%s: Mic Set params timed out port = %#x\n",
4059 __func__, port_id);
4060 rc = -EINVAL;
4061 goto fail_cmd;
4062 } else if (atomic_read(&this_adm.copp.stat
4063 [port_idx][copp_idx]) > 0) {
4064 pr_err("%s: DSP returned error[%s]\n",
4065 __func__, adsp_err_get_err_str(
4066 atomic_read(&this_adm.copp.stat
4067 [port_idx][copp_idx])));
4068 rc = adsp_err_get_lnx_err_code(
4069 atomic_read(&this_adm.copp.stat
4070 [port_idx][copp_idx]));
4071 goto fail_cmd;
4072 }
4073 rc = 0;
4074fail_cmd:
4075 return rc;
4076}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304077EXPORT_SYMBOL(adm_send_set_multichannel_ec_primary_mic_ch);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304078
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304079/**
4080 * adm_param_enable -
4081 * command to send params to ADM for given module
4082 *
4083 * @port_id: Port ID number
4084 * @copp_idx: copp index assigned
4085 * @module_id: ADM module
4086 * @enable: flag to enable or disable module
4087 *
4088 * Returns 0 on success or error on failure
4089 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304090int adm_param_enable(int port_id, int copp_idx, int module_id, int enable)
4091{
4092 struct audproc_enable_param_t adm_mod_enable;
4093 int sz = 0;
4094 int rc = 0;
4095 int port_idx;
4096
4097 pr_debug("%s port_id %d, module_id 0x%x, enable %d\n",
4098 __func__, port_id, module_id, enable);
4099 port_id = afe_convert_virtual_to_portid(port_id);
4100 port_idx = adm_validate_and_get_port_index(port_id);
4101 if (port_idx < 0) {
4102 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4103 rc = -EINVAL;
4104 goto fail_cmd;
4105 }
4106
4107 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4108 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4109 return -EINVAL;
4110 }
4111
4112 sz = sizeof(struct audproc_enable_param_t);
4113
4114 adm_mod_enable.pp_params.hdr.hdr_field =
4115 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4116 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4117 adm_mod_enable.pp_params.hdr.pkt_size = sz;
4118 adm_mod_enable.pp_params.hdr.src_svc = APR_SVC_ADM;
4119 adm_mod_enable.pp_params.hdr.src_domain = APR_DOMAIN_APPS;
4120 adm_mod_enable.pp_params.hdr.src_port = port_id;
4121 adm_mod_enable.pp_params.hdr.dest_svc = APR_SVC_ADM;
4122 adm_mod_enable.pp_params.hdr.dest_domain = APR_DOMAIN_ADSP;
4123 adm_mod_enable.pp_params.hdr.dest_port =
4124 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4125 adm_mod_enable.pp_params.hdr.token = port_idx << 16 | copp_idx;
4126 adm_mod_enable.pp_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4127 adm_mod_enable.pp_params.payload_addr_lsw = 0;
4128 adm_mod_enable.pp_params.payload_addr_msw = 0;
4129 adm_mod_enable.pp_params.mem_map_handle = 0;
4130 adm_mod_enable.pp_params.payload_size = sizeof(adm_mod_enable) -
4131 sizeof(adm_mod_enable.pp_params) +
4132 sizeof(adm_mod_enable.pp_params.params);
4133 adm_mod_enable.pp_params.params.module_id = module_id;
4134 adm_mod_enable.pp_params.params.param_id = AUDPROC_PARAM_ID_ENABLE;
4135 adm_mod_enable.pp_params.params.param_size =
4136 adm_mod_enable.pp_params.payload_size -
4137 sizeof(adm_mod_enable.pp_params.params);
4138 adm_mod_enable.pp_params.params.reserved = 0;
4139 adm_mod_enable.enable = enable;
4140
4141 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4142
4143 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_mod_enable);
4144 if (rc < 0) {
4145 pr_err("%s: Set params failed port = %#x\n",
4146 __func__, port_id);
4147 rc = -EINVAL;
4148 goto fail_cmd;
4149 }
4150 /* Wait for the callback */
4151 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4152 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4153 msecs_to_jiffies(TIMEOUT_MS));
4154 if (!rc) {
4155 pr_err("%s: module %x enable %d timed out on port = %#x\n",
4156 __func__, module_id, enable, port_id);
4157 rc = -EINVAL;
4158 goto fail_cmd;
4159 } else if (atomic_read(&this_adm.copp.stat
4160 [port_idx][copp_idx]) > 0) {
4161 pr_err("%s: DSP returned error[%s]\n",
4162 __func__, adsp_err_get_err_str(
4163 atomic_read(&this_adm.copp.stat
4164 [port_idx][copp_idx])));
4165 rc = adsp_err_get_lnx_err_code(
4166 atomic_read(&this_adm.copp.stat
4167 [port_idx][copp_idx]));
4168 goto fail_cmd;
4169 }
4170 rc = 0;
4171fail_cmd:
4172 return rc;
4173
4174}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304175EXPORT_SYMBOL(adm_param_enable);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304176
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304177/**
4178 * adm_send_calibration -
4179 * send ADM calibration to DSP
4180 *
4181 * @port_id: Port ID number
4182 * @copp_idx: copp index assigned
4183 * @path: direction or ADM path type
4184 * @perf_mode: performance mode like LL/ULL/..
4185 * @cal_type: calibration type to use
4186 * @params: pointer with cal data
4187 * @size: cal size
4188 *
4189 * Returns 0 on success or error on failure
4190 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304191int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode,
4192 int cal_type, char *params, int size)
4193{
4194
4195 struct adm_cmd_set_pp_params_v5 *adm_params = NULL;
4196 int sz, rc = 0;
4197 int port_idx;
4198
4199 pr_debug("%s:port_id %d, path %d, perf_mode %d, cal_type %d, size %d\n",
4200 __func__, port_id, path, perf_mode, cal_type, size);
4201
4202 port_id = afe_convert_virtual_to_portid(port_id);
4203 port_idx = adm_validate_and_get_port_index(port_id);
4204 if (port_idx < 0) {
4205 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4206 rc = -EINVAL;
4207 goto end;
4208 }
4209
4210 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4211 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4212 return -EINVAL;
4213 }
4214
4215 /* Maps audio_dev_ctrl path definition to ACDB definition */
4216 if (get_cal_path(path) != RX_DEVICE) {
4217 pr_err("%s: acdb_path %d\n", __func__, path);
4218 rc = -EINVAL;
4219 goto end;
4220 }
4221
4222 sz = sizeof(struct adm_cmd_set_pp_params_v5) + size;
4223 adm_params = kzalloc(sz, GFP_KERNEL);
4224 if (!adm_params) {
4225 pr_err("%s, adm params memory alloc failed", __func__);
4226 rc = -ENOMEM;
4227 goto end;
4228 }
4229
4230 memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)),
4231 params, size);
4232
4233 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4234 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4235 adm_params->hdr.pkt_size = sz;
4236 adm_params->hdr.src_svc = APR_SVC_ADM;
4237 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
4238 adm_params->hdr.src_port = port_id;
4239 adm_params->hdr.dest_svc = APR_SVC_ADM;
4240 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
4241 adm_params->hdr.dest_port =
4242 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4243 adm_params->hdr.token = port_idx << 16 | copp_idx;
4244 adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4245 /* payload address and mmap handle initialized to zero by kzalloc */
4246 adm_params->payload_size = size;
4247
4248 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4249 rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
4250 if (rc < 0) {
4251 pr_err("%s: Set params failed port = %#x\n",
4252 __func__, port_id);
4253 rc = -EINVAL;
4254 goto end;
4255 }
4256 /* Wait for the callback */
4257 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4258 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4259 msecs_to_jiffies(TIMEOUT_MS));
4260 if (!rc) {
4261 pr_err("%s: Set params timed out port = %#x\n",
4262 __func__, port_id);
4263 rc = -EINVAL;
4264 goto end;
4265 } else if (atomic_read(&this_adm.copp.stat
4266 [port_idx][copp_idx]) > 0) {
4267 pr_err("%s: DSP returned error[%s]\n",
4268 __func__, adsp_err_get_err_str(
4269 atomic_read(&this_adm.copp.stat
4270 [port_idx][copp_idx])));
4271 rc = adsp_err_get_lnx_err_code(
4272 atomic_read(&this_adm.copp.stat
4273 [port_idx][copp_idx]));
4274 goto end;
4275 }
4276 rc = 0;
4277
4278end:
4279 kfree(adm_params);
4280 return rc;
4281}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304282EXPORT_SYMBOL(adm_send_calibration);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304283
4284/*
4285 * adm_update_wait_parameters must be called with routing driver locks.
4286 * adm_reset_wait_parameters must be called with routing driver locks.
4287 * set and reset parmeters are separated to make sure it is always called
4288 * under routing driver lock.
4289 * adm_wait_timeout is to block until timeout or interrupted. Timeout is
4290 * not a an error.
4291 */
4292int adm_set_wait_parameters(int port_id, int copp_idx)
4293{
4294
4295 int ret = 0, port_idx;
4296
4297 pr_debug("%s: port_id 0x%x, copp_idx %d\n", __func__, port_id,
4298 copp_idx);
4299 port_id = afe_convert_virtual_to_portid(port_id);
4300 port_idx = adm_validate_and_get_port_index(port_id);
4301 if (port_idx < 0) {
4302 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4303 ret = -EINVAL;
4304 goto end;
4305 }
4306
4307 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4308 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4309 return -EINVAL;
4310 }
4311
4312 this_adm.copp.adm_delay[port_idx][copp_idx] = 1;
4313 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 0);
4314
4315end:
4316 return ret;
4317
4318}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304319EXPORT_SYMBOL(adm_set_wait_parameters);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304320
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304321/**
4322 * adm_reset_wait_parameters -
4323 * reset wait parameters or ADM delay value
4324 *
4325 * @port_id: Port ID number
4326 * @copp_idx: copp index assigned
4327 *
4328 * Returns 0 on success or error on failure
4329 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304330int adm_reset_wait_parameters(int port_id, int copp_idx)
4331{
4332 int ret = 0, port_idx;
4333
4334 pr_debug("%s: port_id 0x%x copp_idx %d\n", __func__, port_id,
4335 copp_idx);
4336 port_id = afe_convert_virtual_to_portid(port_id);
4337 port_idx = adm_validate_and_get_port_index(port_id);
4338 if (port_idx < 0) {
4339 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4340 ret = -EINVAL;
4341 goto end;
4342 }
4343
4344 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4345 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4346 return -EINVAL;
4347 }
4348
4349 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 1);
4350 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
4351
4352end:
4353 return ret;
4354}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304355EXPORT_SYMBOL(adm_reset_wait_parameters);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304356
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304357/**
4358 * adm_wait_timeout -
4359 * ADM wait command after command send to DSP
4360 *
4361 * @port_id: Port ID number
4362 * @copp_idx: copp index assigned
4363 * @wait_time: value in ms for command timeout
4364 *
4365 * Returns 0 on success or error on failure
4366 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304367int adm_wait_timeout(int port_id, int copp_idx, int wait_time)
4368{
4369 int ret = 0, port_idx;
4370
4371 pr_debug("%s: port_id 0x%x, copp_idx %d, wait_time %d\n", __func__,
4372 port_id, copp_idx, wait_time);
4373 port_id = afe_convert_virtual_to_portid(port_id);
4374 port_idx = adm_validate_and_get_port_index(port_id);
4375 if (port_idx < 0) {
4376 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4377 ret = -EINVAL;
4378 goto end;
4379 }
4380
4381 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4382 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4383 return -EINVAL;
4384 }
4385
4386 ret = wait_event_timeout(
4387 this_adm.copp.adm_delay_wait[port_idx][copp_idx],
4388 atomic_read(&this_adm.copp.adm_delay_stat[port_idx][copp_idx]),
4389 msecs_to_jiffies(wait_time));
4390 pr_debug("%s: return %d\n", __func__, ret);
4391 if (ret != 0)
4392 ret = -EINTR;
4393end:
4394 pr_debug("%s: return %d--\n", __func__, ret);
4395 return ret;
4396}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304397EXPORT_SYMBOL(adm_wait_timeout);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304398
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304399/**
4400 * adm_store_cal_data -
4401 * Retrieve calibration data for ADM copp device
4402 *
4403 * @port_id: Port ID number
4404 * @copp_idx: copp index assigned
4405 * @path: direction or copp type
4406 * @perf_mode: performance mode like LL/ULL/..
4407 * @cal_index: calibration index to use
4408 * @params: pointer to store cal data
4409 * @size: pointer to fill with cal size
4410 *
4411 * Returns 0 on success or error on failure
4412 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304413int adm_store_cal_data(int port_id, int copp_idx, int path, int perf_mode,
4414 int cal_index, char *params, int *size)
4415{
4416 int rc = 0;
4417 struct cal_block_data *cal_block = NULL;
4418 int app_type, acdb_id, port_idx, sample_rate;
4419
4420 if (this_adm.cal_data[cal_index] == NULL) {
4421 pr_debug("%s: cal_index %d not allocated!\n",
4422 __func__, cal_index);
4423 goto end;
4424 }
4425
4426 if (get_cal_path(path) != RX_DEVICE) {
4427 pr_debug("%s: Invalid path to store calibration %d\n",
4428 __func__, path);
4429 rc = -EINVAL;
4430 goto end;
4431 }
4432
4433 port_id = afe_convert_virtual_to_portid(port_id);
4434 port_idx = adm_validate_and_get_port_index(port_id);
4435 if (port_idx < 0) {
4436 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
4437 rc = -EINVAL;
4438 goto end;
4439 }
4440
4441 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4442 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4443 return -EINVAL;
4444 }
4445
4446 acdb_id = atomic_read(&this_adm.copp.acdb_id[port_idx][copp_idx]);
4447 app_type = atomic_read(&this_adm.copp.app_type[port_idx][copp_idx]);
4448 sample_rate = atomic_read(&this_adm.copp.rate[port_idx][copp_idx]);
4449
4450 mutex_lock(&this_adm.cal_data[cal_index]->lock);
4451 cal_block = adm_find_cal(cal_index, get_cal_path(path), app_type,
4452 acdb_id, sample_rate);
4453 if (cal_block == NULL)
4454 goto unlock;
4455
4456 if (cal_block->cal_data.size <= 0) {
4457 pr_debug("%s: No ADM cal send for port_id = 0x%x!\n",
4458 __func__, port_id);
4459 rc = -EINVAL;
4460 goto unlock;
4461 }
4462
4463 if (cal_index == ADM_AUDPROC_CAL) {
4464 if (cal_block->cal_data.size > AUD_PROC_BLOCK_SIZE) {
4465 pr_err("%s:audproc:invalid size exp/actual[%zd, %d]\n",
4466 __func__, cal_block->cal_data.size, *size);
4467 rc = -ENOMEM;
4468 goto unlock;
4469 }
4470 } else if (cal_index == ADM_AUDVOL_CAL) {
4471 if (cal_block->cal_data.size > AUD_VOL_BLOCK_SIZE) {
4472 pr_err("%s:aud_vol:invalid size exp/actual[%zd, %d]\n",
4473 __func__, cal_block->cal_data.size, *size);
4474 rc = -ENOMEM;
4475 goto unlock;
4476 }
4477 } else {
4478 pr_debug("%s: Not valid calibration for dolby topolgy\n",
4479 __func__);
4480 rc = -EINVAL;
4481 goto unlock;
4482 }
4483 memcpy(params, cal_block->cal_data.kvaddr, cal_block->cal_data.size);
4484 *size = cal_block->cal_data.size;
4485
4486 pr_debug("%s:port_id %d, copp_idx %d, path %d",
4487 __func__, port_id, copp_idx, path);
4488 pr_debug("perf_mode %d, cal_type %d, size %d\n",
4489 perf_mode, cal_index, *size);
4490
4491unlock:
4492 mutex_unlock(&this_adm.cal_data[cal_index]->lock);
4493end:
4494 return rc;
4495}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304496EXPORT_SYMBOL(adm_store_cal_data);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304497
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304498/**
4499 * adm_send_compressed_device_mute -
4500 * command to send mute for compressed device
4501 *
4502 * @port_id: Port ID number
4503 * @copp_idx: copp index assigned
4504 * @mute_on: flag to indicate mute or unmute
4505 *
4506 * Returns 0 on success or error on failure
4507 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304508int adm_send_compressed_device_mute(int port_id, int copp_idx, bool mute_on)
4509{
4510 struct adm_set_compressed_device_mute mute_params;
4511 int ret = 0;
4512 int port_idx;
4513
4514 pr_debug("%s port_id: 0x%x, copp_idx %d, mute_on: %d\n",
4515 __func__, port_id, copp_idx, mute_on);
4516 port_id = afe_convert_virtual_to_portid(port_id);
4517 port_idx = adm_validate_and_get_port_index(port_id);
4518 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
4519 pr_err("%s: Invalid port_id %#x copp_idx %d\n",
4520 __func__, port_id, copp_idx);
4521 ret = -EINVAL;
4522 goto end;
4523 }
4524
4525 mute_params.command.hdr.hdr_field =
4526 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4527 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4528 mute_params.command.hdr.pkt_size =
4529 sizeof(struct adm_set_compressed_device_mute);
4530 mute_params.command.hdr.src_svc = APR_SVC_ADM;
4531 mute_params.command.hdr.src_domain = APR_DOMAIN_APPS;
4532 mute_params.command.hdr.src_port = port_id;
4533 mute_params.command.hdr.dest_svc = APR_SVC_ADM;
4534 mute_params.command.hdr.dest_domain = APR_DOMAIN_ADSP;
4535 mute_params.command.hdr.dest_port =
4536 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4537 mute_params.command.hdr.token = port_idx << 16 | copp_idx;
4538 mute_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4539 mute_params.command.payload_addr_lsw = 0;
4540 mute_params.command.payload_addr_msw = 0;
4541 mute_params.command.mem_map_handle = 0;
4542 mute_params.command.payload_size = sizeof(mute_params) -
4543 sizeof(mute_params.command);
4544 mute_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_MUTE;
4545 mute_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_MUTE;
4546 mute_params.params.param_size = mute_params.command.payload_size -
4547 sizeof(mute_params.params);
4548 mute_params.params.reserved = 0;
4549 mute_params.mute_on = mute_on;
4550
4551 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4552 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mute_params);
4553 if (ret < 0) {
4554 pr_err("%s: device mute for port %d copp %d failed, ret %d\n",
4555 __func__, port_id, copp_idx, ret);
4556 ret = -EINVAL;
4557 goto end;
4558 }
4559
4560 /* Wait for the callback */
4561 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4562 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4563 msecs_to_jiffies(TIMEOUT_MS));
4564 if (!ret) {
4565 pr_err("%s: send device mute for port %d copp %d failed\n",
4566 __func__, port_id, copp_idx);
4567 ret = -EINVAL;
4568 goto end;
4569 } else if (atomic_read(&this_adm.copp.stat
4570 [port_idx][copp_idx]) > 0) {
4571 pr_err("%s: DSP returned error[%s]\n",
4572 __func__, adsp_err_get_err_str(
4573 atomic_read(&this_adm.copp.stat
4574 [port_idx][copp_idx])));
4575 ret = adsp_err_get_lnx_err_code(
4576 atomic_read(&this_adm.copp.stat
4577 [port_idx][copp_idx]));
4578 goto end;
4579 }
4580 ret = 0;
4581end:
4582 return ret;
4583}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304584EXPORT_SYMBOL(adm_send_compressed_device_mute);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304585
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304586/**
4587 * adm_send_compressed_device_latency -
4588 * command to send latency for compressed device
4589 *
4590 * @port_id: Port ID number
4591 * @copp_idx: copp index assigned
4592 * @latency: latency value to pass
4593 *
4594 * Returns 0 on success or error on failure
4595 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304596int adm_send_compressed_device_latency(int port_id, int copp_idx, int latency)
4597{
4598 struct adm_set_compressed_device_latency latency_params;
4599 int port_idx;
4600 int ret = 0;
4601
4602 pr_debug("%s port_id: 0x%x, copp_idx %d latency: %d\n", __func__,
4603 port_id, copp_idx, latency);
4604 port_id = afe_convert_virtual_to_portid(port_id);
4605 port_idx = adm_validate_and_get_port_index(port_id);
4606 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
4607 pr_err("%s: Invalid port_id %#x copp_idx %d\n",
4608 __func__, port_id, copp_idx);
4609 ret = -EINVAL;
4610 goto end;
4611 }
4612
4613 latency_params.command.hdr.hdr_field =
4614 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4615 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4616 latency_params.command.hdr.pkt_size =
4617 sizeof(struct adm_set_compressed_device_latency);
4618 latency_params.command.hdr.src_svc = APR_SVC_ADM;
4619 latency_params.command.hdr.src_domain = APR_DOMAIN_APPS;
4620 latency_params.command.hdr.src_port = port_id;
4621 latency_params.command.hdr.dest_svc = APR_SVC_ADM;
4622 latency_params.command.hdr.dest_domain = APR_DOMAIN_ADSP;
4623 latency_params.command.hdr.dest_port =
4624 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4625 latency_params.command.hdr.token = port_idx << 16 | copp_idx;
4626 latency_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4627 latency_params.command.payload_addr_lsw = 0;
4628 latency_params.command.payload_addr_msw = 0;
4629 latency_params.command.mem_map_handle = 0;
4630 latency_params.command.payload_size = sizeof(latency_params) -
4631 sizeof(latency_params.command);
4632 latency_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_LATENCY;
4633 latency_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_LATENCY;
4634 latency_params.params.param_size = latency_params.command.payload_size -
4635 sizeof(latency_params.params);
4636 latency_params.params.reserved = 0;
4637 latency_params.latency = latency;
4638
4639 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4640 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&latency_params);
4641 if (ret < 0) {
4642 pr_err("%s: send device latency err %d for port %d copp %d\n",
4643 __func__, port_id, copp_idx, ret);
4644 ret = -EINVAL;
4645 goto end;
4646 }
4647
4648 /* Wait for the callback */
4649 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4650 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4651 msecs_to_jiffies(TIMEOUT_MS));
4652 if (!ret) {
4653 pr_err("%s: send device latency for port %d failed\n", __func__,
4654 port_id);
4655 ret = -EINVAL;
4656 goto end;
4657 } else if (atomic_read(&this_adm.copp.stat
4658 [port_idx][copp_idx]) > 0) {
4659 pr_err("%s: DSP returned error[%s]\n",
4660 __func__, adsp_err_get_err_str(
4661 atomic_read(&this_adm.copp.stat
4662 [port_idx][copp_idx])));
4663 ret = adsp_err_get_lnx_err_code(
4664 atomic_read(&this_adm.copp.stat
4665 [port_idx][copp_idx]));
4666 goto end;
4667 }
4668 ret = 0;
4669end:
4670 return ret;
4671}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304672EXPORT_SYMBOL(adm_send_compressed_device_latency);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304673
4674/**
4675 * adm_swap_speaker_channels
4676 *
4677 * Receives port_id, copp_idx, sample rate, spk_swap and
4678 * send MFC command to swap speaker channel.
4679 * Return zero on success. On failure returns nonzero.
4680 *
4681 * port_id - Passed value, port_id for which channels swap is wanted
4682 * copp_idx - Passed value, copp_idx for which channels swap is wanted
4683 * sample_rate - Passed value, sample rate used by app type config
4684 * spk_swap - Passed value, spk_swap for check if swap flag is set
4685 */
4686int adm_swap_speaker_channels(int port_id, int copp_idx,
4687 int sample_rate, bool spk_swap)
4688{
4689 struct audproc_mfc_output_media_fmt mfc_cfg;
4690 uint16_t num_channels;
4691 int port_idx;
4692 int ret = 0;
4693
4694 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
4695 __func__, port_id, copp_idx);
4696 port_id = q6audio_convert_virtual_to_portid(port_id);
4697 port_idx = adm_validate_and_get_port_index(port_id);
4698 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
4699 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4700 ret = -EINVAL;
4701 goto done;
4702 }
4703
4704 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4705 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4706 ret = -EINVAL;
4707 goto done;
4708 }
4709
4710 num_channels = atomic_read(
4711 &this_adm.copp.channels[port_idx][copp_idx]);
4712 if (num_channels != 2) {
4713 pr_debug("%s: Invalid number of channels: %d\n",
4714 __func__, num_channels);
4715 ret = -EINVAL;
4716 goto done;
4717 }
4718
4719 memset(&mfc_cfg, 0, sizeof(mfc_cfg));
4720 mfc_cfg.params.hdr.hdr_field =
4721 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4722 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4723 mfc_cfg.params.hdr.pkt_size =
4724 sizeof(mfc_cfg);
4725 mfc_cfg.params.hdr.src_svc = APR_SVC_ADM;
4726 mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS;
4727 mfc_cfg.params.hdr.src_port = port_id;
4728 mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM;
4729 mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4730 mfc_cfg.params.hdr.dest_port =
4731 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4732 mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx;
4733 mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4734 mfc_cfg.params.payload_addr_lsw = 0;
4735 mfc_cfg.params.payload_addr_msw = 0;
4736 mfc_cfg.params.mem_map_handle = 0;
4737 mfc_cfg.params.payload_size = sizeof(mfc_cfg) -
4738 sizeof(mfc_cfg.params);
4739 mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC;
4740 mfc_cfg.data.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
4741 mfc_cfg.data.param_size = mfc_cfg.params.payload_size -
4742 sizeof(mfc_cfg.data);
4743 mfc_cfg.data.reserved = 0;
4744 mfc_cfg.sampling_rate = sample_rate;
4745 mfc_cfg.bits_per_sample =
4746 atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]);
4747 mfc_cfg.num_channels = num_channels;
4748
4749 /* Currently applying speaker swap for only 2 channel use case */
4750 if (spk_swap) {
4751 mfc_cfg.channel_type[0] =
4752 (uint16_t) PCM_CHANNEL_FR;
4753 mfc_cfg.channel_type[1] =
4754 (uint16_t) PCM_CHANNEL_FL;
4755 } else {
4756 mfc_cfg.channel_type[0] =
4757 (uint16_t) PCM_CHANNEL_FL;
4758 mfc_cfg.channel_type[1] =
4759 (uint16_t) PCM_CHANNEL_FR;
4760 }
4761
4762 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4763 pr_debug("%s: mfc config: port_idx %d copp_idx %d copp SR %d copp BW %d copp chan %d\n",
4764 __func__, port_idx, copp_idx, mfc_cfg.sampling_rate,
4765 mfc_cfg.bits_per_sample, mfc_cfg.num_channels);
4766
4767 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg);
4768 if (ret < 0) {
4769 pr_err("%s: port_id: for[0x%x] failed %d\n",
4770 __func__, port_id, ret);
4771 goto done;
4772 }
4773 /* Wait for the callback with copp id */
4774 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4775 atomic_read(&this_adm.copp.stat
4776 [port_idx][copp_idx]) >= 0,
4777 msecs_to_jiffies(TIMEOUT_MS));
4778 if (!ret) {
4779 pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n",
4780 __func__, port_id);
4781 ret = -ETIMEDOUT;
4782 goto done;
4783 }
4784
4785 if (atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) > 0) {
4786 pr_err("%s: DSP returned error[%s]\n",
4787 __func__, adsp_err_get_err_str(
4788 atomic_read(&this_adm.copp.stat
4789 [port_idx][copp_idx])));
4790 ret = adsp_err_get_lnx_err_code(
4791 atomic_read(&this_adm.copp.stat
4792 [port_idx][copp_idx]));
4793 goto done;
4794 }
4795
4796 pr_debug("%s: mfc_cfg Set params returned success", __func__);
4797 ret = 0;
4798
4799done:
4800 return ret;
4801}
4802EXPORT_SYMBOL(adm_swap_speaker_channels);
4803
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304804/**
4805 * adm_set_sound_focus -
4806 * Update sound focus info
4807 *
4808 * @port_id: Port ID number
4809 * @copp_idx: copp index assigned
4810 * @soundFocusData: sound focus data to pass
4811 *
4812 * Returns 0 on success or error on failure
4813 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304814int adm_set_sound_focus(int port_id, int copp_idx,
4815 struct sound_focus_param soundFocusData)
4816{
4817 struct adm_set_fluence_soundfocus_param soundfocus_params;
4818 int sz = 0;
4819 int ret = 0;
4820 int port_idx;
4821 int i;
4822
4823 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
4824 __func__, port_id, copp_idx);
4825
4826 port_id = afe_convert_virtual_to_portid(port_id);
4827 port_idx = adm_validate_and_get_port_index(port_id);
4828 if (port_idx < 0) {
4829 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4830
4831 ret = -EINVAL;
4832 goto done;
4833 }
4834
4835 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4836 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4837
4838 ret = -EINVAL;
4839 goto done;
4840 }
4841
4842 sz = sizeof(struct adm_set_fluence_soundfocus_param);
4843 soundfocus_params.params.hdr.hdr_field =
4844 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
4845 APR_PKT_VER);
4846 soundfocus_params.params.hdr.pkt_size = sz;
4847 soundfocus_params.params.hdr.src_svc = APR_SVC_ADM;
4848 soundfocus_params.params.hdr.src_domain = APR_DOMAIN_APPS;
4849 soundfocus_params.params.hdr.src_port = port_id;
4850 soundfocus_params.params.hdr.dest_svc = APR_SVC_ADM;
4851 soundfocus_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4852 soundfocus_params.params.hdr.dest_port =
4853 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4854 soundfocus_params.params.hdr.token = port_idx << 16 |
4855 ADM_CLIENT_ID_SOURCE_TRACKING << 8 | copp_idx;
4856 soundfocus_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4857 soundfocus_params.params.payload_addr_lsw = 0;
4858 soundfocus_params.params.payload_addr_msw = 0;
4859 soundfocus_params.params.mem_map_handle = 0;
4860 soundfocus_params.params.payload_size = sizeof(soundfocus_params) -
4861 sizeof(soundfocus_params.params);
4862 soundfocus_params.data.module_id = VOICEPROC_MODULE_ID_GENERIC_TX;
4863 soundfocus_params.data.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS;
4864 soundfocus_params.data.param_size =
4865 soundfocus_params.params.payload_size -
4866 sizeof(soundfocus_params.data);
4867 soundfocus_params.data.reserved = 0;
4868
4869 memset(&(soundfocus_params.soundfocus_data), 0xFF,
4870 sizeof(struct adm_param_fluence_soundfocus_t));
4871 for (i = 0; i < MAX_SECTORS; i++) {
4872 soundfocus_params.soundfocus_data.start_angles[i] =
4873 soundFocusData.start_angle[i];
4874 soundfocus_params.soundfocus_data.enables[i] =
4875 soundFocusData.enable[i];
4876 pr_debug("%s: start_angle[%d] = %d\n",
4877 __func__, i, soundFocusData.start_angle[i]);
4878 pr_debug("%s: enable[%d] = %d\n",
4879 __func__, i, soundFocusData.enable[i]);
4880 }
4881 soundfocus_params.soundfocus_data.gain_step =
4882 soundFocusData.gain_step;
4883 pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step);
4884
4885 soundfocus_params.soundfocus_data.reserved = 0;
4886
4887 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4888 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&soundfocus_params);
4889 if (ret < 0) {
4890 pr_err("%s: Set params failed\n", __func__);
4891
4892 ret = -EINVAL;
4893 goto done;
4894 }
4895 /* Wait for the callback */
4896 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4897 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4898 msecs_to_jiffies(TIMEOUT_MS));
4899 if (!ret) {
4900 pr_err("%s: Set params timed out\n", __func__);
4901
4902 ret = -EINVAL;
4903 goto done;
4904 }
4905
4906 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
4907 pr_err("%s - set params returned error [%s]\n",
4908 __func__, adsp_err_get_err_str(
4909 this_adm.sourceTrackingData.apr_cmd_status));
4910
4911 ret = adsp_err_get_lnx_err_code(
4912 this_adm.sourceTrackingData.apr_cmd_status);
4913 goto done;
4914 }
4915
4916 ret = 0;
4917
4918done:
4919 pr_debug("%s: Exit, ret=%d\n", __func__, ret);
4920
4921 return ret;
4922}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304923EXPORT_SYMBOL(adm_set_sound_focus);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304924
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304925/**
4926 * adm_get_sound_focus -
4927 * Retrieve sound focus info
4928 *
4929 * @port_id: Port ID number
4930 * @copp_idx: copp index assigned
4931 * @soundFocusData: pointer for sound focus data to be updated with
4932 *
4933 * Returns 0 on success or error on failure
4934 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304935int adm_get_sound_focus(int port_id, int copp_idx,
4936 struct sound_focus_param *soundFocusData)
4937{
4938 int ret = 0, i;
4939 char *params_value;
4940 uint32_t param_payload_len = sizeof(struct adm_param_data_v5) +
4941 sizeof(struct adm_param_fluence_soundfocus_t);
4942 struct adm_param_fluence_soundfocus_t *soundfocus_params;
4943
4944 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
4945 __func__, port_id, copp_idx);
4946
4947 params_value = kzalloc(param_payload_len, GFP_KERNEL);
4948 if (!params_value) {
4949 ret = -ENOMEM;
4950 goto done;
4951 }
4952 ret = adm_get_params_v2(port_id, copp_idx,
4953 VOICEPROC_MODULE_ID_GENERIC_TX,
4954 VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS,
4955 param_payload_len,
4956 params_value,
4957 ADM_CLIENT_ID_SOURCE_TRACKING);
4958 if (ret) {
4959 pr_err("%s: get parameters failed ret:%d\n", __func__, ret);
4960
4961 kfree(params_value);
4962 ret = -EINVAL;
4963 goto done;
4964 }
4965
4966 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
4967 pr_err("%s - get params returned error [%s]\n",
4968 __func__, adsp_err_get_err_str(
4969 this_adm.sourceTrackingData.apr_cmd_status));
4970
4971 kfree(params_value);
4972 ret = adsp_err_get_lnx_err_code(
4973 this_adm.sourceTrackingData.apr_cmd_status);
4974 goto done;
4975 }
4976
4977 soundfocus_params = (struct adm_param_fluence_soundfocus_t *)
4978 params_value;
4979 for (i = 0; i < MAX_SECTORS; i++) {
4980 soundFocusData->start_angle[i] =
4981 soundfocus_params->start_angles[i];
4982 soundFocusData->enable[i] = soundfocus_params->enables[i];
4983 pr_debug("%s: start_angle[%d] = %d\n",
4984 __func__, i, soundFocusData->start_angle[i]);
4985 pr_debug("%s: enable[%d] = %d\n",
4986 __func__, i, soundFocusData->enable[i]);
4987 }
4988 soundFocusData->gain_step = soundfocus_params->gain_step;
4989 pr_debug("%s: gain_step = %d\n", __func__, soundFocusData->gain_step);
4990
4991 kfree(params_value);
4992
4993done:
4994 pr_debug("%s: Exit, ret = %d\n", __func__, ret);
4995
4996 return ret;
4997}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304998EXPORT_SYMBOL(adm_get_sound_focus);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304999
5000static int adm_source_tracking_alloc_map_memory(void)
5001{
5002 int ret;
5003
5004 pr_debug("%s: Enter\n", __func__);
5005
5006 ret = msm_audio_ion_alloc("SOURCE_TRACKING",
5007 &this_adm.sourceTrackingData.ion_client,
5008 &this_adm.sourceTrackingData.ion_handle,
5009 AUD_PROC_BLOCK_SIZE,
5010 &this_adm.sourceTrackingData.memmap.paddr,
5011 &this_adm.sourceTrackingData.memmap.size,
5012 &this_adm.sourceTrackingData.memmap.kvaddr);
5013 if (ret) {
5014 pr_err("%s: failed to allocate memory\n", __func__);
5015
5016 ret = -EINVAL;
5017 goto done;
5018 }
5019
5020 atomic_set(&this_adm.mem_map_index, ADM_MEM_MAP_INDEX_SOURCE_TRACKING);
5021 ret = adm_memory_map_regions(&this_adm.sourceTrackingData.memmap.paddr,
5022 0,
5023 (uint32_t *)&this_adm.sourceTrackingData.memmap.size,
5024 1);
5025 if (ret < 0) {
5026 pr_err("%s: failed to map memory, paddr = 0x%pK, size = %d\n",
5027 __func__,
5028 (void *)this_adm.sourceTrackingData.memmap.paddr,
5029 (uint32_t)this_adm.sourceTrackingData.memmap.size);
5030
5031 msm_audio_ion_free(this_adm.sourceTrackingData.ion_client,
5032 this_adm.sourceTrackingData.ion_handle);
5033 this_adm.sourceTrackingData.ion_client = NULL;
5034 this_adm.sourceTrackingData.ion_handle = NULL;
5035 this_adm.sourceTrackingData.memmap.size = 0;
5036 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
5037 this_adm.sourceTrackingData.memmap.paddr = 0;
5038 this_adm.sourceTrackingData.apr_cmd_status = -1;
5039 atomic_set(&this_adm.mem_map_handles
5040 [ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
5041
5042 ret = -EINVAL;
5043 goto done;
5044 }
5045 ret = 0;
5046 pr_debug("%s: paddr = 0x%pK, size = %d, mem_map_handle = 0x%x\n",
5047 __func__, (void *)this_adm.sourceTrackingData.memmap.paddr,
5048 (uint32_t)this_adm.sourceTrackingData.memmap.size,
5049 atomic_read(&this_adm.mem_map_handles
5050 [ADM_MEM_MAP_INDEX_SOURCE_TRACKING]));
5051
5052done:
5053 pr_debug("%s: Exit, ret = %d\n", __func__, ret);
5054
5055 return ret;
5056}
5057
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305058/**
5059 * adm_get_source_tracking -
5060 * Retrieve source tracking info
5061 *
5062 * @port_id: Port ID number
5063 * @copp_idx: copp index assigned
5064 * @sourceTrackingData: pointer for source track data to be updated with
5065 *
5066 * Returns 0 on success or error on failure
5067 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305068int adm_get_source_tracking(int port_id, int copp_idx,
5069 struct source_tracking_param *sourceTrackingData)
5070{
5071 struct adm_cmd_get_pp_params_v5 admp;
5072 int p_idx, ret = 0, i;
5073 struct adm_param_fluence_sourcetracking_t *source_tracking_params;
5074
5075 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
5076 __func__, port_id, copp_idx);
5077
5078 if (!this_adm.sourceTrackingData.memmap.paddr) {
5079 /* Allocate and map shared memory for out of band usage */
5080 ret = adm_source_tracking_alloc_map_memory();
5081 if (ret != 0) {
5082 ret = -EINVAL;
5083 goto done;
5084 }
5085 }
5086
5087 port_id = afe_convert_virtual_to_portid(port_id);
5088 p_idx = adm_validate_and_get_port_index(port_id);
5089 if (p_idx < 0) {
5090 pr_err("%s - invalid port index %i, port id %i, copp idx %i\n",
5091 __func__, p_idx, port_id, copp_idx);
5092
5093 ret = -EINVAL;
5094 goto done;
5095 }
5096
5097 admp.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
5098 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
5099 admp.hdr.pkt_size = sizeof(admp);
5100 admp.hdr.src_svc = APR_SVC_ADM;
5101 admp.hdr.src_domain = APR_DOMAIN_APPS;
5102 admp.hdr.src_port = port_id;
5103 admp.hdr.dest_svc = APR_SVC_ADM;
5104 admp.hdr.dest_domain = APR_DOMAIN_ADSP;
5105 admp.hdr.dest_port = atomic_read(&this_adm.copp.id[p_idx][copp_idx]);
5106 admp.hdr.token = p_idx << 16 | ADM_CLIENT_ID_SOURCE_TRACKING << 8 |
5107 copp_idx;
5108 admp.hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5;
5109 admp.data_payload_addr_lsw =
5110 lower_32_bits(this_adm.sourceTrackingData.memmap.paddr);
5111 admp.data_payload_addr_msw =
5112 msm_audio_populate_upper_32_bits(
5113 this_adm.sourceTrackingData.memmap.paddr);
5114 admp.mem_map_handle = atomic_read(&this_adm.mem_map_handles[
5115 ADM_MEM_MAP_INDEX_SOURCE_TRACKING]);
5116 admp.module_id = VOICEPROC_MODULE_ID_GENERIC_TX;
5117 admp.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOURCETRACKING;
5118 admp.param_max_size = sizeof(struct adm_param_fluence_sourcetracking_t)
5119 + sizeof(struct adm_param_data_v5);
5120 admp.reserved = 0;
5121
5122 atomic_set(&this_adm.copp.stat[p_idx][copp_idx], -1);
5123
5124 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&admp);
5125 if (ret < 0) {
5126 pr_err("%s - failed to get Source Tracking Params\n",
5127 __func__);
5128
5129 ret = -EINVAL;
5130 goto done;
5131 }
5132 ret = wait_event_timeout(this_adm.copp.wait[p_idx][copp_idx],
5133 atomic_read(&this_adm.copp.stat[p_idx][copp_idx]) >= 0,
5134 msecs_to_jiffies(TIMEOUT_MS));
5135 if (!ret) {
5136 pr_err("%s - get params timed out\n", __func__);
5137
5138 ret = -EINVAL;
5139 goto done;
5140 } else if (atomic_read(&this_adm.copp.stat
5141 [p_idx][copp_idx]) > 0) {
5142 pr_err("%s: DSP returned error[%s]\n",
5143 __func__, adsp_err_get_err_str(
5144 atomic_read(&this_adm.copp.stat
5145 [p_idx][copp_idx])));
5146 ret = adsp_err_get_lnx_err_code(
5147 atomic_read(&this_adm.copp.stat
5148 [p_idx][copp_idx]));
5149 goto done;
5150 }
5151
5152 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
5153 pr_err("%s - get params returned error [%s]\n",
5154 __func__, adsp_err_get_err_str(
5155 this_adm.sourceTrackingData.apr_cmd_status));
5156
5157 ret = adsp_err_get_lnx_err_code(
5158 this_adm.sourceTrackingData.apr_cmd_status);
5159 goto done;
5160 }
5161
5162 source_tracking_params = (struct adm_param_fluence_sourcetracking_t *)
5163 (this_adm.sourceTrackingData.memmap.kvaddr +
5164 sizeof(struct adm_param_data_v5));
5165 for (i = 0; i < MAX_SECTORS; i++) {
5166 sourceTrackingData->vad[i] = source_tracking_params->vad[i];
5167 pr_debug("%s: vad[%d] = %d\n",
5168 __func__, i, sourceTrackingData->vad[i]);
5169 }
5170 sourceTrackingData->doa_speech = source_tracking_params->doa_speech;
5171 pr_debug("%s: doa_speech = %d\n",
5172 __func__, sourceTrackingData->doa_speech);
5173
5174 for (i = 0; i < MAX_NOISE_SOURCE_INDICATORS; i++) {
5175 sourceTrackingData->doa_noise[i] =
5176 source_tracking_params->doa_noise[i];
5177 pr_debug("%s: doa_noise[%d] = %d\n",
5178 __func__, i, sourceTrackingData->doa_noise[i]);
5179 }
5180 for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) {
5181 sourceTrackingData->polar_activity[i] =
5182 source_tracking_params->polar_activity[i];
5183 pr_debug("%s: polar_activity[%d] = %d\n",
5184 __func__, i, sourceTrackingData->polar_activity[i]);
5185 }
5186
5187 ret = 0;
5188
5189done:
5190 pr_debug("%s: Exit, ret=%d\n", __func__, ret);
5191
5192 return ret;
5193}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305194EXPORT_SYMBOL(adm_get_source_tracking);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305195
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305196int __init adm_init(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305197{
5198 int i = 0, j;
5199
5200 this_adm.apr = NULL;
5201 this_adm.ec_ref_rx = -1;
5202 this_adm.num_ec_ref_rx_chans = 0;
5203 this_adm.ec_ref_rx_bit_width = 0;
5204 this_adm.ec_ref_rx_sampling_rate = 0;
5205 atomic_set(&this_adm.matrix_map_stat, 0);
5206 init_waitqueue_head(&this_adm.matrix_map_wait);
5207 atomic_set(&this_adm.adm_stat, 0);
5208 init_waitqueue_head(&this_adm.adm_wait);
5209
5210 for (i = 0; i < AFE_MAX_PORTS; i++) {
5211 for (j = 0; j < MAX_COPPS_PER_PORT; j++) {
5212 atomic_set(&this_adm.copp.id[i][j], RESET_COPP_ID);
5213 atomic_set(&this_adm.copp.cnt[i][j], 0);
5214 atomic_set(&this_adm.copp.topology[i][j], 0);
5215 atomic_set(&this_adm.copp.mode[i][j], 0);
5216 atomic_set(&this_adm.copp.stat[i][j], 0);
5217 atomic_set(&this_adm.copp.rate[i][j], 0);
5218 atomic_set(&this_adm.copp.channels[i][j], 0);
5219 atomic_set(&this_adm.copp.bit_width[i][j], 0);
5220 atomic_set(&this_adm.copp.app_type[i][j], 0);
5221 atomic_set(&this_adm.copp.acdb_id[i][j], 0);
5222 init_waitqueue_head(&this_adm.copp.wait[i][j]);
5223 atomic_set(&this_adm.copp.adm_delay_stat[i][j], 0);
5224 init_waitqueue_head(
5225 &this_adm.copp.adm_delay_wait[i][j]);
5226 atomic_set(&this_adm.copp.topology[i][j], 0);
5227 this_adm.copp.adm_delay[i][j] = 0;
5228 this_adm.copp.adm_status[i][j] =
5229 ADM_STATUS_CALIBRATION_REQUIRED;
5230 }
5231 }
5232
5233 if (adm_init_cal_data())
5234 pr_err("%s: could not init cal data!\n", __func__);
5235
5236 this_adm.sourceTrackingData.ion_client = NULL;
5237 this_adm.sourceTrackingData.ion_handle = NULL;
5238 this_adm.sourceTrackingData.memmap.size = 0;
5239 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
5240 this_adm.sourceTrackingData.memmap.paddr = 0;
5241 this_adm.sourceTrackingData.apr_cmd_status = -1;
5242 atomic_set(&this_adm.mem_map_handles[ADM_MEM_MAP_INDEX_SOURCE_TRACKING],
5243 0);
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305244 mutex_init(&dts_srs_lock);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305245
5246 return 0;
5247}
5248
Asish Bhattacharya5faacb32017-12-04 17:23:15 +05305249void adm_exit(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305250{
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305251 mutex_destroy(&dts_srs_lock);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305252 adm_delete_cal_data();
5253}