blob: 514091167c9a613633fdf7a4d808c1d0e56072e0 [file] [log] [blame]
Ben Romberger55886882014-01-10 13:49:02 -08001/*
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +05302 * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
Ben Romberger55886882014-01-10 13:49:02 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Ben Romberger61764e32014-01-10 13:49:02 -080030#define LOG_TAG "platform_info"
Ben Romberger55886882014-01-10 13:49:02 -080031#define LOG_NDDEBUG 0
32
33#include <errno.h>
34#include <stdio.h>
35#include <expat.h>
36#include <cutils/log.h>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070037#include <cutils/str_parms.h>
Ben Romberger55886882014-01-10 13:49:02 -080038#include <audio_hw.h>
Vignesh Kulothungan55396882017-04-20 14:37:02 -070039#include "acdb.h"
Ben Romberger61764e32014-01-10 13:49:02 -080040#include "platform_api.h"
41#include <platform.h>
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070042#include <math.h>
Ben Romberger55886882014-01-10 13:49:02 -080043
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053044#ifdef DYNAMIC_LOG_ENABLED
45#include <log_xml_parser.h>
46#define LOG_MASK HAL_MOD_FILE_PLATFORM_INFO
47#include <log_utils.h>
48#endif
49
Ben Romberger55886882014-01-10 13:49:02 -080050#define BUF_SIZE 1024
51
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070052typedef enum {
53 ROOT,
54 ACDB,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070055 MODULE,
56 AEC,
57 NS,
Amit Shekhar5a39c912014-10-14 15:39:30 -070058 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070059 PCM_ID,
60 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080061 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070062 CONFIG_PARAMS,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070063 GAIN_LEVEL_MAPPING,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053064 ACDB_METAINFO_KEY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070065} section_t;
66
67typedef void (* section_process_fn)(const XML_Char **attr);
68
69static void process_acdb_id(const XML_Char **attr);
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070070static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type);
71static void process_effect_aec(const XML_Char **attr);
72static void process_effect_ns(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070073static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070074static void process_pcm_id(const XML_Char **attr);
75static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080076static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070077static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070078static void process_root(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070079static void process_gain_db_to_level_map(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053080static void process_acdb_metainfo_key(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070081
82static section_process_fn section_table[] = {
83 [ROOT] = process_root,
84 [ACDB] = process_acdb_id,
Vikram Pandurangadf59cae2017-08-03 18:04:55 -070085 [AEC] = process_effect_aec,
86 [NS] = process_effect_ns,
Amit Shekhar5a39c912014-10-14 15:39:30 -070087 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070088 [PCM_ID] = process_pcm_id,
89 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080090 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070091 [CONFIG_PARAMS] = process_config_params,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070092 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053093 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070094};
95
96static section_t section;
97
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070098struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -070099 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700100 void *platform;
101 struct str_parms *kvpairs;
102};
103
104static struct platform_info my_data;
105
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700106/*
107 * <audio_platform_info>
108 * <acdb_ids>
109 * <device name="???" acdb_id="???"/>
110 * ...
111 * ...
112 * </acdb_ids>
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700113 * <module_ids>
114 * <device name="???" module_id="???"/>
115 * ...
116 * ...
117 * </module_ids>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700118 * <backend_names>
119 * <device name="???" backend="???"/>
120 * ...
121 * ...
122 * </backend_names>
123 * <pcm_ids>
124 * <usecase name="???" type="in/out" id="???"/>
125 * ...
126 * ...
127 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800128 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530129 * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800130 * ...
131 * ...
132 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700133 * <config_params>
134 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
135 * ...
136 * ...
137 * </config_params>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700138 * </audio_platform_info>
139 */
140
141static void process_root(const XML_Char **attr __unused)
142{
143}
144
145/* mapping from usecase to pcm dev id */
146static void process_pcm_id(const XML_Char **attr)
147{
148 int index;
149
150 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700151 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700152 goto done;
153 }
154
155 index = platform_get_usecase_index((char *)attr[1]);
156 if (index < 0) {
157 ALOGE("%s: usecase %s not found!",
158 __func__, attr[1]);
159 goto done;
160 }
161
162 if (strcmp(attr[2], "type") != 0) {
163 ALOGE("%s: usecase type not mentioned", __func__);
164 goto done;
165 }
166
167 int type = -1;
168
169 if (!strcasecmp((char *)attr[3], "in")) {
170 type = 1;
171 } else if (!strcasecmp((char *)attr[3], "out")) {
172 type = 0;
173 } else {
174 ALOGE("%s: type must be IN or OUT", __func__);
175 goto done;
176 }
177
178 if (strcmp(attr[4], "id") != 0) {
179 ALOGE("%s: usecase id not mentioned", __func__);
180 goto done;
181 }
182
183 int id = atoi((char *)attr[5]);
184
185 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
186 ALOGE("%s: usecase %s type %d id %d was not set!",
187 __func__, attr[1], type, id);
188 goto done;
189 }
190
191done:
192 return;
193}
194
195/* backend to be used for a device */
196static void process_backend_name(const XML_Char **attr)
197{
198 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530199 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530200 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700201
202 if (strcmp(attr[0], "name") != 0) {
203 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
204 goto done;
205 }
206
207 index = platform_get_snd_device_index((char *)attr[1]);
208 if (index < 0) {
209 ALOGE("%s: Device %s not found, no ACDB ID set!",
210 __func__, attr[1]);
211 goto done;
212 }
213
214 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530215 if (strcmp(attr[2], "interface") == 0)
216 hw_interface = (char *)attr[3];
217 } else {
218 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700219 }
220
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530221 if (attr[4] != NULL) {
222 if (strcmp(attr[4], "interface") != 0) {
223 hw_interface = NULL;
224 } else {
225 hw_interface = (char *)attr[5];
226 }
227 }
228
Ashish Jaind150d4c2017-02-03 18:44:34 +0530229 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700230 ALOGE("%s: Device %s backend %s was not set!",
231 __func__, attr[1], attr[3]);
232 goto done;
233 }
234
235done:
236 return;
237}
238
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700239static void process_gain_db_to_level_map(const XML_Char **attr)
240{
241 struct amp_db_and_gain_table tbl_entry;
242
243 if ((strcmp(attr[0], "db") != 0) ||
244 (strcmp(attr[2], "level") != 0)) {
245 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
246 __func__, attr[0], attr[2]);
247 goto done;
248 }
249
250 tbl_entry.db = atof(attr[1]);
251 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
252 tbl_entry.level = atoi(attr[3]);
253
254 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
255 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
256 platform_add_gain_level_mapping(&tbl_entry);
257
258done:
259 return;
260}
261
262
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700263static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800264{
Ben Romberger61764e32014-01-10 13:49:02 -0800265 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800266
Ben Romberger61764e32014-01-10 13:49:02 -0800267 if (strcmp(attr[0], "name") != 0) {
268 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800269 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800270 }
Ben Romberger55886882014-01-10 13:49:02 -0800271
Ben Romberger61764e32014-01-10 13:49:02 -0800272 index = platform_get_snd_device_index((char *)attr[1]);
273 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800274 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
275 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800276 goto done;
277 }
278
279 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800280 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
281 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800282 goto done;
283 }
284
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700285 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
286 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800287 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800288 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800289 }
Ben Romberger55886882014-01-10 13:49:02 -0800290
Ben Romberger55886882014-01-10 13:49:02 -0800291done:
292 return;
293}
294
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700295static void process_audio_effect(const XML_Char **attr, effect_type_t effect_type)
296{
297 int index;
298 struct audio_effect_config effect_config;
299
300 if (strcmp(attr[0], "name") != 0) {
301 ALOGE("%s: 'name' not found, no MODULE ID set!", __func__);
302 goto done;
303 }
304
305 index = platform_get_snd_device_index((char *)attr[1]);
306 if (index < 0) {
307 ALOGE("%s: Device %s in platform info xml not found, no MODULE ID set!",
308 __func__, attr[1]);
309 goto done;
310 }
311
312 if (strcmp(attr[2], "module_id") != 0) {
313 ALOGE("%s: Device %s in platform info xml has no module_id, no MODULE ID set!",
314 __func__, attr[2]);
315 goto done;
316 }
317
318 if (strcmp(attr[4], "instance_id") != 0) {
319 ALOGE("%s: Device %s in platform info xml has no instance_id, no INSTANCE ID set!",
320 __func__, attr[4]);
321 goto done;
322 }
323
324 if (strcmp(attr[6], "param_id") != 0) {
325 ALOGE("%s: Device %s in platform info xml has no param_id, no PARAM ID set!",
326 __func__, attr[6]);
327 goto done;
328 }
329
330 if (strcmp(attr[8], "param_value") != 0) {
331 ALOGE("%s: Device %s in platform info xml has no param_value, no PARAM VALUE set!",
332 __func__, attr[8]);
333 goto done;
334 }
335
336 effect_config = (struct audio_effect_config){strtol((char *)attr[3], NULL, 0),
337 strtol((char *)attr[5], NULL, 0),
338 strtol((char *)attr[7], NULL, 0),
339 strtol((char *)attr[9], NULL, 0)};
340
341
342 if (platform_set_effect_config_data(index, effect_config, effect_type) < 0) {
343 ALOGE("%s: Effect = %d Device %s, MODULE/INSTANCE/PARAM ID %lu %lu %lu %lu was not set!",
344 __func__, effect_type, attr[1], strtol((char *)attr[3], NULL, 0),
345 strtol((char *)attr[5], NULL, 0), strtol((char *)attr[7], NULL, 0),
346 strtol((char *)attr[9], NULL, 0));
347 goto done;
348 }
349
350done:
351 return;
352}
353
354static void process_effect_aec(const XML_Char **attr)
355{
356 process_audio_effect(attr, EFFECT_AEC);
357 return;
358}
359
360static void process_effect_ns(const XML_Char **attr)
361{
362 process_audio_effect(attr, EFFECT_NS);
363 return;
364}
365
Amit Shekhar5a39c912014-10-14 15:39:30 -0700366static void process_bit_width(const XML_Char **attr)
367{
368 int index;
369
370 if (strcmp(attr[0], "name") != 0) {
371 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
372 goto done;
373 }
374
375 index = platform_get_snd_device_index((char *)attr[1]);
376 if (index < 0) {
377 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
378 __func__, attr[1]);
379 goto done;
380 }
381
382 if (strcmp(attr[2], "bit_width") != 0) {
383 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
384 __func__, attr[1]);
385 goto done;
386 }
387
388 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
389 ALOGE("%s: Device %s, ACDB ID %d was not set!",
390 __func__, attr[1], atoi((char *)attr[3]));
391 goto done;
392 }
393
394done:
395 return;
396}
397
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800398static void process_interface_name(const XML_Char **attr)
399{
400 int ret;
401
402 if (strcmp(attr[0], "name") != 0) {
403 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
404
405 goto done;
406 }
407
408 if (strcmp(attr[2], "interface") != 0) {
409 ALOGE("%s: Device %s has no Audio Interface set!",
410 __func__, attr[1]);
411
412 goto done;
413 }
414
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530415 if (strcmp(attr[4], "codec_type") != 0) {
416 ALOGE("%s: Device %s has no codec type set!",
417 __func__, attr[1]);
418
419 goto done;
420 }
421
422 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
423 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800424 if (ret < 0) {
425 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800426 goto done;
427 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800428
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800429done:
430 return;
431}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530432
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700433static void process_config_params(const XML_Char **attr)
434{
435 if (strcmp(attr[0], "key") != 0) {
436 ALOGE("%s: 'key' not found", __func__);
437 goto done;
438 }
439
440 if (strcmp(attr[2], "value") != 0) {
441 ALOGE("%s: 'value' not found", __func__);
442 goto done;
443 }
444
445 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
446done:
447 return;
448}
449
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530450/* process acdb meta info key value */
451static void process_acdb_metainfo_key(const XML_Char **attr)
452{
453 if (strcmp(attr[0], "name") != 0) {
454 ALOGE("%s: 'name' not found", __func__);
455 goto done;
456 }
457
458 if (strcmp(attr[2], "value") != 0) {
459 ALOGE("%s: 'value' not found", __func__);
460 goto done;
461 }
462
463 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700464 switch(my_data.caller) {
465 case ACDB_EXTN:
466 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
467 ALOGE("%s: key %d was not set!", __func__, key);
468 goto done;
469 }
470 break;
471 case PLATFORM:
472 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
473 ALOGE("%s: key %d was not set!", __func__, key);
474 goto done;
475 }
476 break;
477 default:
478 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530479 }
480
481done:
482 return;
483}
484
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700485static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -0800486 const XML_Char **attr)
487{
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700488 if (my_data.caller == ACDB_EXTN) {
489 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
490 section = ACDB_METAINFO_KEY;
491 } else if (strcmp(tag_name, "param") == 0) {
492 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
493 ALOGE("param tag only supported with CONFIG_PARAMS section");
494 return;
495 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700496
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700497 section_process_fn fn = section_table[section];
498 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700499 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700500 } else if(my_data.caller == PLATFORM) {
501 if (strcmp(tag_name, "bit_width_configs") == 0) {
502 section = BITWIDTH;
503 } else if (strcmp(tag_name, "acdb_ids") == 0) {
504 section = ACDB;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700505 } else if (strcmp(tag_name, "module_ids") == 0) {
506 section = MODULE;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700507 } else if (strcmp(tag_name, "pcm_ids") == 0) {
508 section = PCM_ID;
509 } else if (strcmp(tag_name, "backend_names") == 0) {
510 section = BACKEND_NAME;
511 } else if (strcmp(tag_name, "config_params") == 0) {
512 section = CONFIG_PARAMS;
513 } else if (strcmp(tag_name, "interface_names") == 0) {
514 section = INTERFACE_NAME;
515 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
516 section = GAIN_LEVEL_MAPPING;
517 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
518 section = ACDB_METAINFO_KEY;
519 } else if (strcmp(tag_name, "device") == 0) {
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700520 if ((section != ACDB) && (section != AEC) && (section != NS) &&
521 (section != BACKEND_NAME) && (section != BITWIDTH) &&
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700522 (section != INTERFACE_NAME)) {
523 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
524 return;
525 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700526
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700527 /* call into process function for the current section */
528 section_process_fn fn = section_table[section];
529 fn(attr);
530 } else if (strcmp(tag_name, "gain_level_map") == 0) {
531 if (section != GAIN_LEVEL_MAPPING) {
532 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
533 return;
534 }
535
536 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
537 fn(attr);
538 } else if (strcmp(tag_name, "usecase") == 0) {
539 if (section != PCM_ID) {
540 ALOGE("usecase tag only supported with PCM_ID section");
541 return;
542 }
543
544 section_process_fn fn = section_table[PCM_ID];
545 fn(attr);
546 } else if (strcmp(tag_name, "param") == 0) {
547 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
548 ALOGE("param tag only supported with CONFIG_PARAMS section");
549 return;
550 }
551
552 section_process_fn fn = section_table[section];
553 fn(attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700554 }
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700555 else if (strcmp(tag_name, "aec") == 0) {
556 if (section != MODULE) {
557 ALOGE("aec tag only supported with MODULE section");
558 return;
559 }
560 section = AEC;
561 }
562 else if (strcmp(tag_name, "ns") == 0) {
563 if (section != MODULE) {
564 ALOGE("ns tag only supported with MODULE section");
565 return;
566 }
567 section = NS;
568 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700569 } else {
570 ALOGE("%s: unknown caller!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700571 }
Ben Romberger55886882014-01-10 13:49:02 -0800572 return;
573}
574
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700575static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -0800576{
Amit Shekhar5a39c912014-10-14 15:39:30 -0700577 if (strcmp(tag_name, "bit_width_configs") == 0) {
578 section = ROOT;
579 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700580 section = ROOT;
Vikram Pandurangadf59cae2017-08-03 18:04:55 -0700581 } else if (strcmp(tag_name, "module_ids") == 0) {
582 section = ROOT;
583 } else if (strcmp(tag_name, "aec") == 0) {
584 section = MODULE;
585 } else if (strcmp(tag_name, "ns") == 0) {
586 section = MODULE;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700587 } else if (strcmp(tag_name, "pcm_ids") == 0) {
588 section = ROOT;
589 } else if (strcmp(tag_name, "backend_names") == 0) {
590 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700591 } else if (strcmp(tag_name, "config_params") == 0) {
592 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700593 if (my_data.caller == PLATFORM) {
594 platform_set_parameters(my_data.platform, my_data.kvpairs);
595 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800596 } else if (strcmp(tag_name, "interface_names") == 0) {
597 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700598 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
599 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530600 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
601 section = ROOT;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700602 }
Ben Romberger55886882014-01-10 13:49:02 -0800603}
604
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700605int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -0800606{
607 XML_Parser parser;
608 FILE *file;
609 int ret = 0;
610 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -0800611 void *buf;
612
Helen Zeng6a16ad72014-02-23 22:04:44 -0800613 file = fopen(filename, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700614 section = ROOT;
615
Ben Romberger55886882014-01-10 13:49:02 -0800616 if (!file) {
617 ALOGD("%s: Failed to open %s, using defaults.",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800618 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -0800619 ret = -ENODEV;
620 goto done;
621 }
622
623 parser = XML_ParserCreate(NULL);
624 if (!parser) {
625 ALOGE("%s: Failed to create XML parser!", __func__);
626 ret = -ENODEV;
627 goto err_close_file;
628 }
629
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700630 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700631 my_data.platform = platform;
632 my_data.kvpairs = str_parms_create();
633
Ben Romberger55886882014-01-10 13:49:02 -0800634 XML_SetElementHandler(parser, start_tag, end_tag);
635
636 while (1) {
637 buf = XML_GetBuffer(parser, BUF_SIZE);
638 if (buf == NULL) {
639 ALOGE("%s: XML_GetBuffer failed", __func__);
640 ret = -ENOMEM;
641 goto err_free_parser;
642 }
643
644 bytes_read = fread(buf, 1, BUF_SIZE, file);
645 if (bytes_read < 0) {
646 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
647 ret = bytes_read;
648 goto err_free_parser;
649 }
650
651 if (XML_ParseBuffer(parser, bytes_read,
652 bytes_read == 0) == XML_STATUS_ERROR) {
653 ALOGE("%s: XML_ParseBuffer failed, for %s",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800654 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -0800655 ret = -EINVAL;
656 goto err_free_parser;
657 }
658
659 if (bytes_read == 0)
660 break;
661 }
662
Ben Romberger55886882014-01-10 13:49:02 -0800663err_free_parser:
664 XML_ParserFree(parser);
665err_close_file:
666 fclose(file);
667done:
668 return ret;
669}