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