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> |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 39 | #include "acdb.h" |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 40 | #include "platform_api.h" |
| 41 | #include <platform.h> |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 42 | #include <math.h> |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 43 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 44 | #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 Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 50 | #define BUF_SIZE 1024 |
| 51 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 52 | typedef enum { |
| 53 | ROOT, |
| 54 | ACDB, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 55 | BITWIDTH, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 56 | PCM_ID, |
| 57 | BACKEND_NAME, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 58 | INTERFACE_NAME, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 59 | CONFIG_PARAMS, |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 60 | GAIN_LEVEL_MAPPING, |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 61 | ACDB_METAINFO_KEY, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 62 | } section_t; |
| 63 | |
| 64 | typedef void (* section_process_fn)(const XML_Char **attr); |
| 65 | |
| 66 | static void process_acdb_id(const XML_Char **attr); |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 67 | static void process_bit_width(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 68 | static void process_pcm_id(const XML_Char **attr); |
| 69 | static void process_backend_name(const XML_Char **attr); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 70 | static void process_interface_name(const XML_Char **attr); |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 71 | static void process_config_params(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 72 | static void process_root(const XML_Char **attr); |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 73 | static void process_gain_db_to_level_map(const XML_Char **attr); |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 74 | static void process_acdb_metainfo_key(const XML_Char **attr); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 75 | |
| 76 | static section_process_fn section_table[] = { |
| 77 | [ROOT] = process_root, |
| 78 | [ACDB] = process_acdb_id, |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 79 | [BITWIDTH] = process_bit_width, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 80 | [PCM_ID] = process_pcm_id, |
| 81 | [BACKEND_NAME] = process_backend_name, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 82 | [INTERFACE_NAME] = process_interface_name, |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 83 | [CONFIG_PARAMS] = process_config_params, |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 84 | [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map, |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 85 | [ACDB_METAINFO_KEY] = process_acdb_metainfo_key, |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | static section_t section; |
| 89 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 90 | struct platform_info { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 91 | caller_t caller; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 92 | void *platform; |
| 93 | struct str_parms *kvpairs; |
| 94 | }; |
| 95 | |
| 96 | static struct platform_info my_data; |
| 97 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 98 | /* |
| 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 Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 115 | * <interface_names> |
Karthik Reddy Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 116 | * <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] | 117 | * ... |
| 118 | * ... |
| 119 | * </interface_names> |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 120 | * <config_params> |
| 121 | * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/> |
| 122 | * ... |
| 123 | * ... |
| 124 | * </config_params> |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 125 | * </audio_platform_info> |
| 126 | */ |
| 127 | |
| 128 | static void process_root(const XML_Char **attr __unused) |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | /* mapping from usecase to pcm dev id */ |
| 133 | static void process_pcm_id(const XML_Char **attr) |
| 134 | { |
| 135 | int index; |
| 136 | |
| 137 | if (strcmp(attr[0], "name") != 0) { |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 138 | ALOGE("%s: 'name' not found, no pcm_id set!", __func__); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 139 | 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 | |
| 178 | done: |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | /* backend to be used for a device */ |
| 183 | static void process_backend_name(const XML_Char **attr) |
| 184 | { |
| 185 | int index; |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 186 | char *hw_interface = NULL; |
Ashish Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 187 | char *backend = NULL; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 188 | |
| 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 Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 202 | if (strcmp(attr[2], "interface") == 0) |
| 203 | hw_interface = (char *)attr[3]; |
| 204 | } else { |
| 205 | backend = (char *)attr[3]; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 208 | 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 Jain | d150d4c | 2017-02-03 18:44:34 +0530 | [diff] [blame] | 216 | if (platform_set_snd_device_backend(index, backend, hw_interface) < 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 217 | ALOGE("%s: Device %s backend %s was not set!", |
| 218 | __func__, attr[1], attr[3]); |
| 219 | goto done; |
| 220 | } |
| 221 | |
| 222 | done: |
| 223 | return; |
| 224 | } |
| 225 | |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 226 | static 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 | |
| 245 | done: |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 250 | static void process_acdb_id(const XML_Char **attr) |
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 | int index; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 253 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 254 | if (strcmp(attr[0], "name") != 0) { |
| 255 | ALOGE("%s: 'name' not found, no ACDB ID set!", __func__); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 256 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 257 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 258 | |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 259 | index = platform_get_snd_device_index((char *)attr[1]); |
| 260 | if (index < 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 261 | ALOGE("%s: Device %s in platform info xml not found, no ACDB ID set!", |
| 262 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 263 | goto done; |
| 264 | } |
| 265 | |
| 266 | if (strcmp(attr[2], "acdb_id") != 0) { |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 267 | ALOGE("%s: Device %s in platform info xml has no acdb_id, no ACDB ID set!", |
| 268 | __func__, attr[1]); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 269 | goto done; |
| 270 | } |
| 271 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 272 | 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 Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 274 | __func__, attr[1], atoi((char *)attr[3])); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 275 | goto done; |
Ben Romberger | 61764e3 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 276 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 277 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 278 | done: |
| 279 | return; |
| 280 | } |
| 281 | |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 282 | static 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 | |
| 310 | done: |
| 311 | return; |
| 312 | } |
| 313 | |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 314 | static 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 Katta | 508eca4 | 2015-05-11 13:43:18 +0530 | [diff] [blame] | 331 | 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 Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 340 | if (ret < 0) { |
| 341 | ALOGE("%s: Audio Interface not set!", __func__); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 342 | goto done; |
| 343 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 344 | |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 345 | done: |
| 346 | return; |
| 347 | } |
Laxminath Kasam | 44f4940 | 2015-05-29 18:37:11 +0530 | [diff] [blame] | 348 | |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 349 | static 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]); |
| 362 | done: |
| 363 | return; |
| 364 | } |
| 365 | |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 366 | /* process acdb meta info key value */ |
| 367 | static 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 Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 380 | 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 Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | done: |
| 398 | return; |
| 399 | } |
| 400 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 401 | static void start_tag(void *userdata __unused, const XML_Char *tag_name, |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 402 | const XML_Char **attr) |
| 403 | { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 404 | 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 George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 412 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 413 | section_process_fn fn = section_table[section]; |
| 414 | fn(attr); |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 415 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 416 | } 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 Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 439 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 440 | /* 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 George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 467 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 468 | } else { |
| 469 | ALOGE("%s: unknown caller!", __func__); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 470 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 471 | return; |
| 472 | } |
| 473 | |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 474 | static void end_tag(void *userdata __unused, const XML_Char *tag_name) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 475 | { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 476 | if (strcmp(tag_name, "bit_width_configs") == 0) { |
| 477 | section = ROOT; |
| 478 | } else if (strcmp(tag_name, "acdb_ids") == 0) { |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 479 | 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 Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 484 | } else if (strcmp(tag_name, "config_params") == 0) { |
| 485 | section = ROOT; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 486 | if (my_data.caller == PLATFORM) { |
| 487 | platform_set_parameters(my_data.platform, my_data.kvpairs); |
| 488 | } |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 489 | } else if (strcmp(tag_name, "interface_names") == 0) { |
| 490 | section = ROOT; |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 491 | } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) { |
| 492 | section = ROOT; |
Dhanalakshmi Siddani | 21be3ac | 2016-12-29 14:31:08 +0530 | [diff] [blame] | 493 | } else if (strcmp(tag_name, "acdb_metainfo_key") == 0) { |
| 494 | section = ROOT; |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 495 | } |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 498 | int platform_info_init(const char *filename, void *platform, caller_t caller_type) |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 499 | { |
| 500 | XML_Parser parser; |
| 501 | FILE *file; |
| 502 | int ret = 0; |
| 503 | int bytes_read; |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 504 | void *buf; |
| 505 | |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 506 | file = fopen(filename, "r"); |
Haynes Mathew George | f4da6fe | 2014-06-20 19:14:25 -0700 | [diff] [blame] | 507 | section = ROOT; |
| 508 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 509 | if (!file) { |
| 510 | ALOGD("%s: Failed to open %s, using defaults.", |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 511 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 512 | 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 Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 523 | my_data.caller = caller_type; |
Ravi Kumar Alamanda | 14b0f2d | 2015-06-28 21:04:09 -0700 | [diff] [blame] | 524 | my_data.platform = platform; |
| 525 | my_data.kvpairs = str_parms_create(); |
| 526 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 527 | 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 Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 547 | __func__, filename); |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 548 | ret = -EINVAL; |
| 549 | goto err_free_parser; |
| 550 | } |
| 551 | |
| 552 | if (bytes_read == 0) |
| 553 | break; |
| 554 | } |
| 555 | |
Ben Romberger | 5588688 | 2014-01-10 13:49:02 -0800 | [diff] [blame] | 556 | err_free_parser: |
| 557 | XML_ParserFree(parser); |
| 558 | err_close_file: |
| 559 | fclose(file); |
| 560 | done: |
| 561 | return ret; |
| 562 | } |