1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * HwInit.c
3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * All rights reserved.
6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Redistribution and use in source and binary forms, with or without
8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * modification, are permitted provided that the following conditions
9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * are met:
10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions of source code must retain the above copyright
12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer.
13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions in binary form must reproduce the above copyright
14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer in
15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    the documentation and/or other materials provided with the
16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    distribution.
17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Neither the name Texas Instruments nor the names of its
18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    contributors may be used to endorse or promote products derived
19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    from this software without specific prior written permission.
20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*******************************************************************************/
37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*                                                                             */
38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*  MODULE:  HwInit.c                                                          */
39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*  PURPOSE: HwInit module manages the init process of the TNETW, included     */
40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*           firmware download process. It shall perform Hard Reset the chip   */
41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*           if possible (this will require a Reset line to be connected to    */
42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*           the host); Start InterfaceCtrl; Download NVS and FW               */
43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*                                                                             */
44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*                                                                             */
45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*******************************************************************************/
46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define __FILE_ID__  FILE_ID_105
48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "tidef.h"
49981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "osApi.h"
50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "report.h"
51981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "HwInit_api.h"
52981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "FwEvent_api.h"
53981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "TwIf.h"
54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "TWDriver.h"
55981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "TWDriverInternal.h"
56981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "eventMbox_api.h"
57981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "CmdBld.h"
58981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "CmdMBox_api.h"
590182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt#ifdef TI_RANDOM_DEFAULT_MAC
600182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt#include <linux/random.h>
610182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt#include <linux/jiffies.h>
620182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt#endif
63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* remove the chipID check when WL6-PG1.0 becomes obsolete (temporary global variable!!) */
65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_BOOL bChipIs1273Pg10 = TI_TRUE;
66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
68981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtextern void TWD_FinalizeOnFailure   (TI_HANDLE hTWD);
69981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtextern void cmdBld_FinalizeDownload (TI_HANDLE hCmdBld, TBootAttr *pBootAttr, FwStaticData_t *pFwInfo);
70981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
71981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
72981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
73981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Defines
74981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************/
75981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
76981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Download phase partition */
77981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_DOWN_MEM_ADDR       0
78981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_DOWN_MEM_SIZE       0x177C0
79981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_DOWN_REG_ADDR       REGISTERS_BASE
80981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_DOWN_REG_SIZE       0x8800
81981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
82981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Working phase partition */
83653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define PARTITION_WORK_MEM_ADDR1       0x40000
84653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define PARTITION_WORK_MEM_SIZE1       0x14FC0
85653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define PARTITION_WORK_MEM_ADDR2       REGISTERS_BASE
86653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define PARTITION_WORK_MEM_SIZE2       0xA000
87653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define PARTITION_WORK_MEM_ADDR3       0x3004F8
88653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define PARTITION_WORK_MEM_SIZE3       0x4
89653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define PARTITION_WORK_MEM_ADDR4       0x40404
90981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
91981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* DRPW setting partition */
92981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_DRPW_MEM_ADDR       0x40000
93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_DRPW_MEM_SIZE       0x14FC0
94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_DRPW_REG_ADDR       DRPW_BASE
95981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_DRPW_REG_SIZE       0x6000
96981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
97981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Total range of bus addresses range */
98981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define PARTITION_TOTAL_ADDR_RANGE    0x1FFC0
99981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Maximal block size in a single SDIO transfer --> Firmware image load chunk size */
101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef _VLCT_
102a67e2e5196684101f6b16308dd998cde279d3ba1Dmitry Shmidt#define MAX_SDIO_BLOCK					(4000)
103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#else
104a67e2e5196684101f6b16308dd998cde279d3ba1Dmitry Shmidt#define MAX_SDIO_BLOCK					(500)
105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define ACX_EEPROMLESS_IND_REG        (SCR_PAD4)
108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define USE_EEPROM                    (0)
109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define SOFT_RESET_MAX_TIME           (1000000)
110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define SOFT_RESET_STALL_TIME         (1000)
111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define NVS_DATA_BUNDARY_ALIGNMENT    (4)
112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define MAX_HW_INIT_CONSECUTIVE_TXN     15
114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define WORD_SIZE                       4
116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define WORD_ALIGNMENT_MASK             0x3
117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define DEF_NVS_SIZE                    ((NVS_PRE_PARAMETERS_LENGTH) + (NVS_TX_TYPE_INDEX) + 4)
118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
119653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define RADIO_SM_WAIT_LOOP  32
120653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
121653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define FREF_CLK_FREQ_MASK      0x7
122653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define FREF_CLK_TYPE_MASK      BIT_3
123653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define FREF_CLK_POLARITY_MASK  BIT_4
124653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
125653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define FREF_CLK_TYPE_BITS      0xfffffe7f
126653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define CLK_REQ_PRCM            0x100
127653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
128653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define FREF_CLK_POLARITY_BITS  0xfffff8ff
129653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define CLK_REQ_OUTN_SEL        0x700
130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Macros
133981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************/
134981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
135981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define SET_DEF_NVS(aNVS)     aNVS[0]=0x01; aNVS[1]=0x6d; aNVS[2]=0x54; aNVS[3]=0x56; aNVS[4]=0x34; \
136981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              aNVS[5]=0x12; aNVS[6]=0x28; aNVS[7]=0x01; aNVS[8]=0x71; aNVS[9]=0x54; \
137981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              aNVS[10]=0x00; aNVS[11]=0x08; aNVS[12]=0x00; aNVS[13]=0x00; aNVS[14]=0x00; \
138981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              aNVS[15]=0x00; aNVS[16]=0x00; aNVS[17]=0x00; aNVS[18]=0x00; aNVS[19]=0x00; \
139981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              aNVS[20]=0x00; aNVS[21]=0x00; aNVS[22]=0x00; aNVS[23]=0x00; aNVS[24]=eNVS_NON_FILE;\
140981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt							  aNVS[25]=0x00; aNVS[26]=0x00; aNVS[27]=0x00;
141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
143653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define SET_PARTITION(pPartition,uAddr1,uMemSize1,uAddr2,uMemSize2,uAddr3,uMemSize3,uAddr4) \
144653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    ((TPartition*)pPartition)[0].uMemAdrr = uAddr1; \
145653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    ((TPartition*)pPartition)[0].uMemSize = uMemSize1; \
146653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    ((TPartition*)pPartition)[1].uMemAdrr = uAddr2; \
147653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    ((TPartition*)pPartition)[1].uMemSize = uMemSize2; \
148653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    ((TPartition*)pPartition)[2].uMemAdrr = uAddr3; \
149653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    ((TPartition*)pPartition)[2].uMemSize = uMemSize3; \
150653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    ((TPartition*)pPartition)[3].uMemAdrr = uAddr4;
151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define HW_INIT_PTXN_SET(pHwInit, pTxn)  pTxn = (TTxnStruct*)&(pHwInit->aHwInitTxn[pHwInit->uTxnIndex].tTxnStruct);
153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, uAddr, uVal, uSize, direction, fCB, hCB)     \
155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              HW_INIT_PTXN_SET(pHwInit, pTxn) \
156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              TXN_PARAM_SET_DIRECTION(pTxn, direction); \
157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData = (TI_UINT32)uVal; \
158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              BUILD_TTxnStruct(pTxn, uAddr, &(pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData), uSize, fCB, hCB)
159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define BUILD_HW_INIT_FW_STATIC_TXN(pHwInit, pTxn, uAddr, fCB, hCB)     \
161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              HW_INIT_PTXN_SET(pHwInit, pTxn) \
162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              TXN_PARAM_SET_DIRECTION(pTxn, TXN_DIRECTION_READ); \
163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              BUILD_TTxnStruct(pTxn, uAddr, &(pHwInit->tFwStaticTxn.tFwStaticInfo), sizeof(FwStaticData_t), fCB, hCB)
164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define BUILD_HW_INIT_FW_DL_TXN(pHwInit, pTxn, uAddr, uVal, uSize, direction, fCB, hCB)     \
166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              HW_INIT_PTXN_SET(pHwInit, pTxn) \
167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              TXN_PARAM_SET_DIRECTION(pTxn, direction); \
168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              BUILD_TTxnStruct(pTxn, uAddr, uVal, uSize, fCB, hCB)
169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
171653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define SET_DRP_PARTITION(pPartition)\
172653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                        SET_PARTITION(pPartition, PARTITION_DRPW_MEM_ADDR, PARTITION_DRPW_MEM_SIZE, PARTITION_DRPW_REG_ADDR, PARTITION_DRPW_REG_SIZE, 0, 0, 0)
173653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
174653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define SET_FW_LOAD_PARTITION(pPartition,uFwAddress)\
175653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                            SET_PARTITION(pPartition,uFwAddress,PARTITION_DOWN_MEM_SIZE, PARTITION_DOWN_REG_ADDR, PARTITION_DOWN_REG_SIZE,0,0,0)
176653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
177653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#define SET_WORK_PARTITION(pPartition)\
178653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                        SET_PARTITION(pPartition,PARTITION_WORK_MEM_ADDR1, PARTITION_WORK_MEM_SIZE1, PARTITION_WORK_MEM_ADDR2, PARTITION_WORK_MEM_SIZE2, PARTITION_WORK_MEM_ADDR3, PARTITION_WORK_MEM_SIZE3, PARTITION_WORK_MEM_ADDR4)
179653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
180981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Handle return status inside a state machine */
181981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define EXCEPT(phwinit,status)                                   \
182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switch (status) {                                           \
183981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TI_OK:                                             \
184981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_OK:                                     \
185981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_COMPLETE:                               \
186981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             break;                                             \
187981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_PENDING:                                \
188981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             return TXN_STATUS_PENDING;                         \
189981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        default:                                                \
190981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             TWD_FinalizeOnFailure (phwinit->hTWD);             \
191981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             return TXN_STATUS_ERROR;                           \
192981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
193981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
194981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
195981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Handle return status inside an init sequence state machine  */
196981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define EXCEPT_I(phwinit,status)                                \
197981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switch (status) {                                           \
198981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TI_OK:                                             \
199981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_COMPLETE:                               \
200981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             break;                                             \
201981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_PENDING:                                \
202981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             phwinit->uInitSeqStatus = status;                  \
203981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             return TXN_STATUS_PENDING;                         \
204981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        default:                                                \
205981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             TWD_FinalizeOnFailure (phwinit->hTWD);             \
206981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             return TXN_STATUS_ERROR;                           \
207981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
208981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
209981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
210981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* Handle return status inside a load image state machine */
211981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define EXCEPT_L(phwinit,status)                                \
212981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switch (status) {                                           \
213981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_OK:                                     \
214981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_COMPLETE:                               \
215981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             break;                                             \
216981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_PENDING:                                \
217981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             phwinit->DownloadStatus = status;                  \
218981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             return TXN_STATUS_PENDING;                         \
219981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        default:                                                \
220981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             phwinit->DownloadStatus = status;                  \
221981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             TWD_FinalizeOnFailure (phwinit->hTWD);             \
222981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             return TXN_STATUS_ERROR;                           \
223981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
224981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
225981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
226981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
227981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Types
228981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************/
229981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
230981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtenum
231981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
232981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    REF_FREQ_19_2                   = 0,
233981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    REF_FREQ_26_0                   = 1,
234981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    REF_FREQ_38_4                   = 2,
235981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    REF_FREQ_40_0                   = 3,
236981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    REF_FREQ_33_6                   = 4,
237981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    REF_FREQ_NUM                    = 5
238981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt};
239981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
240981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtenum
241981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
242981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    LUT_PARAM_INTEGER_DIVIDER       = 0,
243981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    LUT_PARAM_FRACTIONAL_DIVIDER    = 1,
244981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    LUT_PARAM_ATTN_BB               = 2,
245981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    LUT_PARAM_ALPHA_BB              = 3,
246981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    LUT_PARAM_STOP_TIME_BB          = 4,
247981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    LUT_PARAM_BB_PLL_LOOP_FILTER    = 5,
248981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    LUT_PARAM_NUM                   = 6
249981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt};
250981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
251981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef struct
252981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
253981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct              tTxnStruct;
254981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uData;
255981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
256981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} THwInitTxn;
257981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
258981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef struct
259981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
260981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct              tTxnStruct;
261981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    FwStaticData_t          tFwStaticInfo;
262981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
263981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} TFwStaticTxn;
264981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
265981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
266981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* The HW Init module object */
267981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef struct
268981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
269981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Handles */
270981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE               hOs;
271981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE               hReport;
272981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE               hTWD;
273981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE               hBusTxn;
274981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE               hTwIf;
275981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
276981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE 		    hFileInfo;	/* holds parameters of FW Image Portion - for DW Download */
277981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TEndOfHwInitCb          fInitHwCb;
278981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
279981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Firmware image ptr */
280981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8               *pFwBuf;
281981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Firmware image length */
282981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uFwLength;
283981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uFwAddress;
284981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               bFwBufLast;
285981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uFwLastAddr;
286981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* EEPROM image ptr */
287981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8               *pEEPROMBuf;
288981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* EEPROM image length */
289981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uEEPROMLen;
290981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
291981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8               *pEEPROMCurPtr;
292981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uEEPROMCurLen;
293981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBootAttr               tBootAttr;
294981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE               hHwCtrl;
295981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    ETxnStatus              DownloadStatus;
296981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Upper module callback for the init stage */
297981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    fnotify_t               fCb;
298981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Upper module handle for the init stage */
299981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE               hCb;
300981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Init stage */
301981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uInitStage;
302981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Reset statge */
303981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uResetStage;
304981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* EEPROM burst stage */
305981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uEEPROMStage;
306981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Init state machine temporary data */
307981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uInitData;
308981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* ELP command image */
309981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uElpCmd;
310981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Chip ID */
311981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uChipId;
312981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Boot state machine temporary data */
313981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uBootData;
314981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uSelfClearTime;
315981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8                uEEPROMBurstLen;
316981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8                uEEPROMBurstLoop;
317981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uEEPROMRegAddr;
318981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS               uEEPROMStatus;
319981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uNVSStartAddr;
320981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uNVSNumChar;
321981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uNVSNumByte;
322981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS               uNVSStatus;
323981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uScrPad6;
324981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uRefFreq;
325981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uInitSeqStage;
326981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS               uInitSeqStatus;
327981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uLoadStage;
328981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uBlockReadNum;
329981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uBlockWriteNum;
330981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uPartitionLimit;
331981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uFinStage;
332981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uFinData;
333981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uFinLoop;
334981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     TI_UINT32               uRegStage;
335981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uRegLoop;
336981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uRegSeqStage;
337981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uRegData;
338981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
339653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    /* Top register Read/Write SM temporary data*/
340653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    TI_UINT32               uTopRegAddr;
341653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    TI_UINT32               uTopRegValue;
342653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    TI_UINT32               uTopRegMask;
343653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    TI_UINT32               uTopRegUpdateValue;
344653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    TI_UINT32               uTopStage;
345653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
346981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8                auFwTmpBuf [WSPI_PAD_LEN_WRITE + MAX_SDIO_BLOCK];
347981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
348981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TFinalizeCb             fFinalizeDownload;
349981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE               hFinalizeDownload;
350981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Size of the Fw image, retrieved from the image itself */
351981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uFwDataLen;
352981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8                aDefaultNVS[DEF_NVS_SIZE];
353981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8                uTxnIndex;
354981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInitTxn              aHwInitTxn[MAX_HW_INIT_CONSECUTIVE_TXN];
355981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TFwStaticTxn            tFwStaticTxn;
356981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
357981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32               uSavedDataForWspiHdr;  /* For saving the 4 bytes before the NVS data for WSPI case
358981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                                        where they are overrun by the WSPI BusDrv */
359653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    TPartition              aPartition[NUM_OF_PARTITION];
360981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} THwInit;
361981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
362981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
363981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
364981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Local Functions Prototypes
365981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************/
366981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void      hwInit_SetPartition                (THwInit   *pHwInit,
367653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                                                     TPartition *pPartition);
368981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_BootSm                      (TI_HANDLE hHwInit);
369981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_ResetSm                     (TI_HANDLE hHwInit);
370981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_EepromlessStartBurstSm      (TI_HANDLE hHwInit);
371981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_LoadFwImageSm               (TI_HANDLE hHwInit);
372981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_FinalizeDownloadSm          (TI_HANDLE hHwInit);
373653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidtstatic TI_STATUS hwInit_TopRegisterRead(TI_HANDLE hHwInit);
374653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidtstatic TI_STATUS hwInit_InitTopRegisterRead(TI_HANDLE hHwInit, TI_UINT32 uAddress);
375653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidtstatic TI_STATUS hwInit_TopRegisterWrite(TI_HANDLE hHwInit);
376653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidtstatic TI_STATUS hwInit_InitTopRegisterWrite(TI_HANDLE hHwInit, TI_UINT32 uAddress, TI_UINT32 uValue);
377981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
378981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
379981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
380981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
381981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*******************************************************************************
382981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*                       PUBLIC  FUNCTIONS  IMPLEMENTATION                      *
383981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt********************************************************************************/
384981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
385981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
386981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*************************************************************************
387981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*                        hwInit_Create                                   *
388981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt**************************************************************************
389981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* DESCRIPTION:  This function initializes the HwInit module.
390981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
391981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* INPUT:        hOs - handle to Os Abstraction Layer
392981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
393981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* RETURN:       Handle to the allocated HwInit module
394981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*************************************************************************/
395981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_HANDLE hwInit_Create (TI_HANDLE hOs)
396981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
397981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit *pHwInit;
398981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
399981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Allocate HwInit module */
400981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit = os_memoryAlloc (hOs, sizeof(THwInit));
401981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
402981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pHwInit == NULL)
403981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
404981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        WLAN_OS_REPORT(("Error allocating the HwInit Module\n"));
405981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return NULL;
406981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
407981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
408981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Reset HwInit module */
409981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_memoryZero (hOs, pHwInit, sizeof(THwInit));
410981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
411981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->hOs = hOs;
412981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
413981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return (TI_HANDLE)pHwInit;
414981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
415981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
416981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
417981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/***************************************************************************
418981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*                           hwInit_Destroy                                 *
419981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt****************************************************************************
420981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* DESCRIPTION:  This function unload the HwInit module.
421981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
422981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* INPUTS:       hHwInit - the object
423981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
424981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* OUTPUT:
425981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
426981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* RETURNS:      TI_OK - Unload succesfull
427981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*               TI_NOK - Unload unsuccesfull
428981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt***************************************************************************/
429981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_Destroy (TI_HANDLE hHwInit)
430981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
431981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit *pHwInit = (THwInit *)hHwInit;
432981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
433981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Free HwInit Module */
434981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_memoryFree (pHwInit->hOs, pHwInit, sizeof(THwInit));
435981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
436981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
437981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
438981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
439981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
440981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/***************************************************************************
441981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*                           hwInit_Init                                    *
442981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt****************************************************************************
443981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* DESCRIPTION:  This function configures the hwInit module
444981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*
445981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* RETURNS:      TI_OK - Configuration successful
446981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*               TI_NOK - Configuration unsuccessful
447981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt***************************************************************************/
448981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_Init (TI_HANDLE      hHwInit,
449981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                         TI_HANDLE      hReport,
450981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                         TI_HANDLE      hTWD,
451981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                         TI_HANDLE 	hFinalizeDownload,
452981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			 TFinalizeCb    fFinalizeDownload,
453981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                         TEndOfHwInitCb fInitHwCb)
454981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
455981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit   *pHwInit = (THwInit *)hHwInit;
456981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct* pTxn;
4570182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt#ifdef TI_RANDOM_DEFAULT_MAC
4580182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt    u32 rand_mac;
4590182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt#endif
460981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
461981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Configure modules handles */
462981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->hReport    = hReport;
463981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->hTWD       = hTWD;
464981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->hTwIf      = ((TTwd *)hTWD)->hTwIf;
465981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->hOs        = ((TTwd *)hTWD)->hOs;
466981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->fInitHwCb  = fInitHwCb;
467981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->fFinalizeDownload 	= fFinalizeDownload;
468981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->hFinalizeDownload 	= hFinalizeDownload;
469981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
470981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    SET_DEF_NVS(pHwInit->aDefaultNVS)
4710182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt#ifdef TI_RANDOM_DEFAULT_MAC
4720182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt    /* Create random MAC address: offset 3, 4 and 5 */
4730182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt    srandom32((u32)jiffies);
4740182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt    rand_mac = random32();
4750182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt    pHwInit->aDefaultNVS[3] = (u8)rand_mac;
4760182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt    pHwInit->aDefaultNVS[4] = (u8)(rand_mac >> 8);
4770182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt    pHwInit->aDefaultNVS[5] = (u8)(rand_mac >> 16);
4780182115b13c0c9dc9bf238106846b0499e894e22Dmitry Shmidt#endif
479981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
480981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for (pHwInit->uTxnIndex=0;pHwInit->uTxnIndex<MAX_HW_INIT_CONSECUTIVE_TXN;pHwInit->uTxnIndex++)
481981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
482981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        HW_INIT_PTXN_SET(pHwInit, pTxn)
483981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Setting write as default transaction */
484981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_WRITE, TXN_INC_ADDR)
485981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
486981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
487981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT, ".....HwInit configured successfully\n");
488981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
489981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
490981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
491981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
492981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
493981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_SetNvsImage (TI_HANDLE hHwInit, TI_UINT8 *pbuf, TI_UINT32 length)
494981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
495981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit   *pHwInit = (THwInit *)hHwInit;
496981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
497981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->pEEPROMBuf = pbuf;
498981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->uEEPROMLen = length;
499981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
500981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
501981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
502981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
503981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
504981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_SetFwImage (TI_HANDLE hHwInit, TFileInfo *pFileInfo)
505981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
506981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit   *pHwInit = (THwInit *)hHwInit;
507981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
508981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ((hHwInit == NULL) || (pFileInfo == NULL))
509981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
510981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	return TI_NOK;
511981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
512981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
513981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->pFwBuf 	= pFileInfo->pBuffer;
514981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->uFwLength  = pFileInfo->uLength;
515981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->uFwAddress = pFileInfo->uAddress;
516981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->bFwBufLast = pFileInfo->bLast;
517981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
518981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
519981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
520981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
521981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
522981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
523981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     hwInit_SetPartition
524981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Set HW addresses partition
525981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
526981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Set the HW address ranges for download or working memory and registers access.
527981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Generate and configure the bus access address mapping table.
528981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * The partition is split between register (fixed partition of 24KB size, exists in all modes),
529981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     and memory (dynamically changed during init and gets constant value in run-time, 104KB size).
530981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * The TwIf configures the memory mapping table on the device by issuing write transaction to
531981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     table address (note that the TxnQ and bus driver see this as a regular transaction).
532981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
533981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note In future versions, a specific bus may not support partitioning (as in wUART),
534981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *       In this case the HwInit module shall not call this function (will learn the bus
535981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *       configuration from the INI file).
536981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
537981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pHwInit   - The module's object
538653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * \param  pPartition  - all partition base address
539981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return void
540981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
541981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
542981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void hwInit_SetPartition (THwInit   *pHwInit,
543653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                                 TPartition *pPartition)
544981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
545653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt   TRACE7(pHwInit->hReport, REPORT_SEVERITY_INFORMATION, "hwInit_SetPartition: uMemAddr1=0x%x, MemSize1=0x%x uMemAddr2=0x%x, MemSize2=0x%x, uMemAddr3=0x%x, MemSize3=0x%x, uMemAddr4=0x%x, MemSize4=0x%x\n",pPartition[0].uMemAdrr, pPartition[0].uMemSize,pPartition[1].uMemAdrr, pPartition[1].uMemSize,pPartition[2].uMemAdrr, pPartition[2].uMemSize,pPartition[3].uMemAdrr );
546981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
547981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Prepare partition Txn data and send to HW */
548653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    twIf_SetPartition (pHwInit->hTwIf,pPartition);
549981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
550981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
551981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
552981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
553981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_Boot()
554981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
555981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: Start HW init sequence which writes and reads some HW registers
556981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                  that are needed prior to FW download.
557981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
558981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:  None
559981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
560981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
561981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
562981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: TI_OK or TI_NOK
563981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
564981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_Boot (TI_HANDLE hHwInit)
565981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
566981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit      *pHwInit = (THwInit *)hHwInit;
567981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTwd         *pTWD = (TTwd *)pHwInit->hTWD;
568981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TWlanParams  *pWlanParams = &DB_WLAN(pTWD->hCmdBld);
569981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBootAttr     tBootAttr;
570981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
571981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tBootAttr.MacClock = pWlanParams->MacClock;
572981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tBootAttr.ArmClock = pWlanParams->ArmClock;
573981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
574981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
575981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * Initialize the status of download to  pending
576981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * It will be set to TXN_STATUS_COMPLETE at the FinalizeDownload function
577981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
578981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->DownloadStatus = TXN_STATUS_PENDING;
579981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
580981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Call the boot sequence state machine */
581981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->uInitStage = 0;
582981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
583981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_memoryCopy (pHwInit->hOs, &pHwInit->tBootAttr, &tBootAttr, sizeof(TBootAttr));
584981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
585981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    hwInit_BootSm (hHwInit);
586981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
587981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
588981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * If it returns the status of the StartInstance only then we can here query for the download status
589981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * and then return the status up to the TNETW_Driver.
590981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * This return value will go back up to the TNETW Driver layer so that the init from OS will know
591981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * if to wait for the InitComplte or not in case of TXN_STATUS_ERROR.
592981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * This value will always be pending since the SPI is ASYNC
593981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * and in SDIOa timer is set so it will be ASync also in anyway.
594981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
595981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return pHwInit->DownloadStatus;
596981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
597981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
598981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
599981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt /****************************************************************************
600981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: Firmware boot state machine
601981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
602981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:
603981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
604981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
605981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
606981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: TI_OK
607981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
608981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_BootSm (TI_HANDLE hHwInit)
609981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
610981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit    *pHwInit = (THwInit *)hHwInit;
611981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS   status = 0;
612981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct  *pTxn;
613981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32   uData;
614981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTwd        *pTWD        = (TTwd *) pHwInit->hTWD;
615981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    IniFileGeneralParam  *pGenParams = &DB_GEN(pTWD->hCmdBld);
616981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32   clkVal = 0x3;
617981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
618981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    switch (pHwInit->uInitStage)
619981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
620981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 0:
621981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage++;
622981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex = 0;
623981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
624981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Set the bus addresses partition to its "running" mode */
625653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        SET_WORK_PARTITION(pHwInit->aPartition)
626653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        hwInit_SetPartition (pHwInit,pHwInit->aPartition);
627981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
628981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef _VLCT_
629981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         /* Set FW to test mode */
630981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, SCR_PAD8, 0xBABABABE,
631981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
632981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         twIf_Transact(pHwInit->hTwIf, pTxn);
633981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         pHwInit->uTxnIndex++;
634981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
635981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
636653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        if (( 0 == (pGenParams->RefClk & FREF_CLK_FREQ_MASK)) || (2 == (pGenParams->RefClk & FREF_CLK_FREQ_MASK))
637653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             || (4 == (pGenParams->RefClk & FREF_CLK_FREQ_MASK)))
638653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        {/* ref clk: 19.2/38.4/38.4-XTAL */
639981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            clkVal = 0x3;
640981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
641653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        if ((1 == (pGenParams->RefClk & FREF_CLK_FREQ_MASK)) || (3 == (pGenParams->RefClk & FREF_CLK_FREQ_MASK)))
642981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {/* ref clk: 26/52 */
643981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            clkVal = 0x5;
644981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
645981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
646981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        WLAN_OS_REPORT(("CHIP VERSION... set 1273 chip top registers\n"));
647981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
648981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* set the reference clock freq' to be used (pll_selinpfref field) */
649981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, PLL_PARAMETERS, clkVal,
650981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
651981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        twIf_Transact(pHwInit->hTwIf, pTxn);
652981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
653981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex++;
654981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
655981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* read the PAUSE value to highest threshold */
656981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, PLL_PARAMETERS, 0,
657981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_BootSm, hHwInit)
658981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        status = twIf_Transact(pHwInit->hTwIf, pTxn);
659981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
660981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status)
661981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
662981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 1:
663981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage ++;
664981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
665981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        uData = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
666981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        uData &= ~(0x3ff);
667981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
668981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Now we can zero the index */
669981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex = 0;
670981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
671981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* set the the PAUSE value to highest threshold */
672981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        uData |= WU_COUNTER_PAUSE_VAL;
673981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, WU_COUNTER_PAUSE, uData,
674981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
675981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        twIf_Transact(pHwInit->hTwIf, pTxn);
676981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
677981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex++;
678981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
679981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Continue the ELP wake up sequence */
680981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL,
681981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
682981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        twIf_Transact(pHwInit->hTwIf, pTxn);
683981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
684981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Wait 500uS */
685981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_StalluSec (pHwInit->hOs, 500);
686981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
687981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Set the bus addresses partition to DRPw registers region */
688653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        SET_DRP_PARTITION(pHwInit->aPartition)
689653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        hwInit_SetPartition (pHwInit,pHwInit->aPartition);
690981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
691981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex++;
692981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
693981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Read-modify-write DRPW_SCRATCH_START register (see next state) to be used by DRPw FW.
694981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           The RTRIM value will be added  by the FW before taking DRPw out of reset */
695981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, DRPW_SCRATCH_START, 0,
696981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ,(TTxnDoneCb)hwInit_BootSm, hHwInit)
697981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        status = twIf_Transact(pHwInit->hTwIf, pTxn);
698981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
699981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status)
700981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
701981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 2:
702981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage ++;
703981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
704981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* multiply fref value by 2, so that {0,1,2,3} values will become {0,2,4,6} */
705981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Then, move it 4 places to the right, to alter Fref relevant bits in register 0x2c */
706981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        clkVal = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
707981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex = 0; /* Reset index only after getting the last read value! */
708981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        clkVal |= (pGenParams->RefClk << 1) << 4;
709981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, DRPW_SCRATCH_START, clkVal,
710981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
711981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        twIf_Transact(pHwInit->hTwIf, pTxn);
712981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
713981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex++;
714981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
715653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
716981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Set the bus addresses partition back to its "running" mode */
717653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        SET_WORK_PARTITION(pHwInit->aPartition)
718653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        hwInit_SetPartition (pHwInit,pHwInit->aPartition);
719981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
720981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
721981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * end of CHIP init seq.
722981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
723981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
724981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Disable interrupts */
725981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, ACX_REG_INTERRUPT_MASK, ACX_INTR_ALL,
726981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
727981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        twIf_Transact(pHwInit->hTwIf, pTxn);
728981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
729981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex++;
730981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
731981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Read the CHIP ID to get an indication that the bus is TI_OK */
732981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, CHIP_ID, 0,
733981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ,(TTxnDoneCb)hwInit_BootSm, hHwInit)
734981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        status = twIf_Transact(pHwInit->hTwIf, pTxn);
735981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
736981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status)
737981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
738981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 3:
739981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage ++;
740981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
741981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
742981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         pHwInit->uChipId = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
743981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
744981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* This is only sanity check that the HW exists, we can continue and fail on FwLoad */
745981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		if (pHwInit->uChipId == CHIP_ID_1273_PG10)
746981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
747981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT(("Working on a 1273 PG 1.0 board.\n"));
748981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            bChipIs1273Pg10 = TI_TRUE;
749981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
750981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		else if (pHwInit->uChipId == CHIP_ID_1273_PG20)
751981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
752981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT(("Working on a 1273 PG 2.0 board.\n"));
753981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            bChipIs1273Pg10 = TI_FALSE;
754981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
755981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
756981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
757981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT (("Error!! Found unknown Chip Id = 0x%x\n", pHwInit->uChipId));
758981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            bChipIs1273Pg10 = TI_FALSE;
759981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
760981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
761981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * NOTE: no exception because of forward compatibility
762981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
763981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
764981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
765981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
766981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Soft reset
767981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
768981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uResetStage = 0;
769981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uSelfClearTime = 0;
770981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uBootData = 0;
771981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        status = hwInit_ResetSm (pHwInit);
772981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
773981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status)
774981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
775981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 4:
776981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage ++;
777981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
778981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "TNET SOFT-RESET\n");
779981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
780981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        WLAN_OS_REPORT(("Starting to process NVS...\n"));
781981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
782981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
783981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Start EEPROM/NVS burst
784981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
785981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
786981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (pHwInit->pEEPROMBuf)
787981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
788981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* NVS file exists (EEPROM-less support) */
789981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uEEPROMCurLen = pHwInit->uEEPROMLen;
790981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
791981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE2(pHwInit->hReport, REPORT_SEVERITY_INIT , "EEPROM Image addr=0x%x, EEPROM Len=0x0x%x\n", pHwInit->pEEPROMBuf, pHwInit->uEEPROMLen);
792981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT (("NVS found, EEPROM Image addr=0x%x, EEPROM Len=0x0x%x\n",
793981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                              pHwInit->pEEPROMBuf, pHwInit->uEEPROMLen));
794981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
795981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
796981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
797981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT (("No Nvs, Setting default MAC address\n"));
798981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uEEPROMCurLen = DEF_NVS_SIZE;
799981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->pEEPROMBuf = (TI_UINT8*)(&pHwInit->aDefaultNVS[0]);
800981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT (("pHwInit->uEEPROMCurLen: %x\n", pHwInit->uEEPROMCurLen));
801653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            WLAN_OS_REPORT (("ERROR: If you are not calibating the device, you will soon get errors !!!\n"));
802981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
803981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
804981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
805981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->pEEPROMCurPtr = pHwInit->pEEPROMBuf;
806981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uEEPROMStage = 0;
807981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        status = hwInit_EepromlessStartBurstSm (hHwInit);
808981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
809981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status)
810981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
811981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 5:
812981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage ++;
813981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex = 0;
814981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
815981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (pHwInit->pEEPROMBuf)
816981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
817981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Signal FW that we are eeprom less */
818981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG,
819981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
820981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);
821981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
822981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "DRIVER NVS BURST-READ\n");
823981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
824981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
825981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
826981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	    /* 1273 - EEPROM is not support by FPGA yet */
827981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
828981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * Start ACX EEPROM
829981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
830981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*pHwInit->uRegister = START_EEPROM_MGR;
831981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_WRITE, TXN_INC_ADDR)
832981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_TTxnStruct(pTxn, ACX_REG_EE_START, &pHwInit->uRegister, REGISTER_SIZE, 0, NULL, NULL)
833981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);*/
834981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
835981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
836981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * The stall is needed so the EEPROM NVS burst read will complete
837981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
838981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_StalluSec (pHwInit->hOs, 40000);
839981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
840981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, ACX_EEPROMLESS_IND_REG, USE_EEPROM,
841981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
842981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);
843981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
844981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "STARTING EEPROM NVS BURST-READ\n");
845981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
846981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
847981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex++;
848981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
849981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Read Chip ID */
850981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn,  CHIP_ID, 0,
851981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ,(TTxnDoneCb)hwInit_BootSm, hHwInit)
852981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        status = twIf_Transact(pHwInit->hTwIf, pTxn);
853981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
854981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status)
855981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
856981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 6:
857981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage ++;
858981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
859981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uBootData = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
860981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Now we can zero the index */
861981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uTxnIndex = 0;
862981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
863981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        WLAN_OS_REPORT(("Chip ID is 0x%X.\n", pHwInit->uBootData));
864981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* if the WLAN_EN is ON but MainClock is problamtic the chip-id will be zero*/
865981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (pHwInit->uBootData == 0)
866981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
867981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         WLAN_OS_REPORT(("Cannot read ChipID stopping\n", pHwInit->uBootData));
868981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         TWD_FinalizeOnFailure (pHwInit->hTWD);
869981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         return TXN_STATUS_ERROR;
870981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
871981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
872981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
873981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
874981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Read Scr2 to verify that the HW is ready */
875981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, SCR_PAD2, 0,
876981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ,(TTxnDoneCb)hwInit_BootSm, hHwInit)
877981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        status = twIf_Transact(pHwInit->hTwIf, pTxn);
878981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status)
879981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
880981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 7:
881981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage ++;
882981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
883981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uBootData = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
884981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
885981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (pHwInit->uBootData == 0xffffffff)
886981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
887981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE0(pHwInit->hReport, REPORT_SEVERITY_FATAL_ERROR , "Error in SCR_PAD2 register\n");
888981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, TXN_STATUS_ERROR)
889981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
890981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
891981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Call the restart sequence */
892981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitSeqStage = 0;
893981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitSeqStatus = TXN_STATUS_COMPLETE;
894981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
895981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status)
896981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
897981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    case 8:
898653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        pHwInit->uInitStage++;
899653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        if ((pGenParams->RefClk & FREF_CLK_TYPE_MASK) != 0x0)
900653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        {
901653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            status = hwInit_InitTopRegisterRead(hHwInit, 0x448);
902653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            EXCEPT (pHwInit, status)
903653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        }
904653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
905653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    case 9:
906653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        pHwInit->uInitStage++;
907653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
908653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        if ((pGenParams->RefClk & FREF_CLK_TYPE_MASK) != 0x0)
909653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        {
910653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			pHwInit->uTopRegValue &= FREF_CLK_TYPE_BITS;
911653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pHwInit->uTopRegValue |= CLK_REQ_PRCM;
912653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			status =  hwInit_InitTopRegisterWrite( hHwInit, 0x448, pHwInit->uTopRegValue);
913653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            EXCEPT (pHwInit, status)
914653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        }
915653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
916653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    case 10:
917653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        pHwInit->uInitStage++;
918653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt		if ((pGenParams->RefClk & FREF_CLK_POLARITY_MASK) == 0x0)
919653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        {
920653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            status = hwInit_InitTopRegisterRead(hHwInit, 0xCB2);
921653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            EXCEPT (pHwInit, status)
922653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        }
923653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
924653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    case 11:
925653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        pHwInit->uInitStage++;
926653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        if ((pGenParams->RefClk & FREF_CLK_POLARITY_MASK) == 0x0)
927653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        {
928653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pHwInit->uTopRegValue &= FREF_CLK_POLARITY_BITS;
929653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pHwInit->uTopRegValue |= CLK_REQ_OUTN_SEL;
930653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            status =  hwInit_InitTopRegisterWrite( hHwInit, 0xCB2, pHwInit->uTopRegValue);
931653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            EXCEPT (pHwInit, status)
932653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        }
933653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
934653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt    case 12:
935981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uInitStage = 0;
936981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
937981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Set the Download Status to COMPLETE */
938981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->DownloadStatus = TXN_STATUS_COMPLETE;
939981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
940981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Call upper layer callback */
941981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (pHwInit->fInitHwCb)
942981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
943981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            (*pHwInit->fInitHwCb) (pHwInit->hTWD);
944981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
945981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
946981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_OK;
947981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
948981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
949981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
950981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
951981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
952981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
953981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_LoadFw (TI_HANDLE hHwInit)
954981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
955981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit   *pHwInit = (THwInit *)hHwInit;
956981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS  status;
957981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
958981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* check parameters */
959981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (hHwInit == NULL)
960981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
961981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, TXN_STATUS_ERROR)
962981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
963981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
964981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pHwInit->pFwBuf)
965981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
966981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "CPU halt -> download code\n");
967981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
968981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Load firmware image */
969981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pHwInit->uLoadStage = 0;
970981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        status = hwInit_LoadFwImageSm (pHwInit);
971981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
972981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        switch (status)
973981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
974653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        case TI_OK:
975653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        case TXN_STATUS_OK:
976981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_COMPLETE:
977981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT (("Firmware successfully downloaded.\n"));
978981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
979981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case TXN_STATUS_PENDING:
980981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT (("Starting to download firmware...\n"));
981981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
982981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        default:
983981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "Firmware download failed!\n");
984981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            break;
985981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
986981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
987981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, status);
988981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
989981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
990981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
991981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "Firmware not downloaded...\n");
992981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
993981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        EXCEPT (pHwInit, TXN_STATUS_ERROR)
994981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
995981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
996981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    WLAN_OS_REPORT (("FW download OK...\n"));
997981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
998981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
999981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1000981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1001981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
1002981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_FinalizeDownloadSm()
1003981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
1004981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: Run the Hardware firmware
1005981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *              Wait for Init Complete
1006981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *              Configure the Bus Access with Addresses available on the scratch pad register
1007981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *              Change the SDIO/SPI partitions to be able to see all the memory addresses
1008981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1009981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:  None
1010981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1011981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
1012981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1013981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: None
1014981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
1015981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_FinalizeDownloadSm (TI_HANDLE hHwInit)
1016981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1017981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit  *pHwInit = (THwInit *)hHwInit;
1018981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTwd     *pTWD = (TTwd *)pHwInit->hTWD;
1019981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS status = TI_OK;
1020981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32   uIntVect;
1021981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct* pTxn;
1022981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1023981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef _VLCT_
1024981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    #define FIN_LOOP 10
1025981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#else
1026981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    #define FIN_LOOP 20000
1027981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
1028981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1029981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while (TI_TRUE)
1030981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1031981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        switch (pHwInit->uFinStage)
1032981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1033981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 0:
1034981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinStage = 1;
1035981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1036981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
1037981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * Run the firmware (I) - Read current value from ECPU Control Reg.
1038981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
1039981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, ACX_REG_ECPU_CONTROL, 0,
1040981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_FinalizeDownloadSm, hHwInit)
1041981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = twIf_Transact(pHwInit->hTwIf, pTxn);
1042981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1043981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, status)
1044981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1045981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 1:
1046981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinStage ++;
1047981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
1048981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinData = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
1049981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Now we can zero the index */
1050981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1051981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1052981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
1053981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * Run the firmware (II) - Take HW out of reset (write ECPU_CONTROL_HALT to ECPU Control Reg.)
1054981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
1055981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, ACX_REG_ECPU_CONTROL, (pHwInit->uFinData | ECPU_CONTROL_HALT),
1056981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1057981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);
1058981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1059981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            WLAN_OS_REPORT (("Firmware running.\n"));
1060981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1061981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
1062981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * CHIP ID Debug
1063981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
1064981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1065981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex++;
1066981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1067981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, CHIP_ID, 0,
1068981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_FinalizeDownloadSm, hHwInit)
1069981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = twIf_Transact(pHwInit->hTwIf, pTxn);
1070981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1071981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, status)
1072981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1073981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 2:
1074981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinStage ++;
1075981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinLoop = 0;
1076981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1077981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
1078981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinData = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
1079981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1080981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE1(pHwInit->hReport, REPORT_SEVERITY_INIT , "CHIP ID IS %x\n", pHwInit->uFinData);
1081981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1082981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "Wait init complete\n");
1083981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1084981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 3:
1085981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1086981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1087981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
1088981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * Wait for init complete
1089981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
1090981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pHwInit->uFinLoop < FIN_LOOP)
1091981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1092981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uFinStage = 4;
1093981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1094981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                os_StalluSec (pHwInit->hOs, 50);
1095981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1096981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Read interrupt status register */
1097981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, ACX_REG_INTERRUPT_NO_CLEAR, 0,
1098981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_FinalizeDownloadSm, hHwInit)
1099981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                status = twIf_Transact(pHwInit->hTwIf, pTxn);
1100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                EXCEPT (pHwInit, status)
1102981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1104981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			{
1105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				pHwInit->uFinStage = 5;
1106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			}
1107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 4:
1110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
1111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinData = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
1112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Now we can zero the index */
1113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pHwInit->uFinData == 0xffffffff) /* error */
1116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "Error reading hardware complete init indication\n");
1118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->DownloadStatus = TXN_STATUS_ERROR;
1120981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                EXCEPT (pHwInit, TXN_STATUS_ERROR)
1121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1123981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (IS_MASK_ON (pHwInit->uFinData, ACX_INTR_INIT_COMPLETE))
1124981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1125981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uFinStage = 5;
1126981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1127981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Interrupt ACK */
1128981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, ACX_REG_INTERRUPT_ACK, ACX_INTR_INIT_COMPLETE,
1129981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                twIf_Transact(pHwInit->hTwIf, pTxn);
1131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                break;
1133981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1134981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1135981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1136981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uFinStage = 3;
1137981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uFinLoop ++;
1138981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1139981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1140981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 5:
1142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinStage++;
1143981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1144981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pHwInit->uFinLoop >= FIN_LOOP)
1145981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1146981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "Timeout waiting for the hardware to complete initialization\n");
1147981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1148981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->DownloadStatus = TXN_STATUS_ERROR;
1149981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                EXCEPT (pHwInit, TXN_STATUS_ERROR);
1150981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "Firmware init complete...\n");
1153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
1155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * There are valid addresses of the command and event mailbox
1156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * on the scratch pad registers
1157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
1158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Hardware config command mail box */
1159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = cmdMbox_ConfigHw (pTWD->hCmdMbox,
1160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                       (fnotify_t)hwInit_FinalizeDownloadSm,
1161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                       hHwInit);
1162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, status)
1163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 6:
1165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinStage++;
1166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Hardware config event mail box */
1168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = eventMbox_InitMboxAddr (pTWD->hEventMbox,
1169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                         (fnotify_t)hwInit_FinalizeDownloadSm,
1170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                         hHwInit);
1171981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, status);
1172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1173981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 7:
1174981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinStage++;
1175981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1176981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1177653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            SET_WORK_PARTITION(pHwInit->aPartition)
1178981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Set the bus addresses partition to its "running" mode */
1179653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            SET_WORK_PARTITION(pHwInit->aPartition)
1180653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            hwInit_SetPartition (pHwInit,pHwInit->aPartition);
1181653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
1182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
1183981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * In case of full asynchronous mode the firmware event must be ready
1184653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             * to receive event from the command mailbox, so enable FW interrupts.
1185981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
1186981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1187653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            /* Clear the FW interrupt sources needed for init phase */
1188981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            uIntVect = fwEvent_GetInitMask (pTWD->hFwEvent);
1189981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, ACX_REG_INTERRUPT_MASK, (~uIntVect),
1190981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1191981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);
1192981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex++;
1193981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1194653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            /* Read static FW information from Cmd-Mbox */
1195981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_FW_STATIC_TXN(pHwInit, pTxn, cmdMbox_GetMboxAddress (pTWD->hCmdMbox),
1196981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                        (TTxnDoneCb)hwInit_FinalizeDownloadSm, hHwInit)
1197981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = twIf_Transact(pHwInit->hTwIf, pTxn);
1198981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1199981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, status);
1200981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1201981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1202981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 8:
1203981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1204981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uFinStage = 0;
1205981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1206981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            cmdBld_FinalizeDownload (pTWD->hCmdBld, &pHwInit->tBootAttr, &(pHwInit->tFwStaticTxn.tFwStaticInfo));
1207981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1208981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Set the Download Status to COMPLETE */
1209981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->DownloadStatus = TXN_STATUS_COMPLETE;
1210981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1211981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return TXN_STATUS_COMPLETE;
1212981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1213981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        } /* End switch */
1214981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1215981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    } /* End while */
1216981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1217981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1218981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1219981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1220981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
1221981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_ResetSm()
1222981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
1223981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: Reset hardware state machine
1224981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1225981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:  None
1226981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1227981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
1228981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1229981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: TI_OK or TI_NOK
1230981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
1231981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_ResetSm (TI_HANDLE hHwInit)
1232981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1233981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit *pHwInit = (THwInit *)hHwInit;
1234981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS status = TI_OK;
1235981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct* pTxn;
1236981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1237981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->uTxnIndex = 0;
1238981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1239981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Disable Rx/Tx */
1240981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, REG_ENABLE_TX_RX, 0x0,
1241981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1242981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    twIf_Transact(pHwInit->hTwIf, pTxn);
1243981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1244981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->uTxnIndex++;
1245981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1246981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Disable auto calibration on start */
1247981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, SPARE_A2, 0xFFFF,
1248981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE,(TTxnDoneCb)hwInit_BootSm, hHwInit)
1249981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    status = twIf_Transact(pHwInit->hTwIf, pTxn);
1250981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1251981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return status;
1252981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1253981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1254981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1255981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
1256981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_EepromlessStartBurstSm()
1257981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
1258981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: prepare eepromless configuration before boot
1259981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1260981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:
1261981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1262981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:
1263981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1264981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS:
1265981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
1266981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_EepromlessStartBurstSm (TI_HANDLE hHwInit)
1267981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1268981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit   *pHwInit = (THwInit *)hHwInit;
1269981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS  status = TI_OK;
1270981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8   *uAddr;
1271981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32  uDeltaLength;
1272981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct* pTxn;
1273981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1274981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->uTxnIndex = 0;
1275981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1276981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while (TI_TRUE)
1277981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1278981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        switch (pHwInit->uEEPROMStage)
1279981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1280981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
1281981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Stages 0, 1 handles the eeprom format parameters:
1282981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * ------------------------------------------------
1283981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Length  - 8bit       --> The length is counted in 32bit words
1284981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Address - 16bit
1285981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Data    - (Length * 4) bytes
1286981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         *
1287981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * Note: The nvs is in big endian format and we need to change it to little endian
1288981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
1289981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 0:
1290981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Check if address LSB = 1 --> Register address */
1291981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if ((pHwInit->uEEPROMRegAddr = pHwInit->pEEPROMCurPtr[1]) & 1)
1292981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1293981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Mask the register's address LSB before writing to it */
1294981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMRegAddr &= 0xfe;
1295981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Change the address's endian */
1296981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMRegAddr |= (TI_UINT32)pHwInit->pEEPROMCurPtr[2] << 8;
1297981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Length of burst data */
1298981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMBurstLen = pHwInit->pEEPROMCurPtr[0];
1299981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->pEEPROMCurPtr += 3;
1300981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMBurstLoop = 0;
1301981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /*
1302981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 * We've finished reading the burst information.
1303981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 * Go to stage 1 in order to write it
1304981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 */
1305981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMStage = 1;
1306981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1307981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* If address LSB = 0 --> We're not in the burst section */
1308981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1309981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1310981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* End of Burst transaction: we should see 7 zeroed bytes */
1311981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                if (pHwInit->pEEPROMCurPtr[0] == 0)
1312981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                {
1313981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    pHwInit->pEEPROMCurPtr += 7;
1314981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                }
1315981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMCurLen -= (pHwInit->pEEPROMCurPtr - pHwInit->pEEPROMBuf + 1);
1316981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMCurLen = (pHwInit->uEEPROMCurLen + NVS_DATA_BUNDARY_ALIGNMENT - 1) & 0xfffffffc;
1317981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* End of Burst transaction, go to TLV section */
1318981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMStage = 2;
1319981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1320981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1321981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1322981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 1:
1323981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pHwInit->uEEPROMBurstLoop < pHwInit->uEEPROMBurstLen)
1324981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1325981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Change the data's endian */
1326981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TI_UINT32 val = (pHwInit->pEEPROMCurPtr[0] |
1327981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                (pHwInit->pEEPROMCurPtr[1] << 8) |
1328981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                (pHwInit->pEEPROMCurPtr[2] << 16) |
1329981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                (pHwInit->pEEPROMCurPtr[3] << 24));
1330981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1331981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE2(pHwInit->hReport, REPORT_SEVERITY_INIT , "NVS::BurstRead: *(%08x) = %x\n", pHwInit->uEEPROMRegAddr, val);
1332981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1333981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, (REGISTERS_BASE+pHwInit->uEEPROMRegAddr), val,
1334981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, (TTxnDoneCb)hwInit_EepromlessStartBurstSm, hHwInit)
1335981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                status = twIf_Transact(pHwInit->hTwIf, pTxn);
1336981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1337981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMStatus = status;
1338981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMRegAddr += WORD_SIZE;
1339981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->pEEPROMCurPtr +=  WORD_SIZE;
1340981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* While not end of burst, we stay in stage 1 */
1341981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMStage = 1;
1342981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMBurstLoop ++;
1343981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1344981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                EXCEPT (pHwInit, status);
1345981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1346981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1347981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1348981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* If end of burst return to stage 0 to read the next one */
1349981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMStage = 0;
1350981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1351981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1352981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1353981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1354981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 2:
1355981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1356981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1357981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uEEPROMStage = 3;
1358981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1359981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Set the bus addresses partition to its "running" mode */
1360653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            SET_WORK_PARTITION(pHwInit->aPartition)
1361653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            hwInit_SetPartition (pHwInit,pHwInit->aPartition);
1362981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1363981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1364981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 3:
1365981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "Reached TLV section\n");
1366981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1367981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Align the host address */
1368981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (((TI_UINT32)pHwInit->pEEPROMCurPtr & WORD_ALIGNMENT_MASK) && (pHwInit->uEEPROMCurLen > 0) )
1369981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1370981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                uAddr = (TI_UINT8*)(((TI_UINT32)pHwInit->pEEPROMCurPtr & 0xFFFFFFFC)+WORD_SIZE);
1371981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                uDeltaLength = uAddr - pHwInit->pEEPROMCurPtr + 1;
1372981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1373981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->pEEPROMCurPtr = uAddr;
1374981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMCurLen-= uDeltaLength;
1375981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1376981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1377981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE2(pHwInit->hReport, REPORT_SEVERITY_INIT , "NVS::WriteTLV: pEEPROMCurPtr= %x, Length=%d\n", pHwInit->pEEPROMCurPtr, pHwInit->uEEPROMCurLen);
1378981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1379981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pHwInit->uEEPROMCurLen)
1380981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1381981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Save the 4 bytes before the NVS data for WSPI case where they are overrun by the WSPI BusDrv */
1382981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uSavedDataForWspiHdr = *(TI_UINT32 *)(pHwInit->pEEPROMCurPtr - WSPI_PAD_LEN_WRITE);
1383981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1384981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Prepare the Txn structure for the NVS transaction to the CMD_MBOX */
1385981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                HW_INIT_PTXN_SET(pHwInit, pTxn)
1386981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TXN_PARAM_SET_DIRECTION(pTxn, TXN_DIRECTION_WRITE);
1387981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                BUILD_TTxnStruct(pTxn, CMD_MBOX_ADDRESS, pHwInit->pEEPROMCurPtr, pHwInit->uEEPROMCurLen,
1388981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                 (TTxnDoneCb)hwInit_EepromlessStartBurstSm, hHwInit)
1389981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1390981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Transact the NVS data to the CMD_MBOX */
1391981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                status = twIf_Transact(pHwInit->hTwIf, pTxn);
1392981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1393981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uEEPROMCurLen = 0;
1394981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uNVSStatus = status;
1395981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1396981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                EXCEPT (pHwInit, status);
1397981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1398981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1399981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1400981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Restore the 4 bytes before the NVS data for WSPI case were they are overrun by the WSPI BusDrv */
1401981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                *(TI_UINT32 *)(pHwInit->pEEPROMCurPtr - WSPI_PAD_LEN_WRITE) = pHwInit->uSavedDataForWspiHdr;
1402981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1403981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Call the upper level state machine */
1404981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                if (pHwInit->uEEPROMStatus == TXN_STATUS_PENDING ||
1405981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    pHwInit->uNVSStatus == TXN_STATUS_PENDING)
1406981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                {
1407981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    hwInit_BootSm (hHwInit);
1408981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                }
1409981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1410981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return TXN_STATUS_COMPLETE;
1411981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1412981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        } /* End switch */
1413981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1414981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    } /* End while */
1415981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1416981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1417981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
1418981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_LoadFwImageSm()
1419981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
1420981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: Load image from the host and download into the hardware
1421981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1422981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:  None
1423981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1424981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
1425981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1426981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: TI_OK or TI_NOK
1427981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
1428981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1429981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1430981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define ADDRESS_SIZE		(sizeof(TI_INT32))
1431981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1432981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS hwInit_LoadFwImageSm (TI_HANDLE hHwInit)
1433981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1434981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit *pHwInit 			= (THwInit *)hHwInit;
1435981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS status 			= TI_OK;
1436981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	ETxnStatus	TxnStatus;
1437981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	TI_UINT32 uMaxPartitionSize	= PARTITION_DOWN_MEM_SIZE;
1438981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct* pTxn;
1439981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1440981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pHwInit->uTxnIndex = 0;
1441981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1442981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while (TI_TRUE)
1443981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1444981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        switch (pHwInit->uLoadStage)
1445981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1446981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		case 0:
1447981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uLoadStage = 1;
1448981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1449981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			/* Check the Downloaded FW alignment */
1450981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			if ((pHwInit->uFwLength % ADDRESS_SIZE) != 0)
1451981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			{
1452981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				TRACE1(pHwInit->hReport, REPORT_SEVERITY_ERROR , "Length of downloaded Portion (%d) is not aligned\n",pHwInit->uFwLength);
1453981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				EXCEPT_L (pHwInit, TXN_STATUS_ERROR);
1454981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			}
1455981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1456981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			TRACE2(pHwInit->hReport, REPORT_SEVERITY_INIT , "Image addr=0x%x, Len=0x%x\n", pHwInit->pFwBuf, pHwInit->uFwLength);
1457981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1458981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			/* Set bus memory partition to current download area */
1459653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt           SET_FW_LOAD_PARTITION(pHwInit->aPartition,pHwInit->uFwAddress)
1460653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt           hwInit_SetPartition (pHwInit,pHwInit->aPartition);
1461981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = TI_OK;
1462981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			break;
1463981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1464981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 1:
1465981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1466981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			pHwInit->uLoadStage = 2;
1467981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			/* if initial size is smaller than MAX_SDIO_BLOCK - go strait to stage 4 to write partial block */
1468981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			if (pHwInit->uFwLength < MAX_SDIO_BLOCK)
1469981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			{
1470981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				pHwInit->uLoadStage = 4;
1471981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			}
1472981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1473981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			pHwInit->uBlockReadNum 		= 0;
1474981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			pHwInit->uBlockWriteNum 	= 0;
1475981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			pHwInit->uPartitionLimit 	= pHwInit->uFwAddress + uMaxPartitionSize;
1476981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1477981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1478981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1479981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 2:
1480981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1481981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Load firmware by blocks */
1482981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 			if (pHwInit->uBlockReadNum < (pHwInit->uFwLength / MAX_SDIO_BLOCK))
1483981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1484981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uLoadStage = 3;
1485981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1486981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Change partition */
1487981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				/* The +2 is for the last block and the block remainder */
1488981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				if ( ((pHwInit->uBlockWriteNum + 2) * MAX_SDIO_BLOCK + pHwInit->uFwAddress) > pHwInit->uPartitionLimit)
1489981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                {
1490981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt					pHwInit->uFwAddress += pHwInit->uBlockWriteNum * MAX_SDIO_BLOCK;
1491981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt					/* update uPartitionLimit */
1492981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt					pHwInit->uPartitionLimit = pHwInit->uFwAddress + uMaxPartitionSize;
1493981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    /* Set bus memory partition to current download area */
1494653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    SET_FW_LOAD_PARTITION(pHwInit->aPartition,pHwInit->uFwAddress)
1495653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                    hwInit_SetPartition (pHwInit,pHwInit->aPartition);
1496981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    TxnStatus = TXN_STATUS_OK;
1497981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt					pHwInit->uBlockWriteNum = 0;
1498981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    TRACE1(pHwInit->hReport, REPORT_SEVERITY_INIT , "Change partition to address offset = 0x%x\n", 									   pHwInit->uFwAddress + pHwInit->uBlockWriteNum * MAX_SDIO_BLOCK);
1499981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    EXCEPT_L (pHwInit, TxnStatus);
1500981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                }
1501981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1502981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1503981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1504981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uLoadStage = 4;
1505981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE0(pHwInit->hReport, REPORT_SEVERITY_INIT , "Load firmware with Portions\n");
1506981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1507981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1508981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1509981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 3:
1510981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uLoadStage = 2;
1511981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1512981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1513981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1514981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Copy image block to temporary buffer */
1515981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_memoryCopy (pHwInit->hOs,
1516981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           (void *)&pHwInit->auFwTmpBuf[WSPI_PAD_LEN_WRITE],
1517981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt						   (void *)(pHwInit->pFwBuf + pHwInit->uBlockReadNum * MAX_SDIO_BLOCK),
1518981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt						   MAX_SDIO_BLOCK);
1519981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1520981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Load the block. Save WSPI_PAD_LEN_WRITE space for WSPI bus command */
1521981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             BUILD_HW_INIT_FW_DL_TXN(pHwInit, pTxn, (pHwInit->uFwAddress + pHwInit->uBlockWriteNum * MAX_SDIO_BLOCK),
1522981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                     (pHwInit->auFwTmpBuf + WSPI_PAD_LEN_WRITE), MAX_SDIO_BLOCK, TXN_DIRECTION_WRITE,
1523981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                     (TTxnDoneCb)hwInit_LoadFwImageSm, hHwInit)
1524981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TxnStatus = twIf_Transact(pHwInit->hTwIf, pTxn);
1525981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1526981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Log ERROR if the transaction returned ERROR */
1527981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (TxnStatus == TXN_STATUS_ERROR)
1528981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1529981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE1(pHwInit->hReport, REPORT_SEVERITY_ERROR , "hwInit_LoadFwImageSm: twIf_Transact retruned status=0x%x\n", TxnStatus);
1530981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1531981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1532981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			pHwInit->uBlockWriteNum ++;
1533981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			pHwInit->uBlockReadNum ++;
1534981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT_L (pHwInit, TxnStatus);
1535981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1536981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1537981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 4:
1538981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			pHwInit->uLoadStage 	= 5;
1539981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1540981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1541981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1542981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			/* If No Last block to write */
1543981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			if ( pHwInit->uFwLength % MAX_SDIO_BLOCK == 0 )
1544981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			{
1545981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				continue;
1546981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			}
1547981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1548981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1549981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Copy the last image block */
1550981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             os_memoryCopy (pHwInit->hOs,
1551981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           (void *)&pHwInit->auFwTmpBuf[WSPI_PAD_LEN_WRITE],
1552981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt						   (void *)(pHwInit->pFwBuf + pHwInit->uBlockReadNum * MAX_SDIO_BLOCK),
1553981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt						   pHwInit->uFwLength % MAX_SDIO_BLOCK);
1554981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1555981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Load the last block */
1556981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             BUILD_HW_INIT_FW_DL_TXN(pHwInit, pTxn, (pHwInit->uFwAddress + pHwInit->uBlockWriteNum * MAX_SDIO_BLOCK),
1557981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                     (pHwInit->auFwTmpBuf + WSPI_PAD_LEN_WRITE), (pHwInit->uFwLength % MAX_SDIO_BLOCK), TXN_DIRECTION_WRITE,
1558981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                     (TTxnDoneCb)hwInit_LoadFwImageSm, hHwInit)
1559981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TxnStatus = twIf_Transact(pHwInit->hTwIf, pTxn);
1560981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1561981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (TxnStatus == TXN_STATUS_ERROR)
1562981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			{
1563981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE1(pHwInit->hReport, REPORT_SEVERITY_ERROR , "hwInit_LoadFwImageSm: last block retruned status=0x%x\n", TxnStatus);
1564981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			}
1565981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1566981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT_L (pHwInit, TxnStatus);
1567981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1568981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1569981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 5:
1570981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uLoadStage = 0;
1571981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1572981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			/*If end of overall FW Download Process: Finalize download (run firmware)*/
1573981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			if ( pHwInit->bFwBufLast == TI_TRUE )
1574981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			{
1575981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				/* The download has completed */
1576981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				WLAN_OS_REPORT (("Finished downloading firmware.\n"));
1577981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				status = hwInit_FinalizeDownloadSm (hHwInit);
1578981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			}
1579981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			/* Have to wait to more FW Portions */
1580981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			else
1581981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			{
1582981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				/* Call the upper layer callback */
1583981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				if ( pHwInit->fFinalizeDownload != NULL )
1584981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				{
1585981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt					(pHwInit->fFinalizeDownload) (pHwInit->hFinalizeDownload);
1586981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				}
1587981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1588981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				status = TI_OK;
1589981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			}
1590981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return status;
1591981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1592981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        } /* End switch */
1593981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1594981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    } /* End while */
1595981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1596981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} /* hwInit_LoadFwImageSm() */
1597981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1598981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define READ_TOP_REG_LOOP  32
1599981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1600981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
1601981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_ReadRadioParamsSm ()
1602981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
1603981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: hwInit_ReadRadioParamsSm
1604981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:  None
1605981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1606981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
1607981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1608981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: TI_OK or TI_NOK
1609981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
1610981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_ReadRadioParamsSm (TI_HANDLE hHwInit)
1611981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1612981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    THwInit      *pHwInit = (THwInit *)hHwInit;
1613981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTwd         *pTWD = (TTwd *)pHwInit->hTWD;
1614981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt   IniFileGeneralParam *pGenParams = &DB_GEN(pTWD->hCmdBld);
1615981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32  val= 0, value;
1616981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32  add = FUNC7_SEL;
1617981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	TI_UINT32  retAddress;
1618981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct  *pTxn;
1619981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS   status = 0;
1620981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1621981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1622981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    while (TI_TRUE)
1623981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
1624981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       switch (pHwInit->uRegStage)
1625981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
1626981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 0:
1627981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uRegStage = 1;
1628981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex++;
1629981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1630981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
1631981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * Select GPIO over Debug for BT_FUNC7 clear bit 17
1632981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
1633981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, GPIO_SELECT, 0,
1634981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_ReadRadioParamsSm, hHwInit)
1635981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = twIf_Transact(pHwInit->hTwIf, pTxn);
1636981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1637981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, status)
1638981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1639981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 1:
1640981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uRegStage ++;
1641981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uRegLoop = 0;
1642981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1643981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
1644981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            val = (pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData);
1645981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            val &= 0xFFFDFFFF; /*clear bit 17*/
1646981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Now we can zero the index */
1647981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1648981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1649981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, GPIO_SELECT, val,
1650981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1651981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1652981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);
1653981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1654981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex++;
1655981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1656981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uRegData = FUNC7_SEL;
1657981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1658981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1659981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1660981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 2:
1661981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1662981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uRegStage ++;
1663981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            add = pHwInit->uRegData;
1664981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1665981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1666981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* Select GPIO over Debug for BT_FUNC7*/
1667981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            retAddress = (TI_UINT32)(add / 2);
1668981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	        val = (retAddress & 0x7FF);
1669981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        	val |= BIT_16 | BIT_17;
1670981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1671981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_CTR, val,
1672981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1673981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);
1674981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1675981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex++;
1676981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1677981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_CMD, 0x2,
1678981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1679981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);
1680981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1681981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1682981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1683981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 3:
1684981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1685981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uRegStage ++;
1686981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex++;
1687981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1688981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_DATA_RD, 0,
1689981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_ReadRadioParamsSm, hHwInit)
1690981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = twIf_Transact(pHwInit->hTwIf, pTxn);
1691981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1692981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, status)
1693981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1694981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1695981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 4:
1696981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1697981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            val = (pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData);
1698981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1699981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1700981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (val & BIT_18)
1701981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1702981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              if ((val & BIT_16) && (!(val & BIT_17)))
1703981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
1704981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  pHwInit->uRegStage ++;
1705981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  pHwInit->uRegLoop = 0;
1706981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1707981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
1708981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              else
1709981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
1710981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "can't writing bt_func7_sel\n");
1711981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1712981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TWD_FinalizeFEMRead(pHwInit->hTWD);
1713981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1714981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return TI_NOK;
1715981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
1716981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1717981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
1718981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
1719981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              if (pHwInit->uRegLoop < READ_TOP_REG_LOOP)
1720981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
1721981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 pHwInit->uRegStage = 3;
1722981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 pHwInit->uRegLoop++;
1723981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
1724981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              else
1725981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
1726981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1727981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "Timeout waiting for writing bt_func7_sel\n");
1728981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1729981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TWD_FinalizeFEMRead(pHwInit->hTWD);
1730981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1731981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return TI_NOK;
1732981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1733981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
1734981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
1735981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1736981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            continue;
1737981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1738981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 5:
1739981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               pHwInit->uRegStage ++;
1740981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               add = pHwInit->uRegData;
1741981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               retAddress = (TI_UINT32)(add / 2);
1742981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	           value = (retAddress & 0x7FF);
1743981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               value |= BIT_16 | BIT_17;
1744981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1745981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_CTR, value,
1746981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                  REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1747981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               twIf_Transact(pHwInit->hTwIf, pTxn);
1748981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1749981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               pHwInit->uTxnIndex++;
1750981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1751981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              if (pHwInit->uRegSeqStage == 0)
1752981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
1753981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  if (pHwInit->uRegData == FUNC7_SEL)
1754981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    value = (val | 0x600);
1755981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  else
1756981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    value = (val | 0x1000);
1757981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
1758981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              else
1759981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
1760981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  if (pHwInit->uRegData == FUNC7_SEL)
1761981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    value = (val & 0xF8FF);
1762981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  else
1763981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    value = (val & 0xCFFF);
1764981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1765981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
1766981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1767981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	      value &= 0xFFFF;
1768981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1769981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_WDATA, value,
1770981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                  REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1771981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               twIf_Transact(pHwInit->hTwIf, pTxn);
1772981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1773981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               pHwInit->uTxnIndex++;
1774981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1775981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_CMD, 0x1,
1776981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                  REGISTER_SIZE, TXN_DIRECTION_WRITE, (TTxnDoneCb)hwInit_ReadRadioParamsSm, hHwInit)
1777981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1778981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               /*BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, INDIRECT_REG5, 0x1,
1779981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                  REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL) */
1780981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1781981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               status = twIf_Transact(pHwInit->hTwIf, pTxn);
1782981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1783981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               pHwInit->uTxnIndex++;
1784981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1785981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               if ((pHwInit->uRegData == FUNC7_SEL)&& (pHwInit->uRegSeqStage == 0))
1786981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               {
1787981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 pHwInit->uRegData = FUNC7_PULL;
1788981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 pHwInit->uRegStage = 2;
1789981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               }
1790981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               else
1791981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               {
1792981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  if ((pHwInit->uRegData == FUNC7_PULL)&& (pHwInit->uRegSeqStage == 1))
1793981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                   {
1794981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                     pHwInit->uRegData = FUNC7_SEL;
1795981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                     pHwInit->uRegStage = 2;
1796981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                   }
1797981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               }
1798981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1799981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               EXCEPT (pHwInit, status)
1800981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               continue;
1801981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1802981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 6:
1803981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1804981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              if (pHwInit->uRegSeqStage == 1)
1805981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
1806981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  pHwInit->uRegStage = 8;
1807981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
1808981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              else
1809981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
1810981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uRegStage ++;
1811981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uTxnIndex++;
1812981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1813981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, GPIO_OE_RADIO, 0,
1814981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_ReadRadioParamsSm, hHwInit)
1815981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                status = twIf_Transact(pHwInit->hTwIf, pTxn);
1816981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                EXCEPT (pHwInit, status)
1817981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
1818981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              continue;
1819981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1820981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 7:
1821981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uRegStage ++;
1822981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1823981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* We don't zero pHwInit->uTxnIndex at the begining because we need it's value to the next transaction */
1824981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            val = (pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData);
1825981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            val |= 0x00020000;
1826981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1827981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex = 0;
1828981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, GPIO_OE_RADIO, val,
1829981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1830981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            twIf_Transact(pHwInit->hTwIf, pTxn);
1831981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1832981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pHwInit->uTxnIndex++;
1833981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1834981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, GPIO_IN, 0,
1835981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                               REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_ReadRadioParamsSm, hHwInit)
1836981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            status = twIf_Transact(pHwInit->hTwIf, pTxn);
1837981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1838981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EXCEPT (pHwInit, status)
1839981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1840981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1841981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        case 8:
1842981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (pHwInit->uRegSeqStage == 0)
1843981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             {
1844981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	       val = (pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData);
1845981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	       val &= 0x20000;
1846981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	       if(val)
1847981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	      {
1848981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		   pGenParams->TXBiPFEMManufacturer = FEM_TRIQUINT_TYPE_E;
1849981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	      }
1850981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	      else
1851981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	      {
1852981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	  	   pGenParams->TXBiPFEMManufacturer = FEM_RFMD_TYPE_E;
1853981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	      }
1854981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               WLAN_OS_REPORT (("FEM Type %d \n",pGenParams->TXBiPFEMManufacturer));
1855981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			   pHwInit->uTxnIndex = 0;
1856981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               pHwInit->uRegSeqStage = 1;
1857981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               pHwInit->uRegStage = 2;
1858981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               pHwInit->uRegData = FUNC7_PULL;
1859981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               continue;
1860981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             }
1861981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             else
1862981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             {
1863981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              TRACE0(pHwInit->hReport, REPORT_SEVERITY_INFORMATION, "hwInit_ReadRadioParamsSm Ended Successfully\n");
1864981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1865981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              TWD_FinalizeFEMRead(pHwInit->hTWD);
1866981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1867981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              return TI_OK;
1868981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1869981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             }
1870981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1871981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        } /* End switch */
1872981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1873981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    } /* End while */
1874981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1875981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1876981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1877981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1878981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
1879981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_ReadRadioParams()
1880981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
1881981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: hwInit_ReadRadioParamsSm
1882981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * initalizie hwInit_ReadRadioParamsSm parmaeters
1883981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  ****************************************************************************/
1884981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1885981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_ReadRadioParams (TI_HANDLE hHwInit)
1886981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1887981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  THwInit      *pHwInit = (THwInit *)hHwInit;
1888981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1889981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  pHwInit->uRegStage = 0;
1890981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  pHwInit->uRegSeqStage = 0;
1891981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1892981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  return hwInit_ReadRadioParamsSm (hHwInit);
1893981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1894981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1895981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
1896981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_InitPoalrity()
1897981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
1898981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: hwInit_ReadRadioParamsSm
1899981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * initalizie hwInit_ReadRadioParamsSm parmaeters
1900981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  ****************************************************************************/
1901981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1902981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS hwInit_InitPolarity(TI_HANDLE hHwInit)
1903981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
1904981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  THwInit      *pHwInit = (THwInit *)hHwInit;
1905981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1906981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  pHwInit->uRegStage = 0;
1907981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  pHwInit->uRegSeqStage = 0;
1908981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1909981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  return hwInit_WriteIRQPolarity (hHwInit);
1910981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
1911981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1912981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1913981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1914981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
1915981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      hwInit_WriteIRQPolarity ()
1916981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
1917981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: hwInit_WriteIRQPolarity
1918981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt  * INPUTS:  None
1919981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1920981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
1921981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
1922981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: TI_OK or TI_NOK
1923981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
1924981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt TI_STATUS hwInit_WriteIRQPolarity(TI_HANDLE hHwInit)
1925981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt {
1926981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     THwInit     *pHwInit = (THwInit *)hHwInit;
1927981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     TI_UINT32   Address,value;
1928981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     TI_UINT32   val=0;
1929981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     TTxnStruct  *pTxn;
1930981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     TI_STATUS   status = 0;
1931981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1932981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt   /*  To write to a top level address from the WLAN IP:
1933981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       Write the top level address to the OCP_POR_CTR register.
1934981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       Divide the top address by 2, and add 0x30000 to the result � for example for top address 0xC00, write to the OCP_POR_CTR 0x30600
1935981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       Write the data to the OCP_POR_WDATA register
1936981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       Write 0x1 to the OCP_CMD register.
1937981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1938981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      To read from a top level address:
1939981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Write the top level address to the OCP_POR_CTR register.
1940981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Divide the top address by 2, and add 0x30000 to the result � for example for top address 0xC00, write to the OCP_POR_CTR 0x30600
1941981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Write 0x2 to the OCP_CMD register.
1942981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Poll bit [18] of OCP_DATA_RD for data valid indication
1943981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Check bits 17:16 of OCP_DATA_RD:
1944981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      00 � no response
1945981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      01 � data valid / accept
1946981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      10 � request failed
1947981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      11 � response error
1948981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt      Read the data from the OCP_DATA_RD register
1949981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt   */
1950981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1951981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     while (TI_TRUE)
1952981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     {
1953981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         switch (pHwInit->uRegStage)
1954981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         {
1955981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         case 0:
1956981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1957981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             pHwInit->uRegStage = 1;
1958981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             pHwInit->uTxnIndex++;
1959981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             pHwInit->uRegLoop = 0;
1960981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1961981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             /* first read the IRQ Polarity register*/
1962981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             Address = (TI_UINT32)(FN0_CCCR_REG_32 / 2);
1963981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             val = (Address & 0x7FF);
1964981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             val |= BIT_16 | BIT_17;
1965981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1966981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             /* Write IRQ Polarity address register to OCP_POR_CTR*/
1967981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_CTR, val,
1968981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1969981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1970981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             twIf_Transact(pHwInit->hTwIf, pTxn);
1971981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1972981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             pHwInit->uTxnIndex++;
1973981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1974981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             /* Write read (2)command to the OCP_CMD register. */
1975981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1976981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_CMD, 0x2,
1977981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
1978981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             twIf_Transact(pHwInit->hTwIf, pTxn);
1979981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1980981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             continue;
1981981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1982981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         case 1:
1983981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1984981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             pHwInit->uRegStage ++;
1985981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             pHwInit->uTxnIndex++;
1986981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1987981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_DATA_RD, 0,
1988981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_WriteIRQPolarity, hHwInit)
1989981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             status = twIf_Transact(pHwInit->hTwIf, pTxn);
1990981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1991981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             EXCEPT (pHwInit, status)
1992981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1993981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1994981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         case 2:
1995981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             /* get the value from  IRQ Polarity register*/
1996981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             val = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
1997981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
1998981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             pHwInit->uTxnIndex = 0;
1999981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2000981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             /*Poll bit 18 of OCP_DATA_RD for data valid indication*/
2001981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             if (val & BIT_18)
2002981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             {
2003981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               if ((val & BIT_16) && (!(val & BIT_17)))
2004981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               {
2005981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                   pHwInit->uRegStage ++;
2006981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                   pHwInit->uRegLoop = 0;
2007981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2008981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               }
2009981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               else
2010981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               {
2011981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "can't writing bt_func7_sel\n");
2012981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 TWD_FinalizePolarityRead(pHwInit->hTWD);
2013981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2014981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return TI_NOK;
2015981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               }
2016981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             }
2017981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             else
2018981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             {
2019981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               if (pHwInit->uRegLoop < READ_TOP_REG_LOOP)
2020981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               {
2021981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  pHwInit->uRegStage = 1;
2022981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  pHwInit->uRegLoop++;
2023981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               }
2024981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               else
2025981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               {
2026981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2027981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "Timeout waiting for writing bt_func7_sel\n");
2028981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                 TWD_FinalizePolarityRead(pHwInit->hTWD);
2029981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2030981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                return TI_NOK;
2031981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2032981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               }
2033981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             }
2034981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2035981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             continue;
2036981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2037981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2038981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         case 3:
2039981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               /* second, write new value of IRQ polarity due to complation flag 1 - active low, 0 - active high*/
2040981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uRegStage ++;
2041981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                Address = (TI_UINT32)(FN0_CCCR_REG_32 / 2);
2042981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                value = (Address & 0x7FF);
2043981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                value |= BIT_16 | BIT_17;
2044981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2045981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* Write IRQ Polarity address register to OCP_POR_CTR*/
2046981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2047981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_CTR, value,
2048981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                   REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
2049981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2050981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                twIf_Transact(pHwInit->hTwIf, pTxn);
2051981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2052981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uTxnIndex++;
2053981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2054981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef USE_IRQ_ACTIVE_HIGH
2055981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE0(pHwInit->hReport, REPORT_SEVERITY_INFORMATION , "Hwinit IRQ polarity active high\n");
2056981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                val |= 0x0<<1;
2057981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2058981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#else
2059981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE0(pHwInit->hReport, REPORT_SEVERITY_INFORMATION , "Hwinit IRQ polarity active low\n");
2060981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                val |= 0x01<<1;
2061981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
2062981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2063981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              /* Write the new IRQ polarity value to the OCP_POR_WDATA register */
2064981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_WDATA, val,
2065981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                   REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
2066981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                twIf_Transact(pHwInit->hTwIf, pTxn);
2067981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2068981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uTxnIndex++;
2069981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2070981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               /* Write write (1)command to the OCP_CMD register. */
2071981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_CMD, 0x1,
2072981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                   REGISTER_SIZE, TXN_DIRECTION_WRITE, (TTxnDoneCb)hwInit_WriteIRQPolarity, hHwInit)
2073981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                status = twIf_Transact(pHwInit->hTwIf, pTxn);
2074981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2075981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pHwInit->uTxnIndex++;
2076981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2077981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                EXCEPT (pHwInit, status)
2078981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                continue;
2079981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2080981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         case 4:
2081981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2082981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt               TWD_FinalizePolarityRead(pHwInit->hTWD);
2083981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2084981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              return TI_OK;
2085981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2086981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2087981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         } /* End switch */
2088981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2089981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     } /* End while */
2090981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2091981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt }
2092981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2093981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2094653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt/****************************************************************************
2095653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt *                      hwInit_InitTopRegisterWrite()
2096653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt ****************************************************************************
2097653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * DESCRIPTION: hwInit_InitTopRegisterWrite
2098653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * initalizie hwInit_TopRegisterWrite SM parmaeters
2099653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  ****************************************************************************/
2100653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2101653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry ShmidtTI_STATUS hwInit_InitTopRegisterWrite(TI_HANDLE hHwInit, TI_UINT32 uAddress, TI_UINT32 uValue)
2102653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt{
2103653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  THwInit      *pHwInit = (THwInit *)hHwInit;
2104653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2105653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  pHwInit->uTopStage = 0;
2106653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  uAddress = (TI_UINT32)(uAddress / 2);
2107653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  uAddress = (uAddress & 0x7FF);
2108653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  uAddress|= BIT_16 | BIT_17;
2109653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  pHwInit->uTopRegAddr = uAddress;
2110653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  pHwInit->uTopRegValue = uValue & 0xffff;
2111653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  return hwInit_TopRegisterWrite (hHwInit);
2112653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt}
2113653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2114653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2115653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt/****************************************************************************
2116653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt *                      hwInit_WriteTopRegister ()
2117653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt ****************************************************************************
2118653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * DESCRIPTION: Generic function that writes to the top registers area
2119653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  * INPUTS:  None
2120653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt *
2121653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * OUTPUT:  None
2122653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt *
2123653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * RETURNS: TI_OK or TI_NOK
2124653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt ****************************************************************************/
2125653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt TI_STATUS hwInit_TopRegisterWrite(TI_HANDLE hHwInit)
2126653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt {
2127653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     /*  To write to a top level address from the WLAN IP:
2128653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         Write the top level address to the OCP_POR_CTR register.
2129653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         Divide the top address by 2, and add 0x30000 to the result � for example for top address 0xC00, write to the OCP_POR_CTR 0x30600
2130653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         Write the data to the OCP_POR_WDATA register
2131653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         Write 0x1 to the OCP_CMD register.
2132653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     */
2133653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     THwInit *pHwInit = (THwInit *)hHwInit;
2134653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     TTxnStruct *pTxn;
2135653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     TI_STATUS status = 0;
2136653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2137653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     while (TI_TRUE)
2138653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     {
2139653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         switch (pHwInit->uTopStage)
2140653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         {
2141653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         case 0:
2142653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTopStage = 1;
2143653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2144653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex++;
2145653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             /* Write the address to OCP_POR_CTR*/
2146653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_CTR, pHwInit->uTopRegAddr,
2147653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                                    REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
2148653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             twIf_Transact(pHwInit->hTwIf, pTxn);
2149653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2150653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex++;
2151653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             /* Write the new value to the OCP_POR_WDATA register */
2152653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_WDATA, pHwInit->uTopRegValue,
2153653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                                    REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
2154653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             twIf_Transact(pHwInit->hTwIf, pTxn);
2155653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2156653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex++;
2157653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             /* Write write (1)command to the OCP_CMD register. */
2158653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_CMD, 0x1,
2159653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                                    REGISTER_SIZE, TXN_DIRECTION_WRITE, (TTxnDoneCb)hwInit_TopRegisterWrite, hHwInit)
2160653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             status = twIf_Transact(pHwInit->hTwIf, pTxn);
2161653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2162653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex++;
2163653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2164653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             EXCEPT (pHwInit, status)
2165653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             continue;
2166653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2167653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         case 1:
2168653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2169653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex = 0;
2170653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2171653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             return TI_OK;
2172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
2173653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         } /* End switch */
2174653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2175653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     } /* End while */
2176653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2177653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt }
2178653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2179653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2180653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt /****************************************************************************
2181653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt *                      hwInit_InitTopRegisterWrite()
2182653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt ****************************************************************************
2183653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * DESCRIPTION: hwInit_InitTopRegisterWrite
2184653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * initalizie hwInit_TopRegisterWrite SM parmaeters
2185653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  ****************************************************************************/
2186653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2187653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry ShmidtTI_STATUS hwInit_InitTopRegisterRead(TI_HANDLE hHwInit, TI_UINT32 uAddress)
2188653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt{
2189653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  THwInit      *pHwInit = (THwInit *)hHwInit;
2190653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2191653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  pHwInit->uTopStage = 0;
2192653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  uAddress = (TI_UINT32)(uAddress / 2);
2193653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  uAddress = (uAddress & 0x7FF);
2194653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  uAddress|= BIT_16 | BIT_17;
2195653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  pHwInit->uTopRegAddr = uAddress;
2196653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  return hwInit_TopRegisterRead (hHwInit);
2197653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt}
2198653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2199653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2200653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt/****************************************************************************
2201653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt *                      hwInit_WriteTopRegister ()
2202653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt ****************************************************************************
2203653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * DESCRIPTION: Generic function that writes to the top registers area
2204653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt  * INPUTS:  None
2205653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt *
2206653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * OUTPUT:  None
2207653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt *
2208653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt * RETURNS: TI_OK or TI_NOK
2209653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt ****************************************************************************/
2210653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt TI_STATUS hwInit_TopRegisterRead(TI_HANDLE hHwInit)
2211653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt {
2212653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     /*
2213653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        To read from a top level address:
2214653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        Write the top level address to the OCP_POR_CTR register.
2215653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        Divide the top address by 2, and add 0x30000 to the result � for example for top address 0xC00, write to the OCP_POR_CTR 0x30600
2216653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        Write 0x2 to the OCP_CMD register.
2217653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        Poll bit [18] of OCP_DATA_RD for data valid indication
2218653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        Check bits 17:16 of OCP_DATA_RD:
2219653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        00 � no response
2220653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        01 � data valid / accept
2221653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        10 � request failed
2222653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        11 � response error
2223653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        Read the data from the OCP_DATA_RD register
2224653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     */
2225653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2226653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     THwInit *pHwInit = (THwInit *)hHwInit;
2227653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     TTxnStruct *pTxn;
2228653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     TI_STATUS status = 0;
2229653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2230653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     while (TI_TRUE)
2231653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     {
2232653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         switch (pHwInit->uTopStage)
2233653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         {
2234653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         case 0:
2235653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTopStage = 1;
2236653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex++;
2237653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uRegLoop = 0;
2238653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2239653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             /* Write the address to OCP_POR_CTR*/
2240653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_POR_CTR, pHwInit->uTopRegAddr,
2241653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                                    REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
2242653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             twIf_Transact(pHwInit->hTwIf, pTxn);
2243653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2244653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex++;
2245653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_CMD, 0x2,
2246653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                                    REGISTER_SIZE, TXN_DIRECTION_WRITE, NULL, NULL)
2247653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             twIf_Transact(pHwInit->hTwIf, pTxn);
2248653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2249653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             continue;
2250653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2251653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         case 1:
2252653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTopStage ++;
2253653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex++;
2254653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2255653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             BUILD_HW_INIT_TXN_DATA(pHwInit, pTxn, OCP_DATA_RD, 0,
2256653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                                    REGISTER_SIZE, TXN_DIRECTION_READ, (TTxnDoneCb)hwInit_TopRegisterRead, hHwInit)
2257653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             status = twIf_Transact(pHwInit->hTwIf, pTxn);
2258653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2259653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             EXCEPT (pHwInit, status)
2260653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2261653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         case 2:
2262653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             /* get the value from  IRQ Polarity register*/
2263653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTopRegValue = pHwInit->aHwInitTxn[pHwInit->uTxnIndex].uData;
2264653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2265653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             pHwInit->uTxnIndex = 0;
2266653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2267653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             /*Poll bit 18 of OCP_DATA_RD for data valid indication*/
2268653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             if (pHwInit->uTopRegValue & BIT_18)
2269653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             {
2270653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               if ((pHwInit->uTopRegValue & BIT_16) && (!(pHwInit->uTopRegValue & BIT_17)))
2271653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               {
2272653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                   pHwInit->uTopRegValue &= 0xffff;
2273653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                   pHwInit->uTxnIndex = 0;
2274653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                   pHwInit->uRegLoop = 0;
2275653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                   return TI_OK;
2276653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               }
2277653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               else
2278653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               {
2279653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                 TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "can't writing bt_func7_sel\n");
2280653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                 return TI_NOK;
2281653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               }
2282653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             }
2283653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             else
2284653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             {
2285653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               if (pHwInit->uRegLoop < READ_TOP_REG_LOOP)
2286653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               {
2287653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                  pHwInit->uTopStage = 1;
2288653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                  pHwInit->uRegLoop++;
2289653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               }
2290653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               else
2291653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               {
2292653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                 TRACE0(pHwInit->hReport, REPORT_SEVERITY_ERROR , "Timeout waiting for writing bt_func7_sel\n");
2293653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                 return TI_NOK;
2294653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt               }
2295653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt              }
2296653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2297653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt             continue;
2298653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2299653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt         } /* End switch */
2300653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2301653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt     } /* End while */
2302653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
2303653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt }
2304