blob: 3877b1b9abc275b2998614203b6c1045d20fb8c5 [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>
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +020026#include <dsp/q6core.h>
Laxminath Kasam605b42f2017-08-01 22:02:15 +053027#include <dsp/audio_cal_utils.h>
28#include <ipc/apr.h>
29#include "adsp_err.h"
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053030
31#define TIMEOUT_MS 1000
32
33#define RESET_COPP_ID 99
34#define INVALID_COPP_ID 0xFF
35/* Used for inband payload copy, max size is 4k */
36/* 2 is to account for module & param ID in payload */
37#define ADM_GET_PARAMETER_LENGTH (4096 - APR_HDR_SIZE - 2 * sizeof(uint32_t))
38
39#define ULL_SUPPORTED_BITS_PER_SAMPLE 16
40#define ULL_SUPPORTED_SAMPLE_RATE 48000
41
42#ifndef CONFIG_DOLBY_DAP
43#undef DOLBY_ADM_COPP_TOPOLOGY_ID
44#define DOLBY_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFE
45#endif
46
47#ifndef CONFIG_DOLBY_DS2
48#undef DS2_ADM_COPP_TOPOLOGY_ID
49#define DS2_ADM_COPP_TOPOLOGY_ID 0xFFFFFFFF
50#endif
51
52/* ENUM for adm_status */
53enum adm_cal_status {
54 ADM_STATUS_CALIBRATION_REQUIRED = 0,
55 ADM_STATUS_MAX,
56};
57
58struct adm_copp {
59
60 atomic_t id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
61 atomic_t cnt[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
62 atomic_t topology[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
63 atomic_t mode[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
64 atomic_t stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
65 atomic_t rate[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
66 atomic_t bit_width[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
67 atomic_t channels[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
68 atomic_t app_type[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
69 atomic_t acdb_id[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +053070 atomic_t session_type[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053071 wait_queue_head_t wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
72 wait_queue_head_t adm_delay_wait[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
73 atomic_t adm_delay_stat[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
74 uint32_t adm_delay[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
75 unsigned long adm_status[AFE_MAX_PORTS][MAX_COPPS_PER_PORT];
76};
77
78struct source_tracking_data {
79 struct ion_client *ion_client;
80 struct ion_handle *ion_handle;
81 struct param_outband memmap;
82 int apr_cmd_status;
83};
84
85struct adm_ctl {
86 void *apr;
87
88 struct adm_copp copp;
89
90 atomic_t matrix_map_stat;
91 wait_queue_head_t matrix_map_wait;
92
93 atomic_t adm_stat;
94 wait_queue_head_t adm_wait;
95
96 struct cal_type_data *cal_data[ADM_MAX_CAL_TYPES];
97
98 atomic_t mem_map_handles[ADM_MEM_MAP_INDEX_MAX];
99 atomic_t mem_map_index;
100
101 struct param_outband outband_memmap;
102 struct source_tracking_data sourceTrackingData;
103
104 int set_custom_topology;
105 int ec_ref_rx;
106 int num_ec_ref_rx_chans;
107 int ec_ref_rx_bit_width;
108 int ec_ref_rx_sampling_rate;
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +0200109
110 int native_mode;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530111};
112
113static struct adm_ctl this_adm;
114
115struct adm_multi_ch_map {
116 bool set_channel_map;
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +0200117 char channel_mapping[PCM_FORMAT_MAX_NUM_CHANNEL_V8];
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530118};
119
120#define ADM_MCH_MAP_IDX_PLAYBACK 0
121#define ADM_MCH_MAP_IDX_REC 1
122static struct adm_multi_ch_map multi_ch_maps[2] = {
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +0200123 { false,
124 {0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0}
128 },
129 { false,
130 {0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 0, 0, 0, 0, 0, 0,
133 0, 0, 0, 0, 0, 0, 0, 0}
134 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530135};
136
Rohit kumar5d860f42019-02-01 18:01:12 +0530137static struct adm_multi_ch_map port_channel_map[AFE_MAX_PORTS];
138
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530139static int adm_get_parameters[MAX_COPPS_PER_PORT * ADM_GET_PARAMETER_LENGTH];
140static int adm_module_topo_list[
141 MAX_COPPS_PER_PORT * ADM_GET_TOPO_MODULE_LIST_LENGTH];
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530142static struct mutex dts_srs_lock;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530143
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530144void msm_dts_srs_acquire_lock(void)
145{
146 mutex_lock(&dts_srs_lock);
147}
148
149void msm_dts_srs_release_lock(void)
150{
151 mutex_unlock(&dts_srs_lock);
152}
153
154/**
155 * adm_validate_and_get_port_index -
156 * validate given port id
157 *
158 * @port_id: Port ID number
159 *
160 * Returns valid index on success or error on failure
161 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530162int adm_validate_and_get_port_index(int port_id)
163{
164 int index;
165 int ret;
166
167 ret = q6audio_validate_port(port_id);
168 if (ret < 0) {
169 pr_err("%s: port validation failed id 0x%x ret %d\n",
170 __func__, port_id, ret);
171 return -EINVAL;
172 }
173
174 index = afe_get_port_index(port_id);
175 if (index < 0 || index >= AFE_MAX_PORTS) {
176 pr_err("%s: Invalid port idx %d port_id 0x%x\n",
177 __func__, index,
178 port_id);
179 return -EINVAL;
180 }
181 pr_debug("%s: port_idx- %d\n", __func__, index);
182 return index;
183}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530184EXPORT_SYMBOL(adm_validate_and_get_port_index);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530185
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530186/**
187 * adm_get_default_copp_idx -
188 * retrieve default copp_idx for given port
189 *
190 * @port_id: Port ID number
191 *
192 * Returns valid value on success or error on failure
193 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530194int adm_get_default_copp_idx(int port_id)
195{
196 int port_idx = adm_validate_and_get_port_index(port_id), idx;
197
198 if (port_idx < 0) {
199 pr_err("%s: Invalid port id: 0x%x", __func__, port_id);
200 return -EINVAL;
201 }
202 pr_debug("%s: port_idx:%d\n", __func__, port_idx);
203 for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) {
204 if (atomic_read(&this_adm.copp.id[port_idx][idx]) !=
205 RESET_COPP_ID)
206 return idx;
207 }
208 return -EINVAL;
209}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530210EXPORT_SYMBOL(adm_get_default_copp_idx);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530211
212int adm_get_topology_for_port_from_copp_id(int port_id, int copp_id)
213{
214 int port_idx = adm_validate_and_get_port_index(port_id), idx;
215
216 if (port_idx < 0) {
217 pr_err("%s: Invalid port id: 0x%x", __func__, port_id);
218 return 0;
219 }
220 for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++)
221 if (atomic_read(&this_adm.copp.id[port_idx][idx]) == copp_id)
222 return atomic_read(&this_adm.copp.topology[port_idx]
223 [idx]);
224 pr_err("%s: Invalid copp_id %d port_id 0x%x\n",
225 __func__, copp_id, port_id);
226 return 0;
227}
228
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530229/**
230 * adm_get_topology_for_port_copp_idx -
231 * retrieve topology of given port/copp_idx
232 *
233 * @port_id: Port ID number
234 * @copp_idx: copp index of ADM copp
235 *
236 * Returns valid value on success or 0 on failure
237 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530238int adm_get_topology_for_port_copp_idx(int port_id, int copp_idx)
239{
240 int port_idx = adm_validate_and_get_port_index(port_id);
241
242 if (port_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
243 pr_err("%s: Invalid port: 0x%x copp id: 0x%x",
244 __func__, port_id, copp_idx);
245 return 0;
246 }
247 return atomic_read(&this_adm.copp.topology[port_idx][copp_idx]);
248}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530249EXPORT_SYMBOL(adm_get_topology_for_port_copp_idx);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530250
251int adm_get_indexes_from_copp_id(int copp_id, int *copp_idx, int *port_idx)
252{
253 int p_idx, c_idx;
254
255 for (p_idx = 0; p_idx < AFE_MAX_PORTS; p_idx++) {
256 for (c_idx = 0; c_idx < MAX_COPPS_PER_PORT; c_idx++) {
257 if (atomic_read(&this_adm.copp.id[p_idx][c_idx])
258 == copp_id) {
259 if (copp_idx != NULL)
260 *copp_idx = c_idx;
261 if (port_idx != NULL)
262 *port_idx = p_idx;
263 return 0;
264 }
265 }
266 }
267 return -EINVAL;
268}
269
270static int adm_get_copp_id(int port_idx, int copp_idx)
271{
272 pr_debug("%s: port_idx:%d copp_idx:%d\n", __func__, port_idx, copp_idx);
273
274 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
275 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
276 return -EINVAL;
277 }
278 return atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
279}
280
281static int adm_get_idx_if_copp_exists(int port_idx, int topology, int mode,
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +0530282 int rate, int bit_width, int app_type,
283 int session_type)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530284{
285 int idx;
286
287 pr_debug("%s: port_idx-%d, topology-0x%x, mode-%d, rate-%d, bit_width-%d\n",
288 __func__, port_idx, topology, mode, rate, bit_width);
289
290 for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++)
291 if ((topology ==
292 atomic_read(&this_adm.copp.topology[port_idx][idx])) &&
293 (mode == atomic_read(&this_adm.copp.mode[port_idx][idx])) &&
294 (rate == atomic_read(&this_adm.copp.rate[port_idx][idx])) &&
295 (bit_width ==
296 atomic_read(&this_adm.copp.bit_width[port_idx][idx])) &&
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +0530297 (session_type ==
298 atomic_read(
299 &this_adm.copp.session_type[port_idx][idx])) &&
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530300 (app_type ==
301 atomic_read(&this_adm.copp.app_type[port_idx][idx])))
302 return idx;
303 return -EINVAL;
304}
305
306static int adm_get_next_available_copp(int port_idx)
307{
308 int idx;
309
310 pr_debug("%s:\n", __func__);
311 for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) {
312 pr_debug("%s: copp_id:0x%x port_idx:%d idx:%d\n", __func__,
313 atomic_read(&this_adm.copp.id[port_idx][idx]),
314 port_idx, idx);
315 if (atomic_read(&this_adm.copp.id[port_idx][idx]) ==
316 RESET_COPP_ID)
317 break;
318 }
319 return idx;
320}
321
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530322/**
323 * srs_trumedia_open -
324 * command to set SRS trumedia open
325 *
326 * @port_id: Port ID number
327 * @copp_idx: copp index of ADM copp
328 * @srs_tech_id: SRS tech index
329 * @srs_params: params pointer
330 *
331 * Returns 0 on success or error on failure
332 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530333int srs_trumedia_open(int port_id, int copp_idx, __s32 srs_tech_id,
334 void *srs_params)
335{
336 struct adm_cmd_set_pp_params_inband_v5 *adm_params = NULL;
337 struct adm_cmd_set_pp_params_v5 *adm_params_ = NULL;
338 __s32 sz = 0, param_id, module_id = SRS_TRUMEDIA_MODULE_ID, outband = 0;
339 int ret = 0, port_idx;
340
341 pr_debug("SRS - %s", __func__);
342
343 port_id = afe_convert_virtual_to_portid(port_id);
344 port_idx = adm_validate_and_get_port_index(port_id);
345 if (port_idx < 0) {
346 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
347 return -EINVAL;
348 }
349 switch (srs_tech_id) {
350 case SRS_ID_GLOBAL: {
351 struct srs_trumedia_params_GLOBAL *glb_params = NULL;
352
353 sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) +
354 sizeof(struct srs_trumedia_params_GLOBAL);
355 adm_params = kzalloc(sz, GFP_KERNEL);
356 if (!adm_params) {
357 pr_err("%s, adm params memory alloc failed\n",
358 __func__);
359 return -ENOMEM;
360 }
361 adm_params->payload_size =
362 sizeof(struct srs_trumedia_params_GLOBAL) +
363 sizeof(struct adm_param_data_v5);
364 param_id = SRS_TRUMEDIA_PARAMS;
365 adm_params->params.param_size =
366 sizeof(struct srs_trumedia_params_GLOBAL);
367 glb_params = (struct srs_trumedia_params_GLOBAL *)
368 ((u8 *)adm_params +
369 sizeof(struct adm_cmd_set_pp_params_inband_v5));
370 memcpy(glb_params, srs_params,
371 sizeof(struct srs_trumedia_params_GLOBAL));
372 break;
373 }
374 case SRS_ID_WOWHD: {
375 struct srs_trumedia_params_WOWHD *whd_params = NULL;
376
377 sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) +
378 sizeof(struct srs_trumedia_params_WOWHD);
379 adm_params = kzalloc(sz, GFP_KERNEL);
380 if (!adm_params) {
381 pr_err("%s, adm params memory alloc failed\n",
382 __func__);
383 return -ENOMEM;
384 }
385 adm_params->payload_size =
386 sizeof(struct srs_trumedia_params_WOWHD) +
387 sizeof(struct adm_param_data_v5);
388 param_id = SRS_TRUMEDIA_PARAMS_WOWHD;
389 adm_params->params.param_size =
390 sizeof(struct srs_trumedia_params_WOWHD);
391 whd_params = (struct srs_trumedia_params_WOWHD *)
392 ((u8 *)adm_params +
393 sizeof(struct adm_cmd_set_pp_params_inband_v5));
394 memcpy(whd_params, srs_params,
395 sizeof(struct srs_trumedia_params_WOWHD));
396 break;
397 }
398 case SRS_ID_CSHP: {
399 struct srs_trumedia_params_CSHP *chp_params = NULL;
400
401 sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) +
402 sizeof(struct srs_trumedia_params_CSHP);
403 adm_params = kzalloc(sz, GFP_KERNEL);
404 if (!adm_params) {
405 pr_err("%s, adm params memory alloc failed\n",
406 __func__);
407 return -ENOMEM;
408 }
409 adm_params->payload_size =
410 sizeof(struct srs_trumedia_params_CSHP) +
411 sizeof(struct adm_param_data_v5);
412 param_id = SRS_TRUMEDIA_PARAMS_CSHP;
413 adm_params->params.param_size =
414 sizeof(struct srs_trumedia_params_CSHP);
415 chp_params = (struct srs_trumedia_params_CSHP *)
416 ((u8 *)adm_params +
417 sizeof(struct adm_cmd_set_pp_params_inband_v5));
418 memcpy(chp_params, srs_params,
419 sizeof(struct srs_trumedia_params_CSHP));
420 break;
421 }
422 case SRS_ID_HPF: {
423 struct srs_trumedia_params_HPF *hpf_params = NULL;
424
425 sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) +
426 sizeof(struct srs_trumedia_params_HPF);
427 adm_params = kzalloc(sz, GFP_KERNEL);
428 if (!adm_params) {
429 pr_err("%s, adm params memory alloc failed\n",
430 __func__);
431 return -ENOMEM;
432 }
433 adm_params->payload_size =
434 sizeof(struct srs_trumedia_params_HPF) +
435 sizeof(struct adm_param_data_v5);
436 param_id = SRS_TRUMEDIA_PARAMS_HPF;
437 adm_params->params.param_size =
438 sizeof(struct srs_trumedia_params_HPF);
439 hpf_params = (struct srs_trumedia_params_HPF *)
440 ((u8 *)adm_params +
441 sizeof(struct adm_cmd_set_pp_params_inband_v5));
442 memcpy(hpf_params, srs_params,
443 sizeof(struct srs_trumedia_params_HPF));
444 break;
445 }
446 case SRS_ID_AEQ: {
447 int *update_params_ptr = (int *)this_adm.outband_memmap.kvaddr;
448
449 outband = 1;
450 adm_params = kzalloc(sizeof(struct adm_cmd_set_pp_params_v5),
451 GFP_KERNEL);
452 adm_params_ = (struct adm_cmd_set_pp_params_v5 *)adm_params;
453 if (!adm_params_) {
454 pr_err("%s, adm params memory alloc failed\n",
455 __func__);
456 return -ENOMEM;
457 }
458
459 sz = sizeof(struct srs_trumedia_params_AEQ);
460 if (update_params_ptr == NULL) {
461 pr_err("ADM_SRS_TRUMEDIA - %s: null memmap for AEQ params\n",
462 __func__);
463 ret = -EINVAL;
464 goto fail_cmd;
465 }
466 param_id = SRS_TRUMEDIA_PARAMS_AEQ;
467 *update_params_ptr++ = module_id;
468 *update_params_ptr++ = param_id;
469 *update_params_ptr++ = sz;
470 memcpy(update_params_ptr, srs_params, sz);
471
472 adm_params_->payload_size = sz + 12;
473
474 break;
475 }
476 case SRS_ID_HL: {
477 struct srs_trumedia_params_HL *hl_params = NULL;
478
479 sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) +
480 sizeof(struct srs_trumedia_params_HL);
481 adm_params = kzalloc(sz, GFP_KERNEL);
482 if (!adm_params) {
483 pr_err("%s, adm params memory alloc failed\n",
484 __func__);
485 return -ENOMEM;
486 }
487 adm_params->payload_size =
488 sizeof(struct srs_trumedia_params_HL) +
489 sizeof(struct adm_param_data_v5);
490 param_id = SRS_TRUMEDIA_PARAMS_HL;
491 adm_params->params.param_size =
492 sizeof(struct srs_trumedia_params_HL);
493 hl_params = (struct srs_trumedia_params_HL *)
494 ((u8 *)adm_params +
495 sizeof(struct adm_cmd_set_pp_params_inband_v5));
496 memcpy(hl_params, srs_params,
497 sizeof(struct srs_trumedia_params_HL));
498 break;
499 }
500 case SRS_ID_GEQ: {
501 struct srs_trumedia_params_GEQ *geq_params = NULL;
502
503 sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) +
504 sizeof(struct srs_trumedia_params_GEQ);
505 adm_params = kzalloc(sz, GFP_KERNEL);
506 if (!adm_params) {
507 pr_err("%s, adm params memory alloc failed\n",
508 __func__);
509 return -ENOMEM;
510 }
511 adm_params->payload_size =
512 sizeof(struct srs_trumedia_params_GEQ) +
513 sizeof(struct adm_param_data_v5);
514 param_id = SRS_TRUMEDIA_PARAMS_GEQ;
515 adm_params->params.param_size =
516 sizeof(struct srs_trumedia_params_GEQ);
517 geq_params = (struct srs_trumedia_params_GEQ *)
518 ((u8 *)adm_params +
519 sizeof(struct adm_cmd_set_pp_params_inband_v5));
520 memcpy(geq_params, srs_params,
521 sizeof(struct srs_trumedia_params_GEQ));
522 pr_debug("SRS - %s: GEQ params prepared\n", __func__);
523 break;
524 }
525 default:
526 goto fail_cmd;
527 }
528
529 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
530 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
531 adm_params->hdr.src_svc = APR_SVC_ADM;
532 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
533 adm_params->hdr.src_port = port_id;
534 adm_params->hdr.dest_svc = APR_SVC_ADM;
535 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
536 adm_params->hdr.dest_port =
537 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
538 adm_params->hdr.token = port_idx << 16 | copp_idx;
539 adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
540 if (outband && this_adm.outband_memmap.paddr) {
541 adm_params->hdr.pkt_size =
542 sizeof(struct adm_cmd_set_pp_params_v5);
543 adm_params->payload_addr_lsw = lower_32_bits(
544 this_adm.outband_memmap.paddr);
545 adm_params->payload_addr_msw = msm_audio_populate_upper_32_bits(
546 this_adm.outband_memmap.paddr);
547 adm_params->mem_map_handle = atomic_read(&this_adm.
548 mem_map_handles[ADM_SRS_TRUMEDIA]);
549 } else {
550 adm_params->hdr.pkt_size = sz;
551 adm_params->payload_addr_lsw = 0;
552 adm_params->payload_addr_msw = 0;
553 adm_params->mem_map_handle = 0;
554
555 adm_params->params.module_id = module_id;
556 adm_params->params.param_id = param_id;
557 adm_params->params.reserved = 0;
558 }
559
560 pr_debug("SRS - %s: Command was sent now check Q6 - port id = %d, size %d, module id %x, param id %x.\n",
561 __func__, adm_params->hdr.dest_port,
562 adm_params->payload_size, module_id, param_id);
563
564 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
565 ret = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
566 if (ret < 0) {
567 pr_err("SRS - %s: ADM enable for port %d failed\n", __func__,
568 port_id);
569 ret = -EINVAL;
570 goto fail_cmd;
571 }
572 /* Wait for the callback with copp id */
573 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
574 atomic_read(&this_adm.copp.stat
575 [port_idx][copp_idx]) >= 0,
576 msecs_to_jiffies(TIMEOUT_MS));
577 if (!ret) {
578 pr_err("%s: SRS set params timed out port = %d\n",
579 __func__, port_id);
580 ret = -EINVAL;
581 goto fail_cmd;
582 } else if (atomic_read(&this_adm.copp.stat
583 [port_idx][copp_idx]) > 0) {
584 pr_err("%s: DSP returned error[%s]\n",
585 __func__, adsp_err_get_err_str(
586 atomic_read(&this_adm.copp.stat
587 [port_idx][copp_idx])));
588 ret = adsp_err_get_lnx_err_code(
589 atomic_read(&this_adm.copp.stat
590 [port_idx][copp_idx]));
591 goto fail_cmd;
592 }
593
594fail_cmd:
595 kfree(adm_params);
596 return ret;
597}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530598EXPORT_SYMBOL(srs_trumedia_open);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530599
600static int adm_populate_channel_weight(u16 *ptr,
601 struct msm_pcm_channel_mixer *ch_mixer,
602 int channel_index)
603{
604 u16 i, j, start_index = 0;
605
606 if (channel_index > ch_mixer->output_channel) {
607 pr_err("%s: channel index %d is larger than output_channel %d\n",
608 __func__, channel_index, ch_mixer->output_channel);
609 return -EINVAL;
610 }
611
612 for (i = 0; i < ch_mixer->output_channel; i++) {
613 pr_debug("%s: weight for output %d:", __func__, i);
614 for (j = 0; j < ADM_MAX_CHANNELS; j++)
615 pr_debug(" %d",
616 ch_mixer->channel_weight[i][j]);
617 pr_debug("\n");
618 }
619
620 for (i = 0; i < channel_index; ++i)
621 start_index += ch_mixer->input_channels[i];
622
623 for (i = 0; i < ch_mixer->output_channel; ++i) {
624 for (j = start_index;
625 j < start_index +
626 ch_mixer->input_channels[channel_index]; j++) {
627 *ptr = ch_mixer->channel_weight[i][j];
628 pr_debug("%s: ptr[%d][%d] = %d\n",
629 __func__, i, j, *ptr);
630 ptr++;
631 }
632 }
633
634 return 0;
635}
636
637/*
638 * adm_programable_channel_mixer
639 *
640 * Receives port_id, copp_idx, session_id, session_type, ch_mixer
641 * and channel_index to send ADM command to mix COPP data.
642 *
643 * port_id - Passed value, port_id for which backend is wanted
644 * copp_idx - Passed value, copp_idx for which COPP is wanted
645 * session_id - Passed value, session_id for which session is needed
646 * session_type - Passed value, session_type for RX or TX
647 * ch_mixer - Passed value, ch_mixer for which channel mixer config is needed
648 * channel_index - Passed value, channel_index for which channel is needed
Dhanalakshmi Siddani040e0262018-11-26 23:01:26 +0530649 * use_default_chmap - true if default channel map to be used
650 * ch_map - input/output channel map for playback/capture session respectively
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530651 */
652int adm_programable_channel_mixer(int port_id, int copp_idx, int session_id,
653 int session_type,
654 struct msm_pcm_channel_mixer *ch_mixer,
Dhanalakshmi Siddani040e0262018-11-26 23:01:26 +0530655 int channel_index, bool use_default_chmap,
656 char *ch_map)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530657{
658 struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL;
659 struct adm_param_data_v5 data_v5;
660 int ret = 0, port_idx, sz = 0, param_size = 0;
661 u16 *adm_pspd_params;
662 u16 *ptr;
Dhanalakshmi Siddani040e0262018-11-26 23:01:26 +0530663 int index = 0, i;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530664
665 pr_debug("%s: port_id = %d\n", __func__, port_id);
666 port_id = afe_convert_virtual_to_portid(port_id);
667 port_idx = adm_validate_and_get_port_index(port_id);
668 if (port_idx < 0) {
669 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
670 return -EINVAL;
671 }
672 /*
673 * First 8 bytes are 4 bytes as rule number, 2 bytes as output
674 * channel and 2 bytes as input channel.
675 * 2 * ch_mixer->output_channel means output channel mapping.
676 * 2 * ch_mixer->input_channels[channel_index]) means input
677 * channel mapping.
678 * 2 * ch_mixer->input_channels[channel_index] *
679 * ch_mixer->output_channel) means the channel mixer weighting
680 * coefficients.
681 * param_size needs to be a multiple of 4 bytes.
682 */
683
684 param_size = 2 * (4 + ch_mixer->output_channel +
685 ch_mixer->input_channels[channel_index] +
686 ch_mixer->input_channels[channel_index] *
687 ch_mixer->output_channel);
Dhanalakshmi Siddani51ff6552018-11-26 23:07:52 +0530688 /* Params size should be multiple of 4 bytes i.e 32bit aligned */
689 param_size = round_up(param_size, 4);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530690
691 sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) +
692 sizeof(struct default_chmixer_param_id_coeff) +
693 sizeof(struct adm_param_data_v5) + param_size;
694 pr_debug("%s: sz = %d\n", __func__, sz);
695 adm_params = kzalloc(sz, GFP_KERNEL);
696 if (!adm_params)
697 return -ENOMEM;
698
699 adm_params->payload_addr_lsw = 0;
700 adm_params->payload_addr_msw = 0;
701 adm_params->mem_map_handle = 0;
702 adm_params->direction = session_type;
703 adm_params->sessionid = session_id;
704 pr_debug("%s: copp_id = %d, session id %d\n", __func__,
705 atomic_read(&this_adm.copp.id[port_idx][copp_idx]),
706 session_id);
707 adm_params->deviceid = atomic_read(
708 &this_adm.copp.id[port_idx][copp_idx]);
709 adm_params->reserved = 0;
710
711 data_v5.module_id = MTMX_MODULE_ID_DEFAULT_CHMIXER;
712 data_v5.param_id = DEFAULT_CHMIXER_PARAM_ID_COEFF;
713 data_v5.reserved = 0;
714 data_v5.param_size = param_size;
715 adm_params->payload_size =
716 sizeof(struct default_chmixer_param_id_coeff) +
717 sizeof(struct adm_param_data_v5) + data_v5.param_size;
718 adm_pspd_params = (u16 *)((u8 *)adm_params +
719 sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5));
720 memcpy(adm_pspd_params, &data_v5, sizeof(data_v5));
721
722 adm_pspd_params = (u16 *)((u8 *)adm_params +
723 sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)
724 + sizeof(data_v5));
725
726 adm_pspd_params[0] = ch_mixer->rule;
727 adm_pspd_params[2] = ch_mixer->output_channel;
728 adm_pspd_params[3] = ch_mixer->input_channels[channel_index];
729 index = 4;
730
Dhanalakshmi Siddani040e0262018-11-26 23:01:26 +0530731 if ((session_type == SESSION_TYPE_TX) && !use_default_chmap && ch_map) {
732 for (i = 0; i < ch_mixer->output_channel; i++)
733 adm_pspd_params[index++] = ch_map[i];
734 } else {
735 if (ch_mixer->output_channel == 1) {
736 adm_pspd_params[index] = PCM_CHANNEL_FC;
737 } else if (ch_mixer->output_channel == 2) {
738 adm_pspd_params[index] = PCM_CHANNEL_FL;
739 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
740 } else if (ch_mixer->output_channel == 3) {
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 } else if (ch_mixer->output_channel == 4) {
745 adm_pspd_params[index] = PCM_CHANNEL_FL;
746 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
747 adm_pspd_params[index + 2] = PCM_CHANNEL_LS;
748 adm_pspd_params[index + 3] = PCM_CHANNEL_RS;
749 } else if (ch_mixer->output_channel == 5) {
750 adm_pspd_params[index] = PCM_CHANNEL_FL;
751 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
752 adm_pspd_params[index + 2] = PCM_CHANNEL_FC;
753 adm_pspd_params[index + 3] = PCM_CHANNEL_LS;
754 adm_pspd_params[index + 4] = PCM_CHANNEL_RS;
755 } else if (ch_mixer->output_channel == 6) {
756 adm_pspd_params[index] = PCM_CHANNEL_FL;
757 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
758 adm_pspd_params[index + 2] = PCM_CHANNEL_LFE;
759 adm_pspd_params[index + 3] = PCM_CHANNEL_FC;
760 adm_pspd_params[index + 4] = PCM_CHANNEL_LS;
761 adm_pspd_params[index + 5] = PCM_CHANNEL_RS;
762 } else if (ch_mixer->output_channel == 8) {
763 adm_pspd_params[index] = PCM_CHANNEL_FL;
764 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
765 adm_pspd_params[index + 2] = PCM_CHANNEL_LFE;
766 adm_pspd_params[index + 3] = PCM_CHANNEL_FC;
767 adm_pspd_params[index + 4] = PCM_CHANNEL_LS;
768 adm_pspd_params[index + 5] = PCM_CHANNEL_RS;
769 adm_pspd_params[index + 6] = PCM_CHANNEL_LB;
770 adm_pspd_params[index + 7] = PCM_CHANNEL_RB;
771 }
772 index = index + ch_mixer->output_channel;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530773 }
774
Dhanalakshmi Siddani040e0262018-11-26 23:01:26 +0530775 if ((session_type == SESSION_TYPE_RX) && !use_default_chmap && ch_map) {
776 for (i = 0; i < ch_mixer->input_channels[channel_index]; i++)
777 adm_pspd_params[index++] = ch_map[i];
778 } else {
779 if (ch_mixer->input_channels[channel_index] == 1) {
780 adm_pspd_params[index] = PCM_CHANNEL_FC;
781 } else if (ch_mixer->input_channels[channel_index] == 2) {
782 adm_pspd_params[index] = PCM_CHANNEL_FL;
783 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
784 } else if (ch_mixer->input_channels[channel_index] == 3) {
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 } else if (ch_mixer->input_channels[channel_index] == 4) {
789 adm_pspd_params[index] = PCM_CHANNEL_FL;
790 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
791 adm_pspd_params[index + 2] = PCM_CHANNEL_LS;
792 adm_pspd_params[index + 3] = PCM_CHANNEL_RS;
793 } else if (ch_mixer->input_channels[channel_index] == 5) {
794 adm_pspd_params[index] = PCM_CHANNEL_FL;
795 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
796 adm_pspd_params[index + 2] = PCM_CHANNEL_FC;
797 adm_pspd_params[index + 3] = PCM_CHANNEL_LS;
798 adm_pspd_params[index + 4] = PCM_CHANNEL_RS;
799 } else if (ch_mixer->input_channels[channel_index] == 6) {
800 adm_pspd_params[index] = PCM_CHANNEL_FL;
801 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
802 adm_pspd_params[index + 2] = PCM_CHANNEL_LFE;
803 adm_pspd_params[index + 3] = PCM_CHANNEL_FC;
804 adm_pspd_params[index + 4] = PCM_CHANNEL_LS;
805 adm_pspd_params[index + 5] = PCM_CHANNEL_RS;
806 } else if (ch_mixer->input_channels[channel_index] == 8) {
807 adm_pspd_params[index] = PCM_CHANNEL_FL;
808 adm_pspd_params[index + 1] = PCM_CHANNEL_FR;
809 adm_pspd_params[index + 2] = PCM_CHANNEL_LFE;
810 adm_pspd_params[index + 3] = PCM_CHANNEL_FC;
811 adm_pspd_params[index + 4] = PCM_CHANNEL_LS;
812 adm_pspd_params[index + 5] = PCM_CHANNEL_RS;
813 adm_pspd_params[index + 6] = PCM_CHANNEL_LB;
814 adm_pspd_params[index + 7] = PCM_CHANNEL_RB;
815 }
816 index = index + ch_mixer->input_channels[channel_index];
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530817 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530818 ret = adm_populate_channel_weight(&adm_pspd_params[index],
819 ch_mixer, channel_index);
Meng Wang47ea2ca2018-01-23 12:42:52 +0800820 if (ret) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530821 pr_err("%s: fail to get channel weight with error %d\n",
822 __func__, ret);
823 goto fail_cmd;
824 }
825
826 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
827 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
828 adm_params->hdr.src_svc = APR_SVC_ADM;
829 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
830 adm_params->hdr.src_port = port_id;
831 adm_params->hdr.dest_svc = APR_SVC_ADM;
832 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
833 adm_params->hdr.dest_port =
834 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
835 adm_params->hdr.token = port_idx << 16 | copp_idx;
836 adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5;
837 adm_params->hdr.pkt_size = sz;
838 adm_params->payload_addr_lsw = 0;
839 adm_params->payload_addr_msw = 0;
840 adm_params->mem_map_handle = 0;
841 adm_params->reserved = 0;
842
843 ptr = (u16 *)adm_params;
844 for (index = 0; index < (sz / 2); index++)
845 pr_debug("%s: adm_params[%d] = 0x%x\n",
846 __func__, index, (unsigned int)ptr[index]);
847
848 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], 0);
849 ret = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
850 if (ret < 0) {
851 pr_err("%s: Set params failed port %d rc %d\n", __func__,
852 port_id, ret);
853 ret = -EINVAL;
854 goto fail_cmd;
855 }
856
857 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
858 atomic_read(
859 &this_adm.copp.stat[port_idx][copp_idx]) >= 0,
860 msecs_to_jiffies(TIMEOUT_MS));
861 if (!ret) {
862 pr_err("%s: set params timed out port = %d\n",
863 __func__, port_id);
864 ret = -ETIMEDOUT;
865 goto fail_cmd;
866 }
867 ret = 0;
868fail_cmd:
869 kfree(adm_params);
870
871 return ret;
872}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530873EXPORT_SYMBOL(adm_programable_channel_mixer);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530874
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530875/**
876 * adm_set_stereo_to_custom_stereo -
877 * command to update custom stereo
878 *
879 * @port_id: Port ID number
880 * @copp_idx: copp index of ADM copp
881 * @session_id: session id to be updated
882 * @params: params pointer
883 * @param_length: length of params
884 *
885 * Returns 0 on success or error on failure
886 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530887int adm_set_stereo_to_custom_stereo(int port_id, int copp_idx,
888 unsigned int session_id, char *params,
889 uint32_t params_length)
890{
891 struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL;
892 int sz, rc = 0, port_idx;
893
894 pr_debug("%s:\n", __func__);
895 port_id = afe_convert_virtual_to_portid(port_id);
896 port_idx = adm_validate_and_get_port_index(port_id);
897 if (port_idx < 0) {
898 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
899 return -EINVAL;
900 }
901
902 sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) +
903 params_length;
904 adm_params = kzalloc(sz, GFP_KERNEL);
905 if (!adm_params) {
906 pr_err("%s, adm params memory alloc failed\n", __func__);
907 return -ENOMEM;
908 }
909
910 memcpy(((u8 *)adm_params +
911 sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)),
912 params, params_length);
913 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
914 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
915 adm_params->hdr.pkt_size = sz;
916 adm_params->hdr.src_svc = APR_SVC_ADM;
917 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
918 adm_params->hdr.src_port = port_id;
919 adm_params->hdr.dest_svc = APR_SVC_ADM;
920 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
921 adm_params->hdr.dest_port = 0; /* Ignored */;
922 adm_params->hdr.token = port_idx << 16 | copp_idx;
923 adm_params->hdr.opcode = ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5;
924 adm_params->payload_addr_lsw = 0;
925 adm_params->payload_addr_msw = 0;
926 adm_params->mem_map_handle = 0;
927 adm_params->payload_size = params_length;
928 /* direction RX as 0 */
929 adm_params->direction = ADM_MATRIX_ID_AUDIO_RX;
930 /* session id for this cmd to be applied on */
931 adm_params->sessionid = session_id;
932 adm_params->deviceid =
933 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
934 adm_params->reserved = 0;
935 pr_debug("%s: deviceid %d, session_id %d, src_port %d, dest_port %d\n",
936 __func__, adm_params->deviceid, adm_params->sessionid,
937 adm_params->hdr.src_port, adm_params->hdr.dest_port);
938 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
939 rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
940 if (rc < 0) {
941 pr_err("%s: Set params failed port = 0x%x rc %d\n",
942 __func__, port_id, rc);
943 rc = -EINVAL;
944 goto set_stereo_to_custom_stereo_return;
945 }
946 /* Wait for the callback */
947 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
948 atomic_read(&this_adm.copp.stat
949 [port_idx][copp_idx]) >= 0,
950 msecs_to_jiffies(TIMEOUT_MS));
951 if (!rc) {
952 pr_err("%s: Set params timed out port = 0x%x\n", __func__,
953 port_id);
954 rc = -EINVAL;
955 goto set_stereo_to_custom_stereo_return;
956 } else if (atomic_read(&this_adm.copp.stat
957 [port_idx][copp_idx]) > 0) {
958 pr_err("%s: DSP returned error[%s]\n", __func__,
959 adsp_err_get_err_str(atomic_read(
960 &this_adm.copp.stat
961 [port_idx][copp_idx])));
962 rc = adsp_err_get_lnx_err_code(
963 atomic_read(&this_adm.copp.stat
964 [port_idx][copp_idx]));
965 goto set_stereo_to_custom_stereo_return;
966 }
967 rc = 0;
968set_stereo_to_custom_stereo_return:
969 kfree(adm_params);
970 return rc;
971}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530972EXPORT_SYMBOL(adm_set_stereo_to_custom_stereo);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530973
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530974/**
975 * adm_dolby_dap_send_params -
976 * command to send dolby dap params
977 *
978 * @port_id: Port ID number
979 * @copp_idx: copp index of ADM copp
980 * @params: params pointer
981 * @param_length: length of params
982 *
983 * Returns 0 on success or error on failure
984 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530985int adm_dolby_dap_send_params(int port_id, int copp_idx, char *params,
986 uint32_t params_length)
987{
988 struct adm_cmd_set_pp_params_v5 *adm_params = NULL;
989 int sz, rc = 0;
990 int port_idx;
991
992 pr_debug("%s:\n", __func__);
993 port_id = afe_convert_virtual_to_portid(port_id);
994 port_idx = adm_validate_and_get_port_index(port_id);
995 if (port_idx < 0) {
996 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
997 return -EINVAL;
998 }
999
1000 sz = sizeof(struct adm_cmd_set_pp_params_v5) + params_length;
1001 adm_params = kzalloc(sz, GFP_KERNEL);
1002 if (!adm_params) {
1003 pr_err("%s, adm params memory alloc failed", __func__);
1004 return -ENOMEM;
1005 }
1006
1007 memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)),
1008 params, params_length);
1009 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1010 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1011 adm_params->hdr.pkt_size = sz;
1012 adm_params->hdr.src_svc = APR_SVC_ADM;
1013 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
1014 adm_params->hdr.src_port = port_id;
1015 adm_params->hdr.dest_svc = APR_SVC_ADM;
1016 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
1017 adm_params->hdr.dest_port =
1018 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
1019 adm_params->hdr.token = port_idx << 16 | copp_idx;
1020 adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
1021 adm_params->payload_addr_lsw = 0;
1022 adm_params->payload_addr_msw = 0;
1023 adm_params->mem_map_handle = 0;
1024 adm_params->payload_size = params_length;
1025
1026 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
1027 rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
1028 if (rc < 0) {
1029 pr_err("%s: Set params failed port = 0x%x rc %d\n",
1030 __func__, port_id, rc);
1031 rc = -EINVAL;
1032 goto dolby_dap_send_param_return;
1033 }
1034 /* Wait for the callback */
1035 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
1036 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
1037 msecs_to_jiffies(TIMEOUT_MS));
1038 if (!rc) {
1039 pr_err("%s: Set params timed out port = 0x%x\n",
1040 __func__, port_id);
1041 rc = -EINVAL;
1042 goto dolby_dap_send_param_return;
1043 } else if (atomic_read(&this_adm.copp.stat
1044 [port_idx][copp_idx]) > 0) {
1045 pr_err("%s: DSP returned error[%s]\n",
1046 __func__, adsp_err_get_err_str(
1047 atomic_read(&this_adm.copp.stat
1048 [port_idx][copp_idx])));
1049 rc = adsp_err_get_lnx_err_code(
1050 atomic_read(&this_adm.copp.stat
1051 [port_idx][copp_idx]));
1052 goto dolby_dap_send_param_return;
1053 }
1054 rc = 0;
1055dolby_dap_send_param_return:
1056 kfree(adm_params);
1057 return rc;
1058}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301059EXPORT_SYMBOL(adm_dolby_dap_send_params);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301060
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301061/**
1062 * adm_get_params_v5 -
1063 * command to retrieve ADM params for given module
1064 *
1065 * @port_id: Port ID number
1066 * @copp_idx: copp index of ADM copp
1067 * @params: params pointer
1068 * @param_length: length of params
1069 *
1070 * Returns 0 on success or error on failure
1071 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301072int adm_send_params_v5(int port_id, int copp_idx, char *params,
1073 uint32_t params_length)
1074{
1075 struct adm_cmd_set_pp_params_v5 *adm_params = NULL;
1076 int rc = 0;
1077 int sz, port_idx;
1078
1079 pr_debug("%s:\n", __func__);
1080 port_id = afe_convert_virtual_to_portid(port_id);
1081 port_idx = adm_validate_and_get_port_index(port_id);
1082 if (port_idx < 0) {
1083 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
1084 return -EINVAL;
1085 }
1086
1087 sz = sizeof(struct adm_cmd_set_pp_params_v5) + params_length;
1088 adm_params = kzalloc(sz, GFP_KERNEL);
1089 if (!adm_params) {
1090 pr_err("%s, adm params memory alloc failed", __func__);
1091 return -ENOMEM;
1092 }
1093
1094 memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)),
1095 params, params_length);
1096 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1097 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1098 adm_params->hdr.pkt_size = sz;
1099 adm_params->hdr.src_svc = APR_SVC_ADM;
1100 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
1101 adm_params->hdr.src_port = port_id;
1102 adm_params->hdr.dest_svc = APR_SVC_ADM;
1103 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
1104 adm_params->hdr.dest_port =
1105 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
1106 adm_params->hdr.token = port_idx << 16 | copp_idx;
1107 adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
1108 adm_params->payload_addr_lsw = 0;
1109 adm_params->payload_addr_msw = 0;
1110 adm_params->mem_map_handle = 0;
1111 adm_params->payload_size = params_length;
1112
1113 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
1114 rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
1115 if (rc < 0) {
1116 pr_err("%s: Set params failed port = 0x%x rc %d\n",
1117 __func__, port_id, rc);
1118 rc = -EINVAL;
1119 goto send_param_return;
1120 }
1121 /* Wait for the callback */
1122 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
1123 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
1124 msecs_to_jiffies(TIMEOUT_MS));
1125 if (!rc) {
1126 pr_err("%s: Set params timed out port = 0x%x\n",
1127 __func__, port_id);
1128 rc = -EINVAL;
1129 goto send_param_return;
1130 } else if (atomic_read(&this_adm.copp.stat
1131 [port_idx][copp_idx]) > 0) {
1132 pr_err("%s: DSP returned error[%s]\n",
1133 __func__, adsp_err_get_err_str(
1134 atomic_read(&this_adm.copp.stat
1135 [port_idx][copp_idx])));
1136 rc = adsp_err_get_lnx_err_code(
1137 atomic_read(&this_adm.copp.stat
1138 [port_idx][copp_idx]));
1139 goto send_param_return;
1140 }
1141 rc = 0;
1142send_param_return:
1143 kfree(adm_params);
1144 return rc;
1145}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301146EXPORT_SYMBOL(adm_send_params_v5);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301147
1148int adm_get_params_v2(int port_id, int copp_idx, uint32_t module_id,
1149 uint32_t param_id, uint32_t params_length,
1150 char *params, uint32_t client_id)
1151{
1152 struct adm_cmd_get_pp_params_v5 *adm_params = NULL;
1153 int rc = 0, i = 0;
1154 int port_idx, idx;
1155 int *params_data = (int *)params;
1156 uint64_t sz = 0;
1157
1158 port_id = afe_convert_virtual_to_portid(port_id);
1159 port_idx = adm_validate_and_get_port_index(port_id);
1160 if (port_idx < 0) {
1161 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
1162 return -EINVAL;
1163 }
1164
1165 sz = (uint64_t)sizeof(struct adm_cmd_get_pp_params_v5) +
1166 (uint64_t)params_length;
1167 /*
1168 * Check if the value of "sz" (which is ultimately assigned to
1169 * "hdr.pkt_size") crosses U16_MAX.
1170 */
1171 if (sz > U16_MAX) {
1172 pr_err("%s: Invalid params_length\n", __func__);
1173 return -EINVAL;
1174 }
1175 adm_params = kzalloc(sz, GFP_KERNEL);
1176 if (!adm_params) {
1177 pr_err("%s: adm params memory alloc failed", __func__);
1178 return -ENOMEM;
1179 }
1180
1181 memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_get_pp_params_v5)),
1182 params, params_length);
1183 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1184 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1185 adm_params->hdr.pkt_size = sz;
1186 adm_params->hdr.src_svc = APR_SVC_ADM;
1187 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
1188 adm_params->hdr.src_port = port_id;
1189 adm_params->hdr.dest_svc = APR_SVC_ADM;
1190 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
1191 adm_params->hdr.dest_port =
1192 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
1193 adm_params->hdr.token = port_idx << 16 | client_id << 8 | copp_idx;
1194 adm_params->hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5;
1195 adm_params->data_payload_addr_lsw = 0;
1196 adm_params->data_payload_addr_msw = 0;
1197 adm_params->mem_map_handle = 0;
1198 adm_params->module_id = module_id;
1199 adm_params->param_id = param_id;
1200 adm_params->param_max_size = params_length;
1201 adm_params->reserved = 0;
1202
1203 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
1204 rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
1205 if (rc < 0) {
1206 pr_err("%s: Failed to Get Params on port_id 0x%x %d\n",
1207 __func__, port_id, rc);
1208 rc = -EINVAL;
1209 goto adm_get_param_return;
1210 }
1211 /* Wait for the callback with copp id */
1212 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
1213 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
1214 msecs_to_jiffies(TIMEOUT_MS));
1215 if (!rc) {
1216 pr_err("%s: get params timed out port_id = 0x%x\n", __func__,
1217 port_id);
1218 rc = -EINVAL;
1219 goto adm_get_param_return;
1220 } else if (atomic_read(&this_adm.copp.stat
1221 [port_idx][copp_idx]) > 0) {
1222 pr_err("%s: DSP returned error[%s]\n",
1223 __func__, adsp_err_get_err_str(
1224 atomic_read(&this_adm.copp.stat
1225 [port_idx][copp_idx])));
1226 rc = adsp_err_get_lnx_err_code(
1227 atomic_read(&this_adm.copp.stat
1228 [port_idx][copp_idx]));
1229 goto adm_get_param_return;
1230 }
1231 idx = ADM_GET_PARAMETER_LENGTH * copp_idx;
1232
1233 if (adm_get_parameters[idx] < 0) {
1234 pr_err("%s: Size is invalid %d\n", __func__,
1235 adm_get_parameters[idx]);
1236 rc = -EINVAL;
1237 goto adm_get_param_return;
1238 }
1239 if ((params_data) &&
1240 (ARRAY_SIZE(adm_get_parameters) >
1241 idx) &&
1242 (ARRAY_SIZE(adm_get_parameters) >=
1243 1+adm_get_parameters[idx]+idx) &&
1244 (params_length/sizeof(uint32_t) >=
1245 adm_get_parameters[idx])) {
1246 for (i = 0; i < adm_get_parameters[idx]; i++)
1247 params_data[i] = adm_get_parameters[1+i+idx];
1248
1249 } else {
1250 pr_err("%s: Get param data not copied! get_param array size %zd, index %d, params array size %zd, index %d\n",
1251 __func__, ARRAY_SIZE(adm_get_parameters),
1252 (1+adm_get_parameters[idx]+idx),
1253 params_length/sizeof(int),
1254 adm_get_parameters[idx]);
1255 }
1256 rc = 0;
1257adm_get_param_return:
1258 kfree(adm_params);
1259
1260 return rc;
1261}
1262
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301263/**
1264 * adm_get_params -
1265 * command to retrieve ADM params for given module
1266 *
1267 * @port_id: Port ID number
1268 * @copp_idx: copp index of ADM copp
1269 * @module_id: module ID
1270 * @param_id: Param index
1271 * @param_length: length of params
1272 * @params: params pointer
1273 *
1274 * Returns 0 on success or error on failure
1275 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301276int adm_get_params(int port_id, int copp_idx, uint32_t module_id,
1277 uint32_t param_id, uint32_t params_length, char *params)
1278{
1279 return adm_get_params_v2(port_id, copp_idx, module_id, param_id,
1280 params_length, params, 0);
1281}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301282EXPORT_SYMBOL(adm_get_params);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301283
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301284/**
1285 * adm_get_pp_topo_module_list -
1286 * command to update PP top module list
1287 *
1288 * @port_id: Port ID number
1289 * @copp_idx: copp index of ADM copp
1290 * @param_length: length of params
1291 * @params: pointer with PP top module params
1292 *
1293 * Returns 0 on success or error on failure
1294 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301295int adm_get_pp_topo_module_list(int port_id, int copp_idx, int32_t param_length,
1296 char *params)
1297{
1298 struct adm_cmd_get_pp_topo_module_list_t *adm_pp_module_list = NULL;
1299 int sz, rc = 0, i = 0;
1300 int port_idx, idx;
1301 int32_t *params_data = (int32_t *)params;
1302 int *topo_list;
1303
1304 pr_debug("%s : port_id %x", __func__, port_id);
1305 port_id = afe_convert_virtual_to_portid(port_id);
1306 port_idx = adm_validate_and_get_port_index(port_id);
1307 if (port_idx < 0) {
1308 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
1309 return -EINVAL;
1310 }
1311
1312 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
1313 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
1314 return -EINVAL;
1315 }
1316
1317 sz = sizeof(struct adm_cmd_get_pp_topo_module_list_t) + param_length;
1318 adm_pp_module_list = kzalloc(sz, GFP_KERNEL);
1319 if (!adm_pp_module_list) {
1320 pr_err("%s, adm params memory alloc failed", __func__);
1321 return -ENOMEM;
1322 }
1323
1324 memcpy(((u8 *)adm_pp_module_list +
1325 sizeof(struct adm_cmd_get_pp_topo_module_list_t)),
1326 params, param_length);
1327 adm_pp_module_list->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1328 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
1329 adm_pp_module_list->hdr.pkt_size = sz;
1330 adm_pp_module_list->hdr.src_svc = APR_SVC_ADM;
1331 adm_pp_module_list->hdr.src_domain = APR_DOMAIN_APPS;
1332 adm_pp_module_list->hdr.src_port = port_id;
1333 adm_pp_module_list->hdr.dest_svc = APR_SVC_ADM;
1334 adm_pp_module_list->hdr.dest_domain = APR_DOMAIN_ADSP;
1335 adm_pp_module_list->hdr.dest_port =
1336 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
1337 adm_pp_module_list->hdr.token = port_idx << 16 | copp_idx;
1338 adm_pp_module_list->hdr.opcode = ADM_CMD_GET_PP_TOPO_MODULE_LIST;
1339 adm_pp_module_list->param_max_size = param_length;
1340 /* Payload address and mmap handle set to zero by kzalloc */
1341
1342 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
1343
1344 rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_pp_module_list);
1345 if (rc < 0) {
1346 pr_err("%s: Failed to Get Params on port %d\n", __func__,
1347 port_id);
1348 rc = -EINVAL;
1349 goto adm_pp_module_list_l;
1350 }
1351 /* Wait for the callback with copp id */
1352 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
1353 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
1354 msecs_to_jiffies(TIMEOUT_MS));
1355 if (!rc) {
1356 pr_err("%s: get params timed out port = %d\n", __func__,
1357 port_id);
1358 rc = -EINVAL;
1359 goto adm_pp_module_list_l;
1360 } else if (atomic_read(&this_adm.copp.stat
1361 [port_idx][copp_idx]) > 0) {
1362 pr_err("%s: DSP returned error[%s]\n",
1363 __func__, adsp_err_get_err_str(
1364 atomic_read(&this_adm.copp.stat
1365 [port_idx][copp_idx])));
1366 rc = adsp_err_get_lnx_err_code(
1367 atomic_read(&this_adm.copp.stat
1368 [port_idx][copp_idx]));
1369 goto adm_pp_module_list_l;
1370 }
1371 if (params_data) {
1372 idx = ADM_GET_TOPO_MODULE_LIST_LENGTH * copp_idx;
1373 topo_list = (int *)(adm_module_topo_list + idx);
1374 if (param_length <= ADM_GET_TOPO_MODULE_LIST_LENGTH &&
1375 idx <
1376 (MAX_COPPS_PER_PORT * ADM_GET_TOPO_MODULE_LIST_LENGTH))
1377 memcpy(params_data, topo_list, param_length);
1378 else
1379 pr_debug("%s: i/p size:%d > MAX param size:%d\n",
1380 __func__, param_length,
1381 (int)ADM_GET_TOPO_MODULE_LIST_LENGTH);
1382 for (i = 1; i <= params_data[0]; i++)
1383 pr_debug("module = 0x%x\n", params_data[i]);
1384 }
1385 rc = 0;
1386adm_pp_module_list_l:
1387 kfree(adm_pp_module_list);
1388 pr_debug("%s : rc = %d ", __func__, rc);
1389 return rc;
1390}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301391EXPORT_SYMBOL(adm_get_pp_topo_module_list);
1392
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301393static void adm_callback_debug_print(struct apr_client_data *data)
1394{
1395 uint32_t *payload;
1396
1397 payload = data->payload;
1398
1399 if (data->payload_size >= 8)
1400 pr_debug("%s: code = 0x%x PL#0[0x%x], PL#1[0x%x], size = %d\n",
1401 __func__, data->opcode, payload[0], payload[1],
1402 data->payload_size);
1403 else if (data->payload_size >= 4)
1404 pr_debug("%s: code = 0x%x PL#0[0x%x], size = %d\n",
1405 __func__, data->opcode, payload[0],
1406 data->payload_size);
1407 else
1408 pr_debug("%s: code = 0x%x, size = %d\n",
1409 __func__, data->opcode, data->payload_size);
1410}
1411
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301412/**
1413 * adm_set_multi_ch_map -
1414 * Update multi channel map info
1415 *
1416 * @channel_map: pointer with channel map info
1417 * @path: direction or ADM path type
1418 *
1419 * Returns 0 on success or error on failure
1420 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301421int adm_set_multi_ch_map(char *channel_map, int path)
1422{
1423 int idx;
1424
1425 if (path == ADM_PATH_PLAYBACK) {
1426 idx = ADM_MCH_MAP_IDX_PLAYBACK;
1427 } else if (path == ADM_PATH_LIVE_REC) {
1428 idx = ADM_MCH_MAP_IDX_REC;
1429 } else {
1430 pr_err("%s: invalid attempt to set path %d\n", __func__, path);
1431 return -EINVAL;
1432 }
1433
1434 memcpy(multi_ch_maps[idx].channel_mapping, channel_map,
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02001435 PCM_FORMAT_MAX_NUM_CHANNEL_V8);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301436 multi_ch_maps[idx].set_channel_map = true;
1437
1438 return 0;
1439}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301440EXPORT_SYMBOL(adm_set_multi_ch_map);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301441
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301442/**
1443 * adm_get_multi_ch_map -
1444 * Retrieves multi channel map info
1445 *
1446 * @channel_map: pointer to be updated with channel map
1447 * @path: direction or ADM path type
1448 *
1449 * Returns 0 on success or error on failure
1450 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301451int adm_get_multi_ch_map(char *channel_map, int path)
1452{
1453 int idx;
1454
1455 if (path == ADM_PATH_PLAYBACK) {
1456 idx = ADM_MCH_MAP_IDX_PLAYBACK;
1457 } else if (path == ADM_PATH_LIVE_REC) {
1458 idx = ADM_MCH_MAP_IDX_REC;
1459 } else {
1460 pr_err("%s: invalid attempt to get path %d\n", __func__, path);
1461 return -EINVAL;
1462 }
1463
1464 if (multi_ch_maps[idx].set_channel_map) {
1465 memcpy(channel_map, multi_ch_maps[idx].channel_mapping,
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02001466 PCM_FORMAT_MAX_NUM_CHANNEL_V8);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301467 }
1468
1469 return 0;
1470}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05301471EXPORT_SYMBOL(adm_get_multi_ch_map);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301472
Rohit kumar5d860f42019-02-01 18:01:12 +05301473/**
1474 * adm_set_port_multi_ch_map -
1475 * Update port specific channel map info
1476 *
1477 * @channel_map: pointer with channel map info
1478 * @port_id: port for which chmap is set
1479 */
1480void adm_set_port_multi_ch_map(char *channel_map, int port_id)
1481{
1482 int port_idx;
1483
1484 port_id = q6audio_convert_virtual_to_portid(port_id);
1485 port_idx = adm_validate_and_get_port_index(port_id);
1486
1487 if (port_idx < 0) {
1488 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
1489 return;
1490 }
1491
1492 memcpy(port_channel_map[port_idx].channel_mapping, channel_map,
1493 PCM_FORMAT_MAX_NUM_CHANNEL);
1494 port_channel_map[port_idx].set_channel_map = true;
1495}
1496EXPORT_SYMBOL(adm_set_port_multi_ch_map);
1497
Laxminath Kasam468ece32017-11-28 12:40:22 +05301498static void adm_reset_data(void)
1499{
1500 int i, j;
1501
1502 apr_reset(this_adm.apr);
1503 for (i = 0; i < AFE_MAX_PORTS; i++) {
1504 for (j = 0; j < MAX_COPPS_PER_PORT; j++) {
1505 atomic_set(&this_adm.copp.id[i][j],
1506 RESET_COPP_ID);
1507 atomic_set(&this_adm.copp.cnt[i][j], 0);
1508 atomic_set(
1509 &this_adm.copp.topology[i][j], 0);
1510 atomic_set(&this_adm.copp.mode[i][j],
1511 0);
1512 atomic_set(&this_adm.copp.stat[i][j],
1513 0);
1514 atomic_set(&this_adm.copp.rate[i][j],
1515 0);
1516 atomic_set(
1517 &this_adm.copp.channels[i][j],
1518 0);
1519 atomic_set(
1520 &this_adm.copp.bit_width[i][j], 0);
1521 atomic_set(
1522 &this_adm.copp.app_type[i][j], 0);
1523 atomic_set(
1524 &this_adm.copp.acdb_id[i][j], 0);
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +05301525 atomic_set(
1526 &this_adm.copp.session_type[i][j], 0);
Laxminath Kasam468ece32017-11-28 12:40:22 +05301527 this_adm.copp.adm_status[i][j] =
1528 ADM_STATUS_CALIBRATION_REQUIRED;
1529 }
1530 }
1531 this_adm.apr = NULL;
1532 cal_utils_clear_cal_block_q6maps(ADM_MAX_CAL_TYPES,
1533 this_adm.cal_data);
1534 mutex_lock(&this_adm.cal_data
1535 [ADM_CUSTOM_TOP_CAL]->lock);
1536 this_adm.set_custom_topology = 1;
1537 mutex_unlock(&this_adm.cal_data[
1538 ADM_CUSTOM_TOP_CAL]->lock);
1539 rtac_clear_mapping(ADM_RTAC_CAL);
1540 /*
1541 * Free the ION memory and clear the map handles
1542 * for Source Tracking
1543 */
1544 if (this_adm.sourceTrackingData.memmap.paddr != 0) {
1545 msm_audio_ion_free(
1546 this_adm.sourceTrackingData.ion_client,
1547 this_adm.sourceTrackingData.ion_handle);
1548 this_adm.sourceTrackingData.ion_client = NULL;
1549 this_adm.sourceTrackingData.ion_handle = NULL;
1550 this_adm.sourceTrackingData.memmap.size = 0;
1551 this_adm.sourceTrackingData.memmap.kvaddr =
1552 NULL;
1553 this_adm.sourceTrackingData.memmap.paddr = 0;
1554 this_adm.sourceTrackingData.apr_cmd_status = -1;
1555 atomic_set(&this_adm.mem_map_handles[
1556 ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
1557 }
1558}
1559
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301560static int32_t adm_callback(struct apr_client_data *data, void *priv)
1561{
1562 uint32_t *payload;
Laxminath Kasam468ece32017-11-28 12:40:22 +05301563 int i, port_idx, copp_idx, idx, client_id;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301564
1565 if (data == NULL) {
1566 pr_err("%s: data parameter is null\n", __func__);
1567 return -EINVAL;
1568 }
1569
1570 payload = data->payload;
1571
1572 if (data->opcode == RESET_EVENTS) {
1573 pr_debug("%s: Reset event is received: %d %d apr[%pK]\n",
1574 __func__,
1575 data->reset_event, data->reset_proc, this_adm.apr);
Laxminath Kasam468ece32017-11-28 12:40:22 +05301576 if (this_adm.apr)
1577 adm_reset_data();
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301578 return 0;
1579 }
1580
1581 adm_callback_debug_print(data);
Vignesh Kulothungan35274962019-01-22 11:13:09 -08001582 if (data->payload_size >= sizeof(uint32_t)) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301583 copp_idx = (data->token) & 0XFF;
1584 port_idx = ((data->token) >> 16) & 0xFF;
1585 client_id = ((data->token) >> 8) & 0xFF;
1586 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
1587 pr_err("%s: Invalid port idx %d token %d\n",
1588 __func__, port_idx, data->token);
1589 return 0;
1590 }
1591 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
1592 pr_err("%s: Invalid copp idx %d token %d\n",
1593 __func__, copp_idx, data->token);
1594 return 0;
1595 }
1596 if (client_id < 0 || client_id >= ADM_CLIENT_ID_MAX) {
1597 pr_err("%s: Invalid client id %d\n", __func__,
1598 client_id);
1599 return 0;
1600 }
1601 if (data->opcode == APR_BASIC_RSP_RESULT) {
1602 pr_debug("%s: APR_BASIC_RSP_RESULT id 0x%x\n",
1603 __func__, payload[0]);
Vignesh Kulothungan35274962019-01-22 11:13:09 -08001604 if (!((client_id != ADM_CLIENT_ID_SOURCE_TRACKING) &&
1605 (payload[0] == ADM_CMD_SET_PP_PARAMS_V5))) {
1606 if (data->payload_size <
1607 (2 * sizeof(uint32_t))) {
1608 pr_err("%s: Invalid payload size %d\n",
1609 __func__, data->payload_size);
1610 return 0;
1611 }
1612 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301613 if (payload[1] != 0) {
1614 pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
1615 __func__, payload[0], payload[1]);
1616 }
1617 switch (payload[0]) {
1618 case ADM_CMD_SET_PP_PARAMS_V5:
1619 pr_debug("%s: ADM_CMD_SET_PP_PARAMS_V5\n",
1620 __func__);
1621 if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING)
1622 this_adm.sourceTrackingData.
1623 apr_cmd_status = payload[1];
1624 else if (rtac_make_adm_callback(payload,
1625 data->payload_size))
1626 break;
1627 /*
1628 * if soft volume is called and already
1629 * interrupted break out of the sequence here
1630 */
1631 case ADM_CMD_DEVICE_OPEN_V5:
1632 case ADM_CMD_DEVICE_CLOSE_V5:
1633 case ADM_CMD_DEVICE_OPEN_V6:
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02001634 case ADM_CMD_DEVICE_OPEN_V8:
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301635 pr_debug("%s: Basic callback received, wake up.\n",
1636 __func__);
1637 atomic_set(&this_adm.copp.stat[port_idx]
1638 [copp_idx], payload[1]);
1639 wake_up(
1640 &this_adm.copp.wait[port_idx][copp_idx]);
1641 break;
1642 case ADM_CMD_ADD_TOPOLOGIES:
1643 pr_debug("%s: callback received, ADM_CMD_ADD_TOPOLOGIES.\n",
1644 __func__);
1645 atomic_set(&this_adm.adm_stat, payload[1]);
1646 wake_up(&this_adm.adm_wait);
1647 break;
1648 case ADM_CMD_MATRIX_MAP_ROUTINGS_V5:
1649 case ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5:
1650 pr_debug("%s: Basic callback received, wake up.\n",
1651 __func__);
1652 atomic_set(&this_adm.matrix_map_stat,
1653 payload[1]);
1654 wake_up(&this_adm.matrix_map_wait);
1655 break;
1656 case ADM_CMD_SHARED_MEM_UNMAP_REGIONS:
1657 pr_debug("%s: ADM_CMD_SHARED_MEM_UNMAP_REGIONS\n",
1658 __func__);
1659 atomic_set(&this_adm.adm_stat, payload[1]);
1660 wake_up(&this_adm.adm_wait);
1661 break;
1662 case ADM_CMD_SHARED_MEM_MAP_REGIONS:
1663 pr_debug("%s: ADM_CMD_SHARED_MEM_MAP_REGIONS\n",
1664 __func__);
1665 /* Should only come here if there is an APR */
1666 /* error or malformed APR packet. Otherwise */
1667 /* response will be returned as */
1668 if (payload[1] != 0) {
1669 pr_err("%s: ADM map error, resuming\n",
1670 __func__);
1671 atomic_set(&this_adm.adm_stat,
1672 payload[1]);
1673 wake_up(&this_adm.adm_wait);
1674 }
1675 break;
1676 case ADM_CMD_GET_PP_PARAMS_V5:
1677 pr_debug("%s: ADM_CMD_GET_PP_PARAMS_V5\n",
1678 __func__);
1679 /* Should only come here if there is an APR */
1680 /* error or malformed APR packet. Otherwise */
1681 /* response will be returned as */
1682 /* ADM_CMDRSP_GET_PP_PARAMS_V5 */
1683 if (client_id ==
1684 ADM_CLIENT_ID_SOURCE_TRACKING) {
1685 this_adm.sourceTrackingData.
1686 apr_cmd_status = payload[1];
1687 if (payload[1] != 0)
1688 pr_err("%s: ADM get param error = %d\n",
1689 __func__, payload[1]);
1690
1691 atomic_set(&this_adm.copp.stat
1692 [port_idx][copp_idx],
1693 payload[1]);
1694 wake_up(&this_adm.copp.wait
1695 [port_idx][copp_idx]);
1696 } else {
1697 if (payload[1] != 0) {
1698 pr_err("%s: ADM get param error = %d, resuming\n",
1699 __func__, payload[1]);
1700
1701 rtac_make_adm_callback(payload,
1702 data->payload_size);
1703 }
1704 }
1705 break;
1706 case ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5:
1707 pr_debug("%s: ADM_CMD_SET_PSPD_MTMX_STRTR_PARAMS_V5\n",
1708 __func__);
1709 atomic_set(&this_adm.copp.stat[port_idx]
1710 [copp_idx], payload[1]);
1711 wake_up(
1712 &this_adm.copp.wait[port_idx][copp_idx]);
1713 break;
1714 case ADM_CMD_GET_PP_TOPO_MODULE_LIST:
1715 pr_debug("%s:ADM_CMD_GET_PP_TOPO_MODULE_LIST\n",
1716 __func__);
1717 if (payload[1] != 0)
1718 pr_err("%s: ADM get topo list error = %d,\n",
1719 __func__, payload[1]);
1720 break;
1721 default:
1722 pr_err("%s: Unknown Cmd: 0x%x\n", __func__,
1723 payload[0]);
1724 break;
1725 }
1726 return 0;
1727 }
1728
1729 switch (data->opcode) {
1730 case ADM_CMDRSP_DEVICE_OPEN_V5:
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02001731 case ADM_CMDRSP_DEVICE_OPEN_V6:
1732 case ADM_CMDRSP_DEVICE_OPEN_V8: {
1733 struct adm_cmd_rsp_device_open_v5 *open =
1734 (struct adm_cmd_rsp_device_open_v5 *)data->payload;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301735
Vignesh Kulothungan35274962019-01-22 11:13:09 -08001736 if (data->payload_size <
1737 sizeof(struct adm_cmd_rsp_device_open_v5)) {
1738 pr_err("%s: Invalid payload size %d\n",
1739 __func__, data->payload_size);
1740 return 0;
1741 }
1742 open =
1743 (struct adm_cmd_rsp_device_open_v5 *)data->payload;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301744 if (open->copp_id == INVALID_COPP_ID) {
1745 pr_err("%s: invalid coppid rxed %d\n",
1746 __func__, open->copp_id);
1747 atomic_set(&this_adm.copp.stat[port_idx]
1748 [copp_idx], ADSP_EBADPARAM);
1749 wake_up(
1750 &this_adm.copp.wait[port_idx][copp_idx]);
1751 break;
1752 }
1753 atomic_set(&this_adm.copp.stat
1754 [port_idx][copp_idx], payload[0]);
1755 atomic_set(&this_adm.copp.id[port_idx][copp_idx],
1756 open->copp_id);
1757 pr_debug("%s: coppid rxed=%d\n", __func__,
1758 open->copp_id);
1759 wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
1760 }
1761 break;
1762 case ADM_CMDRSP_GET_PP_PARAMS_V5:
1763 pr_debug("%s: ADM_CMDRSP_GET_PP_PARAMS_V5\n", __func__);
1764 if (payload[0] != 0)
1765 pr_err("%s: ADM_CMDRSP_GET_PP_PARAMS_V5 returned error = 0x%x\n",
1766 __func__, payload[0]);
1767 if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING)
1768 this_adm.sourceTrackingData.apr_cmd_status =
1769 payload[0];
1770 else if (rtac_make_adm_callback(payload,
1771 data->payload_size))
1772 break;
1773
1774 idx = ADM_GET_PARAMETER_LENGTH * copp_idx;
1775 if ((payload[0] == 0) && (data->payload_size >
1776 (4 * sizeof(*payload))) &&
Soumya Managoli61769582019-09-06 12:35:58 +05301777 (data->payload_size -
1778 (4 * sizeof(*payload)) >=
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301779 payload[3]) &&
1780 (ARRAY_SIZE(adm_get_parameters) >
1781 idx) &&
1782 (ARRAY_SIZE(adm_get_parameters)-idx-1 >=
1783 payload[3])) {
1784 adm_get_parameters[idx] = payload[3] /
1785 sizeof(uint32_t);
1786 /*
1787 * payload[3] is param_size which is
1788 * expressed in number of bytes
1789 */
1790 pr_debug("%s: GET_PP PARAM:received parameter length: 0x%x\n",
1791 __func__, adm_get_parameters[idx]);
1792 /* storing param size then params */
1793 for (i = 0; i < payload[3] /
1794 sizeof(uint32_t); i++)
1795 adm_get_parameters[idx+1+i] =
1796 payload[4+i];
1797 } else if (payload[0] == 0) {
1798 adm_get_parameters[idx] = -1;
1799 pr_err("%s: Out of band case, setting size to %d\n",
1800 __func__, adm_get_parameters[idx]);
1801 } else {
1802 adm_get_parameters[idx] = -1;
1803 pr_err("%s: GET_PP_PARAMS failed, setting size to %d\n",
1804 __func__, adm_get_parameters[idx]);
1805 }
1806 atomic_set(&this_adm.copp.stat
1807 [port_idx][copp_idx], payload[0]);
1808 wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
1809 break;
1810 case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST:
1811 pr_debug("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST\n",
1812 __func__);
1813 if (payload[0] != 0) {
1814 pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST",
1815 __func__);
1816 pr_err(":err = 0x%x\n", payload[0]);
Vignesh Kulothungan35274962019-01-22 11:13:09 -08001817 } else if (data->payload_size >=
1818 (2 * sizeof(uint32_t))) {
Soumya Managolie668fa22019-08-28 16:47:22 +05301819 if ((payload[1] >
Vignesh Kulothungan35274962019-01-22 11:13:09 -08001820 ((ADM_GET_TOPO_MODULE_LIST_LENGTH /
Soumya Managolie668fa22019-08-28 16:47:22 +05301821 sizeof(uint32_t)) - 1)) ||
1822 ((data->payload_size -
1823 (2 * sizeof(uint32_t))) <
1824 (payload[1] * sizeof(uint32_t)))) {
Vignesh Kulothungan35274962019-01-22 11:13:09 -08001825 pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST",
1826 __func__);
1827 pr_err(":size = %d\n", payload[1]);
1828 } else {
1829 idx = ADM_GET_TOPO_MODULE_LIST_LENGTH *
1830 copp_idx;
1831 pr_debug("%s:Num modules payload[1] %d\n",
1832 __func__, payload[1]);
1833 adm_module_topo_list[idx] = payload[1];
1834 for (i = 1; i <= payload[1]; i++) {
1835 adm_module_topo_list[idx+i] =
1836 payload[1+i];
1837 pr_debug("%s:payload[%d] = %x\n",
Soumya Managolie668fa22019-08-28 16:47:22 +05301838 __func__, (i+1),
1839 payload[1+i]);
Vignesh Kulothungan35274962019-01-22 11:13:09 -08001840 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301841 }
Vignesh Kulothungan35274962019-01-22 11:13:09 -08001842 } else
1843 pr_err("%s: Invalid payload size %d\n",
1844 __func__, data->payload_size);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301845 atomic_set(&this_adm.copp.stat
1846 [port_idx][copp_idx], payload[0]);
1847 wake_up(&this_adm.copp.wait[port_idx][copp_idx]);
1848 break;
1849 case ADM_CMDRSP_SHARED_MEM_MAP_REGIONS:
1850 pr_debug("%s: ADM_CMDRSP_SHARED_MEM_MAP_REGIONS\n",
1851 __func__);
1852 atomic_set(&this_adm.mem_map_handles[
1853 atomic_read(&this_adm.mem_map_index)],
1854 *payload);
1855 atomic_set(&this_adm.adm_stat, 0);
1856 wake_up(&this_adm.adm_wait);
1857 break;
1858 default:
1859 pr_err("%s: Unknown cmd:0x%x\n", __func__,
1860 data->opcode);
1861 break;
1862 }
1863 }
1864 return 0;
1865}
1866
1867static int adm_memory_map_regions(phys_addr_t *buf_add, uint32_t mempool_id,
1868 uint32_t *bufsz, uint32_t bufcnt)
1869{
1870 struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
1871 struct avs_shared_map_region_payload *mregions = NULL;
1872 void *mmap_region_cmd = NULL;
1873 void *payload = NULL;
1874 int ret = 0;
1875 int i = 0;
1876 int cmd_size = 0;
1877
1878 pr_debug("%s:\n", __func__);
1879 if (this_adm.apr == NULL) {
1880 this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
1881 0xFFFFFFFF, &this_adm);
1882 if (this_adm.apr == NULL) {
1883 pr_err("%s: Unable to register ADM\n", __func__);
1884 ret = -ENODEV;
1885 return ret;
1886 }
1887 rtac_set_adm_handle(this_adm.apr);
1888 }
1889
1890 cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
1891 + sizeof(struct avs_shared_map_region_payload)
1892 * bufcnt;
1893
1894 mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
1895 if (!mmap_region_cmd)
1896 return -ENOMEM;
1897
1898 mmap_regions = (struct avs_cmd_shared_mem_map_regions *)mmap_region_cmd;
1899 mmap_regions->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1900 APR_HDR_LEN(APR_HDR_SIZE),
1901 APR_PKT_VER);
1902 mmap_regions->hdr.pkt_size = cmd_size;
1903 mmap_regions->hdr.src_port = 0;
1904
1905 mmap_regions->hdr.dest_port = 0;
1906 mmap_regions->hdr.token = 0;
1907 mmap_regions->hdr.opcode = ADM_CMD_SHARED_MEM_MAP_REGIONS;
1908 mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL & 0x00ff;
1909 mmap_regions->num_regions = bufcnt & 0x00ff;
1910 mmap_regions->property_flag = 0x00;
1911
1912 pr_debug("%s: map_regions->num_regions = %d\n", __func__,
1913 mmap_regions->num_regions);
1914 payload = ((u8 *) mmap_region_cmd +
1915 sizeof(struct avs_cmd_shared_mem_map_regions));
1916 mregions = (struct avs_shared_map_region_payload *)payload;
1917
1918 for (i = 0; i < bufcnt; i++) {
1919 mregions->shm_addr_lsw = lower_32_bits(buf_add[i]);
1920 mregions->shm_addr_msw =
1921 msm_audio_populate_upper_32_bits(buf_add[i]);
1922 mregions->mem_size_bytes = bufsz[i];
1923 ++mregions;
1924 }
1925
1926 atomic_set(&this_adm.adm_stat, -1);
1927 ret = apr_send_pkt(this_adm.apr, (uint32_t *) mmap_region_cmd);
1928 if (ret < 0) {
1929 pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__,
1930 mmap_regions->hdr.opcode, ret);
1931 ret = -EINVAL;
1932 goto fail_cmd;
1933 }
1934
1935 ret = wait_event_timeout(this_adm.adm_wait,
1936 atomic_read(&this_adm.adm_stat) >= 0,
1937 5 * HZ);
1938 if (!ret) {
1939 pr_err("%s: timeout. waited for memory_map\n", __func__);
1940 ret = -EINVAL;
1941 goto fail_cmd;
1942 } else if (atomic_read(&this_adm.adm_stat) > 0) {
1943 pr_err("%s: DSP returned error[%s]\n",
1944 __func__, adsp_err_get_err_str(
1945 atomic_read(&this_adm.adm_stat)));
1946 ret = adsp_err_get_lnx_err_code(
1947 atomic_read(&this_adm.adm_stat));
1948 goto fail_cmd;
1949 }
1950fail_cmd:
1951 kfree(mmap_region_cmd);
1952 return ret;
1953}
1954
1955static int adm_memory_unmap_regions(void)
1956{
1957 struct avs_cmd_shared_mem_unmap_regions unmap_regions;
1958 int ret = 0;
1959
1960 pr_debug("%s:\n", __func__);
1961 if (this_adm.apr == NULL) {
1962 pr_err("%s: APR handle NULL\n", __func__);
1963 return -EINVAL;
1964 }
1965
1966 unmap_regions.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
1967 APR_HDR_LEN(APR_HDR_SIZE),
1968 APR_PKT_VER);
1969 unmap_regions.hdr.pkt_size = sizeof(unmap_regions);
1970 unmap_regions.hdr.src_port = 0;
1971 unmap_regions.hdr.dest_port = 0;
1972 unmap_regions.hdr.token = 0;
1973 unmap_regions.hdr.opcode = ADM_CMD_SHARED_MEM_UNMAP_REGIONS;
1974 unmap_regions.mem_map_handle = atomic_read(&this_adm.
1975 mem_map_handles[atomic_read(&this_adm.mem_map_index)]);
1976 atomic_set(&this_adm.adm_stat, -1);
1977 ret = apr_send_pkt(this_adm.apr, (uint32_t *) &unmap_regions);
1978 if (ret < 0) {
1979 pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__,
1980 unmap_regions.hdr.opcode, ret);
1981 ret = -EINVAL;
1982 goto fail_cmd;
1983 }
1984
1985 ret = wait_event_timeout(this_adm.adm_wait,
1986 atomic_read(&this_adm.adm_stat) >= 0,
1987 5 * HZ);
1988 if (!ret) {
1989 pr_err("%s: timeout. waited for memory_unmap\n",
1990 __func__);
1991 ret = -EINVAL;
1992 goto fail_cmd;
1993 } else if (atomic_read(&this_adm.adm_stat) > 0) {
1994 pr_err("%s: DSP returned error[%s]\n",
1995 __func__, adsp_err_get_err_str(
1996 atomic_read(&this_adm.adm_stat)));
1997 ret = adsp_err_get_lnx_err_code(
1998 atomic_read(&this_adm.adm_stat));
1999 goto fail_cmd;
2000 } else {
2001 pr_debug("%s: Unmap handle 0x%x succeeded\n", __func__,
2002 unmap_regions.mem_map_handle);
2003 }
2004fail_cmd:
2005 return ret;
2006}
2007
2008static int remap_cal_data(struct cal_block_data *cal_block, int cal_index)
2009{
2010 int ret = 0;
2011
2012 if (cal_block->map_data.ion_client == NULL) {
2013 pr_err("%s: No ION allocation for cal index %d!\n",
2014 __func__, cal_index);
2015 ret = -EINVAL;
2016 goto done;
2017 }
2018
2019 if ((cal_block->map_data.map_size > 0) &&
2020 (cal_block->map_data.q6map_handle == 0)) {
2021 atomic_set(&this_adm.mem_map_index, cal_index);
2022 ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
2023 (uint32_t *)&cal_block->map_data.map_size, 1);
2024 if (ret < 0) {
2025 pr_err("%s: ADM mmap did not work! size = %zd ret %d\n",
2026 __func__,
2027 cal_block->map_data.map_size, ret);
2028 pr_debug("%s: ADM mmap did not work! addr = 0x%pK, size = %zd ret %d\n",
2029 __func__,
2030 &cal_block->cal_data.paddr,
2031 cal_block->map_data.map_size, ret);
2032 goto done;
2033 }
2034 cal_block->map_data.q6map_handle = atomic_read(&this_adm.
2035 mem_map_handles[cal_index]);
2036 }
2037done:
2038 return ret;
2039}
2040
2041static void send_adm_custom_topology(void)
2042{
2043 struct cal_block_data *cal_block = NULL;
2044 struct cmd_set_topologies adm_top;
2045 int cal_index = ADM_CUSTOM_TOP_CAL;
2046 int result;
2047
2048 if (this_adm.cal_data[cal_index] == NULL)
2049 goto done;
2050
2051 mutex_lock(&this_adm.cal_data[cal_index]->lock);
2052 if (!this_adm.set_custom_topology)
2053 goto unlock;
2054 this_adm.set_custom_topology = 0;
2055
2056 cal_block = cal_utils_get_only_cal_block(this_adm.cal_data[cal_index]);
Vikram Pandurangad3b58cc2017-09-27 12:17:36 -07002057 if (cal_block == NULL || cal_utils_is_cal_stale(cal_block))
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302058 goto unlock;
2059
2060 pr_debug("%s: Sending cal_index %d\n", __func__, cal_index);
2061
2062 result = remap_cal_data(cal_block, cal_index);
2063 if (result) {
2064 pr_err("%s: Remap_cal_data failed for cal %d!\n",
2065 __func__, cal_index);
2066 goto unlock;
2067 }
2068 atomic_set(&this_adm.mem_map_index, cal_index);
2069 atomic_set(&this_adm.mem_map_handles[cal_index],
2070 cal_block->map_data.q6map_handle);
2071
2072 if (cal_block->cal_data.size == 0) {
2073 pr_debug("%s: No ADM cal to send\n", __func__);
2074 goto unlock;
2075 }
2076
2077 adm_top.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2078 APR_HDR_LEN(20), APR_PKT_VER);
2079 adm_top.hdr.pkt_size = sizeof(adm_top);
2080 adm_top.hdr.src_svc = APR_SVC_ADM;
2081 adm_top.hdr.src_domain = APR_DOMAIN_APPS;
2082 adm_top.hdr.src_port = 0;
2083 adm_top.hdr.dest_svc = APR_SVC_ADM;
2084 adm_top.hdr.dest_domain = APR_DOMAIN_ADSP;
2085 adm_top.hdr.dest_port = 0;
2086 adm_top.hdr.token = 0;
2087 adm_top.hdr.opcode = ADM_CMD_ADD_TOPOLOGIES;
2088 adm_top.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr);
2089 adm_top.payload_addr_msw = msm_audio_populate_upper_32_bits(
2090 cal_block->cal_data.paddr);
2091 adm_top.mem_map_handle = cal_block->map_data.q6map_handle;
2092 adm_top.payload_size = cal_block->cal_data.size;
2093
2094 atomic_set(&this_adm.adm_stat, -1);
2095 pr_debug("%s: Sending ADM_CMD_ADD_TOPOLOGIES payload = 0x%pK, size = %d\n",
2096 __func__, &cal_block->cal_data.paddr,
2097 adm_top.payload_size);
2098 result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_top);
2099 if (result < 0) {
2100 pr_err("%s: Set topologies failed payload size = %zd result %d\n",
2101 __func__, cal_block->cal_data.size, result);
2102 goto unlock;
2103 }
2104 /* Wait for the callback */
2105 result = wait_event_timeout(this_adm.adm_wait,
2106 atomic_read(&this_adm.adm_stat) >= 0,
2107 msecs_to_jiffies(TIMEOUT_MS));
2108 if (!result) {
2109 pr_err("%s: Set topologies timed out payload size = %zd\n",
2110 __func__, cal_block->cal_data.size);
2111 goto unlock;
2112 } else if (atomic_read(&this_adm.adm_stat) > 0) {
2113 pr_err("%s: DSP returned error[%s]\n",
2114 __func__, adsp_err_get_err_str(
2115 atomic_read(&this_adm.adm_stat)));
2116 result = adsp_err_get_lnx_err_code(
2117 atomic_read(&this_adm.adm_stat));
2118 goto unlock;
2119 }
2120unlock:
2121 mutex_unlock(&this_adm.cal_data[cal_index]->lock);
2122done:
2123 return;
2124}
2125
2126static int send_adm_cal_block(int port_id, int copp_idx,
2127 struct cal_block_data *cal_block, int perf_mode,
2128 int app_type, int acdb_id, int sample_rate)
2129{
2130 s32 result = 0;
2131 struct adm_cmd_set_pp_params_v5 adm_params;
2132 int port_idx;
2133
2134 pr_debug("%s: Port id 0x%x sample_rate %d ,\n", __func__,
2135 port_id, sample_rate);
2136 port_id = afe_convert_virtual_to_portid(port_id);
2137 port_idx = adm_validate_and_get_port_index(port_id);
2138 if (port_idx < 0) {
2139 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
2140 return -EINVAL;
2141 }
2142 if (!cal_block) {
2143 pr_debug("%s: No ADM cal to send for port_id = 0x%x!\n",
2144 __func__, port_id);
2145 result = -EINVAL;
2146 goto done;
2147 }
2148 if (cal_block->cal_data.size <= 0) {
2149 pr_debug("%s: No ADM cal send for port_id = 0x%x!\n",
2150 __func__, port_id);
2151 result = -EINVAL;
2152 goto done;
2153 }
2154
2155 if (perf_mode == LEGACY_PCM_MODE &&
2156 ((atomic_read(&this_adm.copp.topology[port_idx][copp_idx])) ==
2157 DS2_ADM_COPP_TOPOLOGY_ID)) {
2158 pr_err("%s: perf_mode %d, topology 0x%x\n", __func__, perf_mode,
2159 atomic_read(
2160 &this_adm.copp.topology[port_idx][copp_idx]));
2161 goto done;
2162 }
2163
2164 adm_params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2165 APR_HDR_LEN(20), APR_PKT_VER);
2166 adm_params.hdr.pkt_size = sizeof(adm_params);
2167 adm_params.hdr.src_svc = APR_SVC_ADM;
2168 adm_params.hdr.src_domain = APR_DOMAIN_APPS;
2169 adm_params.hdr.src_port = port_id;
2170 adm_params.hdr.dest_svc = APR_SVC_ADM;
2171 adm_params.hdr.dest_domain = APR_DOMAIN_ADSP;
2172
2173 adm_params.hdr.token = port_idx << 16 | copp_idx;
2174 adm_params.hdr.dest_port =
2175 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
2176 adm_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
2177 adm_params.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr);
2178 adm_params.payload_addr_msw = msm_audio_populate_upper_32_bits(
2179 cal_block->cal_data.paddr);
2180 adm_params.mem_map_handle = cal_block->map_data.q6map_handle;
2181 adm_params.payload_size = cal_block->cal_data.size;
2182
2183 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2184 pr_debug("%s: Sending SET_PARAMS payload = 0x%pK, size = %d\n",
2185 __func__, &cal_block->cal_data.paddr,
2186 adm_params.payload_size);
2187 result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_params);
2188 if (result < 0) {
2189 pr_err("%s: Set params failed port 0x%x result %d\n",
2190 __func__, port_id, result);
2191 pr_debug("%s: Set params failed port = 0x%x payload = 0x%pK result %d\n",
2192 __func__, port_id, &cal_block->cal_data.paddr, result);
2193 result = -EINVAL;
2194 goto done;
2195 }
2196 /* Wait for the callback */
2197 result = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2198 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
2199 msecs_to_jiffies(TIMEOUT_MS));
2200 if (!result) {
2201 pr_err("%s: Set params timed out port = 0x%x\n",
2202 __func__, port_id);
2203 pr_debug("%s: Set params timed out port = 0x%x, payload = 0x%pK\n",
2204 __func__, port_id, &cal_block->cal_data.paddr);
2205 result = -EINVAL;
2206 goto done;
2207 } else if (atomic_read(&this_adm.copp.stat
2208 [port_idx][copp_idx]) > 0) {
2209 pr_err("%s: DSP returned error[%s]\n",
2210 __func__, adsp_err_get_err_str(
2211 atomic_read(&this_adm.copp.stat
2212 [port_idx][copp_idx])));
2213 result = adsp_err_get_lnx_err_code(
2214 atomic_read(&this_adm.copp.stat
2215 [port_idx][copp_idx]));
2216 goto done;
2217 }
2218
2219done:
2220 return result;
2221}
2222
2223static struct cal_block_data *adm_find_cal_by_path(int cal_index, int path)
2224{
2225 struct list_head *ptr, *next;
2226 struct cal_block_data *cal_block = NULL;
2227 struct audio_cal_info_audproc *audproc_cal_info = NULL;
2228 struct audio_cal_info_audvol *audvol_cal_info = NULL;
2229
2230 pr_debug("%s:\n", __func__);
2231
2232 list_for_each_safe(ptr, next,
2233 &this_adm.cal_data[cal_index]->cal_blocks) {
2234
2235 cal_block = list_entry(ptr,
2236 struct cal_block_data, list);
2237
Vikram Pandurangad3b58cc2017-09-27 12:17:36 -07002238 if (cal_utils_is_cal_stale(cal_block))
2239 continue;
2240
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302241 if (cal_index == ADM_AUDPROC_CAL ||
Bhalchandra Gajareface2762018-05-10 14:16:49 -07002242 cal_index == ADM_LSM_AUDPROC_CAL ||
2243 cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302244 audproc_cal_info = cal_block->cal_info;
2245 if ((audproc_cal_info->path == path) &&
2246 (cal_block->cal_data.size > 0))
2247 return cal_block;
2248 } else if (cal_index == ADM_AUDVOL_CAL) {
2249 audvol_cal_info = cal_block->cal_info;
2250 if ((audvol_cal_info->path == path) &&
2251 (cal_block->cal_data.size > 0))
2252 return cal_block;
2253 }
2254 }
2255 pr_debug("%s: Can't find ADM cal for cal_index %d, path %d\n",
2256 __func__, cal_index, path);
2257 return NULL;
2258}
2259
2260static struct cal_block_data *adm_find_cal_by_app_type(int cal_index, int path,
2261 int app_type)
2262{
2263 struct list_head *ptr, *next;
2264 struct cal_block_data *cal_block = NULL;
2265 struct audio_cal_info_audproc *audproc_cal_info = NULL;
2266 struct audio_cal_info_audvol *audvol_cal_info = NULL;
2267
2268 pr_debug("%s\n", __func__);
2269
2270 list_for_each_safe(ptr, next,
2271 &this_adm.cal_data[cal_index]->cal_blocks) {
2272
2273 cal_block = list_entry(ptr,
2274 struct cal_block_data, list);
2275
Vikram Pandurangad3b58cc2017-09-27 12:17:36 -07002276 if (cal_utils_is_cal_stale(cal_block))
2277 continue;
2278
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302279 if (cal_index == ADM_AUDPROC_CAL ||
Bhalchandra Gajareface2762018-05-10 14:16:49 -07002280 cal_index == ADM_LSM_AUDPROC_CAL ||
2281 cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302282 audproc_cal_info = cal_block->cal_info;
2283 if ((audproc_cal_info->path == path) &&
2284 (audproc_cal_info->app_type == app_type) &&
2285 (cal_block->cal_data.size > 0))
2286 return cal_block;
2287 } else if (cal_index == ADM_AUDVOL_CAL) {
2288 audvol_cal_info = cal_block->cal_info;
2289 if ((audvol_cal_info->path == path) &&
2290 (audvol_cal_info->app_type == app_type) &&
2291 (cal_block->cal_data.size > 0))
2292 return cal_block;
2293 }
2294 }
2295 pr_debug("%s: Can't find ADM cali for cal_index %d, path %d, app %d, defaulting to search by path\n",
2296 __func__, cal_index, path, app_type);
2297 return adm_find_cal_by_path(cal_index, path);
2298}
2299
2300
2301static struct cal_block_data *adm_find_cal(int cal_index, int path,
2302 int app_type, int acdb_id,
2303 int sample_rate)
2304{
2305 struct list_head *ptr, *next;
2306 struct cal_block_data *cal_block = NULL;
2307 struct audio_cal_info_audproc *audproc_cal_info = NULL;
2308 struct audio_cal_info_audvol *audvol_cal_info = NULL;
2309
2310 pr_debug("%s:\n", __func__);
2311
2312 list_for_each_safe(ptr, next,
2313 &this_adm.cal_data[cal_index]->cal_blocks) {
2314
2315 cal_block = list_entry(ptr,
2316 struct cal_block_data, list);
Vikram Pandurangad3b58cc2017-09-27 12:17:36 -07002317 if (cal_utils_is_cal_stale(cal_block))
2318 continue;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302319
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302320 if (cal_index == ADM_AUDPROC_CAL ||
Bhalchandra Gajareface2762018-05-10 14:16:49 -07002321 cal_index == ADM_LSM_AUDPROC_CAL ||
2322 cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302323 audproc_cal_info = cal_block->cal_info;
2324 if ((audproc_cal_info->path == path) &&
2325 (audproc_cal_info->app_type == app_type) &&
2326 (audproc_cal_info->acdb_id == acdb_id) &&
2327 (audproc_cal_info->sample_rate == sample_rate) &&
2328 (cal_block->cal_data.size > 0))
2329 return cal_block;
2330 } else if (cal_index == ADM_AUDVOL_CAL) {
2331 audvol_cal_info = cal_block->cal_info;
2332 if ((audvol_cal_info->path == path) &&
2333 (audvol_cal_info->app_type == app_type) &&
2334 (audvol_cal_info->acdb_id == acdb_id) &&
2335 (cal_block->cal_data.size > 0))
2336 return cal_block;
2337 }
2338 }
2339 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",
2340 __func__, cal_index, path, app_type, acdb_id, sample_rate);
2341 return adm_find_cal_by_app_type(cal_index, path, app_type);
2342}
2343
2344static int adm_remap_and_send_cal_block(int cal_index, int port_id,
2345 int copp_idx, struct cal_block_data *cal_block, int perf_mode,
2346 int app_type, int acdb_id, int sample_rate)
2347{
2348 int ret = 0;
2349
2350 pr_debug("%s: Sending cal_index cal %d\n", __func__, cal_index);
2351 ret = remap_cal_data(cal_block, cal_index);
2352 if (ret) {
2353 pr_err("%s: Remap_cal_data failed for cal %d!\n",
2354 __func__, cal_index);
2355 goto done;
2356 }
2357 ret = send_adm_cal_block(port_id, copp_idx, cal_block, perf_mode,
2358 app_type, acdb_id, sample_rate);
2359 if (ret < 0)
2360 pr_debug("%s: No cal sent for cal_index %d, port_id = 0x%x! ret %d sample_rate %d\n",
2361 __func__, cal_index, port_id, ret, sample_rate);
2362done:
2363 return ret;
2364}
2365
2366static void send_adm_cal_type(int cal_index, int path, int port_id,
2367 int copp_idx, int perf_mode, int app_type,
2368 int acdb_id, int sample_rate)
2369{
2370 struct cal_block_data *cal_block = NULL;
2371 int ret;
2372
2373 pr_debug("%s: cal index %d\n", __func__, cal_index);
2374
2375 if (this_adm.cal_data[cal_index] == NULL) {
2376 pr_debug("%s: cal_index %d not allocated!\n",
2377 __func__, cal_index);
2378 goto done;
2379 }
2380
2381 mutex_lock(&this_adm.cal_data[cal_index]->lock);
2382 cal_block = adm_find_cal(cal_index, path, app_type, acdb_id,
2383 sample_rate);
2384 if (cal_block == NULL)
2385 goto unlock;
2386
2387 ret = adm_remap_and_send_cal_block(cal_index, port_id, copp_idx,
2388 cal_block, perf_mode, app_type, acdb_id, sample_rate);
Vikram Pandurangad3b58cc2017-09-27 12:17:36 -07002389
2390 cal_utils_mark_cal_used(cal_block);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302391unlock:
2392 mutex_unlock(&this_adm.cal_data[cal_index]->lock);
2393done:
2394 return;
2395}
2396
2397static int get_cal_path(int path)
2398{
2399 if (path == 0x1)
2400 return RX_DEVICE;
2401 else
2402 return TX_DEVICE;
2403}
2404
2405static void send_adm_cal(int port_id, int copp_idx, int path, int perf_mode,
Aditya Bavanarifcd80ec2018-01-08 13:16:32 +05302406 int app_type, int acdb_id, int sample_rate,
2407 int passthr_mode)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302408{
2409 pr_debug("%s: port id 0x%x copp_idx %d\n", __func__, port_id, copp_idx);
2410
Bhalchandra Gajareface2762018-05-10 14:16:49 -07002411 if (passthr_mode != LISTEN) {
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302412 send_adm_cal_type(ADM_AUDPROC_CAL, path, port_id, copp_idx,
2413 perf_mode, app_type, acdb_id, sample_rate);
Bhalchandra Gajareface2762018-05-10 14:16:49 -07002414 } else {
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05302415 send_adm_cal_type(ADM_LSM_AUDPROC_CAL, path, port_id, copp_idx,
2416 perf_mode, app_type, acdb_id, sample_rate);
Bhalchandra Gajareface2762018-05-10 14:16:49 -07002417
2418 send_adm_cal_type(ADM_LSM_AUDPROC_PERSISTENT_CAL, path,
2419 port_id, copp_idx, perf_mode, app_type,
2420 acdb_id, sample_rate);
2421 }
2422
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302423 send_adm_cal_type(ADM_AUDVOL_CAL, path, port_id, copp_idx, perf_mode,
2424 app_type, acdb_id, sample_rate);
2425}
2426
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302427/**
2428 * adm_connect_afe_port -
2429 * command to send ADM connect AFE port
2430 *
2431 * @mode: value of mode for ADM connect AFE
2432 * @session_id: session active to connect
2433 * @port_id: Port ID number
2434 *
2435 * Returns 0 on success or error on failure
2436 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302437int adm_connect_afe_port(int mode, int session_id, int port_id)
2438{
2439 struct adm_cmd_connect_afe_port_v5 cmd;
2440 int ret = 0;
2441 int port_idx, copp_idx = 0;
2442
2443 pr_debug("%s: port_id: 0x%x session id:%d mode:%d\n", __func__,
2444 port_id, session_id, mode);
2445
2446 port_id = afe_convert_virtual_to_portid(port_id);
2447 port_idx = adm_validate_and_get_port_index(port_id);
2448 if (port_idx < 0) {
2449 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
2450 return -EINVAL;
2451 }
2452
2453 if (this_adm.apr == NULL) {
2454 this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
2455 0xFFFFFFFF, &this_adm);
2456 if (this_adm.apr == NULL) {
2457 pr_err("%s: Unable to register ADM\n", __func__);
2458 ret = -ENODEV;
2459 return ret;
2460 }
2461 rtac_set_adm_handle(this_adm.apr);
2462 }
2463 pr_debug("%s: Port ID 0x%x, index %d\n", __func__, port_id, port_idx);
2464
2465 cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
2466 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
2467 cmd.hdr.pkt_size = sizeof(cmd);
2468 cmd.hdr.src_svc = APR_SVC_ADM;
2469 cmd.hdr.src_domain = APR_DOMAIN_APPS;
2470 cmd.hdr.src_port = port_id;
2471 cmd.hdr.dest_svc = APR_SVC_ADM;
2472 cmd.hdr.dest_domain = APR_DOMAIN_ADSP;
2473 cmd.hdr.dest_port = 0; /* Ignored */
2474 cmd.hdr.token = port_idx << 16 | copp_idx;
2475 cmd.hdr.opcode = ADM_CMD_CONNECT_AFE_PORT_V5;
2476
2477 cmd.mode = mode;
2478 cmd.session_id = session_id;
2479 cmd.afe_port_id = port_id;
2480
2481 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
2482 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&cmd);
2483 if (ret < 0) {
2484 pr_err("%s: ADM enable for port_id: 0x%x failed ret %d\n",
2485 __func__, port_id, ret);
2486 ret = -EINVAL;
2487 goto fail_cmd;
2488 }
2489 /* Wait for the callback with copp id */
2490 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
2491 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
2492 msecs_to_jiffies(TIMEOUT_MS));
2493 if (!ret) {
2494 pr_err("%s: ADM connect timedout for port_id: 0x%x\n",
2495 __func__, port_id);
2496 ret = -EINVAL;
2497 goto fail_cmd;
2498 } else if (atomic_read(&this_adm.copp.stat
2499 [port_idx][copp_idx]) > 0) {
2500 pr_err("%s: DSP returned error[%s]\n",
2501 __func__, adsp_err_get_err_str(
2502 atomic_read(&this_adm.copp.stat
2503 [port_idx][copp_idx])));
2504 ret = adsp_err_get_lnx_err_code(
2505 atomic_read(&this_adm.copp.stat
2506 [port_idx][copp_idx]));
2507 goto fail_cmd;
2508 }
2509 atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]);
2510 return 0;
2511
2512fail_cmd:
2513
2514 return ret;
2515}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302516EXPORT_SYMBOL(adm_connect_afe_port);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302517
2518int adm_arrange_mch_map(struct adm_cmd_device_open_v5 *open, int path,
Rohit kumar5d860f42019-02-01 18:01:12 +05302519 int channel_mode, int port_idx)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302520{
2521 int rc = 0, idx;
2522
2523 memset(open->dev_channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
2524 switch (path) {
2525 case ADM_PATH_PLAYBACK:
2526 idx = ADM_MCH_MAP_IDX_PLAYBACK;
2527 break;
2528 case ADM_PATH_LIVE_REC:
2529 case ADM_PATH_NONLIVE_REC:
2530 idx = ADM_MCH_MAP_IDX_REC;
2531 break;
2532 default:
2533 goto non_mch_path;
2534 };
Rohit kumar5d860f42019-02-01 18:01:12 +05302535
2536 if ((open->dev_num_channel > 2) &&
2537 (port_channel_map[port_idx].set_channel_map ||
2538 multi_ch_maps[idx].set_channel_map)) {
2539 if (port_channel_map[port_idx].set_channel_map)
2540 memcpy(open->dev_channel_mapping,
2541 port_channel_map[port_idx].channel_mapping,
2542 PCM_FORMAT_MAX_NUM_CHANNEL);
2543 else
2544 memcpy(open->dev_channel_mapping,
2545 multi_ch_maps[idx].channel_mapping,
2546 PCM_FORMAT_MAX_NUM_CHANNEL);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302547 } else {
2548 if (channel_mode == 1) {
2549 open->dev_channel_mapping[0] = PCM_CHANNEL_FC;
2550 } else if (channel_mode == 2) {
2551 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2552 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2553 } else if (channel_mode == 3) {
2554 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2555 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2556 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2557 } else if (channel_mode == 4) {
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_LS;
2561 open->dev_channel_mapping[3] = PCM_CHANNEL_RS;
2562 } else if (channel_mode == 5) {
2563 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2564 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2565 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2566 open->dev_channel_mapping[3] = PCM_CHANNEL_LS;
2567 open->dev_channel_mapping[4] = PCM_CHANNEL_RS;
2568 } else if (channel_mode == 6) {
2569 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2570 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2571 open->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2572 open->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2573 open->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2574 open->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2575 } else if (channel_mode == 7) {
2576 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2577 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2578 open->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2579 open->dev_channel_mapping[3] = PCM_CHANNEL_LFE;
2580 open->dev_channel_mapping[4] = PCM_CHANNEL_LB;
2581 open->dev_channel_mapping[5] = PCM_CHANNEL_RB;
2582 open->dev_channel_mapping[6] = PCM_CHANNEL_CS;
2583 } else if (channel_mode == 8) {
2584 open->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2585 open->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2586 open->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2587 open->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2588 open->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2589 open->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2590 open->dev_channel_mapping[6] = PCM_CHANNEL_LB;
2591 open->dev_channel_mapping[7] = PCM_CHANNEL_RB;
2592 } else {
2593 pr_err("%s: invalid num_chan %d\n", __func__,
2594 channel_mode);
2595 rc = -EINVAL;
2596 goto inval_ch_mod;
2597 }
2598 }
2599
2600non_mch_path:
2601inval_ch_mod:
2602 return rc;
2603}
2604
2605int adm_arrange_mch_ep2_map(struct adm_cmd_device_open_v6 *open_v6,
2606 int channel_mode)
2607{
2608 int rc = 0;
2609
2610 memset(open_v6->dev_channel_mapping_eid2, 0,
2611 PCM_FORMAT_MAX_NUM_CHANNEL);
2612
2613 if (channel_mode == 1) {
2614 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FC;
2615 } else if (channel_mode == 2) {
2616 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2617 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2618 } else if (channel_mode == 3) {
2619 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2620 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2621 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC;
2622 } else if (channel_mode == 4) {
2623 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2624 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2625 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LS;
2626 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_RS;
2627 } else if (channel_mode == 5) {
2628 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2629 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2630 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_FC;
2631 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_LS;
2632 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_RS;
2633 } else if (channel_mode == 6) {
2634 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2635 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2636 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE;
2637 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC;
2638 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS;
2639 open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS;
2640 } else if (channel_mode == 8) {
2641 open_v6->dev_channel_mapping_eid2[0] = PCM_CHANNEL_FL;
2642 open_v6->dev_channel_mapping_eid2[1] = PCM_CHANNEL_FR;
2643 open_v6->dev_channel_mapping_eid2[2] = PCM_CHANNEL_LFE;
2644 open_v6->dev_channel_mapping_eid2[3] = PCM_CHANNEL_FC;
2645 open_v6->dev_channel_mapping_eid2[4] = PCM_CHANNEL_LS;
2646 open_v6->dev_channel_mapping_eid2[5] = PCM_CHANNEL_RS;
2647 open_v6->dev_channel_mapping_eid2[6] = PCM_CHANNEL_LB;
2648 open_v6->dev_channel_mapping_eid2[7] = PCM_CHANNEL_RB;
2649 } else {
2650 pr_err("%s: invalid num_chan %d\n", __func__,
2651 channel_mode);
2652 rc = -EINVAL;
2653 }
2654
2655 return rc;
2656}
2657
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02002658static int adm_arrange_mch_map_v8(
2659 struct adm_device_endpoint_payload *ep_payload,
2660 int path,
2661 int channel_mode)
2662{
2663 int rc = 0, idx;
2664
2665 memset(ep_payload->dev_channel_mapping,
2666 0, PCM_FORMAT_MAX_NUM_CHANNEL_V8);
2667 switch (path) {
2668 case ADM_PATH_PLAYBACK:
2669 idx = ADM_MCH_MAP_IDX_PLAYBACK;
2670 break;
2671 case ADM_PATH_LIVE_REC:
2672 case ADM_PATH_NONLIVE_REC:
2673 idx = ADM_MCH_MAP_IDX_REC;
2674 break;
2675 default:
2676 goto non_mch_path;
2677 };
2678
2679 if ((ep_payload->dev_num_channel > 2) &&
2680 multi_ch_maps[idx].set_channel_map) {
2681 memcpy(ep_payload->dev_channel_mapping,
2682 multi_ch_maps[idx].channel_mapping,
2683 PCM_FORMAT_MAX_NUM_CHANNEL_V8);
2684 } else {
2685 if (channel_mode == 1) {
2686 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FC;
2687 } else if (channel_mode == 2) {
2688 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2689 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2690 } else if (channel_mode == 3) {
2691 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2692 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2693 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2694 } else if (channel_mode == 4) {
2695 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2696 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2697 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LS;
2698 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_RS;
2699 } else if (channel_mode == 5) {
2700 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2701 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2702 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2703 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LS;
2704 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_RS;
2705 } else if (channel_mode == 6) {
2706 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2707 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2708 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2709 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2710 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2711 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2712 } else if (channel_mode == 7) {
2713 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2714 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2715 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2716 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LFE;
2717 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
2718 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
2719 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_CS;
2720 } else if (channel_mode == 8) {
2721 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2722 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2723 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2724 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2725 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2726 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2727 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
2728 ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
2729 } else if (channel_mode == 10) {
2730 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2731 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2732 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2733 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2734 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
2735 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
2736 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS;
2737 ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS;
2738 ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
2739 ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
2740 } else if (channel_mode == 12) {
2741 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2742 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2743 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2744 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2745 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
2746 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
2747 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS;
2748 ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS;
2749 ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
2750 ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
2751 ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL;
2752 ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR;
2753 } else if (channel_mode == 16) {
2754 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2755 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2756 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2757 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2758 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LB;
2759 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RB;
2760 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LS;
2761 ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RS;
2762 ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
2763 ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
2764 ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL;
2765 ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR;
2766 ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC;
2767 ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC;
2768 ep_payload->dev_channel_mapping[14] = PCM_CHANNEL_RLC;
2769 ep_payload->dev_channel_mapping[15] = PCM_CHANNEL_RRC;
2770 } else {
2771 pr_err("%s: invalid num_chan %d\n", __func__,
2772 channel_mode);
2773 rc = -EINVAL;
2774 goto inval_ch_mod;
2775 }
2776 }
2777
2778non_mch_path:
2779inval_ch_mod:
2780 return rc;
2781}
2782
2783static int adm_arrange_mch_ep2_map_v8(
2784 struct adm_device_endpoint_payload *ep_payload,
2785 int channel_mode)
2786{
2787 int rc = 0;
2788
2789 memset(ep_payload->dev_channel_mapping, 0,
2790 PCM_FORMAT_MAX_NUM_CHANNEL_V8);
2791
2792 if (channel_mode == 1) {
2793 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FC;
2794 } else if (channel_mode == 2) {
2795 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2796 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2797 } else if (channel_mode == 3) {
2798 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2799 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2800 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2801 } else if (channel_mode == 4) {
2802 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2803 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2804 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LS;
2805 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_RS;
2806 } else if (channel_mode == 5) {
2807 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2808 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2809 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_FC;
2810 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_LS;
2811 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_RS;
2812 } else if (channel_mode == 6) {
2813 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2814 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2815 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2816 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2817 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2818 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2819 } else if (channel_mode == 8) {
2820 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2821 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2822 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2823 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2824 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2825 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2826 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
2827 ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
2828 } else if (channel_mode == 10) {
2829 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2830 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2831 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2832 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2833 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2834 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2835 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
2836 ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
2837 ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_CS;
2838 ep_payload->dev_channel_mapping[9] = PCM_CHANNELS;
2839 } else if (channel_mode == 12) {
2840 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2841 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2842 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2843 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2844 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2845 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2846 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
2847 ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
2848 ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_TFL;
2849 ep_payload->dev_channel_mapping[9] = PCM_CHANNEL_TFR;
2850 ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_TSL;
2851 ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_TSR;
2852 } else if (channel_mode == 16) {
2853 ep_payload->dev_channel_mapping[0] = PCM_CHANNEL_FL;
2854 ep_payload->dev_channel_mapping[1] = PCM_CHANNEL_FR;
2855 ep_payload->dev_channel_mapping[2] = PCM_CHANNEL_LFE;
2856 ep_payload->dev_channel_mapping[3] = PCM_CHANNEL_FC;
2857 ep_payload->dev_channel_mapping[4] = PCM_CHANNEL_LS;
2858 ep_payload->dev_channel_mapping[5] = PCM_CHANNEL_RS;
2859 ep_payload->dev_channel_mapping[6] = PCM_CHANNEL_LB;
2860 ep_payload->dev_channel_mapping[7] = PCM_CHANNEL_RB;
2861 ep_payload->dev_channel_mapping[8] = PCM_CHANNEL_CS;
2862 ep_payload->dev_channel_mapping[9] = PCM_CHANNELS;
2863 ep_payload->dev_channel_mapping[10] = PCM_CHANNEL_CVH;
2864 ep_payload->dev_channel_mapping[11] = PCM_CHANNEL_MS;
2865 ep_payload->dev_channel_mapping[12] = PCM_CHANNEL_FLC;
2866 ep_payload->dev_channel_mapping[13] = PCM_CHANNEL_FRC;
2867 ep_payload->dev_channel_mapping[14] = PCM_CHANNEL_RLC;
2868 ep_payload->dev_channel_mapping[15] = PCM_CHANNEL_RRC;
2869 } else {
2870 pr_err("%s: invalid num_chan %d\n", __func__,
2871 channel_mode);
2872 rc = -EINVAL;
2873 }
2874
2875 return rc;
2876}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05302877/**
2878 * adm_open -
2879 * command to send ADM open
2880 *
2881 * @port_id: port id number
2882 * @path: direction or ADM path type
2883 * @rate: sample rate of session
2884 * @channel_mode: number of channels set
2885 * @topology: topology active for this session
2886 * @perf_mode: performance mode like LL/ULL/..
2887 * @bit_width: bit width to set for copp
2888 * @app_type: App type used for this session
2889 * @acdb_id: ACDB ID of this device
2890 *
2891 * Returns 0 on success or error on failure
2892 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302893int adm_open(int port_id, int path, int rate, int channel_mode, int topology,
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +05302894 int perf_mode, uint16_t bit_width, int app_type, int acdb_id,
2895 int session_type)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302896{
2897 struct adm_cmd_device_open_v5 open;
2898 struct adm_cmd_device_open_v6 open_v6;
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02002899 struct adm_cmd_device_open_v8 open_v8;
2900 struct adm_device_endpoint_payload ep1_payload;
2901 struct adm_device_endpoint_payload ep2_payload;
2902 int ep1_payload_size = 0;
2903 int ep2_payload_size = 0;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302904 int ret = 0;
Asish Bhattacharya34504582017-08-08 12:55:01 +05302905 int port_idx, flags;
2906 int copp_idx = -1;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302907 int tmp_port = q6audio_get_port_id(port_id);
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02002908 void *adm_params = NULL;
2909 int param_size;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302910
2911 pr_debug("%s:port %#x path:%d rate:%d mode:%d perf_mode:%d,topo_id %d\n",
2912 __func__, port_id, path, rate, channel_mode, perf_mode,
2913 topology);
2914
2915 port_id = q6audio_convert_virtual_to_portid(port_id);
2916 port_idx = adm_validate_and_get_port_index(port_id);
2917 if (port_idx < 0) {
2918 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
2919 return -EINVAL;
2920 }
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02002921 if (channel_mode <= 0 || channel_mode > 32) {
2922 pr_err("%s: Invalid channel number 0x%x\n",
2923 __func__, channel_mode);
2924 return -EINVAL;
2925 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302926
2927 if (this_adm.apr == NULL) {
2928 this_adm.apr = apr_register("ADSP", "ADM", adm_callback,
2929 0xFFFFFFFF, &this_adm);
2930 if (this_adm.apr == NULL) {
2931 pr_err("%s: Unable to register ADM\n", __func__);
2932 return -ENODEV;
2933 }
2934 rtac_set_adm_handle(this_adm.apr);
2935 }
2936
2937 if (perf_mode == ULL_POST_PROCESSING_PCM_MODE) {
2938 flags = ADM_ULL_POST_PROCESSING_DEVICE_SESSION;
2939 if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) ||
2940 (topology == DS2_ADM_COPP_TOPOLOGY_ID) ||
2941 (topology == SRS_TRUMEDIA_TOPOLOGY_ID))
2942 topology = DEFAULT_COPP_TOPOLOGY;
2943 } else if (perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) {
2944 flags = ADM_ULTRA_LOW_LATENCY_DEVICE_SESSION;
2945 topology = NULL_COPP_TOPOLOGY;
2946 rate = ULL_SUPPORTED_SAMPLE_RATE;
2947 bit_width = ULL_SUPPORTED_BITS_PER_SAMPLE;
2948 } else if (perf_mode == LOW_LATENCY_PCM_MODE) {
2949 flags = ADM_LOW_LATENCY_DEVICE_SESSION;
2950 if ((topology == DOLBY_ADM_COPP_TOPOLOGY_ID) ||
2951 (topology == DS2_ADM_COPP_TOPOLOGY_ID) ||
2952 (topology == SRS_TRUMEDIA_TOPOLOGY_ID))
2953 topology = DEFAULT_COPP_TOPOLOGY;
2954 } else {
2955 if ((path == ADM_PATH_COMPRESSED_RX) ||
2956 (path == ADM_PATH_COMPRESSED_TX))
2957 flags = 0;
2958 else
2959 flags = ADM_LEGACY_DEVICE_SESSION;
2960 }
2961
Laxminath Kasam8f7ccc22017-08-28 17:35:04 +05302962 if ((topology == VPM_TX_SM_ECNS_V2_COPP_TOPOLOGY) ||
Bala Kishore Pati798cbf82018-10-22 11:58:41 +05302963 (topology == VPM_TX_SM_ECNS_COPP_TOPOLOGY) ||
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302964 (topology == VPM_TX_DM_FLUENCE_COPP_TOPOLOGY) ||
2965 (topology == VPM_TX_DM_RFECNS_COPP_TOPOLOGY))
2966 rate = 16000;
2967
Asish Bhattacharya34504582017-08-08 12:55:01 +05302968 /*
2969 * Routing driver reuses the same adm for streams with the same
2970 * app_type, sample_rate etc.
2971 * This isn't allowed for ULL streams as per the DSP interface
2972 */
2973 if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE)
2974 copp_idx = adm_get_idx_if_copp_exists(port_idx, topology,
2975 perf_mode,
2976 rate, bit_width,
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +05302977 app_type, session_type);
Asish Bhattacharya34504582017-08-08 12:55:01 +05302978
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302979 if (copp_idx < 0) {
2980 copp_idx = adm_get_next_available_copp(port_idx);
2981 if (copp_idx >= MAX_COPPS_PER_PORT) {
2982 pr_err("%s: exceeded copp id %d\n",
2983 __func__, copp_idx);
2984 return -EINVAL;
2985 }
2986 atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0);
2987 atomic_set(&this_adm.copp.topology[port_idx][copp_idx],
2988 topology);
2989 atomic_set(&this_adm.copp.mode[port_idx][copp_idx],
2990 perf_mode);
2991 atomic_set(&this_adm.copp.rate[port_idx][copp_idx],
2992 rate);
2993 atomic_set(&this_adm.copp.channels[port_idx][copp_idx],
2994 channel_mode);
2995 atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx],
2996 bit_width);
2997 atomic_set(&this_adm.copp.app_type[port_idx][copp_idx],
2998 app_type);
2999 atomic_set(&this_adm.copp.acdb_id[port_idx][copp_idx],
3000 acdb_id);
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +05303001 atomic_set(&this_adm.copp.session_type[port_idx][copp_idx],
3002 session_type);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303003 set_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3004 (void *)&this_adm.copp.adm_status[port_idx][copp_idx]);
3005 if ((path != ADM_PATH_COMPRESSED_RX) &&
3006 (path != ADM_PATH_COMPRESSED_TX))
3007 send_adm_custom_topology();
3008 }
3009
3010 if (this_adm.copp.adm_delay[port_idx][copp_idx] &&
3011 perf_mode == LEGACY_PCM_MODE) {
3012 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx],
3013 1);
3014 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
3015 wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]);
3016 }
3017
3018 /* Create a COPP if port id are not enabled */
3019 if (atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]) == 0) {
3020 pr_debug("%s: open ADM: port_idx: %d, copp_idx: %d\n", __func__,
3021 port_idx, copp_idx);
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003022 if ((topology == SRS_TRUMEDIA_TOPOLOGY_ID) &&
3023 perf_mode == LEGACY_PCM_MODE) {
3024 int res;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303025
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003026 atomic_set(&this_adm.mem_map_index, ADM_SRS_TRUMEDIA);
3027 msm_dts_srs_tm_ion_memmap(&this_adm.outband_memmap);
3028 res = adm_memory_map_regions(
3029 &this_adm.outband_memmap.paddr, 0,
3030 (uint32_t *)&this_adm.outband_memmap.size, 1);
3031 if (res < 0) {
3032 pr_err("%s: SRS adm_memory_map_regions failed! addr = 0x%pK, size = %d\n",
3033 __func__,
3034 (void *)this_adm.outband_memmap.paddr,
3035 (uint32_t)this_adm.outband_memmap.size);
3036 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303037 }
3038
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303039
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003040 if (q6core_get_avcs_api_version_per_service(
3041 APRV2_IDS_SERVICE_ID_ADSP_ADM_V) >=
3042 ADSP_ADM_API_VERSION_V3) {
3043 memset(&open_v8, 0, sizeof(open_v8));
3044 memset(&ep1_payload, 0, sizeof(ep1_payload));
3045 memset(&ep2_payload, 0, sizeof(ep2_payload));
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303046
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003047 open_v8.hdr.hdr_field = APR_HDR_FIELD(
3048 APR_MSG_TYPE_SEQ_CMD,
3049 APR_HDR_LEN(APR_HDR_SIZE),
3050 APR_PKT_VER);
3051 open_v8.hdr.src_svc = APR_SVC_ADM;
3052 open_v8.hdr.src_domain = APR_DOMAIN_APPS;
3053 open_v8.hdr.src_port = tmp_port;
3054 open_v8.hdr.dest_svc = APR_SVC_ADM;
3055 open_v8.hdr.dest_domain = APR_DOMAIN_ADSP;
3056 open_v8.hdr.dest_port = tmp_port;
3057 open_v8.hdr.token = port_idx << 16 | copp_idx;
3058 open_v8.hdr.opcode = ADM_CMD_DEVICE_OPEN_V8;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303059
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003060 if (this_adm.native_mode != 0) {
3061 open_v8.flags = flags |
3062 (this_adm.native_mode << 11);
3063 this_adm.native_mode = 0;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303064 } else {
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003065 open_v8.flags = flags;
3066 }
3067 open_v8.mode_of_operation = path;
3068 open_v8.endpoint_id_1 = tmp_port;
3069 open_v8.endpoint_id_2 = 0xFFFF;
3070 open_v8.endpoint_id_3 = 0xFFFF;
3071
3072 if (this_adm.ec_ref_rx && (path != 1)) {
3073 open_v8.endpoint_id_2 = this_adm.ec_ref_rx;
3074 this_adm.ec_ref_rx = -1;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303075 }
3076
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003077 open_v8.topology_id = topology;
3078 open_v8.reserved = 0;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303079
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003080 /* variable endpoint payload */
3081 ep1_payload.dev_num_channel = channel_mode & 0x00FF;
3082 ep1_payload.bit_width = bit_width;
3083 ep1_payload.sample_rate = rate;
3084 ret = adm_arrange_mch_map_v8(&ep1_payload, path,
3085 channel_mode);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303086 if (ret)
3087 return ret;
3088
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003089 pr_debug("%s: port_id=0x%x %x %x topology_id=0x%X flags %x ref_ch %x\n",
3090 __func__, open_v8.endpoint_id_1,
3091 open_v8.endpoint_id_2,
3092 open_v8.endpoint_id_3,
3093 open_v8.topology_id,
3094 open_v8.flags,
3095 this_adm.num_ec_ref_rx_chans);
3096
3097 ep1_payload_size = 8 +
3098 roundup(ep1_payload.dev_num_channel, 4);
3099 param_size = sizeof(struct adm_cmd_device_open_v8)
3100 + ep1_payload_size;
3101 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3102
3103 if ((this_adm.num_ec_ref_rx_chans != 0) && (path != 1)
3104 && (open_v8.endpoint_id_2 != 0xFFFF)) {
3105 ep2_payload.dev_num_channel =
3106 this_adm.num_ec_ref_rx_chans;
3107 this_adm.num_ec_ref_rx_chans = 0;
3108
3109 if (this_adm.ec_ref_rx_bit_width != 0) {
3110 ep2_payload.bit_width =
3111 this_adm.ec_ref_rx_bit_width;
3112 this_adm.ec_ref_rx_bit_width = 0;
3113 } else {
3114 ep2_payload.bit_width = bit_width;
3115 }
3116
3117 if (this_adm.ec_ref_rx_sampling_rate != 0) {
3118 ep2_payload.sample_rate =
3119 this_adm.ec_ref_rx_sampling_rate;
3120 this_adm.ec_ref_rx_sampling_rate = 0;
3121 } else {
3122 ep2_payload.sample_rate = rate;
3123 }
3124
3125 pr_debug("%s: adm open_v8 eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n",
3126 __func__,
3127 ep2_payload.dev_num_channel,
3128 ep2_payload.bit_width,
3129 ep2_payload.sample_rate);
3130
3131 ret = adm_arrange_mch_ep2_map_v8(&ep2_payload,
3132 ep2_payload.dev_num_channel);
3133
3134 if (ret)
3135 return ret;
3136 ep2_payload_size = 8 +
3137 roundup(ep2_payload.dev_num_channel, 4);
3138 param_size += ep2_payload_size;
3139 }
3140
3141 adm_params = kzalloc(param_size, GFP_KERNEL);
3142 if (!adm_params)
3143 return -ENOMEM;
3144 open_v8.hdr.pkt_size = param_size;
3145 memcpy(adm_params, &open_v8, sizeof(open_v8));
3146 memcpy(adm_params + sizeof(open_v8),
3147 (void *)&ep1_payload,
3148 ep1_payload_size);
3149 memcpy(adm_params + sizeof(open_v8)
3150 + ep1_payload_size,
3151 (void *)&ep2_payload,
3152 ep2_payload_size);
3153
3154 ret = apr_send_pkt(this_adm.apr,
3155 (uint32_t *)adm_params);
3156 if (ret < 0) {
3157 pr_err("%s: port_id: 0x%x for[0x%x] failed %d for open_v8\n",
3158 __func__, tmp_port, port_id, ret);
3159 return -EINVAL;
3160 }
3161 kfree(adm_params);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303162 } else {
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003163
3164 open.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3165 APR_HDR_LEN(APR_HDR_SIZE),
3166 APR_PKT_VER);
3167 open.hdr.pkt_size = sizeof(open);
3168 open.hdr.src_svc = APR_SVC_ADM;
3169 open.hdr.src_domain = APR_DOMAIN_APPS;
3170 open.hdr.src_port = tmp_port;
3171 open.hdr.dest_svc = APR_SVC_ADM;
3172 open.hdr.dest_domain = APR_DOMAIN_ADSP;
3173 open.hdr.dest_port = tmp_port;
3174 open.hdr.token = port_idx << 16 | copp_idx;
3175 open.hdr.opcode = ADM_CMD_DEVICE_OPEN_V5;
3176 open.flags = flags;
3177 open.mode_of_operation = path;
3178 open.endpoint_id_1 = tmp_port;
3179 open.endpoint_id_2 = 0xFFFF;
3180
3181 if (this_adm.ec_ref_rx && (path != 1)) {
3182 open.endpoint_id_2 = this_adm.ec_ref_rx;
3183 this_adm.ec_ref_rx = -1;
3184 }
3185
3186 open.topology_id = topology;
3187
3188 open.dev_num_channel = channel_mode & 0x00FF;
3189 open.bit_width = bit_width;
3190 WARN_ON((perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) &&
3191 (rate != ULL_SUPPORTED_SAMPLE_RATE));
3192 open.sample_rate = rate;
3193
3194 ret = adm_arrange_mch_map(&open, path, channel_mode,
3195 port_idx);
3196 if (ret)
3197 return ret;
3198
3199 pr_debug("%s: port_id=0x%x rate=%d topology_id=0x%X\n",
3200 __func__, open.endpoint_id_1, open.sample_rate,
3201 open.topology_id);
3202
3203 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3204
3205 if ((this_adm.num_ec_ref_rx_chans != 0) &&
3206 (path != 1) && (open.endpoint_id_2 != 0xFFFF)) {
3207 memset(&open_v6, 0,
3208 sizeof(struct adm_cmd_device_open_v6));
3209 memcpy(&open_v6, &open,
3210 sizeof(struct adm_cmd_device_open_v5));
3211 open_v6.hdr.opcode = ADM_CMD_DEVICE_OPEN_V6;
3212 open_v6.hdr.pkt_size = sizeof(open_v6);
3213 open_v6.dev_num_channel_eid2 =
3214 this_adm.num_ec_ref_rx_chans;
3215 this_adm.num_ec_ref_rx_chans = 0;
3216
3217 if (this_adm.ec_ref_rx_bit_width != 0) {
3218 open_v6.bit_width_eid2 =
3219 this_adm.ec_ref_rx_bit_width;
3220 this_adm.ec_ref_rx_bit_width = 0;
3221 } else {
3222 open_v6.bit_width_eid2 = bit_width;
3223 }
3224
3225 if (this_adm.ec_ref_rx_sampling_rate != 0) {
3226 open_v6.sample_rate_eid2 =
3227 this_adm.ec_ref_rx_sampling_rate;
3228 this_adm.ec_ref_rx_sampling_rate = 0;
3229 } else {
3230 open_v6.sample_rate_eid2 = rate;
3231 }
3232
3233 pr_debug("%s: eid2_channels=%d eid2_bit_width=%d eid2_rate=%d\n",
3234 __func__, open_v6.dev_num_channel_eid2,
3235 open_v6.bit_width_eid2,
3236 open_v6.sample_rate_eid2);
3237
3238 ret = adm_arrange_mch_ep2_map(&open_v6,
3239 open_v6.dev_num_channel_eid2);
3240
3241 if (ret)
3242 return ret;
3243
3244 ret = apr_send_pkt(this_adm.apr,
3245 (uint32_t *)&open_v6);
3246 } else {
3247 ret = apr_send_pkt(this_adm.apr,
3248 (uint32_t *)&open);
3249 }
3250 if (ret < 0) {
3251 pr_err("%s: port_id: 0x%x for[0x%x] failed %d\n",
3252 __func__, tmp_port, port_id, ret);
3253 return -EINVAL;
3254 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303255 }
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003256
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303257 /* Wait for the callback with copp id */
3258 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3259 atomic_read(&this_adm.copp.stat
3260 [port_idx][copp_idx]) >= 0,
3261 msecs_to_jiffies(TIMEOUT_MS));
3262 if (!ret) {
3263 pr_err("%s: ADM open timedout for port_id: 0x%x for [0x%x]\n",
3264 __func__, tmp_port, port_id);
3265 return -EINVAL;
3266 } else if (atomic_read(&this_adm.copp.stat
3267 [port_idx][copp_idx]) > 0) {
3268 pr_err("%s: DSP returned error[%s]\n",
3269 __func__, adsp_err_get_err_str(
3270 atomic_read(&this_adm.copp.stat
3271 [port_idx][copp_idx])));
3272 return adsp_err_get_lnx_err_code(
3273 atomic_read(&this_adm.copp.stat
3274 [port_idx][copp_idx]));
3275 }
3276 }
3277 atomic_inc(&this_adm.copp.cnt[port_idx][copp_idx]);
3278 return copp_idx;
3279}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303280EXPORT_SYMBOL(adm_open);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303281
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303282/**
3283 * adm_copp_mfc_cfg -
3284 * command to send ADM MFC config
3285 *
3286 * @port_id: Port ID number
3287 * @copp_idx: copp index assigned
3288 * @dst_sample_rate: sink sample rate
3289 *
3290 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303291void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate)
3292{
3293 struct audproc_mfc_output_media_fmt mfc_cfg;
3294 struct adm_cmd_device_open_v5 open;
3295 int port_idx;
3296 int sz = 0;
3297 int rc = 0;
3298 int i = 0;
3299
3300 port_id = q6audio_convert_virtual_to_portid(port_id);
3301 port_idx = adm_validate_and_get_port_index(port_id);
3302
3303 if (port_idx < 0) {
3304 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
3305 goto fail_cmd;
3306 }
3307
3308 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
3309 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
3310 goto fail_cmd;
3311 }
3312
3313 sz = sizeof(struct audproc_mfc_output_media_fmt);
3314
3315 mfc_cfg.params.hdr.hdr_field =
3316 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3317 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
3318 mfc_cfg.params.hdr.pkt_size = sz;
3319 mfc_cfg.params.hdr.src_svc = APR_SVC_ADM;
3320 mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS;
3321 mfc_cfg.params.hdr.src_port = port_id;
3322 mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM;
3323 mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP;
3324 mfc_cfg.params.hdr.dest_port =
3325 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
3326 mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx;
3327 mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
3328 mfc_cfg.params.payload_addr_lsw = 0;
3329 mfc_cfg.params.payload_addr_msw = 0;
3330 mfc_cfg.params.mem_map_handle = 0;
3331 mfc_cfg.params.payload_size = sizeof(mfc_cfg) -
3332 sizeof(mfc_cfg.params);
3333 mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC;
3334 mfc_cfg.data.param_id =
3335 AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
3336 mfc_cfg.data.param_size = mfc_cfg.params.payload_size -
3337 sizeof(mfc_cfg.data);
3338 mfc_cfg.data.reserved = 0;
3339 mfc_cfg.sampling_rate = dst_sample_rate;
3340 mfc_cfg.bits_per_sample =
3341 atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]);
3342 open.dev_num_channel = mfc_cfg.num_channels =
3343 atomic_read(&this_adm.copp.channels[port_idx][copp_idx]);
3344
3345 rc = adm_arrange_mch_map(&open, ADM_PATH_PLAYBACK,
Rohit kumar5d860f42019-02-01 18:01:12 +05303346 mfc_cfg.num_channels, port_idx);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303347 if (rc < 0) {
3348 pr_err("%s: unable to get channal map\n", __func__);
3349 goto fail_cmd;
3350 }
3351
3352 for (i = 0; i < mfc_cfg.num_channels; i++)
3353 mfc_cfg.channel_type[i] =
3354 (uint16_t) open.dev_channel_mapping[i];
3355
3356 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3357
3358 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",
3359 __func__, port_idx, copp_idx,
3360 atomic_read(&this_adm.copp.rate[port_idx][copp_idx]),
3361 mfc_cfg.bits_per_sample, mfc_cfg.num_channels,
3362 mfc_cfg.sampling_rate);
3363
3364 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg);
3365
3366 if (rc < 0) {
3367 pr_err("%s: port_id: for[0x%x] failed %d\n",
3368 __func__, port_id, rc);
3369 goto fail_cmd;
3370 }
3371 /* Wait for the callback with copp id */
3372 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3373 atomic_read(&this_adm.copp.stat
3374 [port_idx][copp_idx]) >= 0,
3375 msecs_to_jiffies(TIMEOUT_MS));
3376 if (!rc) {
3377 pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n",
3378 __func__, port_id);
3379 goto fail_cmd;
3380 } else if (atomic_read(&this_adm.copp.stat
3381 [port_idx][copp_idx]) > 0) {
3382 pr_err("%s: DSP returned error[%s]\n",
3383 __func__, adsp_err_get_err_str(
3384 atomic_read(&this_adm.copp.stat
3385 [port_idx][copp_idx])));
3386 goto fail_cmd;
3387 }
3388 rc = 0;
3389fail_cmd:
3390 return;
3391}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303392EXPORT_SYMBOL(adm_copp_mfc_cfg);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303393
3394static void route_set_opcode_matrix_id(
3395 struct adm_cmd_matrix_map_routings_v5 **route_addr,
3396 int path, uint32_t passthr_mode)
3397{
3398 struct adm_cmd_matrix_map_routings_v5 *route = *route_addr;
3399
3400 switch (path) {
3401 case ADM_PATH_PLAYBACK:
3402 route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5;
3403 route->matrix_id = ADM_MATRIX_ID_AUDIO_RX;
3404 break;
3405 case ADM_PATH_LIVE_REC:
3406 if (passthr_mode == LISTEN) {
3407 route->hdr.opcode =
3408 ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
3409 route->matrix_id = ADM_MATRIX_ID_LISTEN_TX;
3410 break;
3411 }
3412 /* fall through to set matrix id for non-listen case */
3413 case ADM_PATH_NONLIVE_REC:
3414 route->hdr.opcode = ADM_CMD_MATRIX_MAP_ROUTINGS_V5;
3415 route->matrix_id = ADM_MATRIX_ID_AUDIO_TX;
3416 break;
3417 case ADM_PATH_COMPRESSED_RX:
3418 route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
3419 route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_RX;
3420 break;
3421 case ADM_PATH_COMPRESSED_TX:
3422 route->hdr.opcode = ADM_CMD_STREAM_DEVICE_MAP_ROUTINGS_V5;
3423 route->matrix_id = ADM_MATRIX_ID_COMPRESSED_AUDIO_TX;
3424 break;
3425 default:
3426 pr_err("%s: Wrong path set[%d]\n", __func__, path);
3427 break;
3428 }
3429 pr_debug("%s: opcode 0x%x, matrix id %d\n",
3430 __func__, route->hdr.opcode, route->matrix_id);
3431}
3432
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303433/**
3434 * adm_matrix_map -
3435 * command to send ADM matrix map for ADM copp list
3436 *
3437 * @path: direction or ADM path type
3438 * @payload_map: have info of session id and associated copp_idx/num_copps
3439 * @perf_mode: performance mode like LL/ULL/..
3440 * @passthr_mode: flag to indicate passthrough mode
3441 *
3442 * Returns 0 on success or error on failure
3443 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303444int adm_matrix_map(int path, struct route_payload payload_map, int perf_mode,
3445 uint32_t passthr_mode)
3446{
3447 struct adm_cmd_matrix_map_routings_v5 *route;
3448 struct adm_session_map_node_v5 *node;
3449 uint16_t *copps_list;
3450 int cmd_size = 0;
3451 int ret = 0, i = 0;
3452 void *payload = NULL;
3453 void *matrix_map = NULL;
3454 int port_idx, copp_idx;
3455
3456 /* Assumes port_ids have already been validated during adm_open */
3457 cmd_size = (sizeof(struct adm_cmd_matrix_map_routings_v5) +
3458 sizeof(struct adm_session_map_node_v5) +
3459 (sizeof(uint32_t) * payload_map.num_copps));
3460 matrix_map = kzalloc(cmd_size, GFP_KERNEL);
3461 if (matrix_map == NULL) {
3462 pr_err("%s: Mem alloc failed\n", __func__);
3463 ret = -EINVAL;
3464 return ret;
3465 }
3466 route = (struct adm_cmd_matrix_map_routings_v5 *)matrix_map;
3467
3468 route->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3469 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
3470 route->hdr.pkt_size = cmd_size;
3471 route->hdr.src_svc = 0;
3472 route->hdr.src_domain = APR_DOMAIN_APPS;
3473 route->hdr.src_port = 0; /* Ignored */;
3474 route->hdr.dest_svc = APR_SVC_ADM;
3475 route->hdr.dest_domain = APR_DOMAIN_ADSP;
3476 route->hdr.dest_port = 0; /* Ignored */;
3477 route->hdr.token = 0;
3478 route->num_sessions = 1;
3479 route_set_opcode_matrix_id(&route, path, passthr_mode);
3480
3481 payload = ((u8 *)matrix_map +
3482 sizeof(struct adm_cmd_matrix_map_routings_v5));
3483 node = (struct adm_session_map_node_v5 *)payload;
3484
3485 node->session_id = payload_map.session_id;
3486 node->num_copps = payload_map.num_copps;
3487 payload = (u8 *)node + sizeof(struct adm_session_map_node_v5);
3488 copps_list = (uint16_t *)payload;
3489 for (i = 0; i < payload_map.num_copps; i++) {
3490 port_idx =
3491 adm_validate_and_get_port_index(payload_map.port_id[i]);
3492 if (port_idx < 0) {
3493 pr_err("%s: Invalid port_id 0x%x\n", __func__,
3494 payload_map.port_id[i]);
3495 ret = -EINVAL;
3496 goto fail_cmd;
3497 }
3498 copp_idx = payload_map.copp_idx[i];
3499 copps_list[i] = atomic_read(&this_adm.copp.id[port_idx]
3500 [copp_idx]);
3501 }
3502 atomic_set(&this_adm.matrix_map_stat, -1);
3503
3504 ret = apr_send_pkt(this_adm.apr, (uint32_t *)matrix_map);
3505 if (ret < 0) {
3506 pr_err("%s: routing for syream %d failed ret %d\n",
3507 __func__, payload_map.session_id, ret);
3508 ret = -EINVAL;
3509 goto fail_cmd;
3510 }
3511 ret = wait_event_timeout(this_adm.matrix_map_wait,
3512 atomic_read(&this_adm.matrix_map_stat) >= 0,
3513 msecs_to_jiffies(TIMEOUT_MS));
3514 if (!ret) {
3515 pr_err("%s: routing for syream %d failed\n", __func__,
3516 payload_map.session_id);
3517 ret = -EINVAL;
3518 goto fail_cmd;
3519 } else if (atomic_read(&this_adm.matrix_map_stat) > 0) {
3520 pr_err("%s: DSP returned error[%s]\n", __func__,
3521 adsp_err_get_err_str(atomic_read(
3522 &this_adm.matrix_map_stat)));
3523 ret = adsp_err_get_lnx_err_code(
3524 atomic_read(&this_adm.matrix_map_stat));
3525 goto fail_cmd;
3526 }
3527
3528 if ((perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) &&
3529 (path != ADM_PATH_COMPRESSED_RX)) {
3530 for (i = 0; i < payload_map.num_copps; i++) {
3531 port_idx = afe_get_port_index(payload_map.port_id[i]);
3532 copp_idx = payload_map.copp_idx[i];
3533 if (port_idx < 0 || copp_idx < 0 ||
3534 (copp_idx > MAX_COPPS_PER_PORT - 1)) {
3535 pr_err("%s: Invalid idx port_idx %d copp_idx %d\n",
3536 __func__, port_idx, copp_idx);
3537 continue;
3538 }
3539 rtac_add_adm_device(payload_map.port_id[i],
3540 atomic_read(&this_adm.copp.id
3541 [port_idx][copp_idx]),
3542 get_cal_path(path),
3543 payload_map.session_id,
3544 payload_map.app_type[i],
3545 payload_map.acdb_dev_id[i]);
3546
3547 if (!test_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3548 (void *)&this_adm.copp.adm_status[port_idx]
3549 [copp_idx])) {
3550 pr_debug("%s: adm copp[0x%x][%d] already sent",
3551 __func__, port_idx, copp_idx);
3552 continue;
3553 }
3554 send_adm_cal(payload_map.port_id[i], copp_idx,
3555 get_cal_path(path), perf_mode,
3556 payload_map.app_type[i],
3557 payload_map.acdb_dev_id[i],
Aditya Bavanarifcd80ec2018-01-08 13:16:32 +05303558 payload_map.sample_rate[i],
3559 passthr_mode);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303560 /* ADM COPP calibration is already sent */
3561 clear_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3562 (void *)&this_adm.copp.
3563 adm_status[port_idx][copp_idx]);
3564 pr_debug("%s: copp_id: %d\n", __func__,
3565 atomic_read(&this_adm.copp.id[port_idx]
3566 [copp_idx]));
3567 }
3568 }
3569
3570fail_cmd:
3571 kfree(matrix_map);
3572 return ret;
3573}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303574EXPORT_SYMBOL(adm_matrix_map);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303575
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303576/**
3577 * adm_ec_ref_rx_id -
3578 * Update EC ref port ID
3579 *
3580 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303581void adm_ec_ref_rx_id(int port_id)
3582{
3583 this_adm.ec_ref_rx = port_id;
3584 pr_debug("%s: ec_ref_rx:%d\n", __func__, this_adm.ec_ref_rx);
3585}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303586EXPORT_SYMBOL(adm_ec_ref_rx_id);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303587
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303588/**
3589 * adm_num_ec_ref_rx_chans -
3590 * Update EC ref number of channels
3591 *
3592 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303593void adm_num_ec_ref_rx_chans(int num_chans)
3594{
3595 this_adm.num_ec_ref_rx_chans = num_chans;
3596 pr_debug("%s: num_ec_ref_rx_chans:%d\n",
3597 __func__, this_adm.num_ec_ref_rx_chans);
3598}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303599EXPORT_SYMBOL(adm_num_ec_ref_rx_chans);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303600
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303601/**
3602 * adm_ec_ref_rx_bit_width -
3603 * Update EC ref bit_width
3604 *
3605 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303606void adm_ec_ref_rx_bit_width(int bit_width)
3607{
3608 this_adm.ec_ref_rx_bit_width = bit_width;
3609 pr_debug("%s: ec_ref_rx_bit_width:%d\n",
3610 __func__, this_adm.ec_ref_rx_bit_width);
3611}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303612EXPORT_SYMBOL(adm_ec_ref_rx_bit_width);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303613
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303614/**
3615 * adm_ec_ref_rx_sampling_rate -
3616 * Update EC ref sample rate
3617 *
3618 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303619void adm_ec_ref_rx_sampling_rate(int sampling_rate)
3620{
3621 this_adm.ec_ref_rx_sampling_rate = sampling_rate;
3622 pr_debug("%s: ec_ref_rx_sampling_rate:%d\n",
3623 __func__, this_adm.ec_ref_rx_sampling_rate);
3624}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303625EXPORT_SYMBOL(adm_ec_ref_rx_sampling_rate);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303626
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303627/**
Dieter Lueckinga8b8e3b2018-09-28 14:29:17 +02003628 * adm_set_native_mode -
3629 * Set adm channel native mode.
3630 * If enabled matrix mixer will be
3631 * running in native mode for channel
3632 * configuration for this device session.
3633 *
3634 */
3635void adm_set_native_mode(int mode)
3636{
3637 this_adm.native_mode = mode;
3638 pr_debug("%s: enable native_mode :%d\n",
3639 __func__, this_adm.native_mode);
3640}
3641EXPORT_SYMBOL(adm_set_native_mode);
3642
3643/**
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303644 * adm_close -
3645 * command to close ADM copp
3646 *
3647 * @port_id: Port ID number
3648 * @perf_mode: performance mode like LL/ULL/..
3649 * @copp_idx: copp index assigned
3650 *
3651 * Returns 0 on success or error on failure
3652 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303653int adm_close(int port_id, int perf_mode, int copp_idx)
3654{
3655 struct apr_hdr close;
3656
3657 int ret = 0, port_idx;
3658 int copp_id = RESET_COPP_ID;
3659
3660 pr_debug("%s: port_id=0x%x perf_mode: %d copp_idx: %d\n", __func__,
3661 port_id, perf_mode, copp_idx);
3662
3663 port_id = q6audio_convert_virtual_to_portid(port_id);
3664 port_idx = adm_validate_and_get_port_index(port_id);
3665 if (port_idx < 0) {
3666 pr_err("%s: Invalid port_id 0x%x\n",
3667 __func__, port_id);
3668 return -EINVAL;
3669 }
3670
3671 if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) {
3672 pr_err("%s: Invalid copp idx: %d\n", __func__, copp_idx);
3673 return -EINVAL;
3674 }
3675
Rohit kumar5d860f42019-02-01 18:01:12 +05303676 port_channel_map[port_idx].set_channel_map = false;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303677 if (this_adm.copp.adm_delay[port_idx][copp_idx] && perf_mode
3678 == LEGACY_PCM_MODE) {
3679 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx],
3680 1);
3681 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
3682 wake_up(&this_adm.copp.adm_delay_wait[port_idx][copp_idx]);
3683 }
3684
3685 atomic_dec(&this_adm.copp.cnt[port_idx][copp_idx]);
3686 if (!(atomic_read(&this_adm.copp.cnt[port_idx][copp_idx]))) {
3687 copp_id = adm_get_copp_id(port_idx, copp_idx);
3688 pr_debug("%s: Closing ADM port_idx:%d copp_idx:%d copp_id:0x%x\n",
3689 __func__, port_idx, copp_idx, copp_id);
3690 if ((!perf_mode) && (this_adm.outband_memmap.paddr != 0) &&
3691 (atomic_read(&this_adm.copp.topology[port_idx][copp_idx]) ==
3692 SRS_TRUMEDIA_TOPOLOGY_ID)) {
3693 atomic_set(&this_adm.mem_map_index,
3694 ADM_SRS_TRUMEDIA);
3695 ret = adm_memory_unmap_regions();
3696 if (ret < 0) {
3697 pr_err("%s: adm mem unmmap err %d",
3698 __func__, ret);
3699 } else {
3700 atomic_set(&this_adm.mem_map_handles
3701 [ADM_SRS_TRUMEDIA], 0);
3702 }
3703 }
3704
3705
3706 if ((afe_get_port_type(port_id) == MSM_AFE_PORT_TYPE_TX) &&
3707 this_adm.sourceTrackingData.memmap.paddr) {
3708 atomic_set(&this_adm.mem_map_index,
3709 ADM_MEM_MAP_INDEX_SOURCE_TRACKING);
3710 ret = adm_memory_unmap_regions();
3711 if (ret < 0) {
3712 pr_err("%s: adm mem unmmap err %d",
3713 __func__, ret);
3714 }
3715 msm_audio_ion_free(
3716 this_adm.sourceTrackingData.ion_client,
3717 this_adm.sourceTrackingData.ion_handle);
3718 this_adm.sourceTrackingData.ion_client = NULL;
3719 this_adm.sourceTrackingData.ion_handle = NULL;
3720 this_adm.sourceTrackingData.memmap.size = 0;
3721 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
3722 this_adm.sourceTrackingData.memmap.paddr = 0;
3723 this_adm.sourceTrackingData.apr_cmd_status = -1;
3724 atomic_set(&this_adm.mem_map_handles[
3725 ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
3726 }
3727
3728 close.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
3729 APR_HDR_LEN(APR_HDR_SIZE),
3730 APR_PKT_VER);
3731 close.pkt_size = sizeof(close);
3732 close.src_svc = APR_SVC_ADM;
3733 close.src_domain = APR_DOMAIN_APPS;
3734 close.src_port = port_id;
3735 close.dest_svc = APR_SVC_ADM;
3736 close.dest_domain = APR_DOMAIN_ADSP;
3737 close.dest_port = copp_id;
3738 close.token = port_idx << 16 | copp_idx;
3739 close.opcode = ADM_CMD_DEVICE_CLOSE_V5;
3740
3741 atomic_set(&this_adm.copp.id[port_idx][copp_idx],
3742 RESET_COPP_ID);
3743 atomic_set(&this_adm.copp.cnt[port_idx][copp_idx], 0);
3744 atomic_set(&this_adm.copp.topology[port_idx][copp_idx], 0);
3745 atomic_set(&this_adm.copp.mode[port_idx][copp_idx], 0);
3746 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
3747 atomic_set(&this_adm.copp.rate[port_idx][copp_idx], 0);
3748 atomic_set(&this_adm.copp.channels[port_idx][copp_idx], 0);
3749 atomic_set(&this_adm.copp.bit_width[port_idx][copp_idx], 0);
3750 atomic_set(&this_adm.copp.app_type[port_idx][copp_idx], 0);
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +05303751 atomic_set(&this_adm.copp.session_type[port_idx][copp_idx], 0);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303752
3753 clear_bit(ADM_STATUS_CALIBRATION_REQUIRED,
3754 (void *)&this_adm.copp.adm_status[port_idx][copp_idx]);
3755
3756 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close);
3757 if (ret < 0) {
3758 pr_err("%s: ADM close failed %d\n", __func__, ret);
3759 return -EINVAL;
3760 }
3761
3762 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
3763 atomic_read(&this_adm.copp.stat
3764 [port_idx][copp_idx]) >= 0,
3765 msecs_to_jiffies(TIMEOUT_MS));
3766 if (!ret) {
3767 pr_err("%s: ADM cmd Route timedout for port 0x%x\n",
3768 __func__, port_id);
3769 return -EINVAL;
3770 } else if (atomic_read(&this_adm.copp.stat
3771 [port_idx][copp_idx]) > 0) {
3772 pr_err("%s: DSP returned error[%s]\n",
3773 __func__, adsp_err_get_err_str(
3774 atomic_read(&this_adm.copp.stat
3775 [port_idx][copp_idx])));
3776 return adsp_err_get_lnx_err_code(
3777 atomic_read(&this_adm.copp.stat
3778 [port_idx][copp_idx]));
3779 }
3780 }
3781
3782 if (perf_mode != ULTRA_LOW_LATENCY_PCM_MODE) {
3783 pr_debug("%s: remove adm device from rtac\n", __func__);
3784 rtac_remove_adm_device(port_id, copp_id);
3785 }
3786 return 0;
3787}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05303788EXPORT_SYMBOL(adm_close);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303789
3790int send_rtac_audvol_cal(void)
3791{
3792 int ret = 0;
3793 int ret2 = 0;
3794 int i = 0;
3795 int copp_idx, port_idx, acdb_id, app_id, path;
3796 struct cal_block_data *cal_block = NULL;
3797 struct audio_cal_info_audvol *audvol_cal_info = NULL;
3798 struct rtac_adm rtac_adm_data;
3799
3800 mutex_lock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock);
3801
3802 cal_block = cal_utils_get_only_cal_block(
3803 this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]);
Vikram Pandurangad3b58cc2017-09-27 12:17:36 -07003804 if (cal_block == NULL || cal_utils_is_cal_stale(cal_block)) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303805 pr_err("%s: can't find cal block!\n", __func__);
3806 goto unlock;
3807 }
3808
3809 audvol_cal_info = cal_block->cal_info;
3810 if (audvol_cal_info == NULL) {
3811 pr_err("%s: audvol_cal_info is NULL!\n", __func__);
3812 goto unlock;
3813 }
3814
3815 get_rtac_adm_data(&rtac_adm_data);
3816 for (; i < rtac_adm_data.num_of_dev; i++) {
3817
3818 acdb_id = rtac_adm_data.device[i].acdb_dev_id;
3819 if (acdb_id == 0)
3820 acdb_id = audvol_cal_info->acdb_id;
3821
3822 app_id = rtac_adm_data.device[i].app_type;
3823 if (app_id == 0)
3824 app_id = audvol_cal_info->app_type;
3825
3826 path = afe_get_port_type(rtac_adm_data.device[i].afe_port);
3827 if ((acdb_id == audvol_cal_info->acdb_id) &&
3828 (app_id == audvol_cal_info->app_type) &&
3829 (path == audvol_cal_info->path)) {
3830
3831 if (adm_get_indexes_from_copp_id(rtac_adm_data.
3832 device[i].copp, &copp_idx, &port_idx) != 0) {
3833 pr_debug("%s: Copp Id %d is not active\n",
3834 __func__,
3835 rtac_adm_data.device[i].copp);
3836 continue;
3837 }
3838
3839 ret2 = adm_remap_and_send_cal_block(ADM_RTAC_AUDVOL_CAL,
3840 rtac_adm_data.device[i].afe_port,
3841 copp_idx, cal_block,
3842 atomic_read(&this_adm.copp.
3843 mode[port_idx][copp_idx]),
3844 audvol_cal_info->app_type,
3845 audvol_cal_info->acdb_id,
3846 atomic_read(&this_adm.copp.
3847 rate[port_idx][copp_idx]));
3848 if (ret2 < 0) {
3849 pr_debug("%s: remap and send failed for copp Id %d, acdb id %d, app type %d, path %d\n",
3850 __func__, rtac_adm_data.device[i].copp,
3851 audvol_cal_info->acdb_id,
3852 audvol_cal_info->app_type,
3853 audvol_cal_info->path);
3854 ret = ret2;
3855 }
3856 }
3857 }
3858unlock:
3859 mutex_unlock(&this_adm.cal_data[ADM_RTAC_AUDVOL_CAL]->lock);
3860 return ret;
3861}
3862
3863int adm_map_rtac_block(struct rtac_cal_block_data *cal_block)
3864{
3865 int result = 0;
3866
3867 pr_debug("%s:\n", __func__);
3868
3869 if (cal_block == NULL) {
3870 pr_err("%s: cal_block is NULL!\n",
3871 __func__);
3872 result = -EINVAL;
3873 goto done;
3874 }
3875
3876 if (cal_block->cal_data.paddr == 0) {
3877 pr_debug("%s: No address to map!\n",
3878 __func__);
3879 result = -EINVAL;
3880 goto done;
3881 }
3882
3883 if (cal_block->map_data.map_size == 0) {
3884 pr_debug("%s: map size is 0!\n",
3885 __func__);
3886 result = -EINVAL;
3887 goto done;
3888 }
3889
3890 /* valid port ID needed for callback use primary I2S */
3891 atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL);
3892 result = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
3893 &cal_block->map_data.map_size, 1);
3894 if (result < 0) {
3895 pr_err("%s: RTAC mmap did not work! size = %d result %d\n",
3896 __func__,
3897 cal_block->map_data.map_size, result);
3898 pr_debug("%s: RTAC mmap did not work! addr = 0x%pK, size = %d\n",
3899 __func__,
3900 &cal_block->cal_data.paddr,
3901 cal_block->map_data.map_size);
3902 goto done;
3903 }
3904
3905 cal_block->map_data.map_handle = atomic_read(
3906 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]);
3907done:
3908 return result;
3909}
3910
3911int adm_unmap_rtac_block(uint32_t *mem_map_handle)
3912{
3913 int result = 0;
3914
3915 pr_debug("%s:\n", __func__);
3916
3917 if (mem_map_handle == NULL) {
3918 pr_debug("%s: Map handle is NULL, nothing to unmap\n",
3919 __func__);
3920 goto done;
3921 }
3922
3923 if (*mem_map_handle == 0) {
3924 pr_debug("%s: Map handle is 0, nothing to unmap\n",
3925 __func__);
3926 goto done;
3927 }
3928
3929 if (*mem_map_handle != atomic_read(
3930 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL])) {
3931 pr_err("%s: Map handles do not match! Unmapping RTAC, RTAC map 0x%x, ADM map 0x%x\n",
3932 __func__, *mem_map_handle, atomic_read(
3933 &this_adm.mem_map_handles[ADM_RTAC_APR_CAL]));
3934
3935 /* if mismatch use handle passed in to unmap */
3936 atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL],
3937 *mem_map_handle);
3938 }
3939
3940 /* valid port ID needed for callback use primary I2S */
3941 atomic_set(&this_adm.mem_map_index, ADM_RTAC_APR_CAL);
3942 result = adm_memory_unmap_regions();
3943 if (result < 0) {
3944 pr_debug("%s: adm_memory_unmap_regions failed, error %d\n",
3945 __func__, result);
3946 } else {
3947 atomic_set(&this_adm.mem_map_handles[ADM_RTAC_APR_CAL], 0);
3948 *mem_map_handle = 0;
3949 }
3950done:
3951 return result;
3952}
3953
3954static int get_cal_type_index(int32_t cal_type)
3955{
3956 int ret = -EINVAL;
3957
3958 switch (cal_type) {
3959 case ADM_AUDPROC_CAL_TYPE:
3960 ret = ADM_AUDPROC_CAL;
3961 break;
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05303962 case ADM_LSM_AUDPROC_CAL_TYPE:
3963 ret = ADM_LSM_AUDPROC_CAL;
3964 break;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303965 case ADM_AUDVOL_CAL_TYPE:
3966 ret = ADM_AUDVOL_CAL;
3967 break;
3968 case ADM_CUST_TOPOLOGY_CAL_TYPE:
3969 ret = ADM_CUSTOM_TOP_CAL;
3970 break;
3971 case ADM_RTAC_INFO_CAL_TYPE:
3972 ret = ADM_RTAC_INFO_CAL;
3973 break;
3974 case ADM_RTAC_APR_CAL_TYPE:
3975 ret = ADM_RTAC_APR_CAL;
3976 break;
3977 case ADM_RTAC_AUDVOL_CAL_TYPE:
3978 ret = ADM_RTAC_AUDVOL_CAL;
3979 break;
Bhalchandra Gajareface2762018-05-10 14:16:49 -07003980 case ADM_LSM_AUDPROC_PERSISTENT_CAL_TYPE:
3981 ret = ADM_LSM_AUDPROC_PERSISTENT_CAL;
3982 break;
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05303983 default:
3984 pr_err("%s: invalid cal type %d!\n", __func__, cal_type);
3985 }
3986 return ret;
3987}
3988
3989static int adm_alloc_cal(int32_t cal_type, size_t data_size, void *data)
3990{
3991 int ret = 0;
3992 int cal_index;
3993
3994 pr_debug("%s:\n", __func__);
3995
3996 cal_index = get_cal_type_index(cal_type);
3997 if (cal_index < 0) {
3998 pr_err("%s: could not get cal index %d!\n",
3999 __func__, cal_index);
4000 ret = -EINVAL;
4001 goto done;
4002 }
4003
4004 ret = cal_utils_alloc_cal(data_size, data,
4005 this_adm.cal_data[cal_index], 0, NULL);
4006 if (ret < 0) {
4007 pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
4008 __func__, ret, cal_type);
4009 ret = -EINVAL;
4010 goto done;
4011 }
4012done:
4013 return ret;
4014}
4015
4016static int adm_dealloc_cal(int32_t cal_type, size_t data_size, void *data)
4017{
4018 int ret = 0;
4019 int cal_index;
4020
4021 pr_debug("%s:\n", __func__);
4022
4023 cal_index = get_cal_type_index(cal_type);
4024 if (cal_index < 0) {
4025 pr_err("%s: could not get cal index %d!\n",
4026 __func__, cal_index);
4027 ret = -EINVAL;
4028 goto done;
4029 }
4030
4031 ret = cal_utils_dealloc_cal(data_size, data,
4032 this_adm.cal_data[cal_index]);
4033 if (ret < 0) {
4034 pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
4035 __func__, ret, cal_type);
4036 ret = -EINVAL;
4037 goto done;
4038 }
4039done:
4040 return ret;
4041}
4042
4043static int adm_set_cal(int32_t cal_type, size_t data_size, void *data)
4044{
4045 int ret = 0;
4046 int cal_index;
4047
4048 pr_debug("%s:\n", __func__);
4049
4050 cal_index = get_cal_type_index(cal_type);
4051 if (cal_index < 0) {
4052 pr_err("%s: could not get cal index %d!\n",
4053 __func__, cal_index);
4054 ret = -EINVAL;
4055 goto done;
4056 }
4057
4058 ret = cal_utils_set_cal(data_size, data,
4059 this_adm.cal_data[cal_index], 0, NULL);
4060 if (ret < 0) {
4061 pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
4062 __func__, ret, cal_type);
4063 ret = -EINVAL;
4064 goto done;
4065 }
4066
4067 if (cal_index == ADM_CUSTOM_TOP_CAL) {
4068 mutex_lock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock);
4069 this_adm.set_custom_topology = 1;
4070 mutex_unlock(&this_adm.cal_data[ADM_CUSTOM_TOP_CAL]->lock);
4071 } else if (cal_index == ADM_RTAC_AUDVOL_CAL) {
4072 send_rtac_audvol_cal();
4073 }
4074done:
4075 return ret;
4076}
4077
4078static int adm_map_cal_data(int32_t cal_type,
4079 struct cal_block_data *cal_block)
4080{
4081 int ret = 0;
4082 int cal_index;
4083
4084 pr_debug("%s:\n", __func__);
4085
4086 cal_index = get_cal_type_index(cal_type);
4087 if (cal_index < 0) {
4088 pr_err("%s: could not get cal index %d!\n",
4089 __func__, cal_index);
4090 ret = -EINVAL;
4091 goto done;
4092 }
4093
4094 atomic_set(&this_adm.mem_map_index, cal_index);
4095 ret = adm_memory_map_regions(&cal_block->cal_data.paddr, 0,
4096 (uint32_t *)&cal_block->map_data.map_size, 1);
4097 if (ret < 0) {
4098 pr_err("%s: map did not work! cal_type %i ret %d\n",
4099 __func__, cal_index, ret);
4100 ret = -ENODEV;
4101 goto done;
4102 }
4103 cal_block->map_data.q6map_handle = atomic_read(&this_adm.
4104 mem_map_handles[cal_index]);
4105done:
4106 return ret;
4107}
4108
4109static int adm_unmap_cal_data(int32_t cal_type,
4110 struct cal_block_data *cal_block)
4111{
4112 int ret = 0;
4113 int cal_index;
4114
4115 pr_debug("%s:\n", __func__);
4116
4117 cal_index = get_cal_type_index(cal_type);
4118 if (cal_index < 0) {
4119 pr_err("%s: could not get cal index %d!\n",
4120 __func__, cal_index);
4121 ret = -EINVAL;
4122 goto done;
4123 }
4124
4125 if (cal_block == NULL) {
4126 pr_err("%s: Cal block is NULL!\n",
4127 __func__);
4128 goto done;
4129 }
4130
4131 if (cal_block->map_data.q6map_handle == 0) {
4132 pr_err("%s: Map handle is NULL, nothing to unmap\n",
4133 __func__);
4134 goto done;
4135 }
4136
4137 atomic_set(&this_adm.mem_map_handles[cal_index],
4138 cal_block->map_data.q6map_handle);
4139 atomic_set(&this_adm.mem_map_index, cal_index);
4140 ret = adm_memory_unmap_regions();
4141 if (ret < 0) {
4142 pr_err("%s: unmap did not work! cal_type %i ret %d\n",
4143 __func__, cal_index, ret);
4144 ret = -ENODEV;
4145 goto done;
4146 }
4147 cal_block->map_data.q6map_handle = 0;
4148done:
4149 return ret;
4150}
4151
4152static void adm_delete_cal_data(void)
4153{
4154 pr_debug("%s:\n", __func__);
4155
4156 cal_utils_destroy_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data);
4157}
4158
4159static int adm_init_cal_data(void)
4160{
4161 int ret = 0;
4162 struct cal_type_info cal_type_info[] = {
4163 {{ADM_CUST_TOPOLOGY_CAL_TYPE,
4164 {adm_alloc_cal, adm_dealloc_cal, NULL,
4165 adm_set_cal, NULL, NULL} },
4166 {adm_map_cal_data, adm_unmap_cal_data,
4167 cal_utils_match_buf_num} },
4168
4169 {{ADM_AUDPROC_CAL_TYPE,
4170 {adm_alloc_cal, adm_dealloc_cal, NULL,
4171 adm_set_cal, NULL, NULL} },
4172 {adm_map_cal_data, adm_unmap_cal_data,
4173 cal_utils_match_buf_num} },
4174
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05304175 {{ADM_LSM_AUDPROC_CAL_TYPE,
4176 {adm_alloc_cal, adm_dealloc_cal, NULL,
4177 adm_set_cal, NULL, NULL} },
4178 {adm_map_cal_data, adm_unmap_cal_data,
4179 cal_utils_match_buf_num} },
4180
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304181 {{ADM_AUDVOL_CAL_TYPE,
4182 {adm_alloc_cal, adm_dealloc_cal, NULL,
4183 adm_set_cal, NULL, NULL} },
4184 {adm_map_cal_data, adm_unmap_cal_data,
4185 cal_utils_match_buf_num} },
4186
4187 {{ADM_RTAC_INFO_CAL_TYPE,
4188 {NULL, NULL, NULL, NULL, NULL, NULL} },
4189 {NULL, NULL, cal_utils_match_buf_num} },
4190
4191 {{ADM_RTAC_APR_CAL_TYPE,
4192 {NULL, NULL, NULL, NULL, NULL, NULL} },
4193 {NULL, NULL, cal_utils_match_buf_num} },
4194
4195 {{SRS_TRUMEDIA_CAL_TYPE,
4196 {NULL, NULL, NULL, NULL, NULL, NULL} },
4197 {NULL, NULL, cal_utils_match_buf_num} },
4198
4199 {{ADM_RTAC_AUDVOL_CAL_TYPE,
4200 {adm_alloc_cal, adm_dealloc_cal, NULL,
4201 adm_set_cal, NULL, NULL} },
4202 {adm_map_cal_data, adm_unmap_cal_data,
4203 cal_utils_match_buf_num} },
Bhalchandra Gajareface2762018-05-10 14:16:49 -07004204
4205 {{ADM_LSM_AUDPROC_PERSISTENT_CAL_TYPE,
4206 {adm_alloc_cal, adm_dealloc_cal, NULL,
4207 adm_set_cal, NULL, NULL} },
4208 {adm_map_cal_data, adm_unmap_cal_data,
4209 cal_utils_match_buf_num} },
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304210 };
4211 pr_debug("%s:\n", __func__);
4212
4213 ret = cal_utils_create_cal_types(ADM_MAX_CAL_TYPES, this_adm.cal_data,
4214 cal_type_info);
4215 if (ret < 0) {
4216 pr_err("%s: could not create cal type! ret %d\n",
4217 __func__, ret);
4218 ret = -EINVAL;
4219 goto err;
4220 }
4221
4222 return ret;
4223err:
4224 adm_delete_cal_data();
4225 return ret;
4226}
4227
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304228/**
4229 * adm_set_volume -
4230 * command to set volume on ADM copp
4231 *
4232 * @port_id: Port ID number
4233 * @copp_idx: copp index assigned
4234 * @volume: gain value to set
4235 *
4236 * Returns 0 on success or error on failure
4237 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304238int adm_set_volume(int port_id, int copp_idx, int volume)
4239{
4240 struct audproc_volume_ctrl_master_gain audproc_vol;
4241 int sz = 0;
4242 int rc = 0;
4243 int port_idx;
4244
4245 pr_debug("%s: port_id %d, volume %d\n", __func__, port_id, volume);
4246 port_id = afe_convert_virtual_to_portid(port_id);
4247 port_idx = adm_validate_and_get_port_index(port_id);
4248 if (port_idx < 0) {
4249 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4250 rc = -EINVAL;
4251 goto fail_cmd;
4252 }
4253
4254 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4255 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4256 return -EINVAL;
4257 }
4258
4259 sz = sizeof(struct audproc_volume_ctrl_master_gain);
4260 audproc_vol.params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4261 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4262 audproc_vol.params.hdr.pkt_size = sz;
4263 audproc_vol.params.hdr.src_svc = APR_SVC_ADM;
4264 audproc_vol.params.hdr.src_domain = APR_DOMAIN_APPS;
4265 audproc_vol.params.hdr.src_port = port_id;
4266 audproc_vol.params.hdr.dest_svc = APR_SVC_ADM;
4267 audproc_vol.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4268 audproc_vol.params.hdr.dest_port =
4269 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4270 audproc_vol.params.hdr.token = port_idx << 16 | copp_idx;
4271 audproc_vol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4272 audproc_vol.params.payload_addr_lsw = 0;
4273 audproc_vol.params.payload_addr_msw = 0;
4274 audproc_vol.params.mem_map_handle = 0;
4275 audproc_vol.params.payload_size = sizeof(audproc_vol) -
4276 sizeof(audproc_vol.params);
4277 audproc_vol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL;
4278 audproc_vol.data.param_id = AUDPROC_PARAM_ID_VOL_CTRL_MASTER_GAIN;
4279 audproc_vol.data.param_size = audproc_vol.params.payload_size -
4280 sizeof(audproc_vol.data);
4281 audproc_vol.data.reserved = 0;
4282 audproc_vol.master_gain = volume;
4283
4284 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4285 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_vol);
4286 if (rc < 0) {
4287 pr_err("%s: Set params failed port = %#x\n",
4288 __func__, port_id);
4289 rc = -EINVAL;
4290 goto fail_cmd;
4291 }
4292 /* Wait for the callback */
4293 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4294 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4295 msecs_to_jiffies(TIMEOUT_MS));
4296 if (!rc) {
4297 pr_err("%s: Vol cntrl Set params timed out port = %#x\n",
4298 __func__, port_id);
4299 rc = -EINVAL;
4300 goto fail_cmd;
4301 } else if (atomic_read(&this_adm.copp.stat
4302 [port_idx][copp_idx]) > 0) {
4303 pr_err("%s: DSP returned error[%s]\n",
4304 __func__, adsp_err_get_err_str(
4305 atomic_read(&this_adm.copp.stat
4306 [port_idx][copp_idx])));
4307 rc = adsp_err_get_lnx_err_code(
4308 atomic_read(&this_adm.copp.stat
4309 [port_idx][copp_idx]));
4310 goto fail_cmd;
4311 }
4312 rc = 0;
4313fail_cmd:
4314 return rc;
4315}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304316EXPORT_SYMBOL(adm_set_volume);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304317
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304318/**
4319 * adm_set_softvolume -
4320 * command to set softvolume
4321 *
4322 * @port_id: Port ID number
4323 * @copp_idx: copp index assigned
4324 * @softvol_param: Params to set for softvolume
4325 *
4326 * Returns 0 on success or error on failure
4327 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304328int adm_set_softvolume(int port_id, int copp_idx,
4329 struct audproc_softvolume_params *softvol_param)
4330{
4331 struct audproc_soft_step_volume_params audproc_softvol;
4332 int sz = 0;
4333 int rc = 0;
4334 int port_idx;
4335
4336 pr_debug("%s: period %d step %d curve %d\n", __func__,
4337 softvol_param->period, softvol_param->step,
4338 softvol_param->rampingcurve);
4339
4340 port_id = afe_convert_virtual_to_portid(port_id);
4341 port_idx = adm_validate_and_get_port_index(port_id);
4342 if (port_idx < 0) {
4343 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4344 rc = -EINVAL;
4345 goto fail_cmd;
4346 }
4347
4348 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4349 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4350 return -EINVAL;
4351 }
4352
4353 sz = sizeof(struct audproc_soft_step_volume_params);
4354
4355 audproc_softvol.params.hdr.hdr_field =
4356 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4357 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4358 audproc_softvol.params.hdr.pkt_size = sz;
4359 audproc_softvol.params.hdr.src_svc = APR_SVC_ADM;
4360 audproc_softvol.params.hdr.src_domain = APR_DOMAIN_APPS;
4361 audproc_softvol.params.hdr.src_port = port_id;
4362 audproc_softvol.params.hdr.dest_svc = APR_SVC_ADM;
4363 audproc_softvol.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4364 audproc_softvol.params.hdr.dest_port =
4365 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4366 audproc_softvol.params.hdr.token = port_idx << 16 | copp_idx;
4367 audproc_softvol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4368 audproc_softvol.params.payload_addr_lsw = 0;
4369 audproc_softvol.params.payload_addr_msw = 0;
4370 audproc_softvol.params.mem_map_handle = 0;
4371 audproc_softvol.params.payload_size = sizeof(audproc_softvol) -
4372 sizeof(audproc_softvol.params);
4373 audproc_softvol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL;
4374 audproc_softvol.data.param_id =
4375 AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS;
4376 audproc_softvol.data.param_size = audproc_softvol.params.payload_size -
4377 sizeof(audproc_softvol.data);
4378 audproc_softvol.data.reserved = 0;
4379 audproc_softvol.period = softvol_param->period;
4380 audproc_softvol.step = softvol_param->step;
4381 audproc_softvol.ramping_curve = softvol_param->rampingcurve;
4382
4383 pr_debug("%s: period %d, step %d, curve %d\n", __func__,
4384 audproc_softvol.period, audproc_softvol.step,
4385 audproc_softvol.ramping_curve);
4386
4387 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4388 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_softvol);
4389 if (rc < 0) {
4390 pr_err("%s: Set params failed port = %#x\n",
4391 __func__, port_id);
4392 rc = -EINVAL;
4393 goto fail_cmd;
4394 }
4395 /* Wait for the callback */
4396 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4397 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4398 msecs_to_jiffies(TIMEOUT_MS));
4399 if (!rc) {
4400 pr_err("%s: Soft volume Set params timed out port = %#x\n",
4401 __func__, port_id);
4402 rc = -EINVAL;
4403 goto fail_cmd;
4404 } else if (atomic_read(&this_adm.copp.stat
4405 [port_idx][copp_idx]) > 0) {
4406 pr_err("%s: DSP returned error[%s]\n",
4407 __func__, adsp_err_get_err_str(
4408 atomic_read(&this_adm.copp.stat
4409 [port_idx][copp_idx])));
4410 rc = adsp_err_get_lnx_err_code(
4411 atomic_read(&this_adm.copp.stat
4412 [port_idx][copp_idx]));
4413 goto fail_cmd;
4414 }
4415 rc = 0;
4416fail_cmd:
4417 return rc;
4418}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304419EXPORT_SYMBOL(adm_set_softvolume);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304420
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304421/**
4422 * adm_set_mic_gain -
4423 * command to set MIC gain
4424 *
4425 * @port_id: Port ID number
4426 * @copp_idx: copp index assigned
4427 * @volume: gain value to set
4428 *
4429 * Returns 0 on success or error on failure
4430 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304431int adm_set_mic_gain(int port_id, int copp_idx, int volume)
4432{
4433 struct adm_set_mic_gain_params mic_gain_params;
4434 int rc = 0;
4435 int sz, port_idx;
4436
4437 pr_debug("%s:\n", __func__);
4438 port_id = afe_convert_virtual_to_portid(port_id);
4439 port_idx = adm_validate_and_get_port_index(port_id);
4440 if (port_idx < 0) {
4441 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
4442 return -EINVAL;
4443 }
4444
4445 sz = sizeof(struct adm_set_mic_gain_params);
4446
4447 mic_gain_params.params.hdr.hdr_field =
4448 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4449 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4450 mic_gain_params.params.hdr.pkt_size = sz;
4451 mic_gain_params.params.hdr.src_svc = APR_SVC_ADM;
4452 mic_gain_params.params.hdr.src_domain = APR_DOMAIN_APPS;
4453 mic_gain_params.params.hdr.src_port = port_id;
4454 mic_gain_params.params.hdr.dest_svc = APR_SVC_ADM;
4455 mic_gain_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4456 mic_gain_params.params.hdr.dest_port =
4457 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4458 mic_gain_params.params.hdr.token = port_idx << 16 | copp_idx;
4459 mic_gain_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4460 mic_gain_params.params.payload_addr_lsw = 0;
4461 mic_gain_params.params.payload_addr_msw = 0;
4462 mic_gain_params.params.mem_map_handle = 0;
4463 mic_gain_params.params.payload_size =
4464 sizeof(struct adm_param_data_v5) +
4465 sizeof(struct admx_mic_gain);
4466 mic_gain_params.data.module_id = ADM_MODULE_IDX_MIC_GAIN_CTRL;
4467 mic_gain_params.data.param_id = ADM_PARAM_IDX_MIC_GAIN;
4468 mic_gain_params.data.param_size =
4469 sizeof(struct admx_mic_gain);
4470 mic_gain_params.data.reserved = 0;
4471 mic_gain_params.mic_gain_data.tx_mic_gain = volume;
4472 mic_gain_params.mic_gain_data.reserved = 0;
4473 pr_debug("%s: Mic Gain set to %d at port_id 0x%x\n",
4474 __func__, volume, port_id);
4475
4476 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4477 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mic_gain_params);
4478 if (rc < 0) {
4479 pr_err("%s: Set params failed port = %#x\n",
4480 __func__, port_id);
4481 rc = -EINVAL;
4482 goto fail_cmd;
4483 }
4484 /* Wait for the callback */
4485 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4486 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4487 msecs_to_jiffies(TIMEOUT_MS));
4488 if (!rc) {
4489 pr_err("%s: Mic Gain Set params timed out port = %#x\n",
4490 __func__, port_id);
4491 rc = -EINVAL;
4492 goto fail_cmd;
4493 } else if (atomic_read(&this_adm.copp.stat
4494 [port_idx][copp_idx]) > 0) {
4495 pr_err("%s: DSP returned error[%s]\n",
4496 __func__, adsp_err_get_err_str(
4497 atomic_read(&this_adm.copp.stat
4498 [port_idx][copp_idx])));
4499 rc = adsp_err_get_lnx_err_code(
4500 atomic_read(&this_adm.copp.stat
4501 [port_idx][copp_idx]));
4502 goto fail_cmd;
4503 }
4504 rc = 0;
4505fail_cmd:
4506 return rc;
4507}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304508EXPORT_SYMBOL(adm_set_mic_gain);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304509
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304510/**
4511 * adm_send_set_multichannel_ec_primary_mic_ch -
4512 * command to set multi-ch EC primary mic
4513 *
4514 * @port_id: Port ID number
4515 * @copp_idx: copp index assigned
4516 * @primary_mic_ch: channel number of primary mic
4517 *
4518 * Returns 0 on success or error on failure
4519 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304520int adm_send_set_multichannel_ec_primary_mic_ch(int port_id, int copp_idx,
4521 int primary_mic_ch)
4522{
4523 struct adm_set_sec_primary_ch_params sec_primary_ch_params;
4524 int rc = 0;
4525 int sz, port_idx;
4526
4527 pr_debug("%s port_id 0x%x, copp_idx 0x%x, primary_mic_ch %d\n",
4528 __func__, port_id, copp_idx, primary_mic_ch);
4529 port_id = afe_convert_virtual_to_portid(port_id);
4530 port_idx = adm_validate_and_get_port_index(port_id);
4531 if (port_idx < 0) {
4532 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
4533 return -EINVAL;
4534 }
4535
4536 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4537 pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx);
4538 return -EINVAL;
4539 }
4540
4541 sz = sizeof(struct adm_set_sec_primary_ch_params);
4542
4543 sec_primary_ch_params.params.hdr.hdr_field =
4544 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4545 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4546 sec_primary_ch_params.params.hdr.pkt_size = sz;
4547 sec_primary_ch_params.params.hdr.src_svc = APR_SVC_ADM;
4548 sec_primary_ch_params.params.hdr.src_domain = APR_DOMAIN_APPS;
4549 sec_primary_ch_params.params.hdr.src_port = port_id;
4550 sec_primary_ch_params.params.hdr.dest_svc = APR_SVC_ADM;
4551 sec_primary_ch_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
4552 sec_primary_ch_params.params.hdr.dest_port =
4553 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4554 sec_primary_ch_params.params.hdr.token = port_idx << 16 | copp_idx;
4555 sec_primary_ch_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4556 sec_primary_ch_params.params.payload_addr_lsw = 0;
4557 sec_primary_ch_params.params.payload_addr_msw = 0;
4558 sec_primary_ch_params.params.mem_map_handle = 0;
4559 sec_primary_ch_params.params.payload_size =
4560 sizeof(struct adm_param_data_v5) +
4561 sizeof(struct admx_sec_primary_mic_ch);
4562 sec_primary_ch_params.data.module_id =
4563 AUDPROC_MODULE_ID_VOICE_TX_SECNS;
4564 sec_primary_ch_params.data.param_id =
4565 AUDPROC_PARAM_IDX_SEC_PRIMARY_MIC_CH;
4566 sec_primary_ch_params.data.param_size =
4567 sizeof(struct admx_sec_primary_mic_ch);
4568 sec_primary_ch_params.data.reserved = 0;
4569 sec_primary_ch_params.sec_primary_mic_ch_data.version = 0;
4570 sec_primary_ch_params.sec_primary_mic_ch_data.reserved = 0;
4571 sec_primary_ch_params.sec_primary_mic_ch_data.sec_primary_mic_ch =
4572 primary_mic_ch;
4573 sec_primary_ch_params.sec_primary_mic_ch_data.reserved1 = 0;
4574
4575 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4576 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&sec_primary_ch_params);
4577 if (rc < 0) {
4578 pr_err("%s: Set params failed port = %#x\n",
4579 __func__, port_id);
4580 rc = -EINVAL;
4581 goto fail_cmd;
4582 }
4583 /* Wait for the callback */
4584 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4585 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4586 msecs_to_jiffies(TIMEOUT_MS));
4587 if (!rc) {
4588 pr_err("%s: Mic Set params timed out port = %#x\n",
4589 __func__, port_id);
4590 rc = -EINVAL;
4591 goto fail_cmd;
4592 } else if (atomic_read(&this_adm.copp.stat
4593 [port_idx][copp_idx]) > 0) {
4594 pr_err("%s: DSP returned error[%s]\n",
4595 __func__, adsp_err_get_err_str(
4596 atomic_read(&this_adm.copp.stat
4597 [port_idx][copp_idx])));
4598 rc = adsp_err_get_lnx_err_code(
4599 atomic_read(&this_adm.copp.stat
4600 [port_idx][copp_idx]));
4601 goto fail_cmd;
4602 }
4603 rc = 0;
4604fail_cmd:
4605 return rc;
4606}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304607EXPORT_SYMBOL(adm_send_set_multichannel_ec_primary_mic_ch);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304608
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304609/**
4610 * adm_param_enable -
4611 * command to send params to ADM for given module
4612 *
4613 * @port_id: Port ID number
4614 * @copp_idx: copp index assigned
4615 * @module_id: ADM module
4616 * @enable: flag to enable or disable module
4617 *
4618 * Returns 0 on success or error on failure
4619 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304620int adm_param_enable(int port_id, int copp_idx, int module_id, int enable)
4621{
4622 struct audproc_enable_param_t adm_mod_enable;
4623 int sz = 0;
4624 int rc = 0;
4625 int port_idx;
4626
4627 pr_debug("%s port_id %d, module_id 0x%x, enable %d\n",
4628 __func__, port_id, module_id, enable);
4629 port_id = afe_convert_virtual_to_portid(port_id);
4630 port_idx = adm_validate_and_get_port_index(port_id);
4631 if (port_idx < 0) {
4632 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4633 rc = -EINVAL;
4634 goto fail_cmd;
4635 }
4636
4637 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4638 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4639 return -EINVAL;
4640 }
4641
4642 sz = sizeof(struct audproc_enable_param_t);
4643
4644 adm_mod_enable.pp_params.hdr.hdr_field =
4645 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4646 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4647 adm_mod_enable.pp_params.hdr.pkt_size = sz;
4648 adm_mod_enable.pp_params.hdr.src_svc = APR_SVC_ADM;
4649 adm_mod_enable.pp_params.hdr.src_domain = APR_DOMAIN_APPS;
4650 adm_mod_enable.pp_params.hdr.src_port = port_id;
4651 adm_mod_enable.pp_params.hdr.dest_svc = APR_SVC_ADM;
4652 adm_mod_enable.pp_params.hdr.dest_domain = APR_DOMAIN_ADSP;
4653 adm_mod_enable.pp_params.hdr.dest_port =
4654 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4655 adm_mod_enable.pp_params.hdr.token = port_idx << 16 | copp_idx;
4656 adm_mod_enable.pp_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4657 adm_mod_enable.pp_params.payload_addr_lsw = 0;
4658 adm_mod_enable.pp_params.payload_addr_msw = 0;
4659 adm_mod_enable.pp_params.mem_map_handle = 0;
4660 adm_mod_enable.pp_params.payload_size = sizeof(adm_mod_enable) -
4661 sizeof(adm_mod_enable.pp_params) +
4662 sizeof(adm_mod_enable.pp_params.params);
4663 adm_mod_enable.pp_params.params.module_id = module_id;
4664 adm_mod_enable.pp_params.params.param_id = AUDPROC_PARAM_ID_ENABLE;
4665 adm_mod_enable.pp_params.params.param_size =
4666 adm_mod_enable.pp_params.payload_size -
4667 sizeof(adm_mod_enable.pp_params.params);
4668 adm_mod_enable.pp_params.params.reserved = 0;
4669 adm_mod_enable.enable = enable;
4670
4671 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4672
4673 rc = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_mod_enable);
4674 if (rc < 0) {
4675 pr_err("%s: Set params failed port = %#x\n",
4676 __func__, port_id);
4677 rc = -EINVAL;
4678 goto fail_cmd;
4679 }
4680 /* Wait for the callback */
4681 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4682 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4683 msecs_to_jiffies(TIMEOUT_MS));
4684 if (!rc) {
4685 pr_err("%s: module %x enable %d timed out on port = %#x\n",
4686 __func__, module_id, enable, port_id);
4687 rc = -EINVAL;
4688 goto fail_cmd;
4689 } else if (atomic_read(&this_adm.copp.stat
4690 [port_idx][copp_idx]) > 0) {
4691 pr_err("%s: DSP returned error[%s]\n",
4692 __func__, adsp_err_get_err_str(
4693 atomic_read(&this_adm.copp.stat
4694 [port_idx][copp_idx])));
4695 rc = adsp_err_get_lnx_err_code(
4696 atomic_read(&this_adm.copp.stat
4697 [port_idx][copp_idx]));
4698 goto fail_cmd;
4699 }
4700 rc = 0;
4701fail_cmd:
4702 return rc;
4703
4704}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304705EXPORT_SYMBOL(adm_param_enable);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304706
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304707/**
4708 * adm_send_calibration -
4709 * send ADM calibration to DSP
4710 *
4711 * @port_id: Port ID number
4712 * @copp_idx: copp index assigned
4713 * @path: direction or ADM path type
4714 * @perf_mode: performance mode like LL/ULL/..
4715 * @cal_type: calibration type to use
4716 * @params: pointer with cal data
4717 * @size: cal size
4718 *
4719 * Returns 0 on success or error on failure
4720 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304721int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode,
4722 int cal_type, char *params, int size)
4723{
4724
4725 struct adm_cmd_set_pp_params_v5 *adm_params = NULL;
4726 int sz, rc = 0;
4727 int port_idx;
4728
4729 pr_debug("%s:port_id %d, path %d, perf_mode %d, cal_type %d, size %d\n",
4730 __func__, port_id, path, perf_mode, cal_type, size);
4731
4732 port_id = afe_convert_virtual_to_portid(port_id);
4733 port_idx = adm_validate_and_get_port_index(port_id);
4734 if (port_idx < 0) {
4735 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4736 rc = -EINVAL;
4737 goto end;
4738 }
4739
4740 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4741 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4742 return -EINVAL;
4743 }
4744
4745 /* Maps audio_dev_ctrl path definition to ACDB definition */
4746 if (get_cal_path(path) != RX_DEVICE) {
4747 pr_err("%s: acdb_path %d\n", __func__, path);
4748 rc = -EINVAL;
4749 goto end;
4750 }
4751
4752 sz = sizeof(struct adm_cmd_set_pp_params_v5) + size;
4753 adm_params = kzalloc(sz, GFP_KERNEL);
4754 if (!adm_params) {
4755 pr_err("%s, adm params memory alloc failed", __func__);
4756 rc = -ENOMEM;
4757 goto end;
4758 }
4759
4760 memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)),
4761 params, size);
4762
4763 adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
4764 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
4765 adm_params->hdr.pkt_size = sz;
4766 adm_params->hdr.src_svc = APR_SVC_ADM;
4767 adm_params->hdr.src_domain = APR_DOMAIN_APPS;
4768 adm_params->hdr.src_port = port_id;
4769 adm_params->hdr.dest_svc = APR_SVC_ADM;
4770 adm_params->hdr.dest_domain = APR_DOMAIN_ADSP;
4771 adm_params->hdr.dest_port =
4772 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
4773 adm_params->hdr.token = port_idx << 16 | copp_idx;
4774 adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
4775 /* payload address and mmap handle initialized to zero by kzalloc */
4776 adm_params->payload_size = size;
4777
4778 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
4779 rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params);
4780 if (rc < 0) {
4781 pr_err("%s: Set params failed port = %#x\n",
4782 __func__, port_id);
4783 rc = -EINVAL;
4784 goto end;
4785 }
4786 /* Wait for the callback */
4787 rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
4788 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
4789 msecs_to_jiffies(TIMEOUT_MS));
4790 if (!rc) {
4791 pr_err("%s: Set params timed out port = %#x\n",
4792 __func__, port_id);
4793 rc = -EINVAL;
4794 goto end;
4795 } else if (atomic_read(&this_adm.copp.stat
4796 [port_idx][copp_idx]) > 0) {
4797 pr_err("%s: DSP returned error[%s]\n",
4798 __func__, adsp_err_get_err_str(
4799 atomic_read(&this_adm.copp.stat
4800 [port_idx][copp_idx])));
4801 rc = adsp_err_get_lnx_err_code(
4802 atomic_read(&this_adm.copp.stat
4803 [port_idx][copp_idx]));
4804 goto end;
4805 }
4806 rc = 0;
4807
4808end:
4809 kfree(adm_params);
4810 return rc;
4811}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304812EXPORT_SYMBOL(adm_send_calibration);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304813
4814/*
4815 * adm_update_wait_parameters must be called with routing driver locks.
4816 * adm_reset_wait_parameters must be called with routing driver locks.
4817 * set and reset parmeters are separated to make sure it is always called
4818 * under routing driver lock.
4819 * adm_wait_timeout is to block until timeout or interrupted. Timeout is
4820 * not a an error.
4821 */
4822int adm_set_wait_parameters(int port_id, int copp_idx)
4823{
4824
4825 int ret = 0, port_idx;
4826
4827 pr_debug("%s: port_id 0x%x, copp_idx %d\n", __func__, port_id,
4828 copp_idx);
4829 port_id = afe_convert_virtual_to_portid(port_id);
4830 port_idx = adm_validate_and_get_port_index(port_id);
4831 if (port_idx < 0) {
4832 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4833 ret = -EINVAL;
4834 goto end;
4835 }
4836
4837 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4838 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4839 return -EINVAL;
4840 }
4841
4842 this_adm.copp.adm_delay[port_idx][copp_idx] = 1;
4843 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 0);
4844
4845end:
4846 return ret;
4847
4848}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304849EXPORT_SYMBOL(adm_set_wait_parameters);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304850
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304851/**
4852 * adm_reset_wait_parameters -
4853 * reset wait parameters or ADM delay value
4854 *
4855 * @port_id: Port ID number
4856 * @copp_idx: copp index assigned
4857 *
4858 * Returns 0 on success or error on failure
4859 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304860int adm_reset_wait_parameters(int port_id, int copp_idx)
4861{
4862 int ret = 0, port_idx;
4863
4864 pr_debug("%s: port_id 0x%x copp_idx %d\n", __func__, port_id,
4865 copp_idx);
4866 port_id = afe_convert_virtual_to_portid(port_id);
4867 port_idx = adm_validate_and_get_port_index(port_id);
4868 if (port_idx < 0) {
4869 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4870 ret = -EINVAL;
4871 goto end;
4872 }
4873
4874 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4875 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4876 return -EINVAL;
4877 }
4878
4879 atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], 1);
4880 this_adm.copp.adm_delay[port_idx][copp_idx] = 0;
4881
4882end:
4883 return ret;
4884}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304885EXPORT_SYMBOL(adm_reset_wait_parameters);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304886
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304887/**
4888 * adm_wait_timeout -
4889 * ADM wait command after command send to DSP
4890 *
4891 * @port_id: Port ID number
4892 * @copp_idx: copp index assigned
4893 * @wait_time: value in ms for command timeout
4894 *
4895 * Returns 0 on success or error on failure
4896 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304897int adm_wait_timeout(int port_id, int copp_idx, int wait_time)
4898{
4899 int ret = 0, port_idx;
4900
4901 pr_debug("%s: port_id 0x%x, copp_idx %d, wait_time %d\n", __func__,
4902 port_id, copp_idx, wait_time);
4903 port_id = afe_convert_virtual_to_portid(port_id);
4904 port_idx = adm_validate_and_get_port_index(port_id);
4905 if (port_idx < 0) {
4906 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
4907 ret = -EINVAL;
4908 goto end;
4909 }
4910
4911 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4912 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4913 return -EINVAL;
4914 }
4915
4916 ret = wait_event_timeout(
4917 this_adm.copp.adm_delay_wait[port_idx][copp_idx],
4918 atomic_read(&this_adm.copp.adm_delay_stat[port_idx][copp_idx]),
4919 msecs_to_jiffies(wait_time));
4920 pr_debug("%s: return %d\n", __func__, ret);
4921 if (ret != 0)
4922 ret = -EINTR;
4923end:
4924 pr_debug("%s: return %d--\n", __func__, ret);
4925 return ret;
4926}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304927EXPORT_SYMBOL(adm_wait_timeout);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304928
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05304929/**
4930 * adm_store_cal_data -
4931 * Retrieve calibration data for ADM copp device
4932 *
4933 * @port_id: Port ID number
4934 * @copp_idx: copp index assigned
4935 * @path: direction or copp type
4936 * @perf_mode: performance mode like LL/ULL/..
4937 * @cal_index: calibration index to use
4938 * @params: pointer to store cal data
4939 * @size: pointer to fill with cal size
4940 *
4941 * Returns 0 on success or error on failure
4942 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304943int adm_store_cal_data(int port_id, int copp_idx, int path, int perf_mode,
4944 int cal_index, char *params, int *size)
4945{
4946 int rc = 0;
4947 struct cal_block_data *cal_block = NULL;
4948 int app_type, acdb_id, port_idx, sample_rate;
4949
4950 if (this_adm.cal_data[cal_index] == NULL) {
4951 pr_debug("%s: cal_index %d not allocated!\n",
4952 __func__, cal_index);
4953 goto end;
4954 }
4955
4956 if (get_cal_path(path) != RX_DEVICE) {
4957 pr_debug("%s: Invalid path to store calibration %d\n",
4958 __func__, path);
4959 rc = -EINVAL;
4960 goto end;
4961 }
4962
4963 port_id = afe_convert_virtual_to_portid(port_id);
4964 port_idx = adm_validate_and_get_port_index(port_id);
4965 if (port_idx < 0) {
4966 pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id);
4967 rc = -EINVAL;
4968 goto end;
4969 }
4970
4971 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
4972 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
4973 return -EINVAL;
4974 }
4975
4976 acdb_id = atomic_read(&this_adm.copp.acdb_id[port_idx][copp_idx]);
4977 app_type = atomic_read(&this_adm.copp.app_type[port_idx][copp_idx]);
4978 sample_rate = atomic_read(&this_adm.copp.rate[port_idx][copp_idx]);
4979
4980 mutex_lock(&this_adm.cal_data[cal_index]->lock);
4981 cal_block = adm_find_cal(cal_index, get_cal_path(path), app_type,
4982 acdb_id, sample_rate);
4983 if (cal_block == NULL)
4984 goto unlock;
4985
4986 if (cal_block->cal_data.size <= 0) {
4987 pr_debug("%s: No ADM cal send for port_id = 0x%x!\n",
4988 __func__, port_id);
4989 rc = -EINVAL;
4990 goto unlock;
4991 }
4992
Aditya Bavanari2a627ae2017-11-21 20:24:53 +05304993 if (cal_index == ADM_AUDPROC_CAL || cal_index == ADM_LSM_AUDPROC_CAL) {
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304994 if (cal_block->cal_data.size > AUD_PROC_BLOCK_SIZE) {
4995 pr_err("%s:audproc:invalid size exp/actual[%zd, %d]\n",
4996 __func__, cal_block->cal_data.size, *size);
4997 rc = -ENOMEM;
4998 goto unlock;
4999 }
Bhalchandra Gajareface2762018-05-10 14:16:49 -07005000 } else if (cal_index == ADM_LSM_AUDPROC_PERSISTENT_CAL) {
5001 if (cal_block->cal_data.size > AUD_PROC_PERSIST_BLOCK_SIZE) {
5002 pr_err("%s:persist invalid size exp/actual[%zd, %d]\n",
5003 __func__, cal_block->cal_data.size, *size);
5004 rc = -ENOMEM;
5005 goto unlock;
5006 }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305007 } else if (cal_index == ADM_AUDVOL_CAL) {
5008 if (cal_block->cal_data.size > AUD_VOL_BLOCK_SIZE) {
5009 pr_err("%s:aud_vol:invalid size exp/actual[%zd, %d]\n",
5010 __func__, cal_block->cal_data.size, *size);
5011 rc = -ENOMEM;
5012 goto unlock;
5013 }
5014 } else {
5015 pr_debug("%s: Not valid calibration for dolby topolgy\n",
5016 __func__);
5017 rc = -EINVAL;
5018 goto unlock;
5019 }
5020 memcpy(params, cal_block->cal_data.kvaddr, cal_block->cal_data.size);
5021 *size = cal_block->cal_data.size;
5022
5023 pr_debug("%s:port_id %d, copp_idx %d, path %d",
5024 __func__, port_id, copp_idx, path);
5025 pr_debug("perf_mode %d, cal_type %d, size %d\n",
5026 perf_mode, cal_index, *size);
5027
5028unlock:
5029 mutex_unlock(&this_adm.cal_data[cal_index]->lock);
5030end:
5031 return rc;
5032}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305033EXPORT_SYMBOL(adm_store_cal_data);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305034
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305035/**
5036 * adm_send_compressed_device_mute -
5037 * command to send mute for compressed device
5038 *
5039 * @port_id: Port ID number
5040 * @copp_idx: copp index assigned
5041 * @mute_on: flag to indicate mute or unmute
5042 *
5043 * Returns 0 on success or error on failure
5044 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305045int adm_send_compressed_device_mute(int port_id, int copp_idx, bool mute_on)
5046{
5047 struct adm_set_compressed_device_mute mute_params;
5048 int ret = 0;
5049 int port_idx;
5050
5051 pr_debug("%s port_id: 0x%x, copp_idx %d, mute_on: %d\n",
5052 __func__, port_id, copp_idx, mute_on);
5053 port_id = afe_convert_virtual_to_portid(port_id);
5054 port_idx = adm_validate_and_get_port_index(port_id);
5055 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
5056 pr_err("%s: Invalid port_id %#x copp_idx %d\n",
5057 __func__, port_id, copp_idx);
5058 ret = -EINVAL;
5059 goto end;
5060 }
5061
5062 mute_params.command.hdr.hdr_field =
5063 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
5064 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
5065 mute_params.command.hdr.pkt_size =
5066 sizeof(struct adm_set_compressed_device_mute);
5067 mute_params.command.hdr.src_svc = APR_SVC_ADM;
5068 mute_params.command.hdr.src_domain = APR_DOMAIN_APPS;
5069 mute_params.command.hdr.src_port = port_id;
5070 mute_params.command.hdr.dest_svc = APR_SVC_ADM;
5071 mute_params.command.hdr.dest_domain = APR_DOMAIN_ADSP;
5072 mute_params.command.hdr.dest_port =
5073 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
5074 mute_params.command.hdr.token = port_idx << 16 | copp_idx;
5075 mute_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
5076 mute_params.command.payload_addr_lsw = 0;
5077 mute_params.command.payload_addr_msw = 0;
5078 mute_params.command.mem_map_handle = 0;
5079 mute_params.command.payload_size = sizeof(mute_params) -
5080 sizeof(mute_params.command);
5081 mute_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_MUTE;
5082 mute_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_MUTE;
5083 mute_params.params.param_size = mute_params.command.payload_size -
5084 sizeof(mute_params.params);
5085 mute_params.params.reserved = 0;
5086 mute_params.mute_on = mute_on;
5087
5088 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
5089 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mute_params);
5090 if (ret < 0) {
5091 pr_err("%s: device mute for port %d copp %d failed, ret %d\n",
5092 __func__, port_id, copp_idx, ret);
5093 ret = -EINVAL;
5094 goto end;
5095 }
5096
5097 /* Wait for the callback */
5098 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
5099 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
5100 msecs_to_jiffies(TIMEOUT_MS));
5101 if (!ret) {
5102 pr_err("%s: send device mute for port %d copp %d failed\n",
5103 __func__, port_id, copp_idx);
5104 ret = -EINVAL;
5105 goto end;
5106 } else if (atomic_read(&this_adm.copp.stat
5107 [port_idx][copp_idx]) > 0) {
5108 pr_err("%s: DSP returned error[%s]\n",
5109 __func__, adsp_err_get_err_str(
5110 atomic_read(&this_adm.copp.stat
5111 [port_idx][copp_idx])));
5112 ret = adsp_err_get_lnx_err_code(
5113 atomic_read(&this_adm.copp.stat
5114 [port_idx][copp_idx]));
5115 goto end;
5116 }
5117 ret = 0;
5118end:
5119 return ret;
5120}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305121EXPORT_SYMBOL(adm_send_compressed_device_mute);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305122
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305123/**
5124 * adm_send_compressed_device_latency -
5125 * command to send latency for compressed device
5126 *
5127 * @port_id: Port ID number
5128 * @copp_idx: copp index assigned
5129 * @latency: latency value to pass
5130 *
5131 * Returns 0 on success or error on failure
5132 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305133int adm_send_compressed_device_latency(int port_id, int copp_idx, int latency)
5134{
5135 struct adm_set_compressed_device_latency latency_params;
5136 int port_idx;
5137 int ret = 0;
5138
5139 pr_debug("%s port_id: 0x%x, copp_idx %d latency: %d\n", __func__,
5140 port_id, copp_idx, latency);
5141 port_id = afe_convert_virtual_to_portid(port_id);
5142 port_idx = adm_validate_and_get_port_index(port_id);
5143 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
5144 pr_err("%s: Invalid port_id %#x copp_idx %d\n",
5145 __func__, port_id, copp_idx);
5146 ret = -EINVAL;
5147 goto end;
5148 }
5149
5150 latency_params.command.hdr.hdr_field =
5151 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
5152 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
5153 latency_params.command.hdr.pkt_size =
5154 sizeof(struct adm_set_compressed_device_latency);
5155 latency_params.command.hdr.src_svc = APR_SVC_ADM;
5156 latency_params.command.hdr.src_domain = APR_DOMAIN_APPS;
5157 latency_params.command.hdr.src_port = port_id;
5158 latency_params.command.hdr.dest_svc = APR_SVC_ADM;
5159 latency_params.command.hdr.dest_domain = APR_DOMAIN_ADSP;
5160 latency_params.command.hdr.dest_port =
5161 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
5162 latency_params.command.hdr.token = port_idx << 16 | copp_idx;
5163 latency_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
5164 latency_params.command.payload_addr_lsw = 0;
5165 latency_params.command.payload_addr_msw = 0;
5166 latency_params.command.mem_map_handle = 0;
5167 latency_params.command.payload_size = sizeof(latency_params) -
5168 sizeof(latency_params.command);
5169 latency_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_LATENCY;
5170 latency_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_LATENCY;
5171 latency_params.params.param_size = latency_params.command.payload_size -
5172 sizeof(latency_params.params);
5173 latency_params.params.reserved = 0;
5174 latency_params.latency = latency;
5175
5176 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
5177 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&latency_params);
5178 if (ret < 0) {
5179 pr_err("%s: send device latency err %d for port %d copp %d\n",
5180 __func__, port_id, copp_idx, ret);
5181 ret = -EINVAL;
5182 goto end;
5183 }
5184
5185 /* Wait for the callback */
5186 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
5187 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
5188 msecs_to_jiffies(TIMEOUT_MS));
5189 if (!ret) {
5190 pr_err("%s: send device latency for port %d failed\n", __func__,
5191 port_id);
5192 ret = -EINVAL;
5193 goto end;
5194 } else if (atomic_read(&this_adm.copp.stat
5195 [port_idx][copp_idx]) > 0) {
5196 pr_err("%s: DSP returned error[%s]\n",
5197 __func__, adsp_err_get_err_str(
5198 atomic_read(&this_adm.copp.stat
5199 [port_idx][copp_idx])));
5200 ret = adsp_err_get_lnx_err_code(
5201 atomic_read(&this_adm.copp.stat
5202 [port_idx][copp_idx]));
5203 goto end;
5204 }
5205 ret = 0;
5206end:
5207 return ret;
5208}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305209EXPORT_SYMBOL(adm_send_compressed_device_latency);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305210
5211/**
5212 * adm_swap_speaker_channels
5213 *
5214 * Receives port_id, copp_idx, sample rate, spk_swap and
5215 * send MFC command to swap speaker channel.
5216 * Return zero on success. On failure returns nonzero.
5217 *
5218 * port_id - Passed value, port_id for which channels swap is wanted
5219 * copp_idx - Passed value, copp_idx for which channels swap is wanted
5220 * sample_rate - Passed value, sample rate used by app type config
5221 * spk_swap - Passed value, spk_swap for check if swap flag is set
5222 */
5223int adm_swap_speaker_channels(int port_id, int copp_idx,
5224 int sample_rate, bool spk_swap)
5225{
5226 struct audproc_mfc_output_media_fmt mfc_cfg;
5227 uint16_t num_channels;
5228 int port_idx;
5229 int ret = 0;
5230
5231 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
5232 __func__, port_id, copp_idx);
5233 port_id = q6audio_convert_virtual_to_portid(port_id);
5234 port_idx = adm_validate_and_get_port_index(port_id);
5235 if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
5236 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
5237 ret = -EINVAL;
5238 goto done;
5239 }
5240
5241 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
5242 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
5243 ret = -EINVAL;
5244 goto done;
5245 }
5246
5247 num_channels = atomic_read(
5248 &this_adm.copp.channels[port_idx][copp_idx]);
5249 if (num_channels != 2) {
5250 pr_debug("%s: Invalid number of channels: %d\n",
5251 __func__, num_channels);
5252 ret = -EINVAL;
5253 goto done;
5254 }
5255
5256 memset(&mfc_cfg, 0, sizeof(mfc_cfg));
5257 mfc_cfg.params.hdr.hdr_field =
5258 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
5259 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
5260 mfc_cfg.params.hdr.pkt_size =
5261 sizeof(mfc_cfg);
5262 mfc_cfg.params.hdr.src_svc = APR_SVC_ADM;
5263 mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS;
5264 mfc_cfg.params.hdr.src_port = port_id;
5265 mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM;
5266 mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP;
5267 mfc_cfg.params.hdr.dest_port =
5268 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
5269 mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx;
5270 mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
5271 mfc_cfg.params.payload_addr_lsw = 0;
5272 mfc_cfg.params.payload_addr_msw = 0;
5273 mfc_cfg.params.mem_map_handle = 0;
5274 mfc_cfg.params.payload_size = sizeof(mfc_cfg) -
5275 sizeof(mfc_cfg.params);
5276 mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC;
5277 mfc_cfg.data.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT;
5278 mfc_cfg.data.param_size = mfc_cfg.params.payload_size -
5279 sizeof(mfc_cfg.data);
5280 mfc_cfg.data.reserved = 0;
5281 mfc_cfg.sampling_rate = sample_rate;
5282 mfc_cfg.bits_per_sample =
5283 atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]);
5284 mfc_cfg.num_channels = num_channels;
5285
5286 /* Currently applying speaker swap for only 2 channel use case */
5287 if (spk_swap) {
5288 mfc_cfg.channel_type[0] =
5289 (uint16_t) PCM_CHANNEL_FR;
5290 mfc_cfg.channel_type[1] =
5291 (uint16_t) PCM_CHANNEL_FL;
5292 } else {
5293 mfc_cfg.channel_type[0] =
5294 (uint16_t) PCM_CHANNEL_FL;
5295 mfc_cfg.channel_type[1] =
5296 (uint16_t) PCM_CHANNEL_FR;
5297 }
5298
5299 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
5300 pr_debug("%s: mfc config: port_idx %d copp_idx %d copp SR %d copp BW %d copp chan %d\n",
5301 __func__, port_idx, copp_idx, mfc_cfg.sampling_rate,
5302 mfc_cfg.bits_per_sample, mfc_cfg.num_channels);
5303
5304 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg);
5305 if (ret < 0) {
5306 pr_err("%s: port_id: for[0x%x] failed %d\n",
5307 __func__, port_id, ret);
5308 goto done;
5309 }
5310 /* Wait for the callback with copp id */
5311 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
5312 atomic_read(&this_adm.copp.stat
5313 [port_idx][copp_idx]) >= 0,
5314 msecs_to_jiffies(TIMEOUT_MS));
5315 if (!ret) {
5316 pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n",
5317 __func__, port_id);
5318 ret = -ETIMEDOUT;
5319 goto done;
5320 }
5321
5322 if (atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) > 0) {
5323 pr_err("%s: DSP returned error[%s]\n",
5324 __func__, adsp_err_get_err_str(
5325 atomic_read(&this_adm.copp.stat
5326 [port_idx][copp_idx])));
5327 ret = adsp_err_get_lnx_err_code(
5328 atomic_read(&this_adm.copp.stat
5329 [port_idx][copp_idx]));
5330 goto done;
5331 }
5332
5333 pr_debug("%s: mfc_cfg Set params returned success", __func__);
5334 ret = 0;
5335
5336done:
5337 return ret;
5338}
5339EXPORT_SYMBOL(adm_swap_speaker_channels);
5340
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305341/**
5342 * adm_set_sound_focus -
5343 * Update sound focus info
5344 *
5345 * @port_id: Port ID number
5346 * @copp_idx: copp index assigned
5347 * @soundFocusData: sound focus data to pass
5348 *
5349 * Returns 0 on success or error on failure
5350 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305351int adm_set_sound_focus(int port_id, int copp_idx,
5352 struct sound_focus_param soundFocusData)
5353{
5354 struct adm_set_fluence_soundfocus_param soundfocus_params;
5355 int sz = 0;
5356 int ret = 0;
5357 int port_idx;
5358 int i;
5359
5360 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
5361 __func__, port_id, copp_idx);
5362
5363 port_id = afe_convert_virtual_to_portid(port_id);
5364 port_idx = adm_validate_and_get_port_index(port_id);
5365 if (port_idx < 0) {
5366 pr_err("%s: Invalid port_id %#x\n", __func__, port_id);
5367
5368 ret = -EINVAL;
5369 goto done;
5370 }
5371
5372 if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
5373 pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx);
5374
5375 ret = -EINVAL;
5376 goto done;
5377 }
5378
5379 sz = sizeof(struct adm_set_fluence_soundfocus_param);
5380 soundfocus_params.params.hdr.hdr_field =
5381 APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE),
5382 APR_PKT_VER);
5383 soundfocus_params.params.hdr.pkt_size = sz;
5384 soundfocus_params.params.hdr.src_svc = APR_SVC_ADM;
5385 soundfocus_params.params.hdr.src_domain = APR_DOMAIN_APPS;
5386 soundfocus_params.params.hdr.src_port = port_id;
5387 soundfocus_params.params.hdr.dest_svc = APR_SVC_ADM;
5388 soundfocus_params.params.hdr.dest_domain = APR_DOMAIN_ADSP;
5389 soundfocus_params.params.hdr.dest_port =
5390 atomic_read(&this_adm.copp.id[port_idx][copp_idx]);
5391 soundfocus_params.params.hdr.token = port_idx << 16 |
5392 ADM_CLIENT_ID_SOURCE_TRACKING << 8 | copp_idx;
5393 soundfocus_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5;
5394 soundfocus_params.params.payload_addr_lsw = 0;
5395 soundfocus_params.params.payload_addr_msw = 0;
5396 soundfocus_params.params.mem_map_handle = 0;
5397 soundfocus_params.params.payload_size = sizeof(soundfocus_params) -
5398 sizeof(soundfocus_params.params);
5399 soundfocus_params.data.module_id = VOICEPROC_MODULE_ID_GENERIC_TX;
5400 soundfocus_params.data.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS;
5401 soundfocus_params.data.param_size =
5402 soundfocus_params.params.payload_size -
5403 sizeof(soundfocus_params.data);
5404 soundfocus_params.data.reserved = 0;
5405
5406 memset(&(soundfocus_params.soundfocus_data), 0xFF,
5407 sizeof(struct adm_param_fluence_soundfocus_t));
5408 for (i = 0; i < MAX_SECTORS; i++) {
5409 soundfocus_params.soundfocus_data.start_angles[i] =
5410 soundFocusData.start_angle[i];
5411 soundfocus_params.soundfocus_data.enables[i] =
5412 soundFocusData.enable[i];
5413 pr_debug("%s: start_angle[%d] = %d\n",
5414 __func__, i, soundFocusData.start_angle[i]);
5415 pr_debug("%s: enable[%d] = %d\n",
5416 __func__, i, soundFocusData.enable[i]);
5417 }
5418 soundfocus_params.soundfocus_data.gain_step =
5419 soundFocusData.gain_step;
5420 pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step);
5421
5422 soundfocus_params.soundfocus_data.reserved = 0;
5423
5424 atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1);
5425 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&soundfocus_params);
5426 if (ret < 0) {
5427 pr_err("%s: Set params failed\n", __func__);
5428
5429 ret = -EINVAL;
5430 goto done;
5431 }
5432 /* Wait for the callback */
5433 ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx],
5434 atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0,
5435 msecs_to_jiffies(TIMEOUT_MS));
5436 if (!ret) {
5437 pr_err("%s: Set params timed out\n", __func__);
5438
5439 ret = -EINVAL;
5440 goto done;
5441 }
5442
5443 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
5444 pr_err("%s - set params returned error [%s]\n",
5445 __func__, adsp_err_get_err_str(
5446 this_adm.sourceTrackingData.apr_cmd_status));
5447
5448 ret = adsp_err_get_lnx_err_code(
5449 this_adm.sourceTrackingData.apr_cmd_status);
5450 goto done;
5451 }
5452
5453 ret = 0;
5454
5455done:
5456 pr_debug("%s: Exit, ret=%d\n", __func__, ret);
5457
5458 return ret;
5459}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305460EXPORT_SYMBOL(adm_set_sound_focus);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305461
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305462/**
5463 * adm_get_sound_focus -
5464 * Retrieve sound focus info
5465 *
5466 * @port_id: Port ID number
5467 * @copp_idx: copp index assigned
5468 * @soundFocusData: pointer for sound focus data to be updated with
5469 *
5470 * Returns 0 on success or error on failure
5471 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305472int adm_get_sound_focus(int port_id, int copp_idx,
5473 struct sound_focus_param *soundFocusData)
5474{
5475 int ret = 0, i;
5476 char *params_value;
5477 uint32_t param_payload_len = sizeof(struct adm_param_data_v5) +
5478 sizeof(struct adm_param_fluence_soundfocus_t);
5479 struct adm_param_fluence_soundfocus_t *soundfocus_params;
5480
5481 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
5482 __func__, port_id, copp_idx);
5483
5484 params_value = kzalloc(param_payload_len, GFP_KERNEL);
5485 if (!params_value) {
5486 ret = -ENOMEM;
5487 goto done;
5488 }
5489 ret = adm_get_params_v2(port_id, copp_idx,
5490 VOICEPROC_MODULE_ID_GENERIC_TX,
5491 VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS,
5492 param_payload_len,
5493 params_value,
5494 ADM_CLIENT_ID_SOURCE_TRACKING);
5495 if (ret) {
5496 pr_err("%s: get parameters failed ret:%d\n", __func__, ret);
5497
5498 kfree(params_value);
5499 ret = -EINVAL;
5500 goto done;
5501 }
5502
5503 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
5504 pr_err("%s - get params returned error [%s]\n",
5505 __func__, adsp_err_get_err_str(
5506 this_adm.sourceTrackingData.apr_cmd_status));
5507
5508 kfree(params_value);
5509 ret = adsp_err_get_lnx_err_code(
5510 this_adm.sourceTrackingData.apr_cmd_status);
5511 goto done;
5512 }
5513
5514 soundfocus_params = (struct adm_param_fluence_soundfocus_t *)
5515 params_value;
5516 for (i = 0; i < MAX_SECTORS; i++) {
5517 soundFocusData->start_angle[i] =
5518 soundfocus_params->start_angles[i];
5519 soundFocusData->enable[i] = soundfocus_params->enables[i];
5520 pr_debug("%s: start_angle[%d] = %d\n",
5521 __func__, i, soundFocusData->start_angle[i]);
5522 pr_debug("%s: enable[%d] = %d\n",
5523 __func__, i, soundFocusData->enable[i]);
5524 }
5525 soundFocusData->gain_step = soundfocus_params->gain_step;
5526 pr_debug("%s: gain_step = %d\n", __func__, soundFocusData->gain_step);
5527
5528 kfree(params_value);
5529
5530done:
5531 pr_debug("%s: Exit, ret = %d\n", __func__, ret);
5532
5533 return ret;
5534}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305535EXPORT_SYMBOL(adm_get_sound_focus);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305536
5537static int adm_source_tracking_alloc_map_memory(void)
5538{
5539 int ret;
5540
5541 pr_debug("%s: Enter\n", __func__);
5542
5543 ret = msm_audio_ion_alloc("SOURCE_TRACKING",
5544 &this_adm.sourceTrackingData.ion_client,
5545 &this_adm.sourceTrackingData.ion_handle,
5546 AUD_PROC_BLOCK_SIZE,
5547 &this_adm.sourceTrackingData.memmap.paddr,
5548 &this_adm.sourceTrackingData.memmap.size,
5549 &this_adm.sourceTrackingData.memmap.kvaddr);
5550 if (ret) {
5551 pr_err("%s: failed to allocate memory\n", __func__);
5552
5553 ret = -EINVAL;
5554 goto done;
5555 }
5556
5557 atomic_set(&this_adm.mem_map_index, ADM_MEM_MAP_INDEX_SOURCE_TRACKING);
5558 ret = adm_memory_map_regions(&this_adm.sourceTrackingData.memmap.paddr,
5559 0,
5560 (uint32_t *)&this_adm.sourceTrackingData.memmap.size,
5561 1);
5562 if (ret < 0) {
5563 pr_err("%s: failed to map memory, paddr = 0x%pK, size = %d\n",
5564 __func__,
5565 (void *)this_adm.sourceTrackingData.memmap.paddr,
5566 (uint32_t)this_adm.sourceTrackingData.memmap.size);
5567
5568 msm_audio_ion_free(this_adm.sourceTrackingData.ion_client,
5569 this_adm.sourceTrackingData.ion_handle);
5570 this_adm.sourceTrackingData.ion_client = NULL;
5571 this_adm.sourceTrackingData.ion_handle = NULL;
5572 this_adm.sourceTrackingData.memmap.size = 0;
5573 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
5574 this_adm.sourceTrackingData.memmap.paddr = 0;
5575 this_adm.sourceTrackingData.apr_cmd_status = -1;
5576 atomic_set(&this_adm.mem_map_handles
5577 [ADM_MEM_MAP_INDEX_SOURCE_TRACKING], 0);
5578
5579 ret = -EINVAL;
5580 goto done;
5581 }
5582 ret = 0;
5583 pr_debug("%s: paddr = 0x%pK, size = %d, mem_map_handle = 0x%x\n",
5584 __func__, (void *)this_adm.sourceTrackingData.memmap.paddr,
5585 (uint32_t)this_adm.sourceTrackingData.memmap.size,
5586 atomic_read(&this_adm.mem_map_handles
5587 [ADM_MEM_MAP_INDEX_SOURCE_TRACKING]));
5588
5589done:
5590 pr_debug("%s: Exit, ret = %d\n", __func__, ret);
5591
5592 return ret;
5593}
5594
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305595/**
5596 * adm_get_source_tracking -
5597 * Retrieve source tracking info
5598 *
5599 * @port_id: Port ID number
5600 * @copp_idx: copp index assigned
5601 * @sourceTrackingData: pointer for source track data to be updated with
5602 *
5603 * Returns 0 on success or error on failure
5604 */
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305605int adm_get_source_tracking(int port_id, int copp_idx,
5606 struct source_tracking_param *sourceTrackingData)
5607{
5608 struct adm_cmd_get_pp_params_v5 admp;
5609 int p_idx, ret = 0, i;
5610 struct adm_param_fluence_sourcetracking_t *source_tracking_params;
5611
5612 pr_debug("%s: Enter, port_id %d, copp_idx %d\n",
5613 __func__, port_id, copp_idx);
5614
5615 if (!this_adm.sourceTrackingData.memmap.paddr) {
5616 /* Allocate and map shared memory for out of band usage */
5617 ret = adm_source_tracking_alloc_map_memory();
5618 if (ret != 0) {
5619 ret = -EINVAL;
5620 goto done;
5621 }
5622 }
5623
5624 port_id = afe_convert_virtual_to_portid(port_id);
5625 p_idx = adm_validate_and_get_port_index(port_id);
5626 if (p_idx < 0) {
5627 pr_err("%s - invalid port index %i, port id %i, copp idx %i\n",
5628 __func__, p_idx, port_id, copp_idx);
5629
5630 ret = -EINVAL;
5631 goto done;
5632 }
5633
5634 admp.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
5635 APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
5636 admp.hdr.pkt_size = sizeof(admp);
5637 admp.hdr.src_svc = APR_SVC_ADM;
5638 admp.hdr.src_domain = APR_DOMAIN_APPS;
5639 admp.hdr.src_port = port_id;
5640 admp.hdr.dest_svc = APR_SVC_ADM;
5641 admp.hdr.dest_domain = APR_DOMAIN_ADSP;
5642 admp.hdr.dest_port = atomic_read(&this_adm.copp.id[p_idx][copp_idx]);
5643 admp.hdr.token = p_idx << 16 | ADM_CLIENT_ID_SOURCE_TRACKING << 8 |
5644 copp_idx;
5645 admp.hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5;
5646 admp.data_payload_addr_lsw =
5647 lower_32_bits(this_adm.sourceTrackingData.memmap.paddr);
5648 admp.data_payload_addr_msw =
5649 msm_audio_populate_upper_32_bits(
5650 this_adm.sourceTrackingData.memmap.paddr);
5651 admp.mem_map_handle = atomic_read(&this_adm.mem_map_handles[
5652 ADM_MEM_MAP_INDEX_SOURCE_TRACKING]);
5653 admp.module_id = VOICEPROC_MODULE_ID_GENERIC_TX;
5654 admp.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOURCETRACKING;
5655 admp.param_max_size = sizeof(struct adm_param_fluence_sourcetracking_t)
5656 + sizeof(struct adm_param_data_v5);
5657 admp.reserved = 0;
5658
5659 atomic_set(&this_adm.copp.stat[p_idx][copp_idx], -1);
5660
5661 ret = apr_send_pkt(this_adm.apr, (uint32_t *)&admp);
5662 if (ret < 0) {
5663 pr_err("%s - failed to get Source Tracking Params\n",
5664 __func__);
5665
5666 ret = -EINVAL;
5667 goto done;
5668 }
5669 ret = wait_event_timeout(this_adm.copp.wait[p_idx][copp_idx],
5670 atomic_read(&this_adm.copp.stat[p_idx][copp_idx]) >= 0,
5671 msecs_to_jiffies(TIMEOUT_MS));
5672 if (!ret) {
5673 pr_err("%s - get params timed out\n", __func__);
5674
5675 ret = -EINVAL;
5676 goto done;
5677 } else if (atomic_read(&this_adm.copp.stat
5678 [p_idx][copp_idx]) > 0) {
5679 pr_err("%s: DSP returned error[%s]\n",
5680 __func__, adsp_err_get_err_str(
5681 atomic_read(&this_adm.copp.stat
5682 [p_idx][copp_idx])));
5683 ret = adsp_err_get_lnx_err_code(
5684 atomic_read(&this_adm.copp.stat
5685 [p_idx][copp_idx]));
5686 goto done;
5687 }
5688
5689 if (this_adm.sourceTrackingData.apr_cmd_status != 0) {
5690 pr_err("%s - get params returned error [%s]\n",
5691 __func__, adsp_err_get_err_str(
5692 this_adm.sourceTrackingData.apr_cmd_status));
5693
5694 ret = adsp_err_get_lnx_err_code(
5695 this_adm.sourceTrackingData.apr_cmd_status);
5696 goto done;
5697 }
5698
5699 source_tracking_params = (struct adm_param_fluence_sourcetracking_t *)
5700 (this_adm.sourceTrackingData.memmap.kvaddr +
5701 sizeof(struct adm_param_data_v5));
5702 for (i = 0; i < MAX_SECTORS; i++) {
5703 sourceTrackingData->vad[i] = source_tracking_params->vad[i];
5704 pr_debug("%s: vad[%d] = %d\n",
5705 __func__, i, sourceTrackingData->vad[i]);
5706 }
5707 sourceTrackingData->doa_speech = source_tracking_params->doa_speech;
5708 pr_debug("%s: doa_speech = %d\n",
5709 __func__, sourceTrackingData->doa_speech);
5710
5711 for (i = 0; i < MAX_NOISE_SOURCE_INDICATORS; i++) {
5712 sourceTrackingData->doa_noise[i] =
5713 source_tracking_params->doa_noise[i];
5714 pr_debug("%s: doa_noise[%d] = %d\n",
5715 __func__, i, sourceTrackingData->doa_noise[i]);
5716 }
5717 for (i = 0; i < MAX_POLAR_ACTIVITY_INDICATORS; i++) {
5718 sourceTrackingData->polar_activity[i] =
5719 source_tracking_params->polar_activity[i];
5720 pr_debug("%s: polar_activity[%d] = %d\n",
5721 __func__, i, sourceTrackingData->polar_activity[i]);
5722 }
5723
5724 ret = 0;
5725
5726done:
5727 pr_debug("%s: Exit, ret=%d\n", __func__, ret);
5728
5729 return ret;
5730}
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305731EXPORT_SYMBOL(adm_get_source_tracking);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305732
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305733int __init adm_init(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305734{
5735 int i = 0, j;
5736
5737 this_adm.apr = NULL;
5738 this_adm.ec_ref_rx = -1;
5739 this_adm.num_ec_ref_rx_chans = 0;
5740 this_adm.ec_ref_rx_bit_width = 0;
5741 this_adm.ec_ref_rx_sampling_rate = 0;
5742 atomic_set(&this_adm.matrix_map_stat, 0);
5743 init_waitqueue_head(&this_adm.matrix_map_wait);
5744 atomic_set(&this_adm.adm_stat, 0);
5745 init_waitqueue_head(&this_adm.adm_wait);
5746
5747 for (i = 0; i < AFE_MAX_PORTS; i++) {
5748 for (j = 0; j < MAX_COPPS_PER_PORT; j++) {
5749 atomic_set(&this_adm.copp.id[i][j], RESET_COPP_ID);
5750 atomic_set(&this_adm.copp.cnt[i][j], 0);
5751 atomic_set(&this_adm.copp.topology[i][j], 0);
5752 atomic_set(&this_adm.copp.mode[i][j], 0);
5753 atomic_set(&this_adm.copp.stat[i][j], 0);
5754 atomic_set(&this_adm.copp.rate[i][j], 0);
5755 atomic_set(&this_adm.copp.channels[i][j], 0);
5756 atomic_set(&this_adm.copp.bit_width[i][j], 0);
5757 atomic_set(&this_adm.copp.app_type[i][j], 0);
5758 atomic_set(&this_adm.copp.acdb_id[i][j], 0);
Sachin Mohan Gadag3c3c5812018-07-20 15:46:54 +05305759 atomic_set(&this_adm.copp.session_type[i][j], 0);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305760 init_waitqueue_head(&this_adm.copp.wait[i][j]);
5761 atomic_set(&this_adm.copp.adm_delay_stat[i][j], 0);
5762 init_waitqueue_head(
5763 &this_adm.copp.adm_delay_wait[i][j]);
5764 atomic_set(&this_adm.copp.topology[i][j], 0);
5765 this_adm.copp.adm_delay[i][j] = 0;
5766 this_adm.copp.adm_status[i][j] =
5767 ADM_STATUS_CALIBRATION_REQUIRED;
5768 }
5769 }
5770
5771 if (adm_init_cal_data())
5772 pr_err("%s: could not init cal data!\n", __func__);
5773
5774 this_adm.sourceTrackingData.ion_client = NULL;
5775 this_adm.sourceTrackingData.ion_handle = NULL;
5776 this_adm.sourceTrackingData.memmap.size = 0;
5777 this_adm.sourceTrackingData.memmap.kvaddr = NULL;
5778 this_adm.sourceTrackingData.memmap.paddr = 0;
5779 this_adm.sourceTrackingData.apr_cmd_status = -1;
5780 atomic_set(&this_adm.mem_map_handles[ADM_MEM_MAP_INDEX_SOURCE_TRACKING],
5781 0);
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305782 mutex_init(&dts_srs_lock);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305783
5784 return 0;
5785}
5786
Asish Bhattacharya5faacb32017-12-04 17:23:15 +05305787void adm_exit(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305788{
Laxminath Kasam468ece32017-11-28 12:40:22 +05305789 if (this_adm.apr)
5790 adm_reset_data();
Laxminath Kasam8b1366a2017-10-05 01:44:16 +05305791 mutex_destroy(&dts_srs_lock);
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05305792 adm_delete_cal_data();
5793}