Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 1 | /* |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 3 | * |
| 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 Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 30 | #define LOG_TAG "platform_info" |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 31 | #define LOG_NDDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
| 34 | #include <stdio.h> |
| 35 | #include <expat.h> |
| 36 | #include <cutils/log.h> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 37 | #include <cutils/str_parms.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 38 | #include <audio_hw.h> |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 39 | #include "platform_api.h" |
| 40 | #include <platform.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 41 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 42 | #define BUF_SIZE 1024 |
| 43 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 44 | typedef enum { |
| 45 | ROOT, |
| 46 | ACDB, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 47 | BITWIDTH, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 48 | PCM_ID, |
| 49 | BACKEND_NAME, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 50 | INTERFACE_NAME, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 51 | CONFIG_PARAMS, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 52 | } section_t; |
| 53 | |
| 54 | typedef void (* section_process_fn)(const XML_Char **attr); |
| 55 | |
| 56 | static void process_acdb_id(const XML_Char **attr); |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 57 | static void process_bit_width(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 58 | static void process_pcm_id(const XML_Char **attr); |
| 59 | static void process_backend_name(const XML_Char **attr); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 60 | static void process_interface_name(const XML_Char **attr); |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 61 | static void process_config_params(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 62 | static void process_root(const XML_Char **attr); |
| 63 | |
| 64 | static section_process_fn section_table[] = { |
| 65 | [ROOT] = process_root, |
| 66 | [ACDB] = process_acdb_id, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 67 | [BITWIDTH] = process_bit_width, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 68 | [PCM_ID] = process_pcm_id, |
| 69 | [BACKEND_NAME] = process_backend_name, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 70 | [INTERFACE_NAME] = process_interface_name, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 71 | [CONFIG_PARAMS] = process_config_params, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | static section_t section; |
| 75 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 76 | struct platform_info { |
| 77 | void *platform; |
| 78 | struct str_parms *kvpairs; |
| 79 | }; |
| 80 | |
| 81 | static struct platform_info my_data; |
| 82 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 83 | /* |
| 84 | * <audio_platform_info> |
| 85 | * <acdb_ids> |
| 86 | * <device name="???" acdb_id="???"/> |
| 87 | * ... |
| 88 | * ... |
| 89 | * </acdb_ids> |
| 90 | * <backend_names> |
| 91 | * <device name="???" backend="???"/> |
| 92 | * ... |
| 93 | * ... |
| 94 | * </backend_names> |
| 95 | * <pcm_ids> |
| 96 | * <usecase name="???" type="in/out" id="???"/> |
| 97 | * ... |
| 98 | * ... |
| 99 | * </pcm_ids> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 100 | * <interface_names> |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 101 | * <device name="Use audio device name here, not sound device name" interface="PRIMARY_I2S" codec_type="external/internal"/> |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 102 | * ... |
| 103 | * ... |
| 104 | * </interface_names> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 105 | * <config_params> |
| 106 | * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/> |
| 107 | * ... |
| 108 | * ... |
| 109 | * </config_params> |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 110 | * </audio_platform_info> |
| 111 | */ |
| 112 | |
| 113 | static void process_root(const XML_Char **attr __unused) |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | /* mapping from usecase to pcm dev id */ |
| 118 | static void process_pcm_id(const XML_Char **attr) |
| 119 | { |
| 120 | int index; |
| 121 | |
| 122 | if (strcmp(attr[0], "name") != 0) { |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 123 | ALOGE("%s: 'name' not found, no pcm_id set!", __func__); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 124 | goto done; |
| 125 | } |
| 126 | |
| 127 | index = platform_get_usecase_index((char *)attr[1]); |
| 128 | if (index < 0) { |
| 129 | ALOGE("%s: usecase %s not found!", |
| 130 | __func__, attr[1]); |
| 131 | goto done; |
| 132 | } |
| 133 | |
| 134 | if (strcmp(attr[2], "type") != 0) { |
| 135 | ALOGE("%s: usecase type not mentioned", __func__); |
| 136 | goto done; |
| 137 | } |
| 138 | |
| 139 | int type = -1; |
| 140 | |
| 141 | if (!strcasecmp((char *)attr[3], "in")) { |
| 142 | type = 1; |
| 143 | } else if (!strcasecmp((char *)attr[3], "out")) { |
| 144 | type = 0; |
| 145 | } else { |
| 146 | ALOGE("%s: type must be IN or OUT", __func__); |
| 147 | goto done; |
| 148 | } |
| 149 | |
| 150 | if (strcmp(attr[4], "id") != 0) { |
| 151 | ALOGE("%s: usecase id not mentioned", __func__); |
| 152 | goto done; |
| 153 | } |
| 154 | |
| 155 | int id = atoi((char *)attr[5]); |
| 156 | |
| 157 | if (platform_set_usecase_pcm_id(index, type, id) < 0) { |
| 158 | ALOGE("%s: usecase %s type %d id %d was not set!", |
| 159 | __func__, attr[1], type, id); |
| 160 | goto done; |
| 161 | } |
| 162 | |
| 163 | done: |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | /* backend to be used for a device */ |
| 168 | static void process_backend_name(const XML_Char **attr) |
| 169 | { |
| 170 | int index; |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 171 | char *hw_interface = NULL; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 172 | |
| 173 | if (strcmp(attr[0], "name") != 0) { |
| 174 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 175 | goto done; |
| 176 | } |
| 177 | |
| 178 | index = platform_get_snd_device_index((char *)attr[1]); |
| 179 | if (index < 0) { |
| 180 | ALOGE("%s: Device %s not found, no ACDB ID set!", |
| 181 | __func__, attr[1]); |
| 182 | goto done; |
| 183 | } |
| 184 | |
| 185 | if (strcmp(attr[2], "backend") != 0) { |
| 186 | ALOGE("%s: Device %s has no backend set!", |
| 187 | __func__, attr[1]); |
| 188 | goto done; |
| 189 | } |
| 190 | |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 191 | if (attr[4] != NULL) { |
| 192 | if (strcmp(attr[4], "interface") != 0) { |
| 193 | hw_interface = NULL; |
| 194 | } else { |
| 195 | hw_interface = (char *)attr[5]; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if (platform_set_snd_device_backend(index, attr[3], hw_interface) < 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 200 | ALOGE("%s: Device %s backend %s was not set!", |
| 201 | __func__, attr[1], attr[3]); |
| 202 | goto done; |
| 203 | } |
| 204 | |
| 205 | done: |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | static void process_acdb_id(const XML_Char **attr) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 210 | { |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 211 | int index; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 212 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 213 | if (strcmp(attr[0], "name") != 0) { |
| 214 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 215 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 216 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 217 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 218 | index = platform_get_snd_device_index((char *)attr[1]); |
| 219 | if (index < 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 220 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 221 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 222 | goto done; |
| 223 | } |
| 224 | |
| 225 | if (strcmp(attr[2], "acdb_id") != 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 226 | ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!", |
| 227 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 228 | goto done; |
| 229 | } |
| 230 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 231 | if (platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) { |
| 232 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 233 | __func__, attr[1], atoi((char *)attr[3])); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 234 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 235 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 236 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 237 | done: |
| 238 | return; |
| 239 | } |
| 240 | |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 241 | static void process_bit_width(const XML_Char **attr) |
| 242 | { |
| 243 | int index; |
| 244 | |
| 245 | if (strcmp(attr[0], "name") != 0) { |
| 246 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
| 247 | goto done; |
| 248 | } |
| 249 | |
| 250 | index = platform_get_snd_device_index((char *)attr[1]); |
| 251 | if (index < 0) { |
| 252 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 253 | __func__, attr[1]); |
| 254 | goto done; |
| 255 | } |
| 256 | |
| 257 | if (strcmp(attr[2], "bit_width") != 0) { |
| 258 | ALOGE("%s: Device %s in platform info xml has no bit_width, no ACDB ID set!", |
| 259 | __func__, attr[1]); |
| 260 | goto done; |
| 261 | } |
| 262 | |
| 263 | if (platform_set_snd_device_bit_width(index, atoi((char *)attr[3])) < 0) { |
| 264 | ALOGE("%s: Device %s, ACDB ID %d was not set!", |
| 265 | __func__, attr[1], atoi((char *)attr[3])); |
| 266 | goto done; |
| 267 | } |
| 268 | |
| 269 | done: |
| 270 | return; |
| 271 | } |
| 272 | |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 273 | static void process_interface_name(const XML_Char **attr) |
| 274 | { |
| 275 | int ret; |
| 276 | |
| 277 | if (strcmp(attr[0], "name") != 0) { |
| 278 | ALOGE("%s: 'name' not found, no Audio Interface set!", __func__); |
| 279 | |
| 280 | goto done; |
| 281 | } |
| 282 | |
| 283 | if (strcmp(attr[2], "interface") != 0) { |
| 284 | ALOGE("%s: Device %s has no Audio Interface set!", |
| 285 | __func__, attr[1]); |
| 286 | |
| 287 | goto done; |
| 288 | } |
| 289 | |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 290 | if (strcmp(attr[4], "codec_type") != 0) { |
| 291 | ALOGE("%s: Device %s has no codec type set!", |
| 292 | __func__, attr[1]); |
| 293 | |
| 294 | goto done; |
| 295 | } |
| 296 | |
| 297 | ret = platform_set_audio_device_interface((char *)attr[1], (char *)attr[3], |
| 298 | (char *)attr[5]); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 299 | if (ret < 0) { |
| 300 | ALOGE("%s: Audio Interface not set!", __func__); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 301 | goto done; |
| 302 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 303 | |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 304 | done: |
| 305 | return; |
| 306 | } |
Laxminath Kasam | 44f4940 | 2015-05-29 18:37:11 +0530 | [diff] [blame] | 307 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 308 | static void process_config_params(const XML_Char **attr) |
| 309 | { |
| 310 | if (strcmp(attr[0], "key") != 0) { |
| 311 | ALOGE("%s: 'key' not found", __func__); |
| 312 | goto done; |
| 313 | } |
| 314 | |
| 315 | if (strcmp(attr[2], "value") != 0) { |
| 316 | ALOGE("%s: 'value' not found", __func__); |
| 317 | goto done; |
| 318 | } |
| 319 | |
| 320 | str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]); |
| 321 | done: |
| 322 | return; |
| 323 | } |
| 324 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 325 | static void start_tag(void *userdata __unused, const XML_Char *tag_name, |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 326 | const XML_Char **attr) |
| 327 | { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 328 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 329 | section = BITWIDTH; |
| 330 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 331 | section = ACDB; |
| 332 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 333 | section = PCM_ID; |
| 334 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 335 | section = BACKEND_NAME; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 336 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 337 | section = CONFIG_PARAMS; |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 338 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 339 | section = INTERFACE_NAME; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 340 | } else if (strcmp(tag_name, "device") == 0) { |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 341 | if ((section != ACDB) && (section != BACKEND_NAME) && (section != BITWIDTH) && |
Laxminath Kasam | 167ade5 | 2016-05-23 17:46:51 +0530 | [diff] [blame] | 342 | (section != INTERFACE_NAME)) { |
| 343 | ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 344 | return; |
| 345 | } |
| 346 | |
| 347 | /* call into process function for the current section */ |
| 348 | section_process_fn fn = section_table[section]; |
| 349 | fn(attr); |
| 350 | } else if (strcmp(tag_name, "usecase") == 0) { |
| 351 | if (section != PCM_ID) { |
| 352 | ALOGE("usecase tag only supported with PCM_ID section"); |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | section_process_fn fn = section_table[PCM_ID]; |
| 357 | fn(attr); |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 358 | } else if (strcmp(tag_name, "param") == 0) { |
| 359 | if (section != CONFIG_PARAMS) { |
| 360 | ALOGE("param tag only supported with CONFIG_PARAMS section"); |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | section_process_fn fn = section_table[section]; |
| 365 | fn(attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 366 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 367 | |
| 368 | return; |
| 369 | } |
| 370 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 371 | static void end_tag(void *userdata __unused, const XML_Char *tag_name) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 372 | { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 373 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 374 | section = ROOT; |
| 375 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 376 | section = ROOT; |
| 377 | } else if (strcmp(tag_name, "pcm_ids") == 0) { |
| 378 | section = ROOT; |
| 379 | } else if (strcmp(tag_name, "backend_names") == 0) { |
| 380 | section = ROOT; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 381 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 382 | section = ROOT; |
| 383 | platform_set_parameters(my_data.platform, my_data.kvpairs); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 384 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 385 | section = ROOT; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 386 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 387 | } |
| 388 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 389 | int platform_info_init(const char *filename, void *platform) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 390 | { |
| 391 | XML_Parser parser; |
| 392 | FILE *file; |
| 393 | int ret = 0; |
| 394 | int bytes_read; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 395 | void *buf; |
| 396 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 397 | file = fopen(filename, "r"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 398 | section = ROOT; |
| 399 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 400 | if (!file) { |
| 401 | ALOGD("%s: Failed to open %s, using defaults.", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 402 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 403 | ret = -ENODEV; |
| 404 | goto done; |
| 405 | } |
| 406 | |
| 407 | parser = XML_ParserCreate(NULL); |
| 408 | if (!parser) { |
| 409 | ALOGE("%s: Failed to create XML parser!", __func__); |
| 410 | ret = -ENODEV; |
| 411 | goto err_close_file; |
| 412 | } |
| 413 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 414 | my_data.platform = platform; |
| 415 | my_data.kvpairs = str_parms_create(); |
| 416 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 417 | XML_SetElementHandler(parser, start_tag, end_tag); |
| 418 | |
| 419 | while (1) { |
| 420 | buf = XML_GetBuffer(parser, BUF_SIZE); |
| 421 | if (buf == NULL) { |
| 422 | ALOGE("%s: XML_GetBuffer failed", __func__); |
| 423 | ret = -ENOMEM; |
| 424 | goto err_free_parser; |
| 425 | } |
| 426 | |
| 427 | bytes_read = fread(buf, 1, BUF_SIZE, file); |
| 428 | if (bytes_read < 0) { |
| 429 | ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); |
| 430 | ret = bytes_read; |
| 431 | goto err_free_parser; |
| 432 | } |
| 433 | |
| 434 | if (XML_ParseBuffer(parser, bytes_read, |
| 435 | bytes_read == 0) == XML_STATUS_ERROR) { |
| 436 | ALOGE("%s: XML_ParseBuffer failed, for %s", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 437 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 438 | ret = -EINVAL; |
| 439 | goto err_free_parser; |
| 440 | } |
| 441 | |
| 442 | if (bytes_read == 0) |
| 443 | break; |
| 444 | } |
| 445 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 446 | err_free_parser: |
| 447 | XML_ParserFree(parser); |
| 448 | err_close_file: |
| 449 | fclose(file); |
| 450 | done: |
| 451 | return ret; |
| 452 | } |