nfc_hal_dm.c revision df5080d7feca9827fd0306471c54f52ecf185c22
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 p += NCI_PATCH_INFO_VERSION_LEN; 611 612 /* Get major/minor version */ 613 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.ver_major, p); 614 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.ver_minor, p); 615 616 /* Skip over max_size and patch_max_size */ 617 p += 4; 618 619 /* Get current lpm patch size */ 620 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.lpm_size, p); 621 STREAM_TO_UINT16 (nfc_hal_cb.nvm_cb.fpm_size, p); 622 623 /* clear all flags which may be set during previous initialization */ 624 nfc_hal_cb.nvm_cb.flags = 0; 625 626 /* Set patch present flag */ 627 if ((nfc_hal_cb.nvm_cb.fpm_size) || (nfc_hal_cb.nvm_cb.lpm_size)) 628 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_PATCH_PRESENT; 629 630 /* LPMPatchCodeHasBadCRC (if not bad crc, then indicate LPM patch is present in nvm) */ 631 STREAM_TO_UINT8 (u8, p); 632 if (u8) 633 { 634 /* LPM patch in NVM fails CRC check */ 635 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_LPM_BAD; 636 } 637 638 639 /* FPMPatchCodeHasBadCRC (if not bad crc, then indicate LPM patch is present in nvm) */ 640 STREAM_TO_UINT8 (u8, p); 641 if (u8) 642 { 643 /* FPM patch in NVM fails CRC check */ 644 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_FPM_BAD; 645 } 646 647 /* Check if downloading patch to RAM only (no NVM) */ 648 STREAM_TO_UINT8 (nfc_hal_cb.nvm_cb.nvm_type, p); 649 if (nfc_hal_cb.nvm_cb.nvm_type == NCI_SPD_NVM_TYPE_NONE) 650 { 651 nfc_hal_cb.nvm_cb.flags |= NFC_HAL_NVM_FLAGS_NO_NVM; 652 } 653 654 /* let platform update baudrate or download patch */ 655 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_APP_COMPLETE); 656 nfc_hal_post_reset_init (nfc_hal_cb.dev_cb.brcm_hw_id, nfc_hal_cb.nvm_cb.nvm_type); 657 } 658 else if (p_cback) 659 { 660 (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code), 661 p_msg->len, 662 (UINT8 *) (p_msg + 1) + p_msg->offset); 663 } 664 else if (op_code == NFC_VS_SEC_PATCH_AUTH_EVT) 665 { 666 HAL_TRACE_DEBUG0 ("signature!!"); 667 nfc_hal_prm_nci_command_complete_cback ((tNFC_HAL_NCI_EVT) (op_code), 668 p_msg->len, 669 (UINT8 *) (p_msg + 1) + p_msg->offset); 670 } 671 } 672} 673 674/******************************************************************************* 675** 676** Function nfc_hal_dm_send_nci_cmd 677** 678** Description Send NCI command to NFCC while initializing BRCM NFCC 679** 680** Returns void 681** 682*******************************************************************************/ 683void nfc_hal_dm_send_nci_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_NCI_CBACK *p_cback) 684{ 685 NFC_HDR *p_buf; 686 UINT8 *ps; 687 688 HAL_TRACE_DEBUG1 ("nfc_hal_dm_send_nci_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp); 689 690 if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE) 691 { 692 HAL_TRACE_ERROR0 ("nfc_hal_dm_send_nci_cmd(): no command window"); 693 return; 694 } 695 696 if ((p_buf = (NFC_HDR *)GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL) 697 { 698 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_VSC; 699 700 p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE; 701 p_buf->event = NFC_HAL_EVT_TO_NFC_NCI; 702 p_buf->len = len; 703 704 memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len); 705 706 /* Keep a copy of the command and send to NCI transport */ 707 708 /* save the message header to double check the response */ 709 ps = (UINT8 *)(p_buf + 1) + p_buf->offset; 710 memcpy(nfc_hal_cb.ncit_cb.last_hdr, ps, NFC_HAL_SAVED_HDR_SIZE); 711 memcpy(nfc_hal_cb.ncit_cb.last_cmd, ps + NCI_MSG_HDR_SIZE, NFC_HAL_SAVED_CMD_SIZE); 712 713 /* save the callback for NCI VSCs */ 714 nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback; 715 716 nfc_hal_nci_send_cmd (p_buf); 717 718 /* start NFC command-timeout timer */ 719 nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP), 720 ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 721 } 722} 723 724/******************************************************************************* 725** 726** Function nfc_hal_dm_send_pend_cmd 727** 728** Description Send a command to NFCC 729** 730** Returns void 731** 732*******************************************************************************/ 733void nfc_hal_dm_send_pend_cmd (void) 734{ 735 NFC_HDR *p_buf = nfc_hal_cb.ncit_cb.p_pend_cmd; 736 UINT8 *p; 737 738 if (p_buf == NULL) 739 return; 740 741 /* check low power mode state */ 742 if (!nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TX_DATA_EVT)) 743 { 744 return; 745 } 746 747 if (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_PROP) 748 { 749#if (NFC_HAL_TRACE_PROTOCOL == TRUE) 750 DispHciCmd (p_buf); 751#endif 752 753 /* save the message header to double check the response */ 754 p = (UINT8 *)(p_buf + 1) + p_buf->offset; 755 memcpy(nfc_hal_cb.ncit_cb.last_hdr, p, NFC_HAL_SAVED_HDR_SIZE); 756 757 /* add packet type for BT message */ 758 p_buf->offset--; 759 p_buf->len++; 760 761 p = (UINT8 *) (p_buf + 1) + p_buf->offset; 762 *p = HCIT_TYPE_COMMAND; 763 764 USERIAL_Write (USERIAL_NFC_PORT, p, p_buf->len); 765 766 GKI_freebuf (p_buf); 767 nfc_hal_cb.ncit_cb.p_pend_cmd = NULL; 768 769 /* start NFC command-timeout timer */ 770 nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP), 771 ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 772 773 } 774} 775 776/******************************************************************************* 777** 778** Function nfc_hal_dm_send_bt_cmd 779** 780** Description Send BT message to NFCC while initializing BRCM NFCC 781** 782** Returns void 783** 784*******************************************************************************/ 785void nfc_hal_dm_send_bt_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_BTVSC_CPLT_CBACK *p_cback) 786{ 787 NFC_HDR *p_buf; 788 789 HAL_TRACE_DEBUG1 ("nfc_hal_dm_send_bt_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp); 790 791 if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE) 792 { 793 HAL_TRACE_ERROR0 ("nfc_hal_dm_send_bt_cmd(): no command window"); 794 return; 795 } 796 797 if ((p_buf = (NFC_HDR *) GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL) 798 { 799 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_PROP; 800 801 p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE; 802 p_buf->len = len; 803 804 memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len); 805 806 /* save the callback for NCI VSCs) */ 807 nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback; 808 809 nfc_hal_cb.ncit_cb.p_pend_cmd = p_buf; 810 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_IDLE) 811 { 812 NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_W4_CONTROL_DONE); 813 nfc_hal_cb.p_stack_cback (HAL_NFC_REQUEST_CONTROL_EVT, HAL_NFC_STATUS_OK); 814 return; 815 } 816 817 nfc_hal_dm_send_pend_cmd(); 818 } 819} 820 821/******************************************************************************* 822** 823** Function nfc_hal_dm_set_nfc_wake 824** 825** Description Set NFC_WAKE line 826** 827** Returns void 828** 829*******************************************************************************/ 830void nfc_hal_dm_set_nfc_wake (UINT8 cmd) 831{ 832 HAL_TRACE_DEBUG1 ("nfc_hal_dm_set_nfc_wake () %s", 833 (cmd == NFC_HAL_ASSERT_NFC_WAKE ? "ASSERT" : "DEASSERT")); 834 835 /* 836 ** nfc_wake_active_mode cmd result of voltage on NFC_WAKE 837 ** 838 ** NFC_HAL_LP_ACTIVE_LOW (0) NFC_HAL_ASSERT_NFC_WAKE (0) pull down NFC_WAKE (GND) 839 ** NFC_HAL_LP_ACTIVE_LOW (0) NFC_HAL_DEASSERT_NFC_WAKE (1) pull up NFC_WAKE (VCC) 840 ** NFC_HAL_LP_ACTIVE_HIGH (1) NFC_HAL_ASSERT_NFC_WAKE (0) pull up NFC_WAKE (VCC) 841 ** NFC_HAL_LP_ACTIVE_HIGH (1) NFC_HAL_DEASSERT_NFC_WAKE (1) pull down NFC_WAKE (GND) 842 */ 843 844 if (cmd == nfc_hal_cb.dev_cb.nfc_wake_active_mode) 845 UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_OFF); /* pull down NFC_WAKE */ 846 else 847 UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_ON); /* pull up NFC_WAKE */ 848} 849 850/******************************************************************************* 851** 852** Function nfc_hal_dm_power_mode_execute 853** 854** Description If snooze mode is enabled in full power mode, 855** Assert NFC_WAKE before sending data 856** Deassert NFC_WAKE when idle timer expires 857** 858** Returns TRUE if DH can send data to NFCC 859** 860*******************************************************************************/ 861BOOLEAN nfc_hal_dm_power_mode_execute (tNFC_HAL_LP_EVT event) 862{ 863 BOOLEAN send_to_nfcc = FALSE; 864 865 HAL_TRACE_DEBUG1 ("nfc_hal_dm_power_mode_execute () event = %d", event); 866 867 if (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL) 868 { 869 if (nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) 870 { 871 /* if any transport activity */ 872 if ( (event == NFC_HAL_LP_TX_DATA_EVT) 873 ||(event == NFC_HAL_LP_RX_DATA_EVT) ) 874 { 875 /* if idle timer is not running */ 876 if (nfc_hal_cb.dev_cb.lp_timer.in_use == FALSE) 877 { 878 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 879 } 880 881 /* start or extend idle timer */ 882 nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00, 883 ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 884 } 885 else if (event == NFC_HAL_LP_TIMEOUT_EVT) 886 { 887 /* let NFCC go to snooze mode */ 888 nfc_hal_dm_set_nfc_wake (NFC_HAL_DEASSERT_NFC_WAKE); 889 } 890 } 891 892 send_to_nfcc = TRUE; 893 } 894 895 return (send_to_nfcc); 896} 897 898/******************************************************************************* 899** 900** Function nci_brcm_lp_timeout_cback 901** 902** Description callback function for low power timeout 903** 904** Returns void 905** 906*******************************************************************************/ 907static void nci_brcm_lp_timeout_cback (void *p_tle) 908{ 909 HAL_TRACE_DEBUG0 ("nci_brcm_lp_timeout_cback ()"); 910 911 nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TIMEOUT_EVT); 912} 913 914/******************************************************************************* 915** 916** Function nfc_hal_dm_pre_init_nfcc 917** 918** Description This function initializes Broadcom specific control blocks for 919** NCI transport 920** 921** Returns void 922** 923*******************************************************************************/ 924void nfc_hal_dm_pre_init_nfcc (void) 925{ 926 HAL_TRACE_DEBUG0 ("nfc_hal_dm_pre_init_nfcc ()"); 927 928 /* if it was waiting for core reset notification after raising REG_PU */ 929 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_NFCC_ENABLE) 930 { 931 nfc_hal_dm_send_get_build_info_cmd (); 932 } 933 /* if it was waiting for core reset notification after setting Xtal */ 934 else if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_POST_XTAL_SET) 935 { 936 { 937 /* Core reset ntf after xtal setting indicating NFCC loaded patch from NVM */ 938 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_PATCH_INFO); 939 940 nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, NULL); 941 } 942 } 943} 944 945/******************************************************************************* 946** 947** Function nfc_hal_dm_shutting_down_nfcc 948** 949** Description This function initializes Broadcom specific control blocks for 950** NCI transport 951** 952** Returns void 953** 954*******************************************************************************/ 955void nfc_hal_dm_shutting_down_nfcc (void) 956{ 957 HAL_TRACE_DEBUG0 ("nfc_hal_dm_shutting_down_nfcc ()"); 958 959 nfc_hal_cb.dev_cb.initializing_state = NFC_HAL_INIT_STATE_CLOSING; 960 961 /* reset low power mode variables */ 962 if ( (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL) 963 &&(nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) ) 964 { 965 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 966 } 967 968 nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE; 969 nfc_hal_cb.hci_cb.hcp_conn_id = 0; 970 971 nfc_hal_cb.dev_cb.power_mode = NFC_HAL_POWER_MODE_FULL; 972 nfc_hal_cb.dev_cb.snooze_mode = NFC_HAL_LP_SNOOZE_MODE_NONE; 973 974 /* Stop all timers */ 975 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer); 976 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer); 977 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.prm.timer); 978 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.hci_cb.hci_timer); 979 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.timer); 980} 981 982/******************************************************************************* 983** 984** Function nfc_hal_dm_init 985** 986** Description This function initializes Broadcom specific control blocks for 987** NCI transport 988** 989** Returns void 990** 991*******************************************************************************/ 992void nfc_hal_dm_init (void) 993{ 994 HAL_TRACE_DEBUG0 ("nfc_hal_dm_init ()"); 995 996 nfc_hal_cb.dev_cb.lp_timer.p_cback = nci_brcm_lp_timeout_cback; 997 998 nfc_hal_cb.ncit_cb.nci_wait_rsp_timer.p_cback = nfc_hal_nci_cmd_timeout_cback; 999 1000 nfc_hal_cb.hci_cb.hci_timer.p_cback = nfc_hal_hci_timeout_cback; 1001 1002 nfc_hal_cb.pre_discover_done = FALSE; 1003 1004 nfc_post_reset_cb.spd_nvm_detection_cur_count = 0; 1005 nfc_post_reset_cb.spd_skip_on_power_cycle = FALSE; 1006 1007} 1008 1009/******************************************************************************* 1010** 1011** Function HAL_NfcDevInitDone 1012** 1013** Description Notify that pre-initialization of NFCC is complete 1014** 1015** Returns void 1016** 1017*******************************************************************************/ 1018void HAL_NfcPreInitDone (tHAL_NFC_STATUS status) 1019{ 1020 HAL_TRACE_DEBUG1 ("HAL_NfcPreInitDone () status=%d", status); 1021 1022 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE) 1023 { 1024 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE); 1025 1026 nfc_hal_main_pre_init_done (status); 1027 } 1028} 1029 1030/******************************************************************************* 1031** 1032** Function HAL_NfcReInit 1033** 1034** Description This function is called to restart initialization after REG_PU 1035** toggled because of failure to detect NVM type or download patchram. 1036** 1037** Note This function should be called only during the HAL init process 1038** 1039** Returns HAL_NFC_STATUS_OK if successfully initiated 1040** HAL_NFC_STATUS_FAILED otherwise 1041** 1042*******************************************************************************/ 1043tHAL_NFC_STATUS HAL_NfcReInit (void) 1044{ 1045 tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED; 1046 1047 HAL_TRACE_DEBUG1 ("HAL_NfcReInit () init st=0x%x", nfc_hal_cb.dev_cb.initializing_state); 1048 if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE) 1049 { 1050 { 1051 /* Wait for NFCC to enable - Core reset notification */ 1052 NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_NFCC_ENABLE); 1053 1054 /* NFCC Enable timeout */ 1055 nfc_hal_main_start_quick_timer (&nfc_hal_cb.timer, NFC_HAL_TTYPE_NFCC_ENABLE, 1056 ((p_nfc_hal_cfg->nfc_hal_nfcc_enable_timeout)*QUICK_TIMER_TICKS_PER_SEC)/1000); 1057 } 1058 1059 status = HAL_NFC_STATUS_OK; 1060 } 1061 return status; 1062} 1063 1064/******************************************************************************* 1065** 1066** Function nfc_hal_dm_set_snooze_mode_cback 1067** 1068** Description This is baud rate update complete callback. 1069** 1070** Returns void 1071** 1072*******************************************************************************/ 1073static void nfc_hal_dm_set_snooze_mode_cback (tNFC_HAL_BTVSC_CPLT *pData) 1074{ 1075 UINT8 status = pData->p_param_buf[0]; 1076 tHAL_NFC_STATUS hal_status; 1077 tHAL_NFC_STATUS_CBACK *p_cback; 1078 1079 /* if it is completed */ 1080 if (status == HCI_SUCCESS) 1081 { 1082 /* update snooze mode */ 1083 nfc_hal_cb.dev_cb.snooze_mode = nfc_hal_cb.dev_cb.new_snooze_mode; 1084 1085 nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE); 1086 1087 if ( nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) 1088 { 1089 /* start idle timer */ 1090 nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00, 1091 ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000); 1092 } 1093 else 1094 { 1095 nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer); 1096 } 1097 hal_status = HAL_NFC_STATUS_OK; 1098 } 1099 else 1100 { 1101 hal_status = HAL_NFC_STATUS_FAILED; 1102 } 1103 1104 if (nfc_hal_cb.dev_cb.p_prop_cback) 1105 { 1106 p_cback = nfc_hal_cb.dev_cb.p_prop_cback; 1107 nfc_hal_cb.dev_cb.p_prop_cback = NULL; 1108 (*p_cback) (hal_status); 1109 } 1110} 1111 1112/******************************************************************************* 1113** 1114** Function HAL_NfcSetSnoozeMode 1115** 1116** Description Set snooze mode 1117** snooze_mode 1118** NFC_HAL_LP_SNOOZE_MODE_NONE - Snooze mode disabled 1119** NFC_HAL_LP_SNOOZE_MODE_UART - Snooze mode for UART 1120** NFC_HAL_LP_SNOOZE_MODE_SPI_I2C - Snooze mode for SPI/I2C 1121** 1122** idle_threshold_dh/idle_threshold_nfcc 1123** Idle Threshold Host in 100ms unit 1124** 1125** nfc_wake_active_mode/dh_wake_active_mode 1126** NFC_HAL_LP_ACTIVE_LOW - high to low voltage is asserting 1127** NFC_HAL_LP_ACTIVE_HIGH - low to high voltage is asserting 1128** 1129** p_snooze_cback 1130** Notify status of operation 1131** 1132** Returns tHAL_NFC_STATUS 1133** 1134*******************************************************************************/ 1135tHAL_NFC_STATUS HAL_NfcSetSnoozeMode (UINT8 snooze_mode, 1136 UINT8 idle_threshold_dh, 1137 UINT8 idle_threshold_nfcc, 1138 UINT8 nfc_wake_active_mode, 1139 UINT8 dh_wake_active_mode, 1140 tHAL_NFC_STATUS_CBACK *p_snooze_cback) 1141{ 1142 UINT8 cmd[NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH]; 1143 UINT8 *p; 1144 1145 HAL_TRACE_API1 ("HAL_NfcSetSnoozeMode (): snooze_mode = %d", snooze_mode); 1146 1147 nfc_hal_cb.dev_cb.new_snooze_mode = snooze_mode; 1148 nfc_hal_cb.dev_cb.nfc_wake_active_mode = nfc_wake_active_mode; 1149 nfc_hal_cb.dev_cb.p_prop_cback = p_snooze_cback; 1150 1151 p = cmd; 1152 1153 /* Add the HCI command */ 1154 UINT16_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE); 1155 UINT8_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH); 1156 1157 memset (p, 0x00, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH); 1158 1159 UINT8_TO_STREAM (p, snooze_mode); /* Sleep Mode */ 1160 1161 UINT8_TO_STREAM (p, idle_threshold_dh); /* Idle Threshold Host */ 1162 UINT8_TO_STREAM (p, idle_threshold_nfcc); /* Idle Threshold HC */ 1163 UINT8_TO_STREAM (p, nfc_wake_active_mode); /* BT Wake Active Mode */ 1164 UINT8_TO_STREAM (p, dh_wake_active_mode); /* Host Wake Active Mode */ 1165 1166 nfc_hal_dm_send_bt_cmd (cmd, 1167 NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH, 1168 nfc_hal_dm_set_snooze_mode_cback); 1169 return (NCI_STATUS_OK); 1170} 1171 1172 1173 1174 1175 1176 1177 1178 1179