xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8189fs/hal/phydm/halrf/halrf_powertracking_win.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
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 /* include files												*/
18 /*============================================================	*/
19 #include "mp_precomp.h"
20 #include "phydm_precomp.h"
21 
22 /* ************************************************************
23  * Global var
24  * ************************************************************ */
25 
26 u32	ofdm_swing_table[OFDM_TABLE_SIZE] = {
27 	0x7f8001fe,	/* 0, +6.0dB */
28 	0x788001e2,	/* 1, +5.5dB */
29 	0x71c001c7,	/* 2, +5.0dB */
30 	0x6b8001ae,	/* 3, +4.5dB */
31 	0x65400195,	/* 4, +4.0dB */
32 	0x5fc0017f,	/* 5, +3.5dB */
33 	0x5a400169,	/* 6, +3.0dB */
34 	0x55400155,	/* 7, +2.5dB */
35 	0x50800142,	/* 8, +2.0dB */
36 	0x4c000130,	/* 9, +1.5dB */
37 	0x47c0011f,	/* 10, +1.0dB */
38 	0x43c0010f,	/* 11, +0.5dB */
39 	0x40000100,	/* 12, +0dB */
40 	0x3c8000f2,	/* 13, -0.5dB */
41 	0x390000e4,	/* 14, -1.0dB */
42 	0x35c000d7,	/* 15, -1.5dB */
43 	0x32c000cb,	/* 16, -2.0dB */
44 	0x300000c0,	/* 17, -2.5dB */
45 	0x2d4000b5,	/* 18, -3.0dB */
46 	0x2ac000ab,	/* 19, -3.5dB */
47 	0x288000a2,	/* 20, -4.0dB */
48 	0x26000098,	/* 21, -4.5dB */
49 	0x24000090,	/* 22, -5.0dB */
50 	0x22000088,	/* 23, -5.5dB */
51 	0x20000080,	/* 24, -6.0dB */
52 	0x1e400079,	/* 25, -6.5dB */
53 	0x1c800072,	/* 26, -7.0dB */
54 	0x1b00006c,	/* 27. -7.5dB */
55 	0x19800066,	/* 28, -8.0dB */
56 	0x18000060,	/* 29, -8.5dB */
57 	0x16c0005b,	/* 30, -9.0dB */
58 	0x15800056,	/* 31, -9.5dB */
59 	0x14400051,	/* 32, -10.0dB */
60 	0x1300004c,	/* 33, -10.5dB */
61 	0x12000048,	/* 34, -11.0dB */
62 	0x11000044,	/* 35, -11.5dB */
63 	0x10000040,	/* 36, -12.0dB */
64 };
65 
66 u8	cck_swing_table_ch1_ch13[CCK_TABLE_SIZE][8] = {
67 	{0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04},	/* 0, +0dB */
68 	{0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04},	/* 1, -0.5dB */
69 	{0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03},	/* 2, -1.0dB */
70 	{0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03},	/* 3, -1.5dB */
71 	{0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03},	/* 4, -2.0dB */
72 	{0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03},	/* 5, -2.5dB */
73 	{0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03},	/* 6, -3.0dB */
74 	{0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03},	/* 7, -3.5dB */
75 	{0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02},	/* 8, -4.0dB */
76 	{0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02},	/* 9, -4.5dB */
77 	{0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02},	/* 10, -5.0dB */
78 	{0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02},	/* 11, -5.5dB */
79 	{0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02},	/* 12, -6.0dB <== default */
80 	{0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02},	/* 13, -6.5dB */
81 	{0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02},	/* 14, -7.0dB */
82 	{0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02},	/* 15, -7.5dB */
83 	{0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01},	/* 16, -8.0dB */
84 	{0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02},	/* 17, -8.5dB */
85 	{0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01},	/* 18, -9.0dB */
86 	{0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01},	/* 19, -9.5dB */
87 	{0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01},	/* 20, -10.0dB */
88 	{0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01},	/* 21, -10.5dB */
89 	{0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01},	/* 22, -11.0dB */
90 	{0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01},	/* 23, -11.5dB */
91 	{0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01},	/* 24, -12.0dB */
92 	{0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01},	/* 25, -12.5dB */
93 	{0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01},	/* 26, -13.0dB */
94 	{0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01},	/* 27, -13.5dB */
95 	{0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01},	/* 28, -14.0dB */
96 	{0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01},	/* 29, -14.5dB */
97 	{0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01},	/* 30, -15.0dB */
98 	{0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01},	/* 31, -15.5dB */
99 	{0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}	/* 32, -16.0dB */
100 };
101 
102 
103 u8	cck_swing_table_ch14[CCK_TABLE_SIZE][8] = {
104 	{0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00},	/* 0, +0dB */
105 	{0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00},	/* 1, -0.5dB */
106 	{0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00},	/* 2, -1.0dB */
107 	{0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00},	/* 3, -1.5dB */
108 	{0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00},	/* 4, -2.0dB */
109 	{0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00},	/* 5, -2.5dB */
110 	{0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00},	/* 6, -3.0dB */
111 	{0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00},	/* 7, -3.5dB */
112 	{0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00},	/* 8, -4.0dB */
113 	{0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00},	/* 9, -4.5dB */
114 	{0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00},	/* 10, -5.0dB */
115 	{0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00},	/* 11, -5.5dB */
116 	{0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00},	/* 12, -6.0dB  <== default */
117 	{0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00},	/* 13, -6.5dB */
118 	{0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00},	/* 14, -7.0dB */
119 	{0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00},	/* 15, -7.5dB */
120 	{0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00},	/* 16, -8.0dB */
121 	{0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00},	/* 17, -8.5dB */
122 	{0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00},	/* 18, -9.0dB */
123 	{0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00},	/* 19, -9.5dB */
124 	{0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00},	/* 20, -10.0dB */
125 	{0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00},	/* 21, -10.5dB */
126 	{0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00},	/* 22, -11.0dB */
127 	{0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00},	/* 23, -11.5dB */
128 	{0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00},	/* 24, -12.0dB */
129 	{0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00},	/* 25, -12.5dB */
130 	{0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00},	/* 26, -13.0dB */
131 	{0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00},	/* 27, -13.5dB */
132 	{0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00},	/* 28, -14.0dB */
133 	{0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00},	/* 29, -14.5dB */
134 	{0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00},	/* 30, -15.0dB */
135 	{0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00},	/* 31, -15.5dB */
136 	{0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}	/* 32, -16.0dB */
137 };
138 
139 
140 u32 ofdm_swing_table_new[OFDM_TABLE_SIZE] = {
141 	0x0b40002d, /* 0,  -15.0dB */
142 	0x0c000030, /* 1,  -14.5dB */
143 	0x0cc00033, /* 2,  -14.0dB */
144 	0x0d800036, /* 3,  -13.5dB */
145 	0x0e400039, /* 4,  -13.0dB */
146 	0x0f00003c, /* 5,  -12.5dB */
147 	0x10000040, /* 6,  -12.0dB */
148 	0x11000044, /* 7,  -11.5dB */
149 	0x12000048, /* 8,  -11.0dB */
150 	0x1300004c, /* 9,  -10.5dB */
151 	0x14400051, /* 10, -10.0dB */
152 	0x15800056, /* 11, -9.5dB */
153 	0x16c0005b, /* 12, -9.0dB */
154 	0x18000060, /* 13, -8.5dB */
155 	0x19800066, /* 14, -8.0dB */
156 	0x1b00006c, /* 15, -7.5dB */
157 	0x1c800072, /* 16, -7.0dB */
158 	0x1e400079, /* 17, -6.5dB */
159 	0x20000080, /* 18, -6.0dB */
160 	0x22000088, /* 19, -5.5dB */
161 	0x24000090, /* 20, -5.0dB */
162 	0x26000098, /* 21, -4.5dB */
163 	0x288000a2, /* 22, -4.0dB */
164 	0x2ac000ab, /* 23, -3.5dB */
165 	0x2d4000b5, /* 24, -3.0dB */
166 	0x300000c0, /* 25, -2.5dB */
167 	0x32c000cb, /* 26, -2.0dB */
168 	0x35c000d7, /* 27, -1.5dB */
169 	0x390000e4, /* 28, -1.0dB */
170 	0x3c8000f2, /* 29, -0.5dB */
171 	0x40000100, /* 30, +0dB */
172 	0x43c0010f, /* 31, +0.5dB */
173 	0x47c0011f, /* 32, +1.0dB */
174 	0x4c000130, /* 33, +1.5dB */
175 	0x50800142, /* 34, +2.0dB */
176 	0x55400155, /* 35, +2.5dB */
177 	0x5a400169, /* 36, +3.0dB */
178 	0x5fc0017f, /* 37, +3.5dB */
179 	0x65400195, /* 38, +4.0dB */
180 	0x6b8001ae, /* 39, +4.5dB */
181 	0x71c001c7, /* 40, +5.0dB */
182 	0x788001e2, /* 41, +5.5dB */
183 	0x7f8001fe  /* 42, +6.0dB */
184 };
185 
186 
187 u8 cck_swing_table_ch1_ch14_88f[CCK_TABLE_SIZE_88F][16] = {
188 	{0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-16dB*/
189 	{0x48, 0x46, 0x3F, 0x36, 0x2A, 0x1E, 0x14, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-15.5dB*/
190 	{0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0x0C, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-15dB*/
191 	{0x51, 0x4F, 0x47, 0x3C, 0x2F, 0x22, 0x16, 0x0D, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-14.5dB*/
192 	{0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-14dB*/
193 	{0x5B, 0x58, 0x50, 0x43, 0x35, 0x26, 0x19, 0x0E, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-13.5dB*/
194 	{0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0x0F, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-13dB*/
195 	{0x66, 0x63, 0x59, 0x4C, 0x3B, 0x2B, 0x1C, 0x10, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-12.5dB*/
196 	{0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-12dB*/
197 	{0x73, 0x6F, 0x64, 0x55, 0x42, 0x30, 0x1F, 0x12, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-11.5dB*/
198 	{0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x09, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-11dB*/
199 	{0x81, 0x7C, 0x71, 0x5F, 0x4A, 0x36, 0x23, 0x14, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-10.5dB*/
200 	{0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-10dB*/
201 	{0x90, 0x8C, 0x7E, 0x6B, 0x54, 0x3C, 0x27, 0x17, 0x0B, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-9.5dB*/
202 	{0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0x0B, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-9dB*/
203 	{0xA2, 0x9D, 0x8E, 0x78, 0x5E, 0x43, 0x2C, 0x19, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-8.5dB*/
204 	{0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-8dB*/
205 	{0xB6, 0xB0, 0x9F, 0x87, 0x69, 0x4C, 0x32, 0x1D, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-7.5dB*/
206 	{0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0x0E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-7dB*/
207 	{0xCC, 0xC5, 0xB2, 0x97, 0x76, 0x55, 0x38, 0x20, 0x0F, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-6.5dB*/
208 	{0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}     /*-6dB*/
209 };
210 
211 
212 u8 cck_swing_table_ch1_ch13_88f[CCK_TABLE_SIZE_88F][16] = {
213 	{0x44, 0x42, 0x3C, 0x33, 0x28, 0x1C, 0x13, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-16dB*/
214 	{0x48, 0x46, 0x3F, 0x36, 0x2A, 0x1E, 0x14, 0x0B, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-15.5dB*/
215 	{0x4D, 0x4A, 0x43, 0x39, 0x2C, 0x20, 0x15, 0x0C, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-15dB*/
216 	{0x51, 0x4F, 0x47, 0x3C, 0x2F, 0x22, 0x16, 0x0D, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-14.5dB*/
217 	{0x56, 0x53, 0x4B, 0x40, 0x32, 0x24, 0x17, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-14dB*/
218 	{0x5B, 0x58, 0x50, 0x43, 0x35, 0x26, 0x19, 0x0E, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-13.5dB*/
219 	{0x60, 0x5D, 0x54, 0x47, 0x38, 0x28, 0x1A, 0x0F, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-13dB*/
220 	{0x66, 0x63, 0x59, 0x4C, 0x3B, 0x2B, 0x1C, 0x10, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-12.5dB*/
221 	{0x6C, 0x69, 0x5F, 0x50, 0x3F, 0x2D, 0x1E, 0x11, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-12dB*/
222 	{0x73, 0x6F, 0x64, 0x55, 0x42, 0x30, 0x1F, 0x12, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-11.5dB*/
223 	{0x79, 0x76, 0x6A, 0x5A, 0x46, 0x33, 0x21, 0x13, 0x09, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-11dB*/
224 	{0x81, 0x7C, 0x71, 0x5F, 0x4A, 0x36, 0x23, 0x14, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-10.5dB*/
225 	{0x88, 0x84, 0x77, 0x65, 0x4F, 0x39, 0x25, 0x15, 0x0A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-10dB*/
226 	{0x90, 0x8C, 0x7E, 0x6B, 0x54, 0x3C, 0x27, 0x17, 0x0B, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-9.5dB*/
227 	{0x99, 0x94, 0x86, 0x71, 0x58, 0x40, 0x2A, 0x18, 0x0B, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-9dB*/
228 	{0xA2, 0x9D, 0x8E, 0x78, 0x5E, 0x43, 0x2C, 0x19, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-8.5dB*/
229 	{0xAC, 0xA6, 0x96, 0x7F, 0x63, 0x47, 0x2F, 0x1B, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-8dB*/
230 	{0xB6, 0xB0, 0x9F, 0x87, 0x69, 0x4C, 0x32, 0x1D, 0x0D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-7.5dB*/
231 	{0xC1, 0xBA, 0xA8, 0x8F, 0x6F, 0x50, 0x35, 0x1E, 0x0E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-7dB*/
232 	{0xCC, 0xC5, 0xB2, 0x97, 0x76, 0x55, 0x38, 0x20, 0x0F, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-6.5dB*/
233 	{0xD8, 0xD1, 0xBD, 0xA0, 0x7D, 0x5A, 0x3B, 0x22, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}     /*-6dB*/
234 };
235 
236 
237 u8 cck_swing_table_ch14_88f[CCK_TABLE_SIZE_88F][16] = {
238 	{0x44,	 0x42, 0x3C, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-16dB*/
239 	{0x48, 0x46, 0x3F, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-15.5dB*/
240 	{0x4D, 0x4A, 0x43, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-15dB*/
241 	{0x51, 0x4F, 0x47, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},	    /*-14.5dB*/
242 	{0x56, 0x53, 0x4B, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-14dB*/
243 	{0x5B, 0x58, 0x50, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-13.5dB*/
244 	{0x60, 0x5D, 0x54, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-13dB*/
245 	{0x66, 0x63, 0x59, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-12.5dB*/
246 	{0x6C, 0x69, 0x5F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-12dB*/
247 	{0x73, 0x6F, 0x64, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-11.5dB*/
248 	{0x79, 0x76, 0x6A, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-11dB*/
249 	{0x81, 0x7C, 0x71, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-10.5dB*/
250 	{0x88, 0x84, 0x77, 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-10dB*/
251 	{0x90, 0x8C, 0x7E, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-9.5dB*/
252 	{0x99, 0x94, 0x86, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-9dB*/
253 	{0xA2, 0x9D, 0x8E, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-8.5dB*/
254 	{0xAC, 0xA6, 0x96, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-8dB*/
255 	{0xB6, 0xB0, 0x9F, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-7.5dB*/
256 	{0xC1, 0xBA, 0xA8, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-7dB*/
257 	{0xCC, 0xC5, 0xB2, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*-6.5dB*/
258 	{0xD8, 0xD1, 0xBD, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}     /*-6dB*/
259 };
260 
261 
262 u8 cck_swing_table_ch1_ch13_new[CCK_TABLE_SIZE][8] = {
263 	{0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01},	/* 0, -16.0dB */
264 	{0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01},	/* 1, -15.5dB */
265 	{0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01},	/* 2, -15.0dB */
266 	{0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01},	/* 3, -14.5dB */
267 	{0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01},	/* 4, -14.0dB */
268 	{0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01},	/* 5, -13.5dB */
269 	{0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01},	/* 6, -13.0dB */
270 	{0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01},	/* 7, -12.5dB */
271 	{0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01},	/* 8, -12.0dB */
272 	{0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01},	/* 9, -11.5dB */
273 	{0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01},	/* 10, -11.0dB */
274 	{0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01},	/* 11, -10.5dB */
275 	{0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01},	/* 12, -10.0dB */
276 	{0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01},	/* 13, -9.5dB */
277 	{0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01},	/* 14, -9.0dB */
278 	{0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02},	/* 15, -8.5dB */
279 	{0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01},	/* 16, -8.0dB */
280 	{0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02},	/* 17, -7.5dB */
281 	{0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02},	/* 18, -7.0dB */
282 	{0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02},	/* 19, -6.5dB */
283 	{0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02},	/* 20, -6.0dB */
284 	{0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02},	/* 21, -5.5dB */
285 	{0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02},	/* 22, -5.0dB */
286 	{0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02},	/* 23, -4.5dB */
287 	{0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02},	/* 24, -4.0dB */
288 	{0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03},	/* 25, -3.5dB */
289 	{0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03},	/* 26, -3.0dB */
290 	{0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03},	/* 27, -2.5dB */
291 	{0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03},	/* 28, -2.0dB */
292 	{0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03},	/* 29, -1.5dB */
293 	{0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03},	/* 30, -1.0dB */
294 	{0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04},	/* 31, -0.5dB */
295 	{0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}	/* 32, +0dB */
296 };
297 
298 
299 u8 cck_swing_table_ch14_new[CCK_TABLE_SIZE][8] = {
300 	{0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00},	/* 0, -16.0dB */
301 	{0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00},	/* 1, -15.5dB */
302 	{0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00},	/* 2, -15.0dB */
303 	{0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00},	/* 3, -14.5dB */
304 	{0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00},	/* 4, -14.0dB */
305 	{0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00},	/* 5, -13.5dB */
306 	{0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00},	/* 6, -13.0dB */
307 	{0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00},	/* 7, -12.5dB */
308 	{0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00},	/* 8, -12.0dB */
309 	{0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00},	/* 9, -11.5dB */
310 	{0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00},	/* 10, -11.0dB */
311 	{0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00},	/* 11, -10.5dB */
312 	{0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00},	/* 12, -10.0dB */
313 	{0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00},	/* 13, -9.5dB */
314 	{0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00},	/* 14, -9.0dB */
315 	{0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00},	/* 15, -8.5dB */
316 	{0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00},	/* 16, -8.0dB */
317 	{0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00},	/* 17, -7.5dB */
318 	{0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00},	/* 18, -7.0dB */
319 	{0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00},	/* 19, -6.5dB */
320 	{0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00},	/* 20, -6.0dB */
321 	{0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00},	/* 21, -5.5dB */
322 	{0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00},	/* 22, -5.0dB */
323 	{0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00},	/* 23, -4.5dB */
324 	{0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00},	/* 24, -4.0dB */
325 	{0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00},	/* 25, -3.5dB */
326 	{0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00},	/* 26, -3.0dB */
327 	{0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00},	/* 27, -2.5dB */
328 	{0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00},	/* 28, -2.0dB */
329 	{0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00},	/* 29, -1.5dB */
330 	{0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00},	/* 30, -1.0dB */
331 	{0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00},	/* 31, -0.5dB */
332 	{0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}	/* 32, +0dB */
333 };
334 u32 cck_swing_table_ch1_ch14_8723d[CCK_TABLE_SIZE_8723D] = {
335 	0x0CD,
336 	0x0D9,
337 	0x0E6,
338 	0x0F3,
339 	0x102,
340 	0x111,
341 	0x121,
342 	0x132,
343 	0x144,
344 	0x158,
345 	0x16C,
346 	0x182,
347 	0x198,
348 	0x1B1,
349 	0x1CA,
350 	0x1E5,
351 	0x202,
352 	0x221,
353 	0x241,
354 	0x263,
355 	0x287,
356 	0x2AE,
357 	0x2D6,
358 	0x301,
359 	0x32F,
360 	0x35F,
361 	0x392,
362 	0x3C9,
363 	0x402,
364 	0x43F,
365 	0x47F,
366 	0x4C3,
367 	0x50C,
368 	0x558,
369 	0x5A9,
370 	0x5FF,
371 	0x65A,
372 	0x6BA,
373 	0x720,
374 	0x78C,
375 	0x7FF,
376 };
377 /* JJ ADD 20161014 */
378 u32 cck_swing_table_ch1_ch14_8710b[CCK_TABLE_SIZE_8710B] = {
379 	0x0CD,			 /*0 ,    -20dB*/
380 	0x0D9,
381 	0x0E6,
382 	0x0F3,
383 	0x102,
384 	0x111,
385 	0x121,
386 	0x132,
387 	0x144,
388 	0x158,
389 	0x16C,
390 	0x182,
391 	0x198,
392 	0x1B1,
393 	0x1CA,
394 	0x1E5,
395 	0x202,
396 	0x221,
397 	0x241,
398 	0x263,		/*19*/
399 	0x287,		/*20*/
400 	0x2AE,		/*21*/
401 	0x2D6,		/*22*/
402 	0x301,		/*23*/
403 	0x32F,		/*24*/
404 	0x35F,		/*25*/
405 	0x392,		/*26*/
406 	0x3C9,		/*27*/
407 	0x402,		/*28*/
408 	0x43F,		/*29*/
409 	0x47F,		/*30*/
410 	0x4C3,		/*31*/
411 	0x50C,		/*32*/
412 	0x558,		/*33*/
413 	0x5A9,		/*34*/
414 	0x5FF,		/*35*/
415 	0x65A,		/*36*/
416 	0x6BA,
417 	0x720,
418 	0x78C,
419 	0x7FF,
420 };
421 
422 /* Winnita ADD 20170828 PathA 0xAB4[10:0],PathB 0xAB4[21:11]*/
423 u32 cck_swing_table_ch1_ch14_8192f[CCK_TABLE_SIZE_8192F] = {
424 	0x0CD,			 /*0 ,    -20dB*/
425 	0x0D9,
426 	0x0E6,
427 	0x0F3,
428 	0x102,
429 	0x111,
430 	0x121,
431 	0x132,
432 	0x144,
433 	0x158,
434 	0x16C,
435 	0x182,
436 	0x198,
437 	0x1B1,
438 	0x1CA,
439 	0x1E5,
440 	0x202,
441 	0x221,
442 	0x241,
443 	0x263,		/*19*/
444 	0x287,		/*20*/
445 	0x2AE,		/*21*/
446 	0x2D6,		/*22*/
447 	0x301,		/*23*/
448 	0x32F,		/*24*/
449 	0x35F,		/*25*/
450 	0x392,		/*26*/
451 	0x3C9,		/*27*/
452 	0x402,		/*28*/
453 	0x43F,		/*29*/
454 	0x47F,		/*30*/
455 	0x4C3,		/*31*/
456 	0x50C,		/*32*/
457 	0x558,		/*33*/
458 	0x5A9,		/*34*/
459 	0x5FF,		/*35*/
460 	0x65A,		/*36*/
461 	0x6BA,
462 	0x720,
463 	0x78C,
464 	0x7FF,
465 };
466 
467 u32 tx_scaling_table_jaguar[TXSCALE_TABLE_SIZE] = {
468 	0x081, /* 0,  -12.0dB */
469 	0x088, /* 1,  -11.5dB */
470 	0x090, /* 2,  -11.0dB */
471 	0x099, /* 3,  -10.5dB */
472 	0x0A2, /* 4,  -10.0dB */
473 	0x0AC, /* 5,  -9.5dB */
474 	0x0B6, /* 6,  -9.0dB */
475 	0x0C0, /* 7,  -8.5dB */
476 	0x0CC, /* 8,  -8.0dB */
477 	0x0D8, /* 9,  -7.5dB */
478 	0x0E5, /* 10, -7.0dB */
479 	0x0F2, /* 11, -6.5dB */
480 	0x101, /* 12, -6.0dB */
481 	0x110, /* 13, -5.5dB */
482 	0x120, /* 14, -5.0dB */
483 	0x131, /* 15, -4.5dB */
484 	0x143, /* 16, -4.0dB */
485 	0x156, /* 17, -3.5dB */
486 	0x16A, /* 18, -3.0dB */
487 	0x180, /* 19, -2.5dB */
488 	0x197, /* 20, -2.0dB */
489 	0x1AF, /* 21, -1.5dB */
490 	0x1C8, /* 22, -1.0dB */
491 	0x1E3, /* 23, -0.5dB */
492 	0x200, /* 24, +0  dB */
493 	0x21E, /* 25, +0.5dB */
494 	0x23E, /* 26, +1.0dB */
495 	0x261, /* 27, +1.5dB */
496 	0x285, /* 28, +2.0dB */
497 	0x2AB, /* 29, +2.5dB */
498 	0x2D3, /* 30, +3.0dB */
499 	0x2FE, /* 31, +3.5dB */
500 	0x32B, /* 32, +4.0dB */
501 	0x35C, /* 33, +4.5dB */
502 	0x38E, /* 34, +5.0dB */
503 	0x3C4, /* 35, +5.5dB */
504 	0x3FE  /* 36, +6.0dB */
505 };
506 
507 void
odm_txpowertracking_init(void * dm_void)508 odm_txpowertracking_init(
509 	void		*dm_void
510 )
511 {
512 	struct dm_struct		*dm = (struct dm_struct *)dm_void;
513 #if (DM_ODM_SUPPORT_TYPE & (ODM_AP))
514 	if (!(dm->support_ic_type & (ODM_RTL8814A | ODM_IC_11N_SERIES | ODM_RTL8822B)))
515 		return;
516 #endif
517 
518 	odm_txpowertracking_thermal_meter_init(dm);
519 }
520 
521 u8
get_swing_index(void * dm_void)522 get_swing_index(
523 	void		*dm_void
524 )
525 {
526 	struct dm_struct		*dm = (struct dm_struct *)dm_void;
527 	void		*adapter = dm->adapter;
528 	HAL_DATA_TYPE	*hal_data = GET_HAL_DATA(((PADAPTER)adapter));
529 	u8			i = 0;
530 	u32			bb_swing, table_value;
531 
532 	if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8723B ||
533 	    dm->support_ic_type == ODM_RTL8192E || dm->support_ic_type == ODM_RTL8188F ||
534 	    dm->support_ic_type == ODM_RTL8703B || dm->support_ic_type == ODM_RTL8723D ||
535 	    dm->support_ic_type == ODM_RTL8192F || dm->support_ic_type == ODM_RTL8710B) {
536 		bb_swing = odm_get_bb_reg(dm, REG_OFDM_0_XA_TX_IQ_IMBALANCE, 0xFFC00000);
537 
538 		for (i = 0; i < OFDM_TABLE_SIZE; i++) {
539 			table_value = ofdm_swing_table_new[i];
540 
541 			if (table_value >= 0x100000)
542 				table_value >>= 22;
543 			if (bb_swing == table_value)
544 				break;
545 		}
546 	} else {
547 		bb_swing = PHY_GetTxBBSwing_8812A(adapter, hal_data->CurrentBandType, RF_PATH_A);
548 
549 		for (i = 0; i < TXSCALE_TABLE_SIZE; i++) {
550 			table_value = tx_scaling_table_jaguar[i];
551 
552 			if (bb_swing == table_value)
553 				break;
554 		}
555 	}
556 
557 	return i;
558 }
559 
560 u8
get_cck_swing_index(void * dm_void)561 get_cck_swing_index(
562 	void		*dm_void
563 )
564 {
565 	struct dm_struct		*dm = (struct dm_struct *)dm_void;
566 
567 	u8			i = 0;
568 	u32			bb_cck_swing;
569 
570 	if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8723B ||
571 	    dm->support_ic_type == ODM_RTL8192E) {
572 		bb_cck_swing = odm_read_1byte(dm, 0xa22);
573 
574 		for (i = 0; i < CCK_TABLE_SIZE; i++) {
575 			if (bb_cck_swing == cck_swing_table_ch1_ch13_new[i][0])
576 				break;
577 		}
578 	} else if (dm->support_ic_type == ODM_RTL8703B) {
579 		bb_cck_swing = odm_read_1byte(dm, 0xa22);
580 
581 		for (i = 0; i < CCK_TABLE_SIZE_88F; i++) {
582 			if (bb_cck_swing == cck_swing_table_ch1_ch14_88f[i][0])
583 				break;
584 		}
585 	}
586 
587 	return i;
588 }
589 
590 s8
get_txagc_default_index(void * dm_void)591 get_txagc_default_index(
592 	void *dm_void
593 )
594 {
595 	struct dm_struct *dm = (struct dm_struct *)dm_void;
596 	s8 tmp;
597 
598 	if (dm->support_ic_type == ODM_RTL8814B) {
599 		tmp = (s8)(odm_get_bb_reg(dm, R_0x18a0, 0x7f) & 0xff);
600 		if (tmp & BIT(6))
601 			tmp = tmp | 0x80;
602 		return tmp;
603 	} else
604 		return 0;
605 }
606 
607 void
odm_txpowertracking_thermal_meter_init(void * dm_void)608 odm_txpowertracking_thermal_meter_init(
609 	void		*dm_void
610 )
611 {
612 	struct dm_struct		*dm = (struct dm_struct *)dm_void;
613 	u8 default_swing_index = get_swing_index(dm);
614 	u8 default_cck_swing_index = get_cck_swing_index(dm);
615 	struct dm_rf_calibration_struct	*cali_info = &(dm->rf_calibrate_info);
616 	struct _hal_rf_ *rf = &dm->rf_table;
617 	struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data;
618 
619 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
620 	void		*adapter = dm->adapter;
621 	HAL_DATA_TYPE	*hal_data = GET_HAL_DATA(((PADAPTER)adapter));
622 	u8			p = 0;
623 
624 	if (*(dm->mp_mode) == false)
625 		cali_info->txpowertrack_control = true;
626 #elif (DM_ODM_SUPPORT_TYPE == ODM_CE)
627 #ifdef CONFIG_RTL8188E
628 	{
629 		cali_info->is_txpowertracking = true;
630 		cali_info->tx_powercount = 0;
631 		cali_info->is_txpowertracking_init = false;
632 
633 		if (*(dm->mp_mode) == false)
634 			cali_info->txpowertrack_control = true;
635 
636 		MSG_8192C("dm txpowertrack_control = %d\n", cali_info->txpowertrack_control);
637 	}
638 #else
639 	{
640 		void		*adapter = dm->adapter;
641 		HAL_DATA_TYPE	*hal_data = GET_HAL_DATA(((PADAPTER)adapter));
642 		struct dm_priv	*pdmpriv = &hal_data->dmpriv;
643 
644 		pdmpriv->is_txpowertracking = true;
645 		pdmpriv->tx_powercount = 0;
646 		pdmpriv->is_txpowertracking_init = false;
647 
648 		if (*(dm->mp_mode) == false)
649 			pdmpriv->txpowertrack_control = true;
650 
651 		MSG_8192C("pdmpriv->txpowertrack_control = %d\n", pdmpriv->txpowertrack_control);
652 
653 	}
654 #endif
655 #elif (DM_ODM_SUPPORT_TYPE & (ODM_AP))
656 #ifdef RTL8188E_SUPPORT
657 	{
658 		cali_info->is_txpowertracking = true;
659 		cali_info->tx_powercount = 0;
660 		cali_info->is_txpowertracking_init = false;
661 		cali_info->txpowertrack_control = true;
662 	}
663 #endif
664 #endif
665 
666 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
667 #if (MP_DRIVER == 1)
668 	cali_info->txpowertrack_control = false;
669 #else
670 	cali_info->txpowertrack_control = true;
671 #endif
672 #else
673 	cali_info->txpowertrack_control = true;
674 #endif
675 
676 	cali_info->thermal_value	= hal_data->eeprom_thermal_meter;
677 	cali_info->thermal_value_iqk	= hal_data->eeprom_thermal_meter;
678 	cali_info->thermal_value_lck	= hal_data->eeprom_thermal_meter;
679 
680 #if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1)
681 	if (dm->support_ic_type == ODM_RTL8822C) {
682 		cali_info->thermal_value_path[RF_PATH_A] = tssi->thermal[RF_PATH_A];
683 		cali_info->thermal_value_path[RF_PATH_B] = tssi->thermal[RF_PATH_B];
684 		cali_info->thermal_value_iqk = tssi->thermal[RF_PATH_A];
685 		cali_info->thermal_value_lck = tssi->thermal[RF_PATH_A];
686 	}
687 
688 	if (dm->support_ic_type == ODM_RTL8814B) {
689 		cali_info->thermal_value_path[RF_PATH_A] = tssi->thermal[RF_PATH_A];
690 		cali_info->thermal_value_path[RF_PATH_B] = tssi->thermal[RF_PATH_B];
691 		cali_info->thermal_value_path[RF_PATH_C] = tssi->thermal[RF_PATH_C];
692 		cali_info->thermal_value_path[RF_PATH_D] = tssi->thermal[RF_PATH_D];
693 		cali_info->thermal_value_iqk = tssi->thermal[RF_PATH_A];
694 		cali_info->thermal_value_lck = tssi->thermal[RF_PATH_A];
695 	}
696 #endif
697 
698 	if (cali_info->default_bb_swing_index_flag != true) {
699 		/*The index of "0 dB" in SwingTable.*/
700 		if (dm->support_ic_type == ODM_RTL8188E || dm->support_ic_type == ODM_RTL8723B ||
701 		    dm->support_ic_type == ODM_RTL8192E || dm->support_ic_type == ODM_RTL8703B) {
702 			cali_info->default_ofdm_index = (default_swing_index >= OFDM_TABLE_SIZE) ? 30 : default_swing_index;
703 			cali_info->default_cck_index = (default_cck_swing_index >= CCK_TABLE_SIZE) ? 20 : default_cck_swing_index;
704 		} else if (dm->support_ic_type == ODM_RTL8188F) {          /*add by Mingzhi.Guo  2015-03-23*/
705 			cali_info->default_ofdm_index = 28;							/*OFDM: -1dB*/
706 			cali_info->default_cck_index = 20;							/*CCK:-6dB*/
707 		} else if (dm->support_ic_type == ODM_RTL8723D) {			 /*add by zhaohe  2015-10-27*/
708 			cali_info->default_ofdm_index = 28;						 	   /*OFDM: -1dB*/
709 			cali_info->default_cck_index = 28;							/*CCK:   -6dB*/
710 			/* JJ ADD 20161014 */
711 		} else if (dm->support_ic_type == ODM_RTL8710B) {
712 			cali_info->default_ofdm_index = 28;					/*OFDM: -1dB*/
713 			cali_info->default_cck_index = 28;					/*CCK:   -6dB*/
714 		/*Winnita add 20170828*/
715 		} else if (dm->support_ic_type == ODM_RTL8192F) {
716 			cali_info->default_ofdm_index = 30;					/*OFDM: 0dB*/
717 			cali_info->default_cck_index = 28;					/*CCK:   -6dB*/
718 		} else {
719 			cali_info->default_ofdm_index = (default_swing_index >= TXSCALE_TABLE_SIZE) ? 24 : default_swing_index;
720 			cali_info->default_cck_index = 24;
721 			cali_info->default_txagc_index = get_txagc_default_index(dm);
722 		}
723 		cali_info->default_bb_swing_index_flag = true;
724 	}
725 
726 	cali_info->bb_swing_idx_cck_base = cali_info->default_cck_index;
727 	cali_info->CCK_index = cali_info->default_cck_index;
728 
729 	for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) {
730 		cali_info->bb_swing_idx_ofdm_base[p] = cali_info->default_ofdm_index;
731 		cali_info->OFDM_index[p] = cali_info->default_ofdm_index;
732 		cali_info->delta_power_index[p] = 0;
733 		cali_info->delta_power_index_last[p] = 0;
734 		cali_info->power_index_offset[p] = 0;
735 		cali_info->kfree_offset[p] = 0;
736 	}
737 	cali_info->modify_tx_agc_value_ofdm = 0;
738 	cali_info->modify_tx_agc_value_cck = 0;
739 	cali_info->tm_trigger = 0;
740 }
741 
742 
743 void
odm_txpowertracking_check(void * dm_void)744 odm_txpowertracking_check(
745 	void		*dm_void
746 )
747 {
748 
749 #if 0
750 	/* 2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate */
751 	/*  at the same time. In the stage2/3, we need to prive universal interface and merge all */
752 	/* HW dynamic mechanism. */
753 #endif
754 
755 	struct dm_struct		*dm = (struct dm_struct *)dm_void;
756 	switch	(dm->support_platform) {
757 	case	ODM_WIN:
758 		odm_txpowertracking_check_mp(dm);
759 		break;
760 
761 	case	ODM_CE:
762 		odm_txpowertracking_check_ce(dm);
763 		break;
764 
765 	case	ODM_AP:
766 		odm_txpowertracking_check_ap(dm);
767 		break;
768 
769 	default:
770 		break;
771 	}
772 
773 }
774 
775 void
odm_txpowertracking_check_ce(void * dm_void)776 odm_txpowertracking_check_ce(
777 	void		*dm_void
778 )
779 {
780 	struct dm_struct		*dm = (struct dm_struct *)dm_void;
781 	struct _hal_rf_				*rf = &(dm->rf_table);
782 #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
783 	void	*adapter = dm->adapter;
784 #if ((RTL8188F_SUPPORT == 1))
785 	rtl8192c_odm_check_txpowertracking(adapter);
786 #endif
787 
788 #if (RTL8188E_SUPPORT == 1)
789 
790 	if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK))
791 		return;
792 
793 	if (!cali_info->tm_trigger) {
794 		odm_set_rf_reg(dm, RF_PATH_A, RF_T_METER, RFREGOFFSETMASK, 0x60);
795 		/*DBG_8192C("Trigger 92C Thermal Meter!!\n");*/
796 
797 		cali_info->tm_trigger = 1;
798 		return;
799 
800 	} else {
801 		/*DBG_8192C("Schedule TxPowerTracking direct call!!\n");*/
802 		odm_txpowertracking_callback_thermal_meter_8188e(adapter);
803 		cali_info->tm_trigger = 0;
804 	}
805 #endif
806 #endif
807 }
808 
809 void
odm_txpowertracking_check_mp(void * dm_void)810 odm_txpowertracking_check_mp(
811 	void		*dm_void
812 )
813 {
814 	struct dm_struct		*dm = (struct dm_struct *)dm_void;
815 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
816 	void	*adapter = dm->adapter;
817 
818 	if (*dm->is_fcs_mode_enable)
819 		return;
820 
821 	if (odm_check_power_status(dm) == false) {
822 		RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("check_pow_status return false\n"));
823 		return;
824 	}
825 
826 	if (IS_HARDWARE_TYPE_8821B(adapter)) /* TODO: Don't Do PowerTracking*/
827 		return;
828 
829 	odm_txpowertracking_thermal_meter_check(adapter);
830 
831 
832 #endif
833 
834 }
835 
836 
837 void
odm_txpowertracking_check_ap(void * dm_void)838 odm_txpowertracking_check_ap(
839 	void		*dm_void
840 )
841 {
842 	return;
843 
844 }
845 
846 #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
847 
848 void
odm_txpowertracking_direct_call(void * adapter)849 odm_txpowertracking_direct_call(
850 	void		*adapter
851 )
852 {
853 	HAL_DATA_TYPE		*hal_data	= GET_HAL_DATA(((PADAPTER)adapter));
854 	struct dm_struct			*dm = &hal_data->DM_OutSrc;
855 
856 	if (dm->support_ic_type & (ODM_RTL8822C | ODM_RTL8814B)) {
857 #if (RTL8822C_SUPPORT == 1 || RTL8814B_SUPPORT == 1)
858 		odm_txpowertracking_new_callback_thermal_meter(dm);
859 #endif
860 	} else
861 		odm_txpowertracking_callback_thermal_meter(adapter);
862 }
863 
864 void
odm_txpowertracking_thermal_meter_check(void * adapter)865 odm_txpowertracking_thermal_meter_check(
866 	void		*adapter
867 )
868 {
869 	static u8			tm_trigger = 0;
870 	HAL_DATA_TYPE			*pHalData = GET_HAL_DATA(((PADAPTER)adapter));
871 	struct dm_struct	*dm = &(pHalData->DM_OutSrc);
872 	struct _hal_rf_			*rf = &(dm->rf_table);
873 	struct _halrf_tssi_data *tssi = &rf->halrf_tssi_data;
874 
875 	if (!(rf->rf_supportability & HAL_RF_TX_PWR_TRACK)) {
876 		RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD,
877 			("===>odm_txpowertracking_thermal_meter_check(),mgnt_info->is_txpowertracking is false, return!!\n"));
878 		return;
879 	}
880 
881 	if (!tm_trigger) {
882 		if (IS_HARDWARE_TYPE_8188E(adapter) || IS_HARDWARE_TYPE_JAGUAR(adapter) || IS_HARDWARE_TYPE_8192E(adapter) || IS_HARDWARE_TYPE_8192F(adapter)
883 		    ||IS_HARDWARE_TYPE_8723B(adapter) || IS_HARDWARE_TYPE_8814A(adapter) || IS_HARDWARE_TYPE_8188F(adapter) || IS_HARDWARE_TYPE_8703B(adapter)
884 		    || IS_HARDWARE_TYPE_8822B(adapter) || IS_HARDWARE_TYPE_8723D(adapter) || IS_HARDWARE_TYPE_8821C(adapter) || IS_HARDWARE_TYPE_8710B(adapter)
885 		    )/* JJ ADD 20161014 */
886 			PHY_SetRFReg(adapter, RF_PATH_A, RF_T_METER_88E, BIT(17) | BIT(16), 0x03);
887 		else if (IS_HARDWARE_TYPE_8822C(adapter)) {
888 			odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01);
889 			odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x00);
890 			odm_set_rf_reg(dm, RF_PATH_A, R_0x42, BIT(19), 0x01);
891 
892 			odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01);
893 			odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x00);
894 			odm_set_rf_reg(dm, RF_PATH_B, R_0x42, BIT(19), 0x01);
895 		} else if (IS_HARDWARE_TYPE_8814B(adapter)) {
896 			odm_set_rf_reg(dm, RF_PATH_A, 0x42, BIT(17), 0x1);
897 			odm_set_rf_reg(dm, RF_PATH_B, 0x42, BIT(17), 0x1);
898 			odm_set_rf_reg(dm, RF_PATH_C, 0x42, BIT(17), 0x1);
899 			odm_set_rf_reg(dm, RF_PATH_D, 0x42, BIT(17), 0x1);
900 		} else
901 			PHY_SetRFReg(adapter, RF_PATH_A, RF_T_METER, RFREGOFFSETMASK, 0x60);
902 
903 		if (dm->support_ic_type & ODM_RTL8814B) {
904 			ODM_delay_us(300);
905 			odm_txpowertracking_direct_call(adapter);
906 			tssi->thermal_trigger = 1;
907 		}
908 
909 		RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("Trigger Thermal Meter!!\n"));
910 
911 		tm_trigger = 1;
912 		return;
913 	} else {
914 		RT_TRACE(COMP_POWER_TRACKING, DBG_LOUD, ("Schedule TxPowerTracking direct call!!\n"));
915 		odm_txpowertracking_direct_call(adapter);
916 
917 		if (dm->support_ic_type & ODM_RTL8814B)
918 			tssi->thermal_trigger = 0;
919 
920 		tm_trigger = 0;
921 	}
922 }
923 
924 #endif
925