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