SAMA5D4 Xplained Ultra Board BSP
guowenxue
2019-08-19 2e7235d10c6dbff81960282e1a1e2e798f9b8db8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/******************************************************************************
 *
 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 *
 *
 ******************************************************************************/
/******************************************************************************
 *
 *
 * Module:    rtl8188e_rf6052.c    ( Source C File)
 *
 * Note:    Provide RF 6052 series relative API.
 *
 * Function:
 *
 * Export:
 *
 * Abbrev:
 *
 * History:
 * Data            Who        Remark
 *
 * 09/25/2008    MHC        Create initial version.
 * 11/05/2008    MHC        Add API for tw power setting.
 *
 *
******************************************************************************/
 
#define _RTL8188E_RF6052_C_
 
#include <drv_types.h>
#include <rtl8188e_hal.h>
 
/*---------------------------Define Local Constant---------------------------*/
 
/*---------------------------Define Local Constant---------------------------*/
 
 
/*------------------------Define global variable-----------------------------*/
/*------------------------Define global variable-----------------------------*/
 
 
/*------------------------Define local variable------------------------------*/
 
/*------------------------Define local variable------------------------------*/
 
 
/*-----------------------------------------------------------------------------
 * Function:    RF_ChangeTxPath
 *
 * Overview:    For RL6052, we must change some RF settign for 1T or 2T.
 *
 * Input:        u2Byte DataRate        // 0x80-8f, 0x90-9f
 *
 * Output:      NONE
 *
 * Return:      NONE
 *
 * Revised History:
 * When            Who        Remark
 * 09/25/2008    MHC        Create Version 0.
 *                        Firmwaer support the utility later.
 *
 *---------------------------------------------------------------------------*/
void rtl8188e_RF_ChangeTxPath(IN    PADAPTER    Adapter,
                  IN    u16        DataRate)
{
    /* We do not support gain table change inACUT now !!!! Delete later !!! */
#if 0/* (RTL92SE_FPGA_VERIFY == 0) */
    static    u1Byte    RF_Path_Type = 2;    /* 1 = 1T 2= 2T */
    static    u4Byte    tx_gain_tbl1[6]
        = {0x17f50, 0x11f40, 0x0cf30, 0x08720, 0x04310, 0x00100};
    static    u4Byte    tx_gain_tbl2[6]
        = {0x15ea0, 0x10e90, 0x0c680, 0x08250, 0x04040, 0x00030};
    u1Byte    i;
 
    if (RF_Path_Type == 2 && (DataRate & 0xF) <= 0x7) {
        /* Set TX SYNC power G2G3 loop filter */
        phy_set_rf_reg(Adapter, RF_PATH_A,
                 RF_TXPA_G2, bRFRegOffsetMask, 0x0f000);
        phy_set_rf_reg(Adapter, RF_PATH_A,
                 RF_TXPA_G3, bRFRegOffsetMask, 0xeacf1);
 
        /* Change TX AGC gain table */
        for (i = 0; i < 6; i++)
            phy_set_rf_reg(Adapter, RF_PATH_A,
                RF_TX_AGC, bRFRegOffsetMask, tx_gain_tbl1[i]);
 
        /* Set PA to high value */
        phy_set_rf_reg(Adapter, RF_PATH_A,
                 RF_TXPA_G2, bRFRegOffsetMask, 0x01e39);
    } else if (RF_Path_Type == 1 && (DataRate & 0xF) >= 0x8) {
        /* Set TX SYNC power G2G3 loop filter */
        phy_set_rf_reg(Adapter, RF_PATH_A,
                 RF_TXPA_G2, bRFRegOffsetMask, 0x04440);
        phy_set_rf_reg(Adapter, RF_PATH_A,
                 RF_TXPA_G3, bRFRegOffsetMask, 0xea4f1);
 
        /* Change TX AGC gain table */
        for (i = 0; i < 6; i++)
            phy_set_rf_reg(Adapter, RF_PATH_A,
                RF_TX_AGC, bRFRegOffsetMask, tx_gain_tbl2[i]);
 
        /* Set PA low gain */
        phy_set_rf_reg(Adapter, RF_PATH_A,
                 RF_TXPA_G2, bRFRegOffsetMask, 0x01e19);
    }
#endif
 
}    /* RF_ChangeTxPath */
 
 
/*-----------------------------------------------------------------------------
 * Function:    PHY_RF6052SetBandwidth()
 *
 * Overview:    This function is called by SetBWModeCallback8190Pci() only
 *
 * Input:       PADAPTER                Adapter
 *            WIRELESS_BANDWIDTH_E    Bandwidth    //20M or 40M
 *
 * Output:      NONE
 *
 * Return:      NONE
 *
 * Note:        For RF type 0222D
 *---------------------------------------------------------------------------*/
VOID
rtl8188e_PHY_RF6052SetBandwidth(
    IN    PADAPTER                Adapter,
    IN    CHANNEL_WIDTH        Bandwidth)    /* 20M or 40M */
{
    HAL_DATA_TYPE    *pHalData = GET_HAL_DATA(Adapter);
 
    switch (Bandwidth) {
    case CHANNEL_WIDTH_20:
        pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT(10) | BIT(11));
        phy_set_rf_reg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
        break;
 
    case CHANNEL_WIDTH_40:
        pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT(10));
        phy_set_rf_reg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
        break;
 
    default:
        break;
    }
 
}
 
