MAINTAINERS: update Shawn's email address
[sfrench/cifs-2.6.git] / drivers / staging / rtl8188eu / hal / HalHWImg8188E_RF.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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/
20
21 #include "odm_precomp.h"
22
23 #include <rtw_iol.h>
24
25 static bool CheckCondition(const u32  Condition, const u32  Hex)
26 {
27         u32 _board     = (Hex & 0x000000FF);
28         u32 _interface = (Hex & 0x0000FF00) >> 8;
29         u32 _platform  = (Hex & 0x00FF0000) >> 16;
30         u32 cond = Condition;
31
32         if (Condition == 0xCDCDCDCD)
33                 return true;
34
35         cond = Condition & 0x000000FF;
36         if ((_board == cond) && cond != 0x00)
37                 return false;
38
39         cond = Condition & 0x0000FF00;
40         cond = cond >> 8;
41         if ((_interface & cond) == 0 && cond != 0x07)
42                 return false;
43
44         cond = Condition & 0x00FF0000;
45         cond = cond >> 16;
46         if ((_platform & cond) == 0 && cond != 0x0F)
47                 return false;
48         return true;
49 }
50
51
52 /******************************************************************************
53 *                           RadioA_1T.TXT
54 ******************************************************************************/
55
56 static u32 Array_RadioA_1T_8188E[] = {
57                 0x000, 0x00030000,
58                 0x008, 0x00084000,
59                 0x018, 0x00000407,
60                 0x019, 0x00000012,
61                 0x01E, 0x00080009,
62                 0x01F, 0x00000880,
63                 0x02F, 0x0001A060,
64                 0x03F, 0x00000000,
65                 0x042, 0x000060C0,
66                 0x057, 0x000D0000,
67                 0x058, 0x000BE180,
68                 0x067, 0x00001552,
69                 0x083, 0x00000000,
70                 0x0B0, 0x000FF8FC,
71                 0x0B1, 0x00054400,
72                 0x0B2, 0x000CCC19,
73                 0x0B4, 0x00043003,
74                 0x0B6, 0x0004953E,
75                 0x0B7, 0x0001C718,
76                 0x0B8, 0x000060FF,
77                 0x0B9, 0x00080001,
78                 0x0BA, 0x00040000,
79                 0x0BB, 0x00000400,
80                 0x0BF, 0x000C0000,
81                 0x0C2, 0x00002400,
82                 0x0C3, 0x00000009,
83                 0x0C4, 0x00040C91,
84                 0x0C5, 0x00099999,
85                 0x0C6, 0x000000A3,
86                 0x0C7, 0x00088820,
87                 0x0C8, 0x00076C06,
88                 0x0C9, 0x00000000,
89                 0x0CA, 0x00080000,
90                 0x0DF, 0x00000180,
91                 0x0EF, 0x000001A0,
92                 0x051, 0x0006B27D,
93                 0xFF0F041F, 0xABCD,
94                 0x052, 0x0007E4DD,
95                 0xCDCDCDCD, 0xCDCD,
96                 0x052, 0x0007E49D,
97                 0xFF0F041F, 0xDEAD,
98                 0x053, 0x00000073,
99                 0x056, 0x00051FF3,
100                 0x035, 0x00000086,
101                 0x035, 0x00000186,
102                 0x035, 0x00000286,
103                 0x036, 0x00001C25,
104                 0x036, 0x00009C25,
105                 0x036, 0x00011C25,
106                 0x036, 0x00019C25,
107                 0x0B6, 0x00048538,
108                 0x018, 0x00000C07,
109                 0x05A, 0x0004BD00,
110                 0x019, 0x000739D0,
111                 0x034, 0x0000ADF3,
112                 0x034, 0x00009DF0,
113                 0x034, 0x00008DED,
114                 0x034, 0x00007DEA,
115                 0x034, 0x00006DE7,
116                 0x034, 0x000054EE,
117                 0x034, 0x000044EB,
118                 0x034, 0x000034E8,
119                 0x034, 0x0000246B,
120                 0x034, 0x00001468,
121                 0x034, 0x0000006D,
122                 0x000, 0x00030159,
123                 0x084, 0x00068200,
124                 0x086, 0x000000CE,
125                 0x087, 0x00048A00,
126                 0x08E, 0x00065540,
127                 0x08F, 0x00088000,
128                 0x0EF, 0x000020A0,
129                 0x03B, 0x000F02B0,
130                 0x03B, 0x000EF7B0,
131                 0x03B, 0x000D4FB0,
132                 0x03B, 0x000CF060,
133                 0x03B, 0x000B0090,
134                 0x03B, 0x000A0080,
135                 0x03B, 0x00090080,
136                 0x03B, 0x0008F780,
137                 0x03B, 0x000722B0,
138                 0x03B, 0x0006F7B0,
139                 0x03B, 0x00054FB0,
140                 0x03B, 0x0004F060,
141                 0x03B, 0x00030090,
142                 0x03B, 0x00020080,
143                 0x03B, 0x00010080,
144                 0x03B, 0x0000F780,
145                 0x0EF, 0x000000A0,
146                 0x000, 0x00010159,
147                 0x018, 0x0000F407,
148                 0xFFE, 0x00000000,
149                 0xFFE, 0x00000000,
150                 0x01F, 0x00080003,
151                 0xFFE, 0x00000000,
152                 0xFFE, 0x00000000,
153                 0x01E, 0x00000001,
154                 0x01F, 0x00080000,
155                 0x000, 0x00033E60,
156 };
157
158 enum HAL_STATUS ODM_ReadAndConfig_RadioA_1T_8188E(struct odm_dm_struct *pDM_Odm)
159 {
160         #define READ_NEXT_PAIR(v1, v2, i) do    \
161                  { i += 2; v1 = Array[i];       \
162                  v2 = Array[i+1]; } while (0)
163
164         u32     hex         = 0;
165         u32     i           = 0;
166         u8     platform    = pDM_Odm->SupportPlatform;
167         u8     interfaceValue   = pDM_Odm->SupportInterface;
168         u8     board       = pDM_Odm->BoardType;
169         u32     ArrayLen    = sizeof(Array_RadioA_1T_8188E)/sizeof(u32);
170         u32    *Array       = Array_RadioA_1T_8188E;
171         bool            biol = false;
172         struct adapter *Adapter =  pDM_Odm->Adapter;
173         struct xmit_frame *pxmit_frame = NULL;
174         u8 bndy_cnt = 1;
175         enum HAL_STATUS rst = HAL_STATUS_SUCCESS;
176
177         hex += board;
178         hex += interfaceValue << 8;
179         hex += platform << 16;
180         hex += 0xFF000000;
181         biol = rtw_IOL_applied(Adapter);
182
183         if (biol) {
184                 pxmit_frame = rtw_IOL_accquire_xmit_frame(Adapter);
185                 if (pxmit_frame == NULL) {
186                         pr_info("rtw_IOL_accquire_xmit_frame failed\n");
187                         return HAL_STATUS_FAILURE;
188                 }
189         }
190
191         for (i = 0; i < ArrayLen; i += 2) {
192                 u32 v1 = Array[i];
193                 u32 v2 = Array[i+1];
194
195                 /*  This (offset, data) pair meets the condition. */
196                 if (v1 < 0xCDCDCDCD) {
197                         if (biol) {
198                                 if (rtw_IOL_cmd_boundary_handle(pxmit_frame))
199                                         bndy_cnt++;
200
201                                 if (v1 == 0xffe)
202                                         rtw_IOL_append_DELAY_MS_cmd(pxmit_frame, 50);
203                                 else if (v1 == 0xfd)
204                                         rtw_IOL_append_DELAY_MS_cmd(pxmit_frame, 5);
205                                 else if (v1 == 0xfc)
206                                         rtw_IOL_append_DELAY_MS_cmd(pxmit_frame, 1);
207                                 else if (v1 == 0xfb)
208                                         rtw_IOL_append_DELAY_US_cmd(pxmit_frame, 50);
209                                 else if (v1 == 0xfa)
210                                         rtw_IOL_append_DELAY_US_cmd(pxmit_frame, 5);
211                                 else if (v1 == 0xf9)
212                                         rtw_IOL_append_DELAY_US_cmd(pxmit_frame, 1);
213                                 else
214                                         rtw_IOL_append_WRF_cmd(pxmit_frame, RF_PATH_A, (u16)v1, v2, bRFRegOffsetMask);
215                         } else {
216                                 odm_ConfigRF_RadioA_8188E(pDM_Odm, v1, v2);
217                         }
218                     continue;
219                 } else { /*  This line is the start line of branch. */
220                         if (!CheckCondition(Array[i], hex)) {
221                                 /*  Discard the following (offset, data) pairs. */
222                                 READ_NEXT_PAIR(v1, v2, i);
223                                 while (v2 != 0xDEAD &&
224                                        v2 != 0xCDEF &&
225                                        v2 != 0xCDCD && i < ArrayLen - 2)
226                                         READ_NEXT_PAIR(v1, v2, i);
227                                 i -= 2; /*  prevent from for-loop += 2 */
228                         } else { /*  Configure matched pairs and skip to end of if-else. */
229                         READ_NEXT_PAIR(v1, v2, i);
230                                 while (v2 != 0xDEAD &&
231                                        v2 != 0xCDEF &&
232                                        v2 != 0xCDCD && i < ArrayLen - 2) {
233                                         if (biol) {
234                                                 if (rtw_IOL_cmd_boundary_handle(pxmit_frame))
235                                                         bndy_cnt++;
236
237                                                 if (v1 == 0xffe)
238                                                         rtw_IOL_append_DELAY_MS_cmd(pxmit_frame, 50);
239                                                 else if (v1 == 0xfd)
240                                                         rtw_IOL_append_DELAY_MS_cmd(pxmit_frame, 5);
241                                                 else if (v1 == 0xfc)
242                                                         rtw_IOL_append_DELAY_MS_cmd(pxmit_frame, 1);
243                                                 else if (v1 == 0xfb)
244                                                         rtw_IOL_append_DELAY_US_cmd(pxmit_frame, 50);
245                                                 else if (v1 == 0xfa)
246                                                         rtw_IOL_append_DELAY_US_cmd(pxmit_frame, 5);
247                                                 else if (v1 == 0xf9)
248                                                         rtw_IOL_append_DELAY_US_cmd(pxmit_frame, 1);
249                                                 else
250                                                         rtw_IOL_append_WRF_cmd(pxmit_frame, RF_PATH_A, (u16)v1, v2, bRFRegOffsetMask);
251                                         } else {
252                                                 odm_ConfigRF_RadioA_8188E(pDM_Odm, v1, v2);
253                                         }
254                                         READ_NEXT_PAIR(v1, v2, i);
255                                 }
256
257                                 while (v2 != 0xDEAD && i < ArrayLen - 2)
258                                         READ_NEXT_PAIR(v1, v2, i);
259                         }
260                 }
261         }
262         if (biol) {
263                 if (!rtw_IOL_exec_cmds_sync(pDM_Odm->Adapter, pxmit_frame, 1000, bndy_cnt)) {
264                         rst = HAL_STATUS_FAILURE;
265                         pr_info("~~~ IOL Config %s Failed !!!\n", __func__);
266                 }
267         }
268         return rst;
269 }