1 /******************************************************************************
2 *
3 * Copyright (C) 1999-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #define LOG_TAG "NfcNciHal"
20
21 #include "_OverrideLog.h"
22 #include "config.h"
23 #include "nfc_hal_int.h"
24 #include "userial.h"
25 extern "C" {
26 #include "nfc_hal_post_reset.h"
27 }
28 #include <cutils/properties.h>
29 #include <malloc.h>
30 #include <string>
31 #include "StartupConfig.h"
32 #include "spdhelper.h"
33
34 #define FW_PRE_PATCH "FW_PRE_PATCH"
35 #define FW_PATCH "FW_PATCH"
36 #define MAX_RF_DATA_CREDITS "MAX_RF_DATA_CREDITS"
37
38 #define MAX_BUFFER (512)
39 static char sPrePatchFn[MAX_BUFFER + 1];
40 static char sPatchFn[MAX_BUFFER + 1];
41 static void* sPrmBuf = NULL;
42 static void* sI2cFixPrmBuf = NULL;
43
44 #define CONFIG_MAX_LEN 256
45 static uint8_t sConfig[CONFIG_MAX_LEN];
46 static StartupConfig sStartupConfig;
47 static StartupConfig sLptdConfig;
48 static StartupConfig sPreDiscoveryConfig;
49 static StartupConfig sXtalCustomParam;
50 extern uint8_t* p_nfc_hal_dm_start_up_cfg; // defined in the HAL
51 static uint8_t nfa_dm_start_up_vsc_cfg[CONFIG_MAX_LEN];
52 extern uint8_t* p_nfc_hal_dm_start_up_vsc_cfg; // defined in the HAL
53 extern uint8_t* p_nfc_hal_dm_lptd_cfg; // defined in the HAL
54 static uint8_t sDontSendLptd[] = {0};
55 extern uint8_t* p_nfc_hal_pre_discover_cfg; // defined in the HAL
56 extern uint8_t* p_nfc_hal_dm_xtal_params_cfg; // defined in HAL
57
58 extern tSNOOZE_MODE_CONFIG gSnoozeModeCfg;
59 extern tNFC_HAL_CFG* p_nfc_hal_cfg;
60 static void mayDisableSecureElement(StartupConfig& config);
61
62 /* Default patchfile (in NCD format) */
63 #ifndef NFA_APP_DEFAULT_PATCHFILE_NAME
64 #define NFA_APP_DEFAULT_PATCHFILE_NAME "\0"
65 #endif
66
67 /* Default patchfile (in NCD format) */
68 #ifndef NFA_APP_DEFAULT_I2C_PATCHFILE_NAME
69 #define NFA_APP_DEFAULT_I2C_PATCHFILE_NAME "\0"
70 #endif
71
72 tNFC_POST_RESET_CB nfc_post_reset_cb = {
73 /* Default Patch & Pre-Patch */
74 NFA_APP_DEFAULT_PATCHFILE_NAME,
75 NULL,
76 NFA_APP_DEFAULT_I2C_PATCHFILE_NAME,
77 NULL,
78
79 /* Default UART baud rate */
80 NFC_HAL_DEFAULT_BAUD,
81
82 /* Default tNFC_HAL_DEV_INIT_CFG (flags, num_xtal_cfg, {brcm_hw_id,
83 xtal-freq, xtal-index} ) */
84 {2, /* number of valid entries */
85 {
86 {0x43341000, 37400,
87 NFC_HAL_XTAL_INDEX_37400}, // All revisions of 43341 use 37,400
88 {0x20795000, 26000, NFC_HAL_XTAL_INDEX_26000},
89 {0, 0, 0},
90 {0, 0, 0},
91 {0, 0, 0},
92 }},
93
94 /* Default low power mode settings */
95 NFC_HAL_LP_SNOOZE_MODE_NONE, /* Snooze Mode */
96 NFC_HAL_LP_IDLE_THRESHOLD_HOST, /* Idle Threshold Host */
97 NFC_HAL_LP_IDLE_THRESHOLD_HC, /* Idle Threshold HC */
98 NFC_HAL_LP_ACTIVE_LOW, /* NFC_WAKE Active Mode */
99 NFC_HAL_LP_ACTIVE_HIGH, /* DH_WAKE Active Mode */
100
101 NFA_APP_MAX_NUM_REINIT, /* max retry to get NVM type */
102 0, /* current retry count */
103 TRUE, /* debug mode for downloading patchram */
104 FALSE /* skip downloading patchram after reinit because of patch download
105 failure */
106 };
107
108 /*******************************************************************************
109 **
110 ** Function getFileLength
111 **
112 ** Description return the size of a file
113 **
114 ** Returns file size in number of bytes
115 **
116 *******************************************************************************/
getFileLength(FILE * fp)117 static long getFileLength(FILE* fp) {
118 long sz;
119 fseek(fp, 0L, SEEK_END);
120 sz = ftell(fp);
121 fseek(fp, 0L, SEEK_SET);
122
123 return (sz > 0) ? sz : 0;
124 }
125
126 /*******************************************************************************
127 **
128 ** Function isFileExist
129 **
130 ** Description Check if file name exists (android does not support fexists)
131 **
132 ** Returns TRUE if file exists
133 **
134 *******************************************************************************/
isFileExist(const char * pFilename)135 static bool isFileExist(const char* pFilename) {
136 FILE* pf;
137
138 pf = fopen(pFilename, "r");
139 if (pf != NULL) {
140 fclose(pf);
141 return TRUE;
142 }
143 return FALSE;
144 }
145
146 /*******************************************************************************
147 **
148 ** Function findPatchramFile
149 **
150 ** Description Find the patchram file name specified in the .conf
151 **
152 ** Returns pointer to the file name
153 **
154 *******************************************************************************/
findPatchramFile(const char * pConfigName,char * pBuffer,int bufferLen)155 static const char* findPatchramFile(const char* pConfigName, char* pBuffer,
156 int bufferLen) {
157 ALOGD("%s: config=%s", __func__, pConfigName);
158
159 if (pConfigName == NULL) {
160 ALOGD("%s No patchfile defined\n", __func__);
161 return NULL;
162 }
163
164 if (GetStrValue(pConfigName, &pBuffer[0], bufferLen)) {
165 ALOGD("%s found patchfile %s\n", __func__, pBuffer);
166 return (pBuffer[0] == '\0') ? NULL : pBuffer;
167 }
168
169 ALOGD("%s Cannot find patchfile '%s'\n", __func__, pConfigName);
170 return NULL;
171 }
172
173 /*******************************************************************************
174 **
175 ** Function: continueAfterSetSnoozeMode
176 **
177 ** Description: Called after Snooze Mode is enabled.
178 **
179 ** Returns: none
180 **
181 *******************************************************************************/
continueAfterSetSnoozeMode(tHAL_NFC_STATUS status)182 static void continueAfterSetSnoozeMode(tHAL_NFC_STATUS status) {
183 ALOGD("%s: status=%u", __func__, status);
184 // let stack download firmware during next initialization
185 nfc_post_reset_cb.spd_skip_on_power_cycle = FALSE;
186 if (status == NCI_STATUS_OK)
187 HAL_NfcPreInitDone(HAL_NFC_STATUS_OK);
188 else
189 HAL_NfcPreInitDone(HAL_NFC_STATUS_FAILED);
190 }
191
192 /*******************************************************************************
193 **
194 ** Function: postDownloadPatchram
195 **
196 ** Description: Called after patch download
197 **
198 ** Returns: none
199 **
200 *******************************************************************************/
postDownloadPatchram(tHAL_NFC_STATUS status)201 static void postDownloadPatchram(tHAL_NFC_STATUS status) {
202 ALOGD("%s: status=%i", __func__, status);
203 GetStrValue(NAME_SNOOZE_MODE_CFG, (char*)&gSnoozeModeCfg,
204 sizeof(gSnoozeModeCfg));
205 if (status != HAL_NFC_STATUS_OK) {
206 ALOGE("%s: Patch download failed", __func__);
207 if (status == HAL_NFC_STATUS_REFUSED) {
208 SpdHelper::setPatchAsBad();
209 } else
210 SpdHelper::incErrorCount();
211
212 /* If in SPD Debug mode, fail immediately and obviously */
213 if (SpdHelper::isSpdDebug())
214 HAL_NfcPreInitDone(HAL_NFC_STATUS_FAILED);
215 else {
216 /* otherwise, power cycle the chip and let the stack startup normally */
217 ALOGD("%s: re-init; don't download firmware", __func__);
218 // stop stack from downloading firmware during next initialization
219 nfc_post_reset_cb.spd_skip_on_power_cycle = TRUE;
220 USERIAL_PowerupDevice(0);
221 HAL_NfcReInit();
222 }
223 }
224 /* Set snooze mode here */
225 else if (gSnoozeModeCfg.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) {
226 status = HAL_NfcSetSnoozeMode(
227 gSnoozeModeCfg.snooze_mode, gSnoozeModeCfg.idle_threshold_dh,
228 gSnoozeModeCfg.idle_threshold_nfcc, gSnoozeModeCfg.nfc_wake_active_mode,
229 gSnoozeModeCfg.dh_wake_active_mode, continueAfterSetSnoozeMode);
230 if (status != NCI_STATUS_OK) {
231 ALOGE("%s: Setting snooze mode failed, status=%i", __func__, status);
232 HAL_NfcPreInitDone(HAL_NFC_STATUS_FAILED);
233 }
234 } else {
235 ALOGD("%s: Not using Snooze Mode", __func__);
236 HAL_NfcPreInitDone(HAL_NFC_STATUS_OK);
237 }
238 }
239
240 /*******************************************************************************
241 **
242 ** Function: prmCallback
243 **
244 ** Description: Patchram callback (for static patchram mode)
245 **
246 ** Returns: none
247 **
248 *******************************************************************************/
prmCallback(uint8_t event)249 void prmCallback(uint8_t event) {
250 ALOGD("%s: event=0x%x", __func__, event);
251 switch (event) {
252 case NFC_HAL_PRM_CONTINUE_EVT:
253 /* This event does not occur if static patchram buf is used */
254 break;
255
256 case NFC_HAL_PRM_COMPLETE_EVT:
257 postDownloadPatchram(HAL_NFC_STATUS_OK);
258 break;
259
260 case NFC_HAL_PRM_ABORT_EVT:
261 postDownloadPatchram(HAL_NFC_STATUS_FAILED);
262 break;
263
264 case NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT:
265 ALOGD("%s: invalid patch...skipping patch download", __func__);
266 postDownloadPatchram(HAL_NFC_STATUS_REFUSED);
267 break;
268
269 case NFC_HAL_PRM_ABORT_BAD_SIGNATURE_EVT:
270 ALOGD("%s: patch authentication failed", __func__);
271 postDownloadPatchram(HAL_NFC_STATUS_REFUSED);
272 break;
273
274 case NFC_HAL_PRM_ABORT_NO_NVM_EVT:
275 ALOGD("%s: No NVM detected", __func__);
276 HAL_NfcPreInitDone(HAL_NFC_STATUS_FAILED);
277 break;
278
279 default:
280 ALOGD("%s: not handled event=0x%x", __func__, event);
281 break;
282 }
283 }
284
285 /*******************************************************************************
286 **
287 ** Function getNfaValues
288 **
289 ** Description Get configuration values needed by NFA layer
290 **
291 ** Returns: None
292 **
293 *******************************************************************************/
getNfaValues(uint32_t chipid)294 static void getNfaValues(uint32_t chipid) {
295 unsigned long num = 0;
296 int actualLen = 0;
297
298 sStartupConfig.initialize();
299 sLptdConfig.initialize();
300 sPreDiscoveryConfig.initialize();
301
302 actualLen =
303 GetStrValue(NAME_NFA_DM_START_UP_CFG, (char*)sConfig, sizeof(sConfig));
304 if (actualLen) sStartupConfig.append(sConfig, actualLen);
305
306 // Set antenna tuning configuration if configured.
307 actualLen =
308 GetStrValue(NAME_PREINIT_DSP_CFG, (char*)sConfig, sizeof(sConfig));
309 if (actualLen) sStartupConfig.append(sConfig, actualLen);
310
311 if (GetStrValue(NAME_NFA_DM_START_UP_VSC_CFG, (char*)nfa_dm_start_up_vsc_cfg,
312 sizeof(nfa_dm_start_up_vsc_cfg))) {
313 p_nfc_hal_dm_start_up_vsc_cfg = &nfa_dm_start_up_vsc_cfg[0];
314 ALOGD("START_UP_VSC_CFG[0] = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
315 nfa_dm_start_up_vsc_cfg[0], nfa_dm_start_up_vsc_cfg[1],
316 nfa_dm_start_up_vsc_cfg[2], nfa_dm_start_up_vsc_cfg[3],
317 nfa_dm_start_up_vsc_cfg[4], nfa_dm_start_up_vsc_cfg[5],
318 nfa_dm_start_up_vsc_cfg[6], nfa_dm_start_up_vsc_cfg[7]);
319 }
320
321 actualLen = GetStrValue(NAME_LPTD_CFG, (char*)sConfig, sizeof(sConfig));
322 if (actualLen) {
323 sLptdConfig.append(sConfig, actualLen);
324 p_nfc_hal_dm_lptd_cfg =
325 const_cast<uint8_t*>(sLptdConfig.getInternalBuffer());
326 } else {
327 // Default to not sending any LPTD setting.
328 p_nfc_hal_dm_lptd_cfg = sDontSendLptd;
329 }
330
331 mayDisableSecureElement(sStartupConfig);
332 p_nfc_hal_dm_start_up_cfg =
333 const_cast<uint8_t*>(sStartupConfig.getInternalBuffer());
334
335 actualLen = GetStrValue(NAME_NFA_DM_PRE_DISCOVERY_CFG, (char*)sConfig,
336 sizeof(sConfig));
337 if (actualLen) {
338 sPreDiscoveryConfig.append(sConfig, actualLen);
339 mayDisableSecureElement(sPreDiscoveryConfig);
340 p_nfc_hal_pre_discover_cfg =
341 const_cast<uint8_t*>(sPreDiscoveryConfig.getInternalBuffer());
342 }
343
344 // configure how many secure elements are available for each type of chip
345 if (p_nfc_hal_cfg->nfc_hal_hci_uicc_support > 0) {
346 if ((chipid & BRCM_NFC_GEN_MASK) == BRCM_NFC_20791_GEN) {
347 nfc_hal_cb.max_ee = BRCM_NFC_20791_GEN_MAX_EE;
348 p_nfc_hal_cfg->nfc_hal_hci_uicc_support =
349 HAL_NFC_HCI_UICC0_HOST | HAL_NFC_HCI_UICC1_HOST;
350 } else if ((chipid & BRCM_NFC_GEN_MASK) == BRCM_NFC_43341_GEN) {
351 nfc_hal_cb.max_ee = BRCM_NFC_43341_GEN_MAX_EE;
352 p_nfc_hal_cfg->nfc_hal_hci_uicc_support =
353 HAL_NFC_HCI_UICC0_HOST | HAL_NFC_HCI_UICC1_HOST;
354 } else if ((chipid & BRCM_NFC_GEN_MASK) == BRCM_NFC_20795_GEN) {
355 nfc_hal_cb.max_ee = BRCM_NFC_20795_GEN_MAX_EE;
356 p_nfc_hal_cfg->nfc_hal_hci_uicc_support = HAL_NFC_HCI_UICC0_HOST |
357 HAL_NFC_HCI_UICC1_HOST |
358 HAL_NFC_HCI_UICC2_HOST;
359 }
360
361 // let .conf variable determine how many EE's to discover
362 if (GetNumValue(NAME_NFA_MAX_EE_SUPPORTED, &num, sizeof(num)))
363 nfc_hal_cb.max_ee = num;
364 }
365 }
366
367 /*******************************************************************************
368 **
369 ** Function StartPatchDownload
370 **
371 ** Description Reads configuration settings, and begins the download
372 ** process if patch files are configured.
373 **
374 ** Returns: None
375 **
376 *******************************************************************************/
StartPatchDownload(uint32_t chipid)377 static void StartPatchDownload(uint32_t chipid) {
378 ALOGD("%s: chipid=%lx", __func__, chipid);
379
380 char chipID[30];
381 sprintf(chipID, "%lx", chipid);
382 ALOGD("%s: chidId=%s", __func__, chipID);
383
384 readOptionalConfig(chipID); // Read optional chip specific settings
385 readOptionalConfig("fime"); // Read optional FIME specific settings
386 getNfaValues(chipid); // Get NFA configuration values into variables
387
388 findPatchramFile(FW_PATCH, sPatchFn, sizeof(sPatchFn));
389 findPatchramFile(FW_PRE_PATCH, sPrePatchFn, sizeof(sPatchFn));
390
391 {
392 FILE* fd;
393 /* If an I2C fix patch file was specified, then tell the stack about it */
394 if (sPrePatchFn[0] != '\0') {
395 fd = fopen(sPrePatchFn, "rb");
396 if (fd != NULL) {
397 uint32_t lenPrmBuffer = getFileLength(fd);
398
399 sI2cFixPrmBuf = malloc(lenPrmBuffer);
400 if (sI2cFixPrmBuf != NULL) {
401 size_t actualLen = fread(sI2cFixPrmBuf, 1, lenPrmBuffer, fd);
402 if (actualLen == lenPrmBuffer) {
403 ALOGD("%s Setting I2C fix to %s (size: %lu)", __func__, sPrePatchFn,
404 lenPrmBuffer);
405 HAL_NfcPrmSetI2cPatch((uint8_t*)sI2cFixPrmBuf,
406 (uint16_t)lenPrmBuffer, 0);
407 } else
408 ALOGE("%s fail reading i2c fix; actual len=%zu; expected len=%lu",
409 __func__, actualLen, lenPrmBuffer);
410 } else {
411 ALOGE("%s Unable to get buffer to i2c fix (%lu bytes)", __func__,
412 lenPrmBuffer);
413 }
414
415 fclose(fd);
416 } else {
417 ALOGE("%s Unable to open i2c fix patchfile %s", __func__, sPrePatchFn);
418 }
419 }
420 }
421
422 {
423 FILE* fd;
424
425 /* If a patch file was specified, then download it now */
426 if (sPatchFn[0] != '\0') {
427 uint32_t bDownloadStarted = false;
428
429 /* open patchfile, read it into a buffer */
430 fd = fopen(sPatchFn, "rb");
431 if (fd != NULL) {
432 uint32_t lenPrmBuffer = getFileLength(fd);
433 ALOGD("%s Downloading patchfile %s (size: %lu) format=%u", __func__,
434 sPatchFn, lenPrmBuffer, NFC_HAL_PRM_FORMAT_NCD);
435 sPrmBuf = malloc(lenPrmBuffer);
436 if (sPrmBuf != NULL) {
437 size_t actualLen = fread(sPrmBuf, 1, lenPrmBuffer, fd);
438 if (actualLen == lenPrmBuffer) {
439 if (!SpdHelper::isPatchBad((uint8_t*)sPrmBuf, lenPrmBuffer)) {
440 /* Download patch using static memeory mode */
441 HAL_NfcPrmDownloadStart(NFC_HAL_PRM_FORMAT_NCD, 0,
442 (uint8_t*)sPrmBuf, lenPrmBuffer, 0,
443 prmCallback);
444 bDownloadStarted = true;
445 }
446 } else
447 ALOGE("%s fail reading patchram", __func__);
448 } else
449 ALOGE("%s Unable to buffer to hold patchram (%lu bytes)", __func__,
450 lenPrmBuffer);
451
452 fclose(fd);
453 } else
454 ALOGE("%s Unable to open patchfile %s", __func__, sPatchFn);
455
456 /* If the download never got started */
457 if (!bDownloadStarted) {
458 /* If debug mode, fail in an obvious way, otherwise try to start stack
459 */
460 postDownloadPatchram(SpdHelper::isSpdDebug() ? HAL_NFC_STATUS_FAILED
461 : HAL_NFC_STATUS_OK);
462 }
463 } else {
464 ALOGE(
465 "%s: No patchfile specified or disabled. Proceeding to post-download "
466 "procedure...",
467 __func__);
468 postDownloadPatchram(HAL_NFC_STATUS_OK);
469 }
470 }
471
472 ALOGD("%s: exit", __func__);
473 }
474
475 /*******************************************************************************
476 **
477 ** Function: nfc_hal_post_reset_init
478 **
479 ** Description: Called by the NFC HAL after controller has been reset.
480 ** Begin to download firmware patch files.
481 **
482 ** Returns: none
483 **
484 *******************************************************************************/
nfc_hal_post_reset_init(uint32_t brcm_hw_id,uint8_t nvm_type)485 void nfc_hal_post_reset_init(uint32_t brcm_hw_id, uint8_t nvm_type) {
486 ALOGD("%s: brcm_hw_id=0x%lx, nvm_type=%d", __func__, brcm_hw_id, nvm_type);
487 tHAL_NFC_STATUS stat = HAL_NFC_STATUS_FAILED;
488 uint8_t max_credits = 1, allow_no_nvm = 0;
489
490 p_nfc_hal_cfg->nfc_hal_prm_nvm_required =
491 TRUE; // don't download firmware if controller cannot detect EERPOM
492
493 if (nvm_type == NCI_SPD_NVM_TYPE_NONE) {
494 GetNumValue(NAME_ALLOW_NO_NVM, &allow_no_nvm, sizeof(allow_no_nvm));
495 if (allow_no_nvm == 0) {
496 ALOGD("%s: No NVM detected, FAIL the init stage to force a retry",
497 __func__);
498 USERIAL_PowerupDevice(0);
499 stat = HAL_NfcReInit();
500 return;
501 }
502
503 p_nfc_hal_cfg->nfc_hal_prm_nvm_required =
504 FALSE; // allow download firmware if controller cannot detect EERPOM
505 }
506
507 /* Start downloading the patch files */
508 StartPatchDownload(brcm_hw_id);
509
510 if (GetNumValue(MAX_RF_DATA_CREDITS, &max_credits, sizeof(max_credits)) &&
511 (max_credits > 0)) {
512 ALOGD("%s : max_credits=%d", __func__, max_credits);
513 HAL_NfcSetMaxRfDataCredits(max_credits);
514 }
515 }
516
517 /*******************************************************************************
518 **
519 ** Function: mayDisableSecureElement
520 **
521 ** Description: Optionally adjust a TLV to disable secure element. This
522 *feature
523 ** is enabled by setting the system property
524 ** nfc.disable_secure_element to a bit mask represented by a
525 *hex
526 ** octet: C0 = do not detect any secure element.
527 ** 40 = do not detect secure element in slot 0.
528 ** 80 = do not detect secure element in slot 1.
529 **
530 ** config: a sequence of TLV's.
531 **
532 *******************************************************************************/
mayDisableSecureElement(StartupConfig & config)533 void mayDisableSecureElement(StartupConfig& config) {
534 unsigned int bitmask = 0;
535 char valueStr[PROPERTY_VALUE_MAX] = {0};
536 int len = property_get("nfc.disable_secure_element", valueStr, "");
537 if (len > 0) {
538 sscanf(valueStr, "%x", &bitmask); // read system property as a hex octet
539 ALOGD("%s: disable 0x%02X", __func__, (uint8_t)bitmask);
540 config.disableSecureElement((uint8_t)(bitmask & 0xC0));
541 }
542 }
543
544 /*******************************************************************************
545 **
546 ** Function: configureCrystalFrequency
547 **
548 ** Description: Configure controller's crystal frequency by reading values from
549 ** .conf file. If .conf file does not define any value, then use
550 ** default values defined in struct nfc_post_reset_cb.
551 **
552 ** Returns: none
553 **
554 *******************************************************************************/
configureCrystalFrequency()555 void configureCrystalFrequency() {
556 unsigned long num = 0;
557 uint32_t hwId = 0;
558 uint16_t xtalFreq = 0;
559 uint8_t xtalIndex = 0;
560 int actualLen = 0;
561
562 if (GetNumValue(NAME_XTAL_HARDWARE_ID, &num, sizeof(num))) hwId = num;
563
564 if (GetNumValue(NAME_XTAL_FREQUENCY, &num, sizeof(num)))
565 xtalFreq = (uint16_t)num;
566
567 if (GetNumValue(NAME_XTAL_FREQ_INDEX, &num, sizeof(num)))
568 xtalIndex = (uint8_t)num;
569
570 actualLen =
571 GetStrValue(NAME_XTAL_PARAMS_CFG, (char*)sConfig, sizeof(sConfig));
572 if (actualLen &&
573 (xtalIndex ==
574 NFC_HAL_XTAL_INDEX_SPECIAL)) // whether to use custom crystal frequency
575 {
576 sXtalCustomParam.append(sConfig, actualLen);
577 p_nfc_hal_dm_xtal_params_cfg =
578 const_cast<uint8_t*>(sXtalCustomParam.getInternalBuffer());
579 }
580
581 if ((hwId == 0) && (xtalFreq == 0) && (xtalIndex == 0)) return;
582
583 ALOGD("%s: hwId=0x%lX; freq=%u; index=%u", __func__, hwId, xtalFreq,
584 xtalIndex);
585 nfc_post_reset_cb.dev_init_config.xtal_cfg[0].brcm_hw_id =
586 (hwId & BRCM_NFC_GEN_MASK);
587 nfc_post_reset_cb.dev_init_config.xtal_cfg[0].xtal_freq = xtalFreq;
588 nfc_post_reset_cb.dev_init_config.xtal_cfg[0].xtal_index = xtalIndex;
589 nfc_post_reset_cb.dev_init_config.num_xtal_cfg = 1;
590 }
591