1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-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  *  Internal NFC HAL API functions.
23  *
24  ******************************************************************************/
25 #ifndef NFC_HAL_INT_API_H
26 #define NFC_HAL_INT_API_H
27 
28 /****************************************************************************
29 ** Device Configuration definitions
30 ****************************************************************************/
31 
32 #define NFC_HAL_PLL_325_SETCONFIG_PARAM_LEN     (2 + NCI_PARAM_LEN_PLL325_CFG_PARAM)
33 
34 /* Crystal Frequency Index (in 1 KHz) */
35 enum
36 {
37     NFC_HAL_XTAL_INDEX_9600,
38     NFC_HAL_XTAL_INDEX_13000,
39     NFC_HAL_XTAL_INDEX_16200,
40     NFC_HAL_XTAL_INDEX_19200,
41     NFC_HAL_XTAL_INDEX_24000,
42     NFC_HAL_XTAL_INDEX_26000,
43     NFC_HAL_XTAL_INDEX_38400,
44     NFC_HAL_XTAL_INDEX_52000,
45     NFC_HAL_XTAL_INDEX_37400,
46     NFC_HAL_XTAL_INDEX_MAX,
47     NFC_HAL_XTAL_INDEX_SPECIAL = 0xFF
48 };
49 typedef UINT8 tNFC_HAL_XTAL_INDEX;
50 
51 /* Broadcom specific device initialization before sending NCI reset */
52 
53 typedef struct
54 {
55     UINT32                  brcm_hw_id;
56     UINT16                  xtal_freq;
57     UINT8                   xtal_index;
58 } tNFC_HAL_DEV_INIT_XTAL_CFG;
59 
60 #define NFC_HAL_DEV_INIT_MAX_XTAL_CFG       5
61 
62 typedef struct
63 {
64     UINT8                       num_xtal_cfg;
65     tNFC_HAL_DEV_INIT_XTAL_CFG  xtal_cfg[NFC_HAL_DEV_INIT_MAX_XTAL_CFG];
66 } tNFC_HAL_DEV_INIT_CFG;
67 
68 /*****************************************************************************
69 **  Low Power Mode definitions
70 *****************************************************************************/
71 
72 #define NFC_HAL_LP_SNOOZE_MODE_NONE      NFC_SNOOZE_MODE_NONE       /* Snooze mode disabled    */
73 #define NFC_HAL_LP_SNOOZE_MODE_UART      NFC_SNOOZE_MODE_UART       /* Snooze mode for UART    */
74 #define NFC_HAL_LP_SNOOZE_MODE_SPI_I2C   NFC_SNOOZE_MODE_SPI_I2C    /* Snooze mode for SPI/I2C */
75 
76 #define NFC_HAL_LP_ACTIVE_LOW            NFC_SNOOZE_ACTIVE_LOW      /* high to low voltage is asserting */
77 #define NFC_HAL_LP_ACTIVE_HIGH           NFC_SNOOZE_ACTIVE_HIGH     /* low to high voltage is asserting */
78 
79 /*****************************************************************************
80 **  Patch RAM Constants
81 *****************************************************************************/
82 
83 /* patch format type */
84 #define NFC_HAL_PRM_FORMAT_BIN  0x00
85 #define NFC_HAL_PRM_FORMAT_HCD  0x01
86 #define NFC_HAL_PRM_FORMAT_NCD  0x02
87 typedef UINT8 tNFC_HAL_PRM_FORMAT;
88 
89 /*****************************************************************************
90 **  Patch RAM Callback for event notificaton
91 *****************************************************************************/
92 /* Events for tNFC_HAL_PRM_CBACK */
93 enum
94 {
95     NFC_HAL_PRM_CONTINUE_EVT,
96     NFC_HAL_PRM_COMPLETE_EVT,
97     NFC_HAL_PRM_ABORT_EVT,
98     NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT,       /* Patch is invalid (bad version, project id, or chip)  */
99     NFC_HAL_PRM_ABORT_BAD_SIGNATURE_EVT,       /* Patch has invalid signature                          */
100     NFC_HAL_PRM_SPD_GET_PATCHFILE_HDR_EVT,     /* Secure Patch Download: request for patchfile header  */
101     NFC_HAL_PRM_SPD_GET_NEXT_PATCH,            /* Get first command of next patch in patchfile         */
102     NFC_HAL_PRM_ABORT_NO_NVM_EVT               /* nfc_hal_prm_nvm_required is TRUE and NVM is unavail  */
103 };
104 
105 typedef void (tNFC_HAL_PRM_CBACK) (UINT8 event);
106 
107 typedef UINT8 tNFC_HAL_NCI_EVT;     /* MT + Opcode */
108 typedef void (tNFC_HAL_NCI_CBACK) (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data);
109 
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 
114 /*******************************************************************************
115 **
116 ** Function         HAL_NfcPreInitDone
117 **
118 ** Description      Notify that pre-initialization of NFCC is complete
119 **
120 ** Returns          void
121 **
122 *******************************************************************************/
123 void HAL_NfcPreInitDone (tHAL_NFC_STATUS status);
124 
125 /*******************************************************************************
126 **
127 ** Function         HAL_NfcReInit
128 **
129 ** Description      This function is called to restart initialization after REG_PU
130 **                  toggled because of failure to detect NVM type or download patchram.
131 **
132 ** Note             This function should be called only during the HAL init process
133 **
134 ** Returns          HAL_NFC_STATUS_OK if successfully initiated
135 **                  HAL_NFC_STATUS_FAILED otherwise
136 **
137 *******************************************************************************/
138 tHAL_NFC_STATUS HAL_NfcReInit (void);
139 
140 /*******************************************************************************
141 **
142 ** Function         HAL_NfcSetSnoozeMode
143 **
144 ** Description      Set snooze mode
145 **                  snooze_mode
146 **                      NFC_HAL_LP_SNOOZE_MODE_NONE - Snooze mode disabled
147 **                      NFC_HAL_LP_SNOOZE_MODE_UART - Snooze mode for UART
148 **                      NFC_HAL_LP_SNOOZE_MODE_SPI_I2C - Snooze mode for SPI/I2C
149 **
150 **                  idle_threshold_dh/idle_threshold_nfcc
151 **                      Idle Threshold Host in 100ms unit
152 **
153 **                  nfc_wake_active_mode/dh_wake_active_mode
154 **                      NFC_HAL_LP_ACTIVE_LOW - high to low voltage is asserting
155 **                      NFC_HAL_LP_ACTIVE_HIGH - low to high voltage is asserting
156 **
157 **                  p_snooze_cback
158 **                      Notify status of operation
159 **
160 ** Returns          tHAL_NFC_STATUS
161 **
162 *******************************************************************************/
163 tHAL_NFC_STATUS HAL_NfcSetSnoozeMode (UINT8 snooze_mode,
164                                       UINT8 idle_threshold_dh,
165                                       UINT8 idle_threshold_nfcc,
166                                       UINT8 nfc_wake_active_mode,
167                                       UINT8 dh_wake_active_mode,
168                                       tHAL_NFC_STATUS_CBACK *p_snooze_cback);
169 
170 /*******************************************************************************
171 **
172 ** Function         HAL_NfcPrmDownloadStart
173 **
174 ** Description      Initiate patch download
175 **
176 ** Input Params
177 **                  format_type     patch format type
178 **                                  (NFC_HAL_PRM_FORMAT_BIN, NFC_HAL_PRM_FORMAT_HCD, or
179 **                                   NFC_HAL_PRM_FORMAT_NCD)
180 **
181 **                  dest_address    destination adderess (needed for BIN format only)
182 **
183 **                  p_patchram_buf  pointer to patchram buffer. If NULL,
184 **                                  then app must call HAL_NfcPrmDownloadContinue when
185 **                                  NFC_HAL_PRM_CONTINUE_EVT is received, to send the next
186 **                                  segment of patchram
187 **
188 **                  patchram_len    size of p_patchram_buf (if non-NULL)
189 **
190 **                  patchram_delay  The delay after each patch.
191 **                                  If the given value is less than the size of the patchram,
192 **                                  the size of patchram is used instead.
193 **
194 **                  p_cback         callback for download status
195 **
196 **
197 ** Returns          TRUE if successful, otherwise FALSE
198 **
199 **
200 *******************************************************************************/
201 BOOLEAN HAL_NfcPrmDownloadStart (tNFC_HAL_PRM_FORMAT format_type,
202                                  UINT32              dest_address,
203                                  UINT8               *p_patchram_buf,
204                                  UINT32              patchram_len,
205                                  UINT32              patchram_delay,
206                                  tNFC_HAL_PRM_CBACK  *p_cback);
207 
208 /*******************************************************************************
209 **
210 ** Function         HAL_NfcPrmDownloadContinue
211 **
212 ** Description      Send next segment of patchram to controller. Called when
213 **                  NFC_HAL_PRM_CONTINUE_EVT is received.
214 **
215 **                  Only needed if HAL_NfcPrmDownloadStart was called with
216 **                  p_patchram_buf=NULL
217 **
218 ** Input Params     p_patch_data    pointer to patch data
219 **                  patch_data_len  patch data len
220 **
221 ** Returns          TRUE if successful, otherwise FALSE
222 **
223 *******************************************************************************/
224 BOOLEAN HAL_NfcPrmDownloadContinue (UINT8 *p_patch_data,
225                                     UINT16 patch_data_len);
226 
227 /*******************************************************************************
228 **
229 ** Function         HAL_NfcPrmSetI2cPatch
230 **
231 ** Description      Specify patchfile for BCM20791B3 I2C fix. This fix
232 **                  must be downloaded prior to initial patch download for I2C
233 **                  transport
234 **
235 ** Input Params     p_i2c_patchfile_buf: pointer to patch for i2c fix
236 **                  i2c_patchfile_len: length of patch
237 **                  prei2c_delay: the delay before downloading main patch
238 **                                if 0 is given, NFC_HAL_PRM_POST_I2C_FIX_DELAY is used instead.
239 **
240 ** Returns          Nothing
241 **
242 **
243 *******************************************************************************/
244 void HAL_NfcPrmSetI2cPatch (UINT8 *p_i2c_patchfile_buf,
245                       UINT16 i2c_patchfile_len, UINT32 prei2c_delay);
246 
247 /*******************************************************************************
248 **
249 ** Function         HAL_NfcPrmSetSpdNciCmdPayloadSize
250 **
251 ** Description      Set Host-to-NFCC NCI message size for secure patch download
252 **
253 **                  This API must be called before calling HAL_NfcPrmDownloadStart.
254 **                  If the API is not called, then PRM will use the default
255 **                  message size.
256 **
257 **                  Typically, this API is only called for platforms that have
258 **                  message-size limitations in the transport/driver.
259 **
260 **                  Valid message size range: NFC_HAL_PRM_MIN_NCI_CMD_PAYLOAD_SIZE to 255.
261 **
262 ** Returns          HAL_NFC_STATUS_OK if successful
263 **                  HAL_NFC_STATUS_FAILED otherwise
264 **
265 **
266 *******************************************************************************/
267 tHAL_NFC_STATUS HAL_NfcPrmSetSpdNciCmdPayloadSize (UINT8 max_payload_size);
268 
269 /*******************************************************************************
270 **
271 ** Function         HAL_NfcSetMaxRfDataCredits
272 **
273 ** Description      This function sets the maximum RF data credit for HAL.
274 **                  If 0, use the value reported from NFCC.
275 **
276 ** Returns          none
277 **
278 *******************************************************************************/
279 void HAL_NfcSetMaxRfDataCredits (UINT8 max_credits);
280 
281 /*******************************************************************************
282 **
283 ** Function         HAL_NfcSetTraceLevel
284 **
285 ** Description      This function sets the trace level for HAL.  If called with
286 **                  a value of 0xFF, it simply returns the current trace level.
287 **
288 ** Returns          The new or current trace level
289 **
290 *******************************************************************************/
291 UINT8 HAL_NfcSetTraceLevel (UINT8 new_level);
292 
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 
298 #endif /* NFC_HAL_INT_API_H */
299 
300