| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2008, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bhab_3520_priv.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/2 $ |
|---|
| 12 | * $brcm_Date: 10/27/08 11:11a $ |
|---|
| 13 | * |
|---|
| 14 | * |
|---|
| 15 | * Revision History: |
|---|
| 16 | * |
|---|
| 17 | * $brcm_Log: /magnum/basemodules/hab/3520/bhab_3520_priv.h $ |
|---|
| 18 | * |
|---|
| 19 | * Hydra_Software_Devel/2 10/27/08 11:11a gmohile |
|---|
| 20 | * PR 47386 : Add temination byte for send hab command |
|---|
| 21 | * |
|---|
| 22 | * Hydra_Software_Devel/1 10/20/08 2:51p gmohile |
|---|
| 23 | * PR 47386 : Checkin initial version |
|---|
| 24 | * |
|---|
| 25 | ***************************************************************************/ |
|---|
| 26 | |
|---|
| 27 | #ifndef BHAB_3520_PRIV_H |
|---|
| 28 | #define BHAB_3520_PRIV_H |
|---|
| 29 | |
|---|
| 30 | #include "bstd.h" |
|---|
| 31 | #include "bi2c.h" |
|---|
| 32 | #include "bkni.h" |
|---|
| 33 | #include "bhab_priv.h" |
|---|
| 34 | |
|---|
| 35 | #include "bchp_3520.h" |
|---|
| 36 | |
|---|
| 37 | #define DEVICE(val) BCM3520_##val |
|---|
| 38 | |
|---|
| 39 | #define BHAB_WINDOW_IRAM 0x00000000 |
|---|
| 40 | #define BHAB_WINDOW_IROM 0x00008000 |
|---|
| 41 | #define BHAB_WINDOW_HAB 0x00010000 |
|---|
| 42 | #define BHAB_WINDOW_IDATA 0x00010400 |
|---|
| 43 | |
|---|
| 44 | #define BHAB_IRAM_SIZE 0x8000 |
|---|
| 45 | #define BHAB_IROM_SIZE 0x8000 |
|---|
| 46 | #define BHAB_MEM_SIZE 0x00010000 |
|---|
| 47 | #define BHAB_HAB_SIZE 0x80 |
|---|
| 48 | |
|---|
| 49 | #define BHAB_P_ACQUIRE_MUTEX(handle) BKNI_AcquireMutex(((BHAB_3520_P_Handle *)(handle->pImpl))->hMutex) |
|---|
| 50 | #define BHAB_P_RELEASE_MUTEX(handle) BKNI_ReleaseMutex(((BHAB_3520_P_Handle *)(handle->pImpl))->hMutex) |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | typedef struct BHAB_P_CallbackInfo |
|---|
| 54 | { |
|---|
| 55 | BHAB_IntCallbackFunc func; |
|---|
| 56 | void * pParm1; |
|---|
| 57 | int parm2 ; |
|---|
| 58 | } BHAB_P_CallbackInfo; |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | typedef struct BHAB_3520_P_Handle |
|---|
| 62 | { |
|---|
| 63 | BREG_I2C_Handle hRegister; /* handle to the master I2C device used to access registers */ |
|---|
| 64 | BKNI_EventHandle hInterruptEvent; /* interrupt event handle */ |
|---|
| 65 | BKNI_EventHandle hApiEvent; /* API event handle */ |
|---|
| 66 | BKNI_EventHandle hLockChangeEvent; /* change of lock status event handle */ |
|---|
| 67 | BKNI_EventHandle hInitDoneEvent; /* AP initialization done event handle */ |
|---|
| 68 | BKNI_EventHandle hHabDoneEvent; /* HAB done event handle */ |
|---|
| 69 | BKNI_MutexHandle hMutex; /* Mutex handle for serialization */ |
|---|
| 70 | uint8_t last_page_16_15; /* most recent position of the 128 byte window into the AP address space */ |
|---|
| 71 | uint8_t last_page_14_7; /* most recent position of the 128 byte window into the AP address space */ |
|---|
| 72 | uint8_t last_mbox_15_8; /* most recent position of the IO MBOX window */ |
|---|
| 73 | BHAB_P_CallbackInfo InterruptCallbackInfo[BHAB_DevId_eMax]; |
|---|
| 74 | } BHAB_3520_P_Handle; |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | /****************************************************************************** |
|---|
| 78 | Summary: |
|---|
| 79 | Enables/Disables the L1 host interrupt. |
|---|
| 80 | Description: |
|---|
| 81 | Enables/Disables the L1 host interrupt by calling the application-supplied |
|---|
| 82 | callback routine the the BHAB settings. |
|---|
| 83 | Returns: |
|---|
| 84 | BERR_Code |
|---|
| 85 | ******************************************************************************/ |
|---|
| 86 | BERR_Code BHAB_3520_P_EnableHostInterrupt( |
|---|
| 87 | BHAB_Handle handle, /* [in] BHAB PI handle */ |
|---|
| 88 | bool bEnable /* [in] true=enables the L1 interrupt on the host processor */ |
|---|
| 89 | ); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | /****************************************************************************** |
|---|
| 93 | Summary: |
|---|
| 94 | Disables all host interrupts. |
|---|
| 95 | Description: |
|---|
| 96 | This function clears the host interrupt enable bits on the BCM3520. |
|---|
| 97 | Returns: |
|---|
| 98 | BERR_Code |
|---|
| 99 | ******************************************************************************/ |
|---|
| 100 | BERR_Code BHAB_3520_P_DisableInterrupts( |
|---|
| 101 | BHAB_Handle handle /* [in] BHAB Handle */ |
|---|
| 102 | ); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | /****************************************************************************** |
|---|
| 106 | Summary: |
|---|
| 107 | Enables the AP initialization done interrupt. |
|---|
| 108 | Description: |
|---|
| 109 | This function is called by the BHAB_InitAp(). |
|---|
| 110 | Returns: |
|---|
| 111 | BERR_Code |
|---|
| 112 | ******************************************************************************/ |
|---|
| 113 | BERR_Code BHAB_3520_P_EnableInitDoneInterrupt( |
|---|
| 114 | BHAB_Handle handle /* [in] BHAB Handle */ |
|---|
| 115 | ); |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | /****************************************************************************** |
|---|
| 119 | Summary: |
|---|
| 120 | Waits for a BHAB event. |
|---|
| 121 | Description: |
|---|
| 122 | This function waits for an interrupt within the given timeout period. Any |
|---|
| 123 | interrupts are then decoded via I2C. If the given event has been signaled, |
|---|
| 124 | then this function returns BERR_SUCCESS. |
|---|
| 125 | Returns: |
|---|
| 126 | BERR_Code |
|---|
| 127 | ******************************************************************************/ |
|---|
| 128 | BERR_Code BHAB_3520_P_WaitForEvent( |
|---|
| 129 | BHAB_Handle handle, /* [in] BHAB Handle */ |
|---|
| 130 | BKNI_EventHandle hEvent, /* [in] event to wait on */ |
|---|
| 131 | int timeoutMsec /* [in] timeout in milliseconds */ |
|---|
| 132 | ); |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | /****************************************************************************** |
|---|
| 136 | Summary: |
|---|
| 137 | Runs the AP. |
|---|
| 138 | Description: |
|---|
| 139 | This function takes the AP to out of reset/idle state and starts running. |
|---|
| 140 | Returns: |
|---|
| 141 | BERR_Code |
|---|
| 142 | ******************************************************************************/ |
|---|
| 143 | BERR_Code BHAB_3520_P_RunAp( |
|---|
| 144 | BHAB_Handle handle /* [in] BHAB PI Handle */ |
|---|
| 145 | ); |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | /****************************************************************************** |
|---|
| 149 | Summary: |
|---|
| 150 | Resets the AP. |
|---|
| 151 | Description: |
|---|
| 152 | This function puts the AP in reset state. |
|---|
| 153 | Returns: |
|---|
| 154 | BERR_Code |
|---|
| 155 | ******************************************************************************/ |
|---|
| 156 | BERR_Code BHAB_3520_P_ResetAp( |
|---|
| 157 | BHAB_Handle handle /* [in] BHAB PI Handle */ |
|---|
| 158 | ); |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | /****************************************************************************** |
|---|
| 162 | Summary: |
|---|
| 163 | Positions the 128 byte window in the AP address space. |
|---|
| 164 | Description: |
|---|
| 165 | The last 128-byte window position is stored in the BHAB_Handle struct, |
|---|
| 166 | so I2C accesses will occur only if the window has moved. |
|---|
| 167 | Returns: |
|---|
| 168 | BERR_Code |
|---|
| 169 | ******************************************************************************/ |
|---|
| 170 | BERR_Code BHAB_3520_P_SetApWindow( |
|---|
| 171 | BHAB_Handle handle, /* [in] BHAB PI Handle */ |
|---|
| 172 | uint32_t window /* [in] base address of the 128-byte window */ |
|---|
| 173 | ); |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | /****************************************************************************** |
|---|
| 177 | Summary: |
|---|
| 178 | Reads from the host access buffer. |
|---|
| 179 | Description: |
|---|
| 180 | This function positions the 128 byte window in the AP address space to the |
|---|
| 181 | host access buffer area. (n) bytes are then read into (buf) starting from |
|---|
| 182 | the given HAB (offset) address. |
|---|
| 183 | Returns: |
|---|
| 184 | BERR_Code |
|---|
| 185 | ******************************************************************************/ |
|---|
| 186 | BERR_Code BHAB_3520_P_ReadHab( |
|---|
| 187 | BHAB_Handle handle, /* [in] BHAB PI Handle */ |
|---|
| 188 | uint8_t offset, /* [in] starting offset within the HAB to read */ |
|---|
| 189 | uint8_t *buf, /* [out] holds the data read */ |
|---|
| 190 | uint8_t n /* [in] number of bytes to read */ |
|---|
| 191 | ); |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | /****************************************************************************** |
|---|
| 195 | Summary: |
|---|
| 196 | Writes to the host access buffer. |
|---|
| 197 | Description: |
|---|
| 198 | This function positions the 128 byte window in the AP address space to the |
|---|
| 199 | host access buffer area. (n) bytes in (buf) are then written starting from |
|---|
| 200 | the given HAB (offset) address. |
|---|
| 201 | Returns: |
|---|
| 202 | BERR_Code |
|---|
| 203 | ******************************************************************************/ |
|---|
| 204 | BERR_Code BHAB_3520_P_WriteHab( |
|---|
| 205 | BHAB_Handle handle, /* [in] BHAB PI Handle */ |
|---|
| 206 | uint8_t offset, /* [in] starting offset in the HAB to write */ |
|---|
| 207 | uint8_t *buf, /* [in] specifies the data to write */ |
|---|
| 208 | uint8_t n /* [in] number of bytes to write */ |
|---|
| 209 | ); |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | /****************************************************************************** |
|---|
| 213 | Summary: |
|---|
| 214 | This function sends the command already written in the HAB. |
|---|
| 215 | Description: |
|---|
| 216 | This function asserts HABR, waits for the AP to release the HAB, then |
|---|
| 217 | optionally checks for a service acknowlegement from the AP. If bCheckForAck |
|---|
| 218 | is true, then read_len must be greater than 0. This function is called by |
|---|
| 219 | BHAB_P_SendHabCommand(). |
|---|
| 220 | Returns: |
|---|
| 221 | BERR_Code |
|---|
| 222 | ******************************************************************************/ |
|---|
| 223 | BERR_Code BHAB_3520_P_ServiceHab( |
|---|
| 224 | BHAB_Handle h, /* [in] BHAB Handle */ |
|---|
| 225 | uint8_t *read_buf, /* [out] holds the data read from the HAB */ |
|---|
| 226 | uint8_t read_len, /* [in] number of bytes to read from the HAB */ |
|---|
| 227 | bool bCheckForAck, /* [in] true = determine if the AP has serviced the command */ |
|---|
| 228 | uint8_t ack_byte /* [in] value of the ack byte to expect */ |
|---|
| 229 | ); |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | /****************************************************************************** |
|---|
| 233 | Summary: |
|---|
| 234 | Sets certain BKNI_Events based on the source of the BCM3520 host interrupt. |
|---|
| 235 | Description: |
|---|
| 236 | This function reads and clears the BCM3520 interrupt status registers, |
|---|
| 237 | clears the enable mask of the interrupts, and sets BKNI_Events based on the |
|---|
| 238 | interrupt sources. |
|---|
| 239 | Returns: |
|---|
| 240 | BERR_Code |
|---|
| 241 | ******************************************************************************/ |
|---|
| 242 | BERR_Code BHAB_3520_P_DecodeInterrupt( |
|---|
| 243 | BHAB_Handle handle /* [in] BHAB Handle */ |
|---|
| 244 | ); |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | /****************************************************************************** |
|---|
| 249 | Summary: |
|---|
| 250 | Returns the BERR_Code corresponding to the given BHAB_ApStatus. |
|---|
| 251 | Description: |
|---|
| 252 | This function returns ths BERR_Code of any errors in the given BHAB_ApStatus. |
|---|
| 253 | Returns: |
|---|
| 254 | BERR_Code |
|---|
| 255 | ******************************************************************************/ |
|---|
| 256 | BERR_Code BHAB_3520_P_DecodeError( |
|---|
| 257 | BHAB_Handle h, /* [in] BHAB PI Handle */ |
|---|
| 258 | BHAB_ApStatus *pApStatus /* [in] AP status returned by BHAB_GetApStatus */ |
|---|
| 259 | ); |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | /****************************************************************************** |
|---|
| 263 | Summary: |
|---|
| 264 | This function checks if the host is currently permitted to send an HAB |
|---|
| 265 | command. |
|---|
| 266 | Description: |
|---|
| 267 | The HAB is available to the host if all 3 conditions currently apply: |
|---|
| 268 | 1) The AP is running. |
|---|
| 269 | 2) The AP has initialized. |
|---|
| 270 | 3) The AP is not currently servicing the HAB (i.e. HABR bit is 0) |
|---|
| 271 | Returns: |
|---|
| 272 | BERR_Code - BERR_SUCCESS if HAB is available, otherwise BERR_Code is reason |
|---|
| 273 | why HAB is not available |
|---|
| 274 | ******************************************************************************/ |
|---|
| 275 | BERR_Code BHAB_3520_P_CheckHab( |
|---|
| 276 | BHAB_Handle h /* [in] BHAB PI Handle */ |
|---|
| 277 | ); |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | /****************** BCM3520 implementation of API functions *****************/ |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | BERR_Code BHAB_3520_Open( |
|---|
| 286 | BHAB_Handle *handle, /* [out] BHAB handle */ |
|---|
| 287 | void *pReg, /* [in] pointer ot i2c or spi handle */ |
|---|
| 288 | const BHAB_Settings *pDefSettings /* [in] Default Settings */ |
|---|
| 289 | ); |
|---|
| 290 | |
|---|
| 291 | BERR_Code BHAB_3520_Close( |
|---|
| 292 | BHAB_Handle h /* [in] BHAB handle */ |
|---|
| 293 | ); |
|---|
| 294 | |
|---|
| 295 | BERR_Code BHAB_3520_InitAp( |
|---|
| 296 | BHAB_Handle h, /* [in] BHAB handle */ |
|---|
| 297 | const uint8_t *pImage /* [in] pointer to AP microcode image */ |
|---|
| 298 | ); |
|---|
| 299 | |
|---|
| 300 | BERR_Code BHAB_3520_GetApStatus( |
|---|
| 301 | BHAB_Handle handle, /* [in] HAB device handle */ |
|---|
| 302 | BHAB_ApStatus *pStatus /* [out] AP status */ |
|---|
| 303 | ); |
|---|
| 304 | |
|---|
| 305 | BERR_Code BHAB_3520_GetApVersion( |
|---|
| 306 | BHAB_Handle handle, /* [in] BHAB handle */ |
|---|
| 307 | uint16_t *pChipId, /* [out] chip id */ |
|---|
| 308 | uint16_t *pChipVer, /* [out] chip revision number */ |
|---|
| 309 | uint8_t *pApVer, /* [out] AP microcode version */ |
|---|
| 310 | uint8_t *pScrVer, /* [out] acquisition script version */ |
|---|
| 311 | uint8_t *pCfgVer /* [out] host configuration version */ |
|---|
| 312 | ); |
|---|
| 313 | |
|---|
| 314 | BERR_Code BHAB_3520_ReadRegister( |
|---|
| 315 | BHAB_Handle handle, /* [in] BHAB handle */ |
|---|
| 316 | uint32_t reg, /* [in] address of register to read */ |
|---|
| 317 | uint32_t *val /* [in] contains data that was read */ |
|---|
| 318 | ); |
|---|
| 319 | |
|---|
| 320 | BERR_Code BHAB_3520_WriteRegister( |
|---|
| 321 | BHAB_Handle handle, /* [in] BHAB handle */ |
|---|
| 322 | uint32_t reg, /* [in] address of register to read */ |
|---|
| 323 | uint32_t *val /* [in] contains data that was read */ |
|---|
| 324 | ); |
|---|
| 325 | |
|---|
| 326 | BERR_Code BHAB_3520_ReadMemory( |
|---|
| 327 | BHAB_Handle h, /* [in] BHAB PI Handle */ |
|---|
| 328 | uint16_t addr, /* [in] starting address */ |
|---|
| 329 | uint8_t *buf, /* [out] holds the data read */ |
|---|
| 330 | uint16_t n /* [in] number of bytes to read */ |
|---|
| 331 | ); |
|---|
| 332 | |
|---|
| 333 | BERR_Code BHAB_3520_WriteMemory( |
|---|
| 334 | BHAB_Handle handle, /* [in] BHAB PI Handle */ |
|---|
| 335 | uint16_t addr, /* [in] starting address in AP RAM */ |
|---|
| 336 | uint8_t *buf, /* [in] specifies the data to write */ |
|---|
| 337 | uint16_t n /* [in] number of bytes to write */ |
|---|
| 338 | ); |
|---|
| 339 | |
|---|
| 340 | BERR_Code BHAB_3520_ReadMbox( |
|---|
| 341 | BHAB_Handle handle, /* [in] BHAB PI Handle */ |
|---|
| 342 | uint16_t reg, /* [in] RBUS register address */ |
|---|
| 343 | uint32_t *val /* [out] value read from register */ |
|---|
| 344 | ); |
|---|
| 345 | |
|---|
| 346 | BERR_Code BHAB_3520_WriteMbox( |
|---|
| 347 | BHAB_Handle handle, /* [in] BHAB PI Handle */ |
|---|
| 348 | uint16_t reg, /* [in] RBUS register address */ |
|---|
| 349 | uint32_t *val /* [in] value to write */ |
|---|
| 350 | ); |
|---|
| 351 | |
|---|
| 352 | BERR_Code BHAB_3520_HandleInterrupt_isr( |
|---|
| 353 | BHAB_Handle handle /* [in] BHAB handle */ |
|---|
| 354 | ); |
|---|
| 355 | |
|---|
| 356 | BERR_Code BHAB_3520_ProcessInterruptEvent( |
|---|
| 357 | BHAB_Handle handle /* [in] HAB device handle */ |
|---|
| 358 | ); |
|---|
| 359 | |
|---|
| 360 | BERR_Code BHAB_3520_EnableLockInterrupt( |
|---|
| 361 | BHAB_Handle handle, /* [in] BHAB Handle */ |
|---|
| 362 | BHAB_DevId eDevId, /* [in] Device ID */ |
|---|
| 363 | bool bEnable /* [in] true = enable lock interrupts, false = disables lock interrupts */ |
|---|
| 364 | ); |
|---|
| 365 | |
|---|
| 366 | BERR_Code BHAB_3520_InstallInterruptCallback( |
|---|
| 367 | BHAB_Handle handle, /* [in] BHAB handle */ |
|---|
| 368 | BHAB_DevId eDevId, /* [in] Device ID */ |
|---|
| 369 | BHAB_InterruptType eInterruptType, /* [in] Id for Interrupt to install the callback*/ |
|---|
| 370 | BHAB_IntCallbackFunc fCallBack, /* [in] Callback function pointer */ |
|---|
| 371 | void * pParm1, /* [in] Paramater1 for callback function*/ |
|---|
| 372 | int parm2 /* [in] Paramater2 for callback function*/ |
|---|
| 373 | ); |
|---|
| 374 | |
|---|
| 375 | BERR_Code BHAB_3520_UnInstallInterruptCallback( |
|---|
| 376 | BHAB_Handle handle, /* [in] BHAB handle */ |
|---|
| 377 | BHAB_DevId eDevId, /* [in] Device ID */ |
|---|
| 378 | BHAB_InterruptType eInterruptType /* [in] Id for Interrupt to uninstall the callback*/ |
|---|
| 379 | ); |
|---|
| 380 | |
|---|
| 381 | BERR_Code BHAB_3520_SendHabCommand( |
|---|
| 382 | BHAB_Handle h, /* [in] BHAB PI Handle */ |
|---|
| 383 | uint8_t *write_buf, /* [in] specifies the HAB command to send */ |
|---|
| 384 | uint8_t write_len, /* [in] number of bytes in the HAB command */ |
|---|
| 385 | uint8_t *read_buf, /* [out] holds the data read from the HAB */ |
|---|
| 386 | uint8_t read_len, /* [in] number of bytes to read from the HAB */ |
|---|
| 387 | bool bCheckForAck, /* [in] true = determine if the AP has serviced the command */ |
|---|
| 388 | bool bInsertTermination /* [in] true = insert termination byte 0x00 in write buffer at read_len position */ |
|---|
| 389 | ); |
|---|
| 390 | |
|---|
| 391 | BERR_Code BHAB_3520_GetLockStateChangeEventHandle( |
|---|
| 392 | BHAB_Handle handle, /* [in] BHAB handle */ |
|---|
| 393 | BKNI_EventHandle *hEvent /* [out] lock event handle */ |
|---|
| 394 | ); |
|---|
| 395 | |
|---|
| 396 | BERR_Code BHAB_3520_GetInterruptEventHandle( |
|---|
| 397 | BHAB_Handle handle, /* [in] BHAB handle */ |
|---|
| 398 | BKNI_EventHandle *hEvent /* [out] interrupt event handle */ |
|---|
| 399 | ); |
|---|
| 400 | |
|---|
| 401 | #endif |
|---|