blob: 597d1f768668435f1746b243aa21a189fe42b50c [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,
Amit Shekhar5a39c912014-10-14 15:39:30 -070055 BITWIDTH,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070056 PCM_ID,
57 BACKEND_NAME,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080058 INTERFACE_NAME,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070059 CONFIG_PARAMS,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070060 GAIN_LEVEL_MAPPING,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053061 ACDB_METAINFO_KEY,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070062} section_t;
63
64typedef void (* section_process_fn)(const XML_Char **attr);
65
66static void process_acdb_id(const XML_Char **attr);
Amit Shekhar5a39c912014-10-14 15:39:30 -070067static void process_bit_width(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070068static void process_pcm_id(const XML_Char **attr);
69static void process_backend_name(const XML_Char **attr);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080070static void process_interface_name(const XML_Char **attr);
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070071static void process_config_params(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070072static void process_root(const XML_Char **attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070073static void process_gain_db_to_level_map(const XML_Char **attr);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053074static void process_acdb_metainfo_key(const XML_Char **attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070075
76static section_process_fn section_table[] = {
77 [ROOT] = process_root,
78 [ACDB] = process_acdb_id,
Amit Shekhar5a39c912014-10-14 15:39:30 -070079 [BITWIDTH] = process_bit_width,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070080 [PCM_ID] = process_pcm_id,
81 [BACKEND_NAME] = process_backend_name,
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -080082 [INTERFACE_NAME] = process_interface_name,
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070083 [CONFIG_PARAMS] = process_config_params,
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -070084 [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +053085 [ACDB_METAINFO_KEY] = process_acdb_metainfo_key,
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070086};
87
88static section_t section;
89
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070090struct platform_info {
Vignesh Kulothungan55396882017-04-20 14:37:02 -070091 caller_t caller;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -070092 void *platform;
93 struct str_parms *kvpairs;
94};
95
96static struct platform_info my_data;
97
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -070098/*
99 * <audio_platform_info>
100 * <acdb_ids>
101 * <device name="???" acdb_id="???"/>
102 * ...
103 * ...
104 * </acdb_ids>
105 * <backend_names>
106 * <device name="???" backend="???"/>
107 * ...
108 * ...
109 * </backend_names>
110 * <pcm_ids>
111 * <usecase name="???" type="in/out" id="???"/>
112 * ...
113 * ...
114 * </pcm_ids>
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800115 * <interface_names>
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530116 * <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 -0800117 * ...
118 * ...
119 * </interface_names>
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700120 * <config_params>
121 * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
122 * ...
123 * ...
124 * </config_params>
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700125 * </audio_platform_info>
126 */
127
128static void process_root(const XML_Char **attr __unused)
129{
130}
131
132/* mapping from usecase to pcm dev id */
133static void process_pcm_id(const XML_Char **attr)
134{
135 int index;
136
137 if (strcmp(attr[0], "name") != 0) {
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700138 ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700139 goto done;
140 }
141
142 index = platform_get_usecase_index((char *)attr[1]);
143 if (index < 0) {
144 ALOGE("%s: usecase %s not found!",
145 __func__, attr[1]);
146 goto done;
147 }
148
149 if (strcmp(attr[2], "type") != 0) {
150 ALOGE("%s: usecase type not mentioned", __func__);
151 goto done;
152 }
153
154 int type = -1;
155
156 if (!strcasecmp((char *)attr[3], "in")) {
157 type = 1;
158 } else if (!strcasecmp((char *)attr[3], "out")) {
159 type = 0;
160 } else {
161 ALOGE("%s: type must be IN or OUT", __func__);
162 goto done;
163 }
164
165 if (strcmp(attr[4], "id") != 0) {
166 ALOGE("%s: usecase id not mentioned", __func__);
167 goto done;
168 }
169
170 int id = atoi((char *)attr[5]);
171
172 if (platform_set_usecase_pcm_id(index, type, id) < 0) {
173 ALOGE("%s: usecase %s type %d id %d was not set!",
174 __func__, attr[1], type, id);
175 goto done;
176 }
177
178done:
179 return;
180}
181
182/* backend to be used for a device */
183static void process_backend_name(const XML_Char **attr)
184{
185 int index;
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530186 char *hw_interface = NULL;
Ashish Jaind150d4c2017-02-03 18:44:34 +0530187 char *backend = NULL;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700188
189 if (strcmp(attr[0], "name") != 0) {
190 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
191 goto done;
192 }
193
194 index = platform_get_snd_device_index((char *)attr[1]);
195 if (index < 0) {
196 ALOGE("%s: Device %s not found, no ACDB ID set!",
197 __func__, attr[1]);
198 goto done;
199 }
200
201 if (strcmp(attr[2], "backend") != 0) {
Ashish Jaind150d4c2017-02-03 18:44:34 +0530202 if (strcmp(attr[2], "interface") == 0)
203 hw_interface = (char *)attr[3];
204 } else {
205 backend = (char *)attr[3];
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700206 }
207
Sidipotu Ashok9f0b16e2016-04-28 13:48:28 +0530208 if (attr[4] != NULL) {
209 if (strcmp(attr[4], "interface") != 0) {
210 hw_interface = NULL;
211 } else {
212 hw_interface = (char *)attr[5];
213 }
214 }
215
Ashish Jaind150d4c2017-02-03 18:44:34 +0530216 if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700217 ALOGE("%s: Device %s backend %s was not set!",
218 __func__, attr[1], attr[3]);
219 goto done;
220 }
221
222done:
223 return;
224}
225
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700226static void process_gain_db_to_level_map(const XML_Char **attr)
227{
228 struct amp_db_and_gain_table tbl_entry;
229
230 if ((strcmp(attr[0], "db") != 0) ||
231 (strcmp(attr[2], "level") != 0)) {
232 ALOGE("%s: invalid attribute passed %s %sexpected amp db level",
233 __func__, attr[0], attr[2]);
234 goto done;
235 }
236
237 tbl_entry.db = atof(attr[1]);
238 tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
239 tbl_entry.level = atoi(attr[3]);
240
241 ALOGV("%s: amp [%f] db [%f] level [%d]", __func__,
242 tbl_entry.amp, tbl_entry.db, tbl_entry.level);
243 platform_add_gain_level_mapping(&tbl_entry);
244
245done:
246 return;
247}
248
249
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700250static void process_acdb_id(const XML_Char **attr)
Ben Romberger55886882014-01-10 13:49:02 -0800251{
Ben Romberger61764e32014-01-10 13:49:02 -0800252 int index;
Ben Romberger55886882014-01-10 13:49:02 -0800253
Ben Romberger61764e32014-01-10 13:49:02 -0800254 if (strcmp(attr[0], "name") != 0) {
255 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
Ben Romberger55886882014-01-10 13:49:02 -0800256 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800257 }
Ben Romberger55886882014-01-10 13:49:02 -0800258
Ben Romberger61764e32014-01-10 13:49:02 -0800259 index = platform_get_snd_device_index((char *)attr[1]);
260 if (index < 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800261 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
262 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800263 goto done;
264 }
265
266 if (strcmp(attr[2], "acdb_id") != 0) {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800267 ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!",
268 __func__, attr[1]);
Ben Romberger55886882014-01-10 13:49:02 -0800269 goto done;
270 }
271
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700272 if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
273 ALOGE("%s: Device %s, ACDB ID %d was not set!",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800274 __func__, attr[1], atoi((char *)attr[3]));
Ben Romberger55886882014-01-10 13:49:02 -0800275 goto done;
Ben Romberger61764e32014-01-10 13:49:02 -0800276 }
Ben Romberger55886882014-01-10 13:49:02 -0800277
Ben Romberger55886882014-01-10 13:49:02 -0800278done:
279 return;
280}
281
Amit Shekhar5a39c912014-10-14 15:39:30 -0700282static void process_bit_width(const XML_Char **attr)
283{
284 int index;
285
286 if (strcmp(attr[0], "name") != 0) {
287 ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
288 goto done;
289 }
290
291 index = platform_get_snd_device_index((char *)attr[1]);
292 if (index < 0) {
293 ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!",
294 __func__, attr[1]);
295 goto done;
296 }
297
298 if (strcmp(attr[2], "bit_width") != 0) {
299 ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!",
300 __func__, attr[1]);
301 goto done;
302 }
303
304 if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) {
305 ALOGE("%s: Device %s, ACDB ID %d was not set!",
306 __func__, attr[1], atoi((char *)attr[3]));
307 goto done;
308 }
309
310done:
311 return;
312}
313
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800314static void process_interface_name(const XML_Char **attr)
315{
316 int ret;
317
318 if (strcmp(attr[0], "name") != 0) {
319 ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
320
321 goto done;
322 }
323
324 if (strcmp(attr[2], "interface") != 0) {
325 ALOGE("%s: Device %s has no Audio Interface set!",
326 __func__, attr[1]);
327
328 goto done;
329 }
330
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530331 if (strcmp(attr[4], "codec_type") != 0) {
332 ALOGE("%s: Device %s has no codec type set!",
333 __func__, attr[1]);
334
335 goto done;
336 }
337
338 ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3],
339 (char *)attr[5]);
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800340 if (ret < 0) {
341 ALOGE("%s: Audio Interface not set!", __func__);
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800342 goto done;
343 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800344
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -0800345done:
346 return;
347}
Laxminath Kasam44f49402015-05-29 18:37:11 +0530348
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700349static void process_config_params(const XML_Char **attr)
350{
351 if (strcmp(attr[0], "key") != 0) {
352 ALOGE("%s: 'key' not found", __func__);
353 goto done;
354 }
355
356 if (strcmp(attr[2], "value") != 0) {
357 ALOGE("%s: 'value' not found", __func__);
358 goto done;
359 }
360
361 str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
362done:
363 return;
364}
365
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530366/* process acdb meta info key value */
367static void process_acdb_metainfo_key(const XML_Char **attr)
368{
369 if (strcmp(attr[0], "name") != 0) {
370 ALOGE("%s: 'name' not found", __func__);
371 goto done;
372 }
373
374 if (strcmp(attr[2], "value") != 0) {
375 ALOGE("%s: 'value' not found", __func__);
376 goto done;
377 }
378
379 int key = atoi((char *)attr[3]);
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700380 switch(my_data.caller) {
381 case ACDB_EXTN:
382 if(acdb_set_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
383 ALOGE("%s: key %d was not set!", __func__, key);
384 goto done;
385 }
386 break;
387 case PLATFORM:
388 if(platform_set_acdb_metainfo_key(my_data.platform, (char*)attr[1], key) < 0) {
389 ALOGE("%s: key %d was not set!", __func__, key);
390 goto done;
391 }
392 break;
393 default:
394 ALOGE("%s: unknown caller!", __func__);
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530395 }
396
397done:
398 return;
399}
400
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700401static void start_tag(void *userdata __unused, const XML_Char *tag_name,
Ben Romberger55886882014-01-10 13:49:02 -0800402 const XML_Char **attr)
403{
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700404 if (my_data.caller == ACDB_EXTN) {
405 if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
406 section = ACDB_METAINFO_KEY;
407 } else if (strcmp(tag_name, "param") == 0) {
408 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
409 ALOGE("param tag only supported with CONFIG_PARAMS section");
410 return;
411 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700412
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700413 section_process_fn fn = section_table[section];
414 fn(attr);
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700415 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700416 } else if(my_data.caller == PLATFORM) {
417 if (strcmp(tag_name, "bit_width_configs") == 0) {
418 section = BITWIDTH;
419 } else if (strcmp(tag_name, "acdb_ids") == 0) {
420 section = ACDB;
421 } else if (strcmp(tag_name, "pcm_ids") == 0) {
422 section = PCM_ID;
423 } else if (strcmp(tag_name, "backend_names") == 0) {
424 section = BACKEND_NAME;
425 } else if (strcmp(tag_name, "config_params") == 0) {
426 section = CONFIG_PARAMS;
427 } else if (strcmp(tag_name, "interface_names") == 0) {
428 section = INTERFACE_NAME;
429 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
430 section = GAIN_LEVEL_MAPPING;
431 } else if(strcmp(tag_name, "acdb_metainfo_key") == 0) {
432 section = ACDB_METAINFO_KEY;
433 } else if (strcmp(tag_name, "device") == 0) {
434 if ((section != ACDB) && (section != BACKEND_NAME) && (section != BITWIDTH) &&
435 (section != INTERFACE_NAME)) {
436 ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
437 return;
438 }
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700439
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700440 /* call into process function for the current section */
441 section_process_fn fn = section_table[section];
442 fn(attr);
443 } else if (strcmp(tag_name, "gain_level_map") == 0) {
444 if (section != GAIN_LEVEL_MAPPING) {
445 ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
446 return;
447 }
448
449 section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
450 fn(attr);
451 } else if (strcmp(tag_name, "usecase") == 0) {
452 if (section != PCM_ID) {
453 ALOGE("usecase tag only supported with PCM_ID section");
454 return;
455 }
456
457 section_process_fn fn = section_table[PCM_ID];
458 fn(attr);
459 } else if (strcmp(tag_name, "param") == 0) {
460 if ((section != CONFIG_PARAMS) && (section != ACDB_METAINFO_KEY)) {
461 ALOGE("param tag only supported with CONFIG_PARAMS section");
462 return;
463 }
464
465 section_process_fn fn = section_table[section];
466 fn(attr);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700467 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700468 } else {
469 ALOGE("%s: unknown caller!", __func__);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700470 }
Ben Romberger55886882014-01-10 13:49:02 -0800471 return;
472}
473
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700474static void end_tag(void *userdata __unused, const XML_Char *tag_name)
Ben Romberger55886882014-01-10 13:49:02 -0800475{
Amit Shekhar5a39c912014-10-14 15:39:30 -0700476 if (strcmp(tag_name, "bit_width_configs") == 0) {
477 section = ROOT;
478 } else if (strcmp(tag_name, "acdb_ids") == 0) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700479 section = ROOT;
480 } else if (strcmp(tag_name, "pcm_ids") == 0) {
481 section = ROOT;
482 } else if (strcmp(tag_name, "backend_names") == 0) {
483 section = ROOT;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700484 } else if (strcmp(tag_name, "config_params") == 0) {
485 section = ROOT;
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700486 if (my_data.caller == PLATFORM) {
487 platform_set_parameters(my_data.platform, my_data.kvpairs);
488 }
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -0800489 } else if (strcmp(tag_name, "interface_names") == 0) {
490 section = ROOT;
Aniket Kumar Lataf56b6402016-10-27 12:03:18 -0700491 } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
492 section = ROOT;
Dhanalakshmi Siddani21be3ac2016-12-29 14:31:08 +0530493 } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) {
494 section = ROOT;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700495 }
Ben Romberger55886882014-01-10 13:49:02 -0800496}
497
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700498int platform_info_init(const char *filename, void *platform, caller_t caller_type)
Ben Romberger55886882014-01-10 13:49:02 -0800499{
500 XML_Parser parser;
501 FILE *file;
502 int ret = 0;
503 int bytes_read;
Ben Romberger55886882014-01-10 13:49:02 -0800504 void *buf;
505
Helen Zeng6a16ad72014-02-23 22:04:44 -0800506 file = fopen(filename, "r");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700507 section = ROOT;
508
Ben Romberger55886882014-01-10 13:49:02 -0800509 if (!file) {
510 ALOGD("%s: Failed to open %s, using defaults.",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800511 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -0800512 ret = -ENODEV;
513 goto done;
514 }
515
516 parser = XML_ParserCreate(NULL);
517 if (!parser) {
518 ALOGE("%s: Failed to create XML parser!", __func__);
519 ret = -ENODEV;
520 goto err_close_file;
521 }
522
Vignesh Kulothungan55396882017-04-20 14:37:02 -0700523 my_data.caller = caller_type;
Ravi Kumar Alamanda14b0f2d2015-06-28 21:04:09 -0700524 my_data.platform = platform;
525 my_data.kvpairs = str_parms_create();
526
Ben Romberger55886882014-01-10 13:49:02 -0800527 XML_SetElementHandler(parser, start_tag, end_tag);
528
529 while (1) {
530 buf = XML_GetBuffer(parser, BUF_SIZE);
531 if (buf == NULL) {
532 ALOGE("%s: XML_GetBuffer failed", __func__);
533 ret = -ENOMEM;
534 goto err_free_parser;
535 }
536
537 bytes_read = fread(buf, 1, BUF_SIZE, file);
538 if (bytes_read < 0) {
539 ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
540 ret = bytes_read;
541 goto err_free_parser;
542 }
543
544 if (XML_ParseBuffer(parser, bytes_read,
545 bytes_read == 0) == XML_STATUS_ERROR) {
546 ALOGE("%s: XML_ParseBuffer failed, for %s",
Helen Zeng6a16ad72014-02-23 22:04:44 -0800547 __func__, filename);
Ben Romberger55886882014-01-10 13:49:02 -0800548 ret = -EINVAL;
549 goto err_free_parser;
550 }
551
552 if (bytes_read == 0)
553 break;
554 }
555
Ben Romberger55886882014-01-10 13:49:02 -0800556err_free_parser:
557 XML_ParserFree(parser);
558err_close_file:
559 fclose(file);
560done:
561 return ret;
562}