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