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