blob: bbe61cc0c27e2c6345c1789bd263597a698e3838 [file] [log] [blame]
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2/* Copyright(c) 2018-2019 Realtek Corporation
3 */
4
5#include "main.h"
6#include "fw.h"
7#include "tx.h"
8#include "rx.h"
9#include "phy.h"
10#include "rtw8822c.h"
11#include "rtw8822c_table.h"
12#include "mac.h"
13#include "reg.h"
14#include "debug.h"
15
16static void rtw8822c_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path,
17 u8 rx_path, bool is_tx2_path);
18
19static void rtw8822ce_efuse_parsing(struct rtw_efuse *efuse,
20 struct rtw8822c_efuse *map)
21{
22 ether_addr_copy(efuse->addr, map->e.mac_addr);
23}
24
25static int rtw8822c_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
26{
27 struct rtw_efuse *efuse = &rtwdev->efuse;
28 struct rtw8822c_efuse *map;
29 int i;
30
31 map = (struct rtw8822c_efuse *)log_map;
32
33 efuse->rfe_option = map->rfe_option;
34 efuse->crystal_cap = map->xtal_k;
35 efuse->channel_plan = map->channel_plan;
36 efuse->country_code[0] = map->country_code[0];
37 efuse->country_code[1] = map->country_code[1];
38 efuse->bt_setting = map->rf_bt_setting;
39 efuse->regd = map->rf_board_option & 0x7;
40
41 for (i = 0; i < 4; i++)
42 efuse->txpwr_idx_table[i] = map->txpwr_idx_table[i];
43
44 switch (rtw_hci_type(rtwdev)) {
45 case RTW_HCI_TYPE_PCIE:
46 rtw8822ce_efuse_parsing(efuse, map);
47 break;
48 default:
49 /* unsupported now */
50 return -ENOTSUPP;
51 }
52
53 return 0;
54}
55
56static void rtw8822c_header_file_init(struct rtw_dev *rtwdev, bool pre)
57{
58 rtw_write32_set(rtwdev, REG_3WIRE, BIT_3WIRE_TX_EN | BIT_3WIRE_RX_EN);
59 rtw_write32_set(rtwdev, REG_3WIRE, BIT_3WIRE_PI_ON);
60 rtw_write32_set(rtwdev, REG_3WIRE2, BIT_3WIRE_TX_EN | BIT_3WIRE_RX_EN);
61 rtw_write32_set(rtwdev, REG_3WIRE2, BIT_3WIRE_PI_ON);
62
63 if (pre)
64 rtw_write32_clr(rtwdev, REG_ENCCK, BIT_CCK_OFDM_BLK_EN);
65 else
66 rtw_write32_set(rtwdev, REG_ENCCK, BIT_CCK_OFDM_BLK_EN);
67}
68
69static void rtw8822c_dac_backup_reg(struct rtw_dev *rtwdev,
70 struct rtw_backup_info *backup,
71 struct rtw_backup_info *backup_rf)
72{
73 u32 path, i;
74 u32 val;
75 u32 reg;
76 u32 rf_addr[DACK_RF_8822C] = {0x8f};
77 u32 addrs[DACK_REG_8822C] = {0x180c, 0x1810, 0x410c, 0x4110,
78 0x1c3c, 0x1c24, 0x1d70, 0x9b4,
79 0x1a00, 0x1a14, 0x1d58, 0x1c38,
80 0x1e24, 0x1e28, 0x1860, 0x4160};
81
82 for (i = 0; i < DACK_REG_8822C; i++) {
83 backup[i].len = 4;
84 backup[i].reg = addrs[i];
85 backup[i].val = rtw_read32(rtwdev, addrs[i]);
86 }
87
88 for (path = 0; path < DACK_PATH_8822C; path++) {
89 for (i = 0; i < DACK_RF_8822C; i++) {
90 reg = rf_addr[i];
91 val = rtw_read_rf(rtwdev, path, reg, RFREG_MASK);
92 backup_rf[path * i + i].reg = reg;
93 backup_rf[path * i + i].val = val;
94 }
95 }
96}
97
98static void rtw8822c_dac_restore_reg(struct rtw_dev *rtwdev,
99 struct rtw_backup_info *backup,
100 struct rtw_backup_info *backup_rf)
101{
102 u32 path, i;
103 u32 val;
104 u32 reg;
105
106 rtw_restore_reg(rtwdev, backup, DACK_REG_8822C);
107
108 for (path = 0; path < DACK_PATH_8822C; path++) {
109 for (i = 0; i < DACK_RF_8822C; i++) {
110 val = backup_rf[path * i + i].val;
111 reg = backup_rf[path * i + i].reg;
112 rtw_write_rf(rtwdev, path, reg, RFREG_MASK, val);
113 }
114 }
115}
116
117static void rtw8822c_rf_minmax_cmp(struct rtw_dev *rtwdev, u32 value,
118 u32 *min, u32 *max)
119{
120 if (value >= 0x200) {
121 if (*min >= 0x200) {
122 if (*min > value)
123 *min = value;
124 } else {
125 *min = value;
126 }
127 if (*max >= 0x200) {
128 if (*max < value)
129 *max = value;
130 }
131 } else {
132 if (*min < 0x200) {
133 if (*min > value)
134 *min = value;
135 }
136
137 if (*max >= 0x200) {
138 *max = value;
139 } else {
140 if (*max < value)
141 *max = value;
142 }
143 }
144}
145
146static void swap_u32(u32 *v1, u32 *v2)
147{
148 u32 tmp;
149
150 tmp = *v1;
151 *v1 = *v2;
152 *v2 = tmp;
153}
154
155static void __rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, u32 *v1, u32 *v2)
156{
157 if (*v1 >= 0x200 && *v2 >= 0x200) {
158 if (*v1 > *v2)
159 swap_u32(v1, v2);
160 } else if (*v1 < 0x200 && *v2 < 0x200) {
161 if (*v1 > *v2)
162 swap_u32(v1, v2);
163 } else if (*v1 < 0x200 && *v2 >= 0x200) {
164 swap_u32(v1, v2);
165 }
166}
167
168static void rtw8822c_dac_iq_sort(struct rtw_dev *rtwdev, u32 *iv, u32 *qv)
169{
170 u32 i, j;
171
172 for (i = 0; i < DACK_SN_8822C - 1; i++) {
173 for (j = 0; j < (DACK_SN_8822C - 1 - i) ; j++) {
174 __rtw8822c_dac_iq_sort(rtwdev, &iv[j], &iv[j + 1]);
175 __rtw8822c_dac_iq_sort(rtwdev, &qv[j], &qv[j + 1]);
176 }
177 }
178}
179
180static void rtw8822c_dac_iq_offset(struct rtw_dev *rtwdev, u32 *vec, u32 *val)
181{
182 u32 p, m, t, i;
183
184 m = 0;
185 p = 0;
186 for (i = 10; i < DACK_SN_8822C - 10; i++) {
187 if (vec[i] > 0x200)
188 m = (0x400 - vec[i]) + m;
189 else
190 p = vec[i] + p;
191 }
192
193 if (p > m) {
194 t = p - m;
195 t = t / (DACK_SN_8822C - 20);
196 } else {
197 t = m - p;
198 t = t / (DACK_SN_8822C - 20);
199 if (t != 0x0)
200 t = 0x400 - t;
201 }
202
203 *val = t;
204}
205
206static u32 rtw8822c_get_path_base_addr(u8 path)
207{
208 u32 base_addr;
209
210 switch (path) {
211 case RF_PATH_A:
212 base_addr = 0x1800;
213 break;
214 case RF_PATH_B:
215 base_addr = 0x4100;
216 break;
217 default:
218 WARN_ON(1);
219 return -1;
220 }
221
222 return base_addr;
223}
224
225static bool rtw8822c_dac_iq_check(struct rtw_dev *rtwdev, u32 value)
226{
227 bool ret = true;
228
229 if ((value >= 0x200 && (0x400 - value) > 0x64) ||
230 (value < 0x200 && value > 0x64)) {
231 ret = false;
232 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] Error overflow\n");
233 }
234
235 return ret;
236}
237
238static void rtw8822c_dac_cal_iq_sample(struct rtw_dev *rtwdev, u32 *iv, u32 *qv)
239{
240 u32 temp;
241 int i = 0, cnt = 0;
242
243 while (i < DACK_SN_8822C && cnt < 10000) {
244 cnt++;
245 temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff);
246 iv[i] = (temp & 0x3ff000) >> 12;
247 qv[i] = temp & 0x3ff;
248
249 if (rtw8822c_dac_iq_check(rtwdev, iv[i]) &&
250 rtw8822c_dac_iq_check(rtwdev, qv[i]))
251 i++;
252 }
253}
254
255static void rtw8822c_dac_cal_iq_search(struct rtw_dev *rtwdev,
256 u32 *iv, u32 *qv,
257 u32 *i_value, u32 *q_value)
258{
259 u32 i_max = 0, q_max = 0, i_min = 0, q_min = 0;
260 u32 i_delta, q_delta;
261 u32 temp;
262 int i, cnt = 0;
263
264 do {
265 i_min = iv[0];
266 i_max = iv[0];
267 q_min = qv[0];
268 q_max = qv[0];
269 for (i = 0; i < DACK_SN_8822C; i++) {
270 rtw8822c_rf_minmax_cmp(rtwdev, iv[i], &i_min, &i_max);
271 rtw8822c_rf_minmax_cmp(rtwdev, qv[i], &q_min, &q_max);
272 }
273
274 if (i_max < 0x200 && i_min < 0x200)
275 i_delta = i_max - i_min;
276 else if (i_max >= 0x200 && i_min >= 0x200)
277 i_delta = i_max - i_min;
278 else
279 i_delta = i_max + (0x400 - i_min);
280
281 if (q_max < 0x200 && q_min < 0x200)
282 q_delta = q_max - q_min;
283 else if (q_max >= 0x200 && q_min >= 0x200)
284 q_delta = q_max - q_min;
285 else
286 q_delta = q_max + (0x400 - q_min);
287
288 rtw_dbg(rtwdev, RTW_DBG_RFK,
289 "[DACK] i: min=0x%08x, max=0x%08x, delta=0x%08x\n",
290 i_min, i_max, i_delta);
291 rtw_dbg(rtwdev, RTW_DBG_RFK,
292 "[DACK] q: min=0x%08x, max=0x%08x, delta=0x%08x\n",
293 q_min, q_max, q_delta);
294
295 rtw8822c_dac_iq_sort(rtwdev, iv, qv);
296
297 if (i_delta > 5 || q_delta > 5) {
298 temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff);
299 iv[0] = (temp & 0x3ff000) >> 12;
300 qv[0] = temp & 0x3ff;
301 temp = rtw_read32_mask(rtwdev, 0x2dbc, 0x3fffff);
302 iv[DACK_SN_8822C - 1] = (temp & 0x3ff000) >> 12;
303 qv[DACK_SN_8822C - 1] = temp & 0x3ff;
304 } else {
305 break;
306 }
307 } while (cnt++ < 100);
308
309 rtw8822c_dac_iq_offset(rtwdev, iv, i_value);
310 rtw8822c_dac_iq_offset(rtwdev, qv, q_value);
311}
312
313static void rtw8822c_dac_cal_rf_mode(struct rtw_dev *rtwdev,
314 u32 *i_value, u32 *q_value)
315{
316 u32 iv[DACK_SN_8822C], qv[DACK_SN_8822C];
317 u32 rf_a, rf_b;
318
319 mdelay(10);
320
321 rf_a = rtw_read_rf(rtwdev, RF_PATH_A, 0x0, RFREG_MASK);
322 rf_b = rtw_read_rf(rtwdev, RF_PATH_B, 0x0, RFREG_MASK);
323
324 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] RF path-A=0x%05x\n", rf_a);
325 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] RF path-B=0x%05x\n", rf_b);
326
327 rtw8822c_dac_cal_iq_sample(rtwdev, iv, qv);
328 rtw8822c_dac_cal_iq_search(rtwdev, iv, qv, i_value, q_value);
329}
330
331static void rtw8822c_dac_bb_setting(struct rtw_dev *rtwdev)
332{
333 rtw_write32_mask(rtwdev, 0x1d58, 0xff8, 0x1ff);
334 rtw_write32_mask(rtwdev, 0x1a00, 0x3, 0x2);
335 rtw_write32_mask(rtwdev, 0x1a14, 0x300, 0x3);
336 rtw_write32(rtwdev, 0x1d70, 0x7e7e7e7e);
337 rtw_write32_mask(rtwdev, 0x180c, 0x3, 0x0);
338 rtw_write32_mask(rtwdev, 0x410c, 0x3, 0x0);
339 rtw_write32(rtwdev, 0x1b00, 0x00000008);
340 rtw_write8(rtwdev, 0x1bcc, 0x3f);
341 rtw_write32(rtwdev, 0x1b00, 0x0000000a);
342 rtw_write8(rtwdev, 0x1bcc, 0x3f);
343 rtw_write32_mask(rtwdev, 0x1e24, BIT(31), 0x0);
344 rtw_write32_mask(rtwdev, 0x1e28, 0xf, 0x3);
345}
346
347static void rtw8822c_dac_cal_adc(struct rtw_dev *rtwdev,
348 u8 path, u32 *adc_ic, u32 *adc_qc)
349{
350 u32 ic = 0, qc = 0, temp = 0;
351 u32 base_addr;
352 u32 path_sel;
353 int i;
354
355 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK path(%d)\n", path);
356
357 base_addr = rtw8822c_get_path_base_addr(path);
358 switch (path) {
359 case RF_PATH_A:
360 path_sel = 0xa0000;
361 break;
362 case RF_PATH_B:
363 path_sel = 0x80000;
364 break;
365 default:
366 WARN_ON(1);
367 return;
368 }
369
370 /* ADCK step1 */
371 rtw_write32_mask(rtwdev, base_addr + 0x30, BIT(30), 0x0);
372 if (path == RF_PATH_B)
373 rtw_write32(rtwdev, base_addr + 0x30, 0x30db8041);
374 rtw_write32(rtwdev, base_addr + 0x60, 0xf0040ff0);
375 rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220);
376 rtw_write32(rtwdev, base_addr + 0x10, 0x02dd08c4);
377 rtw_write32(rtwdev, base_addr + 0x0c, 0x10000260);
378 rtw_write_rf(rtwdev, RF_PATH_A, 0x0, RFREG_MASK, 0x10000);
379 rtw_write_rf(rtwdev, RF_PATH_B, 0x0, RFREG_MASK, 0x10000);
380 for (i = 0; i < 10; i++) {
381 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK count=%d\n", i);
382 rtw_write32(rtwdev, 0x1c3c, path_sel + 0x8003);
383 rtw_write32(rtwdev, 0x1c24, 0x00010002);
384 rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc);
385 rtw_dbg(rtwdev, RTW_DBG_RFK,
386 "[DACK] before: i=0x%x, q=0x%x\n", ic, qc);
387
388 /* compensation value */
389 if (ic != 0x0) {
390 ic = 0x400 - ic;
391 *adc_ic = ic;
392 }
393 if (qc != 0x0) {
394 qc = 0x400 - qc;
395 *adc_qc = qc;
396 }
397 temp = (ic & 0x3ff) | ((qc & 0x3ff) << 10);
398 rtw_write32(rtwdev, base_addr + 0x68, temp);
399 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] ADCK 0x%08x=0x08%x\n",
400 base_addr + 0x68, temp);
401 /* check ADC DC offset */
402 rtw_write32(rtwdev, 0x1c3c, path_sel + 0x8103);
403 rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc);
404 rtw_dbg(rtwdev, RTW_DBG_RFK,
405 "[DACK] after: i=0x%08x, q=0x%08x\n", ic, qc);
406 if (ic >= 0x200)
407 ic = 0x400 - ic;
408 if (qc >= 0x200)
409 qc = 0x400 - qc;
410 if (ic < 5 && qc < 5)
411 break;
412 }
413
414 /* ADCK step2 */
415 rtw_write32(rtwdev, 0x1c3c, 0x00000003);
416 rtw_write32(rtwdev, base_addr + 0x0c, 0x10000260);
417 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c4);
418
419 /* release pull low switch on IQ path */
420 rtw_write_rf(rtwdev, path, 0x8f, BIT(13), 0x1);
421}
422
423static void rtw8822c_dac_cal_step1(struct rtw_dev *rtwdev, u8 path)
424{
425 u32 base_addr;
426
427 base_addr = rtw8822c_get_path_base_addr(path);
428
429 rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220);
430 if (path == RF_PATH_A) {
431 rtw_write32(rtwdev, base_addr + 0x60, 0xf0040ff0);
432 rtw_write32(rtwdev, 0x1c38, 0xffffffff);
433 }
434 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5);
435 rtw_write32(rtwdev, 0x9b4, 0xdb66db00);
436 rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb88);
437 rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff81);
438 rtw_write32(rtwdev, base_addr + 0xc0, 0x0003d208);
439 rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb88);
440 rtw_write32(rtwdev, base_addr + 0xd8, 0x0008ff81);
441 rtw_write32(rtwdev, base_addr + 0xdc, 0x0003d208);
442 rtw_write32(rtwdev, base_addr + 0xb8, 0x60000000);
443 mdelay(2);
444 rtw_write32(rtwdev, base_addr + 0xbc, 0x000aff8d);
445 mdelay(2);
446 rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb89);
447 rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb89);
448 mdelay(1);
449 rtw_write32(rtwdev, base_addr + 0xb8, 0x62000000);
450 mdelay(20);
451 rtw_write32(rtwdev, base_addr + 0xd4, 0x62000000);
452 mdelay(20);
453 rtw_write32(rtwdev, base_addr + 0xb8, 0x02000000);
454 mdelay(20);
455 rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff87);
456 rtw_write32(rtwdev, 0x9b4, 0xdb6db600);
457 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5);
458 rtw_write32(rtwdev, base_addr + 0xbc, 0x0008ff87);
459 rtw_write32(rtwdev, base_addr + 0x60, 0xf0000000);
460}
461
462static void rtw8822c_dac_cal_step2(struct rtw_dev *rtwdev,
463 u8 path, u32 *ic_out, u32 *qc_out)
464{
465 u32 base_addr;
466 u32 ic, qc, ic_in, qc_in;
467
468 base_addr = rtw8822c_get_path_base_addr(path);
469 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xf0000000, 0x0);
470 rtw_write32_mask(rtwdev, base_addr + 0xc0, 0xf, 0x8);
471 rtw_write32_mask(rtwdev, base_addr + 0xd8, 0xf0000000, 0x0);
472 rtw_write32_mask(rtwdev, base_addr + 0xdc, 0xf, 0x8);
473
474 rtw_write32(rtwdev, 0x1b00, 0x00000008);
475 rtw_write8(rtwdev, 0x1bcc, 0x03f);
476 rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220);
477 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5);
478 rtw_write32(rtwdev, 0x1c3c, 0x00088103);
479
480 rtw8822c_dac_cal_rf_mode(rtwdev, &ic_in, &qc_in);
481 ic = ic_in;
482 qc = qc_in;
483
484 /* compensation value */
485 if (ic != 0x0)
486 ic = 0x400 - ic;
487 if (qc != 0x0)
488 qc = 0x400 - qc;
489 if (ic < 0x300) {
490 ic = ic * 2 * 6 / 5;
491 ic = ic + 0x80;
492 } else {
493 ic = (0x400 - ic) * 2 * 6 / 5;
494 ic = 0x7f - ic;
495 }
496 if (qc < 0x300) {
497 qc = qc * 2 * 6 / 5;
498 qc = qc + 0x80;
499 } else {
500 qc = (0x400 - qc) * 2 * 6 / 5;
501 qc = 0x7f - qc;
502 }
503
504 *ic_out = ic;
505 *qc_out = qc;
506
507 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] before i=0x%x, q=0x%x\n", ic_in, qc_in);
508 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] after i=0x%x, q=0x%x\n", ic, qc);
509}
510
511static void rtw8822c_dac_cal_step3(struct rtw_dev *rtwdev, u8 path,
512 u32 adc_ic, u32 adc_qc,
513 u32 *ic_in, u32 *qc_in,
514 u32 *i_out, u32 *q_out)
515{
516 u32 base_addr;
517 u32 ic, qc;
518 u32 temp;
519
520 base_addr = rtw8822c_get_path_base_addr(path);
521 ic = *ic_in;
522 qc = *qc_in;
523
524 rtw_write32(rtwdev, base_addr + 0x0c, 0xdff00220);
525 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5);
526 rtw_write32(rtwdev, 0x9b4, 0xdb66db00);
527 rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb88);
528 rtw_write32(rtwdev, base_addr + 0xbc, 0xc008ff81);
529 rtw_write32(rtwdev, base_addr + 0xc0, 0x0003d208);
530 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xf0000000, ic & 0xf);
531 rtw_write32_mask(rtwdev, base_addr + 0xc0, 0xf, (ic & 0xf0) >> 4);
532 rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb88);
533 rtw_write32(rtwdev, base_addr + 0xd8, 0xe008ff81);
534 rtw_write32(rtwdev, base_addr + 0xdc, 0x0003d208);
535 rtw_write32_mask(rtwdev, base_addr + 0xd8, 0xf0000000, qc & 0xf);
536 rtw_write32_mask(rtwdev, base_addr + 0xdc, 0xf, (qc & 0xf0) >> 4);
537 rtw_write32(rtwdev, base_addr + 0xb8, 0x60000000);
538 mdelay(2);
539 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xe, 0x6);
540 mdelay(2);
541 rtw_write32(rtwdev, base_addr + 0xb0, 0x0a11fb89);
542 rtw_write32(rtwdev, base_addr + 0xcc, 0x0a11fb89);
543 mdelay(1);
544 rtw_write32(rtwdev, base_addr + 0xb8, 0x62000000);
545 mdelay(20);
546 rtw_write32(rtwdev, base_addr + 0xd4, 0x62000000);
547 mdelay(20);
548 rtw_write32(rtwdev, base_addr + 0xb8, 0x02000000);
549 mdelay(20);
550 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0xe, 0x3);
551 rtw_write32(rtwdev, 0x9b4, 0xdb6db600);
552
553 /* check DAC DC offset */
554 temp = ((adc_ic + 0x10) & 0x3ff) | (((adc_qc + 0x10) & 0x3ff) << 10);
555 rtw_write32(rtwdev, base_addr + 0x68, temp);
556 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c5);
557 rtw_write32(rtwdev, base_addr + 0x60, 0xf0000000);
558 rtw8822c_dac_cal_rf_mode(rtwdev, &ic, &qc);
559 if (ic >= 0x10)
560 ic = ic - 0x10;
561 else
562 ic = 0x400 - (0x10 - ic);
563
564 if (qc >= 0x10)
565 qc = qc - 0x10;
566 else
567 qc = 0x400 - (0x10 - qc);
568
569 *i_out = ic;
570 *q_out = qc;
571
572 if (ic >= 0x200)
573 ic = 0x400 - ic;
574 if (qc >= 0x200)
575 qc = 0x400 - qc;
576
577 *ic_in = ic;
578 *qc_in = qc;
579
580 rtw_dbg(rtwdev, RTW_DBG_RFK,
581 "[DACK] after DACK i=0x%x, q=0x%x\n", *i_out, *q_out);
582}
583
584static void rtw8822c_dac_cal_step4(struct rtw_dev *rtwdev, u8 path)
585{
586 u32 base_addr = rtw8822c_get_path_base_addr(path);
587
588 rtw_write32(rtwdev, base_addr + 0x68, 0x0);
589 rtw_write32(rtwdev, base_addr + 0x10, 0x02d508c4);
590 rtw_write32_mask(rtwdev, base_addr + 0xbc, 0x1, 0x0);
591 rtw_write32_mask(rtwdev, base_addr + 0x30, BIT(30), 0x1);
592}
593
594static void rtw8822c_rf_dac_cal(struct rtw_dev *rtwdev)
595{
596 struct rtw_backup_info backup_rf[DACK_RF_8822C * DACK_PATH_8822C];
597 struct rtw_backup_info backup[DACK_REG_8822C];
598 u32 ic = 0, qc = 0, i;
599 u32 i_a = 0x0, q_a = 0x0, i_b = 0x0, q_b = 0x0;
600 u32 ic_a = 0x0, qc_a = 0x0, ic_b = 0x0, qc_b = 0x0;
601 u32 adc_ic_a = 0x0, adc_qc_a = 0x0, adc_ic_b = 0x0, adc_qc_b = 0x0;
602
603 rtw8822c_dac_backup_reg(rtwdev, backup, backup_rf);
604
605 rtw8822c_dac_bb_setting(rtwdev);
606
607 /* path-A */
608 rtw8822c_dac_cal_adc(rtwdev, RF_PATH_A, &adc_ic_a, &adc_qc_a);
609 for (i = 0; i < 10; i++) {
610 rtw8822c_dac_cal_step1(rtwdev, RF_PATH_A);
611 rtw8822c_dac_cal_step2(rtwdev, RF_PATH_A, &ic, &qc);
612 ic_a = ic;
613 qc_a = qc;
614
615 rtw8822c_dac_cal_step3(rtwdev, RF_PATH_A, adc_ic_a, adc_qc_a,
616 &ic, &qc, &i_a, &q_a);
617
618 if (ic < 5 && qc < 5)
619 break;
620 }
621 rtw8822c_dac_cal_step4(rtwdev, RF_PATH_A);
622
623 /* path-B */
624 rtw8822c_dac_cal_adc(rtwdev, RF_PATH_B, &adc_ic_b, &adc_qc_b);
625 for (i = 0; i < 10; i++) {
626 rtw8822c_dac_cal_step1(rtwdev, RF_PATH_B);
627 rtw8822c_dac_cal_step2(rtwdev, RF_PATH_B, &ic, &qc);
628 ic_b = ic;
629 qc_b = qc;
630
631 rtw8822c_dac_cal_step3(rtwdev, RF_PATH_B, adc_ic_b, adc_qc_b,
632 &ic, &qc, &i_b, &q_b);
633
634 if (ic < 5 && qc < 5)
635 break;
636 }
637 rtw8822c_dac_cal_step4(rtwdev, RF_PATH_B);
638
639 rtw_write32(rtwdev, 0x1b00, 0x00000008);
640 rtw_write32_mask(rtwdev, 0x4130, BIT(30), 0x1);
641 rtw_write8(rtwdev, 0x1bcc, 0x0);
642 rtw_write32(rtwdev, 0x1b00, 0x0000000a);
643 rtw_write8(rtwdev, 0x1bcc, 0x0);
644
645 rtw8822c_dac_restore_reg(rtwdev, backup, backup_rf);
646
647 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path A: ic=0x%x, qc=0x%x\n", ic_a, qc_a);
648 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path B: ic=0x%x, qc=0x%x\n", ic_b, qc_b);
649 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path A: i=0x%x, q=0x%x\n", i_a, q_a);
650 rtw_dbg(rtwdev, RTW_DBG_RFK, "[DACK] path B: i=0x%x, q=0x%x\n", i_b, q_b);
651}
652
653static void rtw8822c_rf_x2_check(struct rtw_dev *rtwdev)
654{
655 u8 x2k_busy;
656
657 mdelay(1);
658 x2k_busy = rtw_read_rf(rtwdev, RF_PATH_A, 0xb8, BIT(15));
659 if (x2k_busy == 1) {
660 rtw_write_rf(rtwdev, RF_PATH_A, 0xb8, RFREG_MASK, 0xC4440);
661 rtw_write_rf(rtwdev, RF_PATH_A, 0xba, RFREG_MASK, 0x6840D);
662 rtw_write_rf(rtwdev, RF_PATH_A, 0xb8, RFREG_MASK, 0x80440);
663 mdelay(1);
664 }
665}
666
667static void rtw8822c_rf_init(struct rtw_dev *rtwdev)
668{
669 rtw8822c_rf_dac_cal(rtwdev);
670 rtw8822c_rf_x2_check(rtwdev);
671}
672
673static void rtw8822c_phy_set_param(struct rtw_dev *rtwdev)
674{
675 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
676 struct rtw_hal *hal = &rtwdev->hal;
677 u8 crystal_cap;
678 u8 cck_gi_u_bnd_msb = 0;
679 u8 cck_gi_u_bnd_lsb = 0;
680 u8 cck_gi_l_bnd_msb = 0;
681 u8 cck_gi_l_bnd_lsb = 0;
682 bool is_tx2_path;
683
684 /* power on BB/RF domain */
685 rtw_write8_set(rtwdev, REG_SYS_FUNC_EN,
686 BIT_FEN_BB_GLB_RST | BIT_FEN_BB_RSTB);
687 rtw_write8_set(rtwdev, REG_RF_CTRL,
688 BIT_RF_EN | BIT_RF_RSTB | BIT_RF_SDM_RSTB);
689 rtw_write32_set(rtwdev, REG_WLRF1, BIT_WLRF1_BBRF_EN);
690
691 /* pre init before header files config */
692 rtw8822c_header_file_init(rtwdev, true);
693
694 rtw_phy_load_tables(rtwdev);
695
696 crystal_cap = rtwdev->efuse.crystal_cap & 0x7f;
697 rtw_write32_mask(rtwdev, REG_ANAPAR_XTAL_0, 0xfffc00,
698 crystal_cap | (crystal_cap << 7));
699
700 /* post init after header files config */
701 rtw8822c_header_file_init(rtwdev, false);
702
703 is_tx2_path = false;
704 rtw8822c_config_trx_mode(rtwdev, hal->antenna_tx, hal->antenna_rx,
705 is_tx2_path);
706 rtw_phy_init(rtwdev);
707
708 cck_gi_u_bnd_msb = (u8)rtw_read32_mask(rtwdev, 0x1a98, 0xc000);
709 cck_gi_u_bnd_lsb = (u8)rtw_read32_mask(rtwdev, 0x1aa8, 0xf0000);
710 cck_gi_l_bnd_msb = (u8)rtw_read32_mask(rtwdev, 0x1a98, 0xc0);
711 cck_gi_l_bnd_lsb = (u8)rtw_read32_mask(rtwdev, 0x1a70, 0x0f000000);
712
713 dm_info->cck_gi_u_bnd = ((cck_gi_u_bnd_msb << 4) | (cck_gi_u_bnd_lsb));
714 dm_info->cck_gi_l_bnd = ((cck_gi_l_bnd_msb << 4) | (cck_gi_l_bnd_lsb));
715
716 rtw8822c_rf_init(rtwdev);
717 /* wifi path controller */
718 rtw_write32_mask(rtwdev, 0x70, 0xff000000, 0x0e);
719 rtw_write32_mask(rtwdev, 0x1704, 0xffffffff, 0x7700);
720 rtw_write32_mask(rtwdev, 0x1700, 0xffffffff, 0xc00f0038);
721 rtw_write32_mask(rtwdev, 0x6c0, 0xffffffff, 0xaaaaaaaa);
722 rtw_write32_mask(rtwdev, 0x6c4, 0xffffffff, 0xaaaaaaaa);
723}
724
725#define WLAN_TXQ_RPT_EN 0x1F
726#define WLAN_SLOT_TIME 0x09
727#define WLAN_PIFS_TIME 0x1C
728#define WLAN_SIFS_CCK_CONT_TX 0x0A
729#define WLAN_SIFS_OFDM_CONT_TX 0x0E
730#define WLAN_SIFS_CCK_TRX 0x0A
731#define WLAN_SIFS_OFDM_TRX 0x10
732#define WLAN_NAV_MAX 0xC8
733#define WLAN_RDG_NAV 0x05
734#define WLAN_TXOP_NAV 0x1B
735#define WLAN_CCK_RX_TSF 0x30
736#define WLAN_OFDM_RX_TSF 0x30
737#define WLAN_TBTT_PROHIBIT 0x04 /* unit : 32us */
738#define WLAN_TBTT_HOLD_TIME 0x064 /* unit : 32us */
739#define WLAN_DRV_EARLY_INT 0x04
740#define WLAN_BCN_CTRL_CLT0 0x10
741#define WLAN_BCN_DMA_TIME 0x02
742#define WLAN_BCN_MAX_ERR 0xFF
743#define WLAN_SIFS_CCK_DUR_TUNE 0x0A
744#define WLAN_SIFS_OFDM_DUR_TUNE 0x10
745#define WLAN_SIFS_CCK_CTX 0x0A
746#define WLAN_SIFS_CCK_IRX 0x0A
747#define WLAN_SIFS_OFDM_CTX 0x0E
748#define WLAN_SIFS_OFDM_IRX 0x0E
749#define WLAN_EIFS_DUR_TUNE 0x40
750#define WLAN_EDCA_VO_PARAM 0x002FA226
751#define WLAN_EDCA_VI_PARAM 0x005EA328
752#define WLAN_EDCA_BE_PARAM 0x005EA42B
753#define WLAN_EDCA_BK_PARAM 0x0000A44F
754
755#define WLAN_RX_FILTER0 0xFFFFFFFF
756#define WLAN_RX_FILTER2 0xFFFF
757#define WLAN_RCR_CFG 0xE400220E
758#define WLAN_RXPKT_MAX_SZ 12288
759#define WLAN_RXPKT_MAX_SZ_512 (WLAN_RXPKT_MAX_SZ >> 9)
760
761#define WLAN_AMPDU_MAX_TIME 0x70
762#define WLAN_RTS_LEN_TH 0xFF
763#define WLAN_RTS_TX_TIME_TH 0x08
764#define WLAN_MAX_AGG_PKT_LIMIT 0x20
765#define WLAN_RTS_MAX_AGG_PKT_LIMIT 0x20
766#define WLAN_PRE_TXCNT_TIME_TH 0x1E0
767#define FAST_EDCA_VO_TH 0x06
768#define FAST_EDCA_VI_TH 0x06
769#define FAST_EDCA_BE_TH 0x06
770#define FAST_EDCA_BK_TH 0x06
771#define WLAN_BAR_RETRY_LIMIT 0x01
772#define WLAN_BAR_ACK_TYPE 0x05
773#define WLAN_RA_TRY_RATE_AGG_LIMIT 0x08
774#define WLAN_RESP_TXRATE 0x84
775#define WLAN_ACK_TO 0x21
776#define WLAN_ACK_TO_CCK 0x6A
777#define WLAN_DATA_RATE_FB_CNT_1_4 0x01000000
778#define WLAN_DATA_RATE_FB_CNT_5_8 0x08070504
779#define WLAN_RTS_RATE_FB_CNT_5_8 0x08070504
780#define WLAN_DATA_RATE_FB_RATE0 0xFE01F010
781#define WLAN_DATA_RATE_FB_RATE0_H 0x40000000
782#define WLAN_RTS_RATE_FB_RATE1 0x003FF010
783#define WLAN_RTS_RATE_FB_RATE1_H 0x40000000
784#define WLAN_RTS_RATE_FB_RATE4 0x0600F010
785#define WLAN_RTS_RATE_FB_RATE4_H 0x400003E0
786#define WLAN_RTS_RATE_FB_RATE5 0x0600F015
787#define WLAN_RTS_RATE_FB_RATE5_H 0x000000E0
788
789#define WLAN_TX_FUNC_CFG1 0x30
790#define WLAN_TX_FUNC_CFG2 0x30
791#define WLAN_MAC_OPT_NORM_FUNC1 0x98
792#define WLAN_MAC_OPT_LB_FUNC1 0x80
793#define WLAN_MAC_OPT_FUNC2 0x30810041
794
795#define WLAN_SIFS_CFG (WLAN_SIFS_CCK_CONT_TX | \
796 (WLAN_SIFS_OFDM_CONT_TX << BIT_SHIFT_SIFS_OFDM_CTX) | \
797 (WLAN_SIFS_CCK_TRX << BIT_SHIFT_SIFS_CCK_TRX) | \
798 (WLAN_SIFS_OFDM_TRX << BIT_SHIFT_SIFS_OFDM_TRX))
799
800#define WLAN_SIFS_DUR_TUNE (WLAN_SIFS_CCK_DUR_TUNE | \
801 (WLAN_SIFS_OFDM_DUR_TUNE << 8))
802
803#define WLAN_TBTT_TIME (WLAN_TBTT_PROHIBIT |\
804 (WLAN_TBTT_HOLD_TIME << BIT_SHIFT_TBTT_HOLD_TIME_AP))
805
806#define WLAN_NAV_CFG (WLAN_RDG_NAV | (WLAN_TXOP_NAV << 16))
807#define WLAN_RX_TSF_CFG (WLAN_CCK_RX_TSF | (WLAN_OFDM_RX_TSF) << 8)
808
809#define MAC_CLK_SPEED 80 /* 80M */
810#define EFUSE_PCB_INFO_OFFSET 0xCA
811
812static int rtw8822c_mac_init(struct rtw_dev *rtwdev)
813{
814 u8 value8;
815 u16 value16;
816 u32 value32;
817 u16 pre_txcnt;
818
819 /* txq control */
820 value8 = rtw_read8(rtwdev, REG_FWHW_TXQ_CTRL);
821 value8 |= (BIT(7) & ~BIT(1) & ~BIT(2));
822 rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL, value8);
823 rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL + 1, WLAN_TXQ_RPT_EN);
824 /* sifs control */
825 rtw_write16(rtwdev, REG_SPEC_SIFS, WLAN_SIFS_DUR_TUNE);
826 rtw_write32(rtwdev, REG_SIFS, WLAN_SIFS_CFG);
827 rtw_write16(rtwdev, REG_RESP_SIFS_CCK,
828 WLAN_SIFS_CCK_CTX | WLAN_SIFS_CCK_IRX << 8);
829 rtw_write16(rtwdev, REG_RESP_SIFS_OFDM,
830 WLAN_SIFS_OFDM_CTX | WLAN_SIFS_OFDM_IRX << 8);
831 /* rate fallback control */
832 rtw_write32(rtwdev, REG_DARFRC, WLAN_DATA_RATE_FB_CNT_1_4);
833 rtw_write32(rtwdev, REG_DARFRCH, WLAN_DATA_RATE_FB_CNT_5_8);
834 rtw_write32(rtwdev, REG_RARFRCH, WLAN_RTS_RATE_FB_CNT_5_8);
835 rtw_write32(rtwdev, REG_ARFR0, WLAN_DATA_RATE_FB_RATE0);
836 rtw_write32(rtwdev, REG_ARFRH0, WLAN_DATA_RATE_FB_RATE0_H);
837 rtw_write32(rtwdev, REG_ARFR1_V1, WLAN_RTS_RATE_FB_RATE1);
838 rtw_write32(rtwdev, REG_ARFRH1_V1, WLAN_RTS_RATE_FB_RATE1_H);
839 rtw_write32(rtwdev, REG_ARFR4, WLAN_RTS_RATE_FB_RATE4);
840 rtw_write32(rtwdev, REG_ARFRH4, WLAN_RTS_RATE_FB_RATE4_H);
841 rtw_write32(rtwdev, REG_ARFR5, WLAN_RTS_RATE_FB_RATE5);
842 rtw_write32(rtwdev, REG_ARFRH5, WLAN_RTS_RATE_FB_RATE5_H);
843 /* protocol configuration */
844 rtw_write8(rtwdev, REG_AMPDU_MAX_TIME_V1, WLAN_AMPDU_MAX_TIME);
845 rtw_write8_set(rtwdev, REG_TX_HANG_CTRL, BIT_EN_EOF_V1);
846 pre_txcnt = WLAN_PRE_TXCNT_TIME_TH | BIT_EN_PRECNT;
847 rtw_write8(rtwdev, REG_PRECNT_CTRL, (u8)(pre_txcnt & 0xFF));
848 rtw_write8(rtwdev, REG_PRECNT_CTRL + 1, (u8)(pre_txcnt >> 8));
849 value32 = WLAN_RTS_LEN_TH | (WLAN_RTS_TX_TIME_TH << 8) |
850 (WLAN_MAX_AGG_PKT_LIMIT << 16) |
851 (WLAN_RTS_MAX_AGG_PKT_LIMIT << 24);
852 rtw_write32(rtwdev, REG_PROT_MODE_CTRL, value32);
853 rtw_write16(rtwdev, REG_BAR_MODE_CTRL + 2,
854 WLAN_BAR_RETRY_LIMIT | WLAN_RA_TRY_RATE_AGG_LIMIT << 8);
855 rtw_write8(rtwdev, REG_FAST_EDCA_VOVI_SETTING, FAST_EDCA_VO_TH);
856 rtw_write8(rtwdev, REG_FAST_EDCA_VOVI_SETTING + 2, FAST_EDCA_VI_TH);
857 rtw_write8(rtwdev, REG_FAST_EDCA_BEBK_SETTING, FAST_EDCA_BE_TH);
858 rtw_write8(rtwdev, REG_FAST_EDCA_BEBK_SETTING + 2, FAST_EDCA_BK_TH);
859 /* close BA parser */
860 rtw_write8_clr(rtwdev, REG_LIFETIME_EN, BIT_BA_PARSER_EN);
861 rtw_write32_clr(rtwdev, REG_RRSR, BITS_RRSR_RSC);
862
863 /* EDCA configuration */
864 rtw_write32(rtwdev, REG_EDCA_VO_PARAM, WLAN_EDCA_VO_PARAM);
865 rtw_write32(rtwdev, REG_EDCA_VI_PARAM, WLAN_EDCA_VI_PARAM);
866 rtw_write32(rtwdev, REG_EDCA_BE_PARAM, WLAN_EDCA_BE_PARAM);
867 rtw_write32(rtwdev, REG_EDCA_BK_PARAM, WLAN_EDCA_BK_PARAM);
868 rtw_write8(rtwdev, REG_PIFS, WLAN_PIFS_TIME);
869 rtw_write8_clr(rtwdev, REG_TX_PTCL_CTRL + 1, BIT_SIFS_BK_EN >> 8);
870 rtw_write8_set(rtwdev, REG_RD_CTRL + 1,
871 (BIT_DIS_TXOP_CFE | BIT_DIS_LSIG_CFE |
872 BIT_DIS_STBC_CFE) >> 8);
873
874 /* MAC clock configuration */
875 rtw_write32_clr(rtwdev, REG_AFE_CTRL1, BIT_MAC_CLK_SEL);
876 rtw_write8(rtwdev, REG_USTIME_TSF, MAC_CLK_SPEED);
877 rtw_write8(rtwdev, REG_USTIME_EDCA, MAC_CLK_SPEED);
878
879 rtw_write8_set(rtwdev, REG_MISC_CTRL,
880 BIT_EN_FREE_CNT | BIT_DIS_SECOND_CCA);
881 rtw_write8_clr(rtwdev, REG_TIMER0_SRC_SEL, BIT_TSFT_SEL_TIMER0);
882 rtw_write16(rtwdev, REG_TXPAUSE, 0x0000);
883 rtw_write8(rtwdev, REG_SLOT, WLAN_SLOT_TIME);
884 rtw_write32(rtwdev, REG_RD_NAV_NXT, WLAN_NAV_CFG);
885 rtw_write16(rtwdev, REG_RXTSF_OFFSET_CCK, WLAN_RX_TSF_CFG);
886 /* Set beacon cotnrol - enable TSF and other related functions */
887 rtw_write8_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION);
888 /* Set send beacon related registers */
889 rtw_write32(rtwdev, REG_TBTT_PROHIBIT, WLAN_TBTT_TIME);
890 rtw_write8(rtwdev, REG_DRVERLYINT, WLAN_DRV_EARLY_INT);
891 rtw_write8(rtwdev, REG_BCN_CTRL_CLINT0, WLAN_BCN_CTRL_CLT0);
892 rtw_write8(rtwdev, REG_BCNDMATIM, WLAN_BCN_DMA_TIME);
893 rtw_write8(rtwdev, REG_BCN_MAX_ERR, WLAN_BCN_MAX_ERR);
894
895 /* WMAC configuration */
896 rtw_write8(rtwdev, REG_BBPSF_CTRL + 2, WLAN_RESP_TXRATE);
897 rtw_write8(rtwdev, REG_ACKTO, WLAN_ACK_TO);
898 rtw_write8(rtwdev, REG_ACKTO_CCK, WLAN_ACK_TO_CCK);
899 rtw_write16(rtwdev, REG_EIFS, WLAN_EIFS_DUR_TUNE);
900 rtw_write8(rtwdev, REG_NAV_CTRL + 2, WLAN_NAV_MAX);
901 rtw_write8(rtwdev, REG_WMAC_TRXPTCL_CTL_H + 2, WLAN_BAR_ACK_TYPE);
902 rtw_write32(rtwdev, REG_RXFLTMAP0, WLAN_RX_FILTER0);
903 rtw_write16(rtwdev, REG_RXFLTMAP2, WLAN_RX_FILTER2);
904 rtw_write32(rtwdev, REG_RCR, WLAN_RCR_CFG);
905 rtw_write8(rtwdev, REG_RX_PKT_LIMIT, WLAN_RXPKT_MAX_SZ_512);
906 rtw_write8(rtwdev, REG_TCR + 2, WLAN_TX_FUNC_CFG2);
907 rtw_write8(rtwdev, REG_TCR + 1, WLAN_TX_FUNC_CFG1);
908 rtw_write32_set(rtwdev, REG_GENERAL_OPTION, BIT_DUMMY_FCS_READY_MASK_EN);
909 rtw_write32(rtwdev, REG_WMAC_OPTION_FUNCTION + 8, WLAN_MAC_OPT_FUNC2);
910 rtw_write8(rtwdev, REG_WMAC_OPTION_FUNCTION_1, WLAN_MAC_OPT_NORM_FUNC1);
911
912 /* init low power */
913 value16 = rtw_read16(rtwdev, REG_RXPSF_CTRL + 2) & 0xF00F;
914 value16 |= (BIT_RXGCK_VHT_FIFOTHR(1) | BIT_RXGCK_HT_FIFOTHR(1) |
915 BIT_RXGCK_OFDM_FIFOTHR(1) | BIT_RXGCK_CCK_FIFOTHR(1)) >> 16;
916 rtw_write16(rtwdev, REG_RXPSF_CTRL + 2, value16);
917 value16 = 0;
918 value16 = BIT_SET_RXPSF_PKTLENTHR(value16, 1);
919 value16 |= BIT_RXPSF_CTRLEN | BIT_RXPSF_VHTCHKEN | BIT_RXPSF_HTCHKEN
920 | BIT_RXPSF_OFDMCHKEN | BIT_RXPSF_CCKCHKEN
921 | BIT_RXPSF_OFDMRST;
922 rtw_write16(rtwdev, REG_RXPSF_CTRL, value16);
923 rtw_write32(rtwdev, REG_RXPSF_TYPE_CTRL, 0xFFFFFFFF);
924 /* rx ignore configuration */
925 value16 = rtw_read16(rtwdev, REG_RXPSF_CTRL);
926 value16 &= ~(BIT_RXPSF_MHCHKEN | BIT_RXPSF_CCKRST |
927 BIT_RXPSF_CONT_ERRCHKEN);
928 value16 = BIT_SET_RXPSF_ERRTHR(value16, 0x07);
929 rtw_write16(rtwdev, REG_RXPSF_CTRL, value16);
930
931 return 0;
932}
933
934static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw)
935{
936#define RF18_BAND_MASK (BIT(16) | BIT(9) | BIT(8))
937#define RF18_BAND_2G (0)
938#define RF18_BAND_5G (BIT(16) | BIT(8))
939#define RF18_CHANNEL_MASK (MASKBYTE0)
940#define RF18_RFSI_MASK (BIT(18) | BIT(17))
941#define RF18_RFSI_GE_CH80 (BIT(17))
942#define RF18_RFSI_GT_CH140 (BIT(18))
943#define RF18_BW_MASK (BIT(13) | BIT(12))
944#define RF18_BW_20M (BIT(13) | BIT(12))
945#define RF18_BW_40M (BIT(13))
946#define RF18_BW_80M (BIT(12))
947
948 u32 rf_reg18 = 0;
949 u32 rf_rxbb = 0;
950
951 rf_reg18 = rtw_read_rf(rtwdev, RF_PATH_A, 0x18, RFREG_MASK);
952
953 rf_reg18 &= ~(RF18_BAND_MASK | RF18_CHANNEL_MASK | RF18_RFSI_MASK |
954 RF18_BW_MASK);
955
956 rf_reg18 |= (channel <= 14 ? RF18_BAND_2G : RF18_BAND_5G);
957 rf_reg18 |= (channel & RF18_CHANNEL_MASK);
958 if (channel > 144)
959 rf_reg18 |= RF18_RFSI_GT_CH140;
960 else if (channel >= 80)
961 rf_reg18 |= RF18_RFSI_GE_CH80;
962
963 switch (bw) {
964 case RTW_CHANNEL_WIDTH_5:
965 case RTW_CHANNEL_WIDTH_10:
966 case RTW_CHANNEL_WIDTH_20:
967 default:
968 rf_reg18 |= RF18_BW_20M;
969 rf_rxbb = 0x18;
970 break;
971 case RTW_CHANNEL_WIDTH_40:
972 /* RF bandwidth */
973 rf_reg18 |= RF18_BW_40M;
974 rf_rxbb = 0x10;
975 break;
976 case RTW_CHANNEL_WIDTH_80:
977 rf_reg18 |= RF18_BW_80M;
978 rf_rxbb = 0x8;
979 break;
980 }
981
982 rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE2, 0x04, 0x01);
983 rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWA, 0x1f, 0x12);
984 rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD0, 0xfffff, rf_rxbb);
985 rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE2, 0x04, 0x00);
986
987 rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWE2, 0x04, 0x01);
988 rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWA, 0x1f, 0x12);
989 rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWD0, 0xfffff, rf_rxbb);
990 rtw_write_rf(rtwdev, RF_PATH_B, RF_LUTWE2, 0x04, 0x00);
991
992 rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, rf_reg18);
993 rtw_write_rf(rtwdev, RF_PATH_B, RF_CFGCH, RFREG_MASK, rf_reg18);
994}
995
996static void rtw8822c_toggle_igi(struct rtw_dev *rtwdev)
997{
998 u32 igi;
999
1000 igi = rtw_read32_mask(rtwdev, REG_RXIGI, 0x7f);
1001 rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f, igi - 2);
1002 rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f00, igi - 2);
1003 rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f, igi);
1004 rtw_write32_mask(rtwdev, REG_RXIGI, 0x7f00, igi);
1005}
1006
1007static void rtw8822c_set_channel_bb(struct rtw_dev *rtwdev, u8 channel, u8 bw,
1008 u8 primary_ch_idx)
1009{
1010 if (channel <= 14) {
1011 rtw_write32_clr(rtwdev, REG_BGCTRL, BITS_RX_IQ_WEIGHT);
1012 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8);
1013 rtw_write32_set(rtwdev, REG_TXF4, BIT(20));
1014 rtw_write32_clr(rtwdev, REG_CCK_CHECK, BIT_CHECK_CCK_EN);
1015 rtw_write32_clr(rtwdev, REG_CCKTXONLY, BIT_BB_CCK_CHECK_EN);
1016 rtw_write32_mask(rtwdev, REG_CCAMSK, 0x3F000000, 0xF);
1017
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001018 switch (bw) {
1019 case RTW_CHANNEL_WIDTH_20:
1020 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_CCK,
1021 0x5);
1022 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_CCK,
1023 0x5);
1024 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM,
1025 0x6);
1026 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM,
1027 0x6);
1028 break;
1029 case RTW_CHANNEL_WIDTH_40:
1030 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_CCK,
1031 0x4);
1032 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_CCK,
1033 0x4);
1034 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM,
1035 0x0);
1036 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM,
1037 0x0);
1038 break;
1039 }
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001040 if (channel == 13 || channel == 14)
1041 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x969);
1042 else if (channel == 11 || channel == 12)
1043 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x96a);
1044 else
1045 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x9aa);
1046 if (channel == 14) {
1047 rtw_write32_mask(rtwdev, REG_TXF0, MASKHWORD, 0x3da0);
1048 rtw_write32_mask(rtwdev, REG_TXF1, MASKDWORD,
1049 0x4962c931);
1050 rtw_write32_mask(rtwdev, REG_TXF2, MASKLWORD, 0x6aa3);
1051 rtw_write32_mask(rtwdev, REG_TXF3, MASKHWORD, 0xaa7b);
1052 rtw_write32_mask(rtwdev, REG_TXF4, MASKLWORD, 0xf3d7);
1053 rtw_write32_mask(rtwdev, REG_TXF5, MASKDWORD, 0x0);
1054 rtw_write32_mask(rtwdev, REG_TXF6, MASKDWORD,
1055 0xff012455);
1056 rtw_write32_mask(rtwdev, REG_TXF7, MASKDWORD, 0xffff);
1057 } else {
1058 rtw_write32_mask(rtwdev, REG_TXF0, MASKHWORD, 0x5284);
1059 rtw_write32_mask(rtwdev, REG_TXF1, MASKDWORD,
1060 0x3e18fec8);
1061 rtw_write32_mask(rtwdev, REG_TXF2, MASKLWORD, 0x0a88);
1062 rtw_write32_mask(rtwdev, REG_TXF3, MASKHWORD, 0xacc4);
1063 rtw_write32_mask(rtwdev, REG_TXF4, MASKLWORD, 0xc8b2);
1064 rtw_write32_mask(rtwdev, REG_TXF5, MASKDWORD,
1065 0x00faf0de);
1066 rtw_write32_mask(rtwdev, REG_TXF6, MASKDWORD,
1067 0x00122344);
1068 rtw_write32_mask(rtwdev, REG_TXF7, MASKDWORD,
1069 0x0fffffff);
1070 }
1071 if (channel == 13)
1072 rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x3);
1073 else
1074 rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x1);
1075 } else if (channel > 35) {
1076 rtw_write32_set(rtwdev, REG_CCKTXONLY, BIT_BB_CCK_CHECK_EN);
1077 rtw_write32_set(rtwdev, REG_CCK_CHECK, BIT_CHECK_CCK_EN);
1078 rtw_write32_set(rtwdev, REG_BGCTRL, BITS_RX_IQ_WEIGHT);
1079 rtw_write32_clr(rtwdev, REG_TXF4, BIT(20));
1080 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x0);
1081 rtw_write32_mask(rtwdev, REG_CCAMSK, 0x3F000000, 0x22);
1082 rtw_write32_mask(rtwdev, REG_TXDFIR0, 0x70, 0x3);
1083 if (channel >= 36 && channel <= 64) {
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001084 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM,
1085 0x1);
1086 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM,
1087 0x1);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001088 } else if (channel >= 100 && channel <= 144) {
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001089 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM,
1090 0x2);
1091 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM,
1092 0x2);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001093 } else if (channel >= 149) {
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001094 rtw_write32_mask(rtwdev, REG_RXAGCCTL0, BITS_RXAGC_OFDM,
1095 0x3);
1096 rtw_write32_mask(rtwdev, REG_RXAGCCTL, BITS_RXAGC_OFDM,
1097 0x3);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001098 }
1099
1100 if (channel >= 36 && channel <= 51)
1101 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x494);
1102 else if (channel >= 52 && channel <= 55)
1103 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x493);
1104 else if (channel >= 56 && channel <= 111)
1105 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x453);
1106 else if (channel >= 112 && channel <= 119)
1107 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x452);
1108 else if (channel >= 120 && channel <= 172)
1109 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x412);
1110 else if (channel >= 173 && channel <= 177)
1111 rtw_write32_mask(rtwdev, REG_SCOTRK, 0xfff, 0x411);
1112 }
1113
1114 switch (bw) {
1115 case RTW_CHANNEL_WIDTH_20:
1116 rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x19B);
1117 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0);
1118 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x0);
1119 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x7);
1120 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x6);
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001121 rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0);
1122 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1);
1123 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001124 break;
1125 case RTW_CHANNEL_WIDTH_40:
1126 rtw_write32_mask(rtwdev, REG_CCKSB, BIT(4),
1127 (primary_ch_idx == 1 ? 1 : 0));
1128 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x5);
1129 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xc0, 0x0);
1130 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xff00,
1131 (primary_ch_idx | (primary_ch_idx << 4)));
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001132 rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x1);
1133 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1);
1134 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x1);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001135 break;
1136 case RTW_CHANNEL_WIDTH_80:
1137 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0xa);
1138 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xc0, 0x0);
1139 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xff00,
1140 (primary_ch_idx | (primary_ch_idx << 4)));
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001141 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x6);
1142 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x1);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001143 break;
1144 case RTW_CHANNEL_WIDTH_5:
1145 rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x2AB);
1146 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0);
1147 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x1);
1148 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x4);
1149 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x4);
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001150 rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0);
1151 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1);
1152 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001153 break;
1154 case RTW_CHANNEL_WIDTH_10:
1155 rtw_write32_mask(rtwdev, REG_DFIRBW, 0x3FF0, 0x2AB);
1156 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x0);
1157 rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xffc0, 0x2);
1158 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700, 0x6);
1159 rtw_write32_mask(rtwdev, REG_TXCLK, 0x700000, 0x5);
Chien-Hsun Liaof859e712019-06-14 15:24:09 +08001160 rtw_write32_mask(rtwdev, REG_CCK_SOURCE, BIT_NBI_EN, 0x0);
1161 rtw_write32_mask(rtwdev, REG_SBD, BITS_SUBTUNE, 0x1);
1162 rtw_write32_mask(rtwdev, REG_PT_CHSMO, BIT_PT_OPT, 0x0);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001163 break;
1164 }
1165}
1166
1167static void rtw8822c_set_channel(struct rtw_dev *rtwdev, u8 channel, u8 bw,
1168 u8 primary_chan_idx)
1169{
1170 rtw8822c_set_channel_bb(rtwdev, channel, bw, primary_chan_idx);
1171 rtw_set_channel_mac(rtwdev, channel, bw, primary_chan_idx);
1172 rtw8822c_set_channel_rf(rtwdev, channel, bw);
1173 rtw8822c_toggle_igi(rtwdev);
1174}
1175
1176static void rtw8822c_config_cck_rx_path(struct rtw_dev *rtwdev, u8 rx_path)
1177{
1178 if (rx_path == BB_PATH_A || rx_path == BB_PATH_B) {
1179 rtw_write32_mask(rtwdev, REG_CCANRX, 0x00060000, 0x0);
1180 rtw_write32_mask(rtwdev, REG_CCANRX, 0x00600000, 0x0);
1181 } else if (rx_path == BB_PATH_AB) {
1182 rtw_write32_mask(rtwdev, REG_CCANRX, 0x00600000, 0x1);
1183 rtw_write32_mask(rtwdev, REG_CCANRX, 0x00060000, 0x1);
1184 }
1185
1186 if (rx_path == BB_PATH_A)
1187 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x0);
1188 else if (rx_path == BB_PATH_B)
1189 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x5);
1190 else if (rx_path == BB_PATH_AB)
1191 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0x0f000000, 0x1);
1192}
1193
1194static void rtw8822c_config_ofdm_rx_path(struct rtw_dev *rtwdev, u8 rx_path)
1195{
1196 if (rx_path == BB_PATH_A || rx_path == BB_PATH_B) {
1197 rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x300, 0x0);
1198 rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x600000, 0x0);
1199 rtw_write32_mask(rtwdev, REG_AGCSWSH, BIT(17), 0x0);
1200 rtw_write32_mask(rtwdev, REG_ANTWTPD, BIT(20), 0x0);
1201 rtw_write32_mask(rtwdev, REG_MRCM, BIT(24), 0x0);
1202 } else if (rx_path == BB_PATH_AB) {
1203 rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x300, 0x1);
1204 rtw_write32_mask(rtwdev, REG_RXFNCTL, 0x600000, 0x1);
1205 rtw_write32_mask(rtwdev, REG_AGCSWSH, BIT(17), 0x1);
1206 rtw_write32_mask(rtwdev, REG_ANTWTPD, BIT(20), 0x1);
1207 rtw_write32_mask(rtwdev, REG_MRCM, BIT(24), 0x1);
1208 }
1209
1210 rtw_write32_mask(rtwdev, 0x824, 0x0f000000, rx_path);
1211 rtw_write32_mask(rtwdev, 0x824, 0x000f0000, rx_path);
1212}
1213
1214static void rtw8822c_config_rx_path(struct rtw_dev *rtwdev, u8 rx_path)
1215{
1216 rtw8822c_config_cck_rx_path(rtwdev, rx_path);
1217 rtw8822c_config_ofdm_rx_path(rtwdev, rx_path);
1218}
1219
1220static void rtw8822c_config_cck_tx_path(struct rtw_dev *rtwdev, u8 tx_path,
1221 bool is_tx2_path)
1222{
1223 if (tx_path == BB_PATH_A) {
1224 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8);
1225 } else if (tx_path == BB_PATH_B) {
1226 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x4);
1227 } else {
1228 if (is_tx2_path)
1229 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0xc);
1230 else
1231 rtw_write32_mask(rtwdev, REG_RXCCKSEL, 0xf0000000, 0x8);
1232 }
1233}
1234
1235static void rtw8822c_config_ofdm_tx_path(struct rtw_dev *rtwdev, u8 tx_path,
1236 bool is_tx2_path)
1237{
1238 if (tx_path == BB_PATH_A) {
1239 rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x11);
1240 rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xff, 0x0);
1241 } else if (tx_path == BB_PATH_B) {
1242 rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x12);
1243 rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xff, 0x0);
1244 } else {
1245 if (is_tx2_path) {
1246 rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x33);
1247 rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xffff, 0x0404);
1248 } else {
1249 rtw_write32_mask(rtwdev, REG_ANTMAP0, 0xff, 0x31);
1250 rtw_write32_mask(rtwdev, REG_TXLGMAP, 0xffff, 0x0400);
1251 }
1252 }
1253}
1254
1255static void rtw8822c_config_tx_path(struct rtw_dev *rtwdev, u8 tx_path,
1256 bool is_tx2_path)
1257{
1258 rtw8822c_config_cck_tx_path(rtwdev, tx_path, is_tx2_path);
1259 rtw8822c_config_ofdm_tx_path(rtwdev, tx_path, is_tx2_path);
1260}
1261
1262static void rtw8822c_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path,
1263 u8 rx_path, bool is_tx2_path)
1264{
1265 if ((tx_path | rx_path) & BB_PATH_A)
1266 rtw_write32_mask(rtwdev, REG_ORITXCODE, MASK20BITS, 0x33312);
1267 else
1268 rtw_write32_mask(rtwdev, REG_ORITXCODE, MASK20BITS, 0x11111);
1269 if ((tx_path | rx_path) & BB_PATH_B)
1270 rtw_write32_mask(rtwdev, REG_ORITXCODE2, MASK20BITS, 0x33312);
1271 else
1272 rtw_write32_mask(rtwdev, REG_ORITXCODE2, MASK20BITS, 0x11111);
1273
1274 rtw8822c_config_rx_path(rtwdev, rx_path);
1275 rtw8822c_config_tx_path(rtwdev, tx_path, is_tx2_path);
1276
1277 rtw8822c_toggle_igi(rtwdev);
1278}
1279
1280static void query_phy_status_page0(struct rtw_dev *rtwdev, u8 *phy_status,
1281 struct rtw_rx_pkt_stat *pkt_stat)
1282{
1283 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1284 u8 l_bnd, u_bnd;
1285 u8 gain_a, gain_b;
1286 s8 rx_power[RTW_RF_PATH_MAX];
1287 s8 min_rx_power = -120;
1288
1289 rx_power[RF_PATH_A] = GET_PHY_STAT_P0_PWDB_A(phy_status);
1290 rx_power[RF_PATH_B] = GET_PHY_STAT_P0_PWDB_B(phy_status);
1291 l_bnd = dm_info->cck_gi_l_bnd;
1292 u_bnd = dm_info->cck_gi_u_bnd;
1293 gain_a = GET_PHY_STAT_P0_GAIN_A(phy_status);
1294 gain_b = GET_PHY_STAT_P0_GAIN_B(phy_status);
1295 if (gain_a < l_bnd)
1296 rx_power[RF_PATH_A] += (l_bnd - gain_a) << 1;
1297 else if (gain_a > u_bnd)
1298 rx_power[RF_PATH_A] -= (gain_a - u_bnd) << 1;
1299 if (gain_b < l_bnd)
1300 rx_power[RF_PATH_A] += (l_bnd - gain_b) << 1;
1301 else if (gain_b > u_bnd)
1302 rx_power[RF_PATH_A] -= (gain_b - u_bnd) << 1;
1303
1304 rx_power[RF_PATH_A] -= 110;
1305 rx_power[RF_PATH_B] -= 110;
1306
1307 pkt_stat->rx_power[RF_PATH_A] = max3(rx_power[RF_PATH_A],
1308 rx_power[RF_PATH_B],
1309 min_rx_power);
1310 pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 1);
1311 pkt_stat->bw = RTW_CHANNEL_WIDTH_20;
1312 pkt_stat->signal_power = max(pkt_stat->rx_power[RF_PATH_A],
1313 min_rx_power);
1314}
1315
1316static void query_phy_status_page1(struct rtw_dev *rtwdev, u8 *phy_status,
1317 struct rtw_rx_pkt_stat *pkt_stat)
1318{
1319 u8 rxsc, bw;
1320 s8 min_rx_power = -120;
1321
1322 if (pkt_stat->rate > DESC_RATE11M && pkt_stat->rate < DESC_RATEMCS0)
1323 rxsc = GET_PHY_STAT_P1_L_RXSC(phy_status);
1324 else
1325 rxsc = GET_PHY_STAT_P1_HT_RXSC(phy_status);
1326
1327 if (rxsc >= 9 && rxsc <= 12)
1328 bw = RTW_CHANNEL_WIDTH_40;
1329 else if (rxsc >= 13)
1330 bw = RTW_CHANNEL_WIDTH_80;
1331 else
1332 bw = RTW_CHANNEL_WIDTH_20;
1333
1334 pkt_stat->rx_power[RF_PATH_A] = GET_PHY_STAT_P1_PWDB_A(phy_status) - 110;
1335 pkt_stat->rx_power[RF_PATH_B] = GET_PHY_STAT_P1_PWDB_B(phy_status) - 110;
1336 pkt_stat->rssi = rtw_phy_rf_power_2_rssi(pkt_stat->rx_power, 2);
1337 pkt_stat->bw = bw;
1338 pkt_stat->signal_power = max3(pkt_stat->rx_power[RF_PATH_A],
1339 pkt_stat->rx_power[RF_PATH_B],
1340 min_rx_power);
1341}
1342
1343static void query_phy_status(struct rtw_dev *rtwdev, u8 *phy_status,
1344 struct rtw_rx_pkt_stat *pkt_stat)
1345{
1346 u8 page;
1347
1348 page = *phy_status & 0xf;
1349
1350 switch (page) {
1351 case 0:
1352 query_phy_status_page0(rtwdev, phy_status, pkt_stat);
1353 break;
1354 case 1:
1355 query_phy_status_page1(rtwdev, phy_status, pkt_stat);
1356 break;
1357 default:
1358 rtw_warn(rtwdev, "unused phy status page (%d)\n", page);
1359 return;
1360 }
1361}
1362
1363static void rtw8822c_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc,
1364 struct rtw_rx_pkt_stat *pkt_stat,
1365 struct ieee80211_rx_status *rx_status)
1366{
1367 struct ieee80211_hdr *hdr;
1368 u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz;
1369 u8 *phy_status = NULL;
1370
1371 memset(pkt_stat, 0, sizeof(*pkt_stat));
1372
1373 pkt_stat->phy_status = GET_RX_DESC_PHYST(rx_desc);
1374 pkt_stat->icv_err = GET_RX_DESC_ICV_ERR(rx_desc);
1375 pkt_stat->crc_err = GET_RX_DESC_CRC32(rx_desc);
1376 pkt_stat->decrypted = !GET_RX_DESC_SWDEC(rx_desc);
1377 pkt_stat->is_c2h = GET_RX_DESC_C2H(rx_desc);
1378 pkt_stat->pkt_len = GET_RX_DESC_PKT_LEN(rx_desc);
1379 pkt_stat->drv_info_sz = GET_RX_DESC_DRV_INFO_SIZE(rx_desc);
1380 pkt_stat->shift = GET_RX_DESC_SHIFT(rx_desc);
1381 pkt_stat->rate = GET_RX_DESC_RX_RATE(rx_desc);
1382 pkt_stat->cam_id = GET_RX_DESC_MACID(rx_desc);
1383 pkt_stat->ppdu_cnt = GET_RX_DESC_PPDU_CNT(rx_desc);
1384 pkt_stat->tsf_low = GET_RX_DESC_TSFL(rx_desc);
1385
1386 /* drv_info_sz is in unit of 8-bytes */
1387 pkt_stat->drv_info_sz *= 8;
1388
1389 /* c2h cmd pkt's rx/phy status is not interested */
1390 if (pkt_stat->is_c2h)
1391 return;
1392
1393 hdr = (struct ieee80211_hdr *)(rx_desc + desc_sz + pkt_stat->shift +
1394 pkt_stat->drv_info_sz);
1395 if (pkt_stat->phy_status) {
1396 phy_status = rx_desc + desc_sz + pkt_stat->shift;
1397 query_phy_status(rtwdev, phy_status, pkt_stat);
1398 }
1399
1400 rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status);
1401}
1402
1403static void
1404rtw8822c_set_write_tx_power_ref(struct rtw_dev *rtwdev, u8 *tx_pwr_ref_cck,
1405 u8 *tx_pwr_ref_ofdm)
1406{
1407 struct rtw_hal *hal = &rtwdev->hal;
1408 u32 txref_cck[2] = {0x18a0, 0x41a0};
1409 u32 txref_ofdm[2] = {0x18e8, 0x41e8};
1410 u8 path;
1411
1412 for (path = 0; path < hal->rf_path_num; path++) {
1413 rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0);
1414 rtw_write32_mask(rtwdev, txref_cck[path], 0x7f0000,
1415 tx_pwr_ref_cck[path]);
1416 }
1417 for (path = 0; path < hal->rf_path_num; path++) {
1418 rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0);
1419 rtw_write32_mask(rtwdev, txref_ofdm[path], 0x1fc00,
1420 tx_pwr_ref_ofdm[path]);
1421 }
1422}
1423
1424static void rtw8822c_set_tx_power_diff(struct rtw_dev *rtwdev, u8 rate,
1425 s8 *diff_idx)
1426{
1427 u32 offset_txagc = 0x3a00;
1428 u8 rate_idx = rate & 0xfc;
1429 u8 pwr_idx[4];
1430 u32 phy_pwr_idx;
1431 int i;
1432
1433 for (i = 0; i < 4; i++)
1434 pwr_idx[i] = diff_idx[i] & 0x7f;
1435
1436 phy_pwr_idx = pwr_idx[0] |
1437 (pwr_idx[1] << 8) |
1438 (pwr_idx[2] << 16) |
1439 (pwr_idx[3] << 24);
1440
1441 rtw_write32_mask(rtwdev, 0x1c90, BIT(15), 0x0);
1442 rtw_write32_mask(rtwdev, offset_txagc + rate_idx, MASKDWORD,
1443 phy_pwr_idx);
1444}
1445
1446static void rtw8822c_set_tx_power_index(struct rtw_dev *rtwdev)
1447{
1448 struct rtw_hal *hal = &rtwdev->hal;
1449 u8 rs, rate, j;
1450 u8 pwr_ref_cck[2] = {hal->tx_pwr_tbl[RF_PATH_A][DESC_RATE11M],
1451 hal->tx_pwr_tbl[RF_PATH_B][DESC_RATE11M]};
1452 u8 pwr_ref_ofdm[2] = {hal->tx_pwr_tbl[RF_PATH_A][DESC_RATEMCS7],
1453 hal->tx_pwr_tbl[RF_PATH_B][DESC_RATEMCS7]};
1454 s8 diff_a, diff_b;
1455 u8 pwr_a, pwr_b;
1456 s8 diff_idx[4];
1457
1458 rtw8822c_set_write_tx_power_ref(rtwdev, pwr_ref_cck, pwr_ref_ofdm);
1459 for (rs = 0; rs < RTW_RATE_SECTION_MAX; rs++) {
1460 for (j = 0; j < rtw_rate_size[rs]; j++) {
1461 rate = rtw_rate_section[rs][j];
1462 pwr_a = hal->tx_pwr_tbl[RF_PATH_A][rate];
1463 pwr_b = hal->tx_pwr_tbl[RF_PATH_B][rate];
1464 if (rs == 0) {
1465 diff_a = (s8)pwr_a - (s8)pwr_ref_cck[0];
1466 diff_b = (s8)pwr_b - (s8)pwr_ref_cck[1];
1467 } else {
1468 diff_a = (s8)pwr_a - (s8)pwr_ref_ofdm[0];
1469 diff_b = (s8)pwr_b - (s8)pwr_ref_ofdm[1];
1470 }
1471 diff_idx[rate % 4] = min(diff_a, diff_b);
1472 if (rate % 4 == 3)
1473 rtw8822c_set_tx_power_diff(rtwdev, rate - 3,
1474 diff_idx);
1475 }
1476 }
1477}
1478
1479static void rtw8822c_cfg_ldo25(struct rtw_dev *rtwdev, bool enable)
1480{
1481 u8 ldo_pwr;
1482
1483 ldo_pwr = rtw_read8(rtwdev, REG_ANAPARLDO_POW_MAC);
1484 ldo_pwr = enable ? ldo_pwr | BIT_LDOE25_PON : ldo_pwr & ~BIT_LDOE25_PON;
1485 rtw_write8(rtwdev, REG_ANAPARLDO_POW_MAC, ldo_pwr);
1486}
1487
1488static void rtw8822c_false_alarm_statistics(struct rtw_dev *rtwdev)
1489{
1490 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1491 u32 cck_enable;
1492 u32 cck_fa_cnt;
1493 u32 ofdm_fa_cnt;
Yan-Hsuan Chuange1cc0562019-06-14 15:24:11 +08001494 u32 ofdm_fa_cnt1, ofdm_fa_cnt2, ofdm_fa_cnt3, ofdm_fa_cnt4, ofdm_fa_cnt5;
1495 u16 parity_fail, rate_illegal, crc8_fail, mcs_fail, sb_search_fail,
1496 fast_fsync, crc8_fail_vhta, mcs_fail_vht;
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001497
1498 cck_enable = rtw_read32(rtwdev, REG_ENCCK) & BIT_CCK_BLK_EN;
1499 cck_fa_cnt = rtw_read16(rtwdev, REG_CCK_FACNT);
Yan-Hsuan Chuange1cc0562019-06-14 15:24:11 +08001500
1501 ofdm_fa_cnt1 = rtw_read32(rtwdev, REG_OFDM_FACNT1);
1502 ofdm_fa_cnt2 = rtw_read32(rtwdev, REG_OFDM_FACNT2);
1503 ofdm_fa_cnt3 = rtw_read32(rtwdev, REG_OFDM_FACNT3);
1504 ofdm_fa_cnt4 = rtw_read32(rtwdev, REG_OFDM_FACNT4);
1505 ofdm_fa_cnt5 = rtw_read32(rtwdev, REG_OFDM_FACNT5);
1506
1507 parity_fail = FIELD_GET(GENMASK(31, 16), ofdm_fa_cnt1);
1508 rate_illegal = FIELD_GET(GENMASK(15, 0), ofdm_fa_cnt2);
1509 crc8_fail = FIELD_GET(GENMASK(31, 16), ofdm_fa_cnt2);
1510 crc8_fail_vhta = FIELD_GET(GENMASK(15, 0), ofdm_fa_cnt3);
1511 mcs_fail = FIELD_GET(GENMASK(15, 0), ofdm_fa_cnt4);
1512 mcs_fail_vht = FIELD_GET(GENMASK(31, 16), ofdm_fa_cnt4);
1513 fast_fsync = FIELD_GET(GENMASK(15, 0), ofdm_fa_cnt5);
1514 sb_search_fail = FIELD_GET(GENMASK(31, 16), ofdm_fa_cnt5);
1515
1516 ofdm_fa_cnt = parity_fail + rate_illegal + crc8_fail + crc8_fail_vhta +
1517 mcs_fail + mcs_fail_vht + fast_fsync + sb_search_fail;
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001518
1519 dm_info->cck_fa_cnt = cck_fa_cnt;
1520 dm_info->ofdm_fa_cnt = ofdm_fa_cnt;
1521 dm_info->total_fa_cnt = ofdm_fa_cnt;
1522 dm_info->total_fa_cnt += cck_enable ? cck_fa_cnt : 0;
1523
1524 rtw_write32_mask(rtwdev, REG_CCANRX, BIT_CCK_FA_RST, 0);
1525 rtw_write32_mask(rtwdev, REG_CCANRX, BIT_CCK_FA_RST, 2);
1526 rtw_write32_mask(rtwdev, REG_CCANRX, BIT_OFDM_FA_RST, 0);
1527 rtw_write32_mask(rtwdev, REG_CCANRX, BIT_OFDM_FA_RST, 2);
Yan-Hsuan Chuange02744662019-06-14 15:24:10 +08001528
1529 /* disable rx clk gating to reset counters */
1530 rtw_write32_clr(rtwdev, REG_RX_BREAK, BIT_COM_RX_GCK_EN);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001531 rtw_write32_set(rtwdev, REG_CNT_CTRL, BIT_ALL_CNT_RST);
1532 rtw_write32_clr(rtwdev, REG_CNT_CTRL, BIT_ALL_CNT_RST);
Yan-Hsuan Chuange02744662019-06-14 15:24:10 +08001533 rtw_write32_set(rtwdev, REG_RX_BREAK, BIT_COM_RX_GCK_EN);
Yan-Hsuan Chuange3037482019-04-26 15:17:37 +03001534}
1535
1536static void rtw8822c_do_iqk(struct rtw_dev *rtwdev)
1537{
1538}
1539
1540static struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8822c[] = {
1541 {0x0086,
1542 RTW_PWR_CUT_ALL_MSK,
1543 RTW_PWR_INTF_SDIO_MSK,
1544 RTW_PWR_ADDR_SDIO,
1545 RTW_PWR_CMD_WRITE, BIT(0), 0},
1546 {0x0086,
1547 RTW_PWR_CUT_ALL_MSK,
1548 RTW_PWR_INTF_SDIO_MSK,
1549 RTW_PWR_ADDR_SDIO,
1550 RTW_PWR_CMD_POLLING, BIT(1), BIT(1)},
1551 {0x002E,
1552 RTW_PWR_CUT_ALL_MSK,
1553 RTW_PWR_INTF_ALL_MSK,
1554 RTW_PWR_ADDR_MAC,
1555 RTW_PWR_CMD_WRITE, BIT(2), BIT(2)},
1556 {0x002D,
1557 RTW_PWR_CUT_ALL_MSK,
1558 RTW_PWR_INTF_ALL_MSK,
1559 RTW_PWR_ADDR_MAC,
1560 RTW_PWR_CMD_WRITE, BIT(0), 0},
1561 {0x007F,
1562 RTW_PWR_CUT_ALL_MSK,
1563 RTW_PWR_INTF_ALL_MSK,
1564 RTW_PWR_ADDR_MAC,
1565 RTW_PWR_CMD_WRITE, BIT(7), 0},
1566 {0x004A,
1567 RTW_PWR_CUT_ALL_MSK,
1568 RTW_PWR_INTF_USB_MSK,
1569 RTW_PWR_ADDR_MAC,
1570 RTW_PWR_CMD_WRITE, BIT(0), 0},
1571 {0x0005,
1572 RTW_PWR_CUT_ALL_MSK,
1573 RTW_PWR_INTF_ALL_MSK,
1574 RTW_PWR_ADDR_MAC,
1575 RTW_PWR_CMD_WRITE, BIT(3) | BIT(4) | BIT(7), 0},
1576 {0xFFFF,
1577 RTW_PWR_CUT_ALL_MSK,
1578 RTW_PWR_INTF_ALL_MSK,
1579 0,
1580 RTW_PWR_CMD_END, 0, 0},
1581};
1582
1583static struct rtw_pwr_seq_cmd trans_cardemu_to_act_8822c[] = {
1584 {0x0000,
1585 RTW_PWR_CUT_ALL_MSK,
1586 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
1587 RTW_PWR_ADDR_MAC,
1588 RTW_PWR_CMD_WRITE, BIT(5), 0},
1589 {0x0005,
1590 RTW_PWR_CUT_ALL_MSK,
1591 RTW_PWR_INTF_ALL_MSK,
1592 RTW_PWR_ADDR_MAC,
1593 RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3) | BIT(2)), 0},
1594 {0x0075,
1595 RTW_PWR_CUT_ALL_MSK,
1596 RTW_PWR_INTF_PCI_MSK,
1597 RTW_PWR_ADDR_MAC,
1598 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
1599 {0x0006,
1600 RTW_PWR_CUT_ALL_MSK,
1601 RTW_PWR_INTF_ALL_MSK,
1602 RTW_PWR_ADDR_MAC,
1603 RTW_PWR_CMD_POLLING, BIT(1), BIT(1)},
1604 {0x0075,
1605 RTW_PWR_CUT_ALL_MSK,
1606 RTW_PWR_INTF_PCI_MSK,
1607 RTW_PWR_ADDR_MAC,
1608 RTW_PWR_CMD_WRITE, BIT(0), 0},
1609 {0xFF1A,
1610 RTW_PWR_CUT_ALL_MSK,
1611 RTW_PWR_INTF_USB_MSK,
1612 RTW_PWR_ADDR_MAC,
1613 RTW_PWR_CMD_WRITE, 0xFF, 0},
1614 {0x002E,
1615 RTW_PWR_CUT_ALL_MSK,
1616 RTW_PWR_INTF_ALL_MSK,
1617 RTW_PWR_ADDR_MAC,
1618 RTW_PWR_CMD_WRITE, BIT(3), 0},
1619 {0x0006,
1620 RTW_PWR_CUT_ALL_MSK,
1621 RTW_PWR_INTF_ALL_MSK,
1622 RTW_PWR_ADDR_MAC,
1623 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
1624 {0x0005,
1625 RTW_PWR_CUT_ALL_MSK,
1626 RTW_PWR_INTF_ALL_MSK,
1627 RTW_PWR_ADDR_MAC,
1628 RTW_PWR_CMD_WRITE, BIT(7), 0},
1629 {0x0005,
1630 RTW_PWR_CUT_ALL_MSK,
1631 RTW_PWR_INTF_ALL_MSK,
1632 RTW_PWR_ADDR_MAC,
1633 RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3)), 0},
1634 {0x0005,
1635 RTW_PWR_CUT_ALL_MSK,
1636 RTW_PWR_INTF_ALL_MSK,
1637 RTW_PWR_ADDR_MAC,
1638 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
1639 {0x0005,
1640 RTW_PWR_CUT_ALL_MSK,
1641 RTW_PWR_INTF_ALL_MSK,
1642 RTW_PWR_ADDR_MAC,
1643 RTW_PWR_CMD_POLLING, BIT(0), 0},
1644 {0x0074,
1645 RTW_PWR_CUT_ALL_MSK,
1646 RTW_PWR_INTF_PCI_MSK,
1647 RTW_PWR_ADDR_MAC,
1648 RTW_PWR_CMD_WRITE, BIT(5), BIT(5)},
1649 {0x0071,
1650 RTW_PWR_CUT_ALL_MSK,
1651 RTW_PWR_INTF_PCI_MSK,
1652 RTW_PWR_ADDR_MAC,
1653 RTW_PWR_CMD_WRITE, BIT(4), 0},
1654 {0x0062,
1655 RTW_PWR_CUT_ALL_MSK,
1656 RTW_PWR_INTF_PCI_MSK,
1657 RTW_PWR_ADDR_MAC,
1658 RTW_PWR_CMD_WRITE, (BIT(7) | BIT(6) | BIT(5)),
1659 (BIT(7) | BIT(6) | BIT(5))},
1660 {0x0061,
1661 RTW_PWR_CUT_ALL_MSK,
1662 RTW_PWR_INTF_PCI_MSK,
1663 RTW_PWR_ADDR_MAC,
1664 RTW_PWR_CMD_WRITE, (BIT(7) | BIT(6) | BIT(5)), 0},
1665 {0x001F,
1666 RTW_PWR_CUT_ALL_MSK,
1667 RTW_PWR_INTF_ALL_MSK,
1668 RTW_PWR_ADDR_MAC,
1669 RTW_PWR_CMD_WRITE, (BIT(7) | BIT(6)), BIT(7)},
1670 {0x00EF,
1671 RTW_PWR_CUT_ALL_MSK,
1672 RTW_PWR_INTF_ALL_MSK,
1673 RTW_PWR_ADDR_MAC,
1674 RTW_PWR_CMD_WRITE, (BIT(7) | BIT(6)), BIT(7)},
1675 {0x1045,
1676 RTW_PWR_CUT_ALL_MSK,
1677 RTW_PWR_INTF_ALL_MSK,
1678 RTW_PWR_ADDR_MAC,
1679 RTW_PWR_CMD_WRITE, BIT(4), BIT(4)},
1680 {0x0010,
1681 RTW_PWR_CUT_ALL_MSK,
1682 RTW_PWR_INTF_ALL_MSK,
1683 RTW_PWR_ADDR_MAC,
1684 RTW_PWR_CMD_WRITE, BIT(2), BIT(2)},
1685 {0xFFFF,
1686 RTW_PWR_CUT_ALL_MSK,
1687 RTW_PWR_INTF_ALL_MSK,
1688 0,
1689 RTW_PWR_CMD_END, 0, 0},
1690};
1691
1692static struct rtw_pwr_seq_cmd trans_act_to_cardemu_8822c[] = {
1693 {0x0093,
1694 RTW_PWR_CUT_ALL_MSK,
1695 RTW_PWR_INTF_ALL_MSK,
1696 RTW_PWR_ADDR_MAC,
1697 RTW_PWR_CMD_WRITE, BIT(3), 0},
1698 {0x001F,
1699 RTW_PWR_CUT_ALL_MSK,
1700 RTW_PWR_INTF_ALL_MSK,
1701 RTW_PWR_ADDR_MAC,
1702 RTW_PWR_CMD_WRITE, 0xFF, 0},
1703 {0x00EF,
1704 RTW_PWR_CUT_ALL_MSK,
1705 RTW_PWR_INTF_ALL_MSK,
1706 RTW_PWR_ADDR_MAC,
1707 RTW_PWR_CMD_WRITE, 0xFF, 0},
1708 {0x1045,
1709 RTW_PWR_CUT_ALL_MSK,
1710 RTW_PWR_INTF_ALL_MSK,
1711 RTW_PWR_ADDR_MAC,
1712 RTW_PWR_CMD_WRITE, BIT(4), 0},
1713 {0xFF1A,
1714 RTW_PWR_CUT_ALL_MSK,
1715 RTW_PWR_INTF_USB_MSK,
1716 RTW_PWR_ADDR_MAC,
1717 RTW_PWR_CMD_WRITE, 0xFF, 0x30},
1718 {0x0049,
1719 RTW_PWR_CUT_ALL_MSK,
1720 RTW_PWR_INTF_ALL_MSK,
1721 RTW_PWR_ADDR_MAC,
1722 RTW_PWR_CMD_WRITE, BIT(1), 0},
1723 {0x0006,
1724 RTW_PWR_CUT_ALL_MSK,
1725 RTW_PWR_INTF_ALL_MSK,
1726 RTW_PWR_ADDR_MAC,
1727 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
1728 {0x0002,
1729 RTW_PWR_CUT_ALL_MSK,
1730 RTW_PWR_INTF_ALL_MSK,
1731 RTW_PWR_ADDR_MAC,
1732 RTW_PWR_CMD_WRITE, BIT(1), 0},
1733 {0x0005,
1734 RTW_PWR_CUT_ALL_MSK,
1735 RTW_PWR_INTF_ALL_MSK,
1736 RTW_PWR_ADDR_MAC,
1737 RTW_PWR_CMD_WRITE, BIT(1), BIT(1)},
1738 {0x0005,
1739 RTW_PWR_CUT_ALL_MSK,
1740 RTW_PWR_INTF_ALL_MSK,
1741 RTW_PWR_ADDR_MAC,
1742 RTW_PWR_CMD_POLLING, BIT(1), 0},
1743 {0x0000,
1744 RTW_PWR_CUT_ALL_MSK,
1745 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
1746 RTW_PWR_ADDR_MAC,
1747 RTW_PWR_CMD_WRITE, BIT(5), BIT(5)},
1748 {0xFFFF,
1749 RTW_PWR_CUT_ALL_MSK,
1750 RTW_PWR_INTF_ALL_MSK,
1751 0,
1752 RTW_PWR_CMD_END, 0, 0},
1753};
1754
1755static struct rtw_pwr_seq_cmd trans_cardemu_to_carddis_8822c[] = {
1756 {0x0005,
1757 RTW_PWR_CUT_ALL_MSK,
1758 RTW_PWR_INTF_SDIO_MSK,
1759 RTW_PWR_ADDR_MAC,
1760 RTW_PWR_CMD_WRITE, BIT(7), BIT(7)},
1761 {0x0007,
1762 RTW_PWR_CUT_ALL_MSK,
1763 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
1764 RTW_PWR_ADDR_MAC,
1765 RTW_PWR_CMD_WRITE, 0xFF, 0x00},
1766 {0x0067,
1767 RTW_PWR_CUT_ALL_MSK,
1768 RTW_PWR_INTF_ALL_MSK,
1769 RTW_PWR_ADDR_MAC,
1770 RTW_PWR_CMD_WRITE, BIT(5), 0},
1771 {0x004A,
1772 RTW_PWR_CUT_ALL_MSK,
1773 RTW_PWR_INTF_USB_MSK,
1774 RTW_PWR_ADDR_MAC,
1775 RTW_PWR_CMD_WRITE, BIT(0), 0},
1776 {0x0081,
1777 RTW_PWR_CUT_ALL_MSK,
1778 RTW_PWR_INTF_ALL_MSK,
1779 RTW_PWR_ADDR_MAC,
1780 RTW_PWR_CMD_WRITE, BIT(7) | BIT(6), 0},
1781 {0x0090,
1782 RTW_PWR_CUT_ALL_MSK,
1783 RTW_PWR_INTF_ALL_MSK,
1784 RTW_PWR_ADDR_MAC,
1785 RTW_PWR_CMD_WRITE, BIT(1), 0},
1786 {0x0005,
1787 RTW_PWR_CUT_ALL_MSK,
1788 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
1789 RTW_PWR_ADDR_MAC,
1790 RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3)},
1791 {0x0005,
1792 RTW_PWR_CUT_ALL_MSK,
1793 RTW_PWR_INTF_PCI_MSK,
1794 RTW_PWR_ADDR_MAC,
1795 RTW_PWR_CMD_WRITE, BIT(2), BIT(2)},
1796 {0x0086,
1797 RTW_PWR_CUT_ALL_MSK,
1798 RTW_PWR_INTF_SDIO_MSK,
1799 RTW_PWR_ADDR_SDIO,
1800 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
1801 {0xFFFF,
1802 RTW_PWR_CUT_ALL_MSK,
1803 RTW_PWR_INTF_ALL_MSK,
1804 0,
1805 RTW_PWR_CMD_END, 0, 0},
1806};
1807
1808static struct rtw_pwr_seq_cmd *card_enable_flow_8822c[] = {
1809 trans_carddis_to_cardemu_8822c,
1810 trans_cardemu_to_act_8822c,
1811 NULL
1812};
1813
1814static struct rtw_pwr_seq_cmd *card_disable_flow_8822c[] = {
1815 trans_act_to_cardemu_8822c,
1816 trans_cardemu_to_carddis_8822c,
1817 NULL
1818};
1819
1820static struct rtw_intf_phy_para usb2_param_8822c[] = {
1821 {0xFFFF, 0x00,
1822 RTW_IP_SEL_PHY,
1823 RTW_INTF_PHY_CUT_ALL,
1824 RTW_INTF_PHY_PLATFORM_ALL},
1825};
1826
1827static struct rtw_intf_phy_para usb3_param_8822c[] = {
1828 {0xFFFF, 0x0000,
1829 RTW_IP_SEL_PHY,
1830 RTW_INTF_PHY_CUT_ALL,
1831 RTW_INTF_PHY_PLATFORM_ALL},
1832};
1833
1834static struct rtw_intf_phy_para pcie_gen1_param_8822c[] = {
1835 {0xFFFF, 0x0000,
1836 RTW_IP_SEL_PHY,
1837 RTW_INTF_PHY_CUT_ALL,
1838 RTW_INTF_PHY_PLATFORM_ALL},
1839};
1840
1841static struct rtw_intf_phy_para pcie_gen2_param_8822c[] = {
1842 {0xFFFF, 0x0000,
1843 RTW_IP_SEL_PHY,
1844 RTW_INTF_PHY_CUT_ALL,
1845 RTW_INTF_PHY_PLATFORM_ALL},
1846};
1847
1848static struct rtw_intf_phy_para_table phy_para_table_8822c = {
1849 .usb2_para = usb2_param_8822c,
1850 .usb3_para = usb3_param_8822c,
1851 .gen1_para = pcie_gen1_param_8822c,
1852 .gen2_para = pcie_gen2_param_8822c,
1853 .n_usb2_para = ARRAY_SIZE(usb2_param_8822c),
1854 .n_usb3_para = ARRAY_SIZE(usb2_param_8822c),
1855 .n_gen1_para = ARRAY_SIZE(pcie_gen1_param_8822c),
1856 .n_gen2_para = ARRAY_SIZE(pcie_gen2_param_8822c),
1857};
1858
1859static const struct rtw_rfe_def rtw8822c_rfe_defs[] = {
1860 [0] = RTW_DEF_RFE(8822c, 0, 0),
1861 [1] = RTW_DEF_RFE(8822c, 0, 0),
1862 [2] = RTW_DEF_RFE(8822c, 0, 0),
1863};
1864
1865static struct rtw_hw_reg rtw8822c_dig[] = {
1866 [0] = { .addr = 0x1d70, .mask = 0x7f },
1867 [1] = { .addr = 0x1d70, .mask = 0x7f00 },
1868};
1869
1870static struct rtw_page_table page_table_8822c[] = {
1871 {64, 64, 64, 64, 1},
1872 {64, 64, 64, 64, 1},
1873 {64, 64, 0, 0, 1},
1874 {64, 64, 64, 0, 1},
1875 {64, 64, 64, 64, 1},
1876};
1877
1878static struct rtw_rqpn rqpn_table_8822c[] = {
1879 {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL,
1880 RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW,
1881 RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH},
1882 {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL,
1883 RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW,
1884 RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH},
1885 {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL,
1886 RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_HIGH,
1887 RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH},
1888 {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL,
1889 RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW,
1890 RTW_DMA_MAPPING_HIGH, RTW_DMA_MAPPING_HIGH},
1891 {RTW_DMA_MAPPING_NORMAL, RTW_DMA_MAPPING_NORMAL,
1892 RTW_DMA_MAPPING_LOW, RTW_DMA_MAPPING_LOW,
1893 RTW_DMA_MAPPING_EXTRA, RTW_DMA_MAPPING_HIGH},
1894};
1895
1896static struct rtw_chip_ops rtw8822c_ops = {
1897 .phy_set_param = rtw8822c_phy_set_param,
1898 .read_efuse = rtw8822c_read_efuse,
1899 .query_rx_desc = rtw8822c_query_rx_desc,
1900 .set_channel = rtw8822c_set_channel,
1901 .mac_init = rtw8822c_mac_init,
1902 .read_rf = rtw_phy_read_rf,
1903 .write_rf = rtw_phy_write_rf_reg_mix,
1904 .set_tx_power_index = rtw8822c_set_tx_power_index,
1905 .cfg_ldo25 = rtw8822c_cfg_ldo25,
1906 .false_alarm_statistics = rtw8822c_false_alarm_statistics,
1907 .do_iqk = rtw8822c_do_iqk,
1908};
1909
1910struct rtw_chip_info rtw8822c_hw_spec = {
1911 .ops = &rtw8822c_ops,
1912 .id = RTW_CHIP_TYPE_8822C,
1913 .fw_name = "rtw88/rtw8822c_fw.bin",
1914 .tx_pkt_desc_sz = 48,
1915 .tx_buf_desc_sz = 16,
1916 .rx_pkt_desc_sz = 24,
1917 .rx_buf_desc_sz = 8,
1918 .phy_efuse_size = 512,
1919 .log_efuse_size = 768,
1920 .ptct_efuse_size = 124,
1921 .txff_size = 262144,
1922 .rxff_size = 24576,
1923 .txgi_factor = 2,
1924 .is_pwr_by_rate_dec = false,
1925 .max_power_index = 0x7f,
1926 .csi_buf_pg_num = 50,
1927 .band = RTW_BAND_2G | RTW_BAND_5G,
1928 .page_size = 128,
1929 .dig_min = 0x20,
1930 .ht_supported = true,
1931 .vht_supported = true,
1932 .sys_func_en = 0xD8,
1933 .pwr_on_seq = card_enable_flow_8822c,
1934 .pwr_off_seq = card_disable_flow_8822c,
1935 .page_table = page_table_8822c,
1936 .rqpn_table = rqpn_table_8822c,
1937 .intf_table = &phy_para_table_8822c,
1938 .dig = rtw8822c_dig,
1939 .rf_base_addr = {0x3c00, 0x4c00},
1940 .rf_sipi_addr = {0x1808, 0x4108},
1941 .mac_tbl = &rtw8822c_mac_tbl,
1942 .agc_tbl = &rtw8822c_agc_tbl,
1943 .bb_tbl = &rtw8822c_bb_tbl,
1944 .rfk_init_tbl = &rtw8822c_array_mp_cal_init_tbl,
1945 .rf_tbl = {&rtw8822c_rf_a_tbl, &rtw8822c_rf_b_tbl},
1946 .rfe_defs = rtw8822c_rfe_defs,
1947 .rfe_defs_size = ARRAY_SIZE(rtw8822c_rfe_defs),
1948};
1949EXPORT_SYMBOL(rtw8822c_hw_spec);
1950
1951MODULE_FIRMWARE("rtw88/rtw8822c_fw.bin");