nfc_hal_dm.c revision e9629bad30a9f478b336ab46b8e6e02f7f87af46
1/****************************************************************************** 2 * 3 * Copyright (C) 2012-2014 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 20/****************************************************************************** 21 * 22 * Vendor-specific handler for DM events 23 * 24 ******************************************************************************/ 25#include <string.h> 26#include "nfc_hal_int.h" 27#include "nfc_hal_post_reset.h" 28#include "userial.h" 29#include "upio.h" 30 31/***************************************************************************** 32** Constants and types 33*****************************************************************************/ 34 35#define NFC_HAL_I93_RW_CFG_LEN (5) 36#define NFC_HAL_I93_RW_CFG_PARAM_LEN (3) 37#define NFC_HAL_I93_AFI (0) 38#define NFC_HAL_I93_ENABLE_SMART_POLL (1) 39 40static UINT8 nfc_hal_dm_i93_rw_cfg[NFC_HAL_I93_RW_CFG_LEN] = 41{ 42 NCI_PARAM_ID_I93_DATARATE, 43 NFC_HAL_I93_RW_CFG_PARAM_LEN, 44 NFC_HAL_I93_FLAG_DATA_RATE, /* Bit0:Sub carrier, Bit1:Data rate, Bit4:Enable/Disable AFI */ 45 NFC_HAL_I93_AFI, /* AFI if Bit 4 is set in the flag byte */ 46 NFC_HAL_I93_ENABLE_SMART_POLL /* Bit0:Enable/Disable smart poll */ 47}; 48 49static UINT8 nfc_hal_dm_set_fw_fsm_cmd[NCI_MSG_HDR_SIZE + 1] = 50{ 51 NCI_MTS_CMD|NCI_GID_PROP, 52 NCI_MSG_SET_FWFSM, 53 0x01, 54 0x00, 55}; 56#define NCI_SET_FWFSM_OFFSET_ENABLE 3 57 58#define NCI_PROP_PARAM_SIZE_XTAL_INDEX 3 /* length of parameters in XTAL_INDEX CMD */ 59 60const UINT8 nfc_hal_dm_get_build_info_cmd[NCI_MSG_HDR_SIZE] = 61{ 62 NCI_MTS_CMD|NCI_GID_PROP, 63 NCI_MSG_GET_BUILD_INFO, 64 0x00 65}; 66#define NCI_BUILD_INFO_OFFSET_HWID 25 /* HW ID offset in build info RSP */ 67 68const UINT8 nfc_hal_dm_get_patch_version_cmd [NCI_MSG_HDR_SIZE] = 69{ 70 NCI_MTS_CMD|NCI_GID_PROP, 71 NCI_MSG_GET_PATCH_VERSION, 72 0x00 73}; 74#define NCI_PATCH_INFO_VERSION_LEN 16 /* Length of patch version string in PATCH_INFO */ 75 76/* Version string for BCM20791B3 */ 77const UINT8 NFC_HAL_DM_BCM20791B3_STR[] = "20791B3"; 78#define NFC_HAL_DM_BCM20791B3_STR_LEN (sizeof (NFC_HAL_DM_BCM20791B3_STR)-1) 79 80/* Version string for BCM20791B4 */ 81const UINT8 NFC_HAL_DM_BCM20791B4_STR[] = "20791B4"; 82#define NFC_HAL_DM_BCM20791B4_STR_LEN (sizeof (NFC_HAL_DM_BCM20791B4_STR)-1) 83 84/* Version string for BCM43341B0 */ 85const UINT8 NFC_HAL_DM_BCM43341B0_STR[] = "43341B0"; 86#define NFC_HAL_DM_BCM43341B0_STR_LEN (sizeof (NFC_HAL_DM_BCM43341B0_STR)-1) 87 88/***************************************************************************** 89** Extern function prototypes 90*****************************************************************************/ 91extern UINT8 *p_nfc_hal_dm_lptd_cfg; 92extern UINT8 *p_nfc_hal_dm_pll_325_cfg; 93extern UINT8 *p_nfc_hal_dm_start_up_cfg; 94extern UINT8 *p_nfc_hal_dm_start_up_vsc_cfg; 95extern tNFC_HAL_CFG *p_nfc_hal_cfg; 96 97/***************************************************************************** 98** Local function prototypes 99*****************************************************************************/ 100 101/******************************************************************************* 102** 103** Function nfc_hal_dm_set_config 104** 105** Description Send NCI config items to NFCC 106** 107** Returns tHAL_NFC_STATUS 108** 109*******************************************************************************/ 110tHAL_NFC_STATUS nfc_hal_dm_set_config (UINT8 tlv_size, 111 UINT8 *p_param_tlvs, 112 tNFC_HAL_NCI_CBACK *p_cback) 113{ 114 UINT8 *p_buff, *p; 115 UINT8 num_param = 0, param_len, rem_len, *p_tlv; 116 UINT16 cmd_len = NCI_MSG_HDR_SIZE + tlv_size + 1; 117 tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED; 118 119 if ((tlv_size == 0)||(p_param_tlvs == NULL)) 120 { 121 return status; 122 } 123 124 if ((p_buff = (UINT8 *) GKI_getbuf ((UINT16)(NCI_MSG_HDR_SIZE + tlv_size))) != NULL) 125 { 126 p = p_buff; 127 128 NCI_MSG_BLD_HDR0 (p, NCI_MT_CMD, NCI_GID_CORE); 129 NCI_MSG_BLD_HDR1 (p, NCI_MSG_CORE_SET_CONFIG); 130 UINT8_TO_STREAM (p, (UINT8) (tlv_size + 1)); 131 132 rem_len = tlv_size; 133 p_tlv = p_param_tlvs; 134 while (rem_len > 1) 135 { 136 num_param++; /* number of params */ 137 138 p_tlv ++; /* param type */ 139 param_len = *p_tlv++; /* param length */ 140 141 rem_len -= 2; /* param type and length */ 142 if (rem_len >= param_len) 143 { 144 rem_len -= param_len; 145 p_tlv += param_len; /* next param_type */ 146 147 if (rem_len == 0) 148 { 149 status = HAL_NFC_STATUS_OK; 150 break; 151 } 152 } 153 else 154 { 155 /* error found */ 156 break; 157 } 158 } 159 160 if (status == HAL_NFC_STATUS_OK) 161 { 162 UINT8_TO_STREAM (p, num_param); 163 ARRAY_TO_STREAM (p, p_param_tlvs, tlv_size); 164 165 nfc_hal_dm_send_nci_cmd (p_buff, cmd_len, p_cback); 166 } 167 else 168 { 169 HAL_TRACE_ERROR0 ("nfc_hal_dm_set_config ():Bad TLV"); 170 } 171 172 GKI_freebuf (p_buff); 173 } 174 175 return status; 176} 177 178/******************************************************************************* 179** 180** Function nfc_hal_dm_set_fw_fsm 181** 182** Description Enable or disable FW FSM 183** 184** Returns void 185** 186*******************************************************************************/ 187void nfc_hal_dm_set_fw_fsm (BOOLEAN enable, tNFC_HAL_NCI_CBACK *p_cback) 188{ 189 if (enable) 190 nfc_hal_dm_set_fw_fsm_cmd[NCI_SET_FWFSM_OFFSET_ENABLE] = 0x01; /* Enable, default is disabled */ 191 else 192 nfc_hal_dm_set_fw_fsm_cmd[NCI_SET_FWFSM_OFFSET_ENABLE] = 0x00; /* Disable */ 193 194 nfc_hal_dm_send_nci_cmd (nfc_hal_dm_set_fw_fsm_cmd, NCI_MSG_HDR_SIZE + 1, p_cback); 195} 196 197/******************************************************************************* 198** 199** Function nfc_hal_dm_config_nfcc_cback 200** 201** Description Callback for NCI vendor specific command complete 202** 203** Returns void 204** 205*******************************************************************************/ 206void nfc_hal_dm_config_nfcc_cback (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data) 207{ 208 if (nfc_hal_cb.dev_cb.next_dm_config == NFC_HAL_DM_CONFIG_NONE) 209 { 210 nfc_hal_hci_enable (); 211 } 212 else 213 { 214 nfc_hal_dm_config_nfcc (); 215 } 216} 217 218/******************************************************************************* 219** 220** Function nfc_hal_dm_send_startup_vsc 221** 222** Description Send VS command before NFA start-up 223** 224** Returns None 225** 226*******************************************************************************/ 227void nfc_hal_dm_send_startup_vsc (void) 228{ 229 UINT8 *p, *p_end; 230 UINT16 len; 231 232 HAL_TRACE_DEBUG0 ("nfc_hal_dm_send_startup_vsc ()"); 233 234 /* VSC must have NCI header at least */ 235 if (nfc_hal_cb.dev_cb.next_startup_vsc + NCI_MSG_HDR_SIZE - 1 <= *p_nfc_hal_dm_start_up_vsc_cfg) 236 { 237 p = p_nfc_hal_dm_start_up_vsc_cfg + nfc_hal_cb.dev_cb.next_startup_vsc; 238 len = *(p + 2); 239 p_end = p + NCI_MSG_HDR_SIZE - 1 + len; 240 241 if (p_end <= p_nfc_hal_dm_start_up_vsc_cfg + *p_nfc_hal_dm_start_up_vsc_cfg) 242 { 243 /* move to next VSC */ 244 nfc_hal_cb.dev_cb.next_startup_vsc += NCI_MSG_HDR_SIZE + len; 245 246 /* if this is last VSC */ 247 if (p_end == p_nfc_hal_dm_start_up_vsc_cfg + *p_nfc_hal_dm_start_up_vsc_cfg) 248 nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_NONE; 249 250 nfc_hal_dm_send_nci_cmd (p, (UINT16)(NCI_MSG_HDR_SIZE + len), nfc_hal_dm_config_nfcc_cback); 251 return; 252 } 253 } 254 255 HAL_TRACE_ERROR0 ("nfc_hal_dm_send_startup_vsc (): Bad start-up VSC"); 256 257 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE); 258 nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED); 259} 260 261/******************************************************************************* 262** 263** Function nfc_hal_dm_config_nfcc 264** 265** Description Send VS config before NFA start-up 266** 267** Returns void 268** 269*******************************************************************************/ 270void nfc_hal_dm_config_nfcc (void) 271{ 272 HAL_TRACE_DEBUG1 ("nfc_hal_dm_config_nfcc (): next_dm_config = %d", nfc_hal_cb.dev_cb.next_dm_config); 273 274 if ((p_nfc_hal_dm_lptd_cfg[0]) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_LPTD)) 275 { 276 nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_PLL_325; 277 278 if (nfc_hal_dm_set_config (p_nfc_hal_dm_lptd_cfg[0], 279 &p_nfc_hal_dm_lptd_cfg[1], 280 nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK) 281 { 282 return; 283 } 284 else 285 { 286 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE); 287 nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED); 288 return; 289 } 290 } 291 292 if ((p_nfc_hal_dm_pll_325_cfg) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_PLL_325)) 293 { 294 nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_START_UP; 295 296 if (nfc_hal_dm_set_config (NFC_HAL_PLL_325_SETCONFIG_PARAM_LEN, 297 p_nfc_hal_dm_pll_325_cfg, 298 nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK) 299 { 300 return; 301 } 302 else 303 { 304 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE); 305 nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED); 306 return; 307 } 308 } 309 310 if ((p_nfc_hal_dm_start_up_cfg[0]) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_START_UP)) 311 { 312 nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_I93_DATA_RATE; 313 if (nfc_hal_dm_set_config (p_nfc_hal_dm_start_up_cfg[0], 314 &p_nfc_hal_dm_start_up_cfg[1], 315 nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK) 316 { 317 return; 318 } 319 else 320 { 321 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE); 322 nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED); 323 return; 324 } 325 } 326 327#if (NFC_HAL_I93_FLAG_DATA_RATE == NFC_HAL_I93_FLAG_DATA_RATE_HIGH) 328 if (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_I93_DATA_RATE) 329 { 330 nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_FW_FSM; 331 if (nfc_hal_dm_set_config (NFC_HAL_I93_RW_CFG_LEN, 332 nfc_hal_dm_i93_rw_cfg, 333 nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK) 334 { 335 return; 336 } 337 else 338 { 339 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE); 340 nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED); 341 return; 342 } 343 } 344#endif 345 346 /* FW FSM is disabled as default in NFCC */ 347 if (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_FW_FSM) 348 { 349 nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_START_UP_VSC; 350 nfc_hal_dm_set_fw_fsm (NFC_HAL_DM_MULTI_TECH_RESP, nfc_hal_dm_config_nfcc_cback); 351 return; 352 } 353 354 if (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_START_UP_VSC) 355 { 356 if (p_nfc_hal_dm_start_up_vsc_cfg && *p_nfc_hal_dm_start_up_vsc_cfg) 357 { 358 nfc_hal_dm_send_startup_vsc (); 359 return; 360 } 361 } 362 363 /* nothing to config */ 364 nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_NONE; 365 nfc_hal_dm_config_nfcc_cback (0, 0, NULL); 366} 367 368/******************************************************************************* 369** 370** Function: nfc_hal_dm_get_xtal_index 371** 372** Description: Return Xtal index and frequency 373** 374** Returns: tNFC_HAL_XTAL_INDEX 375** 376*******************************************************************************/ 377tNFC_HAL_XTAL_INDEX nfc_hal_dm_get_xtal_index (UINT32 brcm_hw_id, UINT16 *p_xtal_freq) 378{ 379 UINT8 xx; 380 381 HAL_TRACE_DEBUG1("nfc_hal_dm_get_xtal_index() brcm_hw_id:0x%x", brcm_hw_id); 382 383 for (xx = 0; xx < nfc_post_reset_cb.dev_init_config.num_xtal_cfg; xx++) 384 { 385 if ((brcm_hw_id & BRCM_NFC_GEN_MASK) 386 == nfc_post_reset_cb.dev_init_config.xtal_cfg[xx].brcm_hw_id) 387 { 388 *p_xtal_freq = nfc_post_reset_cb.dev_init_config.xtal_cfg[xx].xtal_freq; 389 return (nfc_post_reset_cb.dev_init_config.xtal_cfg[xx].xtal_index); 390 } 391 } 392 393 /* if not found */ 394 *p_xtal_freq = 0; 395 return (NFC_HAL_XTAL_INDEX_MAX); 396} 397 398/******************************************************************************* 399** 400** Function nfc_hal_dm_set_xtal_freq_index 401** 402** Description Set crystal frequency index 403** 404** Returns void 405** 406*******************************************************************************/ 407void nfc_hal_dm_set_xtal_freq_index (void) 408{ 409 UINT8 nci_brcm_xtal_index_cmd[NCI_MSG_HDR_SIZE + NCI_PROP_PARAM_SIZE_XTAL_INDEX]; 410 UINT8 *p; 411 tNFC_HAL_XTAL_INDEX xtal_index; 412 UINT16 xtal_freq; 413 414 HAL_TRACE_DEBUG1 ("nfc_hal_dm_set_xtal_freq_index (): brcm_hw_id = 0x%x", nfc_hal_cb.dev_cb.brcm_hw_id); 415 416 xtal_index = nfc_hal_dm_get_xtal_index (nfc_hal_cb.dev_cb.brcm_hw_id, &xtal_freq); 417 418 p = nci_brcm_xtal_index_cmd; 419 UINT8_TO_STREAM (p, (NCI_MTS_CMD|NCI_GID_PROP)); 420 UINT8_TO_STREAM (p, NCI_MSG_GET_XTAL_INDEX_FROM_DH); 421 UINT8_TO_STREAM (p, NCI_PROP_PARAM_SIZE_XTAL_INDEX); 422 UINT8_TO_STREAM (p, xtal_index); 423 UINT16_TO_STREAM (p, xtal_freq); 424 425 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_XTAL_SET); 426 427 nfc_hal_dm_send_nci_cmd (nci_brcm_xtal_index_cmd, NCI_MSG_HDR_SIZE + NCI_PROP_PARAM_SIZE_XTAL_INDEX, NULL); 428} 429 430/******************************************************************************* 431** 432** Function nfc_hal_dm_send_get_build_info_cmd 433** 434** Description Send NCI_MSG_GET_BUILD_INFO CMD 435** 436** Returns void 437** 438*******************************************************************************/ 439void nfc_hal_dm_send_get_build_info_cmd (void) 440{ 441 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_BUILD_INFO); 442 443 /* get build information to find out HW */ 444 nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_build_info_cmd, NCI_MSG_HDR_SIZE, NULL); 445} 446/******************************************************************************* 447** 448** Function: nfc_hal_dm_adjust_hw_id 449** 450** Description: The hw_id of certain chips are shifted by 8 bits. 451** Adjust the hw_id before processing. 452** 453** Returns: Nothing 454** 455*******************************************************************************/ 456static UINT32 nfc_hal_dm_adjust_hw_id (UINT32 hw_id) 457{ 458 if ((hw_id & 0xF0000000) == 0) 459 hw_id <<= 4; /* shift hw_id by 4 bits to align w the format of most chips */ 460 return hw_id; 461} 462 463/******************************************************************************* 464** 465** Function nfc_hal_dm_proc_msg_during_init 466** 467** Description Process NCI message while initializing NFCC 468** 469** Returns void 470** 471*******************************************************************************/ 472void nfc_hal_dm_proc_msg_during_init (NFC_HDR *p_msg) 473{ 474 UINT8 *p; 475 UINT8 reset_reason, reset_type; 476 UINT8 mt, pbf, gid, op_code; 477 UINT8 *p_old, old_gid, old_oid, old_mt; 478 UINT8 u8; 479 tNFC_HAL_NCI_CBACK *p_cback = NULL; 480 UINT8 chipverlen; 481 UINT8 chipverstr[NCI_SPD_HEADER_CHIPVER_LEN]; 482 UINT16 xtal_freq; 483 UINT32 hw_id = 0; 484 485 HAL_TRACE_DEBUG1 ("nfc_hal_dm_proc_msg_during_init(): init state:%d", nfc_hal_cb.dev_cb.initializing_state); 486 487 p = (UINT8 *) (p_msg + 1) + p_msg->offset; 488 489 NCI_MSG_PRS_HDR0 (p, mt, pbf, gid); 490 NCI_MSG_PRS_HDR1 (p, op_code); 491 492 /* check if waiting for this response */ 493 if ( (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_CMD) 494 ||(nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_VSC) ) 495 { 496 if (mt == NCI_MT_RSP) 497 { 498 p_old = nfc_hal_cb.ncit_cb.last_hdr; 499 NCI_MSG_PRS_HDR0 (p_old, old_mt, pbf, old_gid); 500 old_oid = ((*p_old) & NCI_OID_MASK); 501 /* make sure this is the RSP we are waiting for before updating the command window */ 502 if ((old_gid == gid) && (old_oid == op_code)) 503 { 504 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE; 505 p_cback = (tNFC_HAL_NCI_CBACK *)nfc_hal_cb.ncit_cb.p_vsc_cback; 506 nfc_hal_cb.ncit_cb.p_vsc_cback = NULL; 507 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer); 508 } 509 } 510 } 511 512 if (gid == NCI_GID_CORE) 513 { 514 if (op_code == NCI_MSG_CORE_RESET) 515 { 516 if (mt == NCI_MT_NTF) 517 { 518 if ( (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_NFCC_ENABLE) 519 ||(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_POST_XTAL_SET) ) 520 { 521 /* 522 ** Core reset ntf in the following cases; 523 ** 1) after power up (raising REG_PU) 524 ** 2) after setting xtal index 525 ** Start pre-initializing NFCC 526 */ 527 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.timer); 528 nfc_hal_dm_pre_init_nfcc (); 529 } 530 else 531 { 532 /* Core reset ntf after post-patch download, Call reset notification callback */ 533 p++; /* Skip over param len */ 534 STREAM_TO_UINT8 (reset_reason, p); 535 STREAM_TO_UINT8 (reset_type, p); 536 nfc_hal_prm_spd_reset_ntf (reset_reason, reset_type); 537 } 538 } 539 } 540 else if (p_cback) 541 { 542 (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code), 543 p_msg->len, 544 (UINT8 *) (p_msg + 1) + p_msg->offset); 545 } 546 } 547 else if (gid == NCI_GID_PROP) /* this is for download patch */ 548 { 549 if (mt == NCI_MT_NTF) 550 op_code |= NCI_NTF_BIT; 551 else 552 op_code |= NCI_RSP_BIT; 553 554 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_XTAL_SET) 555 { 556 if (op_code == (NCI_RSP_BIT|NCI_MSG_GET_XTAL_INDEX_FROM_DH)) 557 { 558 /* start timer in case that NFCC doesn't send RESET NTF after loading patch from NVM */ 559 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_POST_XTAL_SET); 560 561 nfc_hal_main_start_quick_timer (&nfc_hal_cb.timer, NFC_HAL_TTYPE_NFCC_ENABLE, 562 ((p_nfc_hal_cfg->nfc_hal_post_xtal_timeout)*QUICK_TIMER_TICKS_PER_SEC)/1000); 563 } 564 } 565 else if ( (op_code == NFC_VS_GET_BUILD_INFO_EVT) 566 &&(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_BUILD_INFO) ) 567 { 568 p += NCI_BUILD_INFO_OFFSET_HWID; 569 570 STREAM_TO_UINT32 (hw_id, p); 571 nfc_hal_cb.dev_cb.brcm_hw_id = nfc_hal_dm_adjust_hw_id (hw_id); 572 HAL_TRACE_DEBUG2 ("brcm_hw_id: 0x%x -> 0x%x", hw_id, nfc_hal_cb.dev_cb.brcm_hw_id); 573 574 STREAM_TO_UINT8 (chipverlen, p); 575 memset (chipverstr, 0, NCI_SPD_HEADER_CHIPVER_LEN); 576 577 STREAM_TO_ARRAY (chipverstr, p, chipverlen); 578 579 if ((chipverlen == NFC_HAL_DM_BCM20791B3_STR_LEN) && (memcmp (NFC_HAL_DM_BCM20791B3_STR, chipverstr, NFC_HAL_DM_BCM20791B3_STR_LEN) == 0)) 580 { 581 /* BCM2079B3 FW - eSE restarted for patch download */ 582 nfc_hal_cb.hci_cb.hci_fw_workaround = TRUE; 583 nfc_hal_cb.hci_cb.hci_fw_validate_netwk_cmd = TRUE; 584 } 585 else if ( ((chipverlen == NFC_HAL_DM_BCM20791B4_STR_LEN) && (memcmp (NFC_HAL_DM_BCM20791B4_STR, chipverstr, NFC_HAL_DM_BCM20791B4_STR_LEN) == 0)) 586 ||((chipverlen == NFC_HAL_DM_BCM43341B0_STR_LEN) && (memcmp (NFC_HAL_DM_BCM43341B0_STR, chipverstr, NFC_HAL_DM_BCM43341B0_STR_LEN) == 0)) ) 587 { 588 /* BCM43341B0/BCM2079B4 FW - eSE restarted for patch download */ 589 nfc_hal_cb.hci_cb.hci_fw_workaround = TRUE; 590 nfc_hal_cb.hci_cb.hci_fw_validate_netwk_cmd = FALSE; 591 } 592 else 593 { 594 /* BCM2079B5 FW - eSE not be restarted for patch download from UICC */ 595 nfc_hal_cb.hci_cb.hci_fw_workaround = FALSE; 596 nfc_hal_cb.hci_cb.hci_fw_validate_netwk_cmd = FALSE; 597 } 598 599 /* if NFCC needs to set Xtal frequency before getting patch version */ 600 if (nfc_hal_dm_get_xtal_index (nfc_hal_cb.dev_cb.brcm_hw_id, &xtal_freq) < NFC_HAL_XTAL_INDEX_MAX) 601 { 602 { 603 /* set Xtal index before getting patch version */ 604 nfc_hal_dm_set_xtal_freq_index (); 605 return; 606 } 607 } 608 609 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_PATCH_INFO); 610 611 nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, NULL); 612 } 613 else if ( (op_code == NFC_VS_GET_PATCH_VERSION_EVT) 614 &&(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_PATCH_INFO) ) 615 { 616 /* Store NVM info to control block */ 617 618 /* Skip over rsp len */ 619 p++; 620 621 /* Get project id */ 622 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.project_id, p); 623 624 /* RFU */ 625 p++; 626 627 /* Get chip version string */ 628 STREAM_TO_UINT8 (u8, p); 629 if (u8 > NFC_HAL_PRM_MAX_CHIP_VER_LEN) 630 u8 = NFC_HAL_PRM_MAX_CHIP_VER_LEN; 631 memcpy (nfc_hal_cb.nvm_cb.chip_ver, p, u8); 632 p += NCI_PATCH_INFO_VERSION_LEN; 633 634 /* Get major/minor version */ 635 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.ver_major, p); 636 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.ver_minor, p); 637 638 /* Skip over max_size and patch_max_size */ 639 p += 4; 640 641 /* Get current lpm patch size */ 642 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.lpm_size, p); 643 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.fpm_size, p); 644 645 /* clear all flags which may be set during previous initialization */ 646 nfc_hal_cb.nvm_cb.flags = 0; 647 648 /* Set patch present flag */ 649 if ((nfc_hal_cb.nvm_cb.fpm_size) || (nfc_hal_cb.nvm_cb.lpm_size)) 650 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_PATCH_PRESENT; 651 652 /* LPMPatchCodeHasBadCRC (if not bad crc, then indicate LPM patch is present in nvm) */ 653 STREAM_TO_UINT8 (u8, p); 654 if (u8) 655 { 656 /* LPM patch in NVM fails CRC check */ 657 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_LPM_BAD; 658 } 659 660 661 /* FPMPatchCodeHasBadCRC (if not bad crc, then indicate LPM patch is present in nvm) */ 662 STREAM_TO_UINT8 (u8, p); 663 if (u8) 664 { 665 /* FPM patch in NVM fails CRC check */ 666 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_FPM_BAD; 667 } 668 669 /* Check if downloading patch to RAM only (no NVM) */ 670 STREAM_TO_UINT8 (nfc_hal_cb.nvm_cb.nvm_type, p); 671 if (nfc_hal_cb.nvm_cb.nvm_type == NCI_SPD_NVM_TYPE_NONE) 672 { 673 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_NO_NVM; 674 } 675 676 /* let platform update baudrate or download patch */ 677 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_APP_COMPLETE); 678 nfc_hal_post_reset_init (nfc_hal_cb.dev_cb.brcm_hw_id, nfc_hal_cb.nvm_cb.nvm_type); 679 } 680 else if (p_cback) 681 { 682 (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code), 683 p_msg->len, 684 (UINT8 *) (p_msg + 1) + p_msg->offset); 685 } 686 else if (op_code == NFC_VS_SEC_PATCH_AUTH_EVT) 687 { 688 HAL_TRACE_DEBUG0 ("signature!!"); 689 nfc_hal_prm_nci_command_complete_cback ((tNFC_HAL_NCI_EVT) (op_code), 690 p_msg->len, 691 (UINT8 *) (p_msg + 1) + p_msg->offset); 692 } 693 } 694} 695 696/******************************************************************************* 697** 698** Function nfc_hal_dm_send_nci_cmd 699** 700** Description Send NCI command to NFCC while initializing BRCM NFCC 701** 702** Returns void 703** 704*******************************************************************************/ 705void nfc_hal_dm_send_nci_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_NCI_CBACK *p_cback) 706{ 707 NFC_HDR *p_buf; 708 UINT8 *ps; 709 710 HAL_TRACE_DEBUG1 ("nfc_hal_dm_send_nci_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp); 711 712 if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE) 713 { 714 HAL_TRACE_ERROR0 ("nfc_hal_dm_send_nci_cmd(): no command window"); 715 return; 716 } 717 718 if ((p_buf = (NFC_HDR *)GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL) 719 { 720 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_VSC; 721 722 p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE; 723 p_buf->event = NFC_HAL_EVT_TO_NFC_NCI; 724 p_buf->len = len; 725 726 memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len); 727 728 /* Keep a copy of the command and send to NCI transport */ 729 730 /* save the message header to double check the response */ 731 ps = (UINT8 *)(p_buf + 1) + p_buf->offset; 732 memcpy(nfc_hal_cb.ncit_cb.last_hdr, ps, NFC_HAL_SAVED_HDR_SIZE); 733 memcpy(nfc_hal_cb.ncit_cb.last_cmd, ps + NCI_MSG_HDR_SIZE, NFC_HAL_SAVED_CMD_SIZE); 734 735 /* save the callback for NCI VSCs */ 736 nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback; 737 738 nfc_hal_nci_send_cmd (p_buf); 739 740 /* start NFC command-timeout timer */ 741 nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP), 742 ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 743 } 744} 745 746/******************************************************************************* 747** 748** Function nfc_hal_dm_send_pend_cmd 749** 750** Description Send a command to NFCC 751** 752** Returns void 753** 754*******************************************************************************/ 755void nfc_hal_dm_send_pend_cmd (void) 756{ 757 NFC_HDR *p_buf = nfc_hal_cb.ncit_cb.p_pend_cmd; 758 UINT8 *p; 759 760 if (p_buf == NULL) 761 return; 762 763 /* check low power mode state */ 764 if (!nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TX_DATA_EVT)) 765 { 766 return; 767 } 768 769 if (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_PROP) 770 { 771#if (NFC_HAL_TRACE_PROTOCOL == TRUE) 772 DispHciCmd (p_buf); 773#endif 774 775 /* save the message header to double check the response */ 776 p = (UINT8 *)(p_buf + 1) + p_buf->offset; 777 memcpy(nfc_hal_cb.ncit_cb.last_hdr, p, NFC_HAL_SAVED_HDR_SIZE); 778 779 /* add packet type for BT message */ 780 p_buf->offset--; 781 p_buf->len++; 782 783 p = (UINT8 *) (p_buf + 1) + p_buf->offset; 784 *p = HCIT_TYPE_COMMAND; 785 786 USERIAL_Write (USERIAL_NFC_PORT, p, p_buf->len); 787 788 GKI_freebuf (p_buf); 789 nfc_hal_cb.ncit_cb.p_pend_cmd = NULL; 790 791 /* start NFC command-timeout timer */ 792 nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP), 793 ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 794 795 } 796} 797 798/******************************************************************************* 799** 800** Function nfc_hal_dm_send_bt_cmd 801** 802** Description Send BT message to NFCC while initializing BRCM NFCC 803** 804** Returns void 805** 806*******************************************************************************/ 807void nfc_hal_dm_send_bt_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_BTVSC_CPLT_CBACK *p_cback) 808{ 809 NFC_HDR *p_buf; 810 811 HAL_TRACE_DEBUG1 ("nfc_hal_dm_send_bt_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp); 812 813 if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE) 814 { 815 HAL_TRACE_ERROR0 ("nfc_hal_dm_send_bt_cmd(): no command window"); 816 return; 817 } 818 819 if ((p_buf = (NFC_HDR *) GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL) 820 { 821 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_PROP; 822 823 p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE; 824 p_buf->len = len; 825 826 memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len); 827 828 /* save the callback for NCI VSCs) */ 829 nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback; 830 831 nfc_hal_cb.ncit_cb.p_pend_cmd = p_buf; 832 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_IDLE) 833 { 834 NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_W4_CONTROL_DONE); 835 nfc_hal_cb.p_stack_cback (HAL_NFC_REQUEST_CONTROL_EVT, HAL_NFC_STATUS_OK); 836 return; 837 } 838 839 nfc_hal_dm_send_pend_cmd(); 840 } 841} 842 843/******************************************************************************* 844** 845** Function nfc_hal_dm_set_nfc_wake 846** 847** Description Set NFC_WAKE line 848** 849** Returns void 850** 851*******************************************************************************/ 852void nfc_hal_dm_set_nfc_wake (UINT8 cmd) 853{ 854 HAL_TRACE_DEBUG1 ("nfc_hal_dm_set_nfc_wake () %s", 855 (cmd == NFC_HAL_ASSERT_NFC_WAKE ? "ASSERT" : "DEASSERT")); 856 857 /* 858 ** nfc_wake_active_mode cmd result of voltage on NFC_WAKE 859 ** 860 ** NFC_HAL_LP_ACTIVE_LOW (0) NFC_HAL_ASSERT_NFC_WAKE (0) pull down NFC_WAKE (GND) 861 ** NFC_HAL_LP_ACTIVE_LOW (0) NFC_HAL_DEASSERT_NFC_WAKE (1) pull up NFC_WAKE (VCC) 862 ** NFC_HAL_LP_ACTIVE_HIGH (1) NFC_HAL_ASSERT_NFC_WAKE (0) pull up NFC_WAKE (VCC) 863 ** NFC_HAL_LP_ACTIVE_HIGH (1) NFC_HAL_DEASSERT_NFC_WAKE (1) pull down NFC_WAKE (GND) 864 */ 865 866 if (cmd == nfc_hal_cb.dev_cb.nfc_wake_active_mode) 867 UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_OFF); /* pull down NFC_WAKE */ 868 else 869 UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_ON); /* pull up NFC_WAKE */ 870} 871 872/******************************************************************************* 873** 874** Function nfc_hal_dm_power_mode_execute 875** 876** Description If snooze mode is enabled in full power mode, 877** Assert NFC_WAKE before sending data 878** Deassert NFC_WAKE when idle timer expires 879** 880** Returns TRUE if DH can send data to NFCC 881** 882*******************************************************************************/ 883BOOLEAN nfc_hal_dm_power_mode_execute (tNFC_HAL_LP_EVT event) 884{ 885 BOOLEAN send_to_nfcc = FALSE; 886 887 HAL_TRACE_DEBUG1 ("nfc_hal_dm_power_mode_execute () event = %d", event); 888 889 if (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL) 890 { 891 if (nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) 892 { 893 /* if any transport activity */ 894 if ( (event == NFC_HAL_LP_TX_DATA_EVT) 895 ||(event == NFC_HAL_LP_RX_DATA_EVT) ) 896 { 897 /* if idle timer is not running */ 898 if (nfc_hal_cb.dev_cb.lp_timer.in_use == FALSE) 899 { 900 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 901 } 902 903 /* start or extend idle timer */ 904 nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00, 905 ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 906 } 907 else if (event == NFC_HAL_LP_TIMEOUT_EVT) 908 { 909 /* let NFCC go to snooze mode */ 910 nfc_hal_dm_set_nfc_wake (NFC_HAL_DEASSERT_NFC_WAKE); 911 } 912 } 913 914 send_to_nfcc = TRUE; 915 } 916 917 return (send_to_nfcc); 918} 919 920/******************************************************************************* 921** 922** Function nci_brcm_lp_timeout_cback 923** 924** Description callback function for low power timeout 925** 926** Returns void 927** 928*******************************************************************************/ 929static void nci_brcm_lp_timeout_cback (void *p_tle) 930{ 931 HAL_TRACE_DEBUG0 ("nci_brcm_lp_timeout_cback ()"); 932 933 nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TIMEOUT_EVT); 934} 935 936/******************************************************************************* 937** 938** Function nfc_hal_dm_pre_init_nfcc 939** 940** Description This function initializes Broadcom specific control blocks for 941** NCI transport 942** 943** Returns void 944** 945*******************************************************************************/ 946void nfc_hal_dm_pre_init_nfcc (void) 947{ 948 HAL_TRACE_DEBUG0 ("nfc_hal_dm_pre_init_nfcc ()"); 949 950 /* if it was waiting for core reset notification after raising REG_PU */ 951 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_NFCC_ENABLE) 952 { 953 nfc_hal_dm_send_get_build_info_cmd (); 954 } 955 /* if it was waiting for core reset notification after setting Xtal */ 956 else if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_POST_XTAL_SET) 957 { 958 { 959 /* Core reset ntf after xtal setting indicating NFCC loaded patch from NVM */ 960 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_PATCH_INFO); 961 962 nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, NULL); 963 } 964 } 965} 966 967/******************************************************************************* 968** 969** Function nfc_hal_dm_shutting_down_nfcc 970** 971** Description This function initializes Broadcom specific control blocks for 972** NCI transport 973** 974** Returns void 975** 976*******************************************************************************/ 977void nfc_hal_dm_shutting_down_nfcc (void) 978{ 979 HAL_TRACE_DEBUG0 ("nfc_hal_dm_shutting_down_nfcc ()"); 980 981 nfc_hal_cb.dev_cb.initializing_state = NFC_HAL_INIT_STATE_CLOSING; 982 983 /* reset low power mode variables */ 984 if ( (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL) 985 &&(nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) ) 986 { 987 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 988 } 989 990 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE; 991 nfc_hal_cb.hci_cb.hcp_conn_id = 0; 992 993 nfc_hal_cb.dev_cb.power_mode = NFC_HAL_POWER_MODE_FULL; 994 nfc_hal_cb.dev_cb.snooze_mode = NFC_HAL_LP_SNOOZE_MODE_NONE; 995 996 /* Stop all timers */ 997 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer); 998 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer); 999 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.prm.timer); 1000 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.hci_cb.hci_timer); 1001 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.timer); 1002} 1003 1004/******************************************************************************* 1005** 1006** Function nfc_hal_dm_init 1007** 1008** Description This function initializes Broadcom specific control blocks for 1009** NCI transport 1010** 1011** Returns void 1012** 1013*******************************************************************************/ 1014void nfc_hal_dm_init (void) 1015{ 1016 HAL_TRACE_DEBUG0 ("nfc_hal_dm_init ()"); 1017 1018 nfc_hal_cb.dev_cb.lp_timer.p_cback = nci_brcm_lp_timeout_cback; 1019 1020 nfc_hal_cb.ncit_cb.nci_wait_rsp_timer.p_cback = nfc_hal_nci_cmd_timeout_cback; 1021 1022 nfc_hal_cb.hci_cb.hci_timer.p_cback = nfc_hal_hci_timeout_cback; 1023 1024 nfc_hal_cb.pre_discover_done = FALSE; 1025 1026 nfc_post_reset_cb.spd_nvm_detection_cur_count = 0; 1027 nfc_post_reset_cb.spd_skip_on_power_cycle = FALSE; 1028 1029} 1030 1031/******************************************************************************* 1032** 1033** Function HAL_NfcDevInitDone 1034** 1035** Description Notify that pre-initialization of NFCC is complete 1036** 1037** Returns void 1038** 1039*******************************************************************************/ 1040void HAL_NfcPreInitDone (tHAL_NFC_STATUS status) 1041{ 1042 HAL_TRACE_DEBUG1 ("HAL_NfcPreInitDone () status=%d", status); 1043 1044 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE) 1045 { 1046 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE); 1047 1048 nfc_hal_main_pre_init_done (status); 1049 } 1050} 1051 1052/******************************************************************************* 1053** 1054** Function HAL_NfcReInit 1055** 1056** Description This function is called to restart initialization after REG_PU 1057** toggled because of failure to detect NVM type or download patchram. 1058** 1059** Note This function should be called only during the HAL init process 1060** 1061** Returns HAL_NFC_STATUS_OK if successfully initiated 1062** HAL_NFC_STATUS_FAILED otherwise 1063** 1064*******************************************************************************/ 1065tHAL_NFC_STATUS HAL_NfcReInit (void) 1066{ 1067 tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED; 1068 1069 HAL_TRACE_DEBUG1 ("HAL_NfcReInit () init st=0x%x", nfc_hal_cb.dev_cb.initializing_state); 1070 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE) 1071 { 1072 { 1073 /* Wait for NFCC to enable - Core reset notification */ 1074 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_NFCC_ENABLE); 1075 1076 /* NFCC Enable timeout */ 1077 nfc_hal_main_start_quick_timer (&nfc_hal_cb.timer, NFC_HAL_TTYPE_NFCC_ENABLE, 1078 ((p_nfc_hal_cfg->nfc_hal_nfcc_enable_timeout)*QUICK_TIMER_TICKS_PER_SEC)/1000); 1079 } 1080 1081 status = HAL_NFC_STATUS_OK; 1082 } 1083 return status; 1084} 1085 1086/******************************************************************************* 1087** 1088** Function nfc_hal_dm_set_snooze_mode_cback 1089** 1090** Description This is baud rate update complete callback. 1091** 1092** Returns void 1093** 1094*******************************************************************************/ 1095static void nfc_hal_dm_set_snooze_mode_cback (tNFC_HAL_BTVSC_CPLT *pData) 1096{ 1097 UINT8 status = pData->p_param_buf[0]; 1098 tHAL_NFC_STATUS hal_status; 1099 tHAL_NFC_STATUS_CBACK *p_cback; 1100 1101 /* if it is completed */ 1102 if (status == HCI_SUCCESS) 1103 { 1104 /* update snooze mode */ 1105 nfc_hal_cb.dev_cb.snooze_mode = nfc_hal_cb.dev_cb.new_snooze_mode; 1106 1107 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 1108 1109 if ( nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) 1110 { 1111 /* start idle timer */ 1112 nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00, 1113 ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 1114 } 1115 else 1116 { 1117 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer); 1118 } 1119 hal_status = HAL_NFC_STATUS_OK; 1120 } 1121 else 1122 { 1123 hal_status = HAL_NFC_STATUS_FAILED; 1124 } 1125 1126 if (nfc_hal_cb.dev_cb.p_prop_cback) 1127 { 1128 p_cback = nfc_hal_cb.dev_cb.p_prop_cback; 1129 nfc_hal_cb.dev_cb.p_prop_cback = NULL; 1130 (*p_cback) (hal_status); 1131 } 1132} 1133 1134/******************************************************************************* 1135** 1136** Function HAL_NfcSetSnoozeMode 1137** 1138** Description Set snooze mode 1139** snooze_mode 1140** NFC_HAL_LP_SNOOZE_MODE_NONE - Snooze mode disabled 1141** NFC_HAL_LP_SNOOZE_MODE_UART - Snooze mode for UART 1142** NFC_HAL_LP_SNOOZE_MODE_SPI_I2C - Snooze mode for SPI/I2C 1143** 1144** idle_threshold_dh/idle_threshold_nfcc 1145** Idle Threshold Host in 100ms unit 1146** 1147** nfc_wake_active_mode/dh_wake_active_mode 1148** NFC_HAL_LP_ACTIVE_LOW - high to low voltage is asserting 1149** NFC_HAL_LP_ACTIVE_HIGH - low to high voltage is asserting 1150** 1151** p_snooze_cback 1152** Notify status of operation 1153** 1154** Returns tHAL_NFC_STATUS 1155** 1156*******************************************************************************/ 1157tHAL_NFC_STATUS HAL_NfcSetSnoozeMode (UINT8 snooze_mode, 1158 UINT8 idle_threshold_dh, 1159 UINT8 idle_threshold_nfcc, 1160 UINT8 nfc_wake_active_mode, 1161 UINT8 dh_wake_active_mode, 1162 tHAL_NFC_STATUS_CBACK *p_snooze_cback) 1163{ 1164 UINT8 cmd[NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH]; 1165 UINT8 *p; 1166 1167 HAL_TRACE_API1 ("HAL_NfcSetSnoozeMode (): snooze_mode = %d", snooze_mode); 1168 1169 nfc_hal_cb.dev_cb.new_snooze_mode = snooze_mode; 1170 nfc_hal_cb.dev_cb.nfc_wake_active_mode = nfc_wake_active_mode; 1171 nfc_hal_cb.dev_cb.p_prop_cback = p_snooze_cback; 1172 1173 p = cmd; 1174 1175 /* Add the HCI command */ 1176 UINT16_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE); 1177 UINT8_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH); 1178 1179 memset (p, 0x00, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH); 1180 1181 UINT8_TO_STREAM (p, snooze_mode); /* Sleep Mode */ 1182 1183 UINT8_TO_STREAM (p, idle_threshold_dh); /* Idle Threshold Host */ 1184 UINT8_TO_STREAM (p, idle_threshold_nfcc); /* Idle Threshold HC */ 1185 UINT8_TO_STREAM (p, nfc_wake_active_mode); /* BT Wake Active Mode */ 1186 UINT8_TO_STREAM (p, dh_wake_active_mode); /* Host Wake Active Mode */ 1187 1188 nfc_hal_dm_send_bt_cmd (cmd, 1189 NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH, 1190 nfc_hal_dm_set_snooze_mode_cback); 1191 return (NCI_STATUS_OK); 1192} 1193 1194 1195 1196 1197 1198 1199 1200 1201