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