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