PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/TNETW_Driver/FW_Transfer/HwInit/HwInit.c

http://github.com/CyanogenMod/cm-kernel
C | 308 lines | 132 code | 49 blank | 127 comment | 3 complexity | 00668ddcd3af0f3f4716d4fd8bc4c28c MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  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. /* MODULE: hwInit.c */
  38. /* PURPOSE: HwInit module manages the init process of the TNETW, included */
  39. /* firmware download process. It shall perform Hard Reset the chip */
  40. /* if possible (this will require a Reset line to be connected to */
  41. /* the host); Start InterfaceCtrl; Download NVS and FW */
  42. /* */
  43. /* */
  44. /*******************************************************************************/
  45. #include "paramOut.h"
  46. #include "osApi.h"
  47. #include "report.h"
  48. #include "HwInit.h"
  49. #include "HwInit_api.h"
  50. #include "whalCommon.h"
  51. #include "whalBus_Api.h"
  52. #include "shmBus.h"
  53. #include "FwEvent_api.h"
  54. #include "TNETWIF.h"
  55. #include "shmFwCtrl.h"
  56. #include "TNETW_Driver.h"
  57. #include "TNETW_Driver_api.h"
  58. #include "whalHwCtrl.h"
  59. #include "whalHwAccess.h"
  60. #include "eventMbox_api.h"
  61. /* static function */
  62. #ifdef USE_RECOVERY
  63. static TI_STATUS InitHw_StartInit(TI_HANDLE hHwCtrl);
  64. #endif /* USE_RECOVERY */
  65. /*******************************************************************************
  66. * PUBLIC FUNCTIONS IMPLEMENTATION *
  67. ********************************************************************************/
  68. /*************************************************************************
  69. * hwInit_create *
  70. **************************************************************************
  71. * DESCRIPTION: This function initializes the HwInit module.
  72. *
  73. * INPUT: hOs - handle to Os Abstraction Layer
  74. *
  75. * RETURN: Handle to the allocated HwInit module
  76. *************************************************************************/
  77. TI_HANDLE hwInit_create(TI_HANDLE hOs)
  78. {
  79. #ifdef USE_RECOVERY
  80. hwInit_t *hHwInit;
  81. /* allocate HwInit module */
  82. hHwInit = os_memoryAlloc(hOs, (sizeof(hwInit_t)));
  83. if(!hHwInit)
  84. {
  85. WLAN_OS_REPORT(("Error allocating the HwInit Module\n"));
  86. return NULL;
  87. }
  88. /* Reset HwInit module */
  89. os_memoryZero(hOs, hHwInit, (sizeof(hwInit_t)));
  90. hHwInit->hOs = hOs;
  91. return(hHwInit);
  92. #else
  93. return NULL;
  94. #endif /* USE_RECOVERY */
  95. } /* hwInit_create */
  96. /***************************************************************************
  97. * hwInit_config *
  98. ****************************************************************************
  99. * DESCRIPTION: This function configures the hwInit module
  100. *
  101. * RETURNS: OK - Configuration successful
  102. * NOK - Configuration unsuccessful
  103. ***************************************************************************/
  104. TI_STATUS hwInit_config(TI_HANDLE hHwInit,
  105. TI_HANDLE hReport,
  106. TI_HANDLE hTNETWIF)
  107. {
  108. #ifdef USE_RECOVERY
  109. hwInit_t *pHwInit = (hwInit_t *)hHwInit;
  110. /* configure modules handles */
  111. pHwInit->hReport = hReport;
  112. pHwInit->hTNETWIF = hTNETWIF;
  113. pHwInit->smState = HW_INIT_STATE_IDLE;
  114. WLAN_REPORT_INIT(pHwInit->hReport, HW_INIT_MODULE_LOG,
  115. (".....HwInit configured successfully\n"));
  116. #endif /* USE_RECOVERY */
  117. return OK;
  118. } /* hwInit_config */
  119. /***************************************************************************
  120. * hwInit_destroy *
  121. ****************************************************************************
  122. * DESCRIPTION: This function unload the HwInit module.
  123. *
  124. * INPUTS: hHwInit - the object
  125. *
  126. * OUTPUT:
  127. *
  128. * RETURNS: OK - Unload succesfull
  129. * NOK - Unload unsuccesfull
  130. ***************************************************************************/
  131. TI_STATUS hwInit_destroy(TI_HANDLE hHwInit)
  132. {
  133. #ifdef USE_RECOVERY
  134. hwInit_t *pHwInit = (hwInit_t *)hHwInit;
  135. /* free HwInit Module */
  136. os_memoryFree(pHwInit->hOs, pHwInit, sizeof(hwInit_t));
  137. #endif /* USE_RECOVERY */
  138. return OK;
  139. }
  140. /***************************************************************************
  141. * hwInit_recovery *
  142. ****************************************************************************
  143. * DESCRIPTION: Start HW init process after recovery.
  144. *
  145. * INPUTS: hHwInit - the object
  146. *
  147. * OUTPUT:
  148. *
  149. * RETURNS:
  150. * TNETWIF_COMPLETE - if completed, i.e. Synchronous mode.
  151. * TNETWIF_PENDING - if pending, i.e. Asynchronous mode (callback function will be called).
  152. ***************************************************************************/
  153. #ifdef USE_RECOVERY
  154. TI_STATUS hwInit_recovery(TI_HANDLE hHwInit, TI_HANDLE hHwCtrl, void *funcCB, TI_HANDLE hRecoveryCtrl)
  155. {
  156. hwInit_t *pHwInit = (hwInit_t *)hHwInit;
  157. HwCtrl_T *pHwCtrl = (HwCtrl_T *)hHwCtrl;
  158. pHwInit->hHwCtrl = hHwCtrl;
  159. pHwInit->recoveryProcess = TRUE;
  160. pHwInit->hRecoveryCtrl = hRecoveryCtrl;
  161. pHwInit->endOfHwInitCB = (EndOfHwInitCB_t)funcCB;
  162. eventMbox_Stop(pHwCtrl->hEventMbox);
  163. TNETWIF_Start (pHwInit->hTNETWIF, HAL_INIT_MODULE_ID, hHwCtrl, (TNETWIF_callback_t)InitHw_StartInit);
  164. return TNETWIF_PENDING;
  165. }
  166. #endif /* USE_RECOVERY */
  167. /****************************************************************************
  168. * InitHw_FinalizeDownload()
  169. ****************************************************************************
  170. * DESCRIPTION: Different FinalizeDownload for Init and Recovery. (Don't call
  171. * for "config" functions after recovery).
  172. *
  173. * INPUTS: hHwInit - the object
  174. *
  175. * OUTPUT: None
  176. *
  177. * RETURNS: OK or NOK
  178. ****************************************************************************/
  179. TI_STATUS InitHw_FinalizeDownload(TI_HANDLE hHwInit)
  180. {
  181. #ifdef USE_RECOVERY
  182. hwInit_t *pHwInit = (hwInit_t *)hHwInit;
  183. TI_STATUS status;
  184. status = (TI_STATUS)whal_hwCtrl_ConfigHw(pHwInit->hHwCtrl, (void *)pHwInit->endOfHwInitCB, pHwInit->hRecoveryCtrl, TRUE);
  185. if (status != OK)
  186. {
  187. WLAN_REPORT_INFORMATION (pHwInit->hReport, HW_INIT_MODULE_LOG,
  188. ("InitHw_FinalizeDownload: whal_hwCtrl_ConfigHw failed\n"));
  189. return TNETWIF_ERROR;
  190. }
  191. #endif /* USE_RECOVERY */
  192. return TNETWIF_COMPLETE;
  193. }
  194. /****************************************************************************
  195. * InitHw_StartInit()
  196. ****************************************************************************
  197. * DESCRIPTION: start init process for recovery
  198. *
  199. * INPUTS: hHwInit - the object
  200. *
  201. * OUTPUT: None
  202. *
  203. * RETURNS: OK or NOK
  204. ****************************************************************************/
  205. #ifdef USE_RECOVERY
  206. static TI_STATUS InitHw_StartInit(TI_HANDLE hHwCtrl)
  207. {
  208. HwCtrl_T *pHwCtrl = (HwCtrl_T *)hHwCtrl;
  209. WlanParams_T *pWlanParams;
  210. BootAttr_T BootAttr;
  211. TI_STATUS retStatus;
  212. whalBus_T *pWhalBus;
  213. PUINT8 FwBuf, EEpromBuf;
  214. UINT32 FwSize, EEpromSize;
  215. UINT32 *pWLAN_Images[4];
  216. pWlanParams = whal_ParamsGetWlanParams(pHwCtrl->pWhalParams);
  217. BootAttr.MacClock = pWlanParams->MacClock;
  218. BootAttr.ArmClock = pWlanParams->ArmClock;
  219. {
  220. /* Get the FW image */
  221. os_getFirmwareImage (pHwCtrl->hOs, &FwBuf, &FwSize, 0);
  222. os_getRadioImage (pHwCtrl->hOs, &EEpromBuf, &EEpromSize, 0);
  223. pWhalBus = (whalBus_T *)pHwCtrl->hWhalBus;
  224. pWLAN_Images[0] = (UINT32 *)FwBuf;
  225. pWLAN_Images[1] = (UINT32 *)FwSize;
  226. pWLAN_Images[2] = (UINT32 *)EEpromBuf;
  227. pWLAN_Images[3] = (UINT32 *)EEpromSize;
  228. pHwCtrl->uFwBuf = (UINT32)pWLAN_Images[0]; /* Firmware Image ptr */
  229. pHwCtrl->uFwAddr = (UINT32)pWLAN_Images[1]; /* Firmware Image length */
  230. pHwCtrl->uEEEPROMBuf = (UINT32)pWLAN_Images[2]; /* EEPROM Image ptr */
  231. pHwCtrl->uEEEPROMLen = (UINT32)pWLAN_Images[3]; /* EEPROM Image length */
  232. }
  233. /* Reset the TNETW by the reset line */
  234. WLAN_OS_REPORT(("HARD RESET before\n"));
  235. os_hardResetTnetw ();
  236. WLAN_OS_REPORT(("HARD RESET after\n"));
  237. pWhalBus->recoveryProcess = TRUE;
  238. /* SDIO_enumerate */
  239. {
  240. TNETWIF_t *pTNETWIF = (TNETWIF_t *)(pWhalBus->hTNETWIF);
  241. whal_hwAccess_ReConfig(pTNETWIF->hHwAccess); /* SDIO enumerate*/
  242. }
  243. /* set the working partition to its "running" mode offset */
  244. #if (defined(HW_ACCESS_SDIO)|defined(HW_ACCESS_WSPI))
  245. TNETWIF_SetPartitions (pWhalBus->hTNETWIF, HW_ACCESS_DOWNLOAD, HW_ACCESS_DOWN_PART0_ADDR);
  246. #endif
  247. TNETWIF_RegSetBitVal(pWhalBus->hTNETWIF, ACX_REG_ECPU_CONTROL, ECPU_CONTROL_HALT);
  248. retStatus = whalBus_FwCtrl_Boot (pHwCtrl->hWhalBus, (TI_HANDLE)pHwCtrl, &BootAttr);
  249. /* release FW and NVS images */
  250. /*
  251. * Note: This is done assuming the boot process is complelty synchronous!!!
  252. * Also, this is not done in GWSI becaues in GWSI these functions are not defined,
  253. * because the load process is different. This has also to be fixed...
  254. */
  255. os_closeFirmwareImage (pHwCtrl->hOs);
  256. os_closeRadioImage (pHwCtrl->hOs);
  257. return(retStatus);
  258. }
  259. #endif /* USE_RECOVERY */