1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "audio_parse.h"
10 #include "audio_driver_log.h"
11
12 #define HDF_LOG_TAG HDF_AUDIO_KADM
13
14 #define HW_INFO "hwInfo"
15 #define PORT_INFO_LIST_LENGHT 12
16
17 enum AudioRegCfgIndex {
18 AUDIO_REG_CFG_REG_INDEX = 0,
19 AUDIO_REG_CFG_RREG_INDEX,
20 AUDIO_REG_CFG_SHIFT_INDEX,
21 AUDIO_REG_CFG_RSHIFT_INDEX,
22 AUDIO_REG_CFG_MIN_INDEX,
23 AUDIO_REG_CFG_MAX_INDEX,
24 AUDIO_REG_CFG_MASK_INDEX,
25 AUDIO_REG_CFG_INVERT_INDEX,
26 AUDIO_REG_CFG_VALUE_INDEX,
27 AUDIO_REG_CFG_INDEX_MAX
28 };
29
30 enum AudioEnumRegCfgIndex {
31 AUDIO_ENUM_REG_CFG_REG_INDEX = 0,
32 AUDIO_ENUM_REG_CFG_RREG_INDEX,
33 AUDIO_ENUM_REG_CFG_SHIFT_INDEX,
34 AUDIO_ENUM_REG_CFG_RSHIFT_INDEX,
35 AUDIO_ENUM_REG_CFG_MAX_INDEX,
36 AUDIO_ENUM_REG_CFG_MASK_INDEX,
37 AUDIO_ENUM_REG_CFG_TEXTS_INDEX,
38 AUDIO_ENUM_REG_CFG_VALUE_INDEX,
39 AUDIO_ENUM_REG_CFG_SAPM_INDEX,
40 AUDIO_ENUM_REG_CFG_INDEX_MAX
41 };
42
43 enum AudioAddrCfgIndex {
44 AUDIO_ADDR_CFG_REG_INDEX = 0,
45 AUDIO_ADDR_CFG_VALUE_INDEX,
46 AUDIO_ADDR_CFG_INDEX_MAX
47 };
48
49 enum AudioCrtlCfgIndex {
50 AUDIO_CTRL_CFG_INDEX_INDEX = 0,
51 AUDIO_CTRL_CFG_IFACE_INDEX,
52 AUDIO_CTRL_CFG_TYPE_INDEX,
53 AUDIO_CTRL_CFG_ENABLE_INDEX,
54 AUDIO_CTRL_CFG_INDEX_MAX
55 };
56
57 enum AudioSapmComponentIndex {
58 AUDIO_SAPM_COMP_INDEX_TYPE = 0,
59 AUDIO_SAPM_COMP_INDEX_NAME,
60 AUDIO_SAPM_COMP_INDEX_REG,
61 AUDIO_SAPM_COMP_INDEX_MASK,
62 AUDIO_SAPM_COMP_INDEX_SHIFT,
63 AUDIO_SAPM_COMP_INDEX_INVERT,
64 AUDIO_SAPM_COMP_INDEX_KCTL,
65 AUDIO_SAPM_COMP_INDEX_KCTLNUM,
66 AUDIO_SAPM_COMP_INDEX_MAX
67 };
68
69
70 static char *g_audioRegGroupName[AUDIO_GROUP_MAX] = {
71 "resetSeqConfig",
72 "initSeqConfig",
73 "ctrlParamsSeqConfig",
74 "ctrlParamsMuxSeqConfig",
75 "ctrlSapmParamsSeqConfig",
76 "ctrlSapmMuxParamsSeqConfig",
77 "daiStartupSeqConfig",
78 "daiParamsSeqConfig",
79 "daiTriggerSeqConfig",
80 "controlsConfig",
81 "sapmComponent",
82 "sapmConfig"
83 };
84
AudioFillConfigData(const struct HdfDeviceObject * device,struct AudioConfigData * configData)85 int32_t AudioFillConfigData(const struct HdfDeviceObject *device, struct AudioConfigData *configData)
86 {
87 const struct DeviceResourceNode *node = NULL;
88 struct DeviceResourceIface *drsOps = NULL;
89
90 ADM_LOG_DEBUG("Entry.");
91 if (device == NULL || configData == NULL) {
92 ADM_LOG_ERR("Input para check error");
93 return HDF_FAILURE;
94 }
95
96 node = device->property;
97 if (node == NULL) {
98 ADM_LOG_ERR("drs node is NULL.");
99 return HDF_FAILURE;
100 }
101 drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
102 if (drsOps == NULL || drsOps->GetString == NULL) {
103 ADM_LOG_ERR("AudioFillConfigData: invalid drs ops fail!");
104 return HDF_FAILURE;
105 }
106
107 (void)drsOps->GetString(node, "serviceName", &(configData->cardServiceName), 0);
108 (void)drsOps->GetString(node, "codecName", &(configData->codecName), 0);
109 (void)drsOps->GetString(node, "platformName", &(configData->platformName), 0);
110 (void)drsOps->GetString(node, "cpuDaiName", &(configData->cpuDaiName), 0);
111 (void)drsOps->GetString(node, "codecDaiName", &(configData->codecDaiName), 0);
112 (void)drsOps->GetString(node, "dspName", &(configData->dspName), 0);
113 (void)drsOps->GetString(node, "dspDaiName", &(configData->dspDaiName), 0);
114
115 ADM_LOG_INFO("cardServiceName = %s", configData->cardServiceName);
116 ADM_LOG_INFO("codecName = %s, codecDaiName = %s", configData->codecName, configData->codecDaiName);
117 ADM_LOG_INFO("platformName = %s, cpuDaiNamei = %s", configData->platformName, configData->cpuDaiName);
118 ADM_LOG_INFO("dspName = %s, dspDaiName = %s", configData->dspName, configData->dspDaiName);
119
120 return HDF_SUCCESS;
121 }
122
GetAudioRegGroupNameIndex(const char * name)123 static uint32_t GetAudioRegGroupNameIndex(const char *name)
124 {
125 uint32_t index;
126
127 if (name == NULL) {
128 return AUDIO_GROUP_MAX;
129 }
130
131 for (index = 0; index < AUDIO_GROUP_MAX; ++index) {
132 if ((g_audioRegGroupName[index] != NULL) && (strcmp(name, g_audioRegGroupName[index]) == 0)) {
133 break;
134 }
135 }
136
137 return index;
138 }
139
GetRegArray(const struct DeviceResourceIface * parser,const struct DeviceResourceNode * regNode,struct AudioRegCfgGroupNode * group,uint32_t indexMax)140 static uint32_t* GetRegArray(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
141 struct AudioRegCfgGroupNode* group, uint32_t indexMax)
142 {
143 int32_t ret;
144 int32_t index;
145 int32_t num;
146 uint32_t *buf = NULL;
147 if (group == NULL || parser == NULL || regNode == NULL || indexMax == 0) {
148 ADM_LOG_ERR("Input para check error");
149 return NULL;
150 }
151
152 index = group->groupIndex;
153 if (index >= AUDIO_GROUP_MAX) {
154 ADM_LOG_ERR("Input indexMax=%d error", index);
155 return NULL;
156 }
157
158 num = parser->GetElemNum(regNode, g_audioRegGroupName[index]);
159 if (num <= 0 || num > AUDIO_CONFIG_MAX_ITEM) {
160 ADM_LOG_ERR("parser %s element num failed", g_audioRegGroupName[index]);
161 return NULL;
162 }
163
164 group->itemNum = num / indexMax;
165
166 buf = (uint32_t *)OsalMemCalloc(sizeof(uint32_t) * num);
167 if (buf == NULL) {
168 ADM_LOG_ERR("malloc reg array buf failed!");
169 return NULL;
170 }
171
172 ret = parser->GetUint32Array(regNode, g_audioRegGroupName[index], buf, num, 0);
173 if (ret != HDF_SUCCESS) {
174 ADM_LOG_ERR("parser %s reg array failed", g_audioRegGroupName[index]);
175 OsalMemFree(buf);
176 return NULL;
177 }
178 return buf;
179 }
180
ParseAudioRegItem(const struct DeviceResourceIface * parser,const struct DeviceResourceNode * regNode,struct AudioRegCfgGroupNode * group)181 static int32_t ParseAudioRegItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
182 struct AudioRegCfgGroupNode* group)
183 {
184 int32_t step;
185 int32_t index;
186 int32_t *buf = NULL;
187 if (group == NULL || parser == NULL || regNode == NULL) {
188 ADM_LOG_ERR("Input para check error");
189 return HDF_FAILURE;
190 }
191
192 buf = GetRegArray(parser, regNode, group, AUDIO_REG_CFG_INDEX_MAX);
193 if (buf == NULL) {
194 ADM_LOG_ERR("malloc reg array buf failed!");
195 return HDF_FAILURE;
196 }
197
198 group->regCfgItem =
199 (struct AudioMixerControl*)OsalMemCalloc(group->itemNum * sizeof(*(group->regCfgItem)));
200 if (group->regCfgItem == NULL) {
201 OsalMemFree(buf);
202 ADM_LOG_ERR("malloc audio reg config item failed!");
203 return HDF_ERR_MALLOC_FAIL;
204 }
205
206 for (index = 0; index < group->itemNum; ++index) {
207 step = AUDIO_REG_CFG_INDEX_MAX * index;
208
209 group->regCfgItem[index].reg = buf[step + AUDIO_REG_CFG_REG_INDEX];
210 group->regCfgItem[index].rreg = buf[step + AUDIO_REG_CFG_RREG_INDEX];
211 group->regCfgItem[index].shift = buf[step + AUDIO_REG_CFG_SHIFT_INDEX];
212 group->regCfgItem[index].rshift = buf[step + AUDIO_REG_CFG_RSHIFT_INDEX];
213 group->regCfgItem[index].min = buf[step + AUDIO_REG_CFG_MIN_INDEX];
214 group->regCfgItem[index].max = buf[step + AUDIO_REG_CFG_MAX_INDEX];
215 group->regCfgItem[index].mask = buf[step + AUDIO_REG_CFG_MASK_INDEX];
216 group->regCfgItem[index].invert = buf[step + AUDIO_REG_CFG_INVERT_INDEX];
217 group->regCfgItem[index].value = buf[step + AUDIO_REG_CFG_VALUE_INDEX];
218 }
219 OsalMemFree(buf);
220
221 return HDF_SUCCESS;
222 }
223
ParseAudioEnumRegItem(const struct DeviceResourceIface * parser,const struct DeviceResourceNode * regNode,struct AudioRegCfgGroupNode * group)224 static int32_t ParseAudioEnumRegItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
225 struct AudioRegCfgGroupNode* group)
226 {
227 int32_t step;
228 int32_t index;
229 int32_t *buf = NULL;
230
231 if (group == NULL || parser == NULL || regNode == NULL) {
232 ADM_LOG_ERR("Input para check error");
233 return HDF_FAILURE;
234 }
235
236 buf = GetRegArray(parser, regNode, group, AUDIO_ENUM_REG_CFG_INDEX_MAX);
237 if (buf == NULL) {
238 ADM_LOG_ERR("malloc reg array buf failed!");
239 return HDF_FAILURE;
240 }
241
242 group->regEnumCfgItem =
243 (struct AudioEnumCtrlConfig*)OsalMemCalloc(group->itemNum * sizeof(*(group->regEnumCfgItem)));
244 if (group->regEnumCfgItem == NULL) {
245 OsalMemFree(buf);
246 ADM_LOG_ERR("malloc audio Enum reg config item is failed!");
247 return HDF_ERR_MALLOC_FAIL;
248 }
249
250 for (index = 0; index < group->itemNum; ++index) {
251 step = AUDIO_ENUM_REG_CFG_INDEX_MAX * index;
252
253 group->regEnumCfgItem[index].reg = buf[step + AUDIO_ENUM_REG_CFG_REG_INDEX];
254 group->regEnumCfgItem[index].reg2 = buf[step + AUDIO_ENUM_REG_CFG_RREG_INDEX];
255 group->regEnumCfgItem[index].shiftLeft = buf[step + AUDIO_ENUM_REG_CFG_SHIFT_INDEX];
256 group->regEnumCfgItem[index].shiftRight = buf[step + AUDIO_ENUM_REG_CFG_RSHIFT_INDEX];
257 group->regEnumCfgItem[index].max = buf[step + AUDIO_ENUM_REG_CFG_MAX_INDEX];
258 group->regEnumCfgItem[index].mask = buf[step + AUDIO_ENUM_REG_CFG_MASK_INDEX];
259 group->regEnumCfgItem[index].texts = buf[step + AUDIO_ENUM_REG_CFG_TEXTS_INDEX];
260 group->regEnumCfgItem[index].values = buf[step + AUDIO_ENUM_REG_CFG_VALUE_INDEX];
261 group->regEnumCfgItem[index].sapm = buf[step + AUDIO_ENUM_REG_CFG_SAPM_INDEX];
262 }
263 OsalMemFree(buf);
264
265 return HDF_SUCCESS;
266 }
267
ParseAudioSapmItem(const struct DeviceResourceIface * parser,const struct DeviceResourceNode * regNode,struct AudioRegCfgGroupNode * group)268 static int32_t ParseAudioSapmItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
269 struct AudioRegCfgGroupNode* group)
270 {
271 int32_t step;
272 int32_t index;
273 uint32_t *buf = NULL;
274 if (group == NULL || parser == NULL || regNode == NULL) {
275 ADM_LOG_ERR("Input para check error");
276 return HDF_FAILURE;
277 }
278
279 buf = GetRegArray(parser, regNode, group, AUDIO_SAPM_COMP_INDEX_MAX);
280 if (buf == NULL) {
281 ADM_LOG_ERR("malloc reg array buf failed!");
282 return HDF_FAILURE;
283 }
284
285 group->sapmCompItem =
286 (struct AudioSapmCtrlConfig*)OsalMemCalloc(group->itemNum * sizeof(*(group->sapmCompItem)));
287 if (group->sapmCompItem == NULL) {
288 OsalMemFree(buf);
289 ADM_LOG_ERR("malloc audio reg config item failed!");
290 return HDF_ERR_MALLOC_FAIL;
291 }
292
293 for (index = 0; index < group->itemNum; ++index) {
294 step = AUDIO_SAPM_COMP_INDEX_MAX * index;
295 group->sapmCompItem[index].sapmType = buf[step + AUDIO_SAPM_COMP_INDEX_TYPE];
296 group->sapmCompItem[index].compNameIndex = buf[step + AUDIO_SAPM_COMP_INDEX_NAME];
297 group->sapmCompItem[index].reg = buf[step + AUDIO_SAPM_COMP_INDEX_REG];
298 group->sapmCompItem[index].mask = buf[step + AUDIO_SAPM_COMP_INDEX_MASK];
299 group->sapmCompItem[index].shift = buf[step + AUDIO_SAPM_COMP_INDEX_SHIFT];
300 group->sapmCompItem[index].invert = buf[step + AUDIO_SAPM_COMP_INDEX_INVERT];
301 group->sapmCompItem[index].kcontrolNews = buf[step + AUDIO_SAPM_COMP_INDEX_KCTL];
302 group->sapmCompItem[index].kcontrolsNum = buf[step + AUDIO_SAPM_COMP_INDEX_KCTLNUM];
303 }
304
305 OsalMemFree(buf);
306 return HDF_SUCCESS;
307 }
308
309
ParseAudioCtrlItem(const struct DeviceResourceIface * parser,const struct DeviceResourceNode * regNode,struct AudioRegCfgGroupNode * group)310 static int32_t ParseAudioCtrlItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
311 struct AudioRegCfgGroupNode* group)
312 {
313 int32_t step;
314 int32_t index;
315 uint32_t *buf = NULL;
316 if (parser == NULL || regNode == NULL || group == NULL) {
317 ADM_LOG_ERR("Input para check error");
318 return HDF_FAILURE;
319 }
320
321 buf = GetRegArray(parser, regNode, group, AUDIO_CTRL_CFG_INDEX_MAX);
322 if (buf == NULL) {
323 ADM_LOG_ERR("malloc reg array buf failed!");
324 return HDF_FAILURE;
325 }
326
327 group->ctrlCfgItem =
328 (struct AudioControlConfig*)OsalMemCalloc(group->itemNum * sizeof(*(group->ctrlCfgItem)));
329 if (group->ctrlCfgItem == NULL) {
330 OsalMemFree(buf);
331 ADM_LOG_ERR("malloc audio ctrl config item failed!");
332 return HDF_ERR_MALLOC_FAIL;
333 }
334
335 for (index = 0; index < group->itemNum; ++index) {
336 step = AUDIO_CTRL_CFG_INDEX_MAX * index;
337
338 group->ctrlCfgItem[index].arrayIndex = buf[step + AUDIO_CTRL_CFG_INDEX_INDEX];
339 group->ctrlCfgItem[index].iface = buf[step + AUDIO_CTRL_CFG_IFACE_INDEX];
340 group->ctrlCfgItem[index].type = buf[step + AUDIO_CTRL_CFG_TYPE_INDEX];
341 group->ctrlCfgItem[index].enable = buf[step + AUDIO_CTRL_CFG_ENABLE_INDEX];
342 }
343 OsalMemFree(buf);
344 return HDF_SUCCESS;
345 }
346
ParseAudioAddrItem(const struct DeviceResourceIface * parser,const struct DeviceResourceNode * regNode,struct AudioRegCfgGroupNode * group)347 static int32_t ParseAudioAddrItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
348 struct AudioRegCfgGroupNode* group)
349 {
350 int32_t step;
351 int32_t index;
352 uint32_t *buf = NULL;
353
354 if (parser == NULL || regNode == NULL || group == NULL) {
355 ADM_LOG_ERR("Input para check error.");
356 return HDF_FAILURE;
357 }
358
359 buf = GetRegArray(parser, regNode, group, AUDIO_ADDR_CFG_INDEX_MAX);
360 if (buf == NULL) {
361 ADM_LOG_ERR("malloc reg array buf failed!");
362 return HDF_FAILURE;
363 }
364
365 group->addrCfgItem = (struct AudioAddrConfig*)OsalMemCalloc(group->itemNum * sizeof(*(group->addrCfgItem)));
366 if (group->addrCfgItem == NULL) {
367 OsalMemFree(buf);
368 ADM_LOG_ERR("malloc audio addr config item failed!");
369 return HDF_ERR_MALLOC_FAIL;
370 }
371
372 for (index = 0; index < group->itemNum; ++index) {
373 step = AUDIO_ADDR_CFG_INDEX_MAX * index;
374 group->addrCfgItem[index].addr = buf[step + AUDIO_ADDR_CFG_REG_INDEX];
375 group->addrCfgItem[index].value = buf[step + AUDIO_ADDR_CFG_VALUE_INDEX];
376 }
377 OsalMemFree(buf);
378 return HDF_SUCCESS;
379 }
380
ParseAudioRegGroup(const struct DeviceResourceIface * parser,const struct DeviceResourceNode * regCfgNode,struct AudioRegCfgGroupNode ** groupNode,uint32_t index)381 static int32_t ParseAudioRegGroup(const struct DeviceResourceIface *parser,
382 const struct DeviceResourceNode *regCfgNode, struct AudioRegCfgGroupNode **groupNode, uint32_t index)
383 {
384 int32_t ret = HDF_FAILURE;
385 struct AudioRegCfgGroupNode *group = NULL;
386
387 if (parser == NULL || regCfgNode == NULL || groupNode == NULL) {
388 ADM_LOG_ERR("Input para check error");
389 return HDF_FAILURE;
390 }
391
392 group = (struct AudioRegCfgGroupNode*)OsalMemCalloc(sizeof(*group));
393 if (group == NULL) {
394 ADM_LOG_ERR("malloc audio reg config group failed");
395 return HDF_ERR_MALLOC_FAIL;
396 }
397 *groupNode = group;
398 (*groupNode)->groupIndex = index;
399
400 switch (index) {
401 case AUDIO_CTRL_CFG_GROUP:
402 case AUDIO_SAPM_CFG_GROUP:
403 ret = ParseAudioCtrlItem(parser, regCfgNode, group);
404 break;
405 case AUDIO_RSET_GROUP:
406 case AUDIO_INIT_GROUP:
407 ret = ParseAudioAddrItem(parser, regCfgNode, group);
408 break;
409 case AUDIO_DAI_PATAM_GROUP:
410 case AUDIO_DAI_TRIGGER_GROUP:
411 case AUDIO_CTRL_PATAM_GROUP:
412 case AUDIO_CTRL_SAPM_PATAM_GROUP:
413 case AUDIO_DAI_STARTUP_PATAM_GROUP:
414 ret = ParseAudioRegItem(parser, regCfgNode, group);
415 break;
416 case AUDIO_CTRL_PATAM_MUX_GROUP:
417 case AUDIO_CTRL_SAPM_PATAM_MUX_GROUP:
418 ret = ParseAudioEnumRegItem(parser, regCfgNode, group);
419 break;
420 case AUDIO_SAPM_COMP_GROUP:
421 ret = ParseAudioSapmItem(parser, regCfgNode, group);
422 break;
423 default:
424 ADM_LOG_ERR("parse audio config index = %u not found!", index);
425 return HDF_FAILURE;
426 }
427
428 if (ret != HDF_SUCCESS) {
429 ADM_LOG_ERR("parse audio config item failed!");
430 return HDF_FAILURE;
431 }
432 return HDF_SUCCESS;
433 }
434
ReleaseAudioAllRegConfig(struct AudioRegCfgData * config)435 static void ReleaseAudioAllRegConfig(struct AudioRegCfgData *config)
436 {
437 int32_t index;
438
439 if (config == NULL) {
440 return;
441 }
442
443 for (index = 0; index < AUDIO_GROUP_MAX; ++index) {
444 if (config->audioRegParams[index] != NULL) {
445 if (config->audioRegParams[index]->regCfgItem != NULL) {
446 OsalMemFree(config->audioRegParams[index]->regCfgItem);
447 config->audioRegParams[index]->regCfgItem = NULL;
448 }
449 OsalMemFree(config->audioRegParams[index]);
450 config->audioRegParams[index] = NULL;
451 }
452 }
453 }
454
ParseAudioAttr(const struct DeviceResourceIface * parser,const struct DeviceResourceNode * attrNode,struct AudioIdInfo * config)455 static int32_t ParseAudioAttr(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *attrNode,
456 struct AudioIdInfo *config)
457 {
458 int32_t ret;
459 ret = parser->GetString(attrNode, "chipName", &config->chipName, NULL);
460 if (ret != HDF_SUCCESS) {
461 ADM_LOG_ERR("parser chipName reg audioIdInfo failed!");
462 return HDF_SUCCESS;
463 }
464
465 ret = parser->GetUint32(attrNode, "chipIdRegister", &config->chipIdRegister, 0);
466 if (ret != HDF_SUCCESS) {
467 ADM_LOG_ERR("parser chipIdRegister reg audioIdInfo failed!");
468 return HDF_SUCCESS;
469 }
470
471 ret = parser->GetUint32(attrNode, "chipIdSize", &config->chipIdSize, 0);
472 if (ret != HDF_SUCCESS) {
473 ADM_LOG_ERR("parser chipIdSize reg audioIdInfo failed!");
474 return HDF_SUCCESS;
475 }
476 return ret;
477 }
478
AudioSetPortInfoConfig(const uint64_t * buf,struct AudioPcmStream * info)479 static int32_t AudioSetPortInfoConfig(const uint64_t *buf, struct AudioPcmStream *info)
480 {
481 int32_t ret;
482
483 ret = memcpy_s(info, sizeof(struct AudioPcmStream), buf, sizeof(uint64_t) * PORT_INFO_LIST_LENGHT);
484 if (ret != 0) {
485 ADM_LOG_ERR("memcpy_s error ret = %d!", ret);
486 return HDF_FAILURE;
487 }
488
489 return HDF_SUCCESS;
490 }
491
AudioSetPortInfoConfigStub(const uint64_t * buf,struct AudioPortInfo * configData)492 static int32_t AudioSetPortInfoConfigStub(const uint64_t *buf, struct AudioPortInfo *configData)
493 {
494 switch (buf[0]) { /* Playback/Captrue */
495 case PORT_OUT: /* Playback */
496 return AudioSetPortInfoConfig(buf, &configData->render);
497 case PORT_IN: /* Captrue */
498 return AudioSetPortInfoConfig(buf, &configData->capture);
499 default:
500 ADM_LOG_ERR("portDirection = %llu element num failed", buf[0]);
501 return HDF_FAILURE;
502 }
503 }
504
AudioGetPortInfoConfig(struct DeviceResourceIface * drsOps,const struct HdfDeviceObject * device,struct AudioPortInfo * configData)505 static int32_t AudioGetPortInfoConfig(struct DeviceResourceIface *drsOps, const struct HdfDeviceObject *device,
506 struct AudioPortInfo *configData)
507 {
508 uint32_t num;
509 uint32_t ret;
510 uint64_t *buf = NULL;
511
512 num = drsOps->GetElemNum(device->property, HW_INFO);
513 if (num == 0 || num > AUDIO_CONFIG_MAX_ITEM) {
514 ADM_LOG_ERR("parser %s element num failed", HW_INFO);
515 return HDF_FAILURE;
516 }
517
518 buf = (uint64_t *)OsalMemCalloc(sizeof(uint64_t) * num);
519 if (buf == NULL) {
520 ADM_LOG_ERR("malloc reg array buf failed!");
521 return HDF_FAILURE;
522 }
523
524 ret = drsOps->GetUint64Array(device->property, HW_INFO, buf, num, 0);
525 if (ret != HDF_SUCCESS) {
526 OsalMemFree(buf);
527 ADM_LOG_ERR("GetChildNode: Read portCfgNode fail!");
528 return HDF_FAILURE;
529 }
530
531 (void)memset_s(configData, sizeof(struct AudioPortInfo), 0, sizeof(struct AudioPortInfo));
532
533 switch (num) {
534 case PORT_INFO_LIST_LENGHT:
535 AudioSetPortInfoConfigStub(buf, configData);
536 break;
537 case PORT_INFO_LIST_LENGHT + PORT_INFO_LIST_LENGHT:
538 AudioSetPortInfoConfigStub(buf, configData);
539 AudioSetPortInfoConfigStub(buf + PORT_INFO_LIST_LENGHT, configData);
540 break;
541 default:
542 OsalMemFree(buf);
543 ADM_LOG_ERR("configData->portDirection num is not matched! num = %d", num);
544 return HDF_FAILURE;
545 }
546
547 OsalMemFree(buf);
548 return HDF_SUCCESS;
549 }
550
AudioGetPortConfig(const struct HdfDeviceObject * device,struct AudioPortInfo * configData)551 int32_t AudioGetPortConfig(const struct HdfDeviceObject *device, struct AudioPortInfo *configData)
552 {
553 uint32_t ret;
554 struct DeviceResourceIface *drsOps = NULL;
555
556 if (device == NULL || device->property == NULL || configData == NULL) {
557 ADM_LOG_ERR("Input para check error");
558 return HDF_FAILURE;
559 }
560
561 drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
562 if (drsOps == NULL || drsOps->GetString == NULL) {
563 ADM_LOG_ERR("AudioGetPortConfig: invalid drs ops fail!");
564 return HDF_FAILURE;
565 }
566
567 ret = AudioGetPortInfoConfig(drsOps, device, configData);
568 if (ret != HDF_SUCCESS) {
569 ADM_LOG_ERR("parser chipIdRegister reg audioIdInfo failed!");
570 return HDF_FAILURE;
571 }
572 return HDF_SUCCESS;
573 }
574
AudioGetRegConfig(const struct HdfDeviceObject * device,struct AudioRegCfgData * configData)575 int32_t AudioGetRegConfig(const struct HdfDeviceObject *device, struct AudioRegCfgData *configData)
576 {
577 uint16_t index;
578 const struct DeviceResourceNode *regCfgNode = NULL;
579 const struct DeviceResourceAttr *regAttr = NULL;
580 const struct DeviceResourceNode *idNode = NULL;
581 struct DeviceResourceIface *drsOps = NULL;
582
583 if (device == NULL || device->property == NULL || configData == NULL) {
584 ADM_LOG_ERR("Input para check error");
585 return HDF_FAILURE;
586 }
587
588 drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
589 if (drsOps == NULL || drsOps->GetString == NULL) {
590 ADM_LOG_ERR("AudioFillConfigData: invalid drs ops fail!");
591 return HDF_FAILURE;
592 }
593
594 idNode = drsOps->GetChildNode(device->property, "idInfo");
595 if (idNode != NULL) {
596 if (ParseAudioAttr(drsOps, idNode, &configData->audioIdInfo) != HDF_SUCCESS) {
597 ADM_LOG_ERR("audio reg node attr is null");
598 return HDF_FAILURE;
599 }
600 }
601
602 regCfgNode = drsOps->GetChildNode(device->property, "regConfig");
603 if (regCfgNode == NULL) {
604 ADM_LOG_ERR("AudioGetRegConfig: Read audioRegConfig fail!");
605 return HDF_FAILURE;
606 }
607
608 DEV_RES_NODE_FOR_EACH_ATTR(regCfgNode, regAttr) {
609 if (regAttr == NULL || regAttr->name == NULL) {
610 ADM_LOG_ERR("audio reg node attr is null");
611 return HDF_FAILURE;
612 }
613
614 index = GetAudioRegGroupNameIndex(regAttr->name);
615 if (index >= AUDIO_GROUP_MAX) {
616 continue;
617 }
618
619 if (ParseAudioRegGroup(drsOps, regCfgNode, &configData->audioRegParams[index], index) != HDF_SUCCESS) {
620 ADM_LOG_ERR("parse audio register group failed");
621 ReleaseAudioAllRegConfig(configData);
622 return HDF_FAILURE;
623 }
624 }
625 return HDF_SUCCESS;
626 }
627