• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2 **+-----------------------------------------------------------------------+**
3 **|                                                                       |**
4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
5 **| All rights reserved.                                                  |**
6 **|                                                                       |**
7 **| Redistribution and use in source and binary forms, with or without    |**
8 **| modification, are permitted provided that the following conditions    |**
9 **| are met:                                                              |**
10 **|                                                                       |**
11 **|  * Redistributions of source code must retain the above copyright     |**
12 **|    notice, this list of conditions and the following disclaimer.      |**
13 **|  * Redistributions in binary form must reproduce the above copyright  |**
14 **|    notice, this list of conditions and the following disclaimer in    |**
15 **|    the documentation and/or other materials provided with the         |**
16 **|    distribution.                                                      |**
17 **|  * Neither the name Texas Instruments nor the names of its            |**
18 **|    contributors may be used to endorse or promote products derived    |**
19 **|    from this software without specific prior written permission.      |**
20 **|                                                                       |**
21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
32 **|                                                                       |**
33 **+-----------------------------------------------------------------------+**
34 ****************************************************************************/
35 
36 
37 /*******************************************************************************/
38 /*                                                                             */
39 /*  MODULE:  hwInit.c                                                          */
40 /*  PURPOSE: HwInit module manages the init process of the TNETW, included     */
41 /*           firmware download process. It shall perform Hard Reset the chip   */
42 /*           if possible (this will require a Reset line to be connected to    */
43 /*           the host); Start InterfaceCtrl; Download NVS and FW               */
44 /*                                                                             */
45 /*                                                                             */
46 /*******************************************************************************/
47 
48 #include "paramOut.h"
49 #include "osApi.h"
50 #include "report.h"
51 #include "HwInit.h"
52 #include "HwInit_api.h"
53 
54 #include "whalCommon.h"
55 #include "whalBus_Api.h"
56 #include "shmBus.h"
57 
58 #include "FwEvent_api.h"
59 #include "TNETWIF.h"
60 #include "shmFwCtrl.h"
61 #include "TNETW_Driver.h"
62 #include "TNETW_Driver_api.h"
63 #include "whalHwCtrl.h"
64 
65 #include "whalHwAccess.h"
66 #include "eventMbox_api.h"
67 
68 /* static function */
69 #ifdef USE_RECOVERY
70 static TI_STATUS InitHw_StartInit(TI_HANDLE hHwCtrl);
71 #endif /* USE_RECOVERY */
72 
73 /*******************************************************************************
74 *                       PUBLIC  FUNCTIONS  IMPLEMENTATION                      *
75 ********************************************************************************/
76 
77 
78 /*************************************************************************
79 *                        hwInit_create                              *
80 **************************************************************************
81 * DESCRIPTION:  This function initializes the HwInit module.
82 *
83 * INPUT:        hOs - handle to Os Abstraction Layer
84 *
85 * RETURN:       Handle to the allocated HwInit module
86 *************************************************************************/
hwInit_create(TI_HANDLE hOs)87 TI_HANDLE hwInit_create(TI_HANDLE hOs)
88 {
89 #ifdef USE_RECOVERY
90     hwInit_t *hHwInit;
91 
92     /* allocate HwInit module */
93     hHwInit = os_memoryAlloc(hOs, (sizeof(hwInit_t)));
94 
95     if(!hHwInit)
96     {
97         WLAN_OS_REPORT(("Error allocating the HwInit Module\n"));
98         return NULL;
99     }
100 
101     /* Reset HwInit module */
102     os_memoryZero(hOs, hHwInit, (sizeof(hwInit_t)));
103 
104     hHwInit->hOs = hOs;
105 
106     return(hHwInit);
107 #else
108     return NULL;
109 #endif /* USE_RECOVERY */
110 } /* hwInit_create */
111 
112 
113 /***************************************************************************
114 *                           hwInit_config                             *
115 ****************************************************************************
116 * DESCRIPTION:  This function configures the hwInit module
117 *
118 * RETURNS:      OK - Configuration successful
119 *               NOK - Configuration unsuccessful
120 ***************************************************************************/
hwInit_config(TI_HANDLE hHwInit,TI_HANDLE hReport,TI_HANDLE hTNETWIF)121 TI_STATUS hwInit_config(TI_HANDLE hHwInit,
122                         TI_HANDLE hReport,
123                         TI_HANDLE hTNETWIF)
124 {
125 #ifdef USE_RECOVERY
126     hwInit_t *pHwInit = (hwInit_t *)hHwInit;
127 
128     /* configure modules handles */
129     pHwInit->hReport = hReport;
130     pHwInit->hTNETWIF = hTNETWIF;
131 
132     pHwInit->smState = HW_INIT_STATE_IDLE;
133 
134     WLAN_REPORT_INIT(pHwInit->hReport, HW_INIT_MODULE_LOG,
135         (".....HwInit configured successfully\n"));
136 #endif /* USE_RECOVERY */
137     return OK;
138 
139 } /* hwInit_config */
140 
141 
142 /***************************************************************************
143 *                           hwInit_destroy                            *
144 ****************************************************************************
145 * DESCRIPTION:  This function unload the HwInit module.
146 *
147 * INPUTS:       hHwInit - the object
148 *
149 * OUTPUT:
150 *
151 * RETURNS:      OK - Unload succesfull
152 *               NOK - Unload unsuccesfull
153 ***************************************************************************/
hwInit_destroy(TI_HANDLE hHwInit)154 TI_STATUS hwInit_destroy(TI_HANDLE hHwInit)
155 {
156 #ifdef USE_RECOVERY
157     hwInit_t *pHwInit = (hwInit_t *)hHwInit;
158 
159     /* free HwInit Module */
160     os_memoryFree(pHwInit->hOs, pHwInit, sizeof(hwInit_t));
161 #endif /* USE_RECOVERY */
162     return OK;
163 }
164 
165 /***************************************************************************
166 *                           hwInit_recovery                                *
167 ****************************************************************************
168 * DESCRIPTION:  Start HW init process after recovery.
169 *
170 * INPUTS:       hHwInit - the object
171 *
172 * OUTPUT:
173 *
174 * RETURNS:
175 *    TNETWIF_COMPLETE - if completed, i.e. Synchronous mode.
176 *    TNETWIF_PENDING  - if pending, i.e. Asynchronous mode (callback function will be called).
177 ***************************************************************************/
178 #ifdef USE_RECOVERY
hwInit_recovery(TI_HANDLE hHwInit,TI_HANDLE hHwCtrl,void * funcCB,TI_HANDLE hRecoveryCtrl)179 TI_STATUS hwInit_recovery(TI_HANDLE hHwInit, TI_HANDLE hHwCtrl, void *funcCB, TI_HANDLE hRecoveryCtrl)
180 {
181     hwInit_t *pHwInit = (hwInit_t *)hHwInit;
182     HwCtrl_T *pHwCtrl = (HwCtrl_T *)hHwCtrl;
183 
184     pHwInit->hHwCtrl = hHwCtrl;
185     pHwInit->recoveryProcess = TRUE;
186     pHwInit->hRecoveryCtrl = hRecoveryCtrl;
187     pHwInit->endOfHwInitCB = (EndOfHwInitCB_t)funcCB;
188 
189     eventMbox_Stop(pHwCtrl->hEventMbox);
190 
191     TNETWIF_Start (pHwInit->hTNETWIF, HAL_INIT_MODULE_ID, hHwCtrl, (TNETWIF_callback_t)InitHw_StartInit);
192 
193     return TNETWIF_PENDING;
194 }
195 #endif /* USE_RECOVERY */
196 
197 /****************************************************************************
198  *                      InitHw_FinalizeDownload()
199  ****************************************************************************
200  * DESCRIPTION: Different FinalizeDownload for Init and Recovery. (Don't call
201  *              for "config" functions after recovery).
202  *
203  * INPUTS:  hHwInit - the object
204  *
205  * OUTPUT:  None
206  *
207  * RETURNS: OK or NOK
208  ****************************************************************************/
InitHw_FinalizeDownload(TI_HANDLE hHwInit)209 TI_STATUS InitHw_FinalizeDownload(TI_HANDLE hHwInit)
210 {
211 #ifdef USE_RECOVERY
212     hwInit_t *pHwInit = (hwInit_t *)hHwInit;
213     TI_STATUS status;
214 
215     status = (TI_STATUS)whal_hwCtrl_ConfigHw(pHwInit->hHwCtrl, (void *)pHwInit->endOfHwInitCB, pHwInit->hRecoveryCtrl, TRUE);
216     if (status != OK)
217     {
218         WLAN_REPORT_INFORMATION (pHwInit->hReport, HW_INIT_MODULE_LOG,
219             ("InitHw_FinalizeDownload: whal_hwCtrl_ConfigHw failed\n"));
220         return TNETWIF_ERROR;
221     }
222 #endif /* USE_RECOVERY */
223     return TNETWIF_COMPLETE;
224 
225 }
226 
227 
228 /****************************************************************************
229  *                      InitHw_StartInit()
230  ****************************************************************************
231  * DESCRIPTION: start init process for recovery
232  *
233  * INPUTS:  hHwInit - the object
234  *
235  * OUTPUT:  None
236  *
237  * RETURNS: OK or NOK
238  ****************************************************************************/
239 #ifdef USE_RECOVERY
InitHw_StartInit(TI_HANDLE hHwCtrl)240 static TI_STATUS InitHw_StartInit(TI_HANDLE hHwCtrl)
241 {
242     HwCtrl_T *pHwCtrl = (HwCtrl_T *)hHwCtrl;
243     WlanParams_T *pWlanParams;
244     BootAttr_T BootAttr;
245     TI_STATUS retStatus;
246 
247     whalBus_T *pWhalBus;
248     PUINT8  FwBuf, EEpromBuf;
249     UINT32  FwSize, EEpromSize;
250     UINT32 *pWLAN_Images[4];
251 
252     pWlanParams = whal_ParamsGetWlanParams(pHwCtrl->pWhalParams);
253 
254     BootAttr.MacClock          = pWlanParams->MacClock;
255     BootAttr.ArmClock          = pWlanParams->ArmClock;
256 
257     {
258         /* Get the FW image */
259         os_getFirmwareImage (pHwCtrl->hOs, &FwBuf, &FwSize, 0);
260         os_getRadioImage (pHwCtrl->hOs, &EEpromBuf, &EEpromSize, 0);
261         pWhalBus = (whalBus_T *)pHwCtrl->hWhalBus;
262         pWLAN_Images[0] = (UINT32 *)FwBuf;
263         pWLAN_Images[1] = (UINT32 *)FwSize;
264         pWLAN_Images[2] = (UINT32 *)EEpromBuf;
265         pWLAN_Images[3] = (UINT32 *)EEpromSize;
266 
267         pHwCtrl->uFwBuf = (UINT32)pWLAN_Images[0]; /* Firmware Image ptr */
268         pHwCtrl->uFwAddr = (UINT32)pWLAN_Images[1]; /* Firmware Image length */
269         pHwCtrl->uEEEPROMBuf = (UINT32)pWLAN_Images[2]; /* EEPROM Image ptr */
270         pHwCtrl->uEEEPROMLen = (UINT32)pWLAN_Images[3]; /* EEPROM Image length */
271     }
272 
273     /* Reset the TNETW by the reset line */
274     WLAN_OS_REPORT(("HARD RESET before\n"));
275     os_hardResetTnetw ();
276     WLAN_OS_REPORT(("HARD RESET after\n"));
277 
278     pWhalBus->recoveryProcess = TRUE;
279 
280     /* SDIO_enumerate */
281     {
282         TNETWIF_t *pTNETWIF = (TNETWIF_t *)(pWhalBus->hTNETWIF);
283         whal_hwAccess_ReConfig(pTNETWIF->hHwAccess); /* SDIO enumerate*/
284     }
285     /* set the working partition to its "running" mode offset */
286 #if (defined(HW_ACCESS_SDIO)|defined(HW_ACCESS_WSPI))
287 
288     TNETWIF_SetPartitions (pWhalBus->hTNETWIF, HW_ACCESS_DOWNLOAD, HW_ACCESS_DOWN_PART0_ADDR);
289 
290 #endif
291     TNETWIF_RegSetBitVal(pWhalBus->hTNETWIF,  ACX_REG_ECPU_CONTROL, ECPU_CONTROL_HALT);
292 
293     retStatus = whalBus_FwCtrl_Boot (pHwCtrl->hWhalBus, (TI_HANDLE)pHwCtrl, &BootAttr);
294 
295     /* release FW and NVS images */
296     /*
297      * Note: This is done assuming the boot process is complelty synchronous!!!
298      * Also, this is not done in GWSI becaues in GWSI these functions are not defined,
299      * because the load process is different. This has also to be fixed...
300      */
301     os_closeFirmwareImage (pHwCtrl->hOs);
302     os_closeRadioImage (pHwCtrl->hOs);
303 
304     return(retStatus);
305 }
306 #endif /* USE_RECOVERY */
307 
308 
309