nfc_hal_dm.c revision d05817f02d578becbf79b46f2599126404c7b413
1/****************************************************************************** 2 * 3 * Copyright (C) 2012-2013 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** 449** Function nfc_hal_dm_proc_msg_during_init 450** 451** Description Process NCI message while initializing NFCC 452** 453** Returns void 454** 455*******************************************************************************/ 456void nfc_hal_dm_proc_msg_during_init (NFC_HDR *p_msg) 457{ 458 UINT8 *p; 459 UINT8 reset_reason, reset_type; 460 UINT8 mt, pbf, gid, op_code; 461 UINT8 *p_old, old_gid, old_oid, old_mt; 462 UINT8 u8; 463 tNFC_HAL_NCI_CBACK *p_cback = NULL; 464 UINT8 chipverlen; 465 UINT8 chipverstr[NCI_SPD_HEADER_CHIPVER_LEN]; 466 UINT16 xtal_freq; 467 468 HAL_TRACE_DEBUG1 ("nfc_hal_dm_proc_msg_during_init(): init state:%d", nfc_hal_cb.dev_cb.initializing_state); 469 470 p = (UINT8 *) (p_msg + 1) + p_msg->offset; 471 472 NCI_MSG_PRS_HDR0 (p, mt, pbf, gid); 473 NCI_MSG_PRS_HDR1 (p, op_code); 474 475 /* check if waiting for this response */ 476 if ( (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_CMD) 477 ||(nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_VSC) ) 478 { 479 if (mt == NCI_MT_RSP) 480 { 481 p_old = nfc_hal_cb.ncit_cb.last_hdr; 482 NCI_MSG_PRS_HDR0 (p_old, old_mt, pbf, old_gid); 483 old_oid = ((*p_old) & NCI_OID_MASK); 484 /* make sure this is the RSP we are waiting for before updating the command window */ 485 if ((old_gid == gid) && (old_oid == op_code)) 486 { 487 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE; 488 p_cback = (tNFC_HAL_NCI_CBACK *)nfc_hal_cb.ncit_cb.p_vsc_cback; 489 nfc_hal_cb.ncit_cb.p_vsc_cback = NULL; 490 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer); 491 } 492 } 493 } 494 495 if (gid == NCI_GID_CORE) 496 { 497 if (op_code == NCI_MSG_CORE_RESET) 498 { 499 if (mt == NCI_MT_NTF) 500 { 501 if ( (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_NFCC_ENABLE) 502 ||(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_POST_XTAL_SET) ) 503 { 504 /* 505 ** Core reset ntf in the following cases; 506 ** 1) after power up (raising REG_PU) 507 ** 2) after setting xtal index 508 ** Start pre-initializing NFCC 509 */ 510 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.timer); 511 nfc_hal_dm_pre_init_nfcc (); 512 } 513 else 514 { 515 /* Core reset ntf after post-patch download, Call reset notification callback */ 516 p++; /* Skip over param len */ 517 STREAM_TO_UINT8 (reset_reason, p); 518 STREAM_TO_UINT8 (reset_type, p); 519 nfc_hal_prm_spd_reset_ntf (reset_reason, reset_type); 520 } 521 } 522 } 523 else if (p_cback) 524 { 525 (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code), 526 p_msg->len, 527 (UINT8 *) (p_msg + 1) + p_msg->offset); 528 } 529 } 530 else if (gid == NCI_GID_PROP) /* this is for download patch */ 531 { 532 if (mt == NCI_MT_NTF) 533 op_code |= NCI_NTF_BIT; 534 else 535 op_code |= NCI_RSP_BIT; 536 537 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_XTAL_SET) 538 { 539 if (op_code == (NCI_RSP_BIT|NCI_MSG_GET_XTAL_INDEX_FROM_DH)) 540 { 541 /* start timer in case that NFCC doesn't send RESET NTF after loading patch from NVM */ 542 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_POST_XTAL_SET); 543 544 nfc_hal_main_start_quick_timer (&nfc_hal_cb.timer, NFC_HAL_TTYPE_NFCC_ENABLE, 545 ((p_nfc_hal_cfg->nfc_hal_post_xtal_timeout)*QUICK_TIMER_TICKS_PER_SEC)/1000); 546 } 547 } 548 else if ( (op_code == NFC_VS_GET_BUILD_INFO_EVT) 549 &&(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_BUILD_INFO) ) 550 { 551 p += NCI_BUILD_INFO_OFFSET_HWID; 552 553 STREAM_TO_UINT32 (nfc_hal_cb.dev_cb.brcm_hw_id, p); 554 555 STREAM_TO_UINT8 (chipverlen, p); 556 memset (chipverstr, 0, NCI_SPD_HEADER_CHIPVER_LEN); 557 558 STREAM_TO_ARRAY (chipverstr, p, chipverlen); 559 560 if ((chipverlen == NFC_HAL_DM_BCM20791B3_STR_LEN) && (memcmp (NFC_HAL_DM_BCM20791B3_STR, chipverstr, NFC_HAL_DM_BCM20791B3_STR_LEN) == 0)) 561 { 562 /* BCM2079B3 FW - eSE restarted for patch download */ 563 nfc_hal_cb.hci_cb.hci_fw_workaround = TRUE; 564 nfc_hal_cb.hci_cb.hci_fw_validate_netwk_cmd = TRUE; 565 } 566 else if ( ((chipverlen == NFC_HAL_DM_BCM20791B4_STR_LEN) && (memcmp (NFC_HAL_DM_BCM20791B4_STR, chipverstr, NFC_HAL_DM_BCM20791B4_STR_LEN) == 0)) 567 ||((chipverlen == NFC_HAL_DM_BCM43341B0_STR_LEN) && (memcmp (NFC_HAL_DM_BCM43341B0_STR, chipverstr, NFC_HAL_DM_BCM43341B0_STR_LEN) == 0)) ) 568 { 569 /* BCM43341B0/BCM2079B4 FW - eSE restarted for patch download */ 570 nfc_hal_cb.hci_cb.hci_fw_workaround = TRUE; 571 nfc_hal_cb.hci_cb.hci_fw_validate_netwk_cmd = FALSE; 572 } 573 else 574 { 575 /* BCM2079B5 FW - eSE not be restarted for patch download from UICC */ 576 nfc_hal_cb.hci_cb.hci_fw_workaround = FALSE; 577 nfc_hal_cb.hci_cb.hci_fw_validate_netwk_cmd = FALSE; 578 } 579 580 /* if NFCC needs to set Xtal frequency before getting patch version */ 581 if (nfc_hal_dm_get_xtal_index (nfc_hal_cb.dev_cb.brcm_hw_id, &xtal_freq) < NFC_HAL_XTAL_INDEX_MAX) 582 { 583 { 584 /* set Xtal index before getting patch version */ 585 nfc_hal_dm_set_xtal_freq_index (); 586 return; 587 } 588 } 589 590 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_PATCH_INFO); 591 592 nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, NULL); 593 } 594 else if ( (op_code == NFC_VS_GET_PATCH_VERSION_EVT) 595 &&(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_PATCH_INFO) ) 596 { 597 /* Store NVM info to control block */ 598 599 /* Skip over rsp len */ 600 p++; 601 602 /* Get project id */ 603 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.project_id, p); 604 605 /* RFU */ 606 p++; 607 608 /* Get chip version string */ 609 STREAM_TO_UINT8 (u8, p); 610 if (u8 > NFC_HAL_PRM_MAX_CHIP_VER_LEN) 611 u8 = NFC_HAL_PRM_MAX_CHIP_VER_LEN; 612 memcpy (nfc_hal_cb.nvm_cb.chip_ver, p, u8); 613 p += NCI_PATCH_INFO_VERSION_LEN; 614 615 /* Get major/minor version */ 616 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.ver_major, p); 617 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.ver_minor, p); 618 619 /* Skip over max_size and patch_max_size */ 620 p += 4; 621 622 /* Get current lpm patch size */ 623 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.lpm_size, p); 624 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.fpm_size, p); 625 626 /* clear all flags which may be set during previous initialization */ 627 nfc_hal_cb.nvm_cb.flags = 0; 628 629 /* Set patch present flag */ 630 if ((nfc_hal_cb.nvm_cb.fpm_size) || (nfc_hal_cb.nvm_cb.lpm_size)) 631 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_PATCH_PRESENT; 632 633 /* LPMPatchCodeHasBadCRC (if not bad crc, then indicate LPM patch is present in nvm) */ 634 STREAM_TO_UINT8 (u8, p); 635 if (u8) 636 { 637 /* LPM patch in NVM fails CRC check */ 638 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_LPM_BAD; 639 } 640 641 642 /* FPMPatchCodeHasBadCRC (if not bad crc, then indicate LPM patch is present in nvm) */ 643 STREAM_TO_UINT8 (u8, p); 644 if (u8) 645 { 646 /* FPM patch in NVM fails CRC check */ 647 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_FPM_BAD; 648 } 649 650 /* Check if downloading patch to RAM only (no NVM) */ 651 STREAM_TO_UINT8 (nfc_hal_cb.nvm_cb.nvm_type, p); 652 if (nfc_hal_cb.nvm_cb.nvm_type == NCI_SPD_NVM_TYPE_NONE) 653 { 654 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_NO_NVM; 655 } 656 657 /* let platform update baudrate or download patch */ 658 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_APP_COMPLETE); 659 nfc_hal_post_reset_init (nfc_hal_cb.dev_cb.brcm_hw_id, nfc_hal_cb.nvm_cb.nvm_type); 660 } 661 else if (p_cback) 662 { 663 (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code), 664 p_msg->len, 665 (UINT8 *) (p_msg + 1) + p_msg->offset); 666 } 667 else if (op_code == NFC_VS_SEC_PATCH_AUTH_EVT) 668 { 669 HAL_TRACE_DEBUG0 ("signature!!"); 670 nfc_hal_prm_nci_command_complete_cback ((tNFC_HAL_NCI_EVT) (op_code), 671 p_msg->len, 672 (UINT8 *) (p_msg + 1) + p_msg->offset); 673 } 674 } 675} 676 677/******************************************************************************* 678** 679** Function nfc_hal_dm_send_nci_cmd 680** 681** Description Send NCI command to NFCC while initializing BRCM NFCC 682** 683** Returns void 684** 685*******************************************************************************/ 686void nfc_hal_dm_send_nci_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_NCI_CBACK *p_cback) 687{ 688 NFC_HDR *p_buf; 689 UINT8 *ps; 690 691 HAL_TRACE_DEBUG1 ("nfc_hal_dm_send_nci_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp); 692 693 if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE) 694 { 695 HAL_TRACE_ERROR0 ("nfc_hal_dm_send_nci_cmd(): no command window"); 696 return; 697 } 698 699 if ((p_buf = (NFC_HDR *)GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL) 700 { 701 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_VSC; 702 703 p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE; 704 p_buf->event = NFC_HAL_EVT_TO_NFC_NCI; 705 p_buf->len = len; 706 707 memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len); 708 709 /* Keep a copy of the command and send to NCI transport */ 710 711 /* save the message header to double check the response */ 712 ps = (UINT8 *)(p_buf + 1) + p_buf->offset; 713 memcpy(nfc_hal_cb.ncit_cb.last_hdr, ps, NFC_HAL_SAVED_HDR_SIZE); 714 memcpy(nfc_hal_cb.ncit_cb.last_cmd, ps + NCI_MSG_HDR_SIZE, NFC_HAL_SAVED_CMD_SIZE); 715 716 /* save the callback for NCI VSCs */ 717 nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback; 718 719 nfc_hal_nci_send_cmd (p_buf); 720 721 /* start NFC command-timeout timer */ 722 nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP), 723 ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 724 } 725} 726 727/******************************************************************************* 728** 729** Function nfc_hal_dm_send_pend_cmd 730** 731** Description Send a command to NFCC 732** 733** Returns void 734** 735*******************************************************************************/ 736void nfc_hal_dm_send_pend_cmd (void) 737{ 738 NFC_HDR *p_buf = nfc_hal_cb.ncit_cb.p_pend_cmd; 739 UINT8 *p; 740 741 if (p_buf == NULL) 742 return; 743 744 /* check low power mode state */ 745 if (!nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TX_DATA_EVT)) 746 { 747 return; 748 } 749 750 if (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_PROP) 751 { 752#if (NFC_HAL_TRACE_PROTOCOL == TRUE) 753 DispHciCmd (p_buf); 754#endif 755 756 /* save the message header to double check the response */ 757 p = (UINT8 *)(p_buf + 1) + p_buf->offset; 758 memcpy(nfc_hal_cb.ncit_cb.last_hdr, p, NFC_HAL_SAVED_HDR_SIZE); 759 760 /* add packet type for BT message */ 761 p_buf->offset--; 762 p_buf->len++; 763 764 p = (UINT8 *) (p_buf + 1) + p_buf->offset; 765 *p = HCIT_TYPE_COMMAND; 766 767 USERIAL_Write (USERIAL_NFC_PORT, p, p_buf->len); 768 769 GKI_freebuf (p_buf); 770 nfc_hal_cb.ncit_cb.p_pend_cmd = NULL; 771 772 /* start NFC command-timeout timer */ 773 nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP), 774 ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 775 776 } 777} 778 779/******************************************************************************* 780** 781** Function nfc_hal_dm_send_bt_cmd 782** 783** Description Send BT message to NFCC while initializing BRCM NFCC 784** 785** Returns void 786** 787*******************************************************************************/ 788void nfc_hal_dm_send_bt_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_BTVSC_CPLT_CBACK *p_cback) 789{ 790 NFC_HDR *p_buf; 791 792 HAL_TRACE_DEBUG1 ("nfc_hal_dm_send_bt_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp); 793 794 if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE) 795 { 796 HAL_TRACE_ERROR0 ("nfc_hal_dm_send_bt_cmd(): no command window"); 797 return; 798 } 799 800 if ((p_buf = (NFC_HDR *) GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL) 801 { 802 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_PROP; 803 804 p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE; 805 p_buf->len = len; 806 807 memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len); 808 809 /* save the callback for NCI VSCs) */ 810 nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback; 811 812 nfc_hal_cb.ncit_cb.p_pend_cmd = p_buf; 813 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_IDLE) 814 { 815 NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_W4_CONTROL_DONE); 816 nfc_hal_cb.p_stack_cback (HAL_NFC_REQUEST_CONTROL_EVT, HAL_NFC_STATUS_OK); 817 return; 818 } 819 820 nfc_hal_dm_send_pend_cmd(); 821 } 822} 823 824/******************************************************************************* 825** 826** Function nfc_hal_dm_set_nfc_wake 827** 828** Description Set NFC_WAKE line 829** 830** Returns void 831** 832*******************************************************************************/ 833void nfc_hal_dm_set_nfc_wake (UINT8 cmd) 834{ 835 HAL_TRACE_DEBUG1 ("nfc_hal_dm_set_nfc_wake () %s", 836 (cmd == NFC_HAL_ASSERT_NFC_WAKE ? "ASSERT" : "DEASSERT")); 837 838 /* 839 ** nfc_wake_active_mode cmd result of voltage on NFC_WAKE 840 ** 841 ** NFC_HAL_LP_ACTIVE_LOW (0) NFC_HAL_ASSERT_NFC_WAKE (0) pull down NFC_WAKE (GND) 842 ** NFC_HAL_LP_ACTIVE_LOW (0) NFC_HAL_DEASSERT_NFC_WAKE (1) pull up NFC_WAKE (VCC) 843 ** NFC_HAL_LP_ACTIVE_HIGH (1) NFC_HAL_ASSERT_NFC_WAKE (0) pull up NFC_WAKE (VCC) 844 ** NFC_HAL_LP_ACTIVE_HIGH (1) NFC_HAL_DEASSERT_NFC_WAKE (1) pull down NFC_WAKE (GND) 845 */ 846 847 if (cmd == nfc_hal_cb.dev_cb.nfc_wake_active_mode) 848 UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_OFF); /* pull down NFC_WAKE */ 849 else 850 UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_ON); /* pull up NFC_WAKE */ 851} 852 853/******************************************************************************* 854** 855** Function nfc_hal_dm_power_mode_execute 856** 857** Description If snooze mode is enabled in full power mode, 858** Assert NFC_WAKE before sending data 859** Deassert NFC_WAKE when idle timer expires 860** 861** Returns TRUE if DH can send data to NFCC 862** 863*******************************************************************************/ 864BOOLEAN nfc_hal_dm_power_mode_execute (tNFC_HAL_LP_EVT event) 865{ 866 BOOLEAN send_to_nfcc = FALSE; 867 868 HAL_TRACE_DEBUG1 ("nfc_hal_dm_power_mode_execute () event = %d", event); 869 870 if (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL) 871 { 872 if (nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) 873 { 874 /* if any transport activity */ 875 if ( (event == NFC_HAL_LP_TX_DATA_EVT) 876 ||(event == NFC_HAL_LP_RX_DATA_EVT) ) 877 { 878 /* if idle timer is not running */ 879 if (nfc_hal_cb.dev_cb.lp_timer.in_use == FALSE) 880 { 881 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 882 } 883 884 /* start or extend idle timer */ 885 nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00, 886 ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 887 } 888 else if (event == NFC_HAL_LP_TIMEOUT_EVT) 889 { 890 /* let NFCC go to snooze mode */ 891 nfc_hal_dm_set_nfc_wake (NFC_HAL_DEASSERT_NFC_WAKE); 892 } 893 } 894 895 send_to_nfcc = TRUE; 896 } 897 898 return (send_to_nfcc); 899} 900 901/******************************************************************************* 902** 903** Function nci_brcm_lp_timeout_cback 904** 905** Description callback function for low power timeout 906** 907** Returns void 908** 909*******************************************************************************/ 910static void nci_brcm_lp_timeout_cback (void *p_tle) 911{ 912 HAL_TRACE_DEBUG0 ("nci_brcm_lp_timeout_cback ()"); 913 914 nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TIMEOUT_EVT); 915} 916 917/******************************************************************************* 918** 919** Function nfc_hal_dm_pre_init_nfcc 920** 921** Description This function initializes Broadcom specific control blocks for 922** NCI transport 923** 924** Returns void 925** 926*******************************************************************************/ 927void nfc_hal_dm_pre_init_nfcc (void) 928{ 929 HAL_TRACE_DEBUG0 ("nfc_hal_dm_pre_init_nfcc ()"); 930 931 /* if it was waiting for core reset notification after raising REG_PU */ 932 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_NFCC_ENABLE) 933 { 934 nfc_hal_dm_send_get_build_info_cmd (); 935 } 936 /* if it was waiting for core reset notification after setting Xtal */ 937 else if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_POST_XTAL_SET) 938 { 939 { 940 /* Core reset ntf after xtal setting indicating NFCC loaded patch from NVM */ 941 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_PATCH_INFO); 942 943 nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, NULL); 944 } 945 } 946} 947 948/******************************************************************************* 949** 950** Function nfc_hal_dm_shutting_down_nfcc 951** 952** Description This function initializes Broadcom specific control blocks for 953** NCI transport 954** 955** Returns void 956** 957*******************************************************************************/ 958void nfc_hal_dm_shutting_down_nfcc (void) 959{ 960 HAL_TRACE_DEBUG0 ("nfc_hal_dm_shutting_down_nfcc ()"); 961 962 nfc_hal_cb.dev_cb.initializing_state = NFC_HAL_INIT_STATE_CLOSING; 963 964 /* reset low power mode variables */ 965 if ( (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL) 966 &&(nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) ) 967 { 968 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 969 } 970 971 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE; 972 nfc_hal_cb.hci_cb.hcp_conn_id = 0; 973 974 nfc_hal_cb.dev_cb.power_mode = NFC_HAL_POWER_MODE_FULL; 975 nfc_hal_cb.dev_cb.snooze_mode = NFC_HAL_LP_SNOOZE_MODE_NONE; 976 977 /* Stop all timers */ 978 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer); 979 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer); 980 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.prm.timer); 981 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.hci_cb.hci_timer); 982 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.timer); 983} 984 985/******************************************************************************* 986** 987** Function nfc_hal_dm_init 988** 989** Description This function initializes Broadcom specific control blocks for 990** NCI transport 991** 992** Returns void 993** 994*******************************************************************************/ 995void nfc_hal_dm_init (void) 996{ 997 HAL_TRACE_DEBUG0 ("nfc_hal_dm_init ()"); 998 999 nfc_hal_cb.dev_cb.lp_timer.p_cback = nci_brcm_lp_timeout_cback; 1000 1001 nfc_hal_cb.ncit_cb.nci_wait_rsp_timer.p_cback = nfc_hal_nci_cmd_timeout_cback; 1002 1003 nfc_hal_cb.hci_cb.hci_timer.p_cback = nfc_hal_hci_timeout_cback; 1004 1005 nfc_hal_cb.pre_discover_done = FALSE; 1006 1007 nfc_post_reset_cb.spd_nvm_detection_cur_count = 0; 1008 nfc_post_reset_cb.spd_skip_on_power_cycle = FALSE; 1009 1010} 1011 1012/******************************************************************************* 1013** 1014** Function HAL_NfcDevInitDone 1015** 1016** Description Notify that pre-initialization of NFCC is complete 1017** 1018** Returns void 1019** 1020*******************************************************************************/ 1021void HAL_NfcPreInitDone (tHAL_NFC_STATUS status) 1022{ 1023 HAL_TRACE_DEBUG1 ("HAL_NfcPreInitDone () status=%d", status); 1024 1025 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE) 1026 { 1027 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE); 1028 1029 nfc_hal_main_pre_init_done (status); 1030 } 1031} 1032 1033/******************************************************************************* 1034** 1035** Function HAL_NfcReInit 1036** 1037** Description This function is called to restart initialization after REG_PU 1038** toggled because of failure to detect NVM type or download patchram. 1039** 1040** Note This function should be called only during the HAL init process 1041** 1042** Returns HAL_NFC_STATUS_OK if successfully initiated 1043** HAL_NFC_STATUS_FAILED otherwise 1044** 1045*******************************************************************************/ 1046tHAL_NFC_STATUS HAL_NfcReInit (void) 1047{ 1048 tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED; 1049 1050 HAL_TRACE_DEBUG1 ("HAL_NfcReInit () init st=0x%x", nfc_hal_cb.dev_cb.initializing_state); 1051 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE) 1052 { 1053 { 1054 /* Wait for NFCC to enable - Core reset notification */ 1055 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_NFCC_ENABLE); 1056 1057 /* NFCC Enable timeout */ 1058 nfc_hal_main_start_quick_timer (&nfc_hal_cb.timer, NFC_HAL_TTYPE_NFCC_ENABLE, 1059 ((p_nfc_hal_cfg->nfc_hal_nfcc_enable_timeout)*QUICK_TIMER_TICKS_PER_SEC)/1000); 1060 } 1061 1062 status = HAL_NFC_STATUS_OK; 1063 } 1064 return status; 1065} 1066 1067/******************************************************************************* 1068** 1069** Function nfc_hal_dm_set_snooze_mode_cback 1070** 1071** Description This is baud rate update complete callback. 1072** 1073** Returns void 1074** 1075*******************************************************************************/ 1076static void nfc_hal_dm_set_snooze_mode_cback (tNFC_HAL_BTVSC_CPLT *pData) 1077{ 1078 UINT8 status = pData->p_param_buf[0]; 1079 tHAL_NFC_STATUS hal_status; 1080 tHAL_NFC_STATUS_CBACK *p_cback; 1081 1082 /* if it is completed */ 1083 if (status == HCI_SUCCESS) 1084 { 1085 /* update snooze mode */ 1086 nfc_hal_cb.dev_cb.snooze_mode = nfc_hal_cb.dev_cb.new_snooze_mode; 1087 1088 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 1089 1090 if ( nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) 1091 { 1092 /* start idle timer */ 1093 nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00, 1094 ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 1095 } 1096 else 1097 { 1098 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer); 1099 } 1100 hal_status = HAL_NFC_STATUS_OK; 1101 } 1102 else 1103 { 1104 hal_status = HAL_NFC_STATUS_FAILED; 1105 } 1106 1107 if (nfc_hal_cb.dev_cb.p_prop_cback) 1108 { 1109 p_cback = nfc_hal_cb.dev_cb.p_prop_cback; 1110 nfc_hal_cb.dev_cb.p_prop_cback = NULL; 1111 (*p_cback) (hal_status); 1112 } 1113} 1114 1115/******************************************************************************* 1116** 1117** Function HAL_NfcSetSnoozeMode 1118** 1119** Description Set snooze mode 1120** snooze_mode 1121** NFC_HAL_LP_SNOOZE_MODE_NONE - Snooze mode disabled 1122** NFC_HAL_LP_SNOOZE_MODE_UART - Snooze mode for UART 1123** NFC_HAL_LP_SNOOZE_MODE_SPI_I2C - Snooze mode for SPI/I2C 1124** 1125** idle_threshold_dh/idle_threshold_nfcc 1126** Idle Threshold Host in 100ms unit 1127** 1128** nfc_wake_active_mode/dh_wake_active_mode 1129** NFC_HAL_LP_ACTIVE_LOW - high to low voltage is asserting 1130** NFC_HAL_LP_ACTIVE_HIGH - low to high voltage is asserting 1131** 1132** p_snooze_cback 1133** Notify status of operation 1134** 1135** Returns tHAL_NFC_STATUS 1136** 1137*******************************************************************************/ 1138tHAL_NFC_STATUS HAL_NfcSetSnoozeMode (UINT8 snooze_mode, 1139 UINT8 idle_threshold_dh, 1140 UINT8 idle_threshold_nfcc, 1141 UINT8 nfc_wake_active_mode, 1142 UINT8 dh_wake_active_mode, 1143 tHAL_NFC_STATUS_CBACK *p_snooze_cback) 1144{ 1145 UINT8 cmd[NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH]; 1146 UINT8 *p; 1147 1148 HAL_TRACE_API1 ("HAL_NfcSetSnoozeMode (): snooze_mode = %d", snooze_mode); 1149 1150 nfc_hal_cb.dev_cb.new_snooze_mode = snooze_mode; 1151 nfc_hal_cb.dev_cb.nfc_wake_active_mode = nfc_wake_active_mode; 1152 nfc_hal_cb.dev_cb.p_prop_cback = p_snooze_cback; 1153 1154 p = cmd; 1155 1156 /* Add the HCI command */ 1157 UINT16_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE); 1158 UINT8_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH); 1159 1160 memset (p, 0x00, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH); 1161 1162 UINT8_TO_STREAM (p, snooze_mode); /* Sleep Mode */ 1163 1164 UINT8_TO_STREAM (p, idle_threshold_dh); /* Idle Threshold Host */ 1165 UINT8_TO_STREAM (p, idle_threshold_nfcc); /* Idle Threshold HC */ 1166 UINT8_TO_STREAM (p, nfc_wake_active_mode); /* BT Wake Active Mode */ 1167 UINT8_TO_STREAM (p, dh_wake_active_mode); /* Host Wake Active Mode */ 1168 1169 nfc_hal_dm_send_bt_cmd (cmd, 1170 NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH, 1171 nfc_hal_dm_set_snooze_mode_cback); 1172 return (NCI_STATUS_OK); 1173} 1174 1175 1176 1177 1178 1179 1180 1181 1182