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