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