GNU Linux-libre 4.14.259-gnu1
[releases.git] / drivers / staging / rtl8723bs / hal / rtl8723b_rf6052.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  ******************************************************************************/
15 /******************************************************************************
16  *
17  *
18  * Module:      rtl8192c_rf6052.c       (Source C File)
19  *
20  * Note:        Provide RF 6052 series relative API.
21  *
22  * Function:
23  *
24  * Export:
25  *
26  * Abbrev:
27  *
28  * History:
29  * Data                 Who             Remark
30  *
31  * 09/25/2008   MHC             Create initial version.
32  * 11/05/2008   MHC             Add API for tw power setting.
33  *
34  *
35 ******************************************************************************/
36
37 #include <rtl8723b_hal.h>
38
39 /*---------------------------Define Local Constant---------------------------*/
40 /*---------------------------Define Local Constant---------------------------*/
41
42
43 /*------------------------Define global variable-----------------------------*/
44 /*------------------------Define global variable-----------------------------*/
45
46
47 /*------------------------Define local variable------------------------------*/
48 /*  2008/11/20 MH For Debug only, RF */
49 /*------------------------Define local variable------------------------------*/
50
51 /*-----------------------------------------------------------------------------
52  * Function:    PHY_RF6052SetBandwidth()
53  *
54  * Overview:    This function is called by SetBWModeCallback8190Pci() only
55  *
56  * Input:       struct adapter *                        Adapter
57  *              WIRELESS_BANDWIDTH_E    Bandwidth       20M or 40M
58  *
59  * Output:      NONE
60  *
61  * Return:      NONE
62  *
63  * Note:                For RF type 0222D
64  *---------------------------------------------------------------------------*/
65 void PHY_RF6052SetBandwidth8723B(
66         struct adapter *Adapter, enum CHANNEL_WIDTH Bandwidth
67 ) /* 20M or 40M */
68 {
69         struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
70
71         switch (Bandwidth) {
72         case CHANNEL_WIDTH_20:
73                 pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT10 | BIT11);
74                 PHY_SetRFReg(Adapter, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
75                 PHY_SetRFReg(Adapter, ODM_RF_PATH_B, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
76                 break;
77
78         case CHANNEL_WIDTH_40:
79                 pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | BIT10);
80                 PHY_SetRFReg(Adapter, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
81                 PHY_SetRFReg(Adapter, ODM_RF_PATH_B, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]);
82                 break;
83
84         default:
85                 /* RT_TRACE(COMP_DBG, DBG_LOUD, ("PHY_SetRF8225Bandwidth(): unknown Bandwidth: %#X\n", Bandwidth)); */
86                 break;
87         }
88
89 }
90
91 static int phy_RF6052_Config_ParaFile(struct adapter *Adapter)
92 {
93         u32 u4RegValue = 0;
94         u8 eRFPath;
95         struct bb_register_def *pPhyReg;
96
97         int rtStatus = _SUCCESS;
98         struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
99
100         static char sz8723RadioAFile[] = RTL8723B_PHY_RADIO_A;
101         static char sz8723RadioBFile[] = RTL8723B_PHY_RADIO_B;
102         static s8 sz8723BTxPwrTrackFile[] = RTL8723B_TXPWR_TRACK;
103         char *pszRadioAFile, *pszRadioBFile, *pszTxPwrTrackFile;
104
105         pszRadioAFile = sz8723RadioAFile;
106         pszRadioBFile = sz8723RadioBFile;
107         pszTxPwrTrackFile = sz8723BTxPwrTrackFile;
108
109         /* 3----------------------------------------------------------------- */
110         /* 3 <2> Initialize RF */
111         /* 3----------------------------------------------------------------- */
112         /* for (eRFPath = RF_PATH_A; eRFPath <pHalData->NumTotalRFPath; eRFPath++) */
113         for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++) {
114
115                 pPhyReg = &pHalData->PHYRegDef[eRFPath];
116
117                 /*----Store original RFENV control type----*/
118                 switch (eRFPath) {
119                 case RF_PATH_A:
120                 case RF_PATH_C:
121                         u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV);
122                         break;
123                 case RF_PATH_B:
124                 case RF_PATH_D:
125                         u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV<<16);
126                         break;
127                 }
128
129                 /*----Set RF_ENV enable----*/
130                 PHY_SetBBReg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
131                 udelay(1);/* PlatformStallExecution(1); */
132
133                 /*----Set RF_ENV output high----*/
134                 PHY_SetBBReg(Adapter, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
135                 udelay(1);/* PlatformStallExecution(1); */
136
137                 /* Set bit number of Address and Data for RF register */
138                 PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0);  /*  Set 1 to 4 bits for 8255 */
139                 udelay(1);/* PlatformStallExecution(1); */
140
141                 PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0);     /*  Set 0 to 12  bits for 8255 */
142                 udelay(1);/* PlatformStallExecution(1); */
143
144                 /*----Initialize RF fom connfiguration file----*/
145                 switch (eRFPath) {
146                 case RF_PATH_A:
147                         if (PHY_ConfigRFWithParaFile(Adapter, pszRadioAFile,
148                                                      eRFPath) == _FAIL) {
149                                 if (HAL_STATUS_FAILURE == ODM_ConfigRFWithHeaderFile(&pHalData->odmpriv, CONFIG_RF_RADIO, (ODM_RF_RADIO_PATH_E)eRFPath))
150                                         rtStatus = _FAIL;
151                         }
152                         break;
153                 case RF_PATH_B:
154                         if (PHY_ConfigRFWithParaFile(Adapter, pszRadioBFile,
155                                                      eRFPath) == _FAIL) {
156                                 if (HAL_STATUS_FAILURE == ODM_ConfigRFWithHeaderFile(&pHalData->odmpriv, CONFIG_RF_RADIO, (ODM_RF_RADIO_PATH_E)eRFPath))
157                                         rtStatus = _FAIL;
158                         }
159                         break;
160                 case RF_PATH_C:
161                         break;
162                 case RF_PATH_D:
163                         break;
164                 }
165
166                 /*----Restore RFENV control type----*/;
167                 switch (eRFPath) {
168                 case RF_PATH_A:
169                 case RF_PATH_C:
170                         PHY_SetBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue);
171                         break;
172                 case RF_PATH_B:
173                 case RF_PATH_D:
174                         PHY_SetBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue);
175                         break;
176                 }
177
178                 if (rtStatus != _SUCCESS) {
179                         /* RT_TRACE(COMP_FPGA, DBG_LOUD, ("phy_RF6052_Config_ParaFile():Radio[%d] Fail!!", eRFPath)); */
180                         goto phy_RF6052_Config_ParaFile_Fail;
181                 }
182
183         }
184
185         /* 3 ----------------------------------------------------------------- */
186         /* 3 Configuration of Tx Power Tracking */
187         /* 3 ----------------------------------------------------------------- */
188
189         if (PHY_ConfigRFWithTxPwrTrackParaFile(Adapter, pszTxPwrTrackFile) ==
190                 _FAIL) {
191                 ODM_ConfigRFWithTxPwrTrackHeaderFile(&pHalData->odmpriv);
192         }
193
194         /* RT_TRACE(COMP_INIT, DBG_LOUD, ("<---phy_RF6052_Config_ParaFile()\n")); */
195         return rtStatus;
196
197 phy_RF6052_Config_ParaFile_Fail:
198         return rtStatus;
199 }
200
201
202 int PHY_RF6052_Config8723B(struct adapter *Adapter)
203 {
204         struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
205         int rtStatus = _SUCCESS;
206
207         /*  */
208         /*  Initialize general global value */
209         /*  */
210         /*  TODO: Extend RF_PATH_C and RF_PATH_D in the future */
211         if (pHalData->rf_type == RF_1T1R)
212                 pHalData->NumTotalRFPath = 1;
213         else
214                 pHalData->NumTotalRFPath = 2;
215
216         /*  */
217         /*  Config BB and RF */
218         /*  */
219         rtStatus = phy_RF6052_Config_ParaFile(Adapter);
220         return rtStatus;
221
222 }
223
224 /* End of HalRf6052.c */