blob: c5dd85c7cda0cab5e0280d4f982c6060aec1ef0e [file] [log] [blame]
Banajit Goswami08bb7362017-11-03 22:48:23 -07001/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/wait.h>
15#include <linux/sched.h>
16#include <linux/jiffies.h>
17#include <linux/uaccess.h>
18#include <linux/atomic.h>
19#include <linux/wait.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053020#include <sound/asound.h>
Laxminath Kasam8b1366a2017-10-05 01:44:16 +053021#include <dsp/msm-dts-srs-tm-config.h>
Laxminath Kasam605b42f2017-08-01 22:02:15 +053022#include <dsp/apr_audio-v2.h>
23#include <dsp/q6adm-v2.h>
24#include <dsp/q6audio-v2.h>
25#include <dsp/q6afe-v2.h>
26#include <dsp/audio_cal_utils.h>
27#include <ipc/apr.h>
28#include "adsp_err.h"
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053029
30#define TIMEOUT_MS 1000
31
32#define RESET_COPP_ID 99
33#define INVALID_COPP_ID 0xFF
34/* Used for inband payload copy, max size is 4k */
35/* 2 is to account for module & param ID in payload */
36#define ADM_GET_PARAMETER_LENGTH (4096 - APR_HDR_SIZE - 2 * sizeof(uint32_t))
37
38#define ULL_SUPPORTED_BITS_PER_SAMPLE 16
39#define ULL_SUPPORTED_SAMPLE_RATE 48000
40
41#ifndef CONFIG_DOLBY_DAP
42#undef DOLBY_ADM_COPP_TOPOLOGY_ID
43#define DOLBY_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFE
44#endif
45
46#ifndef CONFIG_DOLBY_DS2
47#undef DS2_ADM_COPP_TOPOLOGY_ID
48#define DS2_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFF
49#endif
50
51/* ENUM for adm_status */
52enum adm_cal_status {
53 ADM_STATUS_CALIBRATION_REQUIRED = 0,
54 ADM_STATUS_MAX,
55};
56
57struct adm_copp {
58
59 atomic_t id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
60 atomic_t cnt[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
61 atomic_t topology[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
62 atomic_t mode[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
63 atomic_t stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
64 atomic_t rate[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
65 atomic_t bit_width[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
66 atomic_t channels[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
67 atomic_t app_type[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
68 atomic_t acdb_id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
69 wait_queue_head_t wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
70 wait_queue_head_t adm_delay_wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
71 atomic_t adm_delay_stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
72 uint32_t adm_delay[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
73 unsigned long adm_status[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
74};
75
76struct source_tracking_data {
Banajit Goswami08bb7362017-11-03 22:48:23 -070077 struct dma_buf *dma_buf;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053078 struct param_outband memmap;
79 int apr_cmd_status;
80};
81
82struct adm_ctl {
83 void *apr;
84
85 struct adm_copp copp;
86
87 atomic_t matrix_map_stat;
88 wait_queue_head_t matrix_map_wait;
89
90 atomic_t adm_stat;
91 wait_queue_head_t adm_wait;
92
93 struct cal_type_data *cal_data[ADM_MAX_CAL_TYPES];
94
95 atomic_t mem_map_handles[ADM_MEM_MAP_INDEX_MAX];
96 atomic_t mem_map_index;
97
98 struct param_outband outband_memmap;
99 struct source_tracking_data sourceTrackingData;
100
101 int set_custom_topology;
102 int ec_ref_rx;
103 int num_ec_ref_rx_chans;
104 int ec_ref_rx_bit_width;
105 int ec_ref_rx_sampling_rate;
Aditya Bavanari2a627ae2017-11-21 20:24:53 +0530106 int lsm_port_id;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530107};
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(
Banajit Goswami08bb7362017-11-03 22:48:23 -07001503 this_adm.sourceTrackingData.dma_buf);
1504 this_adm.sourceTrackingData.dma_buf = NULL;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301505 this_adm.sourceTrackingData.memmap.size = 0;
1506 this_adm.sourceTrackingData.memmap.kvaddr =
1507 NULL;
1508 this_adm.sourceTrackingData.memmap.paddr = 0;
1509 this_adm.sourceTrackingData.apr_cmd_status = -1;
1510 atomic_set(&this_adm.mem_map_handles[
1511 ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
1512 }
1513 }
1514 return 0;
1515 }
1516
1517 adm_callback_debug_print(data);
1518 if (data->payload_size) {
1519 copp_idx = (data->token) & 0XFF;
1520 port_idx = ((data->token) >> 16) & 0xFF;
1521 client_id = ((data->token) >> 8) & 0xFF;
1522 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
1523 pr_err("%s: Invalid port idx %d token %d\n",
1524 __func__, port_idx, data->token);
1525 return 0;
1526 }
1527 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
1528 pr_err("%s: Invalid copp idx %d token %d\n",
1529 __func__, copp_idx, data->token);
1530 return 0;
1531 }
1532 if (client_id < 0 || client_id >= ADM_CLIENT_ID_MAX) {
1533 pr_err("%s: Invalid client id %d\n", __func__,
1534 client_id);
1535 return 0;
1536 }
1537 if (data->opcode == APR_BASIC_RSP_RESULT) {
1538 pr_debug("%s: APR_BASIC_RSP_RESULT id 0x%x\n",
1539 __func__, payload[0]);
1540 if (payload[1] != 0) {
1541 pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
1542 __func__, payload[0], payload[1]);
1543 }
1544 switch (payload[0]) {
1545 case ADM_CMD_SET_PP_PARAMS_V5:
1546 pr_debug("%s: ADM_CMD_SET_PP_PARAMS_V5\n",
1547 __func__);
1548 if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING)
1549 this_adm.sourceTrackingData.
1550 apr_cmd_status = payload[1];
1551 else if (rtac_make_adm_callback(payload,
1552 data->payload_size))
1553 break;
1554 /*
1555 * if soft volume is called and already
1556 * interrupted break out of the sequence here
1557 */
1558 case ADM_CMD_DEVICE_OPEN_V5:
1559 case ADM_CMD_DEVICE_CLOSE_V5:
1560 case ADM_CMD_DEVICE_OPEN_V6:
1561 pr_debug("%s: Basic callback received, wake up.\n",
1562 __func__);
1563 atomic_set(&this_adm.copp.stat[port_idx]
1564 [copp_idx], payload[1]);
1565 wake_up(
1566 &this_adm.copp.wait[port_idx][copp_idx]);
1567 break;
1568 case ADM_CMD_ADD_TOPOLOGIES:
1569 pr_debug("%s: callback received, ADM_CMD_ADD_TOPOLOGIES.\n",
1570 __func__);
1571 atomic_set(&this_adm.adm_stat, payload[1]);
1572 wake_up(&this_adm.adm_wait);
1573 break;
1574 case ADM_CMD_MATRIX_MAP_ROUTINGS_V5:
1575 case ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5:
1576 pr_debug("%s: Basic callback received, wake up.\n",
1577 __func__);
1578 atomic_set(&this_adm.matrix_map_stat,
1579 payload[1]);
1580 wake_up(&this_adm.matrix_map_wait);
1581 break;
1582 case ADM_CMD_SHARED_MEM_UNMAP_REGIONS:
1583 pr_debug("%s: ADM_CMD_SHARED_MEM_UNMAP_REGIONS\n",
1584 __func__);
1585 atomic_set(&this_adm.adm_stat, payload[1]);
1586 wake_up(&this_adm.adm_wait);
1587 break;
1588 case ADM_CMD_SHARED_MEM_MAP_REGIONS:
1589 pr_debug("%s: ADM_CMD_SHARED_MEM_MAP_REGIONS\n",
1590 __func__);
1591 /* Should only come here if there is an APR */
1592 /* error or malformed APR packet. Otherwise */
1593 /* response will be returned as */
1594 if (payload[1] != 0) {
1595 pr_err("%s: ADM map error, resuming\n",
1596 __func__);
1597 atomic_set(&this_adm.adm_stat,
1598 payload[1]);
1599 wake_up(&this_adm.adm_wait);
1600 }
1601 break;
1602 case ADM_CMD_GET_PP_PARAMS_V5:
1603 pr_debug("%s: ADM_CMD_GET_PP_PARAMS_V5\n",
1604 __func__);
1605 /* Should only come here if there is an APR */
1606 /* error or malformed APR packet. Otherwise */
1607 /* response will be returned as */
1608 /* ADM_CMDRSP_GET_PP_PARAMS_V5 */
1609 if (client_id ==
1610 ADM_CLIENT_ID_SOURCE_TRACKING) {
1611 this_adm.sourceTrackingData.
1612 apr_cmd_status = payload[1];
1613 if (payload[1] != 0)
1614 pr_err("%s: ADM get param error = %d\n",
1615 __func__, payload[1]);
1616
1617 atomic_set(&this_adm.copp.stat
1618 [port_idx][copp_idx],
1619 payload[1]);
1620 wake_up(&this_adm.copp.wait
1621 [port_idx][copp_idx]);
1622 } else {
1623 if (payload[1] != 0) {
1624 pr_err("%s: ADM get param error = %d, resuming\n",
1625 __func__, payload[1]);
1626
1627 rtac_make_adm_callback(payload,
1628 data->payload_size);
1629 }
1630 }
1631 break;
1632 case ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5:
1633 pr_debug("%s: ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5\n",
1634 __func__);
1635 atomic_set(&this_adm.copp.stat[port_idx]
1636 [copp_idx], payload[1]);
1637 wake_up(
1638 &this_adm.copp.wait[port_idx][copp_idx]);
1639 break;
1640 case ADM_CMD_GET_PP_TOPO_MODULE_LIST:
1641 pr_debug("%s:ADM_CMD_GET_PP_TOPO_MODULE_LIST\n",
1642 __func__);
1643 if (payload[1] != 0)
1644 pr_err("%s: ADM get topo list error = %d,\n",
1645 __func__, payload[1]);
1646 break;
1647 default:
1648 pr_err("%s: Unknown Cmd: 0x%x\n", __func__,
1649 payload[0]);
1650 break;
1651 }
1652 return 0;
1653 }
1654
1655 switch (data->opcode) {
1656 case ADM_CMDRSP_DEVICE_OPEN_V5:
1657 case ADM_CMDRSP_DEVICE_OPEN_V6: {
1658 struct adm_cmd_rsp_device_open_v5 *open =
1659 (struct adm_cmd_rsp_device_open_v5 *)data->payload;
1660
1661 if (open->copp_id == INVALID_COPP_ID) {
1662 pr_err("%s: invalid coppid rxed %d\n",
1663 __func__, open->copp_id);
1664 atomic_set(&this_adm.copp.stat[port_idx]
1665 [copp_idx], ADSP_EBADPARAM);
1666 wake_up(
1667 &this_adm.copp.wait[port_idx][copp_idx]);
1668 break;
1669 }
1670 atomic_set(&this_adm.copp.stat
1671 [port_idx][copp_idx], payload[0]);
1672 atomic_set(&this_adm.copp.id[port_idx][copp_idx],
1673 open->copp_id);
1674 pr_debug("%s: coppid rxed=%d\n", __func__,
1675 open->copp_id);
1676 wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
1677 }
1678 break;
1679 case ADM_CMDRSP_GET_PP_PARAMS_V5:
1680 pr_debug("%s: ADM_CMDRSP_GET_PP_PARAMS_V5\n", __func__);
1681 if (payload[0] != 0)
1682 pr_err("%s: ADM_CMDRSP_GET_PP_PARAMS_V5 returned error = 0x%x\n",
1683 __func__, payload[0]);
1684 if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING)
1685 this_adm.sourceTrackingData.apr_cmd_status =
1686 payload[0];
1687 else if (rtac_make_adm_callback(payload,
1688 data->payload_size))
1689 break;
1690
1691 idx = ADM_GET_PARAMETER_LENGTH * copp_idx;
1692 if ((payload[0] == 0) && (data->payload_size >
1693 (4 * sizeof(*payload))) &&
1694 (data->payload_size - 4 >=
1695 payload[3]) &&
1696 (ARRAY_SIZE(adm_get_parameters) >
1697 idx) &&
1698 (ARRAY_SIZE(adm_get_parameters)-idx-1 >=
1699 payload[3])) {
1700 adm_get_parameters[idx] = payload[3] /
1701 sizeof(uint32_t);
1702 /*
1703 * payload[3] is param_size which is
1704 * expressed in number of bytes
1705 */
1706 pr_debug("%s: GET_PP PARAM:received parameter length: 0x%x\n",
1707 __func__, adm_get_parameters[idx]);
1708 /* storing param size then params */
1709 for (i = 0; i < payload[3] /
1710 sizeof(uint32_t); i++)
1711 adm_get_parameters[idx+1+i] =
1712 payload[4+i];
1713 } else if (payload[0] == 0) {
1714 adm_get_parameters[idx] = -1;
1715 pr_err("%s: Out of band case, setting size to %d\n",
1716 __func__, adm_get_parameters[idx]);
1717 } else {
1718 adm_get_parameters[idx] = -1;
1719 pr_err("%s: GET_PP_PARAMS failed, setting size to %d\n",
1720 __func__, adm_get_parameters[idx]);
1721 }
1722 atomic_set(&this_adm.copp.stat
1723 [port_idx][copp_idx], payload[0]);
1724 wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
1725 break;
1726 case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST:
1727 pr_debug("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST\n",
1728 __func__);
1729 if (payload[0] != 0) {
1730 pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST",
1731 __func__);
1732 pr_err(":err = 0x%x\n", payload[0]);
1733 } else if (payload[1] >
1734 ((ADM_GET_TOPO_MODULE_LIST_LENGTH /
1735 sizeof(uint32_t)) - 1)) {
1736 pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST",
1737 __func__);
1738 pr_err(":size = %d\n", payload[1]);
1739 } else {
1740 idx = ADM_GET_TOPO_MODULE_LIST_LENGTH *
1741 copp_idx;
1742 pr_debug("%s:Num modules payload[1] %d\n",
1743 __func__, payload[1]);
1744 adm_module_topo_list[idx] = payload[1];
1745 for (i = 1; i <= payload[1]; i++) {
1746 adm_module_topo_list[idx+i] =
1747 payload[1+i];
1748 pr_debug("%s:payload[%d] = %x\n",
1749 __func__, (i+1), payload[1+i]);
1750 }
1751 }
1752 atomic_set(&this_adm.copp.stat
1753 [port_idx][copp_idx], payload[0]);
1754 wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
1755 break;
1756 case ADM_CMDRSP_SHARED_MEM_MAP_REGIONS:
1757 pr_debug("%s: ADM_CMDRSP_SHARED_MEM_MAP_REGIONS\n",
1758 __func__);
1759 atomic_set(&this_adm.mem_map_handles[
1760 atomic_read(&this_adm.mem_map_index)],
1761 *payload);
1762 atomic_set(&this_adm.adm_stat, 0);
1763 wake_up(&this_adm.adm_wait);
1764 break;
1765 default:
1766 pr_err("%s: Unknown cmd:0x%x\n", __func__,
1767 data->opcode);
1768 break;
1769 }
1770 }
1771 return 0;
1772}
1773
1774static int adm_memory_map_regions(phys_addr_t *buf_add, uint32_t mempool_id,
1775 uint32_t *bufsz, uint32_t bufcnt)
1776{
1777 struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
1778 struct avs_shared_map_region_payload *mregions = NULL;
1779 void *mmap_region_cmd = NULL;
1780 void *payload = NULL;
1781 int ret = 0;
1782 int i = 0;
1783 int cmd_size = 0;
1784
1785 pr_debug("%s:\n", __func__);
1786 if (this_adm.apr == NULL) {
1787 this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
1788 0xFFFFFFFF, &this_adm);
1789 if (this_adm.apr == NULL) {
1790 pr_err("%s: Unable to register ADM\n", __func__);
1791 ret = -ENODEV;
1792 return ret;
1793 }
1794 rtac_set_adm_handle(this_adm.apr);
1795 }
1796
1797 cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
1798 + sizeof(struct avs_shared_map_region_payload)
1799 * bufcnt;
1800
1801 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
1802 if (!mmap_region_cmd)
1803 return -ENOMEM;
1804
1805 mmap_regions = (struct avs_cmd_shared_mem_map_regions *)mmap_region_cmd;
1806 mmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1807 APR_HDR_LEN(APR_HDR_SIZE),
1808 APR_PKT_VER);
1809 mmap_regions->hdr.pkt_size = cmd_size;
1810 mmap_regions->hdr.src_port = 0;
1811
1812 mmap_regions->hdr.dest_port = 0;
1813 mmap_regions->hdr.token = 0;
1814 mmap_regions->hdr.opcode = ADM_CMD_SHARED_MEM_MAP_REGIONS;
1815 mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL & 0x00ff;
1816 mmap_regions->num_regions = bufcnt & 0x00ff;
1817 mmap_regions->property_flag = 0x00;
1818
1819 pr_debug("%s: map_regions->num_regions = %d\n", __func__,
1820 mmap_regions->num_regions);
1821 payload = ((u8 *) mmap_region_cmd +
1822 sizeof(struct avs_cmd_shared_mem_map_regions));
1823 mregions = (struct avs_shared_map_region_payload *)payload;
1824
1825 for (i = 0; i < bufcnt; i++) {
1826 mregions->shm_addr_lsw = lower_32_bits(buf_add[i]);
1827 mregions->shm_addr_msw =
1828 msm_audio_populate_upper_32_bits(buf_add[i]);
1829 mregions->mem_size_bytes = bufsz[i];
1830 ++mregions;
1831 }
1832
1833 atomic_set(&this_adm.adm_stat, -1);
1834 ret = apr_send_pkt(this_adm.apr, (uint32_t *) mmap_region_cmd);
1835 if (ret < 0) {
1836 pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__,
1837 mmap_regions->hdr.opcode, ret);
1838 ret = -EINVAL;
1839 goto fail_cmd;
1840 }
1841
1842 ret = wait_event_timeout(this_adm.adm_wait,
1843 atomic_read(&this_adm.adm_stat) >= 0,
1844 5 * HZ);
1845 if (!ret) {
1846 pr_err("%s: timeout. waited for memory_map\n", __func__);
1847 ret = -EINVAL;
1848 goto fail_cmd;
1849 } else if (atomic_read(&this_adm.adm_stat) > 0) {
1850 pr_err("%s: DSP returned error[%s]\n",
1851 __func__, adsp_err_get_err_str(
1852 atomic_read(&this_adm.adm_stat)));
1853 ret = adsp_err_get_lnx_err_code(
1854 atomic_read(&this_adm.adm_stat));
1855 goto fail_cmd;
1856 }
1857fail_cmd:
1858 kfree(mmap_region_cmd);
1859 return ret;
1860}
1861
1862static int adm_memory_unmap_regions(void)
1863{
1864 struct avs_cmd_shared_mem_unmap_regions unmap_regions;
1865 int ret = 0;
1866
1867 pr_debug("%s:\n", __func__);
1868 if (this_adm.apr == NULL) {
1869 pr_err("%s: APR handle NULL\n", __func__);
1870 return -EINVAL;
1871 }
1872
1873 unmap_regions.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1874 APR_HDR_LEN(APR_HDR_SIZE),
1875 APR_PKT_VER);
1876 unmap_regions.hdr.pkt_size = sizeof(unmap_regions);
1877 unmap_regions.hdr.src_port = 0;
1878 unmap_regions.hdr.dest_port = 0;
1879 unmap_regions.hdr.token = 0;
1880 unmap_regions.hdr.opcode = ADM_CMD_SHARED_MEM_UNMAP_REGIONS;
1881 unmap_regions.mem_map_handle = atomic_read(&this_adm.
1882 mem_map_handles[atomic_read(&this_adm.mem_map_index)]);
1883 atomic_set(&this_adm.adm_stat, -1);
1884 ret = apr_send_pkt(this_adm.apr, (uint32_t *) &unmap_regions);
1885 if (ret < 0) {
1886 pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__,
1887 unmap_regions.hdr.opcode, ret);
1888 ret = -EINVAL;
1889 goto fail_cmd;
1890 }
1891
1892 ret = wait_event_timeout(this_adm.adm_wait,
1893 atomic_read(&this_adm.adm_stat) >= 0,
1894 5 * HZ);
1895 if (!ret) {
1896 pr_err("%s: timeout. waited for memory_unmap\n",
1897 __func__);
1898 ret = -EINVAL;
1899 goto fail_cmd;
1900 } else if (atomic_read(&this_adm.adm_stat) > 0) {
1901 pr_err("%s: DSP returned error[%s]\n",
1902 __func__, adsp_err_get_err_str(
1903 atomic_read(&this_adm.adm_stat)));
1904 ret = adsp_err_get_lnx_err_code(
1905 atomic_read(&this_adm.adm_stat));
1906 goto fail_cmd;
1907 } else {
1908 pr_debug("%s: Unmap handle 0x%x succeeded\n", __func__,
1909 unmap_regions.mem_map_handle);
1910 }
1911fail_cmd:
1912 return ret;
1913}
1914
1915static int remap_cal_data(struct cal_block_data *cal_block, int cal_index)
1916{
1917 int ret = 0;
1918
Banajit Goswami08bb7362017-11-03 22:48:23 -07001919 if (cal_block->map_data.dma_buf == NULL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301920 pr_err("%s: No ION allocation for cal index %d!\n",
1921 __func__, cal_index);
1922 ret = -EINVAL;
1923 goto done;
1924 }
1925
1926 if ((cal_block->map_data.map_size > 0) &&
1927 (cal_block->map_data.q6map_handle == 0)) {
1928 atomic_set(&this_adm.mem_map_index, cal_index);
1929 ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
1930 (uint32_t *)&cal_block->map_data.map_size, 1);
1931 if (ret < 0) {
1932 pr_err("%s: ADM mmap did not work! size = %zd ret %d\n",
1933 __func__,
1934 cal_block->map_data.map_size, ret);
1935 pr_debug("%s: ADM mmap did not work! addr = 0x%pK, size = %zd ret %d\n",
1936 __func__,
1937 &cal_block->cal_data.paddr,
1938 cal_block->map_data.map_size, ret);
1939 goto done;
1940 }
1941 cal_block->map_data.q6map_handle = atomic_read(&this_adm.
1942 mem_map_handles[cal_index]);
1943 }
1944done:
1945 return ret;
1946}
1947
1948static void send_adm_custom_topology(void)
1949{
1950 struct cal_block_data *cal_block = NULL;
1951 struct cmd_set_topologies adm_top;
1952 int cal_index = ADM_CUSTOM_TOP_CAL;
1953 int result;
1954
1955 if (this_adm.cal_data[cal_index] == NULL)
1956 goto done;
1957
1958 mutex_lock(&this_adm.cal_data[cal_index]->lock);
1959 if (!this_adm.set_custom_topology)
1960 goto unlock;
1961 this_adm.set_custom_topology = 0;
1962
1963 cal_block = cal_utils_get_only_cal_block(this_adm.cal_data[cal_index]);
1964 if (cal_block == NULL)
1965 goto unlock;
1966
1967 pr_debug("%s: Sending cal_index %d\n", __func__, cal_index);
1968
1969 result = remap_cal_data(cal_block, cal_index);
1970 if (result) {
1971 pr_err("%s: Remap_cal_data failed for cal %d!\n",
1972 __func__, cal_index);
1973 goto unlock;
1974 }
1975 atomic_set(&this_adm.mem_map_index, cal_index);
1976 atomic_set(&this_adm.mem_map_handles[cal_index],
1977 cal_block->map_data.q6map_handle);
1978
1979 if (cal_block->cal_data.size == 0) {
1980 pr_debug("%s: No ADM cal to send\n", __func__);
1981 goto unlock;
1982 }
1983
1984 adm_top.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1985 APR_HDR_LEN(20), APR_PKT_VER);
1986 adm_top.hdr.pkt_size = sizeof(adm_top);
1987 adm_top.hdr.src_svc = APR_SVC_ADM;
1988 adm_top.hdr.src_domain = APR_DOMAIN_APPS;
1989 adm_top.hdr.src_port = 0;
1990 adm_top.hdr.dest_svc = APR_SVC_ADM;
1991 adm_top.hdr.dest_domain = APR_DOMAIN_ADSP;
1992 adm_top.hdr.dest_port = 0;
1993 adm_top.hdr.token = 0;
1994 adm_top.hdr.opcode = ADM_CMD_ADD_TOPOLOGIES;
1995 adm_top.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr);
1996 adm_top.payload_addr_msw = msm_audio_populate_upper_32_bits(
1997 cal_block->cal_data.paddr);
1998 adm_top.mem_map_handle = cal_block->map_data.q6map_handle;
1999 adm_top.payload_size = cal_block->cal_data.size;
2000
2001 atomic_set(&this_adm.adm_stat, -1);
2002 pr_debug("%s: Sending ADM_CMD_ADD_TOPOLOGIES payload = 0x%pK, size = %d\n",
2003 __func__, &cal_block->cal_data.paddr,
2004 adm_top.payload_size);
2005 result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_top);
2006 if (result < 0) {
2007 pr_err("%s: Set topologies failed payload size = %zd result %d\n",
2008 __func__, cal_block->cal_data.size, result);
2009 goto unlock;
2010 }
2011 /* Wait for the callback */
2012 result = wait_event_timeout(this_adm.adm_wait,
2013 atomic_read(&this_adm.adm_stat) >= 0,
2014 msecs_to_jiffies(TIMEOUT_MS));
2015 if (!result) {
2016 pr_err("%s: Set topologies timed out payload size = %zd\n",
2017 __func__, cal_block->cal_data.size);
2018 goto unlock;
2019 } else if (atomic_read(&this_adm.adm_stat) > 0) {
2020 pr_err("%s: DSP returned error[%s]\n",
2021 __func__, adsp_err_get_err_str(
2022 atomic_read(&this_adm.adm_stat)));
2023 result = adsp_err_get_lnx_err_code(
2024 atomic_read(&this_adm.adm_stat));
2025 goto unlock;
2026 }
2027unlock:
2028 mutex_unlock(&this_adm.cal_data[cal_index]->lock);
2029done:
2030 return;
2031}
2032
2033static int send_adm_cal_block(int port_id, int copp_idx,
2034 struct cal_block_data *cal_block, int perf_mode,
2035 int app_type, int acdb_id, int sample_rate)
2036{
2037 s32 result = 0;
2038 struct adm_cmd_set_pp_params_v5 adm_params;
2039 int port_idx;
2040
2041 pr_debug("%s: Port id 0x%x sample_rate %d ,\n", __func__,
2042 port_id, sample_rate);
2043 port_id = afe_convert_virtual_to_portid(port_id);
2044 port_idx = adm_validate_and_get_port_index(port_id);
2045 if (port_idx < 0) {
2046 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
2047 return -EINVAL;
2048 }
2049 if (!cal_block) {
2050 pr_debug("%s: No ADM cal to send for port_id = 0x%x!\n",
2051 __func__, port_id);
2052 result = -EINVAL;
2053 goto done;
2054 }
2055 if (cal_block->cal_data.size <= 0) {
2056 pr_debug("%s: No ADM cal send for port_id = 0x%x!\n",
2057 __func__, port_id);
2058 result = -EINVAL;
2059 goto done;
2060 }
2061
2062 if (perf_mode == LEGACY_PCM_MODE &&
2063 ((atomic_read(&this_adm.copp.topology[port_idx][copp_idx])) ==
2064 DS2_ADM_COPP_TOPOLOGY_ID)) {
2065 pr_err("%s: perf_mode %d, topology 0x%x\n", __func__, perf_mode,
2066 atomic_read(
2067 &this_adm.copp.topology[port_idx][copp_idx]));
2068 goto done;
2069 }
2070
2071 adm_params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2072 APR_HDR_LEN(20), APR_PKT_VER);
2073 adm_params.hdr.pkt_size = sizeof(adm_params);
2074 adm_params.hdr.src_svc = APR_SVC_ADM;
2075 adm_params.hdr.src_domain = APR_DOMAIN_APPS;
2076 adm_params.hdr.src_port = port_id;
2077 adm_params.hdr.dest_svc = APR_SVC_ADM;
2078 adm_params.hdr.dest_domain = APR_DOMAIN_ADSP;
2079
2080 adm_params.hdr.token = port_idx << 16 | copp_idx;
2081 adm_params.hdr.dest_port =
2082 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
2083 adm_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
2084 adm_params.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr);
2085 adm_params.payload_addr_msw = msm_audio_populate_upper_32_bits(
2086 cal_block->cal_data.paddr);
2087 adm_params.mem_map_handle = cal_block->map_data.q6map_handle;
2088 adm_params.payload_size = cal_block->cal_data.size;
2089
2090 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2091 pr_debug("%s: Sending SET_PARAMS payload = 0x%pK, size = %d\n",
2092 __func__, &cal_block->cal_data.paddr,
2093 adm_params.payload_size);
2094 result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_params);
2095 if (result < 0) {
2096 pr_err("%s: Set params failed port 0x%x result %d\n",
2097 __func__, port_id, result);
2098 pr_debug("%s: Set params failed port = 0x%x payload = 0x%pK result %d\n",
2099 __func__, port_id, &cal_block->cal_data.paddr, result);
2100 result = -EINVAL;
2101 goto done;
2102 }
2103 /* Wait for the callback */
2104 result = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2105 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
2106 msecs_to_jiffies(TIMEOUT_MS));
2107 if (!result) {
2108 pr_err("%s: Set params timed out port = 0x%x\n",
2109 __func__, port_id);
2110 pr_debug("%s: Set params timed out port = 0x%x, payload = 0x%pK\n",
2111 __func__, port_id, &cal_block->cal_data.paddr);
2112 result = -EINVAL;
2113 goto done;
2114 } else if (atomic_read(&this_adm.copp.stat
2115 [port_idx][copp_idx]) > 0) {
2116 pr_err("%s: DSP returned error[%s]\n",
2117 __func__, adsp_err_get_err_str(
2118 atomic_read(&this_adm.copp.stat
2119 [port_idx][copp_idx])));
2120 result = adsp_err_get_lnx_err_code(
2121 atomic_read(&this_adm.copp.stat
2122 [port_idx][copp_idx]));
2123 goto done;
2124 }
2125
2126done:
2127 return result;
2128}
2129
2130static struct cal_block_data *adm_find_cal_by_path(int cal_index, int path)
2131{
2132 struct list_head *ptr, *next;
2133 struct cal_block_data *cal_block = NULL;
2134 struct audio_cal_info_audproc *audproc_cal_info = NULL;
2135 struct audio_cal_info_audvol *audvol_cal_info = NULL;
2136
2137 pr_debug("%s:\n", __func__);
2138
2139 list_for_each_safe(ptr, next,
2140 &this_adm.cal_data[cal_index]->cal_blocks) {
2141
2142 cal_block = list_entry(ptr,
2143 struct cal_block_data, list);
2144
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302145 if (cal_index == ADM_AUDPROC_CAL ||
2146 cal_index == ADM_LSM_AUDPROC_CAL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302147 audproc_cal_info = cal_block->cal_info;
2148 if ((audproc_cal_info->path == path) &&
2149 (cal_block->cal_data.size > 0))
2150 return cal_block;
2151 } else if (cal_index == ADM_AUDVOL_CAL) {
2152 audvol_cal_info = cal_block->cal_info;
2153 if ((audvol_cal_info->path == path) &&
2154 (cal_block->cal_data.size > 0))
2155 return cal_block;
2156 }
2157 }
2158 pr_debug("%s: Can't find ADM cal for cal_index %d, path %d\n",
2159 __func__, cal_index, path);
2160 return NULL;
2161}
2162
2163static struct cal_block_data *adm_find_cal_by_app_type(int cal_index, int path,
2164 int app_type)
2165{
2166 struct list_head *ptr, *next;
2167 struct cal_block_data *cal_block = NULL;
2168 struct audio_cal_info_audproc *audproc_cal_info = NULL;
2169 struct audio_cal_info_audvol *audvol_cal_info = NULL;
2170
2171 pr_debug("%s\n", __func__);
2172
2173 list_for_each_safe(ptr, next,
2174 &this_adm.cal_data[cal_index]->cal_blocks) {
2175
2176 cal_block = list_entry(ptr,
2177 struct cal_block_data, list);
2178
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302179 if (cal_index == ADM_AUDPROC_CAL ||
2180 cal_index == ADM_LSM_AUDPROC_CAL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302181 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
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302217 if (cal_index == ADM_AUDPROC_CAL ||
2218 cal_index == ADM_LSM_AUDPROC_CAL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302219 audproc_cal_info = cal_block->cal_info;
2220 if ((audproc_cal_info->path == path) &&
2221 (audproc_cal_info->app_type == app_type) &&
2222 (audproc_cal_info->acdb_id == acdb_id) &&
2223 (audproc_cal_info->sample_rate == sample_rate) &&
2224 (cal_block->cal_data.size > 0))
2225 return cal_block;
2226 } else if (cal_index == ADM_AUDVOL_CAL) {
2227 audvol_cal_info = cal_block->cal_info;
2228 if ((audvol_cal_info->path == path) &&
2229 (audvol_cal_info->app_type == app_type) &&
2230 (audvol_cal_info->acdb_id == acdb_id) &&
2231 (cal_block->cal_data.size > 0))
2232 return cal_block;
2233 }
2234 }
2235 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",
2236 __func__, cal_index, path, app_type, acdb_id, sample_rate);
2237 return adm_find_cal_by_app_type(cal_index, path, app_type);
2238}
2239
2240static int adm_remap_and_send_cal_block(int cal_index, int port_id,
2241 int copp_idx, struct cal_block_data *cal_block, int perf_mode,
2242 int app_type, int acdb_id, int sample_rate)
2243{
2244 int ret = 0;
2245
2246 pr_debug("%s: Sending cal_index cal %d\n", __func__, cal_index);
2247 ret = remap_cal_data(cal_block, cal_index);
2248 if (ret) {
2249 pr_err("%s: Remap_cal_data failed for cal %d!\n",
2250 __func__, cal_index);
2251 goto done;
2252 }
2253 ret = send_adm_cal_block(port_id, copp_idx, cal_block, perf_mode,
2254 app_type, acdb_id, sample_rate);
2255 if (ret < 0)
2256 pr_debug("%s: No cal sent for cal_index %d, port_id = 0x%x! ret %d sample_rate %d\n",
2257 __func__, cal_index, port_id, ret, sample_rate);
2258done:
2259 return ret;
2260}
2261
2262static void send_adm_cal_type(int cal_index, int path, int port_id,
2263 int copp_idx, int perf_mode, int app_type,
2264 int acdb_id, int sample_rate)
2265{
2266 struct cal_block_data *cal_block = NULL;
2267 int ret;
2268
2269 pr_debug("%s: cal index %d\n", __func__, cal_index);
2270
2271 if (this_adm.cal_data[cal_index] == NULL) {
2272 pr_debug("%s: cal_index %d not allocated!\n",
2273 __func__, cal_index);
2274 goto done;
2275 }
2276
2277 mutex_lock(&this_adm.cal_data[cal_index]->lock);
2278 cal_block = adm_find_cal(cal_index, path, app_type, acdb_id,
2279 sample_rate);
2280 if (cal_block == NULL)
2281 goto unlock;
2282
2283 ret = adm_remap_and_send_cal_block(cal_index, port_id, copp_idx,
2284 cal_block, perf_mode, app_type, acdb_id, sample_rate);
2285unlock:
2286 mutex_unlock(&this_adm.cal_data[cal_index]->lock);
2287done:
2288 return;
2289}
2290
2291static int get_cal_path(int path)
2292{
2293 if (path == 0x1)
2294 return RX_DEVICE;
2295 else
2296 return TX_DEVICE;
2297}
2298
Aditya Bavanari6348e872017-12-18 11:53:22 +05302299/*
2300 * Command to set LSM port ID
2301 * which is used to send LSM cal
2302 *
2303 * @port_id: Port ID number to be set
2304 *
2305 */
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302306void adm_set_lsm_port_id(int port_id)
2307{
2308 this_adm.lsm_port_id = port_id;
2309}
Aditya Bavanari6348e872017-12-18 11:53:22 +05302310EXPORT_SYMBOL(adm_set_lsm_port_id);
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302311
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302312static void send_adm_cal(int port_id, int copp_idx, int path, int perf_mode,
2313 int app_type, int acdb_id, int sample_rate)
2314{
2315 pr_debug("%s: port id 0x%x copp_idx %d\n", __func__, port_id, copp_idx);
2316
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302317 if (port_id != this_adm.lsm_port_id)
2318 send_adm_cal_type(ADM_AUDPROC_CAL, path, port_id, copp_idx,
2319 perf_mode, app_type, acdb_id, sample_rate);
2320 else
2321 send_adm_cal_type(ADM_LSM_AUDPROC_CAL, path, port_id, copp_idx,
2322 perf_mode, app_type, acdb_id, sample_rate);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302323 send_adm_cal_type(ADM_AUDVOL_CAL, path, port_id, copp_idx, perf_mode,
2324 app_type, acdb_id, sample_rate);
2325}
2326
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302327/**
2328 * adm_connect_afe_port -
2329 * command to send ADM connect AFE port
2330 *
2331 * @mode: value of mode for ADM connect AFE
2332 * @session_id: session active to connect
2333 * @port_id: Port ID number
2334 *
2335 * Returns 0 on success or error on failure
2336 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302337int adm_connect_afe_port(int mode, int session_id, int port_id)
2338{
2339 struct adm_cmd_connect_afe_port_v5 cmd;
2340 int ret = 0;
2341 int port_idx, copp_idx = 0;
2342
2343 pr_debug("%s: port_id: 0x%x session id:%d mode:%d\n", __func__,
2344 port_id, session_id, mode);
2345
2346 port_id = afe_convert_virtual_to_portid(port_id);
2347 port_idx = adm_validate_and_get_port_index(port_id);
2348 if (port_idx < 0) {
2349 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
2350 return -EINVAL;
2351 }
2352
2353 if (this_adm.apr == NULL) {
2354 this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
2355 0xFFFFFFFF, &this_adm);
2356 if (this_adm.apr == NULL) {
2357 pr_err("%s: Unable to register ADM\n", __func__);
2358 ret = -ENODEV;
2359 return ret;
2360 }
2361 rtac_set_adm_handle(this_adm.apr);
2362 }
2363 pr_debug("%s: Port ID 0x%x, index %d\n", __func__, port_id, port_idx);
2364
2365 cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2366 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
2367 cmd.hdr.pkt_size = sizeof(cmd);
2368 cmd.hdr.src_svc = APR_SVC_ADM;
2369 cmd.hdr.src_domain = APR_DOMAIN_APPS;
2370 cmd.hdr.src_port = port_id;
2371 cmd.hdr.dest_svc = APR_SVC_ADM;
2372 cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
2373 cmd.hdr.dest_port = 0; /* Ignored */
2374 cmd.hdr.token = port_idx << 16 | copp_idx;
2375 cmd.hdr.opcode = ADM_CMD_CONNECT_AFE_PORT_V5;
2376
2377 cmd.mode = mode;
2378 cmd.session_id = session_id;
2379 cmd.afe_port_id = port_id;
2380
2381 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2382 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&cmd);
2383 if (ret < 0) {
2384 pr_err("%s: ADM enable for port_id: 0x%x failed ret %d\n",
2385 __func__, port_id, ret);
2386 ret = -EINVAL;
2387 goto fail_cmd;
2388 }
2389 /* Wait for the callback with copp id */
2390 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2391 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
2392 msecs_to_jiffies(TIMEOUT_MS));
2393 if (!ret) {
2394 pr_err("%s: ADM connect timedout for port_id: 0x%x\n",
2395 __func__, port_id);
2396 ret = -EINVAL;
2397 goto fail_cmd;
2398 } else if (atomic_read(&this_adm.copp.stat
2399 [port_idx][copp_idx]) > 0) {
2400 pr_err("%s: DSP returned error[%s]\n",
2401 __func__, adsp_err_get_err_str(
2402 atomic_read(&this_adm.copp.stat
2403 [port_idx][copp_idx])));
2404 ret = adsp_err_get_lnx_err_code(
2405 atomic_read(&this_adm.copp.stat
2406 [port_idx][copp_idx]));
2407 goto fail_cmd;
2408 }
2409 atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]);
2410 return 0;
2411
2412fail_cmd:
2413
2414 return ret;
2415}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302416EXPORT_SYMBOL(adm_connect_afe_port);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302417
2418int adm_arrange_mch_map(struct adm_cmd_device_open_v5 *open, int path,
2419 int channel_mode)
2420{
2421 int rc = 0, idx;
2422
2423 memset(open->dev_channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2424 switch (path) {
2425 case ADM_PATH_PLAYBACK:
2426 idx = ADM_MCH_MAP_IDX_PLAYBACK;
2427 break;
2428 case ADM_PATH_LIVE_REC:
2429 case ADM_PATH_NONLIVE_REC:
2430 idx = ADM_MCH_MAP_IDX_REC;
2431 break;
2432 default:
2433 goto non_mch_path;
2434 };
2435 if ((open->dev_num_channel > 2) && multi_ch_maps[idx].set_channel_map) {
2436 memcpy(open->dev_channel_mapping,
2437 multi_ch_maps[idx].channel_mapping,
2438 PCM_FORMAT_MAX_NUM_CHANNEL);
2439 } else {
2440 if (channel_mode == 1) {
2441 open->dev_channel_mapping[0] = PCM_CHANNEL_FC;
2442 } else if (channel_mode == 2) {
2443 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2444 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2445 } else if (channel_mode == 3) {
2446 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2447 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2448 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2449 } else if (channel_mode == 4) {
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_LS;
2453 open->dev_channel_mapping[3] = PCM_CHANNEL_RS;
2454 } else if (channel_mode == 5) {
2455 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2456 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2457 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2458 open->dev_channel_mapping[3] = PCM_CHANNEL_LS;
2459 open->dev_channel_mapping[4] = PCM_CHANNEL_RS;
2460 } else if (channel_mode == 6) {
2461 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2462 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2463 open->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2464 open->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2465 open->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2466 open->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2467 } else if (channel_mode == 7) {
2468 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2469 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2470 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2471 open->dev_channel_mapping[3] = PCM_CHANNEL_LFE;
2472 open->dev_channel_mapping[4] = PCM_CHANNEL_LB;
2473 open->dev_channel_mapping[5] = PCM_CHANNEL_RB;
2474 open->dev_channel_mapping[6] = PCM_CHANNEL_CS;
2475 } else if (channel_mode == 8) {
2476 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2477 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2478 open->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2479 open->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2480 open->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2481 open->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2482 open->dev_channel_mapping[6] = PCM_CHANNEL_LB;
2483 open->dev_channel_mapping[7] = PCM_CHANNEL_RB;
2484 } else {
2485 pr_err("%s: invalid num_chan %d\n", __func__,
2486 channel_mode);
2487 rc = -EINVAL;
2488 goto inval_ch_mod;
2489 }
2490 }
2491
2492non_mch_path:
2493inval_ch_mod:
2494 return rc;
2495}
2496
2497int adm_arrange_mch_ep2_map(struct adm_cmd_device_open_v6 *open_v6,
2498 int channel_mode)
2499{
2500 int rc = 0;
2501
2502 memset(open_v6->dev_channel_mapping_eid2, 0,
2503 PCM_FORMAT_MAX_NUM_CHANNEL);
2504
2505 if (channel_mode == 1) {
2506 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FC;
2507 } else if (channel_mode == 2) {
2508 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2509 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2510 } else if (channel_mode == 3) {
2511 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2512 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2513 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC;
2514 } else if (channel_mode == 4) {
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_LS;
2518 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_RS;
2519 } else if (channel_mode == 5) {
2520 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2521 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2522 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC;
2523 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_LS;
2524 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_RS;
2525 } else if (channel_mode == 6) {
2526 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2527 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2528 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE;
2529 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC;
2530 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS;
2531 open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS;
2532 } else if (channel_mode == 8) {
2533 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2534 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2535 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE;
2536 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC;
2537 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS;
2538 open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS;
2539 open_v6->dev_channel_mapping_eid2[6] = PCM_CHANNEL_LB;
2540 open_v6->dev_channel_mapping_eid2[7] = PCM_CHANNEL_RB;
2541 } else {
2542 pr_err("%s: invalid num_chan %d\n", __func__,
2543 channel_mode);
2544 rc = -EINVAL;
2545 }
2546
2547 return rc;
2548}
2549
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302550/**
2551 * adm_open -
2552 * command to send ADM open
2553 *
2554 * @port_id: port id number
2555 * @path: direction or ADM path type
2556 * @rate: sample rate of session
2557 * @channel_mode: number of channels set
2558 * @topology: topology active for this session
2559 * @perf_mode: performance mode like LL/ULL/..
2560 * @bit_width: bit width to set for copp
2561 * @app_type: App type used for this session
2562 * @acdb_id: ACDB ID of this device
2563 *
2564 * Returns 0 on success or error on failure
2565 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302566int adm_open(int port_id, int path, int rate, int channel_mode, int topology,
2567 int perf_mode, uint16_t bit_width, int app_type, int acdb_id)
2568{
2569 struct adm_cmd_device_open_v5 open;
2570 struct adm_cmd_device_open_v6 open_v6;
2571 int ret = 0;
Asish Bhattacharya34504582017-08-08 12:55:01 +05302572 int port_idx, flags;
2573 int copp_idx = -1;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302574 int tmp_port = q6audio_get_port_id(port_id);
2575
2576 pr_debug("%s:port %#x path:%d rate:%d mode:%d perf_mode:%d,topo_id %d\n",
2577 __func__, port_id, path, rate, channel_mode, perf_mode,
2578 topology);
2579
2580 port_id = q6audio_convert_virtual_to_portid(port_id);
2581 port_idx = adm_validate_and_get_port_index(port_id);
2582 if (port_idx < 0) {
2583 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
2584 return -EINVAL;
2585 }
2586
2587 if (this_adm.apr == NULL) {
2588 this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
2589 0xFFFFFFFF, &this_adm);
2590 if (this_adm.apr == NULL) {
2591 pr_err("%s: Unable to register ADM\n", __func__);
2592 return -ENODEV;
2593 }
2594 rtac_set_adm_handle(this_adm.apr);
2595 }
2596
2597 if (perf_mode == ULL_POST_PROCESSING_PCM_MODE) {
2598 flags = ADM_ULL_POST_PROCESSING_DEVICE_SESSION;
2599 if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) ||
2600 (topology == DS2_ADM_COPP_TOPOLOGY_ID) ||
2601 (topology == SRS_TRUMEDIA_TOPOLOGY_ID))
2602 topology = DEFAULT_COPP_TOPOLOGY;
2603 } else if (perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) {
2604 flags = ADM_ULTRA_LOW_LATENCY_DEVICE_SESSION;
2605 topology = NULL_COPP_TOPOLOGY;
2606 rate = ULL_SUPPORTED_SAMPLE_RATE;
2607 bit_width = ULL_SUPPORTED_BITS_PER_SAMPLE;
2608 } else if (perf_mode == LOW_LATENCY_PCM_MODE) {
2609 flags = ADM_LOW_LATENCY_DEVICE_SESSION;
2610 if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) ||
2611 (topology == DS2_ADM_COPP_TOPOLOGY_ID) ||
2612 (topology == SRS_TRUMEDIA_TOPOLOGY_ID))
2613 topology = DEFAULT_COPP_TOPOLOGY;
2614 } else {
2615 if ((path == ADM_PATH_COMPRESSED_RX) ||
2616 (path == ADM_PATH_COMPRESSED_TX))
2617 flags = 0;
2618 else
2619 flags = ADM_LEGACY_DEVICE_SESSION;
2620 }
2621
Laxminath Kasam8f7ccc22017-08-28 17:35:04 +05302622 if ((topology == VPM_TX_SM_ECNS_V2_COPP_TOPOLOGY) ||
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302623 (topology == VPM_TX_DM_FLUENCE_COPP_TOPOLOGY) ||
2624 (topology == VPM_TX_DM_RFECNS_COPP_TOPOLOGY))
2625 rate = 16000;
2626
Asish Bhattacharya34504582017-08-08 12:55:01 +05302627 /*
2628 * Routing driver reuses the same adm for streams with the same
2629 * app_type, sample_rate etc.
2630 * This isn't allowed for ULL streams as per the DSP interface
2631 */
2632 if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE)
2633 copp_idx = adm_get_idx_if_copp_exists(port_idx, topology,
2634 perf_mode,
2635 rate, bit_width,
2636 app_type);
2637
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302638 if (copp_idx < 0) {
2639 copp_idx = adm_get_next_available_copp(port_idx);
2640 if (copp_idx >= MAX_COPPS_PER_PORT) {
2641 pr_err("%s: exceeded copp id %d\n",
2642 __func__, copp_idx);
2643 return -EINVAL;
2644 }
2645 atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0);
2646 atomic_set(&this_adm.copp.topology[port_idx][copp_idx],
2647 topology);
2648 atomic_set(&this_adm.copp.mode[port_idx][copp_idx],
2649 perf_mode);
2650 atomic_set(&this_adm.copp.rate[port_idx][copp_idx],
2651 rate);
2652 atomic_set(&this_adm.copp.channels[port_idx][copp_idx],
2653 channel_mode);
2654 atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx],
2655 bit_width);
2656 atomic_set(&this_adm.copp.app_type[port_idx][copp_idx],
2657 app_type);
2658 atomic_set(&this_adm.copp.acdb_id[port_idx][copp_idx],
2659 acdb_id);
2660 set_bit(ADM_STATUS_CALIBRATION_REQUIRED,
2661 (void *)&this_adm.copp.adm_status[port_idx][copp_idx]);
2662 if ((path != ADM_PATH_COMPRESSED_RX) &&
2663 (path != ADM_PATH_COMPRESSED_TX))
2664 send_adm_custom_topology();
2665 }
2666
2667 if (this_adm.copp.adm_delay[port_idx][copp_idx] &&
2668 perf_mode == LEGACY_PCM_MODE) {
2669 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx],
2670 1);
2671 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
2672 wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]);
2673 }
2674
2675 /* Create a COPP if port id are not enabled */
2676 if (atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]) == 0) {
2677 pr_debug("%s: open ADM: port_idx: %d, copp_idx: %d\n", __func__,
2678 port_idx, copp_idx);
2679 if ((topology == SRS_TRUMEDIA_TOPOLOGY_ID) &&
2680 perf_mode == LEGACY_PCM_MODE) {
2681 int res;
2682
2683 atomic_set(&this_adm.mem_map_index, ADM_SRS_TRUMEDIA);
2684 msm_dts_srs_tm_ion_memmap(&this_adm.outband_memmap);
2685 res = adm_memory_map_regions(&this_adm.outband_memmap.paddr, 0,
2686 (uint32_t *)&this_adm.outband_memmap.size, 1);
2687 if (res < 0) {
2688 pr_err("%s: SRS adm_memory_map_regions failed ! addr = 0x%pK, size = %d\n",
2689 __func__, (void *)this_adm.outband_memmap.paddr,
2690 (uint32_t)this_adm.outband_memmap.size);
2691 }
2692 }
2693 open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2694 APR_HDR_LEN(APR_HDR_SIZE),
2695 APR_PKT_VER);
2696 open.hdr.pkt_size = sizeof(open);
2697 open.hdr.src_svc = APR_SVC_ADM;
2698 open.hdr.src_domain = APR_DOMAIN_APPS;
2699 open.hdr.src_port = tmp_port;
2700 open.hdr.dest_svc = APR_SVC_ADM;
2701 open.hdr.dest_domain = APR_DOMAIN_ADSP;
2702 open.hdr.dest_port = tmp_port;
2703 open.hdr.token = port_idx << 16 | copp_idx;
2704 open.hdr.opcode = ADM_CMD_DEVICE_OPEN_V5;
2705 open.flags = flags;
2706 open.mode_of_operation = path;
2707 open.endpoint_id_1 = tmp_port;
2708 open.endpoint_id_2 = 0xFFFF;
2709
2710 if (this_adm.ec_ref_rx && (path != 1)) {
2711 open.endpoint_id_2 = this_adm.ec_ref_rx;
2712 this_adm.ec_ref_rx = -1;
2713 }
2714
2715 open.topology_id = topology;
2716
2717 open.dev_num_channel = channel_mode & 0x00FF;
2718 open.bit_width = bit_width;
2719 WARN_ON((perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) &&
2720 (rate != ULL_SUPPORTED_SAMPLE_RATE));
2721 open.sample_rate = rate;
2722
2723 ret = adm_arrange_mch_map(&open, path, channel_mode);
2724
2725 if (ret)
2726 return ret;
2727
2728 pr_debug("%s: port_id=0x%x rate=%d topology_id=0x%X\n",
2729 __func__, open.endpoint_id_1, open.sample_rate,
2730 open.topology_id);
2731
2732 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2733
2734 if ((this_adm.num_ec_ref_rx_chans != 0) && (path != 1) &&
2735 (open.endpoint_id_2 != 0xFFFF)) {
2736 memset(&open_v6, 0,
2737 sizeof(struct adm_cmd_device_open_v6));
2738 memcpy(&open_v6, &open,
2739 sizeof(struct adm_cmd_device_open_v5));
2740 open_v6.hdr.opcode = ADM_CMD_DEVICE_OPEN_V6;
2741 open_v6.hdr.pkt_size = sizeof(open_v6);
2742 open_v6.dev_num_channel_eid2 =
2743 this_adm.num_ec_ref_rx_chans;
2744 this_adm.num_ec_ref_rx_chans = 0;
2745
2746 if (this_adm.ec_ref_rx_bit_width != 0) {
2747 open_v6.bit_width_eid2 =
2748 this_adm.ec_ref_rx_bit_width;
2749 this_adm.ec_ref_rx_bit_width = 0;
2750 } else {
2751 open_v6.bit_width_eid2 = bit_width;
2752 }
2753
2754 if (this_adm.ec_ref_rx_sampling_rate != 0) {
2755 open_v6.sample_rate_eid2 =
2756 this_adm.ec_ref_rx_sampling_rate;
2757 this_adm.ec_ref_rx_sampling_rate = 0;
2758 } else {
2759 open_v6.sample_rate_eid2 = rate;
2760 }
2761
2762 pr_debug("%s: eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n",
2763 __func__, open_v6.dev_num_channel_eid2,
2764 open_v6.bit_width_eid2,
2765 open_v6.sample_rate_eid2);
2766
2767 ret = adm_arrange_mch_ep2_map(&open_v6,
2768 open_v6.dev_num_channel_eid2);
2769
2770 if (ret)
2771 return ret;
2772
2773 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open_v6);
2774 } else {
2775 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&open);
2776 }
2777 if (ret < 0) {
2778 pr_err("%s: port_id: 0x%x for[0x%x] failed %d\n",
2779 __func__, tmp_port, port_id, ret);
2780 return -EINVAL;
2781 }
2782 /* Wait for the callback with copp id */
2783 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2784 atomic_read(&this_adm.copp.stat
2785 [port_idx][copp_idx]) >= 0,
2786 msecs_to_jiffies(TIMEOUT_MS));
2787 if (!ret) {
2788 pr_err("%s: ADM open timedout for port_id: 0x%x for [0x%x]\n",
2789 __func__, tmp_port, port_id);
2790 return -EINVAL;
2791 } else if (atomic_read(&this_adm.copp.stat
2792 [port_idx][copp_idx]) > 0) {
2793 pr_err("%s: DSP returned error[%s]\n",
2794 __func__, adsp_err_get_err_str(
2795 atomic_read(&this_adm.copp.stat
2796 [port_idx][copp_idx])));
2797 return adsp_err_get_lnx_err_code(
2798 atomic_read(&this_adm.copp.stat
2799 [port_idx][copp_idx]));
2800 }
2801 }
2802 atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]);
2803 return copp_idx;
2804}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302805EXPORT_SYMBOL(adm_open);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302806
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302807/**
2808 * adm_copp_mfc_cfg -
2809 * command to send ADM MFC config
2810 *
2811 * @port_id: Port ID number
2812 * @copp_idx: copp index assigned
2813 * @dst_sample_rate: sink sample rate
2814 *
2815 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302816void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate)
2817{
2818 struct audproc_mfc_output_media_fmt mfc_cfg;
2819 struct adm_cmd_device_open_v5 open;
2820 int port_idx;
2821 int sz = 0;
2822 int rc = 0;
2823 int i = 0;
2824
2825 port_id = q6audio_convert_virtual_to_portid(port_id);
2826 port_idx = adm_validate_and_get_port_index(port_id);
2827
2828 if (port_idx < 0) {
2829 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
2830 goto fail_cmd;
2831 }
2832
2833 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
2834 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
2835 goto fail_cmd;
2836 }
2837
2838 sz = sizeof(struct audproc_mfc_output_media_fmt);
2839
2840 mfc_cfg.params.hdr.hdr_field =
2841 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2842 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
2843 mfc_cfg.params.hdr.pkt_size = sz;
2844 mfc_cfg.params.hdr.src_svc = APR_SVC_ADM;
2845 mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS;
2846 mfc_cfg.params.hdr.src_port = port_id;
2847 mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM;
2848 mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP;
2849 mfc_cfg.params.hdr.dest_port =
2850 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
2851 mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx;
2852 mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
2853 mfc_cfg.params.payload_addr_lsw = 0;
2854 mfc_cfg.params.payload_addr_msw = 0;
2855 mfc_cfg.params.mem_map_handle = 0;
2856 mfc_cfg.params.payload_size = sizeof(mfc_cfg) -
2857 sizeof(mfc_cfg.params);
2858 mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC;
2859 mfc_cfg.data.param_id =
2860 AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
2861 mfc_cfg.data.param_size = mfc_cfg.params.payload_size -
2862 sizeof(mfc_cfg.data);
2863 mfc_cfg.data.reserved = 0;
2864 mfc_cfg.sampling_rate = dst_sample_rate;
2865 mfc_cfg.bits_per_sample =
2866 atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]);
2867 open.dev_num_channel = mfc_cfg.num_channels =
2868 atomic_read(&this_adm.copp.channels[port_idx][copp_idx]);
2869
2870 rc = adm_arrange_mch_map(&open, ADM_PATH_PLAYBACK,
2871 mfc_cfg.num_channels);
2872 if (rc < 0) {
2873 pr_err("%s: unable to get channal map\n", __func__);
2874 goto fail_cmd;
2875 }
2876
2877 for (i = 0; i < mfc_cfg.num_channels; i++)
2878 mfc_cfg.channel_type[i] =
2879 (uint16_t) open.dev_channel_mapping[i];
2880
2881 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2882
2883 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",
2884 __func__, port_idx, copp_idx,
2885 atomic_read(&this_adm.copp.rate[port_idx][copp_idx]),
2886 mfc_cfg.bits_per_sample, mfc_cfg.num_channels,
2887 mfc_cfg.sampling_rate);
2888
2889 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg);
2890
2891 if (rc < 0) {
2892 pr_err("%s: port_id: for[0x%x] failed %d\n",
2893 __func__, port_id, rc);
2894 goto fail_cmd;
2895 }
2896 /* Wait for the callback with copp id */
2897 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2898 atomic_read(&this_adm.copp.stat
2899 [port_idx][copp_idx]) >= 0,
2900 msecs_to_jiffies(TIMEOUT_MS));
2901 if (!rc) {
2902 pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n",
2903 __func__, port_id);
2904 goto fail_cmd;
2905 } else if (atomic_read(&this_adm.copp.stat
2906 [port_idx][copp_idx]) > 0) {
2907 pr_err("%s: DSP returned error[%s]\n",
2908 __func__, adsp_err_get_err_str(
2909 atomic_read(&this_adm.copp.stat
2910 [port_idx][copp_idx])));
2911 goto fail_cmd;
2912 }
2913 rc = 0;
2914fail_cmd:
2915 return;
2916}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302917EXPORT_SYMBOL(adm_copp_mfc_cfg);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302918
2919static void route_set_opcode_matrix_id(
2920 struct adm_cmd_matrix_map_routings_v5 **route_addr,
2921 int path, uint32_t passthr_mode)
2922{
2923 struct adm_cmd_matrix_map_routings_v5 *route = *route_addr;
2924
2925 switch (path) {
2926 case ADM_PATH_PLAYBACK:
2927 route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5;
2928 route->matrix_id = ADM_MATRIX_ID_AUDIO_RX;
2929 break;
2930 case ADM_PATH_LIVE_REC:
2931 if (passthr_mode == LISTEN) {
2932 route->hdr.opcode =
2933 ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
2934 route->matrix_id = ADM_MATRIX_ID_LISTEN_TX;
2935 break;
2936 }
2937 /* fall through to set matrix id for non-listen case */
2938 case ADM_PATH_NONLIVE_REC:
2939 route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5;
2940 route->matrix_id = ADM_MATRIX_ID_AUDIO_TX;
2941 break;
2942 case ADM_PATH_COMPRESSED_RX:
2943 route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
2944 route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_RX;
2945 break;
2946 case ADM_PATH_COMPRESSED_TX:
2947 route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
2948 route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_TX;
2949 break;
2950 default:
2951 pr_err("%s: Wrong path set[%d]\n", __func__, path);
2952 break;
2953 }
2954 pr_debug("%s: opcode 0x%x, matrix id %d\n",
2955 __func__, route->hdr.opcode, route->matrix_id);
2956}
2957
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302958/**
2959 * adm_matrix_map -
2960 * command to send ADM matrix map for ADM copp list
2961 *
2962 * @path: direction or ADM path type
2963 * @payload_map: have info of session id and associated copp_idx/num_copps
2964 * @perf_mode: performance mode like LL/ULL/..
2965 * @passthr_mode: flag to indicate passthrough mode
2966 *
2967 * Returns 0 on success or error on failure
2968 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302969int adm_matrix_map(int path, struct route_payload payload_map, int perf_mode,
2970 uint32_t passthr_mode)
2971{
2972 struct adm_cmd_matrix_map_routings_v5 *route;
2973 struct adm_session_map_node_v5 *node;
2974 uint16_t *copps_list;
2975 int cmd_size = 0;
2976 int ret = 0, i = 0;
2977 void *payload = NULL;
2978 void *matrix_map = NULL;
2979 int port_idx, copp_idx;
2980
2981 /* Assumes port_ids have already been validated during adm_open */
2982 cmd_size = (sizeof(struct adm_cmd_matrix_map_routings_v5) +
2983 sizeof(struct adm_session_map_node_v5) +
2984 (sizeof(uint32_t) * payload_map.num_copps));
2985 matrix_map = kzalloc(cmd_size, GFP_KERNEL);
2986 if (matrix_map == NULL) {
2987 pr_err("%s: Mem alloc failed\n", __func__);
2988 ret = -EINVAL;
2989 return ret;
2990 }
2991 route = (struct adm_cmd_matrix_map_routings_v5 *)matrix_map;
2992
2993 route->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2994 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
2995 route->hdr.pkt_size = cmd_size;
2996 route->hdr.src_svc = 0;
2997 route->hdr.src_domain = APR_DOMAIN_APPS;
2998 route->hdr.src_port = 0; /* Ignored */;
2999 route->hdr.dest_svc = APR_SVC_ADM;
3000 route->hdr.dest_domain = APR_DOMAIN_ADSP;
3001 route->hdr.dest_port = 0; /* Ignored */;
3002 route->hdr.token = 0;
3003 route->num_sessions = 1;
3004 route_set_opcode_matrix_id(&route, path, passthr_mode);
3005
3006 payload = ((u8 *)matrix_map +
3007 sizeof(struct adm_cmd_matrix_map_routings_v5));
3008 node = (struct adm_session_map_node_v5 *)payload;
3009
3010 node->session_id = payload_map.session_id;
3011 node->num_copps = payload_map.num_copps;
3012 payload = (u8 *)node + sizeof(struct adm_session_map_node_v5);
3013 copps_list = (uint16_t *)payload;
3014 for (i = 0; i < payload_map.num_copps; i++) {
3015 port_idx =
3016 adm_validate_and_get_port_index(payload_map.port_id[i]);
3017 if (port_idx < 0) {
3018 pr_err("%s: Invalid port_id 0x%x\n", __func__,
3019 payload_map.port_id[i]);
3020 ret = -EINVAL;
3021 goto fail_cmd;
3022 }
3023 copp_idx = payload_map.copp_idx[i];
3024 copps_list[i] = atomic_read(&this_adm.copp.id[port_idx]
3025 [copp_idx]);
3026 }
3027 atomic_set(&this_adm.matrix_map_stat, -1);
3028
3029 ret = apr_send_pkt(this_adm.apr, (uint32_t *)matrix_map);
3030 if (ret < 0) {
3031 pr_err("%s: routing for syream %d failed ret %d\n",
3032 __func__, payload_map.session_id, ret);
3033 ret = -EINVAL;
3034 goto fail_cmd;
3035 }
3036 ret = wait_event_timeout(this_adm.matrix_map_wait,
3037 atomic_read(&this_adm.matrix_map_stat) >= 0,
3038 msecs_to_jiffies(TIMEOUT_MS));
3039 if (!ret) {
3040 pr_err("%s: routing for syream %d failed\n", __func__,
3041 payload_map.session_id);
3042 ret = -EINVAL;
3043 goto fail_cmd;
3044 } else if (atomic_read(&this_adm.matrix_map_stat) > 0) {
3045 pr_err("%s: DSP returned error[%s]\n", __func__,
3046 adsp_err_get_err_str(atomic_read(
3047 &this_adm.matrix_map_stat)));
3048 ret = adsp_err_get_lnx_err_code(
3049 atomic_read(&this_adm.matrix_map_stat));
3050 goto fail_cmd;
3051 }
3052
3053 if ((perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) &&
3054 (path != ADM_PATH_COMPRESSED_RX)) {
3055 for (i = 0; i < payload_map.num_copps; i++) {
3056 port_idx = afe_get_port_index(payload_map.port_id[i]);
3057 copp_idx = payload_map.copp_idx[i];
3058 if (port_idx < 0 || copp_idx < 0 ||
3059 (copp_idx > MAX_COPPS_PER_PORT - 1)) {
3060 pr_err("%s: Invalid idx port_idx %d copp_idx %d\n",
3061 __func__, port_idx, copp_idx);
3062 continue;
3063 }
3064 rtac_add_adm_device(payload_map.port_id[i],
3065 atomic_read(&this_adm.copp.id
3066 [port_idx][copp_idx]),
3067 get_cal_path(path),
3068 payload_map.session_id,
3069 payload_map.app_type[i],
3070 payload_map.acdb_dev_id[i]);
3071
3072 if (!test_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3073 (void *)&this_adm.copp.adm_status[port_idx]
3074 [copp_idx])) {
3075 pr_debug("%s: adm copp[0x%x][%d] already sent",
3076 __func__, port_idx, copp_idx);
3077 continue;
3078 }
3079 send_adm_cal(payload_map.port_id[i], copp_idx,
3080 get_cal_path(path), perf_mode,
3081 payload_map.app_type[i],
3082 payload_map.acdb_dev_id[i],
3083 payload_map.sample_rate[i]);
3084 /* ADM COPP calibration is already sent */
3085 clear_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3086 (void *)&this_adm.copp.
3087 adm_status[port_idx][copp_idx]);
3088 pr_debug("%s: copp_id: %d\n", __func__,
3089 atomic_read(&this_adm.copp.id[port_idx]
3090 [copp_idx]));
3091 }
3092 }
3093
3094fail_cmd:
3095 kfree(matrix_map);
3096 return ret;
3097}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303098EXPORT_SYMBOL(adm_matrix_map);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303099
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303100/**
3101 * adm_ec_ref_rx_id -
3102 * Update EC ref port ID
3103 *
3104 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303105void adm_ec_ref_rx_id(int port_id)
3106{
3107 this_adm.ec_ref_rx = port_id;
3108 pr_debug("%s: ec_ref_rx:%d\n", __func__, this_adm.ec_ref_rx);
3109}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303110EXPORT_SYMBOL(adm_ec_ref_rx_id);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303111
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303112/**
3113 * adm_num_ec_ref_rx_chans -
3114 * Update EC ref number of channels
3115 *
3116 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303117void adm_num_ec_ref_rx_chans(int num_chans)
3118{
3119 this_adm.num_ec_ref_rx_chans = num_chans;
3120 pr_debug("%s: num_ec_ref_rx_chans:%d\n",
3121 __func__, this_adm.num_ec_ref_rx_chans);
3122}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303123EXPORT_SYMBOL(adm_num_ec_ref_rx_chans);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303124
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303125/**
3126 * adm_ec_ref_rx_bit_width -
3127 * Update EC ref bit_width
3128 *
3129 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303130void adm_ec_ref_rx_bit_width(int bit_width)
3131{
3132 this_adm.ec_ref_rx_bit_width = bit_width;
3133 pr_debug("%s: ec_ref_rx_bit_width:%d\n",
3134 __func__, this_adm.ec_ref_rx_bit_width);
3135}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303136EXPORT_SYMBOL(adm_ec_ref_rx_bit_width);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303137
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303138/**
3139 * adm_ec_ref_rx_sampling_rate -
3140 * Update EC ref sample rate
3141 *
3142 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303143void adm_ec_ref_rx_sampling_rate(int sampling_rate)
3144{
3145 this_adm.ec_ref_rx_sampling_rate = sampling_rate;
3146 pr_debug("%s: ec_ref_rx_sampling_rate:%d\n",
3147 __func__, this_adm.ec_ref_rx_sampling_rate);
3148}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303149EXPORT_SYMBOL(adm_ec_ref_rx_sampling_rate);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303150
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303151/**
3152 * adm_close -
3153 * command to close ADM copp
3154 *
3155 * @port_id: Port ID number
3156 * @perf_mode: performance mode like LL/ULL/..
3157 * @copp_idx: copp index assigned
3158 *
3159 * Returns 0 on success or error on failure
3160 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303161int adm_close(int port_id, int perf_mode, int copp_idx)
3162{
3163 struct apr_hdr close;
3164
3165 int ret = 0, port_idx;
3166 int copp_id = RESET_COPP_ID;
3167
3168 pr_debug("%s: port_id=0x%x perf_mode: %d copp_idx: %d\n", __func__,
3169 port_id, perf_mode, copp_idx);
3170
3171 port_id = q6audio_convert_virtual_to_portid(port_id);
3172 port_idx = adm_validate_and_get_port_index(port_id);
3173 if (port_idx < 0) {
3174 pr_err("%s: Invalid port_id 0x%x\n",
3175 __func__, port_id);
3176 return -EINVAL;
3177 }
3178
3179 if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) {
3180 pr_err("%s: Invalid copp idx: %d\n", __func__, copp_idx);
3181 return -EINVAL;
3182 }
3183
3184 if (this_adm.copp.adm_delay[port_idx][copp_idx] && perf_mode
3185 == LEGACY_PCM_MODE) {
3186 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx],
3187 1);
3188 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
3189 wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]);
3190 }
3191
3192 atomic_dec(&this_adm.copp.cnt[port_idx][copp_idx]);
3193 if (!(atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]))) {
3194 copp_id = adm_get_copp_id(port_idx, copp_idx);
3195 pr_debug("%s: Closing ADM port_idx:%d copp_idx:%d copp_id:0x%x\n",
3196 __func__, port_idx, copp_idx, copp_id);
3197 if ((!perf_mode) && (this_adm.outband_memmap.paddr != 0) &&
3198 (atomic_read(&this_adm.copp.topology[port_idx][copp_idx]) ==
3199 SRS_TRUMEDIA_TOPOLOGY_ID)) {
3200 atomic_set(&this_adm.mem_map_index,
3201 ADM_SRS_TRUMEDIA);
3202 ret = adm_memory_unmap_regions();
3203 if (ret < 0) {
3204 pr_err("%s: adm mem unmmap err %d",
3205 __func__, ret);
3206 } else {
3207 atomic_set(&this_adm.mem_map_handles
3208 [ADM_SRS_TRUMEDIA], 0);
3209 }
3210 }
3211
3212
3213 if ((afe_get_port_type(port_id) == MSM_AFE_PORT_TYPE_TX) &&
3214 this_adm.sourceTrackingData.memmap.paddr) {
3215 atomic_set(&this_adm.mem_map_index,
3216 ADM_MEM_MAP_INDEX_SOURCE_TRACKING);
3217 ret = adm_memory_unmap_regions();
3218 if (ret < 0) {
3219 pr_err("%s: adm mem unmmap err %d",
3220 __func__, ret);
3221 }
3222 msm_audio_ion_free(
Banajit Goswami08bb7362017-11-03 22:48:23 -07003223 this_adm.sourceTrackingData.dma_buf);
3224 this_adm.sourceTrackingData.dma_buf = NULL;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303225 this_adm.sourceTrackingData.memmap.size = 0;
3226 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
3227 this_adm.sourceTrackingData.memmap.paddr = 0;
3228 this_adm.sourceTrackingData.apr_cmd_status = -1;
3229 atomic_set(&this_adm.mem_map_handles[
3230 ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
3231 }
3232
3233 close.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3234 APR_HDR_LEN(APR_HDR_SIZE),
3235 APR_PKT_VER);
3236 close.pkt_size = sizeof(close);
3237 close.src_svc = APR_SVC_ADM;
3238 close.src_domain = APR_DOMAIN_APPS;
3239 close.src_port = port_id;
3240 close.dest_svc = APR_SVC_ADM;
3241 close.dest_domain = APR_DOMAIN_ADSP;
3242 close.dest_port = copp_id;
3243 close.token = port_idx << 16 | copp_idx;
3244 close.opcode = ADM_CMD_DEVICE_CLOSE_V5;
3245
3246 atomic_set(&this_adm.copp.id[port_idx][copp_idx],
3247 RESET_COPP_ID);
3248 atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0);
3249 atomic_set(&this_adm.copp.topology[port_idx][copp_idx], 0);
3250 atomic_set(&this_adm.copp.mode[port_idx][copp_idx], 0);
3251 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3252 atomic_set(&this_adm.copp.rate[port_idx][copp_idx], 0);
3253 atomic_set(&this_adm.copp.channels[port_idx][copp_idx], 0);
3254 atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx], 0);
3255 atomic_set(&this_adm.copp.app_type[port_idx][copp_idx], 0);
3256
3257 clear_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3258 (void *)&this_adm.copp.adm_status[port_idx][copp_idx]);
3259
3260 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close);
3261 if (ret < 0) {
3262 pr_err("%s: ADM close failed %d\n", __func__, ret);
3263 return -EINVAL;
3264 }
3265
3266 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3267 atomic_read(&this_adm.copp.stat
3268 [port_idx][copp_idx]) >= 0,
3269 msecs_to_jiffies(TIMEOUT_MS));
3270 if (!ret) {
3271 pr_err("%s: ADM cmd Route timedout for port 0x%x\n",
3272 __func__, port_id);
3273 return -EINVAL;
3274 } else if (atomic_read(&this_adm.copp.stat
3275 [port_idx][copp_idx]) > 0) {
3276 pr_err("%s: DSP returned error[%s]\n",
3277 __func__, adsp_err_get_err_str(
3278 atomic_read(&this_adm.copp.stat
3279 [port_idx][copp_idx])));
3280 return adsp_err_get_lnx_err_code(
3281 atomic_read(&this_adm.copp.stat
3282 [port_idx][copp_idx]));
3283 }
3284 }
3285
3286 if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) {
3287 pr_debug("%s: remove adm device from rtac\n", __func__);
3288 rtac_remove_adm_device(port_id, copp_id);
3289 }
3290 return 0;
3291}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303292EXPORT_SYMBOL(adm_close);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303293
3294int send_rtac_audvol_cal(void)
3295{
3296 int ret = 0;
3297 int ret2 = 0;
3298 int i = 0;
3299 int copp_idx, port_idx, acdb_id, app_id, path;
3300 struct cal_block_data *cal_block = NULL;
3301 struct audio_cal_info_audvol *audvol_cal_info = NULL;
3302 struct rtac_adm rtac_adm_data;
3303
3304 mutex_lock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock);
3305
3306 cal_block = cal_utils_get_only_cal_block(
3307 this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]);
3308 if (cal_block == NULL) {
3309 pr_err("%s: can't find cal block!\n", __func__);
3310 goto unlock;
3311 }
3312
3313 audvol_cal_info = cal_block->cal_info;
3314 if (audvol_cal_info == NULL) {
3315 pr_err("%s: audvol_cal_info is NULL!\n", __func__);
3316 goto unlock;
3317 }
3318
3319 get_rtac_adm_data(&rtac_adm_data);
3320 for (; i < rtac_adm_data.num_of_dev; i++) {
3321
3322 acdb_id = rtac_adm_data.device[i].acdb_dev_id;
3323 if (acdb_id == 0)
3324 acdb_id = audvol_cal_info->acdb_id;
3325
3326 app_id = rtac_adm_data.device[i].app_type;
3327 if (app_id == 0)
3328 app_id = audvol_cal_info->app_type;
3329
3330 path = afe_get_port_type(rtac_adm_data.device[i].afe_port);
3331 if ((acdb_id == audvol_cal_info->acdb_id) &&
3332 (app_id == audvol_cal_info->app_type) &&
3333 (path == audvol_cal_info->path)) {
3334
3335 if (adm_get_indexes_from_copp_id(rtac_adm_data.
3336 device[i].copp, &copp_idx, &port_idx) != 0) {
3337 pr_debug("%s: Copp Id %d is not active\n",
3338 __func__,
3339 rtac_adm_data.device[i].copp);
3340 continue;
3341 }
3342
3343 ret2 = adm_remap_and_send_cal_block(ADM_RTAC_AUDVOL_CAL,
3344 rtac_adm_data.device[i].afe_port,
3345 copp_idx, cal_block,
3346 atomic_read(&this_adm.copp.
3347 mode[port_idx][copp_idx]),
3348 audvol_cal_info->app_type,
3349 audvol_cal_info->acdb_id,
3350 atomic_read(&this_adm.copp.
3351 rate[port_idx][copp_idx]));
3352 if (ret2 < 0) {
3353 pr_debug("%s: remap and send failed for copp Id %d, acdb id %d, app type %d, path %d\n",
3354 __func__, rtac_adm_data.device[i].copp,
3355 audvol_cal_info->acdb_id,
3356 audvol_cal_info->app_type,
3357 audvol_cal_info->path);
3358 ret = ret2;
3359 }
3360 }
3361 }
3362unlock:
3363 mutex_unlock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock);
3364 return ret;
3365}
3366
3367int adm_map_rtac_block(struct rtac_cal_block_data *cal_block)
3368{
3369 int result = 0;
3370
3371 pr_debug("%s:\n", __func__);
3372
3373 if (cal_block == NULL) {
3374 pr_err("%s: cal_block is NULL!\n",
3375 __func__);
3376 result = -EINVAL;
3377 goto done;
3378 }
3379
3380 if (cal_block->cal_data.paddr == 0) {
3381 pr_debug("%s: No address to map!\n",
3382 __func__);
3383 result = -EINVAL;
3384 goto done;
3385 }
3386
3387 if (cal_block->map_data.map_size == 0) {
3388 pr_debug("%s: map size is 0!\n",
3389 __func__);
3390 result = -EINVAL;
3391 goto done;
3392 }
3393
3394 /* valid port ID needed for callback use primary I2S */
3395 atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL);
3396 result = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
3397 &cal_block->map_data.map_size, 1);
3398 if (result < 0) {
3399 pr_err("%s: RTAC mmap did not work! size = %d result %d\n",
3400 __func__,
3401 cal_block->map_data.map_size, result);
3402 pr_debug("%s: RTAC mmap did not work! addr = 0x%pK, size = %d\n",
3403 __func__,
3404 &cal_block->cal_data.paddr,
3405 cal_block->map_data.map_size);
3406 goto done;
3407 }
3408
3409 cal_block->map_data.map_handle = atomic_read(
3410 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]);
3411done:
3412 return result;
3413}
3414
3415int adm_unmap_rtac_block(uint32_t *mem_map_handle)
3416{
3417 int result = 0;
3418
3419 pr_debug("%s:\n", __func__);
3420
3421 if (mem_map_handle == NULL) {
3422 pr_debug("%s: Map handle is NULL, nothing to unmap\n",
3423 __func__);
3424 goto done;
3425 }
3426
3427 if (*mem_map_handle == 0) {
3428 pr_debug("%s: Map handle is 0, nothing to unmap\n",
3429 __func__);
3430 goto done;
3431 }
3432
3433 if (*mem_map_handle != atomic_read(
3434 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL])) {
3435 pr_err("%s: Map handles do not match! Unmapping RTAC, RTAC map 0x%x, ADM map 0x%x\n",
3436 __func__, *mem_map_handle, atomic_read(
3437 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]));
3438
3439 /* if mismatch use handle passed in to unmap */
3440 atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL],
3441 *mem_map_handle);
3442 }
3443
3444 /* valid port ID needed for callback use primary I2S */
3445 atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL);
3446 result = adm_memory_unmap_regions();
3447 if (result < 0) {
3448 pr_debug("%s: adm_memory_unmap_regions failed, error %d\n",
3449 __func__, result);
3450 } else {
3451 atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL], 0);
3452 *mem_map_handle = 0;
3453 }
3454done:
3455 return result;
3456}
3457
3458static int get_cal_type_index(int32_t cal_type)
3459{
3460 int ret = -EINVAL;
3461
3462 switch (cal_type) {
3463 case ADM_AUDPROC_CAL_TYPE:
3464 ret = ADM_AUDPROC_CAL;
3465 break;
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05303466 case ADM_LSM_AUDPROC_CAL_TYPE:
3467 ret = ADM_LSM_AUDPROC_CAL;
3468 break;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303469 case ADM_AUDVOL_CAL_TYPE:
3470 ret = ADM_AUDVOL_CAL;
3471 break;
3472 case ADM_CUST_TOPOLOGY_CAL_TYPE:
3473 ret = ADM_CUSTOM_TOP_CAL;
3474 break;
3475 case ADM_RTAC_INFO_CAL_TYPE:
3476 ret = ADM_RTAC_INFO_CAL;
3477 break;
3478 case ADM_RTAC_APR_CAL_TYPE:
3479 ret = ADM_RTAC_APR_CAL;
3480 break;
3481 case ADM_RTAC_AUDVOL_CAL_TYPE:
3482 ret = ADM_RTAC_AUDVOL_CAL;
3483 break;
3484 default:
3485 pr_err("%s: invalid cal type %d!\n", __func__, cal_type);
3486 }
3487 return ret;
3488}
3489
3490static int adm_alloc_cal(int32_t cal_type, size_t data_size, void *data)
3491{
3492 int ret = 0;
3493 int cal_index;
3494
3495 pr_debug("%s:\n", __func__);
3496
3497 cal_index = get_cal_type_index(cal_type);
3498 if (cal_index < 0) {
3499 pr_err("%s: could not get cal index %d!\n",
3500 __func__, cal_index);
3501 ret = -EINVAL;
3502 goto done;
3503 }
3504
3505 ret = cal_utils_alloc_cal(data_size, data,
3506 this_adm.cal_data[cal_index], 0, NULL);
3507 if (ret < 0) {
3508 pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
3509 __func__, ret, cal_type);
3510 ret = -EINVAL;
3511 goto done;
3512 }
3513done:
3514 return ret;
3515}
3516
3517static int adm_dealloc_cal(int32_t cal_type, size_t data_size, void *data)
3518{
3519 int ret = 0;
3520 int cal_index;
3521
3522 pr_debug("%s:\n", __func__);
3523
3524 cal_index = get_cal_type_index(cal_type);
3525 if (cal_index < 0) {
3526 pr_err("%s: could not get cal index %d!\n",
3527 __func__, cal_index);
3528 ret = -EINVAL;
3529 goto done;
3530 }
3531
3532 ret = cal_utils_dealloc_cal(data_size, data,
3533 this_adm.cal_data[cal_index]);
3534 if (ret < 0) {
3535 pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
3536 __func__, ret, cal_type);
3537 ret = -EINVAL;
3538 goto done;
3539 }
3540done:
3541 return ret;
3542}
3543
3544static int adm_set_cal(int32_t cal_type, size_t data_size, void *data)
3545{
3546 int ret = 0;
3547 int cal_index;
3548
3549 pr_debug("%s:\n", __func__);
3550
3551 cal_index = get_cal_type_index(cal_type);
3552 if (cal_index < 0) {
3553 pr_err("%s: could not get cal index %d!\n",
3554 __func__, cal_index);
3555 ret = -EINVAL;
3556 goto done;
3557 }
3558
3559 ret = cal_utils_set_cal(data_size, data,
3560 this_adm.cal_data[cal_index], 0, NULL);
3561 if (ret < 0) {
3562 pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
3563 __func__, ret, cal_type);
3564 ret = -EINVAL;
3565 goto done;
3566 }
3567
3568 if (cal_index == ADM_CUSTOM_TOP_CAL) {
3569 mutex_lock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock);
3570 this_adm.set_custom_topology = 1;
3571 mutex_unlock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock);
3572 } else if (cal_index == ADM_RTAC_AUDVOL_CAL) {
3573 send_rtac_audvol_cal();
3574 }
3575done:
3576 return ret;
3577}
3578
3579static int adm_map_cal_data(int32_t cal_type,
3580 struct cal_block_data *cal_block)
3581{
3582 int ret = 0;
3583 int cal_index;
3584
3585 pr_debug("%s:\n", __func__);
3586
3587 cal_index = get_cal_type_index(cal_type);
3588 if (cal_index < 0) {
3589 pr_err("%s: could not get cal index %d!\n",
3590 __func__, cal_index);
3591 ret = -EINVAL;
3592 goto done;
3593 }
3594
3595 atomic_set(&this_adm.mem_map_index, cal_index);
3596 ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
3597 (uint32_t *)&cal_block->map_data.map_size, 1);
3598 if (ret < 0) {
3599 pr_err("%s: map did not work! cal_type %i ret %d\n",
3600 __func__, cal_index, ret);
3601 ret = -ENODEV;
3602 goto done;
3603 }
3604 cal_block->map_data.q6map_handle = atomic_read(&this_adm.
3605 mem_map_handles[cal_index]);
3606done:
3607 return ret;
3608}
3609
3610static int adm_unmap_cal_data(int32_t cal_type,
3611 struct cal_block_data *cal_block)
3612{
3613 int ret = 0;
3614 int cal_index;
3615
3616 pr_debug("%s:\n", __func__);
3617
3618 cal_index = get_cal_type_index(cal_type);
3619 if (cal_index < 0) {
3620 pr_err("%s: could not get cal index %d!\n",
3621 __func__, cal_index);
3622 ret = -EINVAL;
3623 goto done;
3624 }
3625
3626 if (cal_block == NULL) {
3627 pr_err("%s: Cal block is NULL!\n",
3628 __func__);
3629 goto done;
3630 }
3631
3632 if (cal_block->map_data.q6map_handle == 0) {
3633 pr_err("%s: Map handle is NULL, nothing to unmap\n",
3634 __func__);
3635 goto done;
3636 }
3637
3638 atomic_set(&this_adm.mem_map_handles[cal_index],
3639 cal_block->map_data.q6map_handle);
3640 atomic_set(&this_adm.mem_map_index, cal_index);
3641 ret = adm_memory_unmap_regions();
3642 if (ret < 0) {
3643 pr_err("%s: unmap did not work! cal_type %i ret %d\n",
3644 __func__, cal_index, ret);
3645 ret = -ENODEV;
3646 goto done;
3647 }
3648 cal_block->map_data.q6map_handle = 0;
3649done:
3650 return ret;
3651}
3652
3653static void adm_delete_cal_data(void)
3654{
3655 pr_debug("%s:\n", __func__);
3656
3657 cal_utils_destroy_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data);
3658}
3659
3660static int adm_init_cal_data(void)
3661{
3662 int ret = 0;
3663 struct cal_type_info cal_type_info[] = {
3664 {{ADM_CUST_TOPOLOGY_CAL_TYPE,
3665 {adm_alloc_cal, adm_dealloc_cal, NULL,
3666 adm_set_cal, NULL, NULL} },
3667 {adm_map_cal_data, adm_unmap_cal_data,
3668 cal_utils_match_buf_num} },
3669
3670 {{ADM_AUDPROC_CAL_TYPE,
3671 {adm_alloc_cal, adm_dealloc_cal, NULL,
3672 adm_set_cal, NULL, NULL} },
3673 {adm_map_cal_data, adm_unmap_cal_data,
3674 cal_utils_match_buf_num} },
3675
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05303676 {{ADM_LSM_AUDPROC_CAL_TYPE,
3677 {adm_alloc_cal, adm_dealloc_cal, NULL,
3678 adm_set_cal, NULL, NULL} },
3679 {adm_map_cal_data, adm_unmap_cal_data,
3680 cal_utils_match_buf_num} },
3681
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303682 {{ADM_AUDVOL_CAL_TYPE,
3683 {adm_alloc_cal, adm_dealloc_cal, NULL,
3684 adm_set_cal, NULL, NULL} },
3685 {adm_map_cal_data, adm_unmap_cal_data,
3686 cal_utils_match_buf_num} },
3687
3688 {{ADM_RTAC_INFO_CAL_TYPE,
3689 {NULL, NULL, NULL, NULL, NULL, NULL} },
3690 {NULL, NULL, cal_utils_match_buf_num} },
3691
3692 {{ADM_RTAC_APR_CAL_TYPE,
3693 {NULL, NULL, NULL, NULL, NULL, NULL} },
3694 {NULL, NULL, cal_utils_match_buf_num} },
3695
3696 {{SRS_TRUMEDIA_CAL_TYPE,
3697 {NULL, NULL, NULL, NULL, NULL, NULL} },
3698 {NULL, NULL, cal_utils_match_buf_num} },
3699
3700 {{ADM_RTAC_AUDVOL_CAL_TYPE,
3701 {adm_alloc_cal, adm_dealloc_cal, NULL,
3702 adm_set_cal, NULL, NULL} },
3703 {adm_map_cal_data, adm_unmap_cal_data,
3704 cal_utils_match_buf_num} },
3705 };
3706 pr_debug("%s:\n", __func__);
3707
3708 ret = cal_utils_create_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data,
3709 cal_type_info);
3710 if (ret < 0) {
3711 pr_err("%s: could not create cal type! ret %d\n",
3712 __func__, ret);
3713 ret = -EINVAL;
3714 goto err;
3715 }
3716
3717 return ret;
3718err:
3719 adm_delete_cal_data();
3720 return ret;
3721}
3722
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303723/**
3724 * adm_set_volume -
3725 * command to set volume on ADM copp
3726 *
3727 * @port_id: Port ID number
3728 * @copp_idx: copp index assigned
3729 * @volume: gain value to set
3730 *
3731 * Returns 0 on success or error on failure
3732 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303733int adm_set_volume(int port_id, int copp_idx, int volume)
3734{
3735 struct audproc_volume_ctrl_master_gain audproc_vol;
3736 int sz = 0;
3737 int rc = 0;
3738 int port_idx;
3739
3740 pr_debug("%s: port_id %d, volume %d\n", __func__, port_id, volume);
3741 port_id = afe_convert_virtual_to_portid(port_id);
3742 port_idx = adm_validate_and_get_port_index(port_id);
3743 if (port_idx < 0) {
3744 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
3745 rc = -EINVAL;
3746 goto fail_cmd;
3747 }
3748
3749 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
3750 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
3751 return -EINVAL;
3752 }
3753
3754 sz = sizeof(struct audproc_volume_ctrl_master_gain);
3755 audproc_vol.params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3756 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
3757 audproc_vol.params.hdr.pkt_size = sz;
3758 audproc_vol.params.hdr.src_svc = APR_SVC_ADM;
3759 audproc_vol.params.hdr.src_domain = APR_DOMAIN_APPS;
3760 audproc_vol.params.hdr.src_port = port_id;
3761 audproc_vol.params.hdr.dest_svc = APR_SVC_ADM;
3762 audproc_vol.params.hdr.dest_domain = APR_DOMAIN_ADSP;
3763 audproc_vol.params.hdr.dest_port =
3764 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
3765 audproc_vol.params.hdr.token = port_idx << 16 | copp_idx;
3766 audproc_vol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
3767 audproc_vol.params.payload_addr_lsw = 0;
3768 audproc_vol.params.payload_addr_msw = 0;
3769 audproc_vol.params.mem_map_handle = 0;
3770 audproc_vol.params.payload_size = sizeof(audproc_vol) -
3771 sizeof(audproc_vol.params);
3772 audproc_vol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL;
3773 audproc_vol.data.param_id = AUDPROC_PARAM_ID_VOL_CTRL_MASTER_GAIN;
3774 audproc_vol.data.param_size = audproc_vol.params.payload_size -
3775 sizeof(audproc_vol.data);
3776 audproc_vol.data.reserved = 0;
3777 audproc_vol.master_gain = volume;
3778
3779 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3780 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_vol);
3781 if (rc < 0) {
3782 pr_err("%s: Set params failed port = %#x\n",
3783 __func__, port_id);
3784 rc = -EINVAL;
3785 goto fail_cmd;
3786 }
3787 /* Wait for the callback */
3788 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3789 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
3790 msecs_to_jiffies(TIMEOUT_MS));
3791 if (!rc) {
3792 pr_err("%s: Vol cntrl Set params timed out port = %#x\n",
3793 __func__, port_id);
3794 rc = -EINVAL;
3795 goto fail_cmd;
3796 } else if (atomic_read(&this_adm.copp.stat
3797 [port_idx][copp_idx]) > 0) {
3798 pr_err("%s: DSP returned error[%s]\n",
3799 __func__, adsp_err_get_err_str(
3800 atomic_read(&this_adm.copp.stat
3801 [port_idx][copp_idx])));
3802 rc = adsp_err_get_lnx_err_code(
3803 atomic_read(&this_adm.copp.stat
3804 [port_idx][copp_idx]));
3805 goto fail_cmd;
3806 }
3807 rc = 0;
3808fail_cmd:
3809 return rc;
3810}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303811EXPORT_SYMBOL(adm_set_volume);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303812
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303813/**
3814 * adm_set_softvolume -
3815 * command to set softvolume
3816 *
3817 * @port_id: Port ID number
3818 * @copp_idx: copp index assigned
3819 * @softvol_param: Params to set for softvolume
3820 *
3821 * Returns 0 on success or error on failure
3822 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303823int adm_set_softvolume(int port_id, int copp_idx,
3824 struct audproc_softvolume_params *softvol_param)
3825{
3826 struct audproc_soft_step_volume_params audproc_softvol;
3827 int sz = 0;
3828 int rc = 0;
3829 int port_idx;
3830
3831 pr_debug("%s: period %d step %d curve %d\n", __func__,
3832 softvol_param->period, softvol_param->step,
3833 softvol_param->rampingcurve);
3834
3835 port_id = afe_convert_virtual_to_portid(port_id);
3836 port_idx = adm_validate_and_get_port_index(port_id);
3837 if (port_idx < 0) {
3838 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
3839 rc = -EINVAL;
3840 goto fail_cmd;
3841 }
3842
3843 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
3844 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
3845 return -EINVAL;
3846 }
3847
3848 sz = sizeof(struct audproc_soft_step_volume_params);
3849
3850 audproc_softvol.params.hdr.hdr_field =
3851 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3852 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
3853 audproc_softvol.params.hdr.pkt_size = sz;
3854 audproc_softvol.params.hdr.src_svc = APR_SVC_ADM;
3855 audproc_softvol.params.hdr.src_domain = APR_DOMAIN_APPS;
3856 audproc_softvol.params.hdr.src_port = port_id;
3857 audproc_softvol.params.hdr.dest_svc = APR_SVC_ADM;
3858 audproc_softvol.params.hdr.dest_domain = APR_DOMAIN_ADSP;
3859 audproc_softvol.params.hdr.dest_port =
3860 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
3861 audproc_softvol.params.hdr.token = port_idx << 16 | copp_idx;
3862 audproc_softvol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
3863 audproc_softvol.params.payload_addr_lsw = 0;
3864 audproc_softvol.params.payload_addr_msw = 0;
3865 audproc_softvol.params.mem_map_handle = 0;
3866 audproc_softvol.params.payload_size = sizeof(audproc_softvol) -
3867 sizeof(audproc_softvol.params);
3868 audproc_softvol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL;
3869 audproc_softvol.data.param_id =
3870 AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS;
3871 audproc_softvol.data.param_size = audproc_softvol.params.payload_size -
3872 sizeof(audproc_softvol.data);
3873 audproc_softvol.data.reserved = 0;
3874 audproc_softvol.period = softvol_param->period;
3875 audproc_softvol.step = softvol_param->step;
3876 audproc_softvol.ramping_curve = softvol_param->rampingcurve;
3877
3878 pr_debug("%s: period %d, step %d, curve %d\n", __func__,
3879 audproc_softvol.period, audproc_softvol.step,
3880 audproc_softvol.ramping_curve);
3881
3882 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3883 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_softvol);
3884 if (rc < 0) {
3885 pr_err("%s: Set params failed port = %#x\n",
3886 __func__, port_id);
3887 rc = -EINVAL;
3888 goto fail_cmd;
3889 }
3890 /* Wait for the callback */
3891 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3892 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
3893 msecs_to_jiffies(TIMEOUT_MS));
3894 if (!rc) {
3895 pr_err("%s: Soft volume Set params timed out port = %#x\n",
3896 __func__, port_id);
3897 rc = -EINVAL;
3898 goto fail_cmd;
3899 } else if (atomic_read(&this_adm.copp.stat
3900 [port_idx][copp_idx]) > 0) {
3901 pr_err("%s: DSP returned error[%s]\n",
3902 __func__, adsp_err_get_err_str(
3903 atomic_read(&this_adm.copp.stat
3904 [port_idx][copp_idx])));
3905 rc = adsp_err_get_lnx_err_code(
3906 atomic_read(&this_adm.copp.stat
3907 [port_idx][copp_idx]));
3908 goto fail_cmd;
3909 }
3910 rc = 0;
3911fail_cmd:
3912 return rc;
3913}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303914EXPORT_SYMBOL(adm_set_softvolume);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303915
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303916/**
3917 * adm_set_mic_gain -
3918 * command to set MIC gain
3919 *
3920 * @port_id: Port ID number
3921 * @copp_idx: copp index assigned
3922 * @volume: gain value to set
3923 *
3924 * Returns 0 on success or error on failure
3925 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303926int adm_set_mic_gain(int port_id, int copp_idx, int volume)
3927{
3928 struct adm_set_mic_gain_params mic_gain_params;
3929 int rc = 0;
3930 int sz, port_idx;
3931
3932 pr_debug("%s:\n", __func__);
3933 port_id = afe_convert_virtual_to_portid(port_id);
3934 port_idx = adm_validate_and_get_port_index(port_id);
3935 if (port_idx < 0) {
3936 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
3937 return -EINVAL;
3938 }
3939
3940 sz = sizeof(struct adm_set_mic_gain_params);
3941
3942 mic_gain_params.params.hdr.hdr_field =
3943 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3944 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
3945 mic_gain_params.params.hdr.pkt_size = sz;
3946 mic_gain_params.params.hdr.src_svc = APR_SVC_ADM;
3947 mic_gain_params.params.hdr.src_domain = APR_DOMAIN_APPS;
3948 mic_gain_params.params.hdr.src_port = port_id;
3949 mic_gain_params.params.hdr.dest_svc = APR_SVC_ADM;
3950 mic_gain_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
3951 mic_gain_params.params.hdr.dest_port =
3952 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
3953 mic_gain_params.params.hdr.token = port_idx << 16 | copp_idx;
3954 mic_gain_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
3955 mic_gain_params.params.payload_addr_lsw = 0;
3956 mic_gain_params.params.payload_addr_msw = 0;
3957 mic_gain_params.params.mem_map_handle = 0;
3958 mic_gain_params.params.payload_size =
3959 sizeof(struct adm_param_data_v5) +
3960 sizeof(struct admx_mic_gain);
3961 mic_gain_params.data.module_id = ADM_MODULE_IDX_MIC_GAIN_CTRL;
3962 mic_gain_params.data.param_id = ADM_PARAM_IDX_MIC_GAIN;
3963 mic_gain_params.data.param_size =
3964 sizeof(struct admx_mic_gain);
3965 mic_gain_params.data.reserved = 0;
3966 mic_gain_params.mic_gain_data.tx_mic_gain = volume;
3967 mic_gain_params.mic_gain_data.reserved = 0;
3968 pr_debug("%s: Mic Gain set to %d at port_id 0x%x\n",
3969 __func__, volume, port_id);
3970
3971 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3972 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mic_gain_params);
3973 if (rc < 0) {
3974 pr_err("%s: Set params failed port = %#x\n",
3975 __func__, port_id);
3976 rc = -EINVAL;
3977 goto fail_cmd;
3978 }
3979 /* Wait for the callback */
3980 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3981 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
3982 msecs_to_jiffies(TIMEOUT_MS));
3983 if (!rc) {
3984 pr_err("%s: Mic Gain Set params timed out port = %#x\n",
3985 __func__, port_id);
3986 rc = -EINVAL;
3987 goto fail_cmd;
3988 } else if (atomic_read(&this_adm.copp.stat
3989 [port_idx][copp_idx]) > 0) {
3990 pr_err("%s: DSP returned error[%s]\n",
3991 __func__, adsp_err_get_err_str(
3992 atomic_read(&this_adm.copp.stat
3993 [port_idx][copp_idx])));
3994 rc = adsp_err_get_lnx_err_code(
3995 atomic_read(&this_adm.copp.stat
3996 [port_idx][copp_idx]));
3997 goto fail_cmd;
3998 }
3999 rc = 0;
4000fail_cmd:
4001 return rc;
4002}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304003EXPORT_SYMBOL(adm_set_mic_gain);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304004
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304005/**
4006 * adm_send_set_multichannel_ec_primary_mic_ch -
4007 * command to set multi-ch EC primary mic
4008 *
4009 * @port_id: Port ID number
4010 * @copp_idx: copp index assigned
4011 * @primary_mic_ch: channel number of primary mic
4012 *
4013 * Returns 0 on success or error on failure
4014 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304015int adm_send_set_multichannel_ec_primary_mic_ch(int port_id, int copp_idx,
4016 int primary_mic_ch)
4017{
4018 struct adm_set_sec_primary_ch_params sec_primary_ch_params;
4019 int rc = 0;
4020 int sz, port_idx;
4021
4022 pr_debug("%s port_id 0x%x, copp_idx 0x%x, primary_mic_ch %d\n",
4023 __func__, port_id, copp_idx, primary_mic_ch);
4024 port_id = afe_convert_virtual_to_portid(port_id);
4025 port_idx = adm_validate_and_get_port_index(port_id);
4026 if (port_idx < 0) {
4027 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
4028 return -EINVAL;
4029 }
4030
4031 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4032 pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx);
4033 return -EINVAL;
4034 }
4035
4036 sz = sizeof(struct adm_set_sec_primary_ch_params);
4037
4038 sec_primary_ch_params.params.hdr.hdr_field =
4039 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4040 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4041 sec_primary_ch_params.params.hdr.pkt_size = sz;
4042 sec_primary_ch_params.params.hdr.src_svc = APR_SVC_ADM;
4043 sec_primary_ch_params.params.hdr.src_domain = APR_DOMAIN_APPS;
4044 sec_primary_ch_params.params.hdr.src_port = port_id;
4045 sec_primary_ch_params.params.hdr.dest_svc = APR_SVC_ADM;
4046 sec_primary_ch_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4047 sec_primary_ch_params.params.hdr.dest_port =
4048 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4049 sec_primary_ch_params.params.hdr.token = port_idx << 16 | copp_idx;
4050 sec_primary_ch_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4051 sec_primary_ch_params.params.payload_addr_lsw = 0;
4052 sec_primary_ch_params.params.payload_addr_msw = 0;
4053 sec_primary_ch_params.params.mem_map_handle = 0;
4054 sec_primary_ch_params.params.payload_size =
4055 sizeof(struct adm_param_data_v5) +
4056 sizeof(struct admx_sec_primary_mic_ch);
4057 sec_primary_ch_params.data.module_id =
4058 AUDPROC_MODULE_ID_VOICE_TX_SECNS;
4059 sec_primary_ch_params.data.param_id =
4060 AUDPROC_PARAM_IDX_SEC_PRIMARY_MIC_CH;
4061 sec_primary_ch_params.data.param_size =
4062 sizeof(struct admx_sec_primary_mic_ch);
4063 sec_primary_ch_params.data.reserved = 0;
4064 sec_primary_ch_params.sec_primary_mic_ch_data.version = 0;
4065 sec_primary_ch_params.sec_primary_mic_ch_data.reserved = 0;
4066 sec_primary_ch_params.sec_primary_mic_ch_data.sec_primary_mic_ch =
4067 primary_mic_ch;
4068 sec_primary_ch_params.sec_primary_mic_ch_data.reserved1 = 0;
4069
4070 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4071 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&sec_primary_ch_params);
4072 if (rc < 0) {
4073 pr_err("%s: Set params failed port = %#x\n",
4074 __func__, port_id);
4075 rc = -EINVAL;
4076 goto fail_cmd;
4077 }
4078 /* Wait for the callback */
4079 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4080 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4081 msecs_to_jiffies(TIMEOUT_MS));
4082 if (!rc) {
4083 pr_err("%s: Mic Set params timed out port = %#x\n",
4084 __func__, port_id);
4085 rc = -EINVAL;
4086 goto fail_cmd;
4087 } else if (atomic_read(&this_adm.copp.stat
4088 [port_idx][copp_idx]) > 0) {
4089 pr_err("%s: DSP returned error[%s]\n",
4090 __func__, adsp_err_get_err_str(
4091 atomic_read(&this_adm.copp.stat
4092 [port_idx][copp_idx])));
4093 rc = adsp_err_get_lnx_err_code(
4094 atomic_read(&this_adm.copp.stat
4095 [port_idx][copp_idx]));
4096 goto fail_cmd;
4097 }
4098 rc = 0;
4099fail_cmd:
4100 return rc;
4101}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304102EXPORT_SYMBOL(adm_send_set_multichannel_ec_primary_mic_ch);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304103
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304104/**
4105 * adm_param_enable -
4106 * command to send params to ADM for given module
4107 *
4108 * @port_id: Port ID number
4109 * @copp_idx: copp index assigned
4110 * @module_id: ADM module
4111 * @enable: flag to enable or disable module
4112 *
4113 * Returns 0 on success or error on failure
4114 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304115int adm_param_enable(int port_id, int copp_idx, int module_id, int enable)
4116{
4117 struct audproc_enable_param_t adm_mod_enable;
4118 int sz = 0;
4119 int rc = 0;
4120 int port_idx;
4121
4122 pr_debug("%s port_id %d, module_id 0x%x, enable %d\n",
4123 __func__, port_id, module_id, enable);
4124 port_id = afe_convert_virtual_to_portid(port_id);
4125 port_idx = adm_validate_and_get_port_index(port_id);
4126 if (port_idx < 0) {
4127 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4128 rc = -EINVAL;
4129 goto fail_cmd;
4130 }
4131
4132 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4133 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4134 return -EINVAL;
4135 }
4136
4137 sz = sizeof(struct audproc_enable_param_t);
4138
4139 adm_mod_enable.pp_params.hdr.hdr_field =
4140 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4141 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4142 adm_mod_enable.pp_params.hdr.pkt_size = sz;
4143 adm_mod_enable.pp_params.hdr.src_svc = APR_SVC_ADM;
4144 adm_mod_enable.pp_params.hdr.src_domain = APR_DOMAIN_APPS;
4145 adm_mod_enable.pp_params.hdr.src_port = port_id;
4146 adm_mod_enable.pp_params.hdr.dest_svc = APR_SVC_ADM;
4147 adm_mod_enable.pp_params.hdr.dest_domain = APR_DOMAIN_ADSP;
4148 adm_mod_enable.pp_params.hdr.dest_port =
4149 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4150 adm_mod_enable.pp_params.hdr.token = port_idx << 16 | copp_idx;
4151 adm_mod_enable.pp_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4152 adm_mod_enable.pp_params.payload_addr_lsw = 0;
4153 adm_mod_enable.pp_params.payload_addr_msw = 0;
4154 adm_mod_enable.pp_params.mem_map_handle = 0;
4155 adm_mod_enable.pp_params.payload_size = sizeof(adm_mod_enable) -
4156 sizeof(adm_mod_enable.pp_params) +
4157 sizeof(adm_mod_enable.pp_params.params);
4158 adm_mod_enable.pp_params.params.module_id = module_id;
4159 adm_mod_enable.pp_params.params.param_id = AUDPROC_PARAM_ID_ENABLE;
4160 adm_mod_enable.pp_params.params.param_size =
4161 adm_mod_enable.pp_params.payload_size -
4162 sizeof(adm_mod_enable.pp_params.params);
4163 adm_mod_enable.pp_params.params.reserved = 0;
4164 adm_mod_enable.enable = enable;
4165
4166 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4167
4168 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_mod_enable);
4169 if (rc < 0) {
4170 pr_err("%s: Set params failed port = %#x\n",
4171 __func__, port_id);
4172 rc = -EINVAL;
4173 goto fail_cmd;
4174 }
4175 /* Wait for the callback */
4176 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4177 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4178 msecs_to_jiffies(TIMEOUT_MS));
4179 if (!rc) {
4180 pr_err("%s: module %x enable %d timed out on port = %#x\n",
4181 __func__, module_id, enable, port_id);
4182 rc = -EINVAL;
4183 goto fail_cmd;
4184 } else if (atomic_read(&this_adm.copp.stat
4185 [port_idx][copp_idx]) > 0) {
4186 pr_err("%s: DSP returned error[%s]\n",
4187 __func__, adsp_err_get_err_str(
4188 atomic_read(&this_adm.copp.stat
4189 [port_idx][copp_idx])));
4190 rc = adsp_err_get_lnx_err_code(
4191 atomic_read(&this_adm.copp.stat
4192 [port_idx][copp_idx]));
4193 goto fail_cmd;
4194 }
4195 rc = 0;
4196fail_cmd:
4197 return rc;
4198
4199}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304200EXPORT_SYMBOL(adm_param_enable);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304201
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304202/**
4203 * adm_send_calibration -
4204 * send ADM calibration to DSP
4205 *
4206 * @port_id: Port ID number
4207 * @copp_idx: copp index assigned
4208 * @path: direction or ADM path type
4209 * @perf_mode: performance mode like LL/ULL/..
4210 * @cal_type: calibration type to use
4211 * @params: pointer with cal data
4212 * @size: cal size
4213 *
4214 * Returns 0 on success or error on failure
4215 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304216int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode,
4217 int cal_type, char *params, int size)
4218{
4219
4220 struct adm_cmd_set_pp_params_v5 *adm_params = NULL;
4221 int sz, rc = 0;
4222 int port_idx;
4223
4224 pr_debug("%s:port_id %d, path %d, perf_mode %d, cal_type %d, size %d\n",
4225 __func__, port_id, path, perf_mode, cal_type, size);
4226
4227 port_id = afe_convert_virtual_to_portid(port_id);
4228 port_idx = adm_validate_and_get_port_index(port_id);
4229 if (port_idx < 0) {
4230 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4231 rc = -EINVAL;
4232 goto end;
4233 }
4234
4235 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4236 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4237 return -EINVAL;
4238 }
4239
4240 /* Maps audio_dev_ctrl path definition to ACDB definition */
4241 if (get_cal_path(path) != RX_DEVICE) {
4242 pr_err("%s: acdb_path %d\n", __func__, path);
4243 rc = -EINVAL;
4244 goto end;
4245 }
4246
4247 sz = sizeof(struct adm_cmd_set_pp_params_v5) + size;
4248 adm_params = kzalloc(sz, GFP_KERNEL);
4249 if (!adm_params) {
4250 pr_err("%s, adm params memory alloc failed", __func__);
4251 rc = -ENOMEM;
4252 goto end;
4253 }
4254
4255 memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)),
4256 params, size);
4257
4258 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4259 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4260 adm_params->hdr.pkt_size = sz;
4261 adm_params->hdr.src_svc = APR_SVC_ADM;
4262 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
4263 adm_params->hdr.src_port = port_id;
4264 adm_params->hdr.dest_svc = APR_SVC_ADM;
4265 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
4266 adm_params->hdr.dest_port =
4267 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4268 adm_params->hdr.token = port_idx << 16 | copp_idx;
4269 adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4270 /* payload address and mmap handle initialized to zero by kzalloc */
4271 adm_params->payload_size = size;
4272
4273 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4274 rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
4275 if (rc < 0) {
4276 pr_err("%s: Set params failed port = %#x\n",
4277 __func__, port_id);
4278 rc = -EINVAL;
4279 goto end;
4280 }
4281 /* Wait for the callback */
4282 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4283 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4284 msecs_to_jiffies(TIMEOUT_MS));
4285 if (!rc) {
4286 pr_err("%s: Set params timed out port = %#x\n",
4287 __func__, port_id);
4288 rc = -EINVAL;
4289 goto end;
4290 } else if (atomic_read(&this_adm.copp.stat
4291 [port_idx][copp_idx]) > 0) {
4292 pr_err("%s: DSP returned error[%s]\n",
4293 __func__, adsp_err_get_err_str(
4294 atomic_read(&this_adm.copp.stat
4295 [port_idx][copp_idx])));
4296 rc = adsp_err_get_lnx_err_code(
4297 atomic_read(&this_adm.copp.stat
4298 [port_idx][copp_idx]));
4299 goto end;
4300 }
4301 rc = 0;
4302
4303end:
4304 kfree(adm_params);
4305 return rc;
4306}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304307EXPORT_SYMBOL(adm_send_calibration);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304308
4309/*
4310 * adm_update_wait_parameters must be called with routing driver locks.
4311 * adm_reset_wait_parameters must be called with routing driver locks.
4312 * set and reset parmeters are separated to make sure it is always called
4313 * under routing driver lock.
4314 * adm_wait_timeout is to block until timeout or interrupted. Timeout is
4315 * not a an error.
4316 */
4317int adm_set_wait_parameters(int port_id, int copp_idx)
4318{
4319
4320 int ret = 0, port_idx;
4321
4322 pr_debug("%s: port_id 0x%x, copp_idx %d\n", __func__, port_id,
4323 copp_idx);
4324 port_id = afe_convert_virtual_to_portid(port_id);
4325 port_idx = adm_validate_and_get_port_index(port_id);
4326 if (port_idx < 0) {
4327 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4328 ret = -EINVAL;
4329 goto end;
4330 }
4331
4332 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4333 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4334 return -EINVAL;
4335 }
4336
4337 this_adm.copp.adm_delay[port_idx][copp_idx] = 1;
4338 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 0);
4339
4340end:
4341 return ret;
4342
4343}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304344EXPORT_SYMBOL(adm_set_wait_parameters);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304345
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304346/**
4347 * adm_reset_wait_parameters -
4348 * reset wait parameters or ADM delay value
4349 *
4350 * @port_id: Port ID number
4351 * @copp_idx: copp index assigned
4352 *
4353 * Returns 0 on success or error on failure
4354 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304355int adm_reset_wait_parameters(int port_id, int copp_idx)
4356{
4357 int ret = 0, port_idx;
4358
4359 pr_debug("%s: port_id 0x%x copp_idx %d\n", __func__, port_id,
4360 copp_idx);
4361 port_id = afe_convert_virtual_to_portid(port_id);
4362 port_idx = adm_validate_and_get_port_index(port_id);
4363 if (port_idx < 0) {
4364 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4365 ret = -EINVAL;
4366 goto end;
4367 }
4368
4369 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4370 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4371 return -EINVAL;
4372 }
4373
4374 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 1);
4375 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
4376
4377end:
4378 return ret;
4379}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304380EXPORT_SYMBOL(adm_reset_wait_parameters);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304381
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304382/**
4383 * adm_wait_timeout -
4384 * ADM wait command after command send to DSP
4385 *
4386 * @port_id: Port ID number
4387 * @copp_idx: copp index assigned
4388 * @wait_time: value in ms for command timeout
4389 *
4390 * Returns 0 on success or error on failure
4391 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304392int adm_wait_timeout(int port_id, int copp_idx, int wait_time)
4393{
4394 int ret = 0, port_idx;
4395
4396 pr_debug("%s: port_id 0x%x, copp_idx %d, wait_time %d\n", __func__,
4397 port_id, copp_idx, wait_time);
4398 port_id = afe_convert_virtual_to_portid(port_id);
4399 port_idx = adm_validate_and_get_port_index(port_id);
4400 if (port_idx < 0) {
4401 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4402 ret = -EINVAL;
4403 goto end;
4404 }
4405
4406 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4407 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4408 return -EINVAL;
4409 }
4410
4411 ret = wait_event_timeout(
4412 this_adm.copp.adm_delay_wait[port_idx][copp_idx],
4413 atomic_read(&this_adm.copp.adm_delay_stat[port_idx][copp_idx]),
4414 msecs_to_jiffies(wait_time));
4415 pr_debug("%s: return %d\n", __func__, ret);
4416 if (ret != 0)
4417 ret = -EINTR;
4418end:
4419 pr_debug("%s: return %d--\n", __func__, ret);
4420 return ret;
4421}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304422EXPORT_SYMBOL(adm_wait_timeout);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304423
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304424/**
4425 * adm_store_cal_data -
4426 * Retrieve calibration data for ADM copp device
4427 *
4428 * @port_id: Port ID number
4429 * @copp_idx: copp index assigned
4430 * @path: direction or copp type
4431 * @perf_mode: performance mode like LL/ULL/..
4432 * @cal_index: calibration index to use
4433 * @params: pointer to store cal data
4434 * @size: pointer to fill with cal size
4435 *
4436 * Returns 0 on success or error on failure
4437 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304438int adm_store_cal_data(int port_id, int copp_idx, int path, int perf_mode,
4439 int cal_index, char *params, int *size)
4440{
4441 int rc = 0;
4442 struct cal_block_data *cal_block = NULL;
4443 int app_type, acdb_id, port_idx, sample_rate;
4444
4445 if (this_adm.cal_data[cal_index] == NULL) {
4446 pr_debug("%s: cal_index %d not allocated!\n",
4447 __func__, cal_index);
4448 goto end;
4449 }
4450
4451 if (get_cal_path(path) != RX_DEVICE) {
4452 pr_debug("%s: Invalid path to store calibration %d\n",
4453 __func__, path);
4454 rc = -EINVAL;
4455 goto end;
4456 }
4457
4458 port_id = afe_convert_virtual_to_portid(port_id);
4459 port_idx = adm_validate_and_get_port_index(port_id);
4460 if (port_idx < 0) {
4461 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
4462 rc = -EINVAL;
4463 goto end;
4464 }
4465
4466 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4467 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4468 return -EINVAL;
4469 }
4470
4471 acdb_id = atomic_read(&this_adm.copp.acdb_id[port_idx][copp_idx]);
4472 app_type = atomic_read(&this_adm.copp.app_type[port_idx][copp_idx]);
4473 sample_rate = atomic_read(&this_adm.copp.rate[port_idx][copp_idx]);
4474
4475 mutex_lock(&this_adm.cal_data[cal_index]->lock);
4476 cal_block = adm_find_cal(cal_index, get_cal_path(path), app_type,
4477 acdb_id, sample_rate);
4478 if (cal_block == NULL)
4479 goto unlock;
4480
4481 if (cal_block->cal_data.size <= 0) {
4482 pr_debug("%s: No ADM cal send for port_id = 0x%x!\n",
4483 __func__, port_id);
4484 rc = -EINVAL;
4485 goto unlock;
4486 }
4487
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05304488 if (cal_index == ADM_AUDPROC_CAL || cal_index == ADM_LSM_AUDPROC_CAL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304489 if (cal_block->cal_data.size > AUD_PROC_BLOCK_SIZE) {
4490 pr_err("%s:audproc:invalid size exp/actual[%zd, %d]\n",
4491 __func__, cal_block->cal_data.size, *size);
4492 rc = -ENOMEM;
4493 goto unlock;
4494 }
4495 } else if (cal_index == ADM_AUDVOL_CAL) {
4496 if (cal_block->cal_data.size > AUD_VOL_BLOCK_SIZE) {
4497 pr_err("%s:aud_vol:invalid size exp/actual[%zd, %d]\n",
4498 __func__, cal_block->cal_data.size, *size);
4499 rc = -ENOMEM;
4500 goto unlock;
4501 }
4502 } else {
4503 pr_debug("%s: Not valid calibration for dolby topolgy\n",
4504 __func__);
4505 rc = -EINVAL;
4506 goto unlock;
4507 }
4508 memcpy(params, cal_block->cal_data.kvaddr, cal_block->cal_data.size);
4509 *size = cal_block->cal_data.size;
4510
4511 pr_debug("%s:port_id %d, copp_idx %d, path %d",
4512 __func__, port_id, copp_idx, path);
4513 pr_debug("perf_mode %d, cal_type %d, size %d\n",
4514 perf_mode, cal_index, *size);
4515
4516unlock:
4517 mutex_unlock(&this_adm.cal_data[cal_index]->lock);
4518end:
4519 return rc;
4520}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304521EXPORT_SYMBOL(adm_store_cal_data);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304522
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304523/**
4524 * adm_send_compressed_device_mute -
4525 * command to send mute for compressed device
4526 *
4527 * @port_id: Port ID number
4528 * @copp_idx: copp index assigned
4529 * @mute_on: flag to indicate mute or unmute
4530 *
4531 * Returns 0 on success or error on failure
4532 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304533int adm_send_compressed_device_mute(int port_id, int copp_idx, bool mute_on)
4534{
4535 struct adm_set_compressed_device_mute mute_params;
4536 int ret = 0;
4537 int port_idx;
4538
4539 pr_debug("%s port_id: 0x%x, copp_idx %d, mute_on: %d\n",
4540 __func__, port_id, copp_idx, mute_on);
4541 port_id = afe_convert_virtual_to_portid(port_id);
4542 port_idx = adm_validate_and_get_port_index(port_id);
4543 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
4544 pr_err("%s: Invalid port_id %#x copp_idx %d\n",
4545 __func__, port_id, copp_idx);
4546 ret = -EINVAL;
4547 goto end;
4548 }
4549
4550 mute_params.command.hdr.hdr_field =
4551 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4552 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4553 mute_params.command.hdr.pkt_size =
4554 sizeof(struct adm_set_compressed_device_mute);
4555 mute_params.command.hdr.src_svc = APR_SVC_ADM;
4556 mute_params.command.hdr.src_domain = APR_DOMAIN_APPS;
4557 mute_params.command.hdr.src_port = port_id;
4558 mute_params.command.hdr.dest_svc = APR_SVC_ADM;
4559 mute_params.command.hdr.dest_domain = APR_DOMAIN_ADSP;
4560 mute_params.command.hdr.dest_port =
4561 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4562 mute_params.command.hdr.token = port_idx << 16 | copp_idx;
4563 mute_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4564 mute_params.command.payload_addr_lsw = 0;
4565 mute_params.command.payload_addr_msw = 0;
4566 mute_params.command.mem_map_handle = 0;
4567 mute_params.command.payload_size = sizeof(mute_params) -
4568 sizeof(mute_params.command);
4569 mute_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_MUTE;
4570 mute_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_MUTE;
4571 mute_params.params.param_size = mute_params.command.payload_size -
4572 sizeof(mute_params.params);
4573 mute_params.params.reserved = 0;
4574 mute_params.mute_on = mute_on;
4575
4576 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4577 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mute_params);
4578 if (ret < 0) {
4579 pr_err("%s: device mute for port %d copp %d failed, ret %d\n",
4580 __func__, port_id, copp_idx, ret);
4581 ret = -EINVAL;
4582 goto end;
4583 }
4584
4585 /* Wait for the callback */
4586 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4587 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4588 msecs_to_jiffies(TIMEOUT_MS));
4589 if (!ret) {
4590 pr_err("%s: send device mute for port %d copp %d failed\n",
4591 __func__, port_id, copp_idx);
4592 ret = -EINVAL;
4593 goto end;
4594 } else if (atomic_read(&this_adm.copp.stat
4595 [port_idx][copp_idx]) > 0) {
4596 pr_err("%s: DSP returned error[%s]\n",
4597 __func__, adsp_err_get_err_str(
4598 atomic_read(&this_adm.copp.stat
4599 [port_idx][copp_idx])));
4600 ret = adsp_err_get_lnx_err_code(
4601 atomic_read(&this_adm.copp.stat
4602 [port_idx][copp_idx]));
4603 goto end;
4604 }
4605 ret = 0;
4606end:
4607 return ret;
4608}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304609EXPORT_SYMBOL(adm_send_compressed_device_mute);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304610
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304611/**
4612 * adm_send_compressed_device_latency -
4613 * command to send latency for compressed device
4614 *
4615 * @port_id: Port ID number
4616 * @copp_idx: copp index assigned
4617 * @latency: latency value to pass
4618 *
4619 * Returns 0 on success or error on failure
4620 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304621int adm_send_compressed_device_latency(int port_id, int copp_idx, int latency)
4622{
4623 struct adm_set_compressed_device_latency latency_params;
4624 int port_idx;
4625 int ret = 0;
4626
4627 pr_debug("%s port_id: 0x%x, copp_idx %d latency: %d\n", __func__,
4628 port_id, copp_idx, latency);
4629 port_id = afe_convert_virtual_to_portid(port_id);
4630 port_idx = adm_validate_and_get_port_index(port_id);
4631 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
4632 pr_err("%s: Invalid port_id %#x copp_idx %d\n",
4633 __func__, port_id, copp_idx);
4634 ret = -EINVAL;
4635 goto end;
4636 }
4637
4638 latency_params.command.hdr.hdr_field =
4639 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4640 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4641 latency_params.command.hdr.pkt_size =
4642 sizeof(struct adm_set_compressed_device_latency);
4643 latency_params.command.hdr.src_svc = APR_SVC_ADM;
4644 latency_params.command.hdr.src_domain = APR_DOMAIN_APPS;
4645 latency_params.command.hdr.src_port = port_id;
4646 latency_params.command.hdr.dest_svc = APR_SVC_ADM;
4647 latency_params.command.hdr.dest_domain = APR_DOMAIN_ADSP;
4648 latency_params.command.hdr.dest_port =
4649 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4650 latency_params.command.hdr.token = port_idx << 16 | copp_idx;
4651 latency_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4652 latency_params.command.payload_addr_lsw = 0;
4653 latency_params.command.payload_addr_msw = 0;
4654 latency_params.command.mem_map_handle = 0;
4655 latency_params.command.payload_size = sizeof(latency_params) -
4656 sizeof(latency_params.command);
4657 latency_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_LATENCY;
4658 latency_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_LATENCY;
4659 latency_params.params.param_size = latency_params.command.payload_size -
4660 sizeof(latency_params.params);
4661 latency_params.params.reserved = 0;
4662 latency_params.latency = latency;
4663
4664 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4665 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&latency_params);
4666 if (ret < 0) {
4667 pr_err("%s: send device latency err %d for port %d copp %d\n",
4668 __func__, port_id, copp_idx, ret);
4669 ret = -EINVAL;
4670 goto end;
4671 }
4672
4673 /* Wait for the callback */
4674 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4675 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4676 msecs_to_jiffies(TIMEOUT_MS));
4677 if (!ret) {
4678 pr_err("%s: send device latency for port %d failed\n", __func__,
4679 port_id);
4680 ret = -EINVAL;
4681 goto end;
4682 } else if (atomic_read(&this_adm.copp.stat
4683 [port_idx][copp_idx]) > 0) {
4684 pr_err("%s: DSP returned error[%s]\n",
4685 __func__, adsp_err_get_err_str(
4686 atomic_read(&this_adm.copp.stat
4687 [port_idx][copp_idx])));
4688 ret = adsp_err_get_lnx_err_code(
4689 atomic_read(&this_adm.copp.stat
4690 [port_idx][copp_idx]));
4691 goto end;
4692 }
4693 ret = 0;
4694end:
4695 return ret;
4696}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304697EXPORT_SYMBOL(adm_send_compressed_device_latency);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304698
4699/**
4700 * adm_swap_speaker_channels
4701 *
4702 * Receives port_id, copp_idx, sample rate, spk_swap and
4703 * send MFC command to swap speaker channel.
4704 * Return zero on success. On failure returns nonzero.
4705 *
4706 * port_id - Passed value, port_id for which channels swap is wanted
4707 * copp_idx - Passed value, copp_idx for which channels swap is wanted
4708 * sample_rate - Passed value, sample rate used by app type config
4709 * spk_swap - Passed value, spk_swap for check if swap flag is set
4710 */
4711int adm_swap_speaker_channels(int port_id, int copp_idx,
4712 int sample_rate, bool spk_swap)
4713{
4714 struct audproc_mfc_output_media_fmt mfc_cfg;
4715 uint16_t num_channels;
4716 int port_idx;
4717 int ret = 0;
4718
4719 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
4720 __func__, port_id, copp_idx);
4721 port_id = q6audio_convert_virtual_to_portid(port_id);
4722 port_idx = adm_validate_and_get_port_index(port_id);
4723 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
4724 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4725 ret = -EINVAL;
4726 goto done;
4727 }
4728
4729 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4730 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4731 ret = -EINVAL;
4732 goto done;
4733 }
4734
4735 num_channels = atomic_read(
4736 &this_adm.copp.channels[port_idx][copp_idx]);
4737 if (num_channels != 2) {
4738 pr_debug("%s: Invalid number of channels: %d\n",
4739 __func__, num_channels);
4740 ret = -EINVAL;
4741 goto done;
4742 }
4743
4744 memset(&mfc_cfg, 0, sizeof(mfc_cfg));
4745 mfc_cfg.params.hdr.hdr_field =
4746 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4747 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4748 mfc_cfg.params.hdr.pkt_size =
4749 sizeof(mfc_cfg);
4750 mfc_cfg.params.hdr.src_svc = APR_SVC_ADM;
4751 mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS;
4752 mfc_cfg.params.hdr.src_port = port_id;
4753 mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM;
4754 mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4755 mfc_cfg.params.hdr.dest_port =
4756 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4757 mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx;
4758 mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4759 mfc_cfg.params.payload_addr_lsw = 0;
4760 mfc_cfg.params.payload_addr_msw = 0;
4761 mfc_cfg.params.mem_map_handle = 0;
4762 mfc_cfg.params.payload_size = sizeof(mfc_cfg) -
4763 sizeof(mfc_cfg.params);
4764 mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC;
4765 mfc_cfg.data.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
4766 mfc_cfg.data.param_size = mfc_cfg.params.payload_size -
4767 sizeof(mfc_cfg.data);
4768 mfc_cfg.data.reserved = 0;
4769 mfc_cfg.sampling_rate = sample_rate;
4770 mfc_cfg.bits_per_sample =
4771 atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]);
4772 mfc_cfg.num_channels = num_channels;
4773
4774 /* Currently applying speaker swap for only 2 channel use case */
4775 if (spk_swap) {
4776 mfc_cfg.channel_type[0] =
4777 (uint16_t) PCM_CHANNEL_FR;
4778 mfc_cfg.channel_type[1] =
4779 (uint16_t) PCM_CHANNEL_FL;
4780 } else {
4781 mfc_cfg.channel_type[0] =
4782 (uint16_t) PCM_CHANNEL_FL;
4783 mfc_cfg.channel_type[1] =
4784 (uint16_t) PCM_CHANNEL_FR;
4785 }
4786
4787 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4788 pr_debug("%s: mfc config: port_idx %d copp_idx %d copp SR %d copp BW %d copp chan %d\n",
4789 __func__, port_idx, copp_idx, mfc_cfg.sampling_rate,
4790 mfc_cfg.bits_per_sample, mfc_cfg.num_channels);
4791
4792 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg);
4793 if (ret < 0) {
4794 pr_err("%s: port_id: for[0x%x] failed %d\n",
4795 __func__, port_id, ret);
4796 goto done;
4797 }
4798 /* Wait for the callback with copp id */
4799 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4800 atomic_read(&this_adm.copp.stat
4801 [port_idx][copp_idx]) >= 0,
4802 msecs_to_jiffies(TIMEOUT_MS));
4803 if (!ret) {
4804 pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n",
4805 __func__, port_id);
4806 ret = -ETIMEDOUT;
4807 goto done;
4808 }
4809
4810 if (atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) > 0) {
4811 pr_err("%s: DSP returned error[%s]\n",
4812 __func__, adsp_err_get_err_str(
4813 atomic_read(&this_adm.copp.stat
4814 [port_idx][copp_idx])));
4815 ret = adsp_err_get_lnx_err_code(
4816 atomic_read(&this_adm.copp.stat
4817 [port_idx][copp_idx]));
4818 goto done;
4819 }
4820
4821 pr_debug("%s: mfc_cfg Set params returned success", __func__);
4822 ret = 0;
4823
4824done:
4825 return ret;
4826}
4827EXPORT_SYMBOL(adm_swap_speaker_channels);
4828
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304829/**
4830 * adm_set_sound_focus -
4831 * Update sound focus info
4832 *
4833 * @port_id: Port ID number
4834 * @copp_idx: copp index assigned
4835 * @soundFocusData: sound focus data to pass
4836 *
4837 * Returns 0 on success or error on failure
4838 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304839int adm_set_sound_focus(int port_id, int copp_idx,
4840 struct sound_focus_param soundFocusData)
4841{
4842 struct adm_set_fluence_soundfocus_param soundfocus_params;
4843 int sz = 0;
4844 int ret = 0;
4845 int port_idx;
4846 int i;
4847
4848 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
4849 __func__, port_id, copp_idx);
4850
4851 port_id = afe_convert_virtual_to_portid(port_id);
4852 port_idx = adm_validate_and_get_port_index(port_id);
4853 if (port_idx < 0) {
4854 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4855
4856 ret = -EINVAL;
4857 goto done;
4858 }
4859
4860 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4861 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4862
4863 ret = -EINVAL;
4864 goto done;
4865 }
4866
4867 sz = sizeof(struct adm_set_fluence_soundfocus_param);
4868 soundfocus_params.params.hdr.hdr_field =
4869 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
4870 APR_PKT_VER);
4871 soundfocus_params.params.hdr.pkt_size = sz;
4872 soundfocus_params.params.hdr.src_svc = APR_SVC_ADM;
4873 soundfocus_params.params.hdr.src_domain = APR_DOMAIN_APPS;
4874 soundfocus_params.params.hdr.src_port = port_id;
4875 soundfocus_params.params.hdr.dest_svc = APR_SVC_ADM;
4876 soundfocus_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4877 soundfocus_params.params.hdr.dest_port =
4878 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4879 soundfocus_params.params.hdr.token = port_idx << 16 |
4880 ADM_CLIENT_ID_SOURCE_TRACKING << 8 | copp_idx;
4881 soundfocus_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4882 soundfocus_params.params.payload_addr_lsw = 0;
4883 soundfocus_params.params.payload_addr_msw = 0;
4884 soundfocus_params.params.mem_map_handle = 0;
4885 soundfocus_params.params.payload_size = sizeof(soundfocus_params) -
4886 sizeof(soundfocus_params.params);
4887 soundfocus_params.data.module_id = VOICEPROC_MODULE_ID_GENERIC_TX;
4888 soundfocus_params.data.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS;
4889 soundfocus_params.data.param_size =
4890 soundfocus_params.params.payload_size -
4891 sizeof(soundfocus_params.data);
4892 soundfocus_params.data.reserved = 0;
4893
4894 memset(&(soundfocus_params.soundfocus_data), 0xFF,
4895 sizeof(struct adm_param_fluence_soundfocus_t));
4896 for (i = 0; i < MAX_SECTORS; i++) {
4897 soundfocus_params.soundfocus_data.start_angles[i] =
4898 soundFocusData.start_angle[i];
4899 soundfocus_params.soundfocus_data.enables[i] =
4900 soundFocusData.enable[i];
4901 pr_debug("%s: start_angle[%d] = %d\n",
4902 __func__, i, soundFocusData.start_angle[i]);
4903 pr_debug("%s: enable[%d] = %d\n",
4904 __func__, i, soundFocusData.enable[i]);
4905 }
4906 soundfocus_params.soundfocus_data.gain_step =
4907 soundFocusData.gain_step;
4908 pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step);
4909
4910 soundfocus_params.soundfocus_data.reserved = 0;
4911
4912 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4913 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&soundfocus_params);
4914 if (ret < 0) {
4915 pr_err("%s: Set params failed\n", __func__);
4916
4917 ret = -EINVAL;
4918 goto done;
4919 }
4920 /* Wait for the callback */
4921 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4922 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4923 msecs_to_jiffies(TIMEOUT_MS));
4924 if (!ret) {
4925 pr_err("%s: Set params timed out\n", __func__);
4926
4927 ret = -EINVAL;
4928 goto done;
4929 }
4930
4931 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
4932 pr_err("%s - set params returned error [%s]\n",
4933 __func__, adsp_err_get_err_str(
4934 this_adm.sourceTrackingData.apr_cmd_status));
4935
4936 ret = adsp_err_get_lnx_err_code(
4937 this_adm.sourceTrackingData.apr_cmd_status);
4938 goto done;
4939 }
4940
4941 ret = 0;
4942
4943done:
4944 pr_debug("%s: Exit, ret=%d\n", __func__, ret);
4945
4946 return ret;
4947}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304948EXPORT_SYMBOL(adm_set_sound_focus);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304949
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304950/**
4951 * adm_get_sound_focus -
4952 * Retrieve sound focus info
4953 *
4954 * @port_id: Port ID number
4955 * @copp_idx: copp index assigned
4956 * @soundFocusData: pointer for sound focus data to be updated with
4957 *
4958 * Returns 0 on success or error on failure
4959 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304960int adm_get_sound_focus(int port_id, int copp_idx,
4961 struct sound_focus_param *soundFocusData)
4962{
4963 int ret = 0, i;
4964 char *params_value;
4965 uint32_t param_payload_len = sizeof(struct adm_param_data_v5) +
4966 sizeof(struct adm_param_fluence_soundfocus_t);
4967 struct adm_param_fluence_soundfocus_t *soundfocus_params;
4968
4969 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
4970 __func__, port_id, copp_idx);
4971
4972 params_value = kzalloc(param_payload_len, GFP_KERNEL);
4973 if (!params_value) {
4974 ret = -ENOMEM;
4975 goto done;
4976 }
4977 ret = adm_get_params_v2(port_id, copp_idx,
4978 VOICEPROC_MODULE_ID_GENERIC_TX,
4979 VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS,
4980 param_payload_len,
4981 params_value,
4982 ADM_CLIENT_ID_SOURCE_TRACKING);
4983 if (ret) {
4984 pr_err("%s: get parameters failed ret:%d\n", __func__, ret);
4985
4986 kfree(params_value);
4987 ret = -EINVAL;
4988 goto done;
4989 }
4990
4991 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
4992 pr_err("%s - get params returned error [%s]\n",
4993 __func__, adsp_err_get_err_str(
4994 this_adm.sourceTrackingData.apr_cmd_status));
4995
4996 kfree(params_value);
4997 ret = adsp_err_get_lnx_err_code(
4998 this_adm.sourceTrackingData.apr_cmd_status);
4999 goto done;
5000 }
5001
5002 soundfocus_params = (struct adm_param_fluence_soundfocus_t *)
5003 params_value;
5004 for (i = 0; i < MAX_SECTORS; i++) {
5005 soundFocusData->start_angle[i] =
5006 soundfocus_params->start_angles[i];
5007 soundFocusData->enable[i] = soundfocus_params->enables[i];
5008 pr_debug("%s: start_angle[%d] = %d\n",
5009 __func__, i, soundFocusData->start_angle[i]);
5010 pr_debug("%s: enable[%d] = %d\n",
5011 __func__, i, soundFocusData->enable[i]);
5012 }
5013 soundFocusData->gain_step = soundfocus_params->gain_step;
5014 pr_debug("%s: gain_step = %d\n", __func__, soundFocusData->gain_step);
5015
5016 kfree(params_value);
5017
5018done:
5019 pr_debug("%s: Exit, ret = %d\n", __func__, ret);
5020
5021 return ret;
5022}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305023EXPORT_SYMBOL(adm_get_sound_focus);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305024
5025static int adm_source_tracking_alloc_map_memory(void)
5026{
5027 int ret;
5028
5029 pr_debug("%s: Enter\n", __func__);
5030
Banajit Goswami08bb7362017-11-03 22:48:23 -07005031 ret = msm_audio_ion_alloc(&this_adm.sourceTrackingData.dma_buf,
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305032 AUD_PROC_BLOCK_SIZE,
5033 &this_adm.sourceTrackingData.memmap.paddr,
5034 &this_adm.sourceTrackingData.memmap.size,
5035 &this_adm.sourceTrackingData.memmap.kvaddr);
5036 if (ret) {
5037 pr_err("%s: failed to allocate memory\n", __func__);
5038
5039 ret = -EINVAL;
5040 goto done;
5041 }
5042
5043 atomic_set(&this_adm.mem_map_index, ADM_MEM_MAP_INDEX_SOURCE_TRACKING);
5044 ret = adm_memory_map_regions(&this_adm.sourceTrackingData.memmap.paddr,
5045 0,
5046 (uint32_t *)&this_adm.sourceTrackingData.memmap.size,
5047 1);
5048 if (ret < 0) {
5049 pr_err("%s: failed to map memory, paddr = 0x%pK, size = %d\n",
5050 __func__,
5051 (void *)this_adm.sourceTrackingData.memmap.paddr,
5052 (uint32_t)this_adm.sourceTrackingData.memmap.size);
5053
Banajit Goswami08bb7362017-11-03 22:48:23 -07005054 msm_audio_ion_free(this_adm.sourceTrackingData.dma_buf);
5055 this_adm.sourceTrackingData.dma_buf = NULL;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305056 this_adm.sourceTrackingData.memmap.size = 0;
5057 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
5058 this_adm.sourceTrackingData.memmap.paddr = 0;
5059 this_adm.sourceTrackingData.apr_cmd_status = -1;
5060 atomic_set(&this_adm.mem_map_handles
5061 [ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
5062
5063 ret = -EINVAL;
5064 goto done;
5065 }
5066 ret = 0;
5067 pr_debug("%s: paddr = 0x%pK, size = %d, mem_map_handle = 0x%x\n",
5068 __func__, (void *)this_adm.sourceTrackingData.memmap.paddr,
5069 (uint32_t)this_adm.sourceTrackingData.memmap.size,
5070 atomic_read(&this_adm.mem_map_handles
5071 [ADM_MEM_MAP_INDEX_SOURCE_TRACKING]));
5072
5073done:
5074 pr_debug("%s: Exit, ret = %d\n", __func__, ret);
5075
5076 return ret;
5077}
5078
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305079/**
5080 * adm_get_source_tracking -
5081 * Retrieve source tracking info
5082 *
5083 * @port_id: Port ID number
5084 * @copp_idx: copp index assigned
5085 * @sourceTrackingData: pointer for source track data to be updated with
5086 *
5087 * Returns 0 on success or error on failure
5088 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305089int adm_get_source_tracking(int port_id, int copp_idx,
5090 struct source_tracking_param *sourceTrackingData)
5091{
5092 struct adm_cmd_get_pp_params_v5 admp;
5093 int p_idx, ret = 0, i;
5094 struct adm_param_fluence_sourcetracking_t *source_tracking_params;
5095
5096 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
5097 __func__, port_id, copp_idx);
5098
5099 if (!this_adm.sourceTrackingData.memmap.paddr) {
5100 /* Allocate and map shared memory for out of band usage */
5101 ret = adm_source_tracking_alloc_map_memory();
5102 if (ret != 0) {
5103 ret = -EINVAL;
5104 goto done;
5105 }
5106 }
5107
5108 port_id = afe_convert_virtual_to_portid(port_id);
5109 p_idx = adm_validate_and_get_port_index(port_id);
5110 if (p_idx < 0) {
5111 pr_err("%s - invalid port index %i, port id %i, copp idx %i\n",
5112 __func__, p_idx, port_id, copp_idx);
5113
5114 ret = -EINVAL;
5115 goto done;
5116 }
5117
5118 admp.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
5119 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
5120 admp.hdr.pkt_size = sizeof(admp);
5121 admp.hdr.src_svc = APR_SVC_ADM;
5122 admp.hdr.src_domain = APR_DOMAIN_APPS;
5123 admp.hdr.src_port = port_id;
5124 admp.hdr.dest_svc = APR_SVC_ADM;
5125 admp.hdr.dest_domain = APR_DOMAIN_ADSP;
5126 admp.hdr.dest_port = atomic_read(&this_adm.copp.id[p_idx][copp_idx]);
5127 admp.hdr.token = p_idx << 16 | ADM_CLIENT_ID_SOURCE_TRACKING << 8 |
5128 copp_idx;
5129 admp.hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5;
5130 admp.data_payload_addr_lsw =
5131 lower_32_bits(this_adm.sourceTrackingData.memmap.paddr);
5132 admp.data_payload_addr_msw =
5133 msm_audio_populate_upper_32_bits(
5134 this_adm.sourceTrackingData.memmap.paddr);
5135 admp.mem_map_handle = atomic_read(&this_adm.mem_map_handles[
5136 ADM_MEM_MAP_INDEX_SOURCE_TRACKING]);
5137 admp.module_id = VOICEPROC_MODULE_ID_GENERIC_TX;
5138 admp.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOURCETRACKING;
5139 admp.param_max_size = sizeof(struct adm_param_fluence_sourcetracking_t)
5140 + sizeof(struct adm_param_data_v5);
5141 admp.reserved = 0;
5142
5143 atomic_set(&this_adm.copp.stat[p_idx][copp_idx], -1);
5144
5145 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&admp);
5146 if (ret < 0) {
5147 pr_err("%s - failed to get Source Tracking Params\n",
5148 __func__);
5149
5150 ret = -EINVAL;
5151 goto done;
5152 }
5153 ret = wait_event_timeout(this_adm.copp.wait[p_idx][copp_idx],
5154 atomic_read(&this_adm.copp.stat[p_idx][copp_idx]) >= 0,
5155 msecs_to_jiffies(TIMEOUT_MS));
5156 if (!ret) {
5157 pr_err("%s - get params timed out\n", __func__);
5158
5159 ret = -EINVAL;
5160 goto done;
5161 } else if (atomic_read(&this_adm.copp.stat
5162 [p_idx][copp_idx]) > 0) {
5163 pr_err("%s: DSP returned error[%s]\n",
5164 __func__, adsp_err_get_err_str(
5165 atomic_read(&this_adm.copp.stat
5166 [p_idx][copp_idx])));
5167 ret = adsp_err_get_lnx_err_code(
5168 atomic_read(&this_adm.copp.stat
5169 [p_idx][copp_idx]));
5170 goto done;
5171 }
5172
5173 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
5174 pr_err("%s - get params returned error [%s]\n",
5175 __func__, adsp_err_get_err_str(
5176 this_adm.sourceTrackingData.apr_cmd_status));
5177
5178 ret = adsp_err_get_lnx_err_code(
5179 this_adm.sourceTrackingData.apr_cmd_status);
5180 goto done;
5181 }
5182
5183 source_tracking_params = (struct adm_param_fluence_sourcetracking_t *)
5184 (this_adm.sourceTrackingData.memmap.kvaddr +
5185 sizeof(struct adm_param_data_v5));
5186 for (i = 0; i < MAX_SECTORS; i++) {
5187 sourceTrackingData->vad[i] = source_tracking_params->vad[i];
5188 pr_debug("%s: vad[%d] = %d\n",
5189 __func__, i, sourceTrackingData->vad[i]);
5190 }
5191 sourceTrackingData->doa_speech = source_tracking_params->doa_speech;
5192 pr_debug("%s: doa_speech = %d\n",
5193 __func__, sourceTrackingData->doa_speech);
5194
5195 for (i = 0; i < MAX_NOISE_SOURCE_INDICATORS; i++) {
5196 sourceTrackingData->doa_noise[i] =
5197 source_tracking_params->doa_noise[i];
5198 pr_debug("%s: doa_noise[%d] = %d\n",
5199 __func__, i, sourceTrackingData->doa_noise[i]);
5200 }
5201 for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) {
5202 sourceTrackingData->polar_activity[i] =
5203 source_tracking_params->polar_activity[i];
5204 pr_debug("%s: polar_activity[%d] = %d\n",
5205 __func__, i, sourceTrackingData->polar_activity[i]);
5206 }
5207
5208 ret = 0;
5209
5210done:
5211 pr_debug("%s: Exit, ret=%d\n", __func__, ret);
5212
5213 return ret;
5214}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305215EXPORT_SYMBOL(adm_get_source_tracking);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305216
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305217int __init adm_init(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305218{
5219 int i = 0, j;
5220
5221 this_adm.apr = NULL;
5222 this_adm.ec_ref_rx = -1;
5223 this_adm.num_ec_ref_rx_chans = 0;
5224 this_adm.ec_ref_rx_bit_width = 0;
5225 this_adm.ec_ref_rx_sampling_rate = 0;
5226 atomic_set(&this_adm.matrix_map_stat, 0);
5227 init_waitqueue_head(&this_adm.matrix_map_wait);
5228 atomic_set(&this_adm.adm_stat, 0);
5229 init_waitqueue_head(&this_adm.adm_wait);
5230
5231 for (i = 0; i < AFE_MAX_PORTS; i++) {
5232 for (j = 0; j < MAX_COPPS_PER_PORT; j++) {
5233 atomic_set(&this_adm.copp.id[i][j], RESET_COPP_ID);
5234 atomic_set(&this_adm.copp.cnt[i][j], 0);
5235 atomic_set(&this_adm.copp.topology[i][j], 0);
5236 atomic_set(&this_adm.copp.mode[i][j], 0);
5237 atomic_set(&this_adm.copp.stat[i][j], 0);
5238 atomic_set(&this_adm.copp.rate[i][j], 0);
5239 atomic_set(&this_adm.copp.channels[i][j], 0);
5240 atomic_set(&this_adm.copp.bit_width[i][j], 0);
5241 atomic_set(&this_adm.copp.app_type[i][j], 0);
5242 atomic_set(&this_adm.copp.acdb_id[i][j], 0);
5243 init_waitqueue_head(&this_adm.copp.wait[i][j]);
5244 atomic_set(&this_adm.copp.adm_delay_stat[i][j], 0);
5245 init_waitqueue_head(
5246 &this_adm.copp.adm_delay_wait[i][j]);
5247 atomic_set(&this_adm.copp.topology[i][j], 0);
5248 this_adm.copp.adm_delay[i][j] = 0;
5249 this_adm.copp.adm_status[i][j] =
5250 ADM_STATUS_CALIBRATION_REQUIRED;
5251 }
5252 }
5253
5254 if (adm_init_cal_data())
5255 pr_err("%s: could not init cal data!\n", __func__);
5256
Banajit Goswami08bb7362017-11-03 22:48:23 -07005257 this_adm.sourceTrackingData.dma_buf = NULL;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305258 this_adm.sourceTrackingData.memmap.size = 0;
5259 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
5260 this_adm.sourceTrackingData.memmap.paddr = 0;
5261 this_adm.sourceTrackingData.apr_cmd_status = -1;
5262 atomic_set(&this_adm.mem_map_handles[ADM_MEM_MAP_INDEX_SOURCE_TRACKING],
5263 0);
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305264 mutex_init(&dts_srs_lock);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305265
5266 return 0;
5267}
5268
Asish Bhattacharya5faacb32017-12-04 17:23:15 +05305269void adm_exit(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305270{
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305271 mutex_destroy(&dts_srs_lock);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305272 adm_delete_cal_data();
5273}