static int
phy_RF6052_Config_ParaFile(
    IN    PADAPTER        Adapter
)
{
    u32                    u4RegValue = 0;
    u8                    eRFPath;
    BB_REGISTER_DEFINITION_T    *pPhyReg;
 
    int                    rtStatus = _SUCCESS;
    HAL_DATA_TYPE        *pHalData = GET_HAL_DATA(Adapter);
 
    /* 3 */ /* ----------------------------------------------------------------- */
    /* 3 */ /* <2> Initialize RF */
    /* 3 */ /* ----------------------------------------------------------------- */
    /* for(eRFPath = RF_PATH_A; eRFPath <pHalData->NumTotalRFPath; eRFPath++) */
    for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++) {
 
        pPhyReg = &pHalData->PHYRegDef[eRFPath];
 
        /*----Store original RFENV control type----*/
        switch (eRFPath) {
        case RF_PATH_A:
        case RF_PATH_C:
            u4RegValue = phy_query_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV);
            break;
        case RF_PATH_B:
        case RF_PATH_D:
            u4RegValue = phy_query_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV << 16);
            break;
        }
 
        /*----Set RF_ENV enable----*/
        phy_set_bb_reg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV << 16, 0x1);
        rtw_udelay_os(1);/* PlatformStallExecution(1); */
 
        /*----Set RF_ENV output high----*/
        phy_set_bb_reg(Adapter, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
        rtw_udelay_os(1);/* PlatformStallExecution(1); */
 
        /* Set bit number of Address and Data for RF register */
        phy_set_bb_reg(Adapter, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0);    /* Set 1 to 4 bits for 8255 */
        rtw_udelay_os(1);/* PlatformStallExecution(1); */
 
        phy_set_bb_reg(Adapter, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0);    /* Set 0 to 12  bits for 8255 */
        rtw_udelay_os(1);/* PlatformStallExecution(1); */
 
        /*----Initialize RF fom connfiguration file----*/
        switch (eRFPath) {
        case RF_PATH_A:
#ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
            if (PHY_ConfigRFWithParaFile(Adapter, PHY_FILE_RADIO_A, eRFPath) == _FAIL)
#endif
            {
#ifdef CONFIG_EMBEDDED_FWIMG
                if (HAL_STATUS_FAILURE == odm_config_rf_with_header_file(&pHalData->odmpriv, CONFIG_RF_RADIO, (enum odm_rf_radio_path_e)eRFPath))
                    rtStatus = _FAIL;
#endif
            }
            break;
        case RF_PATH_B:
#ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
            if (PHY_ConfigRFWithParaFile(Adapter, PHY_FILE_RADIO_B, eRFPath) == _FAIL)
#endif
            {
#ifdef CONFIG_EMBEDDED_FWIMG
                if (HAL_STATUS_FAILURE == odm_config_rf_with_header_file(&pHalData->odmpriv, CONFIG_RF_RADIO, (enum odm_rf_radio_path_e)eRFPath))
                    rtStatus = _FAIL;
#endif
            }
            break;
        case RF_PATH_C:
            break;
        case RF_PATH_D:
            break;
        }
 
        /*----Restore RFENV control type----*/;
        switch (eRFPath) {
        case RF_PATH_A:
        case RF_PATH_C:
            phy_set_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
            break;
        case RF_PATH_B:
        case RF_PATH_D:
            phy_set_bb_reg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV << 16, u4RegValue);
            break;
        }
 
        if (rtStatus != _SUCCESS) {
            goto phy_RF6052_Config_ParaFile_Fail;
        }
 
    }
 
 
    /* 3 ----------------------------------------------------------------- */
    /* 3 Configuration of Tx Power Tracking */
    /* 3 ----------------------------------------------------------------- */
 
#ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
    if (PHY_ConfigRFWithTxPwrTrackParaFile(Adapter, PHY_FILE_TXPWR_TRACK) == _FAIL)
#endif
    {
#ifdef CONFIG_EMBEDDED_FWIMG
        odm_config_rf_with_tx_pwr_track_header_file(&pHalData->odmpriv);
#endif
    }
 
    return rtStatus;
 
phy_RF6052_Config_ParaFile_Fail:
    return rtStatus;
}
 
 
int
PHY_RF6052_Config8188E(
    IN    PADAPTER        Adapter)
{
    HAL_DATA_TYPE                *pHalData = GET_HAL_DATA(Adapter);
    int                    rtStatus = _SUCCESS;
 
    /*  */
    /* Initialize general global value */
    /*  */
    /* TODO: Extend RF_PATH_C and RF_PATH_D in the future */
    if (pHalData->rf_type == RF_1T1R)
        pHalData->NumTotalRFPath = 1;
    else
        pHalData->NumTotalRFPath = 2;
 
    /*  */
    /* Config BB and RF */
    /*  */
    rtStatus = phy_RF6052_Config_ParaFile(Adapter);
#if 0
    switch (Adapter->MgntInfo.bRegHwParaFile) {
    case 0:
        phy_RF6052_Config_HardCode(Adapter);
        break;
 
    case 1:
        rtStatus = phy_RF6052_Config_ParaFile(Adapter);
        break;
 
    case 2:
        /* Partial Modify. */
        phy_RF6052_Config_HardCode(Adapter);
        phy_RF6052_Config_ParaFile(Adapter);
        break;
 
    default:
        phy_RF6052_Config_HardCode(Adapter);
        break;
    }
#endif
    return rtStatus;
 
}
 
/* End of HalRf6052.c */