xref: /linux/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c (revision a5f22b9b139762685810aa5a41fd0181488aea13)
1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 
8 #include <linux/kernel.h>
9 #include "odm_precomp.h"
10 
CheckPositive(struct dm_odm_t * pDM_Odm,const u32 Condition1,const u32 Condition2)11 static bool CheckPositive(struct dm_odm_t *pDM_Odm, const u32 Condition1, const u32 Condition2)
12 {
13 	u8 _BoardType =
14 		((pDM_Odm->BoardType & BIT4) >> 4) << 0 | /* _GLNA */
15 		((pDM_Odm->BoardType & BIT3) >> 3) << 1 | /* _GPA */
16 		((pDM_Odm->BoardType & BIT7) >> 7) << 2 | /* _ALNA */
17 		((pDM_Odm->BoardType & BIT6) >> 6) << 3 | /* _APA */
18 		((pDM_Odm->BoardType & BIT2) >> 2) << 4;  /* _BT */
19 
20 	u32   cond1   = Condition1, cond2 = Condition2;
21 	u32    driver1 =
22 		pDM_Odm->CutVersion       << 24 |
23 		pDM_Odm->SupportPlatform  << 16 |
24 		pDM_Odm->PackageType      << 12 |
25 		pDM_Odm->SupportInterface << 8  |
26 		_BoardType;
27 
28 	u32 driver2 =
29 		pDM_Odm->TypeGLNA <<  0 |
30 		pDM_Odm->TypeGPA  <<  8 |
31 		pDM_Odm->TypeALNA << 16 |
32 		pDM_Odm->TypeAPA  << 24;
33 
34 	/* Value Defined Check =============== */
35 	/* QFN Type [15:12] and Cut Version [27:24] need to do value check */
36 
37 	if (((cond1 & 0x0000F000) != 0) && ((cond1 & 0x0000F000) != (driver1 & 0x0000F000)))
38 		return false;
39 	if (((cond1 & 0x0F000000) != 0) && ((cond1 & 0x0F000000) != (driver1 & 0x0F000000)))
40 		return false;
41 
42 	/* Bit Defined Check ================ */
43 	/* We don't care [31:28] and [23:20] */
44 	/* */
45 	cond1   &= 0x000F0FFF;
46 	driver1 &= 0x000F0FFF;
47 
48 	if ((cond1 & driver1) == cond1) {
49 		u32 bitMask = 0;
50 
51 		if ((cond1 & 0x0F) == 0) /* BoardType is DONTCARE */
52 			return true;
53 
54 		if ((cond1 & BIT0) != 0) /* GLNA */
55 			bitMask |= 0x000000FF;
56 		if ((cond1 & BIT1) != 0) /* GPA */
57 			bitMask |= 0x0000FF00;
58 		if ((cond1 & BIT2) != 0) /* ALNA */
59 			bitMask |= 0x00FF0000;
60 		if ((cond1 & BIT3) != 0) /* APA */
61 			bitMask |= 0xFF000000;
62 
63 		/* BoardType of each RF path is matched */
64 		if ((cond2 & bitMask) == (driver2 & bitMask))
65 			return true;
66 	}
67 	return false;
68 }
69 
70 /******************************************************************************
71  *                           MAC_REG.TXT
72  ******************************************************************************/
73 
74 static u32 Array_MP_8723B_MAC_REG[] = {
75 		0x02F, 0x00000030,
76 		0x035, 0x00000000,
77 		0x039, 0x00000008,
78 		0x04E, 0x000000E0,
79 		0x064, 0x00000000,
80 		0x067, 0x00000020,
81 		0x428, 0x0000000A,
82 		0x429, 0x00000010,
83 		0x430, 0x00000000,
84 		0x431, 0x00000000,
85 		0x432, 0x00000000,
86 		0x433, 0x00000001,
87 		0x434, 0x00000004,
88 		0x435, 0x00000005,
89 		0x436, 0x00000007,
90 		0x437, 0x00000008,
91 		0x43C, 0x00000004,
92 		0x43D, 0x00000005,
93 		0x43E, 0x00000007,
94 		0x43F, 0x00000008,
95 		0x440, 0x0000005D,
96 		0x441, 0x00000001,
97 		0x442, 0x00000000,
98 		0x444, 0x00000010,
99 		0x445, 0x00000000,
100 		0x446, 0x00000000,
101 		0x447, 0x00000000,
102 		0x448, 0x00000000,
103 		0x449, 0x000000F0,
104 		0x44A, 0x0000000F,
105 		0x44B, 0x0000003E,
106 		0x44C, 0x00000010,
107 		0x44D, 0x00000000,
108 		0x44E, 0x00000000,
109 		0x44F, 0x00000000,
110 		0x450, 0x00000000,
111 		0x451, 0x000000F0,
112 		0x452, 0x0000000F,
113 		0x453, 0x00000000,
114 		0x456, 0x0000005E,
115 		0x460, 0x00000066,
116 		0x461, 0x00000066,
117 		0x4C8, 0x000000FF,
118 		0x4C9, 0x00000008,
119 		0x4CC, 0x000000FF,
120 		0x4CD, 0x000000FF,
121 		0x4CE, 0x00000001,
122 		0x500, 0x00000026,
123 		0x501, 0x000000A2,
124 		0x502, 0x0000002F,
125 		0x503, 0x00000000,
126 		0x504, 0x00000028,
127 		0x505, 0x000000A3,
128 		0x506, 0x0000005E,
129 		0x507, 0x00000000,
130 		0x508, 0x0000002B,
131 		0x509, 0x000000A4,
132 		0x50A, 0x0000005E,
133 		0x50B, 0x00000000,
134 		0x50C, 0x0000004F,
135 		0x50D, 0x000000A4,
136 		0x50E, 0x00000000,
137 		0x50F, 0x00000000,
138 		0x512, 0x0000001C,
139 		0x514, 0x0000000A,
140 		0x516, 0x0000000A,
141 		0x525, 0x0000004F,
142 		0x550, 0x00000010,
143 		0x551, 0x00000010,
144 		0x559, 0x00000002,
145 		0x55C, 0x00000050,
146 		0x55D, 0x000000FF,
147 		0x605, 0x00000030,
148 		0x608, 0x0000000E,
149 		0x609, 0x0000002A,
150 		0x620, 0x000000FF,
151 		0x621, 0x000000FF,
152 		0x622, 0x000000FF,
153 		0x623, 0x000000FF,
154 		0x624, 0x000000FF,
155 		0x625, 0x000000FF,
156 		0x626, 0x000000FF,
157 		0x627, 0x000000FF,
158 		0x638, 0x00000050,
159 		0x63C, 0x0000000A,
160 		0x63D, 0x0000000A,
161 		0x63E, 0x0000000E,
162 		0x63F, 0x0000000E,
163 		0x640, 0x00000040,
164 		0x642, 0x00000040,
165 		0x643, 0x00000000,
166 		0x652, 0x000000C8,
167 		0x66E, 0x00000005,
168 		0x700, 0x00000021,
169 		0x701, 0x00000043,
170 		0x702, 0x00000065,
171 		0x703, 0x00000087,
172 		0x708, 0x00000021,
173 		0x709, 0x00000043,
174 		0x70A, 0x00000065,
175 		0x70B, 0x00000087,
176 		0x765, 0x00000018,
177 		0x76E, 0x00000004,
178 
179 };
180 
ODM_ReadAndConfig_MP_8723B_MAC_REG(struct dm_odm_t * pDM_Odm)181 void ODM_ReadAndConfig_MP_8723B_MAC_REG(struct dm_odm_t *pDM_Odm)
182 {
183 	u32 i = 0;
184 	u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_MAC_REG);
185 	u32 *Array = Array_MP_8723B_MAC_REG;
186 
187 	for (i = 0; i < ArrayLen; i += 2) {
188 		u32 v1 = Array[i];
189 		u32 v2 = Array[i + 1];
190 
191 		/* This (offset, data) pair doesn't care the condition. */
192 		if (v1 < 0x40000000) {
193 			odm_ConfigMAC_8723B(pDM_Odm, v1, (u8)v2);
194 			continue;
195 		} else {
196 			/* This line is the beginning of branch. */
197 			bool bMatched = true;
198 			u8  cCond  = (u8)((v1 & (BIT29 | BIT28)) >> 28);
199 
200 			if (cCond == COND_ELSE) { /* ELSE, ENDIF */
201 				bMatched = true;
202 				READ_NEXT_PAIR(v1, v2, i);
203 			} else if (!CheckPositive(pDM_Odm, v1, v2)) {
204 				bMatched = false;
205 				READ_NEXT_PAIR(v1, v2, i);
206 				READ_NEXT_PAIR(v1, v2, i);
207 			} else {
208 				READ_NEXT_PAIR(v1, v2, i);
209 				bMatched = true;
210 				READ_NEXT_PAIR(v1, v2, i);
211 			}
212 
213 			if (!bMatched) {
214 				/*
215 				 * Condition isn't matched.
216 				 * Discard the following (offset, data) pairs.
217 				 */
218 				while (v1 < 0x40000000 && i < ArrayLen - 2)
219 					READ_NEXT_PAIR(v1, v2, i);
220 
221 				i -= 2; /* prevent from for-loop += 2 */
222 			} else { /* Configure matched pairs and skip to end of if-else. */
223 				while (v1 < 0x40000000 && i < ArrayLen - 2) {
224 					odm_ConfigMAC_8723B(pDM_Odm, v1, (u8)v2);
225 					READ_NEXT_PAIR(v1, v2, i);
226 				}
227 
228 				/* Keeps reading until ENDIF. */
229 				cCond = (u8)((v1 & (BIT29 | BIT28)) >> 28);
230 				while (cCond != COND_ENDIF && i < ArrayLen - 2) {
231 					READ_NEXT_PAIR(v1, v2, i);
232 					cCond = (u8)((v1 & (BIT29 | BIT28)) >> 28);
233 				}
234 			}
235 		}
236 	}
237 }
238